From 19c709fc93ad8050dfeb98ffc20d47b6f5e745bc Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Thu, 29 Mar 2012 16:26:50 -0400 Subject: [PATCH] Various improvements --- sys/common/data_grid.php | 37 ++++++++++++++++++++-- sys/db/query_builder.php | 2 -- sys/windows/add_db.php | 1 - sys/windows/edit_db.php | 10 ++++-- sys/windows/main.php | 2 +- sys/windows/widgets/connection_sidebar.php | 21 ++++++------ sys/windows/widgets/db_tabs.php | 33 +++++++++++++++++++ 7 files changed, 85 insertions(+), 21 deletions(-) diff --git a/sys/common/data_grid.php b/sys/common/data_grid.php index db459ef..a4fb318 100644 --- a/sys/common/data_grid.php +++ b/sys/common/data_grid.php @@ -21,10 +21,15 @@ class Data_Grid extends GtkTreeView { /** * Create the object + * + * @param object $model */ - public function __construct() + public function __construct($model = null) { - $this->model = new GtkTreeStore(Gobject::TYPE_PHP_VALUE, Gobject::TYPE_PHP_VALUE); + $this->model = ( ! is_null($model)) + ? $model + : new GtkTreeStore(Gobject::TYPE_PHP_VALUE, Gobject::TYPE_PHP_VALUE); + parent::__construct($this->model); } @@ -40,4 +45,30 @@ class Data_Grid extends GtkTreeView { { // @todo implement } -} \ No newline at end of file + + // -------------------------------------------------------------------------- + + /** + * Set the value of the cell at the provided coordinate array + * + * @param array $coord + * @param mixed $val + */ + public function set(array $coord, $val) + { + // @todo implement + } + + // -------------------------------------------------------------------------- + + /** + * Return a new Data_grid object + * + * @param object $model + */ + public function reset($model = null) + { + return new Data_Grid($model); + } +} +// End of data_grid.php \ No newline at end of file diff --git a/sys/db/query_builder.php b/sys/db/query_builder.php index 0462c74..f1d3da3 100644 --- a/sys/db/query_builder.php +++ b/sys/db/query_builder.php @@ -21,8 +21,6 @@ class Query_Builder { // Compiled query component strings private $select_string, $from_string, - $insert_string, - $update_string, $set_string, $order_string, $group_string; diff --git a/sys/windows/add_db.php b/sys/windows/add_db.php index fb941f1..9d68a60 100644 --- a/sys/windows/add_db.php +++ b/sys/windows/add_db.php @@ -32,5 +32,4 @@ class Add_DB extends GtkWindow { $this->show_all(); } } - // End of add_db.php \ No newline at end of file diff --git a/sys/windows/edit_db.php b/sys/windows/edit_db.php index 904df90..6697283 100644 --- a/sys/windows/edit_db.php +++ b/sys/windows/edit_db.php @@ -17,7 +17,12 @@ */ class Edit_DB extends GtkWindow { - public function __construct() + /** + * Connection editing window + * + * @param string $db + */ + public function __construct($db) { parent::__construct(); @@ -25,12 +30,11 @@ class Edit_DB extends GtkWindow { $this->set_title("Edit Database Connection"); // Create the layout table - $connection_form = new DB_Info_Widget(); + $connection_form = new DB_Info_Widget(Settings::get_instance()->get_db($db)); // Add the Vbox, and show the window $this->add($connection_form); $this->show_all(); } } - // End of edit_db.php \ No newline at end of file diff --git a/sys/windows/main.php b/sys/windows/main.php index 09985d1..0b9b592 100644 --- a/sys/windows/main.php +++ b/sys/windows/main.php @@ -150,7 +150,7 @@ class Main extends GtkWindow { $scrolled_win = new GtkScrolledWindow(); $scrolled_win->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC); - $scrolled_win->add_with_viewport(new DB_tabs()); + $scrolled_win->add_with_viewport(DB_tabs::get_instance()); // Add the connection sidebar $this->connection_sidebar =& Connection_Sidebar::get_instance(); diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index cd43793..a53491a 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -17,7 +17,7 @@ */ class Connection_Sidebar extends GtkVBox { - protected $settings, $menu, $treeview, $model; + protected $settings, $menu, $treeview; private static $instance; /** @@ -60,9 +60,6 @@ class Connection_Sidebar extends GtkVBox { // Treeview to show database connections { - // Create a Storage object for connection list - $this->model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING); - // Render the treeview $this->_render(); @@ -86,6 +83,11 @@ class Connection_Sidebar extends GtkVBox { */ protected function _render() { + // Initialize the treeview + $this->treeview = new Data_Grid(); + + $model = $this->treeview->get_model(); + // Add the existing connections to the model $db_conns = $this->settings->get_dbs(); if( ! empty($db_conns)) @@ -95,14 +97,11 @@ class Connection_Sidebar extends GtkVBox { $db = $props; $db->name = $name; - $iter = $this->model->append(); - $this->model->set($iter, 0, $db); + $iter = $model->append(); + $model->set($iter, 0, $db); } } - // Initialize the treeview with the data - $this->treeview = new GtkTreeView($this->model); - // Icon column $cell_renderer = new GtkCellRendererPixbuf(); $this->treeview->insert_column_with_data_func(0, 'Type', $cell_renderer, array($this, 'set_icon')); @@ -125,7 +124,7 @@ class Connection_Sidebar extends GtkVBox { public function set_icon($col, $cell, $model, $iter) { $col->set_reorderable(TRUE); - $info = $this->model->get_value($iter, 0); + $info = $model->get_value($iter, 0); $db_type = strtolower($info->type); $img_file = BASE_DIR."/images/{$db_type}-logo-32.png"; @@ -154,7 +153,7 @@ class Connection_Sidebar extends GtkVBox { public function set_label($col, $cell, $model, $iter) { $col->set_reorderable(TRUE); - $info = $this->model->get_value($iter, 0); + $info = $model->get_value($iter, 0); $cell->set_property('text', $info->name); } diff --git a/sys/windows/widgets/db_tabs.php b/sys/windows/widgets/db_tabs.php index 2532426..080ba55 100644 --- a/sys/windows/widgets/db_tabs.php +++ b/sys/windows/widgets/db_tabs.php @@ -17,6 +17,25 @@ */ class DB_tabs extends GTKNotebook { + private static $instance; + + /** + * Return the db tabs object if it exists, or create and return + * + * @return DB_tabs + */ + public static function &get_instance() + { + if (empty(self::$instance)) + { + self::$instance = new DB_tabs(); + } + + return self::$instance; + } + + // -------------------------------------------------------------------------- + /** * Create the object */ @@ -49,5 +68,19 @@ class DB_tabs extends GTKNotebook { $this->append_page($widget, new GtkLabel($label)); } + // -------------------------------------------------------------------------- + + /** + * Creates a new instance of this class, and destroys the existing + * instance + * + * @return DB_tabs + */ + public function reset() + { + unset(self::$instance); + return self::get_instance(); + } + } // End of db_tabs.php