From 5ffdaca76264d3bac2ebb6abc47f466eca427303 Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Tue, 27 Mar 2012 09:37:04 -0400 Subject: [PATCH] Save window size and position on close And Remove some extraneous references. --- sys/windows/main.php | 46 ++++++++++++++++++++-- sys/windows/widgets/connection_sidebar.php | 23 +++++------ 2 files changed, 52 insertions(+), 17 deletions(-) diff --git a/sys/windows/main.php b/sys/windows/main.php index df8c5c8..9f4e068 100644 --- a/sys/windows/main.php +++ b/sys/windows/main.php @@ -27,11 +27,29 @@ class Main extends GtkWindow { public function __construct() { parent::__construct(); - - //Resize to a sane size - $this->set_size_request(640, 480); - $this->set_position(Gtk::WIN_POS_CENTER); + $this->settings =& Settings::get_instance(); + + + if ( ! is_null($this->settings->width) && ! is_null($this->settings->height)) + { + //Resize to the last size + $this->set_size_request($this->settings->width, $this->settings->height); + } + else + { + //Resize to a sane size + $this->set_size_request(640, 480); + } + + if (! is_null($this->settings->position)) + { + $this->move($this->settings->position[0], $this->settings->position[1]); + } + else + { + $this->set_position(Gtk::WIN_POS_CENTER); + } //Layout the interface $this->_main_layout(); @@ -39,6 +57,26 @@ class Main extends GtkWindow { // -------------------------------------------------------------------------- + /** + * Some cleanup for when the main window is closed + */ + public function __destruct() + { + // Save the Window position + $this->settings->position = $this->get_position(); + + list($width, $height) = $this->get_size(); + + // Save the Window hegiht + $this->settings->height = $height; + + // Save the Window width + $this->settings->width = $width; + + } + + // -------------------------------------------------------------------------- + /** * Display About menu with version information */ diff --git a/sys/windows/widgets/connection_sidebar.php b/sys/windows/widgets/connection_sidebar.php index 01cbd24..c616701 100644 --- a/sys/windows/widgets/connection_sidebar.php +++ b/sys/windows/widgets/connection_sidebar.php @@ -64,7 +64,7 @@ class Connection_Sidebar extends GtkVBox { $this->_render(); // Set up context menu event - $this->treeview->connect('button-press-event', array(&$this, 'on_button')); + $this->treeview->connect('button-press-event', array($this, 'on_button')); $selection = $this->treeview->get_selection(); @@ -102,11 +102,11 @@ class Connection_Sidebar extends GtkVBox { // Icon column $cell_renderer = new GtkCellRendererPixbuf(); - $this->treeview->insert_column_with_data_func(0, 'Type', $cell_renderer, array(&$this, 'set_icon')); + $this->treeview->insert_column_with_data_func(0, 'Type', $cell_renderer, array($this, 'set_icon')); // Label column $cell_renderer = new GtkCellRendererText(); - $this->treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array(&$this, 'set_label')); + $this->treeview->insert_column_with_data_func(1, 'Connection name', $cell_renderer, array($this, 'set_label')); } // -------------------------------------------------------------------------- @@ -187,7 +187,9 @@ class Connection_Sidebar extends GtkVBox { if ($event->button == 3) { // get the row and column - list($path_array, $col, $x, $y)= $view->get_path_at_pos($event->x, $event->y); + $path_array = $view->get_path_at_pos($event->x, $event->y); + $path = $path_array[0][0]; + $col = $path_array[1]; // Don't try to get values for an item that doesn't exist. Instead, return, // so that the program doesn't crash because someone thought it funny @@ -196,13 +198,9 @@ class Connection_Sidebar extends GtkVBox { { return; } - - $path = $path_array[0]; - //$col = $path_array[1]; - $col_title = $col->get_title(); } - $this->menu = $this->conn_popup_menu($path, $col_title, $event); + $this->menu = $this->conn_popup_menu($path, $event, $col, $path_array); } // -------------------------------------------------------------------------- @@ -211,11 +209,10 @@ class Connection_Sidebar extends GtkVBox { * Creates and displays a context menu for the selected connection * * @param array $pos - * @param string $title * @param object $event * @return void */ - public function conn_popup_menu($pos, $title, $event) + public function conn_popup_menu($pos, $event, $col, $all) { $this->menu = new GtkMenu(); @@ -223,7 +220,7 @@ class Connection_Sidebar extends GtkVBox { { $remove = new GtkImageMenuItem('Delete Connection'); $remove->set_image(GtkImage::new_from_stock(GTK::STOCK_CANCEL, Gtk::ICON_SIZE_MENU)); - $remove->connect_simple('activate', array($this, 'remove_connection')); + $remove->connect_simple('activate', array($this, 'remove_connection'), $all); $this->menu->append($remove); } @@ -240,7 +237,7 @@ class Connection_Sidebar extends GtkVBox { * * @return void */ - public function remove_connection() + public function remove_connection($col) { //@todo implement $model = $this->treeview->get_model();