Revision
50
Author
emsmith
Date
2006-12-01 13:18:11 -0800 (Fri, 01 Dec 2006)

Log Message

bugs in action fixed...oops

Modified Paths

Diff

Modified: desktop/trunk/lib/actions.class.php (49 => 50)


--- desktop/trunk/lib/actions.class.php	2006-12-01 21:17:47 UTC (rev 49)
+++ desktop/trunk/lib/actions.class.php	2006-12-01 21:18:11 UTC (rev 50)
@@ -27,6 +27,12 @@
 {
 
 	/**
+	 * singleton instance for this class
+	 * @var $singleton instanceof Tooltips
+	 */
+	static protected $singleton;
+
+	/**
 	 * list of all current created action groups
 	 * @var $groups array
 	 */
@@ -47,6 +53,14 @@
 	 */
 	public function __construct()
 	{
+		if(!is_null(self::$singleton))
+		{
+			throw new Exception(CC_Main::i18n(
+			'%1$s is a singleton class - use %1$s::instance() to retrieve the current object',
+			'CC_Writer'));
+		}
+		self::$singleton = $this;
+
 		$this->accel = new GtkAccelGroup();
 		return;
 	}
@@ -178,20 +192,29 @@
 		$group = $this->get_group($group);
 		foreach($definitions as $def)
 		{
+			if(!isset($def['image']))
+			{
+				$def['image'] = NULL;
+			}
 			switch($def['type'])
 			{
 				case 'radio':
 					$action = new GtkRadioAction($def['name'], CC_Main::i18n($def['label']), CC_Main::i18n($def['tooltip']),$def['image'],$def['value']);
-					$action->set_group($group->get_action($def['radio']));
+					$signal = 'toggled';
 					break;
 				case 'toggle':
 					$action = new GtkToggleAction($def['name'], CC_Main::i18n($def['label']), CC_Main::i18n($def['tooltip']),$def['image']);
+					$signal = 'toggled';
 					break;
 				default:
 					$action = new GtkAction($def['name'], CC_Main::i18n($def['label']), CC_Main::i18n($def['tooltip']),$def['image']);
+					$signal = 'activate';
 			}
 			$action->set_property('short-label', isset($def['short-label']) ? CC_Main::i18n($def['short-label']) : NULL);
-			$action->connect($callback);
+			if(isset($def['callback']))
+			{
+				$action->connect($signal, $def['callback']);
+			}
 			if(isset($def['accel']))
 			{
 				$action->set_accel_group($this->accel);
@@ -201,9 +224,42 @@
 			{
 				$group->add_action($action);
 			}
+			if(isset($def['radio']))
+			{
+				$action->set_group($group->get_action($def['radio']));
+			}
 		}
-		unset($def, $definitions, $group, $action, $this);
+		unset($def, $definitions, $group, $action, $this, $signal);
 		return;
 	}
+
+	/**
+	 * static public function instance
+	 *
+	 * this is how items can access the actions
+	 *
+	 * @return object instanceof CC_Actions
+	 */
+	static public function instance()
+	{
+		if(is_null(self::$singleton))
+		{
+			self::$singleton = new CC_Actions();
+		}
+		return self::$singleton;
+	}
+
+	/**
+	 * public function __clone()
+	 *
+	 * disable cloning of a singleton
+	 *
+	 * @return void
+	 */
+	public function __clone()
+	{
+		throw new Exception(CC_Main::i18n('Cannot clone singleton object %s', 'CC_Actions'));
+		return;
+	}
 }
 ?>
\ No newline at end of file

Modified: desktop/trunk/lib/window.class.php (49 => 50)


--- desktop/trunk/lib/window.class.php	2006-12-01 21:17:47 UTC (rev 49)
+++ desktop/trunk/lib/window.class.php	2006-12-01 21:18:11 UTC (rev 50)
@@ -41,7 +41,7 @@
 	public $statusbar;
 
 	//----------------------------------------------------------------
-	//             Overrides
+	//             Setup
 	//----------------------------------------------------------------
 
 	/**
@@ -105,6 +105,151 @@
 	}
 
 	//----------------------------------------------------------------
+	//             Building Items
+	//----------------------------------------------------------------
+
+	/**
+	 * protected function buildActions
+	 *
+	 * creates generic window actions
+	 *
+	 * @todo add additional generic actions
+	 * @return void
+	 */
+	protected function buildActions()
+	{
+		$actions = CC_Actions::instance();
+		$this->add_accel_group($actions->get_accel());
+
+		$actions->add_actions('file', array(
+		array(
+			'type' => 'action',
+			'name' => 'quit',
+			'label' => '_Quit',
+			'short-label' => '_Quit',
+			'tooltip' => 'Exit program',
+			'accel' => '<Ctrl>q',
+			'callback' => array($this, 'onQuit'),
+			'image' => 'gtk-quit',
+			),
+		));
+
+		$actions->add_actions('help', array(
+		array(
+			'type' => 'action',
+			'name' => 'help',
+			'label' => '_Help',
+			'short-label' => '_Help',
+			'tooltip' => 'Open help',
+			'accel' => 'F1',
+			'callback' => array($this, 'onHelp'),
+			'image' => 'gtk-help',
+			),
+		array(
+			'type' => 'action',
+			'name' => 'website',
+			'label' => '_Website',
+			'short-label' => '_Website',
+			'tooltip' => 'Visit Callicore website',
+			'callback' => array($this, 'onWebsite'),
+			'image' => 'cc-browser',
+			),
+		array(
+			'type' => 'action',
+			'name' => 'about',
+			'label' => '_About',
+			'short-label' => '_About',
+			'tooltip' => 'About Callicore',
+			'callback' => array($this, 'onAbout'),
+			'image' => 'gtk-about',
+			),
+		));
+
+		$actions->add_actions('toolbar', array(
+		array(
+			'type' => 'toggle',
+			'name' => 'toggle',
+			'label' => '_Show Toolbar',
+			'short-label' => '_Show',
+			'tooltip' => 'Show and hide the toolbar',
+			'callback' => array($this, 'onToolbarToggle'),
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'small',
+			'label' => '_Small Icons',
+			'short-label' => '_Small',
+			'tooltip' => 'Display small icons on the toolbar',
+			'callback' => array($this, 'onSizeToolbar'),
+			'value' => 1,
+			'radio' => 'small',
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'medium',
+			'label' => '_Medium Icons',
+			'short-label' => '_Medium',
+			'tooltip' => 'Display medium icons on the toolbar',
+			'callback' => array($this, 'onSizeToolbar'),
+			'value' => 2,
+			'radio' => 'small',
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'large',
+			'label' => '_Large Icons',
+			'short-label' => '_Large',
+			'tooltip' => 'Display large icons on the toolbar',
+			'callback' => array($this, 'onSizeToolbar'),
+			'value' => 3,
+			'radio' => 'small',
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'icon',
+			'label' => '_Icons',
+			'short-label' => '_Icons',
+			'tooltip' => 'Display only icons on the toolbar',
+			'callback' => array($this, 'onStyleToolbar'),
+			'value' => 1,
+			'radio' => 'icon',
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'text',
+			'label' => '_Text',
+			'short-label' => '_Text',
+			'tooltip' => 'Display only text on the toolbar',
+			'callback' => array($this, 'onStyleToolbar'),
+			'value' => 2,
+			'radio' => 'icon',
+			),
+		array(
+			'type' => 'radio',
+			'name' => 'both',
+			'label' => '_Both',
+			'short-label' => '_Both',
+			'tooltip' => 'Display icons and text on the toolbar',
+			'callback' => array($this, 'onStyleToolbar'),
+			'value' => 3,
+			'radio' => 'icon',
+			),
+		array(
+			'type' => 'action',
+			'name' => 'customize',
+			'label' => '_Customize...',
+			'short-label' => '_Customize',
+			'tooltip' => 'Customize toolbar',
+			'callback' => array($this, 'onCustomize'),
+			'image' => 'gtk-properties',
+			),
+		));
+
+		unset($actions);
+		return;
+	}
+
+	//----------------------------------------------------------------
 	//             Gui Creation
 	//----------------------------------------------------------------