Database connection defaults / window resizing
This commit is contained in:
parent
f5ffccb0de
commit
7f37614b8c
@ -41,6 +41,13 @@ class Connection_Manager extends \wxFrame {
|
||||
*/
|
||||
protected $fields = array();
|
||||
|
||||
/**
|
||||
* Array of labels for Connection Information manipulation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $labels = array();
|
||||
|
||||
/**
|
||||
* Create the window
|
||||
*
|
||||
@ -100,13 +107,17 @@ class Connection_Manager extends \wxFrame {
|
||||
|
||||
$choice->Create($this, self::COMBO_DB_TYPE, wxDefaultPosition, wxDefaultSize, $db_types);
|
||||
|
||||
// Enable hiding/showing of controls based on choice
|
||||
$choice->Connect(wxEVT_COMMAND_CHOICE_SELECTED, array($this, 'change_db'));
|
||||
|
||||
// Add the controls to the sizer
|
||||
$i = 1;
|
||||
foreach ($this->fields as $lbl => $ctrl)
|
||||
{
|
||||
$label = new \wxStaticText($this, $i, $lbl);
|
||||
// Add the label to the labels array for later manipulation
|
||||
$this->labels[$lbl] = new \wxStaticText($this, $i, $lbl);
|
||||
|
||||
$sizer->Add($label, 0, wxALIGN_LEFT);
|
||||
$sizer->Add($this->labels[$lbl], 0, wxALIGN_LEFT);
|
||||
$sizer->Add($ctrl, 1, wxALIGN_RIGHT|wxEXPAND);
|
||||
|
||||
$i++;
|
||||
@ -118,7 +129,7 @@ class Connection_Manager extends \wxFrame {
|
||||
|
||||
// Add Connection Button
|
||||
$add_button = new \wxButton($this, self::BTN_ADD, 'Add Connection');
|
||||
$add_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn'));
|
||||
$add_button->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn'));
|
||||
|
||||
// Add the buttons to the sizer
|
||||
$sizer->Add($test_button, 1, wxEXPAND);
|
||||
@ -149,7 +160,7 @@ class Connection_Manager extends \wxFrame {
|
||||
$pdo_drivers = \pdo_drivers();
|
||||
|
||||
// Add PDO drivers
|
||||
foreach ($pdo_drivers as &$d)
|
||||
foreach ($pdo_drivers as $d)
|
||||
{
|
||||
// Skip sqlite2 as opposed to sqlite3
|
||||
if ($d === 'sqlite2' && (in_array('sqlite', $pdo_drivers) || in_array('sqlite3', $pdo_drivers)))
|
||||
@ -188,9 +199,10 @@ class Connection_Manager extends \wxFrame {
|
||||
/**
|
||||
* Adds a connection to the connection manager
|
||||
*
|
||||
* @param wxCommandEvent
|
||||
* @return void
|
||||
*/
|
||||
public function add_conn()
|
||||
public function add_conn($event)
|
||||
{
|
||||
$params = $this->_get_vals();
|
||||
|
||||
@ -208,11 +220,66 @@ class Connection_Manager extends \wxFrame {
|
||||
/**
|
||||
* Set defaults for new database type
|
||||
*
|
||||
* @param wxCommandEvent
|
||||
* @return void
|
||||
*/
|
||||
public function change_db()
|
||||
public function change_db($event)
|
||||
{
|
||||
$db = strtolower($event->GetString());
|
||||
$sizer = $this->GetSizer();
|
||||
|
||||
$fields =& $this->fields;
|
||||
|
||||
// Set defaults
|
||||
$this->_show(array(
|
||||
'Host',
|
||||
'Database Name',
|
||||
'Port',
|
||||
'User',
|
||||
'Password'
|
||||
));
|
||||
$this->_hide(array('Database File'));
|
||||
|
||||
$fields['Password']->SetValue('');
|
||||
$fields['Database Name']->SetValue('');
|
||||
$fields['Host']->SetValue('127.0.0.1');
|
||||
|
||||
// Set db-specific defaults
|
||||
switch($db)
|
||||
{
|
||||
case "mysql":
|
||||
$fields['User']->SetValue('root');
|
||||
$fields['Port']->SetValue('3306');
|
||||
break;
|
||||
|
||||
case "postgresql":
|
||||
$fields['User']->SetValue('postgres');
|
||||
$fields['Port']->SetValue('5432');
|
||||
break;
|
||||
|
||||
case "firebird":
|
||||
$fields['User']->SetValue('sysdba');
|
||||
$fields['Password']->SetValue('masterkey');
|
||||
$fields['Port']->SetValue('');
|
||||
$this->_show(array('Database File'));
|
||||
$this->_hide(array('Database Name'));
|
||||
break;
|
||||
|
||||
case "sqlite":
|
||||
$this->_show(array('Database File'));
|
||||
|
||||
$this->_hide(array(
|
||||
'Database Name',
|
||||
'Port',
|
||||
'Host',
|
||||
'User',
|
||||
'Password'
|
||||
));
|
||||
break;
|
||||
}
|
||||
|
||||
// Resize the window to fit the controls
|
||||
$sizer->Fit($this);
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
@ -282,6 +349,44 @@ class Connection_Manager extends \wxFrame {
|
||||
|
||||
return $params;
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Hides a list of elements
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
private function _hide($ctrls)
|
||||
{
|
||||
$f =& $this->fields;
|
||||
$l =& $this->labels;
|
||||
|
||||
foreach($ctrls as $c)
|
||||
{
|
||||
$f[$c]->Hide();
|
||||
$l[$c]->Hide();
|
||||
}
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Shows a list of elements
|
||||
*
|
||||
* @param array
|
||||
*/
|
||||
private function _show($ctrls)
|
||||
{
|
||||
$f =& $this->fields;
|
||||
$l =& $this->labels;
|
||||
|
||||
foreach($ctrls as $c)
|
||||
{
|
||||
$f[$c]->Show();
|
||||
$l[$c]->Show();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// End of connection_manager.php
|
Reference in New Issue
Block a user