This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
OpenSQLManager/sys/windows/main.php

220 lines
4.8 KiB
PHP
Raw Normal View History

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
*/
// --------------------------------------------------------------------------
/**
* Main Window Class
*
* Creates and displays the main interface window
*/
2012-01-26 16:09:05 -05:00
class Main extends GtkWindow {
2012-02-24 17:53:16 -05:00
private $settings, $connection_sidebar;
/**
* 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();
$this->settings =& Settings::get_instance();
2012-03-28 11:23:08 -04:00
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();
}
2012-01-30 13:15:44 -05:00
// --------------------------------------------------------------------------
/**
* 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;
}
// --------------------------------------------------------------------------
2012-01-30 13:15:44 -05:00
/**
* Display About menu with version information
2012-03-28 11:23:08 -04:00
*
* @return void
2012-01-30 13:15:44 -05:00
*/
2012-02-21 11:45:42 -05:00
public function about()
2012-01-30 13:15:44 -05:00
{
$dlg = new GtkAboutDialog();
$dlg->set_transient_for($this);
$dlg->set_program_name($this->get_title());
$dlg->set_version('0.1.0pre');
2012-01-30 13:15:44 -05:00
$dlg->set_copyright("Copyright (c) ".date('Y')." Timothy J. Warren");
$dlg->set_website('https://github.com/aviat4ion/OpenSQLManager');
$dlg->set_website_label('Fork on Github');
$dlg->set_license(file_get_contents(BASE_DIR . "/LICENSE"));
$dlg->set_authors(array(
'Timothy J. Warren',
//'Nathan Dupuie',
));
/*$dlg->set_artists(array(
'Nathan Dupuie',
));*/
2012-01-30 13:15:44 -05:00
$dlg->run();
$dlg->destroy();
}
// --------------------------------------------------------------------------
2012-03-28 11:23:08 -04:00
/**
2012-01-30 13:15:44 -05:00
* Quits the GTK loop
*/
2012-02-21 11:45:42 -05:00
public function quit()
2012-01-30 13:15:44 -05:00
{
Gtk::main_quit();
}
// --------------------------------------------------------------------------
/**
* Layout the main interface
* Create menus, hboxes, vboxs and other widgets
2012-03-28 11:23:08 -04:00
*
* @return void
*/
private function _main_layout()
{
2012-01-27 11:57:13 -05:00
$this->set_title('OpenSQLManager');
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'));
// Main Vbox that everything is contained in
2012-02-23 20:10:13 -05:00
$main_vbox = new GTKVBox(FALSE, 5);
// Main Hpaned for columns
$hpane = new GTKHPaned();
// Add the menubar
$main_vbox->pack_start($this->_create_menu(), FALSE, FALSE);
// Add the main interface area hbox
$main_vbox->pack_start($hpane);
$scrolled_win = new GtkScrolledWindow();
2012-02-24 17:53:16 -05:00
$scrolled_win->set_policy(Gtk::POLICY_AUTOMATIC, Gtk::POLICY_AUTOMATIC);
$scrolled_win->add(new DataGrid());
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();
// Add the left column to the hpane
2012-02-24 17:53:16 -05:00
$hpane->pack1($this->connection_sidebar, FALSE);
$hpane->pack2($scrolled_win);
// 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
// --------------------------------------------------------------------------
/**
* Create the menu for the program
*
* @return GtkMenuBar
*/
private function _create_menu()
{
//Menu Bar
$menu_bar = new GtkMenuBar();
//Menu Bar Top Items
$top_file_menu = new GtkMenuItem('_File');
$top_help_menu = new GtkMenuItem('_Help');
//Add sub Menus to top items
$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
//File Menu
{
2012-01-30 11:22:44 -05:00
//Set up the open item
//$open = new GtkImageMenuItem(GTK::STOCK_OPEN);
//$file_menu->append($open);
2012-01-30 11:22:44 -05:00
//Set up the quit item
$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);
// Add the top level menu to the menubar
$menu_bar->append($top_file_menu);
}
//Help Menu
{
//Set up the about item
$about = new GtkImageMenuItem(GTK::STOCK_ABOUT);
$about->connect_simple('activate', array($this, 'about'));
$help_menu->append($about);
// Add the top level menu to the menubar
$menu_bar->append($top_help_menu);
}
2012-03-28 11:23:08 -04:00
return $menu_bar;
2012-03-28 11:23:08 -04:00
}
}
// End of main.php