Patch #1779 2006-12-31 05:58

revvy

Autosave the layout as well as the project
Download
1779-Autosave_the_l.patch (3.4 KB)
Category
Plugin::Refinement
Status
Closed
Close date
2006-12-31 10:57
Assigned to
 
Index: autosave.cpp
===================================================================
--- autosave.cpp    (revision 3444)
+++ autosave.cpp    (working copy)
@@ -97,39 +97,64 @@
         if(pm && pm->GetActiveProject())
         {
             cbProject * p = pm->GetActiveProject();
-            if(p && p->GetModified())
+            if(p)
             {
                 switch(method)
                 {
                     case 0:
                     {
-                        if(::wxRenameFile(p->GetFilename(), p->GetFilename() + _T(".bak")))
-                            if(p->Save())
-                            {
-                                CodeBlocksEvent e(cbEVT_PROJECT_SAVE);
-                                plm->NotifyPlugins(e);
-                            }
+                                                if(p->GetModified())
+                                                {
+                                                    if(::wxRenameFile(p->GetFilename(), p->GetFilename() + _T(".bak")))
+                                                            if(p->Save())
+                                                            {
+                                                                    CodeBlocksEvent e(cbEVT_PROJECT_SAVE);
+                                                                    plm->NotifyPlugins(e);
+                                                            }
+                                                }
+                                                wxFileName file = p->GetFilename();
+                                                file.SetExt(_T("layout"));
+                                                wxString filename = file.GetFullPath();
+                                                if(::wxRenameFile(filename, filename + _T(".bak")))
+                                                    p->SaveLayout();
                         break;
                     }
                     case 1:
                     {
-                        if(p->Save())
+                        if(p->GetModified() && p->Save())
                         {
                             CodeBlocksEvent e(cbEVT_PROJECT_SAVE);
                             plm->NotifyPlugins(e);
                         }
+                        p->SaveLayout();
                         break;
                     }
                     case 2:
                     {
                         if (p->IsLoaded() == false)
                             return;
-                        ProjectLoader loader(p);
-                        if(loader.Save(p->GetFilename() + _T(".save")))
-                        {
-                            CodeBlocksEvent e(cbEVT_PROJECT_SAVE);
-                            plm->NotifyPlugins(e);
-                        }
+                                                if(p->GetModified())
+                                                {
+                                                    ProjectLoader loader(p);
+                                                    if(loader.Save(p->GetFilename() + _T(".save")))
+                                                    {
+                                                            CodeBlocksEvent e(cbEVT_PROJECT_SAVE);
+                                                            plm->NotifyPlugins(e);
+                                                    }
+                                                }
+                        
+                        wxFileName file = wxFileName(p->GetFilename());
+                                                file.SetExt(_T("layout"));
+                                                wxString filename = file.GetFullPath();
+                                                wxString temp = filename + _T(".temp");
+                                                wxString save = filename + _T(".save");
+                                                if(::wxCopyFile(filename, temp))
+                                                {
+                                                    p->SaveLayout();
+                                                    ::wxRenameFile(filename, save);
+                                                    ::wxRenameFile(temp, filename);
+                                                }
+                        
                         p->SetModified(); // the actual project file is still not updated!
                         break;
                     }
@@ -137,7 +162,7 @@
             }
         }
     }
-else if(e.GetId() == 20000)
+    else if(e.GetId() == 20000)
     {
         int method = Manager::Get()->GetConfigManager(_T("autosave"))->ReadInt(_T("method"));
         EditorManager* em = Manager::Get()->GetEditorManager();
killerbot 2006-12-31 10:57

patch applied. rev 3445.

One important change : in case 2 the "p->SetModified()" should be within the if test of if(p->GetModified()) [like it was originally] otherwise an unmodified one who be put inthe modified state.

many thanks.

One other remark : now we save the layout always, I didn't check, but maybe we can determine if the layout has changed [probably it has, cursor moved of something like, so maybe it's not even worth the hassle] and only save in such case.