~ubuntu-branches/ubuntu/utopic/pgadmin3/utopic

« back to all changes in this revision

Viewing changes to src/ui/events.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Raphael Enrici, src/frm/frmBackup.cpp, debian/control
  • Date: 2006-10-06 21:06:48 UTC
  • mfrom: (1.2.1 upstream) (2.1.2 edgy)
  • Revision ID: james.westby@ubuntu.com-20061006210648-nscnazrse5jbwswf
* Patched frmBackup.cpp to ensure the schema is specified when backing up
  individual tables. (Closes: #387256)
  [src/frm/frmBackup.cpp]
* Cleaned up and updated description of the package. (Closes: #379188)
  [debian/control]

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//////////////////////////////////////////////////////////////////////////
2
 
//
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
7
 
//
8
 
// events.cpp - Event handlers for frmMain
9
 
//
10
 
//
11
 
//////////////////////////////////////////////////////////////////////////
12
 
 
13
 
#include "pgAdmin3.h"
14
 
 
15
 
// wxWindows headers
16
 
#include <wx/wx.h>
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>
24
 
 
25
 
// App headers
26
 
#include "misc.h"
27
 
#include "menu.h"
28
 
#include "frmMain.h"
29
 
#include "dlgServer.h"
30
 
#include "frmOptions.h"
31
 
#include "frmPassword.h"
32
 
#include "frmQuery.h"
33
 
#include "frmStatus.h"
34
 
#include "ctlSQLBox.h"
35
 
#include "pgConn.h"
36
 
#include "pgLanguage.h"
37
 
#include "pgDatabase.h"
38
 
#include "pgSet.h"
39
 
#include "pgServer.h"
40
 
#include "pgObject.h"
41
 
#include "pgTable.h"
42
 
#include "pgCollection.h"
43
 
#include "pgFunction.h"
44
 
#include "frmEditGrid.h"
45
 
#include "frmHelp.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"
52
 
 
53
 
 
54
 
extern wxString loadPath;
55
 
 
56
 
 
57
 
// Event table
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)
131
 
#ifdef __WXGTK__
132
 
    EVT_TREE_KEY_DOWN(CTL_BROWSER,          frmMain::OnTreeKeyDown)
133
 
#endif
134
 
END_EVENT_TABLE()
135
 
 
136
 
 
137
 
 
138
 
 
139
 
// unfortunately, under GTK we won't get the original wxKeyEvent
140
 
// to reset m_metaDown
141
 
void frmMain::OnTreeKeyDown(wxTreeEvent& event)
142
 
{
143
 
    switch (event.GetKeyCode())
144
 
    {
145
 
        case WXK_F1:
146
 
            OnHelp(event);
147
 
            break;
148
 
        case WXK_F5:
149
 
            OnRefresh(event);
150
 
            break;
151
 
        case WXK_DELETE:
152
 
            OnDrop(event);
153
 
            break;
154
 
        default:
155
 
            event.Skip();
156
 
            break;
157
 
    }
158
 
}
159
 
 
160
 
 
161
 
void frmMain::OnExit(wxCommandEvent& event)
162
 
{
163
 
    Close(FALSE);   // Allow sub windows to stop us
164
 
    event.Skip();
165
 
}
166
 
 
167
 
 
168
 
 
169
 
void frmMain::OnClose(wxCloseEvent& event)
170
 
{
171
 
    wxWindow *fr;
172
 
    windowList::Node *node;
173
 
    while ((node=frames.GetFirst()) != NULL)
174
 
    {
175
 
        fr=node->GetData();
176
 
        if (!fr->Close(!event.CanVeto()))
177
 
        {
178
 
            if (event.CanVeto())
179
 
            {
180
 
                event.Veto();
181
 
                return;
182
 
            }
183
 
        }
184
 
        delete node;
185
 
        fr->Destroy();
186
 
    }
187
 
    Destroy();
188
 
}
189
 
 
190
 
 
191
 
void frmMain::OnTipOfTheDay(wxCommandEvent& WXUNUSED(event))
192
 
{
193
 
extern wxString docPath;
194
 
extern wxLocale *locale;
195
 
 
196
 
    wxString file;
197
 
    
198
 
    file = docPath + wxT("/") + locale->GetCanonicalName() + wxT("/tips.txt");
199
 
 
200
 
    if (!wxFile::Exists(file))
201
 
        file = docPath + wxT("/en_US/tips.txt");    
202
 
 
203
 
    if (!wxFile::Exists(file)) {
204
 
        wxLogError(_("Couldn't open a tips.txt file!"));
205
 
        return;
206
 
    }
207
 
 
208
 
    wxTipProvider *tipProvider = wxCreateFileTipProvider(file, settings->GetNextTipOfTheDay());
209
 
    settings->SetShowTipOfTheDay(wxShowTip(this, tipProvider));
210
 
    settings->SetNextTipOfTheDay(tipProvider->GetCurrentTip());
211
 
 
212
 
    delete tipProvider;
213
 
}
214
 
 
215
 
 
216
 
void frmMain::OnStartService(wxCommandEvent& WXUNUSED(event))
217
 
{
218
 
    if (currentObject && currentObject->GetType() == PG_SERVER)
219
 
    {
220
 
        pgServer *server= (pgServer*)currentObject;
221
 
        StartMsg(_("Starting service"));
222
 
        bool rc = server->StartService();
223
 
        if (rc)
224
 
            execSelChange(server->GetId(), true);
225
 
        EndMsg();
226
 
    }
227
 
}
228
 
 
229
 
 
230
 
void frmMain::OnStopService(wxCommandEvent& WXUNUSED(event))
231
 
{
232
 
    if (currentObject && currentObject->GetType() == PG_SERVER)
233
 
    {
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)
238
 
        {
239
 
            return;
240
 
        }
241
 
 
242
 
        StartMsg(_("Stopping service"));
243
 
        bool rc = server->StopService();
244
 
        if (rc)
245
 
                {
246
 
                        wxCommandEvent nullEvent;
247
 
                        OnDisconnect(nullEvent);
248
 
            execSelChange(server->GetId(), true);
249
 
                }
250
 
        EndMsg();
251
 
    }
252
 
}
253
 
 
254
 
 
255
 
void frmMain::OnContents(wxCommandEvent& event)
256
 
{
257
 
    DisplayHelp(this, wxT("index"));
258
 
}
259
 
 
260
 
 
261
 
void frmMain::OnPgsqlHelp(wxCommandEvent& event)
262
 
{
263
 
    DisplaySqlHelp(this, wxT("index"));
264
 
}
265
 
 
266
 
 
267
 
void frmMain::OnFaq(wxCommandEvent& event)
268
 
{
269
 
    frmHelp *h=new frmHelp(this);
270
 
    h->Show(true);
271
 
    if (!h->Load(wxT("http://www.pgadmin.org/pgadmin3/faq/")))
272
 
        h->Destroy();
273
 
}
274
 
 
275
 
 
276
 
void frmMain::OnHelp(wxCommandEvent& event)
277
 
{
278
 
    wxString page;
279
 
 
280
 
    if (currentObject)
281
 
        page=currentObject->GetHelpPage(true);
282
 
 
283
 
    if (page.IsEmpty())
284
 
        page = wxT("sql-commands");
285
 
 
286
 
    DisplaySqlHelp(this, page);
287
 
}
288
 
 
289
 
 
290
 
void frmMain::OnOptions(wxCommandEvent& event)
291
 
{
292
 
    frmOptions *winOptions = new frmOptions(this);
293
 
    winOptions->Show(TRUE);
294
 
}
295
 
 
296
 
void frmMain::OnCollapse(wxTreeEvent &event)
297
 
{
298
 
#ifdef WIN32
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)
303
 
        event.Veto();
304
 
#endif
305
 
    denyCollapseItem=wxTreeItemId();
306
 
}
307
 
 
308
 
 
309
 
void frmMain::OnExpand(wxTreeEvent &event)
310
 
{
311
 
    wxCookieType cookie;
312
 
    wxTreeItemId item=browser->GetFirstChild(event.GetItem(), cookie);
313
 
    if (item && !browser->GetItemData(item))
314
 
    {
315
 
        // the expanding node has a dummy item.
316
 
        // delete dummy item, and expand kids.
317
 
        execSelChange(event.GetItem(), browser->GetSelection() == item);
318
 
 
319
 
        // we don't have any kids, so don't expand
320
 
        if (!browser->GetChildrenCount(event.GetItem()))
321
 
            event.Veto();
322
 
    }
323
 
}
324
 
 
325
 
 
326
 
void frmMain::OnStatus(wxCommandEvent &event)
327
 
{
328
 
    if (!currentObject)
329
 
        return;
330
 
 
331
 
    pgServer *server=currentObject->GetServer();
332
 
    if (!server)
333
 
        return;
334
 
 
335
 
    pgConn *conn = server->CreateConn();
336
 
    if (conn)
337
 
    {
338
 
        wxString txt = wxT("pgAdmin III Server Status - ") + server->GetDescription() 
339
 
            + wxT(" (") + server->GetName() + wxT(":") + NumToStr((long)server->GetPort()) + wxT(")");
340
 
 
341
 
        frmStatus *status = new frmStatus(this, txt, conn);
342
 
        frames.Append(status);
343
 
        status->Go();
344
 
    }
345
 
}
346
 
 
347
 
 
348
 
void frmMain::OnCount(wxCommandEvent &event)
349
 
{
350
 
    if (currentObject && currentObject->GetType() == PG_TABLE)
351
 
    {
352
 
        ((pgTable*)currentObject)->UpdateRows();
353
 
        
354
 
        wxTreeItemId item=browser->GetSelection();
355
 
        if (currentObject == (pgObject*)browser->GetItemData(item))
356
 
            currentObject->ShowTreeDetail(0, 0, properties);
357
 
    }
358
 
}
359
 
 
360
 
 
361
 
void frmMain::OnCheckAlive(wxCommandEvent &event)
362
 
{
363
 
    checkAlive();
364
 
}
365
 
 
366
 
 
367
 
void frmMain::OnPassword(wxCommandEvent& event)
368
 
{
369
 
    frmPassword *winPassword = new frmPassword(this);
370
 
 
371
 
    // We need to pass the server to the password form
372
 
    // Get the item data, and feed it to the relevant handler,
373
 
    // cast as required.
374
 
    if (currentObject)
375
 
    {
376
 
        int type = currentObject->GetType();
377
 
 
378
 
        switch (type) {
379
 
            case PG_SERVER:
380
 
                winPassword->SetServer((pgServer *)currentObject);
381
 
                winPassword->Show(TRUE);
382
 
                break;
383
 
 
384
 
            default:
385
 
                // Should never see this
386
 
                wxLogError(__("You must select a server before changing your password!"));
387
 
                break;
388
 
        }
389
 
    }
390
 
}
391
 
 
392
 
 
393
 
void frmMain::OnMaintenance(wxCommandEvent &ev)
394
 
{
395
 
    if (currentObject)
396
 
    {
397
 
        frmMaintenance *frm=new frmMaintenance(this, currentObject);
398
 
        frm->Go();
399
 
    }
400
 
}
401
 
 
402
 
 
403
 
void frmMain::OnBackup(wxCommandEvent &event)
404
 
{
405
 
    if (currentObject)
406
 
    {
407
 
        frmBackup *frm=new frmBackup(this, currentObject);
408
 
        frm->Go();
409
 
    }
410
 
}
411
 
 
412
 
 
413
 
void frmMain::OnRestore(wxCommandEvent &event)
414
 
{
415
 
    if (currentObject)
416
 
    {
417
 
        frmRestore *frm=new frmRestore(this, currentObject);
418
 
        frm->Go();
419
 
    }
420
 
}
421
 
 
422
 
void frmMain::OnIndexcheck(wxCommandEvent &ev)
423
 
{
424
 
    if (currentObject)
425
 
    {
426
 
        frmIndexcheck *frm=new frmIndexcheck(this, currentObject);
427
 
        frm->Go();
428
 
    }
429
 
}
430
 
 
431
 
 
432
 
void frmMain::OnGrantWizard(wxCommandEvent &ev)
433
 
{
434
 
    if (currentObject)
435
 
    {
436
 
        frmGrantWizard *frm=new frmGrantWizard(this, currentObject);
437
 
        frm->Go();
438
 
    }
439
 
}
440
 
 
441
 
 
442
 
void frmMain::OnSql(wxCommandEvent &ev)
443
 
{
444
 
    if (!currentObject)
445
 
        return;
446
 
 
447
 
    pgDatabase *db=currentObject->GetDatabase();
448
 
    if (!db)
449
 
        return;
450
 
 
451
 
    pgServer *server=db->GetServer();
452
 
    pgConn *conn = db->CreateConn();
453
 
    if (conn)
454
 
    {
455
 
        wxString txt = wxT("pgAdmin III Query - ") + server->GetDescription() + wxT(" (") + server->GetName() + wxT(":") + NumToStr((long)server->GetPort()) + wxT(") - ") + db->GetName();
456
 
 
457
 
        wxString qry;
458
 
        if (settings->GetStickySql()) 
459
 
            qry = sqlPane->GetText();
460
 
        frmQuery *fq= new frmQuery(this, txt, conn, qry);
461
 
        frames.Append(fq);
462
 
        fq->Go();
463
 
    }
464
 
}
465
 
 
466
 
 
467
 
void frmMain::OnViewData(wxCommandEvent& event)
468
 
{
469
 
        ViewData(false);
470
 
}
471
 
 
472
 
void frmMain::OnViewFilteredData(wxCommandEvent& event)
473
 
{
474
 
        ViewData(true);
475
 
}
476
 
 
477
 
void frmMain::ViewData(bool filter)
478
 
{
479
 
    if (!currentObject)
480
 
        return;
481
 
    if (currentObject->GetType() != PG_TABLE && currentObject->GetType() != PG_VIEW)
482
 
        return;
483
 
 
484
 
    pgDatabase *db=((pgSchemaObject*)currentObject)->GetDatabase();
485
 
    if (!db)
486
 
        return;
487
 
 
488
 
    pgServer *server=db->GetServer();
489
 
    pgConn *conn= db->CreateConn();
490
 
    if (conn)
491
 
    {
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();
498
 
 
499
 
        frmEditGrid *eg= new frmEditGrid(this, txt, conn, (pgSchemaObject*)currentObject);
500
 
        frames.Append(eg);
501
 
        eg->ShowForm(filter);
502
 
    }
503
 
}
504
 
 
505
 
void frmMain::OnSaveDefinition(wxCommandEvent& event)
506
 
{
507
 
 
508
 
    wxLogInfo(wxT("Saving object definition"));
509
 
 
510
 
    if (sqlPane->GetText().IsNull()) {
511
 
        wxLogError(__("There is nothing in the SQL pane to save!"));
512
 
        return;
513
 
    }
514
 
 
515
 
    wxFileDialog filename(this, _("Select output file"), wxT(""), wxT(""), _("SQL Scripts (*.sql)|*.sql|All files (*.*)|*.*"));
516
 
    filename.SetStyle(wxSAVE | wxOVERWRITE_PROMPT);
517
 
 
518
 
    // Show the dialogue
519
 
    if (filename.ShowModal() == wxID_OK)
520
 
    {
521
 
        // Write the file
522
 
        if (!FileWrite(filename.GetPath(), sqlPane->GetText()))
523
 
            wxLogError(__("Failed to write to the output file: %s"), filename.GetPath().c_str());
524
 
    }
525
 
    else
526
 
    {
527
 
        wxLogInfo(wxT("User cancelled"));
528
 
    }
529
 
}
530
 
 
531
 
void frmMain::OnShowSystemObjects(wxCommandEvent& event)
532
 
{
533
 
    // Warn the user
534
 
    int rc;
535
 
 
536
 
        wxMessageDialog *dlg;
537
 
    if (settings->GetShowSystemObjects())
538
 
        {
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);
543
 
        }
544
 
    else
545
 
        {
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);
550
 
        }
551
 
        dlg->CenterOnParent();
552
 
        rc=dlg->ShowModal();
553
 
        delete dlg;
554
 
 
555
 
    if (rc == wxID_CANCEL)
556
 
    {
557
 
        viewMenu->Check(MNU_SYSTEMOBJECTS, settings->GetShowSystemObjects());
558
 
        return;
559
 
    }
560
 
 
561
 
    settings->SetShowSystemObjects(!settings->GetShowSystemObjects());
562
 
    viewMenu->Check(MNU_SYSTEMOBJECTS, settings->GetShowSystemObjects());
563
 
 
564
 
    if (rc == wxID_YES)
565
 
    {
566
 
        wxLogInfo(wxT("Clearing treeview to toggle ShowSystemObjects"));
567
 
 
568
 
                // Store the servers to prevent dropped ones reappearing in a minute.
569
 
                StoreServers();
570
 
 
571
 
        // Clear the treeview
572
 
        browser->DeleteAllItems();
573
 
 
574
 
        // Add the root node
575
 
        pgObject *serversObj = new pgServers();
576
 
        servers = browser->AddRoot(wxT("Servers"), PGICON_SERVER, -1, serversObj);
577
 
        RetrieveServers();
578
 
        browser->Expand(servers);
579
 
        browser->SelectItem(servers);
580
 
#ifdef __WIN32__
581
 
        denyCollapseItem = servers;
582
 
#endif
583
 
    }
584
 
}
585
 
 
586
 
 
587
 
void frmMain::OnAddServer(wxCommandEvent &ev)
588
 
{
589
 
    int rc = PGCONN_BAD;
590
 
    
591
 
    dlgServer dlg(this, 0);
592
 
    dlg.CenterOnParent();
593
 
 
594
 
    while (rc != PGCONN_OK)
595
 
    {
596
 
        if (dlg.GoNew() != wxID_OK)
597
 
            return;
598
 
 
599
 
        pgServer *server=(pgServer*)dlg.CreateObject(0);
600
 
 
601
 
        rc = server->Connect(this, false, dlg.GetPassword());
602
 
 
603
 
        switch (rc)
604
 
        {
605
 
            case PGCONN_OK:
606
 
            {
607
 
                wxLogInfo(wxT("pgServer object initialised as required."));
608
 
                browser->AppendItem(servers, server->GetFullName(), PGICON_SERVER, -1, server);
609
 
                browser->Expand(servers);
610
 
                wxString label;
611
 
                label.Printf(_("Servers (%d)"), browser->GetChildrenCount(servers, FALSE));
612
 
                browser->SetItemText(servers, label);
613
 
                StoreServers();
614
 
                return;
615
 
            }
616
 
            case PGCONN_DNSERR:
617
 
            {
618
 
                delete server;
619
 
                break;
620
 
            }
621
 
            case PGCONN_BAD:
622
 
            case PGCONN_BROKEN:
623
 
            {
624
 
                wxLogError(__("Error connecting to the server: %s"), server->GetLastError().c_str());
625
 
 
626
 
                delete server;
627
 
                break;
628
 
            }
629
 
            default:
630
 
            {
631
 
                wxLogInfo(__("pgServer object didn't initialise because the user aborted."));
632
 
                delete server;
633
 
                return;
634
 
            }
635
 
        }
636
 
    }
637
 
}
638
 
 
639
 
 
640
 
void frmMain::OnPropSelChanged(wxListEvent& event)
641
 
{
642
 
    wxTreeItemId item=browser->GetSelection();
643
 
    pgObject *data=(pgObject*)browser->GetItemData(item);
644
 
    if (data && data->IsCollection())
645
 
    {
646
 
        currentObject=((pgCollection*)data)->FindChild(browser, event.GetIndex());
647
 
        if (currentObject)
648
 
        {
649
 
            setDisplay(currentObject);
650
 
            sqlPane->SetReadOnly(false);
651
 
            sqlPane->SetText(currentObject->GetSql(browser));
652
 
            sqlPane->SetReadOnly(true);
653
 
        }
654
 
    }
655
 
}
656
 
 
657
 
 
658
 
void frmMain::OnPropSelActivated(wxListEvent& event)
659
 
{
660
 
    if (currentObject && currentObject->CanEdit())
661
 
    {
662
 
        wxCommandEvent nullEvent;
663
 
        OnProperties(nullEvent);
664
 
    }
665
 
}
666
 
 
667
 
 
668
 
void frmMain::OnPropRightClick(wxListEvent& event)
669
 
{
670
 
    OnPropSelChanged(event);
671
 
 
672
 
    if (currentObject)
673
 
        doPopup(properties, event.GetPoint(), currentObject);
674
 
}
675
 
 
676
 
 
677
 
void frmMain::OnTreeSelChanged(wxTreeEvent& event)
678
 
{
679
 
    denyCollapseItem=wxTreeItemId();
680
 
        // Reset the listviews/SQL pane
681
 
    if (event.GetItem())
682
 
        execSelChange(event.GetItem(), true);
683
 
}
684
 
 
685
 
 
686
 
void frmMain::execSelChange(wxTreeItemId item, bool currentNode)
687
 
{
688
 
    if (currentNode)
689
 
    {
690
 
        properties->ClearAll();
691
 
        properties->AddColumn(_("Properties"), 500);
692
 
        properties->InsertItem(0, _("No properties are available for the current selection"), PGICON_PROPERTY);
693
 
        sqlPane->Clear();
694
 
 
695
 
        // Reset the toolbar & password menu options
696
 
            // Handle the menus associated with the buttons
697
 
        SetButtons(0);
698
 
    }
699
 
 
700
 
    // Get the item data, and feed it to the relevant handler,
701
 
    // cast as required.
702
 
    currentObject = (pgObject *)browser->GetItemData(item);
703
 
 
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;
707
 
 
708
 
    if (currentNode)
709
 
    {
710
 
        properties->Freeze();
711
 
        statistics->Freeze();
712
 
        setDisplay(currentObject, properties, sqlPane);
713
 
        properties->Thaw();
714
 
        statistics->Thaw();
715
 
    }
716
 
    else
717
 
        setDisplay(currentObject, 0, 0);
718
 
}
719
 
 
720
 
 
721
 
void frmMain::setDisplay(pgObject *data, ctlListView *props, ctlSQLBox *sqlbox)
722
 
{
723
 
    data->RemoveDummyChild(browser);
724
 
 
725
 
    int type = data->GetType();
726
 
    pgServer *server=0;
727
 
 
728
 
 
729
 
    bool canStart=false,
730
 
         canStop=false,
731
 
         canConnect=false,
732
 
         canDisconnect=false,
733
 
         canReindex=false,
734
 
         canIndexCheck=false,
735
 
         canGrantWizard=false,
736
 
         canCount=false;
737
 
 
738
 
    bool showTree=true;
739
 
 
740
 
    switch (type)
741
 
    {
742
 
        case PG_SERVER:
743
 
            StartMsg(_("Retrieving server properties"));
744
 
 
745
 
            server = (pgServer *)data;
746
 
 
747
 
            if (server->GetServerControllable())
748
 
            {
749
 
                if (server->GetServerRunning())
750
 
                    canStop = true;
751
 
                else
752
 
                    canStart = true;
753
 
            }
754
 
            if (!server->GetConnected())
755
 
            {
756
 
                canConnect=true;
757
 
            }
758
 
                        else
759
 
            {
760
 
                canDisconnect=true;
761
 
                canReindex=true;
762
 
            }
763
 
            data->ShowTree(this, browser, props, sqlbox);
764
 
            showTree=false;
765
 
            EndMsg();
766
 
            break;
767
 
 
768
 
        case PG_DATABASE:
769
 
        case PG_SCHEMAS:
770
 
        case PG_SCHEMA:
771
 
        case PG_TABLES:
772
 
            canIndexCheck=true;
773
 
            canGrantWizard=true;
774
 
            break;
775
 
        case PG_FUNCTIONS:
776
 
        case PG_TRIGGERFUNCTIONS:
777
 
        case PG_SEQUENCES:
778
 
        case PG_VIEWS:
779
 
            canGrantWizard=true;
780
 
            break;
781
 
        case PG_TABLE:
782
 
            canCount=true;
783
 
        case PG_CONSTRAINTS:
784
 
        case PG_FOREIGNKEY:
785
 
            canIndexCheck=true;
786
 
            break;
787
 
        case PG_DATABASES:
788
 
        case PG_GROUPS:
789
 
        case PG_USERS:
790
 
        case PG_GROUP:
791
 
        case PG_USER:
792
 
        case PG_LANGUAGES:
793
 
        case PG_LANGUAGE:
794
 
        case PG_TABLESPACES:
795
 
        case PG_TABLESPACE:
796
 
        case PG_AGGREGATES:
797
 
        case PG_AGGREGATE:
798
 
        case PG_CASTS:
799
 
        case PG_CAST:
800
 
        case PG_CONVERSIONS:
801
 
        case PG_CONVERSION:
802
 
        case PG_DOMAINS:
803
 
        case PG_DOMAIN:
804
 
        case PG_OPERATORS:
805
 
        case PG_OPERATOR:
806
 
        case PG_FUNCTION:
807
 
        case PG_TRIGGERFUNCTION:
808
 
        case PG_OPERATORCLASSES:
809
 
        case PG_OPERATORCLASS:
810
 
        case PG_SEQUENCE:
811
 
        case PG_TYPES:
812
 
        case PG_TYPE:
813
 
        case PG_VIEW:
814
 
        case PG_CHECK:
815
 
        case PG_COLUMNS:
816
 
        case PG_COLUMN:
817
 
        case PG_PRIMARYKEY:
818
 
        case PG_UNIQUE:
819
 
        case PG_INDEXES:
820
 
        case PG_INDEX:
821
 
        case PG_RULES:
822
 
        case PG_RULE:
823
 
        case PG_TRIGGERS:
824
 
        case PG_TRIGGER:
825
 
        case PGA_AGENT:
826
 
        case PGA_JOB:
827
 
        case PGA_STEP:
828
 
        case PGA_SCHEDULE:
829
 
            break;
830
 
        default:        
831
 
            showTree=false;
832
 
                        break;
833
 
    }
834
 
 
835
 
    if (showTree)
836
 
        data->ShowTree(this, browser, props, sqlbox);
837
 
 
838
 
    if (sqlbox)
839
 
    {
840
 
        sqlbox->SetReadOnly(false);
841
 
        sqlbox->SetText(data->GetSql(browser));
842
 
        sqlbox->SetReadOnly(true);
843
 
    }
844
 
 
845
 
    pgConn *conn=data->GetConnection();
846
 
    if (conn && conn->GetStatus() == PGCONN_BROKEN)
847
 
    {
848
 
        checkAlive();
849
 
        return;
850
 
    }
851
 
    unsigned int i;
852
 
    wxMenuItem *menuItem;
853
 
    i=newMenu->GetMenuItemCount();
854
 
    while (i--)
855
 
    {
856
 
        menuItem=newMenu->GetMenuItems().Item(i)->GetData();
857
 
        if (menuItem)
858
 
            delete newMenu->Remove(menuItem);
859
 
    }
860
 
 
861
 
    i=newContextMenu->GetMenuItemCount();
862
 
    while (i--)
863
 
    {
864
 
        menuItem=newContextMenu->GetMenuItems().Item(i)->GetData();
865
 
        if (menuItem)
866
 
            delete newContextMenu->Remove(menuItem);
867
 
    }
868
 
 
869
 
    editMenu->Enable(MNU_NEWOBJECT, false);
870
 
 
871
 
    wxMenu *indivMenu=data->GetNewMenu();
872
 
    if (indivMenu)
873
 
    {
874
 
        if (indivMenu->GetMenuItemCount())
875
 
        {
876
 
            editMenu->Enable(MNU_NEWOBJECT, true);
877
 
 
878
 
            for (i=0 ; i < indivMenu->GetMenuItemCount() ; i++)
879
 
            {
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());
883
 
            }
884
 
        }
885
 
        delete indivMenu;
886
 
    }
887
 
    else
888
 
    {
889
 
    }
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);
898
 
}
899
 
 
900
 
 
901
 
void frmMain::OnConnect(wxCommandEvent &ev)
902
 
{
903
 
    pgServer *server = (pgServer *)currentObject;
904
 
    if (server && server->GetType() == PG_SERVER && !server->GetConnected())
905
 
        ReconnectServer(server);
906
 
}
907
 
 
908
 
 
909
 
void frmMain::OnDisconnect(wxCommandEvent &ev)
910
 
{
911
 
    pgServer *server = (pgServer *)currentObject;
912
 
    if (server && server->GetType() == PG_SERVER && server->Disconnect())
913
 
    {
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);
918
 
    }
919
 
}
920
 
 
921
 
 
922
 
void frmMain::OnSelActivated(wxTreeEvent &event)
923
 
{
924
 
    // This handler will primarily deal with displaying item
925
 
    // properties in seperate windows and 'Add xxx...' clicks
926
 
 
927
 
    // Get the item data, and feed it to the relevant handler,
928
 
    // cast as required.
929
 
 
930
 
    wxTreeItemId item = event.GetItem();
931
 
    pgObject *data = (pgObject *)browser->GetItemData(item);
932
 
    if (!data)
933
 
        return;
934
 
    int type = data->GetType();
935
 
    pgServer *server;
936
 
    wxCommandEvent nullEvent;
937
 
 
938
 
    switch (type)
939
 
    {
940
 
        case PG_SERVER:
941
 
            server = (pgServer *)data;
942
 
            if (!server->GetConnected())
943
 
            {
944
 
                if (ReconnectServer(server) == PGCONN_OK)
945
 
                {
946
 
                    // prevent from being collapsed immediately
947
 
 
948
 
                    denyCollapseItem=item;
949
 
                }
950
 
            }
951
 
            break;
952
 
 
953
 
        default:
954
 
            if (settings->GetDoubleClickProperties())
955
 
            {
956
 
                if (data->CanEdit())
957
 
                {
958
 
                    OnProperties(nullEvent);
959
 
                    event.Skip();
960
 
                    return;
961
 
                }
962
 
            }
963
 
            break;
964
 
    }
965
 
 
966
 
#ifndef __WXMSW__
967
 
    browser->Expand(item);
968
 
#endif
969
 
}
970
 
 
971
 
 
972
 
void frmMain::appendIfEnabled(int id)
973
 
{
974
 
    if (menuBar->IsEnabled(id))
975
 
    {
976
 
        wxMenuItem *menuItem=menuBar->FindItem(id);
977
 
        if (menuItem)
978
 
            treeContextMenu->Append(id, menuItem->GetLabel(), menuItem->GetHelp());
979
 
    }
980
 
}
981
 
 
982
 
void frmMain::doPopup(wxWindow *win, wxPoint point, pgObject *object)
983
 
{
984
 
    if (treeContextMenu)
985
 
        delete treeContextMenu;
986
 
 
987
 
    treeContextMenu = new wxMenu();
988
 
 
989
 
    if (object && (object->GetType() == PG_SERVER ||object->GetType() == PG_SERVERS))
990
 
    {
991
 
        appendIfEnabled(MNU_ADDSERVER);
992
 
        appendIfEnabled(MNU_PASSWORD);
993
 
    }
994
 
 
995
 
    appendIfEnabled(MNU_REFRESH);
996
 
 
997
 
    if (browser->GetSelection() == object->GetId())
998
 
        appendIfEnabled(MNU_COUNT);
999
 
 
1000
 
    if (object)
1001
 
    {
1002
 
        wxMenu *indivMenu=object->GetNewMenu();
1003
 
        if (indivMenu)
1004
 
        {
1005
 
            if (indivMenu->GetMenuItemCount() > 1)
1006
 
            {
1007
 
                wxMenuItem *menuItem = menuBar->FindItem(MNU_NEWOBJECT);
1008
 
                treeContextMenu->Append(MNU_NEWOBJECT, menuItem->GetLabel(), indivMenu, menuItem->GetHelp());
1009
 
            }
1010
 
            else
1011
 
            {
1012
 
                if (indivMenu->GetMenuItemCount() == 1)
1013
 
                {
1014
 
                    wxMenuItem *menuItem=indivMenu->GetMenuItems().Item(0)->GetData();
1015
 
                    treeContextMenu->Append(menuItem->GetId(), menuItem->GetLabel(), menuItem->GetHelp());
1016
 
                }
1017
 
                delete indivMenu;
1018
 
            }
1019
 
        }
1020
 
    }
1021
 
 
1022
 
    int currentSize = treeContextMenu->GetMenuItemCount();
1023
 
 
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);
1035
 
 
1036
 
    int newSize = treeContextMenu->GetMenuItemCount();
1037
 
    if (newSize > currentSize)
1038
 
    {
1039
 
        treeContextMenu->InsertSeparator(currentSize);
1040
 
        currentSize = newSize +1;
1041
 
    }
1042
 
 
1043
 
    appendIfEnabled(MNU_DROP);
1044
 
    appendIfEnabled(MNU_PROPERTIES);
1045
 
 
1046
 
 
1047
 
    newSize = treeContextMenu->GetMenuItemCount();
1048
 
    if (newSize > currentSize)
1049
 
    {
1050
 
        treeContextMenu->InsertSeparator(currentSize);
1051
 
        currentSize = newSize +1;
1052
 
    }
1053
 
 
1054
 
    if (currentSize)
1055
 
        win->PopupMenu(treeContextMenu, point);
1056
 
}
1057
 
 
1058
 
////////////////////////////////////////////////////////////////////////////////
1059
 
// This handler will display a popup menu for the currently selected item
1060
 
////////////////////////////////////////////////////////////////////////////////
1061
 
void frmMain::OnContextMenu(wxCommandEvent& event)
1062
 
{
1063
 
    wxPoint point;
1064
 
 
1065
 
    if (FindFocus() == browser)
1066
 
    {
1067
 
        wxRect rect;
1068
 
        wxTreeItemId item=browser->GetSelection();
1069
 
 
1070
 
        browser->GetBoundingRect(item, rect);
1071
 
        point = rect.GetPosition();
1072
 
            wxPoint origin = GetClientAreaOrigin();
1073
 
 
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;
1078
 
 
1079
 
        doPopup(this, point, (pgObject*)browser->GetItemData(item));
1080
 
    }
1081
 
 
1082
 
}
1083
 
 
1084
 
 
1085
 
void frmMain::OnConfig(wxCommandEvent& event)
1086
 
{
1087
 
}
1088
 
 
1089
 
 
1090
 
void frmMain::OnHbaConfig(wxCommandEvent& event)
1091
 
{
1092
 
}
1093
 
 
1094
 
    
1095
 
////////////////////////////////////////////////////////////////////////////////
1096
 
// This handler will display a popup menu for the item at the mouse position
1097
 
////////////////////////////////////////////////////////////////////////////////
1098
 
void frmMain::OnSelRightClick(wxTreeEvent& event)
1099
 
{
1100
 
    wxTreeItemId item = event.GetItem();
1101
 
    if (item != browser->GetSelection())
1102
 
    {
1103
 
        browser->SelectItem(item);
1104
 
        currentObject = (pgObject*)browser->GetItemData(item);
1105
 
    }
1106
 
 
1107
 
    if (currentObject)
1108
 
        doPopup(browser, event.GetPoint(), currentObject);
1109
 
}
1110
 
 
1111
 
 
1112
 
void frmMain::OnDelete(wxCommandEvent &ev)
1113
 
{
1114
 
    OnDrop(ev);
1115
 
}
1116
 
 
1117
 
 
1118
 
void frmMain::OnDrop(wxCommandEvent &ev)
1119
 
{
1120
 
    wxTreeItemId item=browser->GetSelection();
1121
 
    pgCollection *collection = (pgCollection*)browser->GetItemData(item);
1122
 
 
1123
 
    if (collection == currentObject)
1124
 
        dropSingleObject(currentObject, true);
1125
 
    else
1126
 
    {
1127
 
        if (collection && collection->IsCollection())
1128
 
        {
1129
 
            long index=properties->GetFirstSelected();
1130
 
 
1131
 
            if (index >= 0)
1132
 
            {
1133
 
                pgObject *data=collection->FindChild(browser, index);
1134
 
 
1135
 
                if (!data || !data->CanDrop())
1136
 
                    return;
1137
 
 
1138
 
                if (properties->GetSelectedItemCount() == 1)
1139
 
                {
1140
 
                    dropSingleObject(data, false);
1141
 
                }
1142
 
                else
1143
 
                {
1144
 
                    if (data->RequireDropConfirm() || settings->GetConfirmDelete())
1145
 
                    {
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)
1149
 
                        {
1150
 
                            return;
1151
 
                        }
1152
 
                    }
1153
 
 
1154
 
                    bool done=true;
1155
 
                    long count=0;
1156
 
                    while (done && data && index >= 0)
1157
 
                    {
1158
 
                        if (data->GetSystemObject())
1159
 
                        {
1160
 
                            wxMessageDialog msg(this, wxString::Format(_("Cannot drop system %s"), 
1161
 
                                data->GetTranslatedTypeName().c_str(), ""), 
1162
 
                                _("Trying to drop system object"), wxICON_EXCLAMATION);
1163
 
                            msg.ShowModal();
1164
 
                            return;
1165
 
                        }
1166
 
 
1167
 
                        done = dropSingleObject(data, false);
1168
 
 
1169
 
                        if (done)
1170
 
                        {
1171
 
                            properties->DeleteItem(index);
1172
 
                            count++;
1173
 
                            index = properties->GetFirstSelected();
1174
 
 
1175
 
                            if (index >= 0)
1176
 
                                data=collection->FindChild(browser, index);
1177
 
                        }
1178
 
                    }
1179
 
                }
1180
 
                Refresh(collection);
1181
 
            }
1182
 
        }
1183
 
    }
1184
 
}
1185
 
 
1186
 
 
1187
 
bool frmMain::dropSingleObject(pgObject *data, bool updateFinal)
1188
 
{
1189
 
    if (updateFinal)
1190
 
    {
1191
 
        // accelerator can bypass disabled menu, so we need to check
1192
 
        if (!data || !data->CanDrop())
1193
 
            return false;
1194
 
 
1195
 
        if (data->GetSystemObject())
1196
 
        {
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);
1200
 
            msg.ShowModal();
1201
 
            return false;
1202
 
        }
1203
 
 
1204
 
        if (data->RequireDropConfirm() || settings->GetConfirmDelete())
1205
 
        {
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)
1210
 
            {
1211
 
                return false;
1212
 
            }
1213
 
        }
1214
 
    }
1215
 
    bool done=data->DropObject(this, browser);
1216
 
 
1217
 
    if (done)
1218
 
    {
1219
 
        wxLogInfo(wxT("Dropping %s %s"), data->GetTypeName().c_str(), data->GetIdentifier().c_str());
1220
 
 
1221
 
        wxTreeItemId parentItem=browser->GetItemParent(data->GetId());
1222
 
 
1223
 
        if (updateFinal)
1224
 
        {
1225
 
            wxTreeItemId nextItem=browser->GetNextVisible(data->GetId());
1226
 
            if (nextItem)
1227
 
            {
1228
 
                pgObject *nextData=(pgObject*)browser->GetItemData(nextItem);
1229
 
                if (!nextData || nextData->GetType() != data->GetType())
1230
 
                    nextItem=browser->GetPrevSibling(data->GetId());
1231
 
            }
1232
 
            else
1233
 
                nextItem=browser->GetPrevSibling(data->GetId());
1234
 
 
1235
 
            if (nextItem)
1236
 
                browser->SelectItem(nextItem);
1237
 
        }
1238
 
        int droppedType = data->GetType();
1239
 
        browser->Delete(data->GetId());
1240
 
        // data is invalid now
1241
 
 
1242
 
 
1243
 
        if (updateFinal)
1244
 
        {
1245
 
            pgCollection *collection=0;
1246
 
 
1247
 
            while (parentItem)
1248
 
            {
1249
 
                collection = (pgCollection*)browser->GetItemData(parentItem);
1250
 
                if (collection && collection->IsCollection() && collection->IsCollectionForType(droppedType))
1251
 
                {
1252
 
                    collection->UpdateChildCount(browser);
1253
 
                    break;
1254
 
                }
1255
 
                parentItem=browser->GetItemParent(parentItem);
1256
 
            }
1257
 
        }
1258
 
    }
1259
 
    return done;
1260
 
}
1261
 
 
1262
 
 
1263
 
void frmMain::OnRefresh(wxCommandEvent &ev)
1264
 
{
1265
 
    // Refresh - Clear the treeview below the current selection
1266
 
    // this doesn't use currentObject deliberately!
1267
 
 
1268
 
    wxTreeItemId item=browser->GetSelection();
1269
 
    pgObject *data = (pgObject*)browser->GetItemData(item);
1270
 
    if (!data)
1271
 
        return;
1272
 
 
1273
 
    Refresh(data);
1274
 
}
1275
 
 
1276
 
 
1277
 
void frmMain::OnCreate(wxCommandEvent &ev)
1278
 
{
1279
 
    if (currentObject)
1280
 
    {
1281
 
        if (!dlgProperty::CreateObjectDialog(this, currentObject, -1))
1282
 
            checkAlive();
1283
 
    }
1284
 
}
1285
 
 
1286
 
 
1287
 
void frmMain::OnNew(wxCommandEvent &ev)
1288
 
{
1289
 
    int type=ev.GetId() - MNU_NEW;
1290
 
    if (type == PG_SERVER)
1291
 
    {
1292
 
        OnConnect(ev);
1293
 
        return;
1294
 
    }
1295
 
 
1296
 
    if (currentObject)
1297
 
    {
1298
 
        if (!dlgProperty::CreateObjectDialog(this, currentObject, type))
1299
 
            checkAlive();
1300
 
    }
1301
 
}
1302
 
 
1303
 
 
1304
 
void frmMain::OnProperties(wxCommandEvent &ev)
1305
 
{
1306
 
    if (currentObject)
1307
 
    {
1308
 
        if (!dlgProperty::EditObjectDialog(this, sqlPane, currentObject))
1309
 
            checkAlive();
1310
 
    }
1311
 
}