Revision
44
Author
emsmith
Date
2006-12-01 10:45:58 -0800 (Fri, 01 Dec 2006)

Log Message

slowly getting the rearranging complete

Modified Paths

Removed Paths

Diff

Deleted: desktop/trunk/programs/writer/lib/actions.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/actions.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/actions.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,210 +0,0 @@
-<?php
-/**
- * actions.class.php - container for gtkactions & gtkactiongroups
- *
- * sets up actions and actiongroups "on demand"
- *
- * 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 toolbar tooltips, adds help tooltip support
- * and generally makes managing actions easier
- */
-class 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)
-	{
-		$action = $this->get_action($group, $action);
-		$widget = $action->create_menu_item();
-		Writer::$tooltips->set_tip($widget, $action->get_property('tooltip'), $action->get_data('help-tooltip'));
-		unset($action, $group);
-		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)
-	{
-		$action = $this->get_action($group, $action);
-		$widget = $action->create_tool_item();
-		Writer::$tooltips->set_tip($widget, $action->get_property('tooltip'), $action->get_data('help-tooltip'));
-		unset($action, $group);
-		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 (isset($this->groups[$group]) && isset($this->groups[$group][$action])) ? $this->groups[$group][$action] : NULL;
-	}
-
-	/**
-	 * 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,
-	 * 'help-tooltip' => help 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'], Writer::i18n($def['label']), Writer::i18n($def['tooltip']),$def['image'],$def['value']);
-					$action->set_group($group->get_action($def['radio']));
-					break;
-				case 'toggle':
-					$action = new GtkToggleAction($def['name'], Writer::i18n($def['label']), Writer::i18n($def['tooltip']),$def['image']);
-					break;
-				default:
-					$action = new GtkAction($def['name'], Writer::i18n($def['label']), Writer::i18n($def['tooltip']),$def['image']);
-			}
-			$action->set_data('help-tooltip', isset($def['help-tooltip']) ? Writer::i18n($def['help-tooltip']) : NULL);
-			$action->set_property('short-label', isset($def['short-label']) ? Writer::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

Deleted: desktop/trunk/programs/writer/lib/config.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/config.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/config.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,149 +0,0 @@
-<?php
-/**
- * config.class.php - Writer configuration and preferences
- *
- * user configuration for writer is stored in Writer::$appdata/config.ini
- *
- * 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
- */
-
-/**
- * Config - reads in an ini file to get configuration settings
- *
- * Writes out to file when a configuration option is changed
- * right now the whole file is rewritten - that may change in the future
- */
-class Config
-{
-	/**
-	 * multi-dim array of current configuration information
-	 * @var $data array
-	 */
-	protected $data;
-
-	/**
-	 * public function __construct
-	 *
-	 * Will load in a current config file and optionally create a new one
-	 *
-	 * @return void
-	 */
-	public function __construct()
-	{
-		if(file_exists(Writer::appdata() . 'config.ini'))
-		{
-			$this->data = parse_ini_file(Writer::appdata() . 'config.ini');
-		}
-		else
-		{
-			$this->data = array();
-			$this->writeFile();
-		}
-		return;
-	}
-
-	/**
-	 * public function __get
-	 *
-	 * gets item from data store
-	 *
-	 * @param string $name
-	 * @return mixed
-	 */
-	protected function __get($name)
-	{
-		if(isset($this->data[$name]))
-		{
-			return $this->data[$name];
-		}
-		return;
-	}
-
-	/**
-	 * public function __isset
-	 *
-	 * checks if item is set in data store
-	 *
-	 * @param string $name
-	 * @return mixed
-	 */
-	protected function __isset($name)
-	{
-		return isset($this->data[$name]);
-	}
-
-	/**
-	 * public function __set
-	 *
-	 * sets an item in the data store and writes out the file
-	 *
-	 * @param string $name
-	 * @param mixed $value
-	 * @return void
-	 */
-	protected function __set($name, $value)
-	{
-		$this->data[$name] = $value;
-		$this->writeFile();
-		unset($name, $value);
-		return;
-	}
-
-	/**
-	 * public function __unset
-	 *
-	 * removes item from the data store and writes out the file
-	 *
-	 * @param string $name
-	 * @return void
-	 */
-	protected function __unset($name)
-	{
-		unset($this->data[$name]);
-		$this->writeFile();
-		unset($name);
-		return;
-	}
-
-	protected function writeFile()
-	{
-		$string = ';Preferences and Configuration for Writer ' . Writer::VERSION
-			. EOL . '; Saved ' . date('Y-m-d H:i:s') . EOL . EOL;
-		foreach($this->data as $key => $value)
-		{
-			if(is_array($value))
-			{
-				$key = preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key) . '[]';
-				foreach($value as $subvalue)
-				{
-					$string .= $key . ' = "' . str_replace('"', '', $subvalue) . '"' . EOL;
-				}
-			}
-			elseif(is_bool($value))
-			{
-				$string .= preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key)
-					. ' = ' . (($value == TRUE) ? 'TRUE' : 'FALSE') . EOL;
-			}
-			else
-			{
-				$string .= preg_replace('/[' . preg_quote('{}|&~![()"') . ']/', '', $key)
-					. ' = "' . str_replace('"', '', $value) . '"' . EOL;
-			}
-		}
-		file_put_contents(Writer::appdata() . 'config.ini', $string);
-		unset($string, $subvalue, $key, $value);
-		return;
-	}
-}
-?>
\ No newline at end of file

Deleted: desktop/trunk/programs/writer/lib/message.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/message.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/message.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,207 +0,0 @@
-<?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
- */
-
-/**
- * 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 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)
-	{
-		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(Writer::i18n('%s : %s', 'Writer', $title));
-		if(is_array($message))
-		{
-			$this->set_markup(Writer::i18n(array_shift($message), $message));
-		}
-		else
-		{
-			$this->set_markup(Writer::i18n($message));
-		}
-
-		unset($message, $title, $type);
-		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 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)
-	{
-		$log = Writer::appdata() . 'error.log';
-		if(file_exists($log) && filesize($log) > 536870912)
-		{
-			rename($log, Writer::appdata() . 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);
-		return;
-	}
-}
-?>
\ No newline at end of file

Deleted: desktop/trunk/programs/writer/lib/splash.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/splash.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/splash.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,138 +0,0 @@
-<?php
-/**
- * splash.class.php - Splash screen display window
- *
- * creates, displays, updates progress bar on splash screen during startup
- *
- * 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
- */
-
-/**
- * Splash - basically a wrapper around GtkWindow
- *
- * Sets up a window with a pretty image backdrop and
- * basic information about what is happening during setup
- */
-class Splash extends GtkWindow
-{
-
-	/**
-	 * progressbar object reference for easy updating
-	 * @var $progressbar object instanceof GtkProgressBar
-	 */
-	protected $progressbar;
-
-	/**
-	 * total startup steps - needed for incrementing progressbar
-	 * @var $steps int
-	 */
-	protected $steps;
-
-	/**
-	 * public function __construct
-	 *
-	 * creates and displays the splash window
-	 * and all the widgets it contains
-	 *
-	 * @return void
-	 */
-	public function __construct($steps)
-	{
-
-		$this->steps = (int) $steps;
-		// Window Features
-		parent::__construct();
-		$this->set_position(Gtk::WIN_POS_CENTER);
-		$this->set_title(Writer::i18n('%s :: %s', 'Writer', 'Loading'));
-		$this->set_resizable(FALSE);
-		$this->set_decorated(FALSE);
-		$this->set_skip_taskbar_hint(TRUE);
-		$this->set_skip_pager_hint(TRUE);
-		$this->set_type_hint(Gdk::WINDOW_TYPE_HINT_SPLASHSCREEN);
-
-		// Pixbuf for Back
-		$pixbuf = GdkPixbuf::new_from_file(DIR . 'images' . DS . 'splash.png');
-		list($pixmap, $mask) = $pixbuf->render_pixmap_and_mask();
-		list($width, $height) = $pixmap->get_size();
-		$this->set_app_paintable(TRUE);
-		$this->set_size_request($width, $height);
-		$this->realize();
-		$this->window->set_back_pixmap($pixmap, FALSE);
-		unset($pixbuf, $pixmap, $mask, $width, $height);
-
-		// Main VBox Container
-		$vbox = new GtkVbox();
-		$vbox->set_border_width(10);
-		$this->add($vbox);
-
-		// Top Bar with Copyright and Version information
-		$hbox = new GtkHBox();
-		$hbox->pack_start(new GtkLabel(Writer::i18n('Copyright (c) E. M. Smith 2006')), FALSE, FALSE);
-		$hbox->pack_end(new GtkLabel(Writer::i18n('version ' . WRITER::VERSION)), FALSE, FALSE);
-		$vbox->pack_start($hbox, FALSE, FALSE);
-
-		// Progressbar on Bottom
-		$this->progressbar = new GtkProgressBar();
-		$this->progressbar->set_text(Writer::i18n('Loading...'));
-		$this->progressbar->set_fraction(0);
-		$vbox->pack_end($this->progressbar, FALSE, FALSE);
-
-		// License info just above progressbar
-		$hbox = new GtkHBox();
-		$hbox->pack_start(new GtkLabel(Writer::i18n('Released under GPL License')), FALSE, FALSE);
-		$vbox->pack_end($hbox, FALSE, FALSE);
-
-		unset($vbox, $hbox);
-
-		$this->show_all();
-		return;
-	}
-
-	/**
-	 * public function parent
-	 *
-	 * although the splashscreen is created first,
-	 * it changes to a transient for the main window
-	 * so we use this to set that relationship
-	 *
-	 * @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;
-	}
-
-	/**
-	 * public function update
-	 *
-	 * update the progressbar text and position
-	 *
-	 * @param string $text text to fill
-	 * @return type about
-	 */
-	public function update($text)
-	{
-		$this->progressbar->set_text(Writer::i18n($text));
-		$this->progressbar->set_fraction($this->progressbar->get_fraction() + (1 / $this->steps));
-		unset($text);
-		while (Gtk::events_pending())
-		Gtk::main_iteration();
-		return;
-	}
-}
-?>
\ No newline at end of file

Deleted: desktop/trunk/programs/writer/lib/tooltips.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/tooltips.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/tooltips.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,66 +0,0 @@
-<?php
-/**
- * tooltips.class.php - wrapper for gtktooltips
- *
- * fixes tooltips for toolbar
- *
- * 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
- */
-
-/**
- * Tooltips - tooltips wrapper
- *
- * fixes the weirdness of toolbar tooltips
- */
-class Tooltips extends GtkTooltips
-{
-
-	/**
-	 * public function __construct
-	 *
-	 * sets delay and enables tooltips
-	 *
-	 * @return void
-	 */
-	public function __construct()
-	{
-
-		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, $help = NULL)
-	{
-		if($widget instanceof GtkToolItem)
-		{
-			$widget->set_tooltip($this, $tooltip, $help);
-		}
-		else
-		{
-			parent::set_tip($widget, $tooltip, $help);
-		}
-		unset($widget, $tooltip, $help);
-		return;
-	}
-}
-?>
\ No newline at end of file

Deleted: desktop/trunk/programs/writer/lib/window.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/window.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/window.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,161 +0,0 @@
-<?php
-/**
- * window.class.php - window abstract class
- *
- * writer general purpose window code, handles menubar, toolbar and statusbar
- * setup as well as general actions and other items
- *
- * 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
- */
-
-/**
- * Window - basic window with menu, toolbar, status bar automagically created
- *
- * Streamlines creation of similiar windows and callbacks
- */
-abstract class Window extends GtkWindow
-{
-
-	/**
-	 * main vbox for window
-	 * @var $vbox object instanceof GtkVBox
-	 */
-	public $vbox;
-
-	/**
-	 * status bar for window
-	 * @var $statusbar object instanceof GtkStatusBar
-	 */
-	public $statusbar;
-
-	//----------------------------------------------------------------
-	//             Overrides
-	//----------------------------------------------------------------
-
-	/**
-	 * public function __construct
-	 *
-	 * Create a new CharacterWindow instance and build internal gui items
-	 *
-	 * @return void
-	 */
-	public function __construct()
-	{
-
-		parent::__construct();
-
-		$config = Writer::$config;
-
-		$this->set_name(strtolower(get_class($this)));
-		$name = $this->name;
-
-		// default size and location
-		$width = isset($config->{$name . '_height'}) ? (int) $config->{$name . '_height'} : 800;
-		$height = isset($config->{$name . '_width'}) ? (int) $config->{$name . '_width'} : 600;
-		$this->set_default_size($width, $height);
-
-		$x = isset($config->{$name . '_x'}) ? (int) $config->{$name . '_x'} : NULL;
-		$y = isset($config->{$name . '_y'}) ? (int) $config->{$name . '_y'} : NULL;
-		if(!is_null($x) && !is_null($y))
-		{
-			$this->move($x, $y);
-		}
-
-		//$this->buildActions();
-		//$this->buildMenu();
-		//$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_end($this->statusbar, 0, 0);
-		$this->add($vbox);
-
-		unset($config, $height, $width, $x, $y, $name, $vbox, $this);
-		return;
-	}
-
-	/**
-	 * public function set_title
-	 *
-	 * overload set_title
-	 *
-	 * @param string $name title to set
-	 * @return void
-	 */
-	public function set_title($title, $class = NULL)
-	{
-		if(is_null($class))
-		{
-			$class = ucfirst(str_replace('window', '', $this->name));
-		}
-		parent::set_title(Writer::i18n('%s :: %s :: %s', 'Writer', $class, $title));
-		unset($title, $class);
-		return;
-	}
-
-	//----------------------------------------------------------------
-	//             Gui Creation
-	//----------------------------------------------------------------
-
-	/**
-	 * protected function buildStatusbar
-	 *
-	 * build statusbar
-	 *
-	 * @return void
-	 */
-	protected function buildStatusbar()
-	{
-		$status = $this->statusbar = new GtkStatusBar();
-		$children = $status->get_children();
-		$status->label = $children[0]->child;
-		$status->label->set_padding(3, 0);
-		$status->label->set_label(Writer::i18n('Ready'));
-		$status->label->set_use_markup(TRUE);
-		unset($status, $children);
-		return;
-	}
-
-	//----------------------------------------------------------------
-	//             Callbacks
-	//----------------------------------------------------------------
-
-	/**
-	 * public function onDeleteEvent
-	 *
-	 * callback for delete-event, saves window size and position
-	 *
-	 * @return void
-	 */
-	public function onDeleteEvent()
-	{
-		$name = $this->name;
-		$config = Writer::$config;
-
-		list($height, $width) = $this->get_size();
-		$config->{$name . '_height'} = $height;
-		$config->{$name . '_width'} = $width;
-
-		list($x, $y) = $this->get_position();
-		$config->{$name . '_x'} = $x;
-		$config->{$name . '_y'} = $y;
-
-		unset($config, $height, $width, $x, $y, $name);
-		$this->destroy();
-		return;
-	}
-}
-?>
\ No newline at end of file

Modified: desktop/trunk/programs/writer/lib/writer.class.php (43 => 44)


--- desktop/trunk/programs/writer/lib/writer.class.php	2006-12-01 18:44:59 UTC (rev 43)
+++ desktop/trunk/programs/writer/lib/writer.class.php	2006-12-01 18:45:58 UTC (rev 44)
@@ -1,9 +1,9 @@
 <?php
 /**
- * writer.class.php - Main class for the writer program
+ * writer.class.php - Main window for the writer program
  *
- * sets up the basic interface, handles loading of settings
- * and other information
+ * main window for the application, opens up last used project or creates a new
+ * blank project if no "last" is available to use
  *
  * This is released under the GPL, see license.txt for details
  *
@@ -20,11 +20,11 @@
  */
 
 /**
- * Writer - checks settings and manages common properties
+ * CC_Writer - checks settings and manages common properties
  *
  * Basically a wrapper class for the application
  */
-class Writer
+class CC_Writer extends CC_Window
 {
 	/**
 	 * @const VERSION app version number
@@ -32,48 +32,12 @@
 	const VERSION = '1.0.0-alpha';
 
 	/**
-	 * you can grab and manipulate everything from here
-	 * @var $window instanceof ProjectWindow (GtkWindow)
+	 * singleton instance for this class
+	 * @var $singleton instanceof Tooltips
 	 */
-	static public $window;
+	static protected $singleton;
 
 	/**
-	 * you can grab and manipulate everything from here
-	 * @var $window instanceof Tooltips (GtkTooltips)
-	 */
-	static public $tooltips;
-
-	/**
-	 * all actions for application are stored here
-	 * @var $window instanceof Actions
-	 */
-	static public $actions;
-
-	/**
-	 * application configuration
-	 * @var $config instanceof Config
-	 */
-	static public $config;
-
-	/**
-	 * Icon sizes - these SHOULD be constants - but
-	 * you can't set class constants after the class is defined
-	 * so they're static vars instead - annoying
-	 *
-	 * sizes are 16, 18, 20, 14, 32, 48, 64 and 128 px square
-	 *
-	 * @var GtkEnum
-	 */
-	static public $MENU = Gtk::ICON_SIZE_MENU;
-	static public $SMALL_TOOLBAR = Gtk::ICON_SIZE_SMALL_TOOLBAR;
-	static public $BUTTON = Gtk::ICON_SIZE_BUTTON;
-	static public $LARGE_TOOLBAR = Gtk::ICON_SIZE_LARGE_TOOLBAR;
-	static public $DND = Gtk::ICON_SIZE_DND;
-	static public $DIALOG = Gtk::ICON_SIZE_DIALOG;
-	static public $LARGE;
-	static public $IMAGE;
-
-	/**
 	 * public function __construct
 	 *
 	 * checks for requirements, runs the splash screen,
@@ -84,240 +48,70 @@
 	 */
 	public function __construct()
 	{
-		$this->checkRequirements();
 
-		$splash = new Splash(7);
+		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;
+
+		$splash = new CC_Splash(7, 'Writer');
+		$splash->setImage(DIR . 'programs' . DS . 'writer' . DS . 'images' . DS . 'splash.png');
+		$splash->setCopyright('Copyright (c) E. M. Smith 2006');
+		$splash->setVersion('version ' . self::VERSION);
+		$splash->setLicense('Released under GPL License');
+		$splash->show_all();
+
 		$splash->update('Checking Requirements');
 
 		$splash->update('Initializing Messages');
-		set_error_handler(array('Message', 'error'));
-		set_exception_handler(array('Message', 'exception'));
+		set_error_handler(array('CC_Message', 'error'));
+		set_exception_handler(array('CC_Message', 'exception'));
 
-		$splash->update('Initializing Theme');
-		$this->theme();
+		$splash->update('Initializing Settings');
+		$config = new CC_Config('Writer');
 
-		$splash->update('Initializing Configuration');
-		self::$config = new Config();
-
-		$splash->update('Initializing Environment');
-		self::$tooltips = new Tooltips();
-		self::$actions = new Actions();
-
 		$splash->update('Loading Project');
-		self::$window = $window = new ProjectWindow();
-		$splash->parent($window);
-		$window->show_all();
+		parent::__construct();
+		$splash->parent($this);
+		$this->show_all();
 
 		$splash->update('Loaded');
-		$splash->destroy();
+		//$splash->destroy();
 		unset($splash, $window);
-
 		return;
 	}
 
-	//----------------------------------------------------------------
-	//             static helper functions
-	//----------------------------------------------------------------
 
 	/**
-	 * public static function i18n
+	 * static public function instance
 	 *
-	 * wrapper for gettext + sprintf/vsprintf
+	 * this is how items can access the main window instance
 	 *
-	 * @param string $string string to translate
-	 * @return string translated string
+	 * @return object instanceof CC_Writer
 	 */
-	public static function i18n($string)
+	static public function instance()
 	{
-		$args = func_get_args();
-		array_shift($args);
-		if(!empty($args) && count($args) == 1 && is_array($args[0]))
+		if(is_null(self::$singleton))
 		{
-			$args = $args[0];
+			self::$singleton = new CC_Writer();
 		}
-		if(function_exists('gettext'))
-		{
-			// if we have args, the first item is format only and not translated
-			if(is_array($args) && !empty($args))
-			{
-				$args = array_map('gettext', $args);
-			}
-			else
-			{
-				$string = gettext($string);
-			}
-		}
-		return vsprintf($string, $args);
+		return self::$singleton;
 	}
 
 	/**
-	 * public static function launchFile
+	 * public function __clone()
 	 *
-	 * creates command string and pipes it to exec to open a file with an external
-	 * app dependent on OS and desktop
+	 * disable cloning of a singleton
 	 *
-	 * @param string $file file to open
 	 * @return void
 	 */
-	public static function launchFile($file)
+	public function __clone()
 	{
-		if(stristr(PHP_OS, 'linux') || stristr(PHP_OS, 'freebsd'))
-		{
-			if(isset($_ENV['KDE_FULL_SESSION']) && $_ENV['KDE_FULL_SESSION'] == 'true')
-			{
-				$file = 'kfmclient exec "' . $file . '"';
-			}
-			else
-			{
-				$file = 'gnome-open "' . $file . '"';
-			}
-			return exec($file);
-		}
-		elseif(stristr(PHP_OS, 'winnt'))
-		{
-			$shell = new COM('WScript.Shell');
-			$shell->Run('cmd /c start "" "' . $file . '"', 0, FALSE);
-			unset($shell, $file);
-		}
-		elseif(stristr(PHP_OS, 'win32'))
-		{
-			$shell = new COM('WScript.Shell');
-			$shell->Run('command /c start "" "' . $file . '"', 0, FALSE);
-			unset($shell, $file);
-		}
-		elseif(stristr(PHP_OS, 'darwin') || stristr(PHP_OS, 'mac'))
-		{
-			$file = 'open "' . $file . '"';
-			return exec($file);
-		}
-		else
-		{
-			return FALSE;
-		}
+		throw new Exception(CC_Main::i18n('Cannot clone singleton object %s', 'CC_Writer'));
 		return;
 	}
-
-	/**
-	 * static public function appdata
-	 *
-	 * finds appdata dependent on env variables and OS
-	 *
-	 * @return void
-	 */
-	static public function appdata()
-	{
-		static $appdata;
-		if(is_null($appdata))
-		{
-			// check environment variables for appdir or use home/.projects
-			if(isset($_ENV['APPDATA']))
-			{
-				$appdata = $_ENV['APPDATA'] . DS . 'Callicore' . DS;
-			}
-			elseif(stristr(PHP_OS, 'darwin'))
-			{
-				$appdata = DIR . 'Library' . DS . 'Application Support'
-					. DS . 'Callicore' . DS;
-			}
-			elseif(stristr(PHP_OS, 'linux') || stristr(PHP_OS, 'freebsd') || stristr(PHP_OS, 'unix'))
-			{
-				$appdata = DIR . 'Callicore' . DS;
-			}
-			else
-			{
-				$appdata = DIR;
-			}
-			if(!file_exists($appdata))
-			{
-				mkdir($appdata);
-			}
-			$appdata .= 'Writer' . DS;
-			if(!file_exists($appdata))
-			{
-				mkdir($appdata);
-			}
-		}
-		return $appdata;
-	}
-
-	//----------------------------------------------------------------
-	//             Startup Items
-	//----------------------------------------------------------------
-
-	/**
-	 * protected function checkRequirements
-	 *
-	 * checks that php version is 5.2 or greater and php extensions
-	 * needed are loaded
-	 *
-	 * @return void
-	 */
-	protected function checkRequirements()
-	{
-		// set up translation
-		if(extension_loaded('gettext'))
-		{
-			// we use system locale
-			bindtextdomain('Writer', DIR . 'locale');
-			textdomain('Writer');
-		}
-		if(version_compare(PHP_VERSION, '5.2.0', '<'))
-		{
-			trigger_error(self::i18n('You must use php 5.2.0 or higher'), E_USER_ERROR);
-		}
-		$have = get_loaded_extensions();
-		$needed = array('standard', 'pcre', 'date', 'PDO', 'pdo_sqlite', 'php-gtk');
-		$diff = array_diff($needed, $have);
-		if(!empty($diff))
-		{
-			trigger_error(self::i18n('%s : %s', 'The following extensions must be loaded in your php.ini for Writer to function', implode(', ', $diff)), E_USER_ERROR);
-		}
-		unset($have, $needed, $diff);
-		return;
-	}
-
-	/**
-	 * public function theme
-	 *
-	 * registers two new icon sizes, parses the hicolor override rc file and the
-	 * application specific rc file, also sets default window icon
-	 *
-	 * @return void
-	 */
-	protected function theme()
-	{
-
-		self::$LARGE = Gtk::icon_size_register('gtk-large',64, 64);
-		self::$IMAGE = Gtk::icon_size_register('gtk-image',128, 128);
-
-		Gtk::rc_parse(DIR . 'images' . DS . 'stock' . DS . 'stock.rc');
-
-		Gtk::rc_parse(DIR . 'images' . DS . 'images.rc');
-
-		$theme = GtkIconTheme::get_for_screen(GdkScreen::get_default());
-
-		$window = new GtkWindow();
-		$theme->add_builtin_icon('writer-icon', self::$MENU,
-			$window->render_icon('writer-icon', self::$MENU));
-		$theme->add_builtin_icon('writer-icon', self::$SMALL_TOOLBAR,
-			$window->render_icon('writer-icon', self::$SMALL_TOOLBAR));
-		$theme->add_builtin_icon('writer-icon', self::$BUTTON,
-			$window->render_icon('writer-icon', self::$BUTTON));
-		$theme->add_builtin_icon('writer-icon', self::$LARGE_TOOLBAR,
-			$window->render_icon('writer-icon', self::$LARGE_TOOLBAR));
-		$theme->add_builtin_icon('writer-icon', self::$DND,
-			$window->render_icon('writer-icon', self::$DND));
-		$theme->add_builtin_icon('writer-icon', self::$DIALOG,
-			$window->render_icon('writer-icon', self::$DIALOG));
-		$theme->add_builtin_icon('writer-icon', self::$LARGE,
-			$window->render_icon('writer-icon', self::$LARGE));
-		$theme->add_builtin_icon('writer-icon', self::$IMAGE,
-			$window->render_icon('writer-icon', self::$IMAGE));
-		unset($window, $theme);
-
-		GtkWindow::set_default_icon_name('writer-icon');
-
-		return;
-	}
 }
 ?>
\ No newline at end of file