Lots of layout improvements
This commit is contained in:
parent
094f797a38
commit
3dfa42b894
@ -1,7 +1,6 @@
|
||||
language: php
|
||||
|
||||
php:
|
||||
- 5.2
|
||||
- 5.3
|
||||
- 5.4
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
@ -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
|
2
sys/db
2
sys/db
@ -1 +1 @@
|
||||
Subproject commit 93ddd7baeccf9cdf703cf43026495b823cd6aefd
|
||||
Subproject commit 35b21c31a54bfac28f02fd44bc0a6cd45c591674
|
161
sys/widgets/connection_manager.php
Normal file
161
sys/widgets/connection_manager.php
Normal file
@ -0,0 +1,161 @@
|
||||
<?php
|
||||
/**
|
||||
* OpenSQLManager
|
||||
*
|
||||
* Free Database manager for Open Source Databases
|
||||
*
|
||||
* @package OpenSQLManager
|
||||
* @author Timothy J. Warren
|
||||
* @copyright Copyright (c) 2012
|
||||
* @link https://github.com/aviat4ion/OpenSQLManager
|
||||
* @license http://philsturgeon.co.uk/code/dbad-license
|
||||
*/
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
||||
namespace OpenSQLManager;
|
||||
|
||||
/**
|
||||
* Widget for adding / Editing Connections
|
||||
*
|
||||
* @package OpenSQLManager
|
||||
* @subpackage Widgets
|
||||
*/
|
||||
class Connection_Manager extends \wxFrame {
|
||||
|
||||
const TXT_CONN_NAME = 1;
|
||||
const COMBO_DB_TYPE = 2;
|
||||
const FILE_DB_FILE = 3;
|
||||
const TXT_DB_NAME = 4;
|
||||
const TXT_DB_HOST = 5;
|
||||
const TXT_DB_PORT = 6;
|
||||
const TXT_DB_USER = 7;
|
||||
const TXT_DB_PASS = 8;
|
||||
|
||||
/**
|
||||
* Array of fields for Connection Information manipulation
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fields = array();
|
||||
|
||||
/**
|
||||
* Create the window
|
||||
*
|
||||
* @param wxWindow
|
||||
* @param mixed
|
||||
*/
|
||||
public function __construct($parent, $params = array())
|
||||
{
|
||||
parent::__construct($parent, 32, "Connection Manager", wxDefaultPosition, new \wxSize(640, 480));//, wxCAPTION|wxCLOSE_BOX);
|
||||
|
||||
// Layout the window
|
||||
$this->_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
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
{
|
||||
|
@ -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;
|
||||
|
||||
}
|
||||
|
||||
// --------------------------------------------------------------------------
|
||||
|
Reference in New Issue
Block a user