This repository has been archived on 2018-10-12. You can view files and clone it, but cannot push or open issues or pull requests.
OpenSQLManager/sys/widgets/connection_sidebar.php

167 lines
3.5 KiB
PHP
Raw Normal View History

<?php
/**
* OpenSQLManager
*
* Free Database manager for Open Source Databases
*
2012-04-20 13:30:27 -04:00
* @package OpenSQLManager
* @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-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 {
const MENU_CONNECT = 1;
const MENU_DISCONNECT = 2;
const MENU_EDIT_CONNECT = 3;
const MENU_DELETE_CONNECT = 4;
const BUTTON_ADD = 5;
2012-04-19 12:29:47 -04:00
/**
* Reference to Settings instance
2012-04-19 21:55:44 -04:00
*
* @var Settings
2012-04-19 12:29:47 -04:00
*/
protected $settings;
/**
* Reference to popup menu
2012-04-19 21:55:44 -04:00
*
2012-05-30 16:41:33 -04:00
* @var wxMenu
2012-04-19 12:29:47 -04:00
*/
protected $menu;
/**
* Singleton instance
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-04-19 12:29:47 -04:00
/**
* Name of current db connection
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-30 16:41:33 -04:00
/**
* Reference to the list control that holds the connections
*
* @var wxListCtrl
*/
private $list;
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-05-30 16:41:33 -04:00
// Create the frame
parent::__construct($parent, 1);
$this->list = new \wxListCtrl($parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_LIST|wxLC_SINGLE_SEL);
2012-05-29 14:29:20 -04:00
$this->settings =& \Settings::get_instance();
2012-05-30 16:41:33 -04:00
// 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);
}
2012-05-30 16:41:33 -04:00
2012-03-26 12:55:52 -04:00
// --------------------------------------------------------------------------
2012-05-30 16:41:33 -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-05-30 16:41:33 -04:00
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();
2012-04-10 15:42:12 -04:00
}
}
2012-05-29 14:29:20 -04:00
2012-05-14 13:25:32 -04:00
// End of connection_sidebar.php