Diff
Copied: desktop/trunk/lib/actions.class.php (from rev 40, desktop/trunk/programs/writer/lib/actions.class.php) (40 => 42)
--- desktop/trunk/programs/writer/lib/actions.class.php 2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/actions.class.php 2006-12-01 17:55:54 UTC (rev 42)
@@ -0,0 +1,209 @@
+<?php
+/**
+ * actions.class.php - container for gtkactions & gtkactiongroups
+ *
+ * manages all actions and actiongroups
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author Elizabeth Smith <emsmith@callicore.net>
+ * @copyright Elizabeth Smith (c)2006
+ * @link http://callicore.net/writer
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version $Id$
+ * @since Php 5.2.0
+ * @package callicore
+ * @subpackage writer
+ * @category lib
+ * @filesource
+ */
+
+/**
+ * Actions - actions/actiongroups map
+ *
+ * fixes the weirdness of tooltips, andd generally makes managing actions easier
+ */
+class CC_Actions
+{
+
+ /**
+ * list of all current created action groups
+ * @var $groups array
+ */
+ protected $groups = array();
+
+ /**
+ * global accelerator container for actions
+ * @var $accel instanceof GtkAccelGroup
+ */
+ protected $accel;
+
+ /**
+ * public function __construct
+ *
+ * sets up the global accelgroup
+ *
+ * @return void
+ */
+ public function __construct()
+ {
+ $this->accel = new GtkAccelGroup();
+ return;
+ }
+
+ /**
+ * public function get_accel
+ *
+ * returns GtkAccelGroup instance, use this to set it in the right window
+ *
+ * @return object instanceof GtkAccelGroup
+ */
+ public function get_accel()
+ {
+ return $this->accel;
+ }
+
+ /**
+ * public function create_menu_item
+ *
+ * uses get_group to fetch the action group specified
+ * uses get_action to fetch the action specified
+ * creates a menu item and sets a tooltip for the action
+ *
+ * @param string $group name of action group to get
+ * @param string $action name of action to get
+ * @return object instanceof GtkMenuItem
+ */
+ public function create_menu_item($group, $action)
+ {
+ $tips = CC_Tooltips::instance();
+ $action = $this->get_action($group, $action);
+ $widget = $action->create_menu_item();
+ $tips->set_tip($widget, $action->get_property('tooltip'));
+ unset($action, $group, $tips);
+ return $widget;
+ }
+
+ /**
+ * public function create_tool_item
+ *
+ * uses get_group to fetch the action group specified
+ * uses get_action to fetch the action specified
+ * creates a toolbar item and sets a tooltip for the action
+ *
+ * @param string $group name of action group to get
+ * @param string $action name of action to get
+ * @return object instanceof GtkToolItem
+ */
+ public function create_tool_item($group, $action)
+ {
+ $tips = CC_Tooltips::instance();
+ $action = $this->get_action($group, $action);
+ $widget = $action->create_tool_item();
+ $tips->set_tip($widget, $action->get_property('tooltip'));
+ unset($action, $group, $tips);
+ return $widget;
+ }
+
+ /**
+ * public function get_group
+ *
+ * returns action group
+ *
+ * @param string $group name of action group to get
+ * @return instanceof GtkActionGroup
+ */
+ public function get_group($group)
+ {
+ return isset($this->groups[$group]) ? $this->groups[$group] : NULL;
+ }
+
+ /**
+ * public function get_action
+ *
+ * returns an action from a group (shortcut)
+ *
+ * @param string $group name of action group to get
+ * @param string $action name of action to get
+ * @return instanceof GtkAction
+ */
+ public function get_action($group, $action)
+ {
+ return $this->get_group($group)->get_action($action);
+ }
+
+ /**
+ * public function add_group
+ *
+ * adds a new group with the specific name
+ *
+ * @param string $group group to create
+ * @return void
+ */
+ public function add_group($group)
+ {
+ $this->groups[$group] = new GtkActionGroup($group);
+ unset($group);
+ return;
+ }
+
+ /**
+ * public function add_actions
+ *
+ * adds actions to a specific group (shortcut)
+ * definition is array(
+ * 'type' => action|toggle|radio,
+ * 'callback' => php callback,
+ * 'accel' => accelerator string to use,
+ * 'name' => internal name for action,
+ * 'label' => label,
+ * 'short-label' => shorter label (for toolbar),
+ * 'tooltip' => tooltip for the action,
+ * 'image' => stock id or named image),
+ * 'value' => value for radio action,
+ * 'radio' => for radio items, the name of the action to group with
+ * );
+ *
+ *
+ * @param string $group group to add to
+ * @param array $definitions array of action definitions
+ * @return void
+ */
+ public function add_actions($group, $definitions)
+ {
+ if(!isset($this->groups[$group]))
+ {
+ $this->add_group($group);
+ }
+ $group = $this->get_group($group);
+ foreach($definitions as $def)
+ {
+ 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']));
+ break;
+ case 'toggle':
+ $action = new GtkToggleAction($def['name'], CC_Main::i18n($def['label']), CC_Main::i18n($def['tooltip']),$def['image']);
+ break;
+ default:
+ $action = new GtkAction($def['name'], CC_Main::i18n($def['label']), CC_Main::i18n($def['tooltip']),$def['image']);
+ }
+ $action->set_property('short-label', isset($def['short-label']) ? CC_Main::i18n($def['short-label']) : NULL);
+ $action->connect($callback);
+ if(isset($def['accel']))
+ {
+ $action->set_accel_group($this->accel);
+ $group->add_action_with_accel($action, $def['accel']);
+ }
+ else
+ {
+ $group->add_action($action);
+ }
+ }
+ unset($def, $definitions, $group, $action, $this);
+ return;
+ }
+}
+?>
\ No newline at end of file
Modified: desktop/trunk/lib/folders.class.php (41 => 42)
--- desktop/trunk/lib/folders.class.php 2006-12-01 16:47:06 UTC (rev 41)
+++ desktop/trunk/lib/folders.class.php 2006-12-01 17:55:54 UTC (rev 42)
@@ -62,9 +62,9 @@
const KDE = 7;
/**
- * @const OTHER (unknown) Desktop
+ * @const unknown Desktop/OS
*/
- const OTHER = 8;
+ const UNKNOWN = 8;
/**
* singleton instance for this class
Copied: desktop/trunk/lib/message.class.php (from rev 40, desktop/trunk/programs/writer/lib/message.class.php) (40 => 42)
--- desktop/trunk/programs/writer/lib/message.class.php 2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/message.class.php 2006-12-01 17:55:54 UTC (rev 42)
@@ -0,0 +1,208 @@
+<?php
+/**
+ * message.class.php - Generic Messag Dialogs
+ *
+ * wraps the gtkmessagedialog class and provides pretty gtk dialog box
+ * php error/exception handling
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author Elizabeth Smith <emsmith@callicore.net>
+ * @copyright Elizabeth Smith (c)2006
+ * @link http://callicore.net/writer
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version $Id$
+ * @since Php 5.2.0
+ * @package callicore
+ * @subpackage writer
+ * @category lib
+ * @filesource
+ */
+
+/**
+ * CC_Message - creates pretty message boxes
+ *
+ * wrapper class for any errors with handlers, can also be used
+ * for generic messages
+ *
+ * TODO: add expander with treeview of trace information
+ */
+class CC_Message extends GtkMessageDialog
+{
+ /**
+ * @const ERROR error message box
+ */
+ const ERROR = Gtk::MESSAGE_ERROR;
+
+ /**
+ * @const WARNING warning message box
+ */
+ const WARNING = Gtk::MESSAGE_WARNING;
+
+ /**
+ * @const INFO information message box
+ */
+ const INFO = Gtk::MESSAGE_INFO;
+
+ /**
+ * @const QUESTION information message box
+ */
+ const QUESTION = Gtk::MESSAGE_QUESTION;
+
+ /**
+ * static - pretty print names for constants
+ * @var $protected array
+ */
+ static protected $messages = array(
+ self::ERROR => 'ERROR',
+ self::WARNING => 'WARNING',
+ self::INFO => 'INFO',
+ );
+
+ /**
+ * public function __construct
+ *
+ * description
+ *
+ * @param string $message text to display in upper area
+ * @param string $title text to display as dialog title
+ * @param int $type one of self::INFO, self::WARNING, self::ERROR
+ * @return void
+ */
+ public function __construct($message, $title = 'Default Message', $type = self::INFO, $program = 'Callicore')
+ {
+ if($type !== self::ERROR && $type !== self::WARNING && $type !== self::QUESTION)
+ {
+ $type = self::INFO;
+ }
+
+ parent::__construct(NULL, 0, $type, Gtk::BUTTONS_CLOSE);
+ $this->set_position(Gtk::WIN_POS_CENTER);
+ $this->set_title(CC_Main::i18n('%s : %s', $program, $title));
+ if(is_array($message))
+ {
+ $this->set_markup(CC_Main::i18n(array_shift($message), $message));
+ }
+ else
+ {
+ $this->set_markup(CC_Main::i18n($message));
+ }
+
+ unset($message, $title, $type, $program);
+ return;
+ }
+
+ /**
+ * public function parent
+ *
+ * although the message may be triggered by an error handler
+ * manual messages may wish to set a parent window
+ *
+ * @param object instanceof GtkWindow $parent GtkWindow object parent
+ * @return void
+ */
+ public function parent($parent)
+ {
+ $this->set_transient_for($parent);
+ $this->set_destroy_with_parent(TRUE);
+ unset($parent);
+ return;
+ }
+
+ /**
+ * static public function error
+ *
+ * error handler - changes php error into message dialog and logs it
+ *
+ * @param int $code error code
+ * @param string $message text for error
+ * @param string $file file where error occured
+ * @param int $line line where error occured
+ * @return void
+ */
+ static public function error($code, $message, $file, $line)
+ {
+ switch($code)
+ {
+ case(E_STRICT):
+ case(E_NOTICE):
+ case(E_USER_NOTICE):
+ {
+ $level = self::INFO;
+ $title = 'Information';
+ $text = '<b><big>An Information Notice has been Detected</big></b>'
+ . "\n" . '<i>The following Information has been detected and logged :</i>'
+ . "\n$message\n" . 'The application will now continue.';
+ break;
+ }
+ case(E_WARNING):
+ case(E_USER_WARNING):
+ {
+ $level = self::WARNING;
+ $title = 'Warning';
+ $text = '<b><big>A Warning has been Detected</big></b>'
+ . "\n" . '<i>The following Warning has been detected and logged :</i>'
+ . "\n$message\n" . 'The application will now continue.';
+ break;
+ }
+ default:
+ {
+ $level = self::ERROR;
+ $title = 'Error';
+ $text = '<b><big>An Error has been Detected</big></b>'
+ . "\n" . '<i>The following Error has been detected and logged :</i>'
+ . "\n$message\n" . 'The application will now terminate.';
+ }
+ }
+ self::log($level, "$message: $code FILE: $file - LINE $line");
+ $win = new CC_Message($text, $title, $level);
+ $win->run();
+ $win->destroy();
+ if($level == self::ERROR)
+ {
+ exit;
+ }
+ unset($code, $message, $file, $line, $level, $title, $win, $text);
+ return;
+ }
+
+ /**
+ * static public function exception
+ *
+ * last ditch exception handler grabs exception data and passes
+ * it to the error handler
+ *
+ * @param object $e instanceof Exception
+ * @return void
+ */
+ static public function exception($e)
+ {
+ self::error(Gtk::MESSAGE_ERROR, $e->getMessage(), $e->getFile(), $e->getLine());
+ unset($e);
+ return;
+ }
+
+ /**
+ * static protected function log
+ *
+ * writes to the error log, useful for debugging
+ *
+ * @param int $level one of self::INFO, self::WARNING, self::ERROR
+ * @param string $message message to log
+ * @return void
+ */
+ static protected function log($level, $message)
+ {
+ $folders = CC_Folders::instance();
+ $log = $folders->getAppdata() . 'error.log';
+ if(file_exists($log) && filesize($log) > 536870912)
+ {
+ rename($log, $folders->getAppdata() . date('Y-m-d') . 'error.log.bak');
+ }
+ file_put_contents($log, self::$messages[$level] . ' ' . date('Y-m-d H:i:s')
+ . ' --> ' . $message . EOL, FILE_APPEND);
+ unset($log, $level, $message, $folders);
+ return;
+ }
+}
+?>
\ No newline at end of file
Copied: desktop/trunk/lib/tooltips.class.php (from rev 40, desktop/trunk/programs/writer/lib/tooltips.class.php) (40 => 42)
--- desktop/trunk/programs/writer/lib/tooltips.class.php 2006-11-30 20:05:37 UTC (rev 40)
+++ desktop/trunk/lib/tooltips.class.php 2006-12-01 17:55:54 UTC (rev 42)
@@ -0,0 +1,108 @@
+<?php
+/**
+ * tooltips.class.php - wrapper for gtktooltips
+ *
+ * fixes tooltips for toolbar and forces singleton
+ *
+ * This is released under the GPL, see license.txt for details
+ *
+ * @author Elizabeth Smith <emsmith@callicore.net>
+ * @copyright Elizabeth Smith (c)2006
+ * @link http://callicore.net/writer
+ * @license http://www.opensource.org/licenses/gpl-license.php GPL
+ * @version $Id$
+ * @since Php 5.2.0
+ * @package callicore
+ * @subpackage writer
+ * @category lib
+ * @filesource
+ */
+
+/**
+ * CC_Tooltips - tooltips wrapper
+ *
+ * fixes the weirdness of toolbar tooltips
+ */
+class CC_Tooltips extends GtkTooltips
+{
+
+ /**
+ * singleton instance for this class
+ * @var $singleton instanceof Tooltips
+ */
+ static protected $singleton;
+
+ /**
+ * public function __construct
+ *
+ * sets delay and enables tooltips
+ *
+ * @return void
+ */
+ 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_Tooltips'));
+ }
+ self::$singleton = $this;
+
+ parent::__construct();
+ $this->enable();
+ return;
+ }
+
+ /**
+ * public function set_tip
+ *
+ * overrides original function for GtkToolItem fix
+ *
+ * @param object $wiget instanceof GtkObject
+ * @return void
+ */
+ public function set_tip($widget, $tooltip)
+ {
+ if($widget instanceof GtkToolItem)
+ {
+ $widget->set_tooltip($this, $tooltip);
+ }
+ else
+ {
+ parent::set_tip($widget, $tooltip);
+ }
+ unset($widget, $tooltip);
+ return;
+ }
+
+ /**
+ * static public function instance
+ *
+ * this is how items can access the tooltips
+ *
+ * @return object instanceof CC_Tooltips
+ */
+ static public function instance()
+ {
+ if(is_null(self::$singleton))
+ {
+ self::$singleton = new CC_Tooltips();
+ }
+ 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_Tooltips'));
+ return;
+ }
+}
+?>
\ No newline at end of file
Modified: desktop/trunk/lib/window.class.php (41 => 42)
--- desktop/trunk/lib/window.class.php 2006-12-01 16:47:06 UTC (rev 41)
+++ desktop/trunk/lib/window.class.php 2006-12-01 17:55:54 UTC (rev 42)
@@ -56,7 +56,7 @@
parent::__construct();
- $config = Config::instance();
+ $config = CC_Config::instance();
$this->set_name(strtolower(get_class($this)));
$name = $this->name;
@@ -98,8 +98,8 @@
*/
public function set_title($title, $program = 'Callicore')
{
- parent::set_title(CC_Main::i18n('%s :: %s', $class, $title));
- unset($title, $class);
+ parent::set_title(CC_Main::i18n('%s :: %s', $program, $title));
+ unset($title, $program);
return;
}