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

241 lines
5.0 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-11-27 09:47:27 -05:00
* @license https://timshomepage.net/dbaj.txt
*/
// --------------------------------------------------------------------------
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-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;
/**
* Reference to the image list control that holds connection images
*
* @var wxImageList
*/
private $img_list;
/**
* 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)
{
$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-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
{
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
// --------------------------------------------------------------------------
/**
* Connect to the database for data display/manipulation
*
* @param wxEvent
* @return void
*/
public function open_connection($event)
{
$id = $event->GetId();
alert('Double click:' . $id);
}
// --------------------------------------------------------------------------
2012-06-04 16:49:30 -04:00
/**
* Add the existing items to the connection sidebar
*
* @return void
*/
public function _layout()
{
$this->list = new \wxListCtrl($this->parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxLC_SMALL_ICON | wxLC_SINGLE_SEL | wxLC_ALIGN_TOP);
$this->img_list = new \wxImageList(32, 32);
$this->settings =& Settings::get_instance();
$this->list->Connect(wxEVT_COMMAND_LIST_ITEM_RIGHT_CLICK, array($this, 'menu'));
$this->list->Connect(wxEVT_LEFT_DCLICK, array($this, 'open_connection'));
// Add Images to the Image list
foreach(glob(OSM_RESOURCE_DIR.'/images/*.xpm') as $path)
{
2012-11-28 10:11:03 -05:00
//$img = new \wxBitmap(file_get_contents($path));
//$this->img_list->Add($img);
}
// 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
}
// 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-05-29 14:29:20 -04:00
2012-05-14 13:25:32 -04:00
// End of connection_sidebar.php