Le 25/03/2010 23:15, Guillaume Lelarge a écrit :
> Le 21/03/2010 08:20, Guillaume Lelarge a écrit :
>> Le 15/03/2010 23:33, Guillaume Lelarge a écrit :
>>> Le 15/03/2010 23:16, Josh Berkus a écrit :
>>>> Version: 1.10.1
>>>> Platform: OSX 10.5
>>>> Severity: Annoyance
>>>> Reproduceable: sometimes
>>>> Description:
>>>>
>>>> 1) have a bunch of query windows for saved SQL files open (call them
>>>> files 1,2,3,4,5 and 6 in order in which they are opened).
>>>> 2) save file #1 and close it.
>>>> 3) In another, the query window for #5 pick file #1 from the "recent
>>>> files" list in the menu.
>>>> 4) File #2 will actually open.
>>>>
>>>> What happened: until File #1 was closed and saved, it was at the bottom
>>>> of the recent files list.  Closing it and saving it will have bumped it
>>>> up to the top of the recent files list.  However, the query window for
>>>> query #5 will not show this change until *after* you attempt to access a
>>>> file from that list, which is why it gives you the wrong file.
>>>>
>>>
>>> You're right. I added a ticket on our trac system
>>> (http://code.pgadmin.org/trac/ticket/149), so that we remember to work
>>> on it ASAP.
>>>
>>>
>>
>> Took a look at it today. The only way to get rid of it easily would be
>> to update the file only when we quit the query tool. Which means that a
>> window will first see the files that were recorded in the history, will
>> update its menu (but not the prefs file) when the user opens files,
>> won't get updates from other query window, and will push its history in
>> the prefs file when the user closes the query window. Whichs also means
>> that when a user quits pgAdmin, only one history will remain, the one of
>> the last query tool closed.
>>
>> Comments?
>>
> 
> No comments on that one?
> 

Patch attached.

I found a better way to fix it, which allows many great things for 1.12.
Anyways, this fix uses this method: for each change on a query window,
all the other query windows are notified of the change and reload the
file. So, they all share the same informations.

Moreover, we had the same issue with the favourites and the macros
files. The patch attached fixes that too.

I don't commit it right now. Dave, can you get a look at it? is the
patch good to go? Thanks.


-- 
Guillaume.
 http://www.postgresqlfr.org
 http://dalibo.com
diff --git a/pgadmin/dlg/dlgClasses.cpp b/pgadmin/dlg/dlgClasses.cpp
index 943a8a5..2ed3170 100644
--- a/pgadmin/dlg/dlgClasses.cpp
+++ b/pgadmin/dlg/dlgClasses.cpp
@@ -293,7 +293,7 @@ void pgFrame::OnRecent(wxCommandEvent& event)
 
 
 
-void pgFrame::UpdateRecentFiles()
+void pgFrame::UpdateRecentFiles(bool updatefile)
 {
     if (!recentFileMenu)
         return;
@@ -314,7 +314,7 @@ void pgFrame::UpdateRecentFiles()
     while (i <= maxFiles)
         lastFiles[i++] = wxT("");
 
-    if (recentIndex > 1 && !lastPath.IsNull())
+    if (recentIndex > 1 && !lastPath.IsNull() && updatefile)
     {
         for (i=recentIndex ; i > 1 ; i--)
             lastFiles[i] = lastFiles[i-1];
@@ -332,7 +332,8 @@ void pgFrame::UpdateRecentFiles()
 
     for (i=1 ; i <= maxFiles ; i++)
     {
-        settings->Write(recentKey + wxString::Format(wxT("/%d"), i), lastFiles[i]);
+        if (updatefile)
+            settings->Write(recentKey + 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]);
diff --git a/pgadmin/frm/frmMain.cpp b/pgadmin/frm/frmMain.cpp
index 67e9b67..1db4c06 100644
--- a/pgadmin/frm/frmMain.cpp
+++ b/pgadmin/frm/frmMain.cpp
@@ -76,7 +76,6 @@
 #include "slony/slCluster.h"
 #include "slony/slSet.h"
 
-
 #if wxDIALOG_UNIT_COMPATIBILITY
 #error wxWindows must be compiled with wxDIALOG_UNIT_COMPATIBILITY=0!
 #endif
@@ -88,6 +87,8 @@ frmMain::frmMain(const wxString& title)
     lastPluginUtility=NULL;
     pluginUtilityCount = 0;
 
+    frmQueries.Clear();
+
     dlgName = wxT("frmMain");
     SetMinSize(wxSize(400,300));
     RestorePosition(50, 50, 750, 550, 600, 450);
@@ -230,7 +231,42 @@ frmMain::~frmMain()
         delete treeContextMenu;
 }
 
+void frmMain::AddFrmQueryTool(frmQuery* fq)
+{
+    frmQueries.Add(fq);
+}
 
+void frmMain::RemoveFrmQueryTool(frmQuery* fq)
+{
+    frmQueries.Remove(fq);
+}
+
+void frmMain::UpdateRecentFilesOnFrmQueries()
+{
+    for (size_t i=0; i < frmQueries.GetCount(); i++)
+    {
+        frmQuery *fq = frmQueries.Item(i);
+        fq->UpdateRecentFiles(false);
+    }
+}
+
+void frmMain::UpdateFavouritesListOnFrmQueries()
+{
+    for (size_t i=0; i < frmQueries.GetCount(); i++)
+    {
+        frmQuery *fq = frmQueries.Item(i);
+        fq->UpdateFavouritesList();
+    }
+}
+
+void frmMain::UpdateMacrosListOnFrmQueries()
+{
+    for (size_t i=0; i < frmQueries.GetCount(); i++)
+    {
+        frmQuery *fq = frmQueries.Item(i);
+        fq->UpdateMacrosList();
+    }
+}
 
 void frmMain::CreateMenus()
 {
diff --git a/pgadmin/frm/frmQuery.cpp b/pgadmin/frm/frmQuery.cpp
index 1a460f3..8b57784 100644
--- a/pgadmin/frm/frmQuery.cpp
+++ b/pgadmin/frm/frmQuery.cpp
@@ -192,6 +192,7 @@ class DnDFile : public wxFileDropTarget
 						m_fquery->setExtendedTitle();
 						m_fquery->SetLineEndingStyle();
 						m_fquery->UpdateRecentFiles();
+                        m_fquery->UpdateRecentFilesOnFrmQueries();
 				}
 			}
 			return true;
@@ -305,14 +306,14 @@ pgsTimer(new pgScriptTimer(this))
     favouritesMenu->Append(MNU_FAVOURITES_ADD, _("Add favourite..."), _("Add current query to favourites"));
     favouritesMenu->Append(MNU_FAVOURITES_MANAGE, _("Manage favourites..."), _("Edit and delete favourites"));
     favouritesMenu->AppendSeparator();
-    favourites = queryFavouriteFileProvider::LoadFavourites(true);
+    favourites = 0L;
     UpdateFavouritesList();
     menuBar->Append(favouritesMenu, _("Fav&ourites"));
 
     macrosMenu = new wxMenu();
     macrosMenu->Append(MNU_MACROS_MANAGE, _("Manage macros..."), _("Edit and delete macros"));
     macrosMenu->AppendSeparator();
-    macros = queryMacroFileProvider::LoadMacros(true);
+    macros = 0L;
     UpdateMacrosList();
     menuBar->Append(macrosMenu, _("&Macros"));
 
@@ -593,6 +594,8 @@ pgsTimer(new pgScriptTimer(this))
 
     msgResult->SetMaxLength(0L);
     msgHistory->SetMaxLength(0L);
+
+    form->AddFrmQueryTool(this);
 }
 
 
@@ -600,6 +603,8 @@ frmQuery::~frmQuery()
 {
     closing = true;
 
+    mainForm->RemoveFrmQueryTool(this);
+
     // Save frmQuery Perspective
     settings->Write(wxT("frmQuery/Perspective-") + VerFromRev(FRMQUERY_PERPSECTIVE_VER), manager.SavePerspective());
 
@@ -875,6 +880,12 @@ void frmQuery::Go()
 }
 
 
+void frmQuery::UpdateRecentFilesOnFrmQueries()
+{
+    mainForm->UpdateRecentFilesOnFrmQueries();
+}
+
+
 typedef struct __sqltokenhelp
 {
     const wxChar *token;
@@ -1385,6 +1396,11 @@ void frmQuery::updateMenu(wxObject *obj)
 
 void frmQuery::UpdateFavouritesList()
 {
+    if (favourites)
+        delete favourites;
+
+    favourites = queryFavouriteFileProvider::LoadFavourites(true);
+
     while (favouritesMenu->GetMenuItemCount() > 3)
     {
         favouritesMenu->Destroy(favouritesMenu->GetMenuItems()[3]);
@@ -1396,6 +1412,11 @@ void frmQuery::UpdateFavouritesList()
 
 void frmQuery::UpdateMacrosList()
 {
+    if (macros)
+        delete macros;
+
+    macros = queryMacroFileProvider::LoadMacros(true);
+
     while (macrosMenu->GetMenuItemCount() > 2)
     {
         macrosMenu->Destroy(macrosMenu->GetMenuItems()[2]);
@@ -1413,7 +1434,7 @@ void frmQuery::OnAddFavourite(wxCommandEvent &event)
     {
         // Added a favourite, so save
         queryFavouriteFileProvider::SaveFavourites(favourites);
-        UpdateFavouritesList();
+        mainForm->UpdateFavouritesListOnFrmQueries();
     }
 }
 
@@ -1425,14 +1446,11 @@ void frmQuery::OnManageFavourites(wxCommandEvent &event)
     {
         // Changed something, so save
         queryFavouriteFileProvider::SaveFavourites(favourites);
-        UpdateFavouritesList();
     }
-    else if (r == -1)
+    if (r == 1 || r == -1)
     {
         // Changed something requiring rollback
-        delete favourites;
-        favourites = queryFavouriteFileProvider::LoadFavourites(true);
-        UpdateFavouritesList();
+        mainForm->UpdateFavouritesListOnFrmQueries();
     }
 }
 
@@ -1594,6 +1612,7 @@ void frmQuery::OpenLastFile()
         setExtendedTitle();
         SetLineEndingStyle();
         UpdateRecentFiles();
+        mainForm->UpdateRecentFilesOnFrmQueries();
     }
 }
 
@@ -2135,14 +2154,11 @@ void frmQuery::OnMacroManage(wxCommandEvent &event)
     {
         // Changed something, so save
         queryMacroFileProvider::SaveMacros(macros);
-        UpdateMacrosList();
     }
-    else if (r == -1)
+    if (r == -1 || r == 1)
     {
         // Changed something requiring rollback
-        delete macros;
-        macros = queryMacroFileProvider::LoadMacros(true);
-        UpdateMacrosList();
+        mainForm->UpdateMacrosListOnFrmQueries();
     }
 
 }
diff --git a/pgadmin/include/dlg/dlgClasses.h b/pgadmin/include/dlg/dlgClasses.h
index 26f576e..c5c4d23 100644
--- a/pgadmin/include/dlg/dlgClasses.h
+++ b/pgadmin/include/dlg/dlgClasses.h
@@ -60,7 +60,7 @@ public:
     void SavePosition();
     void OnAction(wxCommandEvent& event);
 		
-    void UpdateRecentFiles();
+    void UpdateRecentFiles(bool updatefile=true);
 
 	menuFactoryList *GetMenuFactories() { return menuFactories; }
 
diff --git a/pgadmin/include/frm/frmMain.h b/pgadmin/include/frm/frmMain.h
index d9980a9..27d3559 100644
--- a/pgadmin/include/frm/frmMain.h
+++ b/pgadmin/include/frm/frmMain.h
@@ -17,10 +17,12 @@
 #include <wx/wx.h>
 #include <wx/listctrl.h>
 #include <wx/notebook.h>
+#include <wx/dynarray.h>
 
 // wxAUI
 #include <wx/aui/aui.h>
 
+#include "frm/frmQuery.h"
 #include "dlg/dlgClasses.h"
 #include "utils/factory.h"
 
@@ -70,6 +72,9 @@ enum
 };
 
 
+WX_DEFINE_ARRAY_PTR(frmQuery *, ArrayOfFrmQuery);
+
+
 // Class declarations
 class frmMain : public pgFrame
 {
@@ -116,6 +121,12 @@ public:
     wxString GetCurrentNodePath();
     bool SetCurrentNode(wxTreeItemId node, const wxString &path);
 
+    void AddFrmQueryTool(frmQuery *fq);
+    void RemoveFrmQueryTool(frmQuery *fq);
+    void UpdateRecentFilesOnFrmQueries();
+    void UpdateFavouritesListOnFrmQueries();
+    void UpdateMacrosListOnFrmQueries();
+
 private:
     wxAuiManager manager;
     ctlTree *browser;
@@ -145,6 +156,8 @@ private:
     wxTreeItemId denyCollapseItem;
     pgObject *currentObject;
 
+    ArrayOfFrmQuery frmQueries;
+
     void OnEraseBackground(wxEraseEvent& event);
     void OnSize(wxSizeEvent& event);
 	void OnSelectItem(wxListEvent &event);
diff --git a/pgadmin/include/frm/frmQuery.h b/pgadmin/include/frm/frmQuery.h
index c94ad7e..c23f0d4 100644
--- a/pgadmin/include/frm/frmQuery.h
+++ b/pgadmin/include/frm/frmQuery.h
@@ -82,6 +82,10 @@ public:
 		void SetLastPath(wxString p_lastpath) { lastPath = p_lastpath; }
     bool CheckChanged(bool canVeto);
 
+    void UpdateRecentFilesOnFrmQueries();
+    void UpdateFavouritesList();
+    void UpdateMacrosList();
+
 private:
     frmMain *mainForm;
     wxAuiManager manager;
@@ -200,13 +204,11 @@ private:
     void OnScriptComplete(wxCommandEvent &ev);
     void setTools(const bool running);
     void showMessage(const wxString& msg, const wxString &msgShort=wxT(""));
-    void UpdateFavouritesList();
     int GetLineEndingStyle();
     void OnSetEOLMode(wxCommandEvent& event);
     void SetEOLModeDisplay(int mode);
     void OnMacroInvoke(wxCommandEvent& event);
     void OnMacroManage(wxCommandEvent& event);
-    void UpdateMacrosList();
 
     void LoadQueries();
     void SaveQueries();
-- 
Sent via pgadmin-support mailing list (pgadmin-support@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgadmin-support

Reply via email to