2012-02-24 15:16:49 -05:00
|
|
|
<?php
|
|
|
|
/**
|
|
|
|
* OpenSQLManager
|
|
|
|
*
|
|
|
|
* Free Database manager for Open Source Databases
|
|
|
|
*
|
2012-04-20 13:30:27 -04:00
|
|
|
* @package OpenSQLManager
|
2012-02-24 15:16:49 -05:00
|
|
|
* @author Timothy J. Warren
|
|
|
|
* @copyright Copyright (c) 2012
|
|
|
|
* @link https://github.com/aviat4ion/OpenSQLManager
|
2012-03-28 09:57:57 -04:00
|
|
|
* @license http://philsturgeon.co.uk/code/dbad-license
|
2012-02-24 15:16:49 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-05-29 14:29:20 -04:00
|
|
|
namespace OpenSQLManager;
|
|
|
|
|
2012-03-28 09:57:57 -04:00
|
|
|
/**
|
|
|
|
* Widget managing saved database connections
|
2012-04-20 13:30:27 -04:00
|
|
|
*
|
|
|
|
* @package OpenSQLManager
|
|
|
|
* @subpackage Widgets
|
2012-03-28 09:57:57 -04:00
|
|
|
*/
|
2012-05-30 16:41:33 -04:00
|
|
|
class Connection_Sidebar extends \wxPanel {
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
const MENU_CONNECT = 1;
|
|
|
|
const MENU_DISCONNECT = 2;
|
|
|
|
const MENU_EDIT_CONNECT = 3;
|
2012-05-31 09:56:49 -04:00
|
|
|
const MENU_DELETE_CONNECT = 4;
|
2012-05-31 14:18:37 -04:00
|
|
|
const BTN_ADD = 5;
|
2012-02-24 15:16:49 -05:00
|
|
|
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Reference to Settings instance
|
2012-05-31 09:56:49 -04:00
|
|
|
*
|
2012-04-19 21:55:44 -04:00
|
|
|
* @var Settings
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
|
|
|
protected $settings;
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Reference to popup menu
|
2012-05-31 09:56:49 -04:00
|
|
|
*
|
2012-05-30 16:41:33 -04:00
|
|
|
* @var wxMenu
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
|
|
|
protected $menu;
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Singleton instance
|
2012-05-31 09:56:49 -04:00
|
|
|
*
|
2012-04-19 21:55:44 -04:00
|
|
|
* @var Connection_Sidebar
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
2012-02-28 10:38:13 -05:00
|
|
|
private static $instance;
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-04-19 12:29:47 -04:00
|
|
|
/**
|
|
|
|
* Name of current db connection
|
2012-05-31 09:56:49 -04:00
|
|
|
*
|
2012-04-19 21:55:44 -04:00
|
|
|
* @var string
|
2012-04-19 12:29:47 -04:00
|
|
|
*/
|
2012-04-10 15:42:12 -04:00
|
|
|
private $conn_name;
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
/**
|
|
|
|
* Reference to the list control that holds the connections
|
|
|
|
*
|
|
|
|
* @var wxListCtrl
|
|
|
|
*/
|
|
|
|
private $list;
|
2012-11-27 09:34:38 -05:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Reference to the parent of the current object
|
|
|
|
*
|
|
|
|
* @var object
|
|
|
|
*/
|
|
|
|
public $parent;
|
2012-02-24 17:53:16 -05:00
|
|
|
|
2012-03-26 12:55:52 -04:00
|
|
|
/**
|
|
|
|
* Return the current instance of the class
|
|
|
|
*
|
2012-05-30 16:41:33 -04:00
|
|
|
* @param wxWindow
|
2012-03-26 12:55:52 -04:00
|
|
|
* @return Connection_Sidebar
|
|
|
|
*/
|
2012-05-30 16:41:33 -04:00
|
|
|
public static function &get_instance($parent)
|
2012-02-28 10:38:13 -05:00
|
|
|
{
|
|
|
|
if( ! isset(self::$instance))
|
|
|
|
{
|
|
|
|
$name = __CLASS__;
|
2012-05-30 16:41:33 -04:00
|
|
|
self::$instance = new $name($parent);
|
2012-02-28 10:38:13 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
return self::$instance;
|
|
|
|
}
|
|
|
|
|
2012-03-26 12:55:52 -04:00
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
2012-02-28 10:38:13 -05:00
|
|
|
/**
|
|
|
|
* Constructor method
|
2012-05-30 16:41:33 -04:00
|
|
|
*
|
|
|
|
* @param wxWindow
|
2012-02-28 10:38:13 -05:00
|
|
|
*/
|
2012-05-30 16:41:33 -04:00
|
|
|
public function __construct($parent)
|
2012-02-24 15:16:49 -05:00
|
|
|
{
|
2012-11-27 09:34:38 -05:00
|
|
|
$this->parent =& $parent;
|
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
// Create the frame
|
|
|
|
parent::__construct($parent, 1);
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-06-04 16:49:30 -04:00
|
|
|
// Layout the connection list
|
|
|
|
$this->_layout();
|
2012-02-24 15:16:49 -05:00
|
|
|
}
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-03-26 12:55:52 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-02-28 10:38:13 -05:00
|
|
|
/**
|
2012-05-30 16:41:33 -04:00
|
|
|
* Right-click event to create context menu
|
2012-04-11 14:57:38 -04:00
|
|
|
*
|
2012-05-30 16:41:33 -04:00
|
|
|
* @param wxEvent
|
2012-04-11 14:57:38 -04:00
|
|
|
* @return void
|
2012-02-28 10:38:13 -05:00
|
|
|
*/
|
2012-05-30 16:41:33 -04:00
|
|
|
public function menu($event)
|
2012-02-28 10:38:13 -05:00
|
|
|
{
|
2012-06-06 16:26:06 -04:00
|
|
|
if ($this->list->GetSelectedItemCount() > 0)
|
2012-05-30 16:41:33 -04:00
|
|
|
{
|
|
|
|
// 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");
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
// Wire up the event handler
|
|
|
|
$menu->Connect(wxEVT_COMMAND_MENU_SELECTED, array($this, 'menu_event'));
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
// Tell the object to show the menu
|
|
|
|
$this->list->PopupMenu($menu);
|
|
|
|
}
|
|
|
|
}
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
/**
|
|
|
|
* Handler for context menu options
|
|
|
|
*
|
|
|
|
* @param wxEvent
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function menu_event($event)
|
|
|
|
{
|
2012-08-14 13:41:38 -04:00
|
|
|
$id = $event->GetId();
|
|
|
|
|
|
|
|
switch($id)
|
|
|
|
{
|
|
|
|
case self::MENU_EDIT_CONNECT:
|
|
|
|
alert("Edit");
|
|
|
|
break;
|
|
|
|
|
|
|
|
case self::MENU_DELETE_CONNECT:
|
|
|
|
alert("Delete");
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
2012-05-30 16:41:33 -04:00
|
|
|
}
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
// --------------------------------------------------------------------------
|
2012-05-31 09:56:49 -04:00
|
|
|
|
2012-05-30 16:41:33 -04:00
|
|
|
/**
|
|
|
|
* Handles an event for adding a connection
|
|
|
|
*
|
|
|
|
* @param wxEvent
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function add_conn($event)
|
|
|
|
{
|
|
|
|
$win = new Connection_Manager($this);
|
|
|
|
$win->show();
|
2012-04-10 15:42:12 -04:00
|
|
|
}
|
2012-06-04 16:49:30 -04:00
|
|
|
|
|
|
|
// --------------------------------------------------------------------------
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Add the existing items to the connection sidebar
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
2012-11-27 09:34:38 -05:00
|
|
|
public function _layout()
|
|
|
|
{
|
|
|
|
$this->list = new \wxListCtrl($this->parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL);
|
|
|
|
$this->settings =& Settings::get_instance();
|
|
|
|
$this->list->Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, array($this, 'menu'));
|
|
|
|
|
|
|
|
// Create a button for adding new connections
|
|
|
|
$new_conn = new \wxButton($this, self::BTN_ADD, 'New Connection');
|
|
|
|
$new_conn->Connect(wxEVT_COMMAND_BUTTON_CLICKED, array($this, 'add_conn'));
|
|
|
|
|
2012-06-04 16:49:30 -04:00
|
|
|
// Add the actual connections
|
|
|
|
$conns = $this->settings->get_dbs();
|
|
|
|
|
|
|
|
foreach($conns as $c)
|
|
|
|
{
|
2012-06-05 16:53:03 -04:00
|
|
|
$this->list->InsertItem(0, $c->name);
|
2012-06-04 16:49:30 -04:00
|
|
|
}
|
2012-11-27 09:34:38 -05:00
|
|
|
|
|
|
|
// 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, 5);
|
|
|
|
|
|
|
|
$this->SetSizer($sizer);
|
|
|
|
$this->Layout();
|
|
|
|
$this->Fit();
|
2012-06-04 16:49:30 -04:00
|
|
|
}
|
2012-02-24 15:16:49 -05:00
|
|
|
}
|
2012-05-29 14:29:20 -04:00
|
|
|
|
2012-05-14 13:25:32 -04:00
|
|
|
// End of connection_sidebar.php
|