Miscellaneous improvements

This commit is contained in:
Timothy Warren 2012-05-31 14:18:37 -04:00
parent be82e2db00
commit 87fd4dfb98
5 changed files with 120 additions and 22 deletions

View File

@ -93,7 +93,7 @@ function exception_error_handler($errno, $errstr, $errfile, $errline)
// Do this after the two compatibility checks for cleaner output // Do this after the two compatibility checks for cleaner output
// Note that this will throw exceptions on notices // 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", -1);
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -139,7 +139,7 @@ function osm_autoload($class)
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
// Load everything so that we don't have to do requires later // Load everything so that we don't have to do requires later
require_once(BASE_DIR . '/common/functions.php'); array_map('OpenSQLManager\do_include', glob(BASE_DIR.'/common/*.php'));
spl_autoload_register('OpenSQLManager\osm_autoload'); spl_autoload_register('OpenSQLManager\osm_autoload');
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -179,6 +179,7 @@ class OpenSQLManager extends \wxApp {
*/ */
public function OnExit() public function OnExit()
{ {
\wxExit();
return 0; return 0;
} }
} }

View File

@ -69,7 +69,7 @@ class Settings {
{ {
//Create the file! //Create the file!
touch($path); touch($path);
$this->current = new stdClass(); $this->current = new \stdClass();
} }
else else
{ {
@ -79,7 +79,7 @@ class Settings {
// Add the DB object under the settings if it doesn't already exist // Add the DB object under the settings if it doesn't already exist
if( ! isset($this->current->dbs)) if( ! isset($this->current->dbs))
{ {
$this->current->dbs = new stdClass(); $this->current->dbs = new \stdClass();
} }
} }

View File

@ -27,7 +27,7 @@ class Connection_Sidebar extends \wxPanel {
const MENU_DISCONNECT = 2; const MENU_DISCONNECT = 2;
const MENU_EDIT_CONNECT = 3; const MENU_EDIT_CONNECT = 3;
const MENU_DELETE_CONNECT = 4; const MENU_DELETE_CONNECT = 4;
const BUTTON_ADD = 5; const BTN_ADD = 5;
/** /**
* Reference to Settings instance * Reference to Settings instance
@ -97,18 +97,17 @@ class Connection_Sidebar extends \wxPanel {
$this->settings =& Settings::get_instance(); $this->settings =& Settings::get_instance();
// Create a button for adding new connections // Create a button for adding new connections
$new_conn = new \wxButton($this, self::BUTTON_ADD, 'New Connection'); $new_conn = new \wxButton($this, self::BTN_ADD, 'New Connection');
$new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn')); $new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn'));
// Add a sizer // Add a sizer
$sizer = new \wxBoxSizer(wxVERTICAL); $sizer = new \wxBoxSizer(wxVERTICAL);
$sizer->add($this->list, 1, wxALL|wxEXPAND); $sizer->add($this->list, 1, wxALL|wxEXPAND);
$sizer->add($new_conn, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM|wxEXPAND); $sizer->add($new_conn, 0, wxALL|wxALIGN_CENTER_HORIZONTAL|wxALIGN_BOTTOM|wxEXPAND, 5);
$this->SetSizer($sizer); $this->SetSizer($sizer);
$this->Layout(); $this->Layout();
$this->Fit();
$this->Centre(wxBOTH);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------

View File

@ -31,6 +31,7 @@ class Connection_Manager extends \wxFrame {
const TXT_DB_PORT = 6; const TXT_DB_PORT = 6;
const TXT_DB_USER = 7; const TXT_DB_USER = 7;
const TXT_DB_PASS = 8; const TXT_DB_PASS = 8;
const BTN_TEST = 9;
/** /**
* Array of fields for Connection Information manipulation * Array of fields for Connection Information manipulation
@ -47,7 +48,7 @@ class Connection_Manager extends \wxFrame {
*/ */
public function __construct($parent, $params = array()) public function __construct($parent, $params = array())
{ {
parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition, new \wxSize(640, 480));//, wxCAPTION|wxCLOSE_BOX); parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition);
// Layout the window // Layout the window
$this->_layout($params); $this->_layout($params);
@ -62,8 +63,12 @@ class Connection_Manager extends \wxFrame {
*/ */
protected function _layout($params) protected function _layout($params)
{ {
$container_sizer = new \wxBoxSizer(wxVERTICAL);
// Use a table-like sizer // Use a table-like sizer
$sizer = new \wxFlexGridSizer(2, 5, 5); $sizer = new \wxFlexGridSizer(2, 5, 5);
$sizer->SetHGap(5);
$sizer->SetVGap(5);
$sizer->SetFlexibleDirection(wxBOTH); $sizer->SetFlexibleDirection(wxBOTH);
$sizer->AddGrowableCol(0, 1); $sizer->AddGrowableCol(0, 1);
$sizer->AddGrowableCol(1, 1); $sizer->AddGrowableCol(1, 1);
@ -79,9 +84,9 @@ class Connection_Manager extends \wxFrame {
// Create the controls // Create the controls
// label => control // label => control
$this->fields = array( $this->fields = array(
'Connection name' => new \wxTextCtrl($this, self::TXT_CONN_NAME), 'Connection Name' => new \wxTextCtrl($this, self::TXT_CONN_NAME),
'Database Type' => $choice = new \wxChoice(), 'Database Type' => $choice = new \wxChoice(),
'Database File' => new \wxFilePickerCtrl($this, self::FILE_DB_FILE, wxEmptyString, "Select the database file", wxFileSelectorDefaultWildcardStr), 'Database File' => new \wxFilePickerCtrl($this, self::FILE_DB_FILE, wxEmptyString, "Select the database file", '*.*'),
'Database Name' => new \wxTextCtrl($this, self::TXT_DB_NAME), 'Database Name' => new \wxTextCtrl($this, self::TXT_DB_NAME),
'Host' => new \wxTextCtrl($this, self::TXT_DB_HOST), 'Host' => new \wxTextCtrl($this, self::TXT_DB_HOST),
'Port' => new \wxTextCtrl($this, self::TXT_DB_PORT), 'Port' => new \wxTextCtrl($this, self::TXT_DB_PORT),
@ -103,10 +108,25 @@ class Connection_Manager extends \wxFrame {
$i++; $i++;
} }
$this->SetSizer($sizer); // Test Connection Button
$test_button = new \wxButton($this, self::BTN_TEST, 'Test Connection');
$test_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'test_conn'));
// Add Connection Button
// TODO: Add connection button
// Add the buttons to the sizer
$sizer->Add($test_button, 1, wxEXPAND);
// Add the sizer to the window
// Add it inside of another sizer for padding.
$container_sizer->Add($sizer, 1, wxALL|wxEXPAND, 10);
$this->SetSizer($container_sizer);
$this->Layout(); $this->Layout();
$this->Center(wxBOTH); // Autosize the window to fit the controls
$this->Fit();
$this->CenterOnScreen(wxBOTH);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -118,7 +138,7 @@ class Connection_Manager extends \wxFrame {
*/ */
protected function get_available_dbs() protected function get_available_dbs()
{ {
$drivers = array(); $drivers = array("");
$pdo_drivers = \pdo_drivers(); $pdo_drivers = \pdo_drivers();
@ -126,13 +146,13 @@ class Connection_Manager extends \wxFrame {
foreach ($pdo_drivers as &$d) foreach ($pdo_drivers as &$d)
{ {
// Skip sqlite2 as opposed to sqlite3 // Skip sqlite2 as opposed to sqlite3
if($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers))) if ($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers)))
{ {
continue; continue;
} }
// Use the ibase_functions over PDO::Firebird, at least for now // Use the ibase_functions over PDO::Firebird, at least for now
if($d === 'firebird') if ($d === 'firebird')
{ {
continue; continue;
} }
@ -147,7 +167,7 @@ class Connection_Manager extends \wxFrame {
} }
// Add firebird support, if exists // Add firebird support, if exists
if(function_exists('fbird_connect') && ! in_array('firebird', $pdo_drivers)) if (function_exists('fbird_connect'))
{ {
$drivers[] = "Firebird"; $drivers[] = "Firebird";
} }
@ -156,6 +176,84 @@ class Connection_Manager extends \wxFrame {
return $drivers; return $drivers;
} }
// --------------------------------------------------------------------------
/**
* Set defaults for new database type
*
* @return void
*/
public function change_db()
{
}
// --------------------------------------------------------------------------
/**
* Test a db connection, and display a popup with the result
*
* @return void
*/
public function test_conn()
{
// Get the connection parameters
$params = $this->_get_vals();
// Smart alek error for smart alek behavior
if (empty($params->type))
{
error("You need to select the correct database type");
return;
}
// Catch connection exceptions, and
// display the error message to the
// user so they can edit the db
// parameters
try
{
new \Query_Builder($params);
}
catch (\PDOException $e)
{
error("Error connecting to database: \n\n" . $e->getMessage());
return;
}
// Successful Connection?
// Tell the user!
alert("Successfully Connected.");
}
// --------------------------------------------------------------------------
/**
* Get the values of the widgets in the window
*
* @return object
*/
private function _get_vals()
{
$params = new \stdClass();
$fields =& $this->fields;
$types = $this->get_available_dbs();
$type_id = $fields['Database Type']->GetSelection();
$type = $types[$type_id];
$params->name = $fields['Connection Name']->GetValue();
$params->type = $type;
$params->file = $fields['Database File']->GetPath();
$params->conn_db = $fields['Database Name']->GetValue();
$params->host = $fields['Host']->GetValue();
$params->port = $fields['Port']->GetValue();
$params->user = $fields['User']->GetValue();
$params->pass = $fields['Password']->GetValue();
return $params;
}
} }
// End of connection_manager.php // End of connection_manager.php

View File

@ -62,6 +62,8 @@ class Main extends \wxFrame {
// Layout the interface // Layout the interface
$this->_main_layout(); $this->_main_layout();
$this->SetThemeEnabled(TRUE);
$this->CenterOnScreen(wxBOTH);
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------
@ -129,10 +131,9 @@ class Main extends \wxFrame {
$this->_create_menu(); $this->_create_menu();
// Create a split window // Create a split window
$win = new \wxSplitterWindow($this, wxID_ANY, wxDefaultPosition, wxDefaultSize); $win = new \wxSplitterWindow($this, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxSP_THIN_SASH);
$win->setSplitMode(wxSPLIT_HORIZONTAL); $win->setSplitMode(wxSPLIT_HORIZONTAL);
// Add the connection sidebar // Add the connection sidebar
$this->connection_sidebar =& Connection_Sidebar::get_instance($win); $this->connection_sidebar =& Connection_Sidebar::get_instance($win);
$win2 = new Data_Grid($win); $win2 = new Data_Grid($win);
@ -143,7 +144,6 @@ class Main extends \wxFrame {
// Save a reference for later use // Save a reference for later use
$this->split =& $win; $this->split =& $win;
} }
// -------------------------------------------------------------------------- // --------------------------------------------------------------------------