Patch #2748 2009-04-28 18:11

raybert

workspace file improvements
Download
2748-workspace_file.patch (14.1 KB)
Category
Application::Refinement
Status
Closed
Close date
2012-05-28 19:52
Assigned to
killerbot
diff -r b79c5d3ddb2d .hgtags
--- a/.hgtags    Wed Apr 29 01:03:39 2009 -0400
+++ b/.hgtags    Wed Apr 29 11:01:44 2009 -0400
@@ -1,3 +1,5 @@
 0389ce88fc3525b8d308d522505d939760b32905 svn-5550
 84d1ba9c5aca7dc5f46c3dc1df47c5f837b9e1dd baseline
 51788dfbc72159481063e7315beede4e7d119a4e baseline
+b79c5d3ddb2dc39048b5eda39f3ae63e5eddcbfc baseline
+f10e24fc4d48f4a11261a6e7f159e8e0089942f7 workspace-patch-2
diff -r b79c5d3ddb2d src/include/cbworkspace.h
--- a/src/include/cbworkspace.h    Wed Apr 29 01:03:39 2009 -0400
+++ b/src/include/cbworkspace.h    Wed Apr 29 11:01:44 2009 -0400
@@ -107,14 +107,26 @@
           * false, the workspace will be marked as unmodified.
           */
         virtual void SetModified(bool modified);
+
+        /** @brief Set the preferred target for this workspace
+          */
+        virtual void SetPreferredTarget(const wxString &target);
+
+        /** @brief Get the preferred target for this workspace
+          */
+        virtual wxString GetPreferredTarget() const { return m_PreferredTargetName; }
+
     private:
         bool m_IsOK; // succeeded loading?
         bool m_IsDefault; // is this the Code::Blocks default workspace?
         bool m_Modified; // is it modified?
         wxFileName m_Filename; // filename
         wxString m_Title; // title
+        wxString m_PreferredTargetName;
 
         void Load(); // utility function
+        bool SaveLayout();
+        bool LoadLayout();
 };
 
 #endif // CBWORKSPACE_H
diff -r b79c5d3ddb2d src/include/workspaceloader.h
--- a/src/include/workspaceloader.h    Wed Apr 29 01:03:39 2009 -0400
+++ b/src/include/workspaceloader.h    Wed Apr 29 11:01:44 2009 -0400
@@ -16,6 +16,9 @@
 
         bool Open(const wxString& filename, wxString& Title);
         bool Save(const wxString& title, const wxString& filename);
+
+        bool SaveLayout(const wxString& filename);
+        bool LoadLayout(const wxString& filename);
 };
 
 #endif // WORKSPACELOADER_H
diff -r b79c5d3ddb2d src/plugins/compilergcc/compilergcc.cpp
--- a/src/plugins/compilergcc/compilergcc.cpp    Wed Apr 29 01:03:39 2009 -0400
+++ b/src/plugins/compilergcc/compilergcc.cpp    Wed Apr 29 11:01:44 2009 -0400
@@ -1314,6 +1314,18 @@
     }
 }
 
+bool CompilerGCC::IsValidTarget(const wxString &target) const
+{
+    if ( target.IsEmpty() )
+        return false;
+    if ( m_Targets.Index(target) == -1 )
+        return false;
+    ProjectBuildTarget *tgt = Manager::Get()->GetProjectManager()->GetActiveProject()->GetBuildTarget(target);
+    if ( tgt && ! tgt->SupportsCurrentPlatform() )
+        return false;
+    return true;
+}
+
 void CompilerGCC::DoRecreateTargetMenu()
 {
     if (!IsAttached())
@@ -1341,9 +1353,14 @@
             break;
 
         // find out the should-be-selected target
-        wxString tgtStr = m_Project->GetActiveBuildTarget();
-        if (tgtStr.IsEmpty())
-            tgtStr = m_Project->GetFirstValidBuildTargetName(); // a default value
+        wxString preferredTarget = Manager::Get()->GetProjectManager()->GetWorkspace()->GetPreferredTarget();
+        wxString tgtStr = preferredTarget;
+        if ( ! IsValidTarget(tgtStr) )
+            tgtStr = m_Project->GetActiveBuildTarget();
+        if ( ! IsValidTarget(tgtStr) )
+            tgtStr = m_Project->GetFirstValidBuildTargetName(); // last-chance default
+        if ( preferredTarget.IsEmpty() )
+            Manager::Get()->GetProjectManager()->GetWorkspace()->SetPreferredTarget(tgtStr);
 
         // fill the menu and combo
         for (size_t x = 0; x < m_Targets.GetCount(); ++x)
@@ -1434,7 +1451,9 @@
     }
     for (int i = 0; i < project->GetBuildTargetsCount(); ++i)
     {
-        m_Targets.Add(project->GetBuildTarget(i)->GetTitle());
+        ProjectBuildTarget *tgt = project->GetBuildTarget(i);
+        if ( tgt->SupportsCurrentPlatform() )
+            m_Targets.Add( tgt->GetTitle() );
     }
 
     // keep the index for the first real target
@@ -3158,15 +3177,18 @@
 
 void CompilerGCC::OnSelectTarget(wxCommandEvent& event)
 {
-    int sel = event.GetSelection();
     if (event.GetId() == idToolTarget)
     {   // through the toolbar
+        int sel = event.GetSelection();
+        Manager::Get()->GetProjectManager()->GetWorkspace()->SetPreferredTarget( GetTargetString(sel) );
         DoUpdateTargetMenu(sel);
     }
     else
     {   // through Build->SelectTarget
-        DoUpdateTargetMenu(event.GetId() - idMenuSelectTargetOther[0]);
-        m_ToolTarget->SetSelection(event.GetId() - idMenuSelectTargetOther[0]);
+        int i = event.GetId() - idMenuSelectTargetOther[0];
+        Manager::Get()->GetProjectManager()->GetWorkspace()->SetPreferredTarget( GetTargetString(i) );
+        DoUpdateTargetMenu(i);
+        m_ToolTarget->SetSelection(i);
     }
 } // end of OnSelectTarget
 
diff -r b79c5d3ddb2d src/plugins/compilergcc/compilergcc.h
--- a/src/plugins/compilergcc/compilergcc.h    Wed Apr 29 01:03:39 2009 -0400
+++ b/src/plugins/compilergcc/compilergcc.h    Wed Apr 29
download for full patch...
raybert 2009-04-28 18:27

This patch is intended mainly to avoid (arguably) unnecessary modifications to the workspace file that would impact the user's VCS with unnecessary commits.

It also provides a couple of minor usability improvements.

This patch is being discussed in the forum @ http://forums.codeblocks.org/index.php/topic,10395.msg71559.html#msg71559

It addresses the following:

* CB currently writes workspace files with paths that contain the native path separator for the platform it is running on. When sharing the workspace across multiple platforms this sometimes results in a modified workspace file where the only change is the slashes. This also makes it difficult to compare versions of files. This patch forces forward slashes to be used consistently in the workspace file regardless of which platform CB is running on.

* CB currently saves the active project to the workspace file. This causes the same problems as discussed above. This patch introduces a new file (*.workspace.layout) and saves the active project there instead of in the WS file.

* CB currently changes the active build target whenever the active project is changed (if the newly activated project has a different active target). This is confusing and error prone as the user isn't expecting the setting that he/she made to be changed without his/her knowledge. To address this, this patch introduces the concept of a "preferred target". Whenever the user selects a new build target the selection is saved internally as the "preferred target". When the user changes the active project, CB will attempt to keep the "preferred target" active. If the newly activated project doesn't have a target with the same name, its last active target is re-activated. The "preferred target" is also saved in the new "workspace layout" file and re-used the next time the workspace is loaded.

* This patch also prevents CB from listing build targets that are not supported on the current platform from appearing in the drop down box or the menu. (Note: If the active project does not have any target that supports the current platform, the target list will be empty.)

~ray

raybert 2009-04-29 15:09

Minor update that replaces warning dialogs for workspace layout file load/save failures with debug logging. The load failure would happen whenever an old project was opened with a patched CB. The workspace layout file is not vital for anything and therefore doesn't warrant a warning dialog.

killerbot 2012-05-28 19:52

applied