Log Message:
-----------
pgFrame refactoring

Modified Files:
--------------
    pgadmin3/src/ui:
        dlgClasses.cpp (r1.12 -> r1.13)
        events.cpp (r1.116 -> r1.117)
        frmQuery.cpp (r1.73 -> r1.74)

Index: dlgClasses.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/dlgClasses.cpp,v
retrieving revision 1.12
retrieving revision 1.13
diff -Lsrc/ui/dlgClasses.cpp -Lsrc/ui/dlgClasses.cpp -u -w -r1.12 -r1.13
--- src/ui/dlgClasses.cpp
+++ src/ui/dlgClasses.cpp
@@ -129,6 +129,96 @@
 
///////////////////////////////////////////////////////////////////////////////////////
 
 
+BEGIN_EVENT_TABLE(pgFrame, wxFrame)
+    EVT_MENU(MNU_EXIT,                  pgFrame::OnExit)
+    EVT_MENU(MNU_RECENT+1,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+2,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+3,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+4,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+5,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+6,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+7,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+8,              pgFrame::OnRecent)
+    EVT_MENU(MNU_RECENT+9,              pgFrame::OnRecent)
+#ifdef __WXGTK__
+    EVT_KEY_DOWN(                       pgFrame::OnKeyDown)
+#endif
+END_EVENT_TABLE()
+
+
+// Event handlers
+void pgFrame::OnKeyDown(wxKeyEvent& event)
+{
+    event.m_metaDown=false;
+    event.Skip();
+}
+
+
+void pgFrame::OnExit(wxCommandEvent& event)
+{
+    Close();
+}
+
+
+void pgFrame::OnRecent(wxCommandEvent& event)
+{
+    int fileNo=event.GetId() - MNU_RECENT;
+    lastPath = settings->Read(wxT("RecentFiles/") + wxString::Format(wxT("/%d"), 
fileNo), wxT(""));
+
+    if (!lastPath.IsNull())
+    {
+        int dirsep;
+        dirsep = lastPath.Find(wxFILE_SEP_PATH, true);
+        lastDir = lastPath.Mid(0, dirsep);
+        lastFilename = lastPath.Mid(dirsep+1);
+        OpenLastFile();
+    }
+}
+
+
+
+void pgFrame::UpdateRecentFiles()
+{
+    wxString lastFiles[10]; // 0 will be unused for convenience
+    int i, maxFiles=9;
+    int recentIndex=maxFiles;
+
+    for (i=1 ; i <= maxFiles ; i++)
+    {
+        lastFiles[i] = settings->Read(recentKey + wxString::Format(wxT("/%d"), i), 
wxT(""));
+        if (!lastPath.IsNull() && lastPath.IsSameAs(lastFiles[i], 
wxARE_FILENAMES_CASE_SENSITIVE))
+            recentIndex=i;
+    }
+    while (i <= maxFiles)
+        lastFiles[i++] = wxT("");
+
+    if (recentIndex > 1 && !lastPath.IsNull())
+    {
+        for (i=recentIndex ; i > 1 ; i--)
+            lastFiles[i] = lastFiles[i-1];
+        lastFiles[1] = lastPath;
+    }
+
+    i=recentFileMenu->GetMenuItemCount();
+    while (i)
+    {
+        wxMenuItem *item = recentFileMenu->Remove(MNU_RECENT+i);
+        if (item)
+            delete item;
+        i--;
+    }
+
+    for (i=1 ; i <= maxFiles ; i++)
+    {
+        settings->Write(wxT("RecentFiles/") + wxString::Format(wxT("%d"), i), 
lastFiles[i]);
+
+
+        if (!lastFiles[i].IsNull())
+            recentFileMenu->Append(MNU_RECENT+i, wxT("&") + 
wxString::Format(wxT("%d"), i) + wxT("  ") + lastFiles[i]);
+    }
+}
+
+
 void pgFrame::RestorePosition(int defaultX, int defaultY, int defaultW, int defaultH, 
int minW, int minH)
 {
     wxPoint pos(settings->Read(dlgName, wxPoint(defaultX, defaultY)));
Index: frmQuery.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/frmQuery.cpp,v
retrieving revision 1.73
retrieving revision 1.74
diff -Lsrc/ui/frmQuery.cpp -Lsrc/ui/frmQuery.cpp -u -w -r1.73 -r1.74
--- src/ui/frmQuery.cpp
+++ src/ui/frmQuery.cpp
@@ -49,16 +49,6 @@
     EVT_MENU(MNU_SAVE,              frmQuery::OnSave)
     EVT_MENU(MNU_SAVEAS,            frmQuery::OnSaveAs)
     EVT_MENU(MNU_EXPORT,            frmQuery::OnExport)
-    EVT_MENU(MNU_RECENT+1,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+2,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+3,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+4,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+5,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+6,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+7,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+8,          frmQuery::OnRecent)
-    EVT_MENU(MNU_RECENT+9,          frmQuery::OnRecent)
-    EVT_MENU(MNU_EXIT,              frmQuery::OnExit)
     EVT_MENU(MNU_CUT,               frmQuery::OnCut)
     EVT_MENU(MNU_COPY,              frmQuery::OnCopy)
     EVT_MENU(MNU_PASTE,             frmQuery::OnPaste)
@@ -75,9 +65,6 @@
     EVT_MENU(MNU_CLEARHISTORY,      frmQuery::OnClearHistory)
     EVT_MENU(MNU_SAVEHISTORY,       frmQuery::OnSaveHistory)
     EVT_ACTIVATE(                   frmQuery::OnActivate)
-#ifdef __WXGTK__
-    EVT_KEY_DOWN(                   frmQuery::OnKeyDown)
-#endif
     EVT_STC_MODIFIED(CTL_SQLQUERY,  frmQuery::OnChangeStc)
 END_EVENT_TABLE()
 
@@ -92,6 +79,7 @@
     conn=_conn;
 
     dlgName = wxT("frmQuery");
+    recentKey = wxT("RecentFiles");
     RestorePosition(100, 100, 600, 500, 200, 150);
 
     SetIcon(wxIcon(sql_xpm));
@@ -151,7 +139,7 @@
     queryMenu->Check(MNU_VERBOSE, settings->GetExplainVerbose());
     queryMenu->Check(MNU_ANALYZE, settings->GetExplainAnalyze());
 
-    updateRecentFiles();
+    UpdateRecentFiles();
 
     wxAcceleratorEntry entries[8];
 
@@ -262,49 +250,6 @@
 }
 
 
-
-void frmQuery::updateRecentFiles()
-{
-    wxString lastFiles[10]; // 0 will be unused for convenience
-    int i, maxFiles=9;
-    int recentIndex=maxFiles;
-
-    for (i=1 ; i <= maxFiles ; i++)
-    {
-        lastFiles[i] = settings->Read(wxT("RecentFiles/") + 
wxString::Format(wxT("%d"), i), wxT(""));
-        if (!lastPath.IsNull() && lastPath.IsSameAs(lastFiles[i], 
wxARE_FILENAMES_CASE_SENSITIVE))
-            recentIndex=i;
-    }
-    while (i <= maxFiles)
-        lastFiles[i++] = wxT("");
-
-    if (recentIndex > 1 && !lastPath.IsNull())
-    {
-        for (i=recentIndex ; i > 1 ; i--)
-            lastFiles[i] = lastFiles[i-1];
-        lastFiles[1] = lastPath;
-    }
-
-    i=recentFileMenu->GetMenuItemCount();
-    while (i)
-    {
-        wxMenuItem *item = recentFileMenu->Remove(MNU_RECENT+i);
-        if (item)
-            delete item;
-        i--;
-    }
-
-    for (i=1 ; i <= maxFiles ; i++)
-    {
-        settings->Write(wxT("RecentFiles/") + wxString::Format(wxT("%d"), i), 
lastFiles[i]);
-
-
-        if (!lastFiles[i].IsNull())
-            recentFileMenu->Append(MNU_RECENT+i, wxT("&") + 
wxString::Format(wxT("%d"), i) + wxT("  ") + lastFiles[i]);
-    }
-}
-
-
 void frmQuery::OnActivate(wxActivateEvent& event)
 {
     if (event.GetActive())
@@ -313,29 +258,6 @@
 }
 
 
-void frmQuery::OnRecent(wxCommandEvent& event)
-{
-    int fileNo=event.GetId() - MNU_RECENT;
-    lastPath = settings->Read(wxT("RecentFiles/") + wxString::Format(wxT("%d"), 
fileNo), wxT(""));
-
-    if (!lastPath.IsNull())
-    {
-        int dirsep;
-        dirsep = lastPath.Find(wxFILE_SEP_PATH, true);
-        lastDir = lastPath.Mid(0, dirsep);
-        lastFilename = lastPath.Mid(dirsep+1);
-        openLastFile();
-    }
-}
-
-
-void frmQuery::OnKeyDown(wxKeyEvent& event)
-{
-    event.m_metaDown=false;
-    event.Skip();
-}
-
-
 void frmQuery::OnExport(wxCommandEvent &ev)
 {
     sqlResult->Export();
@@ -349,12 +271,6 @@
 }
 
 
-void frmQuery::OnExit(wxCommandEvent& event)
-{
-    Close();
-}
-
-
 typedef struct __sqltokenhelp
 {
     wxChar *token;
@@ -689,7 +605,8 @@
 }
 
 
-void frmQuery::OnClose(wxCloseEvent& event)
+
+bool frmQuery::CheckChanged(bool canVeto)
 {
     if (changed && settings->GetAskSaveConfirmation())
     {
@@ -698,26 +615,35 @@
             fn = wxT(" in file ") + lastPath;
         wxMessageDialog msg(this, wxString::Format(_("The text %s has changed.\nDo 
you want to save changes?"), fn.c_str()), _("pgAdmin III Query"), 
                     wxYES_NO|wxNO_DEFAULT|wxICON_EXCLAMATION|
-                    (event.CanVeto() ? wxCANCEL : 0));
+                    (canVeto ? wxCANCEL : 0));
 
        wxCommandEvent noEvent;
         switch (msg.ShowModal())
         {
             case wxID_YES:
                 if (lastPath.IsNull())
-                {
                     OnSaveAs(noEvent);
-                    if (changed && event.CanVeto())
-                        event.Veto();
-                }
                 else
                     OnSave(noEvent);
-                break;
+
+                return changed;
+
             case wxID_CANCEL:
+                return true;
+        }
+    }
+    return false;
+}
+
+
+void frmQuery::OnClose(wxCloseEvent& event)
+{
+    if (CheckChanged(event.CanVeto()) && event.CanVeto())
+    {
                 event.Veto();
                 return;
         }
-    }
+
     Hide();
 
     if (queryMenu->IsEnabled(MNU_CANCEL))
@@ -746,7 +672,7 @@
 }
 
 
-void frmQuery::openLastFile()
+void frmQuery::OpenLastFile()
 {
     wxString str=FileRead(lastPath);
     if (!str.IsEmpty())
@@ -755,37 +681,14 @@
         wxYield();  // needed to process sqlQuery modify event
         changed = false;
         setExtendedTitle();
-        updateRecentFiles();
+        UpdateRecentFiles();
     }
 }
         
 void frmQuery::OnOpen(wxCommandEvent& event)
 {
-    if (changed && settings->GetAskSaveConfirmation())
-    {
-        wxString fn;
-        if (!lastPath.IsNull())
-            fn = wxT(" in file ") + lastPath;
-        wxMessageDialog msg(this, wxString::Format(_("The text %s has changed.\nDo 
you want to save changes?"), fn.c_str()), _("pgAdmin III Query"), 
-                    wxYES_NO|wxNO_DEFAULT|wxICON_EXCLAMATION|wxCANCEL);
-
-       wxCommandEvent noEvent;
-        switch (msg.ShowModal())
-        {
-            case wxID_YES:
-                if (lastPath.IsNull())
-                {
-                    OnSaveAs(noEvent);
-                    if (changed)
+    if (CheckChanged(false))
                                                return;
-                }
-                else
-                    OnSave(noEvent);
-                break;
-            case wxID_CANCEL:
-                return;
-        }
-    }
 
     wxFileDialog dlg(this, _("Open query file"), lastDir, wxT(""), 
         _("Query files (*.sql)|*.sql|All files (*.*)|*.*"), wxOPEN);
@@ -794,7 +697,7 @@
         lastFilename=dlg.GetFilename();
         lastDir = dlg.GetDirectory();
         lastPath = dlg.GetPath();
-        openLastFile();
+        OpenLastFile();
     }
 }
 
@@ -810,7 +713,7 @@
     {
         changed=false;
         setExtendedTitle();
-        updateRecentFiles();
+        UpdateRecentFiles();
     }
 }
 
@@ -841,7 +744,7 @@
         {
             changed=false;
             setExtendedTitle();
-            updateRecentFiles();
+            UpdateRecentFiles();
         }
     }
     delete dlg;
Index: events.cpp
===================================================================
RCS file: /projects/pgadmin3/src/ui/events.cpp,v
retrieving revision 1.116
retrieving revision 1.117
diff -Lsrc/ui/events.cpp -Lsrc/ui/events.cpp -u -w -r1.116 -r1.117
--- src/ui/events.cpp
+++ src/ui/events.cpp
@@ -75,7 +75,6 @@
     EVT_MENU(MNU_DROP,                      frmMain::OnDrop)
     EVT_MENU(MNU_CREATE,                    frmMain::OnCreate)
     EVT_MENU(MNU_PROPERTIES,                frmMain::OnProperties)
-    EVT_MENU(MNU_EXIT,                      frmMain::OnExit)
     EVT_MENU(MNU_STATUS,                    frmMain::OnStatus)
     EVT_MENU(MNU_BACKUP,                    frmMain::OnBackup)
     EVT_MENU(MNU_RESTORE,                   frmMain::OnRestore)
@@ -131,20 +130,12 @@
     EVT_TREE_ITEM_RIGHT_CLICK(CTL_BROWSER,  frmMain::OnSelRightClick) 
     EVT_CLOSE(                              frmMain::OnClose)
 #ifdef __WXGTK__
-    EVT_KEY_DOWN(                           frmMain::OnKeyDown)
     EVT_TREE_KEY_DOWN(CTL_BROWSER,          frmMain::OnTreeKeyDown)
 #endif
 END_EVENT_TABLE()
 
 
 
-// Event handlers
-void frmMain::OnKeyDown(wxKeyEvent& event)
-{
-    event.m_metaDown=false;
-    event.Skip();
-}
-
 
 // unfortunately, under GTK we won't get the original wxKeyEvent
 // to reset m_metaDown
@@ -168,9 +159,10 @@
 }
 
 
-void frmMain::OnExit(wxCommandEvent& WXUNUSED(event))
+void frmMain::OnExit(wxCommandEvent& event)
 {
     Close(FALSE);   // Allow sub windows to stop us
+    event.Skip();
 }
 
 
---------------------------(end of broadcast)---------------------------
TIP 9: the planner will ignore your desire to choose an index scan if your
      joining column's datatypes do not match

Reply via email to