2012-01-26 16:09:05 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
2012-03-28 11:23:08 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-01-26 16:09:05 -05:00
|
|
|
*/
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Main Window Class
|
|
|
|
*
|
|
|
|
* Creates and displays the main interface window
|
|
|
|
*/
|
2012-01-26 16:09:05 -05:00
|
|
|
class Main extends GtkWindow {
|
|
|
|
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Reference to settings instance
|
2012-04-19 21:55:44 -04:00
|
|
|
*
|
|
|
|
* @var Settings
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
|
|
|
private $settings;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to connection sidebar instance
|
2012-04-19 21:55:44 -04:00
|
|
|
*
|
|
|
|
* @var Connection_Sidebar
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
|
|
|
private $connection_sidebar;
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Create and display the main window on startup
|
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function __construct()
|
2012-01-26 16:09:05 -05:00
|
|
|
{
|
|
|
|
parent::__construct();
|
2012-03-27 09:37:04 -04:00
|
|
|
|
|
|
|
$this->settings =& Settings::get_instance();
|
2012-03-28 11:23:08 -04:00
|
|
|
|
2012-01-30 18:11:01 -05:00
|
|
|
|
2012-03-27 09:37:04 -04:00
|
|
|
if ( ! is_null($this->settings->width) && ! is_null($this->settings->height))
|
|
|
|
{
|
2012-03-28 16:10:39 -04:00
|
|
|
// Resize to the last size
|
2012-03-27 09:37:04 -04:00
|
|
|
$this->set_size_request($this->settings->width, $this->settings->height);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2012-03-28 16:10:39 -04:00
|
|
|
// Resize to a sane size
|
2012-03-27 09:37:04 -04:00
|
|
|
$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);
|
|
|
|
}
|
2012-02-02 22:18:50 -05:00
|
|
|
|
2012-03-28 16:10:39 -04:00
|
|
|
// Layout the interface
|
2012-01-27 16:57:59 -05:00
|
|
|
$this->_main_layout();
|
|
|
|
}
|
|
|
|
|
2012-01-30 13:15:44 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-03-27 09:37:04 -04:00
|
|
|
/**
|
|
|
|
* Some cleanup for when the main window is closed
|
2012-04-11 14:57:38 -04:00
|
|
|
*
|
|
|
|
* @return void
|
2012-03-27 09:37:04 -04:00
|
|
|
*/
|
|
|
|
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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-03-28 11:23:08 -04:00
|
|
|
/**
|
2012-04-11 14:57:38 -04:00
|
|
|
* Exits the GTK loop
|
|
|
|
*
|
|
|
|
* @return void
|
2012-01-30 13:15:44 -05:00
|
|
|
*/
|
2012-02-21 11:45:42 -05:00
|
|
|
public function quit()
|
2012-01-30 13:15:44 -05:00
|
|
|
{
|
|
|
|
Gtk::main_quit();
|
|
|
|
}
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
/**
|
|
|
|
* Layout the main interface
|
|
|
|
* Create menus, hboxes, vboxs and other widgets
|
2012-03-28 11:23:08 -04:00
|
|
|
*
|
|
|
|
* @return void
|
2012-01-27 16:57:59 -05:00
|
|
|
*/
|
|
|
|
private function _main_layout()
|
|
|
|
{
|
2012-04-02 13:04:53 -04:00
|
|
|
$this->set_title(PROGRAM_NAME);
|
2012-03-28 11:23:08 -04:00
|
|
|
|
2012-01-27 11:57:13 -05:00
|
|
|
// Quit when this window is closed
|
|
|
|
$this->connect_simple('destroy', array('gtk', 'main_quit'));
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Main Vbox that everything is contained in
|
2012-02-23 20:10:13 -05:00
|
|
|
$main_vbox = new GTKVBox(FALSE, 5);
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-02-02 19:40:21 -05:00
|
|
|
// Main Hpaned for columns
|
|
|
|
$hpane = new GTKHPaned();
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Add the menubar
|
|
|
|
$main_vbox->pack_start($this->_create_menu(), FALSE, FALSE);
|
|
|
|
|
|
|
|
// Add the main interface area hbox
|
2012-02-02 19:40:21 -05:00
|
|
|
$main_vbox->pack_start($hpane);
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-02-10 09:55:14 -05:00
|
|
|
$scrolled_win = new GtkScrolledWindow();
|
2012-02-24 17:53:16 -05:00
|
|
|
$scrolled_win->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
|
2012-03-29 16:26:50 -04:00
|
|
|
$scrolled_win->add_with_viewport(DB_tabs::get_instance());
|
2012-02-07 10:31:54 -05:00
|
|
|
|
2012-02-24 17:53:16 -05:00
|
|
|
// Add the connection sidebar
|
2012-02-28 10:38:13 -05:00
|
|
|
$this->connection_sidebar =& Connection_Sidebar::get_instance();
|
2012-02-07 10:31:54 -05:00
|
|
|
|
2012-02-02 19:40:21 -05:00
|
|
|
// Add the left column to the hpane
|
2012-02-24 17:53:16 -05:00
|
|
|
$hpane->pack1($this->connection_sidebar, FALSE);
|
2012-02-10 09:55:14 -05:00
|
|
|
$hpane->pack2($scrolled_win);
|
2012-01-30 18:11:01 -05:00
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
// Add the Vbox, and show the window
|
|
|
|
$this->add($main_vbox);
|
|
|
|
$this->show_all();
|
2012-01-26 16:09:05 -05:00
|
|
|
}
|
|
|
|
|
2012-01-30 13:15:44 -05:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
/**
|
|
|
|
* Create the menu for the program
|
|
|
|
*
|
|
|
|
* @return GtkMenuBar
|
|
|
|
*/
|
|
|
|
private function _create_menu()
|
|
|
|
{
|
2012-03-28 16:10:39 -04:00
|
|
|
// Menu Bar
|
2012-01-27 16:57:59 -05:00
|
|
|
$menu_bar = new GtkMenuBar();
|
|
|
|
|
2012-03-28 16:10:39 -04:00
|
|
|
// Menu Bar Top Items
|
2012-01-27 16:57:59 -05:00
|
|
|
$top_file_menu = new GtkMenuItem('_File');
|
|
|
|
$top_help_menu = new GtkMenuItem('_Help');
|
|
|
|
|
2012-03-28 16:10:39 -04:00
|
|
|
// Add sub Menus to top items
|
2012-01-27 16:57:59 -05:00
|
|
|
$file_menu = new GtkMenu();
|
|
|
|
$top_file_menu->set_submenu($file_menu);
|
|
|
|
$help_menu = new GtkMenu();
|
|
|
|
$top_help_menu->set_submenu($help_menu);
|
|
|
|
|
2012-03-28 11:23:08 -04:00
|
|
|
|
2012-03-28 16:10:39 -04:00
|
|
|
// File Menu
|
2012-01-31 11:39:30 -05:00
|
|
|
{
|
2012-03-28 16:10:39 -04:00
|
|
|
// Set up the quit item
|
2012-01-27 16:57:59 -05:00
|
|
|
$quit = new GtkImageMenuItem(GTK::STOCK_QUIT);
|
|
|
|
$quit->connect_simple('activate', array($this, 'quit'));
|
2012-01-27 21:19:39 -05:00
|
|
|
$file_menu->append($quit);
|
2012-01-27 16:57:59 -05:00
|
|
|
|
|
|
|
// Add the top level menu to the menubar
|
|
|
|
$menu_bar->append($top_file_menu);
|
2012-01-31 11:39:30 -05:00
|
|
|
}
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-03-28 16:10:39 -04:00
|
|
|
// Help Menu
|
2012-01-31 11:39:30 -05:00
|
|
|
{
|
2012-03-28 16:10:39 -04:00
|
|
|
// Set up the about item
|
2012-01-27 16:57:59 -05:00
|
|
|
$about = new GtkImageMenuItem(GTK::STOCK_ABOUT);
|
2012-04-02 13:04:53 -04:00
|
|
|
$about->connect_simple('activate', 'about');
|
2012-01-27 16:57:59 -05:00
|
|
|
$help_menu->append($about);
|
|
|
|
|
|
|
|
// Add the top level menu to the menubar
|
|
|
|
$menu_bar->append($top_help_menu);
|
2012-01-31 11:39:30 -05:00
|
|
|
}
|
2012-01-27 16:57:59 -05:00
|
|
|
|
2012-03-28 11:23:08 -04:00
|
|
|
|
2012-01-27 16:57:59 -05:00
|
|
|
return $menu_bar;
|
2012-03-28 11:23:08 -04:00
|
|
|
}
|
2012-01-27 16:57:59 -05:00
|
|
|
}
|
|
|
|
// End of main.php
|