Revision
52
Author
emsmith
Date
2006-12-01 18:07:45 -0800 (Fri, 01 Dec 2006)

Log Message

Toolbars are now building - style and size now work

Modified Paths

Added Paths

Diff

Added: desktop/trunk/lib/toolbar.class.php (51 => 52)


--- desktop/trunk/lib/toolbar.class.php	2006-12-01 21:43:39 UTC (rev 51)
+++ desktop/trunk/lib/toolbar.class.php	2006-12-02 02:07:45 UTC (rev 52)
@@ -0,0 +1,267 @@
+<?php
+/**
+ * toolbar.class.php - extends the gtktoolbar class to add additional features
+ *
+ * adds show/hide signals that will link up to a "show toolbar" action, adds
+ * the ability to change icon size and style type, and adds a customize dialog
+ *
+ * This is released under the GPL, see docs/gpl.txt for details
+ *
+ * @author       Elizabeth Smith <emsmith@callicore.net>
+ * @copyright    Elizabeth Smith (c)2006
+ * @link         http://callicore.net/desktop
+ * @license      http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version      $Id$
+ * @since        Php 5.2.0
+ * @package      callicore
+ * @subpackage   desktop
+ * @category     lib
+ * @filesource
+ */
+
+/**
+ * CC_Toolbar - allows customizable, rememberable toolbars for a window
+ *
+ * manages showing, hiding and customizing a toolbar
+ */
+class CC_Toolbar extends GtkToolbar
+{
+
+	/**
+	 * array of all actions available to put on a toolbar
+	 * @var $options 
+	 */
+	public $options = array();
+
+	/**
+	 * array of items for the current toolbar
+	 * @var $current array
+	 */
+	protected $current = array();
+
+	/**
+	 * default items for window
+	 * @var $default array
+	 */
+	public $default = array();
+
+	/**
+	 * popup menu for the window
+	 * @var $menu object instanceof GtkMenu
+	 */
+	public $menu;
+
+	/**
+	 * public function buildToolbar
+	 *
+	 * takes current settings and recreates the toolbar
+	 *
+	 * @return void
+	 */
+	public function buildToolbar()
+	{
+		$name = $this->name;
+		$config = CC_Config::instance();
+		$actions = CC_Actions::instance();
+
+		$size = isset($config->{$this->name . '_toolbar_size'}) ? (string) $config->{$this->name . '_toolbar_size'} : 'small';
+		$style = isset($config->{$name . '_toolbar_style'}) ? (string) $config->{$name . '_toolbar_style'} : 'icon';
+		$toolitems = $this->current = isset($config->{$name . 'toolbar_items'}) ? $config->{$name . 'toolbar_items'} : $this->default;
+
+		$actions = CC_Actions::instance();
+
+		// Create the popup menu
+		$menu = $this->menu = new GtkMenu();
+
+		$menu->append($actions->create_menu_item('toolbar', 'toggle'));
+
+		$item = new GtkMenuItem(CC_Main::i18n('Toolbar S_tyle'));
+		$menu->add($item);
+		$submenu = new GtkMenu();
+		$item->set_submenu($submenu);
+
+		if($style === 'icon')
+		{
+			$actions->get_action('toolbar', 'icon')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'icon'));
+
+		if($style === 'text')
+		{
+			$actions->get_action('toolbar', 'text')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'text'));
+
+		if($style === 'both')
+		{
+			$actions->get_action('toolbar', 'both')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'both'));
+
+		$item = new GtkMenuItem(CC_Main::i18n('Toolbar Si_ze'));
+		$menu->add($item);
+		$submenu = new GtkMenu();
+		$item->set_submenu($submenu);
+
+		if($size === 'small')
+		{
+			$actions->get_action('toolbar', 'small')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'small'));
+
+		if($size === 'medium')
+		{
+			$actions->get_action('toolbar', 'medium')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'medium'));
+
+		if($size === 'large')
+		{
+			$actions->get_action('toolbar', 'large')->set_active(TRUE);
+		}
+		$submenu->append($actions->create_menu_item('toolbar', 'large'));
+
+		$menu->append(new GtkSeparatorMenuItem());
+
+		$menu->append($actions->create_menu_item('toolbar', 'customize'));
+
+		$menu->show_all();
+
+		$this->set_events($this->get_events() | Gdk::BUTTON_PRESS_MASK);
+		$this->connect('button-press-event', array($this, 'popup'));
+
+		// populate toolbar
+		foreach($toolitems as $item)
+		{
+			if($item === 'separator')
+			{
+				$this->insert(new GtkSeparatorToolItem(), -1);
+			}
+			else
+			{
+				list($group, $name) = explode(':', $item);
+				$this->insert($actions->create_tool_item($group, $name), -1);
+			}
+		}
+		return;
+	}
+
+	/**
+	 * public function doPopup
+	 *
+	 * pops up a popup menu on right click
+	 *
+	 * @param object $window GtkWindow
+	 * @param object $event GdkEvent
+	 * @return void
+	 */
+	public function popup($window, $event)
+	{
+		if($event->button == 3)
+		{
+			$this->menu->popup();
+		}
+		unset($window, $event);
+		return;
+	}
+
+	/**
+	 * public function onToggleToolbar
+	 *
+	 * show-hide toolbar callback
+	 *
+	 * @return void
+	 */
+	public function onToggleToolbar($action)
+	{
+		return;
+		$state = !$this->toolbar->is_visible();
+		$this->toolbar->set_visible($state);
+		CC_Config::instance()->{$this->name . '_show_toolbar'} = $state;
+		if(!is_null($this->statusbar))
+		{
+			$this->statusbar->label->set_label(Writer::i18n('<b>Toolbar visibility changed</b>'));
+		}
+		unset($state);
+		return;
+	}
+
+	/**
+	 * public function onStyleToolbar
+	 *
+	 * change toolbar display type
+	 *
+	 * @return void
+	 */
+	public function onStyleToolbar($action)
+	{
+		$config = CC_Config::instance();
+		switch($action->get_current_value())
+		{
+			case 3:
+			{
+				$config->{$this->name . '_toolbar_style'} = 'both';
+				$this->set_toolbar_style(Gtk::TOOLBAR_BOTH);
+				break;
+			}
+			case 2:
+			{
+				$config->{$this->name . '_toolbar_style'} = 'text';
+				$this->set_toolbar_style(Gtk::TOOLBAR_TEXT);
+				break;
+			}
+			default:
+			{
+				$config->{$this->name . '_toolbar_style'} = 'icon';
+				$this->set_toolbar_style(Gtk::TOOLBAR_ICONS);
+			}
+		}
+		$statusbar = CC_Writer::instance()->statusbar;
+		if(!is_null($statusbar))
+		{
+			$statusbar->label->set_label(CC_Main::i18n('Toolbar style changed'));
+		}
+		unset($config, $action, $statusbar);
+		return;
+	}
+
+	/**
+	 * public function onSizeToolbar
+	 *
+	 * change toolbar icon display size
+	 *
+	 * @return void
+	 */
+	public function onSizeToolbar($action)
+	{
+		$config = CC_Config::instance();
+		switch($action->get_current_value())
+		{
+			case 3:
+			{
+				$config->{$this->name . '_toolbar_size'} = 'large';
+				$this->set_icon_size(CC_Main::$DND);
+				break;
+			}
+			case 2:
+			{
+				$config->{$this->name . '_toolbar_size'} = 'medium';
+				$this->set_icon_size(CC_Main::$LARGE_TOOLBAR);
+				break;
+			}
+			default:
+			{
+				$config->{$this->name . '_toolbar_size'} = 'small';
+				$this->set_icon_size(CC_Main::$BUTTON);
+			}
+		}
+		$statusbar = CC_Writer::instance()->statusbar;
+		if(!is_null($statusbar))
+		{
+			$statusbar->label->set_label(CC_Main::i18n('Toolbar icon size changed'));
+		}
+		unset($config, $action, $statusbar);
+		return;
+	}
+}
+?>
\ No newline at end of file
Property changes on: desktop/trunk/lib/toolbar.class.php
___________________________________________________________________
Name: tsvn:logminsize
   + 15
Name: svn:keywords
   + Id
Name: svn:eol-style
   + LF

Modified: desktop/trunk/lib/window.class.php (51 => 52)


--- desktop/trunk/lib/window.class.php	2006-12-01 21:43:39 UTC (rev 51)
+++ desktop/trunk/lib/window.class.php	2006-12-02 02:07:45 UTC (rev 52)
@@ -41,6 +41,12 @@
 	public $menu;
 
 	/**
+	 * toolbar for the window
+	 * @var $toolbar object instanceof CC_Toolbar
+	 */
+	public $toolbar;
+
+	/**
 	 * status bar for window
 	 * @var $statusbar object instanceof GtkStatusBar
 	 */
@@ -79,14 +85,15 @@
 			$this->move($x, $y);
 		}
 
+		$this->toolbar = new CC_Toolbar();
 		$this->buildActions();
 		$this->buildMenu();
-		//$this->buildToolbar();
+		$this->buildToolbar();
 		$this->buildStatusbar();
 
 		$vbox = $this->vbox = new GtkVBox();
 		$vbox->pack_start($this->menu, 0, 0);
-		//$vbox->pack_start($this->toolbar, 0, 0);
+		$vbox->pack_start($this->toolbar, 0, 0);
 		$vbox->pack_end($this->statusbar, 0, 0);
 		$this->add($vbox);
 
@@ -178,7 +185,7 @@
 			'label' => '_Show Toolbar',
 			'short-label' => '_Show',
 			'tooltip' => 'Show and hide the toolbar',
-			'callback' => array($this, 'onToolbarToggle'),
+			'callback' => array($this->toolbar, 'onToggleToolbar'),
 			),
 		array(
 			'type' => 'radio',
@@ -186,7 +193,7 @@
 			'label' => '_Small Icons',
 			'short-label' => '_Small',
 			'tooltip' => 'Display small icons on the toolbar',
-			'callback' => array($this, 'onSizeToolbar'),
+			'callback' => array($this->toolbar, 'onSizeToolbar'),
 			'value' => 1,
 			'radio' => 'small',
 			),
@@ -196,7 +203,7 @@
 			'label' => '_Medium Icons',
 			'short-label' => '_Medium',
 			'tooltip' => 'Display medium icons on the toolbar',
-			'callback' => array($this, 'onSizeToolbar'),
+			'callback' => array($this->toolbar, 'onSizeToolbar'),
 			'value' => 2,
 			'radio' => 'small',
 			),
@@ -206,7 +213,7 @@
 			'label' => '_Large Icons',
 			'short-label' => '_Large',
 			'tooltip' => 'Display large icons on the toolbar',
-			'callback' => array($this, 'onSizeToolbar'),
+			'callback' => array($this->toolbar, 'onSizeToolbar'),
 			'value' => 3,
 			'radio' => 'small',
 			),
@@ -216,7 +223,7 @@
 			'label' => '_Icons',
 			'short-label' => '_Icons',
 			'tooltip' => 'Display only icons on the toolbar',
-			'callback' => array($this, 'onStyleToolbar'),
+			'callback' => array($this->toolbar, 'onStyleToolbar'),
 			'value' => 1,
 			'radio' => 'icon',
 			),
@@ -226,7 +233,7 @@
 			'label' => '_Text',
 			'short-label' => '_Text',
 			'tooltip' => 'Display only text on the toolbar',
-			'callback' => array($this, 'onStyleToolbar'),
+			'callback' => array($this->toolbar, 'onStyleToolbar'),
 			'value' => 2,
 			'radio' => 'icon',
 			),
@@ -236,7 +243,7 @@
 			'label' => '_Both',
 			'short-label' => '_Both',
 			'tooltip' => 'Display icons and text on the toolbar',
-			'callback' => array($this, 'onStyleToolbar'),
+			'callback' => array($this->toolbar, 'onStyleToolbar'),
 			'value' => 3,
 			'radio' => 'icon',
 			),
@@ -246,7 +253,7 @@
 			'label' => '_Customize...',
 			'short-label' => '_Customize',
 			'tooltip' => 'Customize toolbar',
-			'callback' => array($this, 'onCustomize'),
+			'callback' => array($this->toolbar, 'onCustomize'),
 			'image' => 'gtk-properties',
 			),
 		));
@@ -281,7 +288,7 @@
 
 		$submenu->append($actions->create_menu_item('file', 'quit'));
 
-		$item = new GtkMenuItem(CC_Main::i18n('_Tools'));
+		$item = new GtkMenuItem(CC_Main::i18n('_View'));
 		$menu->add($item);
 		$submenu = new GtkMenu();
 		$item->set_submenu($submenu);
@@ -306,6 +313,28 @@
 	}
 
 	/**
+	 * protected function buildToolbar
+	 *
+	 * set up default and possible actions, and set name for toolbar
+	 *
+	 * @return void
+	 */
+	protected function buildToolbar()
+	{
+		$this->toolbar->default = array('file:quit', 'separator', 'toolbar:toggle',
+			'toolbar:customize');
+
+		$this->toolbar->options = array('separator', 'file:quit', 'help:about',
+			'help:website', 'help:help', 'toolbar:customize', 'toolbar:toggle',
+			'toolbar:icon', 'toolbar:text', 'toolbar: both', 'toolbar:large',
+			'toolbar:medium', 'toolbar:small');
+
+		$this->toolbar->buildToolbar();
+
+		return;
+	}
+
+	/**
 	 * protected function buildStatusbar
 	 *
 	 * build statusbar - gets the label inside and pads it gently (because
@@ -354,83 +383,5 @@
 		$this->destroy();
 		return;
 	}
-
-	/**
-	 * public function styleToolbar
-	 *
-	 * change toolbar display type
-	 *
-	 * @param string $style text|icon|both
-	 * @return void
-	 */
-	public function styleToolbar($style)
-	{
-		$config = Config::instance();
-		switch($style)
-		{
-			case 'both':
-			{
-				$config->{$this->name . '_toolbar_style'} = 'both';
-				$this->toolbar->set_toolbar_style(Gtk::TOOLBAR_BOTH);
-				break;
-			}
-			case 'text':
-			{
-				$config->{$this->name . '_toolbar_style'} = 'text';
-				$this->toolbar->set_toolbar_style(Gtk::TOOLBAR_TEXT);
-				break;
-			}
-			default:
-			{
-				$config->{$this->name . '_toolbar_style'} = 'icon';
-				$this->toolbar->set_toolbar_style(Gtk::TOOLBAR_ICONS);
-			}
-		}
-		if(!is_null($this->statusbar))
-		{
-			$this->statusbar->label->set_label(CC_Main::i18n('Toolbar style changed'));
-		}
-		unset($config, $style);
-		return;
-	}
-
-	/**
-	 * public function sizeToolbar
-	 *
-	 * change toolbar icon display size
-	 *
-	 * @param int $size icon size to change toolbar to
-	 * @return void
-	 */
-	public function sizeToolbar($size)
-	{
-		$config = Config::instance();
-		switch($size)
-		{
-			case 'large':
-			{
-				$config->{$this->name . '_toolbar_size'} = 'large';
-				$this->toolbar->set_icon_size(Writer::$DND);
-				break;
-			}
-			case 'medium':
-			{
-				$config->{$this->name . '_toolbar_size'} = 'medium';
-				$this->toolbar->set_icon_size(Writer::$LARGE_TOOLBAR);
-				break;
-			}
-			default:
-			{
-				$config->{$this->name . '_toolbar_size'} = 'small';
-				$this->toolbar->set_icon_size(Writer::$BUTTON);
-			}
-		}
-		if(!is_null($this->statusbar))
-		{
-			$this->statusbar->label->set_label(Writer::i18n('<b>Toolbar icon size changed</b>'));
-		}
-		unset($config, $size);
-		return;
-	}
 }
 ?>
\ No newline at end of file

Modified: desktop/trunk/programs/writer/lib/writer.class.php (51 => 52)


--- desktop/trunk/programs/writer/lib/writer.class.php	2006-12-01 21:43:39 UTC (rev 51)
+++ desktop/trunk/programs/writer/lib/writer.class.php	2006-12-02 02:07:45 UTC (rev 52)
@@ -368,6 +368,31 @@
 		return;
 	}
 
+	/**
+	 * protected function buildToolbar
+	 *
+	 * set up default and possible actions, and set name for toolbar
+	 *
+	 * @return void
+	 */
+	protected function buildToolbar()
+	{
+		$this->toolbar->default = array('file:new', 'file:delete', 'file:save',
+			'separator', 'manage:import', 'manage:export', 'separator',
+			'file:print', 'manage:properties');
+
+		$this->toolbar->options = array('separator', 'file:new', 'file:open',
+			'file:close','file:delete', 'file:save', 'file:saveas',
+			'file:revert', 'file:print', 'file:quit','manage:wizard',
+			'manage:import', 'manage:export', 'manage:properties',
+			'tools:characters', 'tools:places', 'tools:notes', 'tools:preferences',
+			'help:help', 'help:website', 'help:about');
+
+		$this->toolbar->buildToolbar();
+
+		return;
+	}
+
 	//----------------------------------------------------------------
 	//             Callbacks
 	//----------------------------------------------------------------