From 2fefe6e94932c43a369365b1d4a2fc8e898dfafe Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Mon, 27 Feb 2012 12:14:49 -0500 Subject: [PATCH] Beginning of right-click context menu --- src/databases/sqlite_manip.php | 2 +- src/windows/widgets/connection_sidebar.php | 48 +++++++++++++++++++++- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/src/databases/sqlite_manip.php b/src/databases/sqlite_manip.php index f1528f0..8048c9c 100644 --- a/src/databases/sqlite_manip.php +++ b/src/databases/sqlite_manip.php @@ -67,7 +67,7 @@ class SQLite_manip extends db_manip { } // Generate the sql for the creation of the table - $sql = "CREATE TABLE {$name} ("; + $sql = "CREATE TABLE \"{$name}\" ("; $sql .= implode(",", $columns); $sql .= ")"; diff --git a/src/windows/widgets/connection_sidebar.php b/src/windows/widgets/connection_sidebar.php index 752fa1f..e9a3541 100644 --- a/src/windows/widgets/connection_sidebar.php +++ b/src/windows/widgets/connection_sidebar.php @@ -14,7 +14,7 @@ class Connection_Sidebar extends GtkVBox { - protected $settings; + protected $settings, $menu; public function __construct() { @@ -63,6 +63,8 @@ class Connection_Sidebar extends GtkVBox { $cell_renderer = new GtkCellRendererText(); $treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array(&$this, 'set_label')); + $treeview->connect('button-press-event', array(&$this, 'on_button')); + $selection = $treeview->get_selection(); $selection->set_mode(GTK::SELECTION_SINGLE); @@ -133,6 +135,50 @@ class Connection_Sidebar extends GtkVBox { // -------------------------------------------------------------------------- + /** + * Event for mouse clicks on connection sidebar + * + * @param GtkTreeView $view + * @param $event + * @return void + */ + public function on_button($view, $event) + { + // Right click + if($event->button == 3) + { + // get the row and column + $path_array = $view->get_path_at_pos($event->x, $event->y); + $path = $path_array[0][0]; + $col = $path_array[1]; + $col_title = $col->get_title(); + } + + $this->menu = $this->conn_popup_menu($path, $col_title, $event); + } + + // -------------------------------------------------------------------------- + + /** + * Creates a context menu for the selected connection + * + * @param [type] $pos [description] + * @param [type] $title [description] + * @param [type] $event [description] + * @return [type] + */ + public function conn_popup_menu($pos, $title, $event) + { + $this->menu = new GtkMenu(); + + // Set up menu items + + $this->menu->show_all(); + $this->menu->popup(); + } + + // -------------------------------------------------------------------------- + /** * Remove a connection from the connection manager */