diff --git a/src/windows/main.php b/src/windows/main.php index 3ef4d09..0d4bdf7 100644 --- a/src/windows/main.php +++ b/src/windows/main.php @@ -32,7 +32,6 @@ class Main extends GtkWindow { $this->resize(640, 480); $this->set_position(Gtk::WIN_POS_CENTER); - $this->settings =& Settings::get_instance(); //Layout the interface $this->_main_layout(); @@ -114,7 +113,7 @@ class Main extends GtkWindow { // Add the left column to the hpane - $hpane->pack1($this->_connection_sidebar(), FALSE); + $hpane->pack1(new Connection_Sidebar(), FALSE); $hpane->pack2($scrolled_win); // Add the Vbox, and show the window @@ -173,126 +172,7 @@ class Main extends GtkWindow { return $menu_bar; - } - - // -------------------------------------------------------------------------- - - /** - * Lays out the left sidebar in the main window - * - * @return GtkVbox - */ - private function _connection_sidebar() - { - $dblabel = new GtkLabel('Database Connections'); - $dblabel->set_alignment(0,0); - - $add_button = new GtkButton(); - $add_button->set_label("New Connnection"); - $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, Gtk::ICON_SIZE_SMALL_TOOLBAR)); - - $add_button->connect_simple('clicked', array($this, 'new_conn')); - - $conn_vbox = new GtkVBox(); - - $conn_vbox->pack_start($dblabel, FALSE, FALSE); - - // Treeview to show database connections - { - // Create a Storage object for connection list - $model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING); - - // Add the existing connections to the model - $db_conns = $this->settings->get_dbs(); - if( ! empty($db_conns)) - { - foreach($db_conns as $name => $props) - { - $db = $props; - $db->name = $name; - - $iter = $model->append(); - $model->set($iter, 0, $db); - } - } - - // Initialize the treeview with the data - $treeview = new GtkTreeView($model); - - // Icon column - $cell_renderer = new GtkCellRendererPixbuf(); - $treeview->insert_column_with_data_func(0, 'Type', $cell_renderer, array(&$this, 'set_icon')); - - // Label column - $cell_renderer = new GtkCellRendererText(); - $treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array(&$this, 'set_label')); - - - $selection = $treeview->get_selection(); - $selection->set_mode(GTK::SELECTION_SINGLE); - } - - - $conn_vbox->pack_start($treeview); - $conn_vbox->pack_start($add_button, FALSE); - - return $conn_vbox; - } - - /** - * Sets the icon for the current db type - * - * @param GtkTreeView Column $col - * @param GtkCellRenderer $cell - * @param GtkTreeModel $model - * @param GtkTreeIter $iter - */ - public function set_icon($col, $cell, $model, $iter) - { - $col->set_reorderable(TRUE); - $info = $model->get_value($iter, 0); - $db_type = strtolower($info->type); - $img_file = BASE_DIR."/images/{$db_type}-logo-32.png"; - - if(is_file($img_file)) - { - $cell->set_property('pixbuf', GdkPixbuf::new_from_file($img_file)); - } - else - { - // Load an empty image if the db image doesn't exist - $img = new GtkImage(); - $cell->set_property('pixbuf', $img->get_pixbuf()); - } - } - - /** - * Sets the label of the current db connection - * - * @param GtkTreeViewColumn $col - * @param GtkCellRenderer $cell - * @param GtkTreeModel $model - * @param GtkTreeIter $iter - */ - public function set_label($col, $cell, $model, $iter) - { - $col->set_reorderable(TRUE); - $info = $model->get_value($iter, 0); - $cell->set_property('text', $info->name); - } - - // -------------------------------------------------------------------------- - - /** - * Returns window for creating a new database connection - * - * @return Add_DB object - */ - public function new_conn() - { - return new Add_DB(); - } - + } } // End of main.php \ No newline at end of file diff --git a/src/windows/widgets/connection_sidebar.php b/src/windows/widgets/connection_sidebar.php new file mode 100644 index 0000000..fcbdc02 --- /dev/null +++ b/src/windows/widgets/connection_sidebar.php @@ -0,0 +1,132 @@ +settings =& Settings::get_instance(); + + $dblabel = new GtkLabel('Database Connections'); + $dblabel->set_alignment(0,0); + + $add_button = new GtkButton(); + $add_button->set_label("New Connnection"); + $add_button->set_image(GTKImage::new_from_stock(GTK::STOCK_ADD, Gtk::ICON_SIZE_SMALL_TOOLBAR)); + + $add_button->connect_simple('clicked', array($this, 'new_conn')); + + $this->pack_start($dblabel, FALSE, FALSE); + + // Treeview to show database connections + { + // Create a Storage object for connection list + $model = new GtkListStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING); + + // Add the existing connections to the model + $db_conns = $this->settings->get_dbs(); + if( ! empty($db_conns)) + { + foreach($db_conns as $name => $props) + { + $db = $props; + $db->name = $name; + + $iter = $model->append(); + $model->set($iter, 0, $db); + } + } + + // Initialize the treeview with the data + $treeview = new GtkTreeView($model); + + // Icon column + $cell_renderer = new GtkCellRendererPixbuf(); + $treeview->insert_column_with_data_func(0, 'Type', $cell_renderer, array(&$this, 'set_icon')); + + // Label column + $cell_renderer = new GtkCellRendererText(); + $treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array(&$this, 'set_label')); + + + $selection = $treeview->get_selection(); + $selection->set_mode(GTK::SELECTION_SINGLE); + } + + + $this->pack_start($treeview); + $this->pack_start($add_button, FALSE); + } + + // -------------------------------------------------------------------------- + + /** + * Sets the icon for the current db type + * + * @param GtkTreeView Column $col + * @param GtkCellRenderer $cell + * @param GtkTreeModel $model + * @param GtkTreeIter $iter + */ + public function set_icon($col, $cell, $model, $iter) + { + $col->set_reorderable(TRUE); + $info = $model->get_value($iter, 0); + $db_type = strtolower($info->type); + $img_file = BASE_DIR."/images/{$db_type}-logo-32.png"; + + if(is_file($img_file)) + { + $cell->set_property('pixbuf', GdkPixbuf::new_from_file($img_file)); + } + else + { + // Load an empty image if the db image doesn't exist + $img = new GtkImage(); + $cell->set_property('pixbuf', $img->get_pixbuf()); + } + } + + // -------------------------------------------------------------------------- + + /** + * Sets the label of the current db connection + * + * @param GtkTreeViewColumn $col + * @param GtkCellRenderer $cell + * @param GtkTreeModel $model + * @param GtkTreeIter $iter + */ + public function set_label($col, $cell, $model, $iter) + { + $col->set_reorderable(TRUE); + $info = $model->get_value($iter, 0); + $cell->set_property('text', $info->name); + } + + // -------------------------------------------------------------------------- + + /** + * Returns window for creating a new database connection + * + * @return Add_DB object + */ + public function new_conn() + { + return new Add_DB(); + } + +} diff --git a/src/windows/widgets/datagrid.php b/src/windows/widgets/datagrid.php index ea2928e..68e3e9f 100644 --- a/src/windows/widgets/datagrid.php +++ b/src/windows/widgets/datagrid.php @@ -17,10 +17,11 @@ */ class DataGrid extends GtkTreeView{ - protected $model, $view; + protected $model, $settings; function __construct() { + $this->settings =& Settings::get_instance(); $this->model = new GtkTreeStore(GObject::TYPE_PHP_VALUE, GObject::TYPE_STRING); parent::__construct($this->model); }