1
//////////////////////////////////////////////////////////////////////////
3
// pgAdmin III - PostgreSQL Tools
4
// RCS-ID: $Id: events.cpp,v 1.119 2004/10/27 18:50:28 andreas Exp $
5
// Copyright (C) 2002 - 2004, The pgAdmin Development Team
6
// This software is released under the Artistic Licence
8
// events.cpp - Event handlers for frmMain
11
//////////////////////////////////////////////////////////////////////////
17
#include <wx/splitter.h>
18
#include <wx/settings.h>
19
#include <wx/treectrl.h>
20
#include <wx/listctrl.h>
21
#include <wx/imaglist.h>
22
#include <wx/tipdlg.h>
23
#include <wx/stc/stc.h>
29
#include "dlgServer.h"
30
#include "frmOptions.h"
31
#include "frmPassword.h"
33
#include "frmStatus.h"
34
#include "ctlSQLBox.h"
36
#include "pgLanguage.h"
37
#include "pgDatabase.h"
42
#include "pgCollection.h"
43
#include "pgFunction.h"
44
#include "frmEditGrid.h"
46
#include "dlgProperty.h"
47
#include "frmMaintenance.h"
48
#include "frmBackup.h"
49
#include "frmRestore.h"
50
#include "frmIndexcheck.h"
51
#include "frmGrantWizard.h"
54
extern wxString loadPath;
58
BEGIN_EVENT_TABLE(frmMain, pgFrame)
59
EVT_MENU(MNU_SQL, frmMain::OnSql)
60
EVT_MENU(MNU_MAINTENANCE, frmMain::OnMaintenance)
61
EVT_MENU(MNU_INDEXCHECK, frmMain::OnIndexcheck)
62
EVT_MENU(MNU_GRANTWIZARD, frmMain::OnGrantWizard)
63
EVT_MENU(MNU_CONTENTS, frmMain::OnContents)
64
EVT_MENU(MNU_HELP, frmMain::OnHelp)
65
EVT_MENU(MNU_FAQ, frmMain::OnFaq)
66
EVT_MENU(MNU_PGSQLHELP, frmMain::OnPgsqlHelp)
67
EVT_MENU(MNU_ADDSERVER, frmMain::OnAddServer)
68
EVT_MENU(MNU_REFRESH, frmMain::OnRefresh)
69
EVT_MENU(MNU_CONNECT, frmMain::OnConnect)
70
EVT_MENU(MNU_DISCONNECT, frmMain::OnDisconnect)
71
EVT_MENU(MNU_DELETE, frmMain::OnDelete)
72
EVT_MENU(MNU_DROP, frmMain::OnDrop)
73
EVT_MENU(MNU_CREATE, frmMain::OnCreate)
74
EVT_MENU(MNU_PROPERTIES, frmMain::OnProperties)
75
EVT_MENU(MNU_STATUS, frmMain::OnStatus)
76
EVT_MENU(MNU_BACKUP, frmMain::OnBackup)
77
EVT_MENU(MNU_RESTORE, frmMain::OnRestore)
78
EVT_MENU(MNU_COUNT, frmMain::OnCount)
79
EVT_MENU(MNU_VIEWDATA, frmMain::OnViewData)
80
EVT_MENU(MNU_VIEWFILTEREDDATA, frmMain::OnViewFilteredData)
81
EVT_MENU(MNU_OPTIONS, frmMain::OnOptions)
82
EVT_MENU(MNU_PASSWORD, frmMain::OnPassword)
83
EVT_MENU(MNU_SAVEDEFINITION, frmMain::OnSaveDefinition)
84
EVT_MENU(MNU_SYSTEMOBJECTS, frmMain::OnShowSystemObjects)
85
EVT_MENU(MNU_TIPOFTHEDAY, frmMain::OnTipOfTheDay)
86
EVT_MENU(MNU_STARTSERVICE, frmMain::OnStartService)
87
EVT_MENU(MNU_STOPSERVICE, frmMain::OnStopService)
88
EVT_MENU(MNU_NEW+PG_DATABASE, frmMain::OnNew)
89
EVT_MENU(MNU_NEW+PG_USER, frmMain::OnNew)
90
EVT_MENU(MNU_NEW+PG_GROUP, frmMain::OnNew)
91
EVT_MENU(MNU_NEW+PG_LANGUAGE, frmMain::OnNew)
92
EVT_MENU(MNU_NEW+PG_CAST, frmMain::OnNew)
93
EVT_MENU(MNU_NEW+PG_SCHEMA, frmMain::OnNew)
94
EVT_MENU(MNU_NEW+PG_TABLESPACE, frmMain::OnNew)
95
EVT_MENU(MNU_NEW+PG_AGGREGATE, frmMain::OnNew)
96
EVT_MENU(MNU_NEW+PG_CONVERSION, frmMain::OnNew)
97
EVT_MENU(MNU_NEW+PG_DOMAIN, frmMain::OnNew)
98
EVT_MENU(MNU_NEW+PG_FUNCTION, frmMain::OnNew)
99
EVT_MENU(MNU_NEW+PG_TRIGGERFUNCTION, frmMain::OnNew)
100
EVT_MENU(MNU_NEW+PG_OPERATOR, frmMain::OnNew)
101
EVT_MENU(MNU_NEW+PG_OPERATORCLASS, frmMain::OnNew)
102
EVT_MENU(MNU_NEW+PG_SEQUENCE, frmMain::OnNew)
103
EVT_MENU(MNU_NEW+PG_TABLE, frmMain::OnNew)
104
EVT_MENU(MNU_NEW+PG_TYPE, frmMain::OnNew)
105
EVT_MENU(MNU_NEW+PG_VIEW, frmMain::OnNew)
106
EVT_MENU(MNU_NEW+PG_COLUMN, frmMain::OnNew)
107
EVT_MENU(MNU_NEW+PG_PRIMARYKEY, frmMain::OnNew)
108
EVT_MENU(MNU_NEW+PG_FOREIGNKEY, frmMain::OnNew)
109
EVT_MENU(MNU_NEW+PG_UNIQUE, frmMain::OnNew)
110
EVT_MENU(MNU_NEW+PG_CHECK, frmMain::OnNew)
111
EVT_MENU(MNU_NEW+PG_INDEX, frmMain::OnNew)
112
EVT_MENU(MNU_NEW+PG_RULE, frmMain::OnNew)
113
EVT_MENU(MNU_NEW+PG_TRIGGER, frmMain::OnNew)
114
EVT_MENU(MNU_NEW+PGA_JOB, frmMain::OnNew)
115
EVT_MENU(MNU_NEW+PGA_STEP, frmMain::OnNew)
116
EVT_MENU(MNU_NEW+PGA_SCHEDULE, frmMain::OnNew)
117
EVT_MENU(MNU_CHECKALIVE, frmMain::OnCheckAlive)
118
EVT_MENU(MNU_CONTEXTMENU, frmMain::OnContextMenu)
119
EVT_MENU(MNU_CONFIG, frmMain::OnConfig)
120
EVT_MENU(MNU_HBACONFIG, frmMain::OnHbaConfig)
121
EVT_NOTEBOOK_PAGE_CHANGED(CTL_NOTEBOOK, frmMain::OnPageChange)
122
EVT_LIST_ITEM_SELECTED(CTL_PROPVIEW, frmMain::OnPropSelChanged)
123
EVT_LIST_ITEM_ACTIVATED(CTL_PROPVIEW, frmMain::OnPropSelActivated)
124
EVT_LIST_ITEM_RIGHT_CLICK(CTL_PROPVIEW, frmMain::OnPropRightClick)
125
EVT_TREE_SEL_CHANGED(CTL_BROWSER, frmMain::OnTreeSelChanged)
126
EVT_TREE_ITEM_EXPANDING(CTL_BROWSER, frmMain::OnExpand)
127
EVT_TREE_ITEM_COLLAPSING(CTL_BROWSER, frmMain::OnCollapse)
128
EVT_TREE_ITEM_ACTIVATED(CTL_BROWSER, frmMain::OnSelActivated)
129
EVT_TREE_ITEM_RIGHT_CLICK(CTL_BROWSER, frmMain::OnSelRightClick)
130
EVT_CLOSE( frmMain::OnClose)
132
EVT_TREE_KEY_DOWN(CTL_BROWSER, frmMain::OnTreeKeyDown)
139
// unfortunately, under GTK we won't get the original wxKeyEvent
140
// to reset m_metaDown
141
void frmMain::OnTreeKeyDown(wxTreeEvent& event)
143
switch (event.GetKeyCode())
161
void frmMain::OnExit(wxCommandEvent& event)
163
Close(FALSE); // Allow sub windows to stop us
169
void frmMain::OnClose(wxCloseEvent& event)
172
windowList::Node *node;
173
while ((node=frames.GetFirst()) != NULL)
176
if (!fr->Close(!event.CanVeto()))
191
void frmMain::OnTipOfTheDay(wxCommandEvent& WXUNUSED(event))
193
extern wxString docPath;
194
extern wxLocale *locale;
198
file = docPath + wxT("/") + locale->GetCanonicalName() + wxT("/tips.txt");
200
if (!wxFile::Exists(file))
201
file = docPath + wxT("/en_US/tips.txt");
203
if (!wxFile::Exists(file)) {
204
wxLogError(_("Couldn't open a tips.txt file!"));
208
wxTipProvider *tipProvider = wxCreateFileTipProvider(file, settings->GetNextTipOfTheDay());
209
settings->SetShowTipOfTheDay(wxShowTip(this, tipProvider));
210
settings->SetNextTipOfTheDay(tipProvider->GetCurrentTip());
216
void frmMain::OnStartService(wxCommandEvent& WXUNUSED(event))
218
if (currentObject && currentObject->GetType() == PG_SERVER)
220
pgServer *server= (pgServer*)currentObject;
221
StartMsg(_("Starting service"));
222
bool rc = server->StartService();
224
execSelChange(server->GetId(), true);
230
void frmMain::OnStopService(wxCommandEvent& WXUNUSED(event))
232
if (currentObject && currentObject->GetType() == PG_SERVER)
234
pgServer *server= (pgServer*)currentObject;
235
wxMessageDialog msg(this, _("Are you sure you wish shutdown this server?"),
236
_("Stop service"), wxYES_NO | wxICON_QUESTION);
237
if (msg.ShowModal() != wxID_YES)
242
StartMsg(_("Stopping service"));
243
bool rc = server->StopService();
246
wxCommandEvent nullEvent;
247
OnDisconnect(nullEvent);
248
execSelChange(server->GetId(), true);
255
void frmMain::OnContents(wxCommandEvent& event)
257
DisplayHelp(this, wxT("index"));
261
void frmMain::OnPgsqlHelp(wxCommandEvent& event)
263
DisplaySqlHelp(this, wxT("index"));
267
void frmMain::OnFaq(wxCommandEvent& event)
269
frmHelp *h=new frmHelp(this);
271
if (!h->Load(wxT("http://www.pgadmin.org/pgadmin3/faq/")))
276
void frmMain::OnHelp(wxCommandEvent& event)
281
page=currentObject->GetHelpPage(true);
284
page = wxT("sql-commands");
286
DisplaySqlHelp(this, page);
290
void frmMain::OnOptions(wxCommandEvent& event)
292
frmOptions *winOptions = new frmOptions(this);
293
winOptions->Show(TRUE);
296
void frmMain::OnCollapse(wxTreeEvent &event)
299
// This is weird stuff, but somewhere comes a collapse after we have done
300
// connecting the server and expanding the tree.
301
// Possibly not necessary
302
if (event.GetItem() == denyCollapseItem)
305
denyCollapseItem=wxTreeItemId();
309
void frmMain::OnExpand(wxTreeEvent &event)
312
wxTreeItemId item=browser->GetFirstChild(event.GetItem(), cookie);
313
if (item && !browser->GetItemData(item))
315
// the expanding node has a dummy item.
316
// delete dummy item, and expand kids.
317
execSelChange(event.GetItem(), browser->GetSelection() == item);
319
// we don't have any kids, so don't expand
320
if (!browser->GetChildrenCount(event.GetItem()))
326
void frmMain::OnStatus(wxCommandEvent &event)
331
pgServer *server=currentObject->GetServer();
335
pgConn *conn = server->CreateConn();
338
wxString txt = wxT("pgAdmin III Server Status - ") + server->GetDescription()
339
+ wxT(" (") + server->GetName() + wxT(":") + NumToStr((long)server->GetPort()) + wxT(")");
341
frmStatus *status = new frmStatus(this, txt, conn);
342
frames.Append(status);
348
void frmMain::OnCount(wxCommandEvent &event)
350
if (currentObject && currentObject->GetType() == PG_TABLE)
352
((pgTable*)currentObject)->UpdateRows();
354
wxTreeItemId item=browser->GetSelection();
355
if (currentObject == (pgObject*)browser->GetItemData(item))
356
currentObject->ShowTreeDetail(0, 0, properties);
361
void frmMain::OnCheckAlive(wxCommandEvent &event)
367
void frmMain::OnPassword(wxCommandEvent& event)
369
frmPassword *winPassword = new frmPassword(this);
371
// We need to pass the server to the password form
372
// Get the item data, and feed it to the relevant handler,
376
int type = currentObject->GetType();
380
winPassword->SetServer((pgServer *)currentObject);
381
winPassword->Show(TRUE);
385
// Should never see this
386
wxLogError(__("You must select a server before changing your password!"));
393
void frmMain::OnMaintenance(wxCommandEvent &ev)
397
frmMaintenance *frm=new frmMaintenance(this, currentObject);
403
void frmMain::OnBackup(wxCommandEvent &event)
407
frmBackup *frm=new frmBackup(this, currentObject);
413
void frmMain::OnRestore(wxCommandEvent &event)
417
frmRestore *frm=new frmRestore(this, currentObject);
422
void frmMain::OnIndexcheck(wxCommandEvent &ev)
426
frmIndexcheck *frm=new frmIndexcheck(this, currentObject);
432
void frmMain::OnGrantWizard(wxCommandEvent &ev)
436
frmGrantWizard *frm=new frmGrantWizard(this, currentObject);
442
void frmMain::OnSql(wxCommandEvent &ev)
447
pgDatabase *db=currentObject->GetDatabase();
451
pgServer *server=db->GetServer();
452
pgConn *conn = db->CreateConn();
455
wxString txt = wxT("pgAdmin III Query - ") + server->GetDescription() + wxT(" (") + server->GetName() + wxT(":") + NumToStr((long)server->GetPort()) + wxT(") - ") + db->GetName();
458
if (settings->GetStickySql())
459
qry = sqlPane->GetText();
460
frmQuery *fq= new frmQuery(this, txt, conn, qry);
467
void frmMain::OnViewData(wxCommandEvent& event)
472
void frmMain::OnViewFilteredData(wxCommandEvent& event)
477
void frmMain::ViewData(bool filter)
481
if (currentObject->GetType() != PG_TABLE && currentObject->GetType() != PG_VIEW)
484
pgDatabase *db=((pgSchemaObject*)currentObject)->GetDatabase();
488
pgServer *server=db->GetServer();
489
pgConn *conn= db->CreateConn();
492
wxString txt = wxT("pgAdmin III Edit Data - ")
493
+ server->GetDescription()
494
+ wxT(" (") + server->GetName()
495
+ wxT(":") + NumToStr((long)server->GetPort())
496
+ wxT(") - ") + db->GetName()
497
+ wxT(" - ") + currentObject->GetFullIdentifier();
499
frmEditGrid *eg= new frmEditGrid(this, txt, conn, (pgSchemaObject*)currentObject);
501
eg->ShowForm(filter);
505
void frmMain::OnSaveDefinition(wxCommandEvent& event)
508
wxLogInfo(wxT("Saving object definition"));
510
if (sqlPane->GetText().IsNull()) {
511
wxLogError(__("There is nothing in the SQL pane to save!"));
515
wxFileDialog filename(this, _("Select output file"), wxT(""), wxT(""), _("SQL Scripts (*.sql)|*.sql|All files (*.*)|*.*"));
516
filename.SetStyle(wxSAVE | wxOVERWRITE_PROMPT);
519
if (filename.ShowModal() == wxID_OK)
522
if (!FileWrite(filename.GetPath(), sqlPane->GetText()))
523
wxLogError(__("Failed to write to the output file: %s"), filename.GetPath().c_str());
527
wxLogInfo(wxT("User cancelled"));
531
void frmMain::OnShowSystemObjects(wxCommandEvent& event)
536
wxMessageDialog *dlg;
537
if (settings->GetShowSystemObjects())
539
dlg=new wxMessageDialog(this,
540
_("System objects will not be removed from the object tree until a refresh is performed.\nClose all connections now?"),
541
_("Hide system objects"),
542
wxYES_NO|wxCANCEL | wxICON_QUESTION);
546
dlg=new wxMessageDialog(this,
547
_("System objects will not show in the the object tree until a refresh is performed.\nClose all connections now?"),
548
_("Show system objects"),
549
wxYES_NO|wxCANCEL | wxICON_QUESTION);
551
dlg->CenterOnParent();
555
if (rc == wxID_CANCEL)
557
viewMenu->Check(MNU_SYSTEMOBJECTS, settings->GetShowSystemObjects());
561
settings->SetShowSystemObjects(!settings->GetShowSystemObjects());
562
viewMenu->Check(MNU_SYSTEMOBJECTS, settings->GetShowSystemObjects());
566
wxLogInfo(wxT("Clearing treeview to toggle ShowSystemObjects"));
568
// Store the servers to prevent dropped ones reappearing in a minute.
571
// Clear the treeview
572
browser->DeleteAllItems();
575
pgObject *serversObj = new pgServers();
576
servers = browser->AddRoot(wxT("Servers"), PGICON_SERVER, -1, serversObj);
578
browser->Expand(servers);
579
browser->SelectItem(servers);
581
denyCollapseItem = servers;
587
void frmMain::OnAddServer(wxCommandEvent &ev)
591
dlgServer dlg(this, 0);
592
dlg.CenterOnParent();
594
while (rc != PGCONN_OK)
596
if (dlg.GoNew() != wxID_OK)
599
pgServer *server=(pgServer*)dlg.CreateObject(0);
601
rc = server->Connect(this, false, dlg.GetPassword());
607
wxLogInfo(wxT("pgServer object initialised as required."));
608
browser->AppendItem(servers, server->GetFullName(), PGICON_SERVER, -1, server);
609
browser->Expand(servers);
611
label.Printf(_("Servers (%d)"), browser->GetChildrenCount(servers, FALSE));
612
browser->SetItemText(servers, label);
624
wxLogError(__("Error connecting to the server: %s"), server->GetLastError().c_str());
631
wxLogInfo(__("pgServer object didn't initialise because the user aborted."));
640
void frmMain::OnPropSelChanged(wxListEvent& event)
642
wxTreeItemId item=browser->GetSelection();
643
pgObject *data=(pgObject*)browser->GetItemData(item);
644
if (data && data->IsCollection())
646
currentObject=((pgCollection*)data)->FindChild(browser, event.GetIndex());
649
setDisplay(currentObject);
650
sqlPane->SetReadOnly(false);
651
sqlPane->SetText(currentObject->GetSql(browser));
652
sqlPane->SetReadOnly(true);
658
void frmMain::OnPropSelActivated(wxListEvent& event)
660
if (currentObject && currentObject->CanEdit())
662
wxCommandEvent nullEvent;
663
OnProperties(nullEvent);
668
void frmMain::OnPropRightClick(wxListEvent& event)
670
OnPropSelChanged(event);
673
doPopup(properties, event.GetPoint(), currentObject);
677
void frmMain::OnTreeSelChanged(wxTreeEvent& event)
679
denyCollapseItem=wxTreeItemId();
680
// Reset the listviews/SQL pane
682
execSelChange(event.GetItem(), true);
686
void frmMain::execSelChange(wxTreeItemId item, bool currentNode)
690
properties->ClearAll();
691
properties->AddColumn(_("Properties"), 500);
692
properties->InsertItem(0, _("No properties are available for the current selection"), PGICON_PROPERTY);
695
// Reset the toolbar & password menu options
696
// Handle the menus associated with the buttons
700
// Get the item data, and feed it to the relevant handler,
702
currentObject = (pgObject *)browser->GetItemData(item);
704
// If we didn't get an object, then we may have a right click, or
705
// invalid click, so ignore.
706
if (!currentObject) return;
710
properties->Freeze();
711
statistics->Freeze();
712
setDisplay(currentObject, properties, sqlPane);
717
setDisplay(currentObject, 0, 0);
721
void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox)
723
data->RemoveDummyChild(browser);
725
int type = data->GetType();
735
canGrantWizard=false,
743
StartMsg(_("Retrieving server properties"));
745
server = (pgServer *)data;
747
if (server->GetServerControllable())
749
if (server->GetServerRunning())
754
if (!server->GetConnected())
763
data->ShowTree(this, browser, props, sqlbox);
776
case PG_TRIGGERFUNCTIONS:
807
case PG_TRIGGERFUNCTION:
808
case PG_OPERATORCLASSES:
809
case PG_OPERATORCLASS:
836
data->ShowTree(this, browser, props, sqlbox);
840
sqlbox->SetReadOnly(false);
841
sqlbox->SetText(data->GetSql(browser));
842
sqlbox->SetReadOnly(true);
845
pgConn *conn=data->GetConnection();
846
if (conn && conn->GetStatus() == PGCONN_BROKEN)
852
wxMenuItem *menuItem;
853
i=newMenu->GetMenuItemCount();
856
menuItem=newMenu->GetMenuItems().Item(i)->GetData();
858
delete newMenu->Remove(menuItem);
861
i=newContextMenu->GetMenuItemCount();
864
menuItem=newContextMenu->GetMenuItems().Item(i)->GetData();
866
delete newContextMenu->Remove(menuItem);
869
editMenu->Enable(MNU_NEWOBJECT, false);
871
wxMenu *indivMenu=data->GetNewMenu();
874
if (indivMenu->GetMenuItemCount())
876
editMenu->Enable(MNU_NEWOBJECT, true);
878
for (i=0 ; i < indivMenu->GetMenuItemCount() ; i++)
880
menuItem=indivMenu->GetMenuItems().Item(i)->GetData();
881
newMenu->Append(menuItem->GetId(), menuItem->GetLabel(), menuItem->GetHelp());
882
newContextMenu->Append(menuItem->GetId(), menuItem->GetLabel(), menuItem->GetHelp());
890
toolsMenu->Enable(MNU_CONNECT, canConnect);
891
toolsMenu->Enable(MNU_DISCONNECT, canDisconnect);
892
toolsMenu->Enable(MNU_GRANTWIZARD, canGrantWizard);
893
toolsMenu->Enable(MNU_STARTSERVICE, canStart);
894
toolsMenu->Enable(MNU_STOPSERVICE, canStop);
895
fileMenu->Enable(MNU_PASSWORD, canDisconnect);
896
viewMenu->Enable(MNU_COUNT, canCount);
897
// toolsMenu->Enable(MNU_INDEXCHECK, canIndexCheck);
901
void frmMain::OnConnect(wxCommandEvent &ev)
903
pgServer *server = (pgServer *)currentObject;
904
if (server && server->GetType() == PG_SERVER && !server->GetConnected())
905
ReconnectServer(server);
909
void frmMain::OnDisconnect(wxCommandEvent &ev)
911
pgServer *server = (pgServer *)currentObject;
912
if (server && server->GetType() == PG_SERVER && server->Disconnect())
914
browser->SetItemImage(server->GetId(), PGICON_SERVERBAD, wxTreeItemIcon_Normal);
915
browser->SetItemImage(server->GetId(), PGICON_SERVERBAD, wxTreeItemIcon_Selected);
916
browser->DeleteChildren(server->GetId());
917
execSelChange(server->GetId(), true);
922
void frmMain::OnSelActivated(wxTreeEvent &event)
924
// This handler will primarily deal with displaying item
925
// properties in seperate windows and 'Add xxx...' clicks
927
// Get the item data, and feed it to the relevant handler,
930
wxTreeItemId item = event.GetItem();
931
pgObject *data = (pgObject *)browser->GetItemData(item);
934
int type = data->GetType();
936
wxCommandEvent nullEvent;
941
server = (pgServer *)data;
942
if (!server->GetConnected())
944
if (ReconnectServer(server) == PGCONN_OK)
946
// prevent from being collapsed immediately
948
denyCollapseItem=item;
954
if (settings->GetDoubleClickProperties())
958
OnProperties(nullEvent);
967
browser->Expand(item);
972
void frmMain::appendIfEnabled(int id)
974
if (menuBar->IsEnabled(id))
976
wxMenuItem *menuItem=menuBar->FindItem(id);
978
treeContextMenu->Append(id, menuItem->GetLabel(), menuItem->GetHelp());
982
void frmMain::doPopup(wxWindow *win, wxPoint point, pgObject *object)
985
delete treeContextMenu;
987
treeContextMenu = new wxMenu();
989
if (object && (object->GetType() == PG_SERVER ||object->GetType() == PG_SERVERS))
991
appendIfEnabled(MNU_ADDSERVER);
992
appendIfEnabled(MNU_PASSWORD);
995
appendIfEnabled(MNU_REFRESH);
997
if (browser->GetSelection() == object->GetId())
998
appendIfEnabled(MNU_COUNT);
1002
wxMenu *indivMenu=object->GetNewMenu();
1005
if (indivMenu->GetMenuItemCount() > 1)
1007
wxMenuItem *menuItem = menuBar->FindItem(MNU_NEWOBJECT);
1008
treeContextMenu->Append(MNU_NEWOBJECT, menuItem->GetLabel(), indivMenu, menuItem->GetHelp());
1012
if (indivMenu->GetMenuItemCount() == 1)
1014
wxMenuItem *menuItem=indivMenu->GetMenuItems().Item(0)->GetData();
1015
treeContextMenu->Append(menuItem->GetId(), menuItem->GetLabel(), menuItem->GetHelp());
1022
int currentSize = treeContextMenu->GetMenuItemCount();
1024
appendIfEnabled(MNU_VIEWDATA);
1025
appendIfEnabled(MNU_VIEWFILTEREDDATA);
1026
appendIfEnabled(MNU_MAINTENANCE);
1027
// appendIfEnabled(MNU_INDEXCHECK);
1028
appendIfEnabled(MNU_BACKUP);
1029
appendIfEnabled(MNU_RESTORE);
1030
appendIfEnabled(MNU_GRANTWIZARD);
1031
appendIfEnabled(MNU_STARTSERVICE);
1032
appendIfEnabled(MNU_STOPSERVICE);
1033
appendIfEnabled(MNU_CONNECT);
1034
appendIfEnabled(MNU_DISCONNECT);
1036
int newSize = treeContextMenu->GetMenuItemCount();
1037
if (newSize > currentSize)
1039
treeContextMenu->InsertSeparator(currentSize);
1040
currentSize = newSize +1;
1043
appendIfEnabled(MNU_DROP);
1044
appendIfEnabled(MNU_PROPERTIES);
1047
newSize = treeContextMenu->GetMenuItemCount();
1048
if (newSize > currentSize)
1050
treeContextMenu->InsertSeparator(currentSize);
1051
currentSize = newSize +1;
1055
win->PopupMenu(treeContextMenu, point);
1058
////////////////////////////////////////////////////////////////////////////////
1059
// This handler will display a popup menu for the currently selected item
1060
////////////////////////////////////////////////////////////////////////////////
1061
void frmMain::OnContextMenu(wxCommandEvent& event)
1065
if (FindFocus() == browser)
1068
wxTreeItemId item=browser->GetSelection();
1070
browser->GetBoundingRect(item, rect);
1071
point = rect.GetPosition();
1072
wxPoint origin = GetClientAreaOrigin();
1074
// Because this Tree is inside a vertical splitter, we
1075
// must compensate for the size of the other elements
1076
point.x += origin.x;
1077
point.y += origin.y;
1079
doPopup(this, point, (pgObject*)browser->GetItemData(item));
1085
void frmMain::OnConfig(wxCommandEvent& event)
1090
void frmMain::OnHbaConfig(wxCommandEvent& event)
1095
////////////////////////////////////////////////////////////////////////////////
1096
// This handler will display a popup menu for the item at the mouse position
1097
////////////////////////////////////////////////////////////////////////////////
1098
void frmMain::OnSelRightClick(wxTreeEvent& event)
1100
wxTreeItemId item = event.GetItem();
1101
if (item != browser->GetSelection())
1103
browser->SelectItem(item);
1104
currentObject = (pgObject*)browser->GetItemData(item);
1108
doPopup(browser, event.GetPoint(), currentObject);
1112
void frmMain::OnDelete(wxCommandEvent &ev)
1118
void frmMain::OnDrop(wxCommandEvent &ev)
1120
wxTreeItemId item=browser->GetSelection();
1121
pgCollection *collection = (pgCollection*)browser->GetItemData(item);
1123
if (collection == currentObject)
1124
dropSingleObject(currentObject, true);
1127
if (collection && collection->IsCollection())
1129
long index=properties->GetFirstSelected();
1133
pgObject *data=collection->FindChild(browser, index);
1135
if (!data || !data->CanDrop())
1138
if (properties->GetSelectedItemCount() == 1)
1140
dropSingleObject(data, false);
1144
if (data->RequireDropConfirm() || settings->GetConfirmDelete())
1146
wxMessageDialog msg(this, _("Are you sure you wish to drop multiple objects?"),
1147
_("Drop multiple objects?"), wxYES_NO | wxICON_QUESTION);
1148
if (msg.ShowModal() != wxID_YES)
1156
while (done && data && index >= 0)
1158
if (data->GetSystemObject())
1160
wxMessageDialog msg(this, wxString::Format(_("Cannot drop system %s"),
1161
data->GetTranslatedTypeName().c_str(), ""),
1162
_("Trying to drop system object"), wxICON_EXCLAMATION);
1167
done = dropSingleObject(data, false);
1171
properties->DeleteItem(index);
1173
index = properties->GetFirstSelected();
1176
data=collection->FindChild(browser, index);
1180
Refresh(collection);
1187
bool frmMain::dropSingleObject(pgObject *data, bool updateFinal)
1191
// accelerator can bypass disabled menu, so we need to check
1192
if (!data || !data->CanDrop())
1195
if (data->GetSystemObject())
1197
wxMessageDialog msg(this, wxString::Format(_("Cannot drop system %s %s."),
1198
data->GetTranslatedTypeName().c_str(), data->GetFullIdentifier().c_str()),
1199
_("Trying to drop system object"), wxICON_EXCLAMATION);
1204
if (data->RequireDropConfirm() || settings->GetConfirmDelete())
1206
wxMessageDialog msg(this, wxString::Format(_("Are you sure you wish to drop %s %s?"),
1207
data->GetTranslatedTypeName().c_str(), data->GetFullIdentifier().c_str()),
1208
wxString::Format(_("Drop %s?"), data->GetTranslatedTypeName().c_str()), wxYES_NO | wxICON_QUESTION);
1209
if (msg.ShowModal() != wxID_YES)
1215
bool done=data->DropObject(this, browser);
1219
wxLogInfo(wxT("Dropping %s %s"), data->GetTypeName().c_str(), data->GetIdentifier().c_str());
1221
wxTreeItemId parentItem=browser->GetItemParent(data->GetId());
1225
wxTreeItemId nextItem=browser->GetNextVisible(data->GetId());
1228
pgObject *nextData=(pgObject*)browser->GetItemData(nextItem);
1229
if (!nextData || nextData->GetType() != data->GetType())
1230
nextItem=browser->GetPrevSibling(data->GetId());
1233
nextItem=browser->GetPrevSibling(data->GetId());
1236
browser->SelectItem(nextItem);
1238
int droppedType = data->GetType();
1239
browser->Delete(data->GetId());
1240
// data is invalid now
1245
pgCollection *collection=0;
1249
collection = (pgCollection*)browser->GetItemData(parentItem);
1250
if (collection && collection->IsCollection() && collection->IsCollectionForType(droppedType))
1252
collection->UpdateChildCount(browser);
1255
parentItem=browser->GetItemParent(parentItem);
1263
void frmMain::OnRefresh(wxCommandEvent &ev)
1265
// Refresh - Clear the treeview below the current selection
1266
// this doesn't use currentObject deliberately!
1268
wxTreeItemId item=browser->GetSelection();
1269
pgObject *data = (pgObject*)browser->GetItemData(item);
1277
void frmMain::OnCreate(wxCommandEvent &ev)
1281
if (!dlgProperty::CreateObjectDialog(this, currentObject, -1))
1287
void frmMain::OnNew(wxCommandEvent &ev)
1289
int type=ev.GetId() - MNU_NEW;
1290
if (type == PG_SERVER)
1298
if (!dlgProperty::CreateObjectDialog(this, currentObject, type))
1304
void frmMain::OnProperties(wxCommandEvent &ev)
1308
if (!dlgProperty::EditObjectDialog(this, sqlPane, currentObject))