From 3dfa42b8949edccccbca4a170705ba7457976a7a Mon Sep 17 00:00:00 2001 From: Timothy Warren Date: Wed, 30 May 2012 16:41:33 -0400 Subject: [PATCH] Lots of layout improvements --- .travis.yml | 1 - OpenSQLManager.php | 15 ++- sys/common/functions.php | 29 +----- sys/db | 2 +- sys/widgets/connection_manager.php | 161 +++++++++++++++++++++++++++++ sys/widgets/connection_sidebar.php | 115 ++++++++++++++++----- sys/widgets/data_grid.php | 17 ++- sys/windows/main.php | 32 +++--- 8 files changed, 286 insertions(+), 86 deletions(-) create mode 100644 sys/widgets/connection_manager.php diff --git a/.travis.yml b/.travis.yml index 080e266..c445e22 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,7 +1,6 @@ language: php php: - - 5.2 - 5.3 - 5.4 diff --git a/OpenSQLManager.php b/OpenSQLManager.php index 1bdc523..aab6408 100644 --- a/OpenSQLManager.php +++ b/OpenSQLManager.php @@ -32,10 +32,10 @@ date_default_timezone_set('GMT'); ini_set('memory_limit', -1); // Set the current directory as the base for included files -define('BASE_DIR', dirname(__FILE__).'/sys'); -define('SETTINGS_DIR', dirname(__FILE__)); +define('BASE_DIR', __DIR__.'/sys'); +define('SETTINGS_DIR', __DIR__); define('PROGRAM_NAME', 'OpenSQLManager'); -define('VERSION', '0.1.0pre'); +define('VERSION', '0.2.0pre'); // -------------------------------------------------------------------------- @@ -93,7 +93,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline) // Do this after the two compatibility checks for cleaner output // Note that this will throw exceptions on notices -set_error_handler("OpenSQLManager\exception_error_handler", E_ERROR | E_WARNING | E_NOTICE); +// set_error_handler("OpenSQLManager\exception_error_handler", E_ERROR | E_WARNING | E_NOTICE); // -------------------------------------------------------------------------- @@ -151,9 +151,6 @@ require_once(BASE_DIR . "/db/autoload.php"); // ! App Bootstrap class // -------------------------------------------------------------------------- -// The main Window object -$main = new Main(); - /** * Class for the app itself * @@ -168,7 +165,8 @@ class OpenSQLManager extends \wxApp { */ public function OnInit() { - global $main; + // The main Window object + $main = new Main(); $main->show(); return 0; @@ -181,7 +179,6 @@ class OpenSQLManager extends \wxApp { */ public function OnExit() { - \wxExit(); return 0; } } diff --git a/sys/common/functions.php b/sys/common/functions.php index 1d0698a..82d587e 100644 --- a/sys/common/functions.php +++ b/sys/common/functions.php @@ -50,7 +50,7 @@ function array_to_object($array) */ function alert($message) { - return \wxMessageBox($message, 'Info', wxOK); + return \wxMessageBox($message, 'Info', wxOK|wxICON_INFORMATION); } // -------------------------------------------------------------------------- @@ -63,17 +63,7 @@ function alert($message) */ function error($message) { - /*$dialog = new GTKMessageDialog( - NULL, - Gtk::DIALOG_MODAL, - Gtk::MESSAGE_ERROR, - Gtk::BUTTONS_OK, - $message - ); - - $dialog->set_position(Gtk::WIN_POS_CENTER); - $dialog->run(); - $dialog->destroy();*/ + return \wxMessageBox($message, 'Error', wxOK|wxICON_ERROR); } // -------------------------------------------------------------------------- @@ -86,19 +76,8 @@ function error($message) */ function confirm($message) { - /*$dialog = new GTKMessageDialog( - NULL, - Gtk::DIALOG_MODAL, - Gtk::MESSAGE_QUESTION, - Gtk::BUTTONS_YES_NO, - $message - ); - - $dialog->set_position(Gtk::WIN_POS_CENTER); - $answer = $dialog->run(); - $dialog->destroy(); - - return ($answer === Gtk::RESPONSE_YES) ? TRUE : FALSE;*/ + $answer = \wxMessageBox($message, 'Prompt', wxYES_NO); + return ($answer === wxYES) ? TRUE : FALSE; } // End of functions.php \ No newline at end of file diff --git a/sys/db b/sys/db index 93ddd7b..35b21c3 160000 --- a/sys/db +++ b/sys/db @@ -1 +1 @@ -Subproject commit 93ddd7baeccf9cdf703cf43026495b823cd6aefd +Subproject commit 35b21c31a54bfac28f02fd44bc0a6cd45c591674 diff --git a/sys/widgets/connection_manager.php b/sys/widgets/connection_manager.php new file mode 100644 index 0000000..7609832 --- /dev/null +++ b/sys/widgets/connection_manager.php @@ -0,0 +1,161 @@ +_layout($params); + } + + // -------------------------------------------------------------------------- + + /** + * Layout fields on the form + * + * @param array + */ + protected function _layout($params) + { + // Use a table-like sizer + $sizer = new \wxFlexGridSizer(2, 5, 5); + $sizer->SetFlexibleDirection(wxBOTH); + $sizer->AddGrowableCol(0, 1); + $sizer->AddGrowableCol(1, 1); + + $db_types = $this->get_available_dbs(); + + if ($db_types === FALSE) + { + error("No valid databases set up in PHP"); + return; + } + + // Create the controls + // label => control + $this->fields = array( + 'Connection name' => new \wxTextCtrl($this, self::TXT_CONN_NAME), + 'Database Type' => $choice = new \wxChoice(), + 'Database File' => new \wxFilePickerCtrl($this, self::FILE_DB_FILE, wxEmptyString, "Select the database file", wxFileSelectorDefaultWildcardStr), + 'Database Name' => new \wxTextCtrl($this, self::TXT_DB_NAME), + 'Host' => new \wxTextCtrl($this, self::TXT_DB_HOST), + 'Port' => new \wxTextCtrl($this, self::TXT_DB_PORT), + 'User' => new \wxTextCtrl($this, self::TXT_DB_USER), + 'Password' => new \wxTextCtrl($this, self::TXT_DB_PASS) + ); + + $choice->Create($this, self::COMBO_DB_TYPE, wxDefaultPosition, wxDefaultSize, $db_types); + + // Add the controls to the sizer + $i = 1; + foreach ($this->fields as $lbl => $ctrl) + { + $label = new \wxStaticText($this, $i, $lbl); + + $sizer->Add($label, 0, wxALIGN_LEFT); + $sizer->Add($ctrl, 1, wxALIGN_RIGHT|wxEXPAND); + + $i++; + } + + $this->SetSizer($sizer); + $this->Layout(); + + $this->Center(wxBOTH); + } + + // -------------------------------------------------------------------------- + + /** + * Get the list of available database types + * + * return array + */ + protected function get_available_dbs() + { + $drivers = array(); + + $pdo_drivers = \pdo_drivers(); + + // Add PDO drivers + foreach ($pdo_drivers as &$d) + { + // Skip sqlite2 as opposed to sqlite3 + if($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers))) + { + continue; + } + + // Use the ibase_functions over PDO::Firebird, at least for now + if($d === 'firebird') + { + continue; + } + + // Replace default capitalization with something that looks better. + $d = str_replace("sql", "SQL", $d); + $d = str_ireplace("pg", "Postgre", $d); + $d = str_ireplace("odbc", "ODBC", $d); + $d = ucfirst($d); + + $drivers[] = $d; + } + + // Add firebird support, if exists + if(function_exists('fbird_connect') && ! in_array('firebird', $pdo_drivers)) + { + $drivers[] = "Firebird"; + } + + sort($drivers); + + return $drivers; + } +} + +// End of connection_manager.php \ No newline at end of file diff --git a/sys/widgets/connection_sidebar.php b/sys/widgets/connection_sidebar.php index a378c8e..93d3716 100644 --- a/sys/widgets/connection_sidebar.php +++ b/sys/widgets/connection_sidebar.php @@ -21,7 +21,13 @@ namespace OpenSQLManager; * @package OpenSQLManager * @subpackage Widgets */ -class Connection_Sidebar extends \wxWindow { +class Connection_Sidebar extends \wxPanel { + + const MENU_CONNECT = 1; + const MENU_DISCONNECT = 2; + const MENU_EDIT_CONNECT = 3; + const MENU_DELETE_CONNECT = 4; + const BUTTON_ADD = 5; /** * Reference to Settings instance @@ -33,17 +39,10 @@ class Connection_Sidebar extends \wxWindow { /** * Reference to popup menu * - * @var GtkMenu + * @var wxMenu */ protected $menu; - /** - * Treeview for displaying connections - * - * @var GtkTreeView - */ - protected $treeview; - /** * Singleton instance * @@ -57,18 +56,26 @@ class Connection_Sidebar extends \wxWindow { * @var string */ private $conn_name; + + /** + * Reference to the list control that holds the connections + * + * @var wxListCtrl + */ + private $list; /** * Return the current instance of the class * + * @param wxWindow * @return Connection_Sidebar */ - public static function &get_instance() + public static function &get_instance($parent) { if( ! isset(self::$instance)) { $name = __CLASS__; - self::$instance = new $name(); + self::$instance = new $name($parent); } return self::$instance; @@ -78,24 +85,82 @@ class Connection_Sidebar extends \wxWindow { /** * Constructor method - */ - public function __construct() - { - parent::__construct(); - - $this->settings =& \Settings::get_instance(); - } - - // -------------------------------------------------------------------------- - - /** - * Renders the connection sidebar widget * + * @param wxWindow + */ + public function __construct($parent) + { + // Create the frame + parent::__construct($parent, 1); + + $this->list = new \wxListCtrl($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL); + $this->settings =& \Settings::get_instance(); + + // Create a button for adding new connections + $new_conn = new \wxButton($this, self::BUTTON_ADD, 'New Connection'); + $new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn')); + + // Add a sizer + $sizer = new \wxBoxSizer(wxVERTICAL); + $sizer->add($this->list, 1, wxALL|wxEXPAND); + $sizer->add($new_conn, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM|wxEXPAND); + + $this->SetSizer($sizer); + $this->Layout(); + + $this->Centre(wxBOTH); + } + + // -------------------------------------------------------------------------- + + /** + * Right-click event to create context menu + * + * @param wxEvent * @return void */ - protected function _render() + public function menu($event) { - + if ($this->list->GetCount() > 0 && $this->list->GetSelection() >= 0) + { + // Create the menu items + $menu = new \wxMenu(); + $menu->Append(self::MENU_EDIT_CONNECT, "Edit Connection", "Edit Connection Settings for the selected Database"); + $menu->Append(self::MENU_DELETE_CONNECT, "Delete Connection", "Remove the selected connection"); + + // Wire up the event handler + $menu->Connect(wxEVT_COMMAND_MENU_SELECTED, array($this, 'menu_event')); + + // Tell the object to show the menu + $this->list->PopupMenu($menu); + } + } + + // -------------------------------------------------------------------------- + + /** + * Handler for context menu options + * + * @param wxEvent + * @return void + */ + public function menu_event($event) + { + + } + + // -------------------------------------------------------------------------- + + /** + * Handles an event for adding a connection + * + * @param wxEvent + * @return void + */ + public function add_conn($event) + { + $win = new Connection_Manager($this); + $win->show(); } } diff --git a/sys/widgets/data_grid.php b/sys/widgets/data_grid.php index 7d44f7b..a0b9e0c 100644 --- a/sys/widgets/data_grid.php +++ b/sys/widgets/data_grid.php @@ -23,24 +23,19 @@ namespace OpenSQLManager; */ class Data_Grid extends \wxGrid { - /** - * GtkTreeStore object - * - * @var wxGridTableBase - */ - protected $model; - /** * Create the object * * @param object $model */ - public function __construct($model = null) + public function __construct($parent = NULL) { - if ( ! is_null($model)) + if ( ! is_null($parent)) { - $this->model = $model; - parent::__construct($this->model); + parent::__construct($parent, wxID_ANY); + $this->CreateGrid(0,0); + $this->HideColLabels(); + $this->HideRowLabels(); } else { diff --git a/sys/windows/main.php b/sys/windows/main.php index 7c57747..6a6c3c5 100644 --- a/sys/windows/main.php +++ b/sys/windows/main.php @@ -38,6 +38,13 @@ class Main extends \wxFrame { * @var Connection_Sidebar */ private $connection_sidebar; + + /** + * Reference to split window + * + * @var wxSplitterWindow + */ + protected $split; /** * Create and display the main window on startup @@ -46,8 +53,6 @@ class Main extends \wxFrame { { parent::__construct(NULL, NULL, PROGRAM_NAME, \wxDefaultPosition, new \wxSize(800, 600)); - //$this->SetSizeHints(wxDefaultSize, wxDefaultSize); - $this->_create_menu(); $sbar = $this->CreateStatusBar(2); @@ -122,24 +127,23 @@ class Main extends \wxFrame { { // Set up the main menu $this->_create_menu(); - + // Create a split window $win = new \wxSplitterWindow($this, wxID_ANY, wxDefaultPosition, wxDefaultSize); $win->setSplitMode(wxSPLIT_HORIZONTAL); - - // Add a sizer - $bSizer1 = new \wxBoxSizer(wxHORIZONTAL); - $bSizer1->Add($win, 1, wxALL|wxEXPAND, 0); - $this->SetSizer($bSizer1); - $this->Layout(); - $this->Centre(wxBOTH); + // Add the connection sidebar + $this->connection_sidebar =& Connection_Sidebar::get_instance($win); + $win2 = new Data_Grid($win); + + // Add the widgets to the split window + $win->SplitVertically($this->connection_sidebar, $win2); + $win->SetSashPosition(200, TRUE); - //$tabs = new \wxNotebook($win, 2); - - // Add the connection sidebar - $this->connection_sidebar =& Connection_Sidebar::get_instance(); + // Save a reference for later use + $this->split =& $win; + } // --------------------------------------------------------------------------