Patch #2751 2009-04-30 17:41

raybert

persistent storage of bookmarks
Download
2751-persistent_sto.patch (13.3 KB)
Category
Application::FeatureAdd
Status
Open
Close date
 
Assigned to
 
diff -r 6fcf35fb5ad7 src/include/cbeditor.h
--- a/src/include/cbeditor.h    Wed Apr 29 11:33:50 2009 -0400
+++ b/src/include/cbeditor.h    Thu Apr 30 13:35:54 2009 -0400
@@ -248,6 +248,12 @@
         /** Go to previous bookmark. */
         void GotoPreviousBookmark();
 
+        /** Set a bookmark at the specified line. */
+        void SetBookmark(int line = -1);
+
+        /** Get a list of all bookmarks */
+        void GetAllBookmarks(BookmarkList &marks);
+
         /** Highlight the line the debugger will execute next. */
         void SetDebugLine(int line);
 
diff -r 6fcf35fb5ad7 src/include/editorbase.h
--- a/src/include/editorbase.h    Wed Apr 29 11:33:50 2009 -0400
+++ b/src/include/editorbase.h    Thu Apr 30 13:35:54 2009 -0400
@@ -13,9 +13,12 @@
 #include "settings.h"
 #include "cbexception.h"
 
+#include <set>
+
 class wxMenu;
 class EditorBase;
 struct EditorBaseInternalData;
+typedef std::set<int> BookmarkList;
 
 WX_DECLARE_HASH_MAP(int, EditorBase*, wxIntegerHash, wxIntegerEqual, SwitchToMap);
 
@@ -196,6 +199,15 @@
         /** Go to previous bookmark. */
         virtual void GotoPreviousBookmark(){}
 
+        /** Set a bookmark at specified line.
+          * @param line The line to set the bookmark on. If @c line is -1,
+          *             use current line.
+          */
+        virtual void SetBookmark(int line = -1);
+
+        /** Get a list of all bookmarks by line number. */
+        virtual void GetAllBookmarks(BookmarkList &marks) {}
+
         /** @brief Mark the debugger's active line.
           *
           * Highlight the line the debugger will execute next.
diff -r 6fcf35fb5ad7 src/include/projectfile.h
--- a/src/include/projectfile.h    Wed Apr 29 11:33:50 2009 -0400
+++ b/src/include/projectfile.h    Thu Apr 30 13:35:54 2009 -0400
@@ -7,6 +7,7 @@
 #define PROJECTFILE_H
 
 #include <vector>
+#include <set>
 
 #include "settings.h"
 #include "globals.h"
@@ -33,6 +34,7 @@
 
 class ProjectFile;
 typedef std::vector<ProjectFile*> ProjectFilesVector;
+typedef std::set<int> BookmarkList;
 
 /** Represents a file in a Code::Blocks project. */
 class ProjectFile  : public BlockAllocated<ProjectFile, 1000>
@@ -139,7 +141,7 @@
         unsigned short int weight;
 
         /** If true, the file is open inside an editor. */
-        bool editorOpen; // layout info
+        enum { eUnattached, eOpenOnLoad, eAttached } editorOpen; // layout info
 
         /** The last known caret position in an editor for this file. */
         int editorPos; // layout info
@@ -175,6 +177,11 @@
 
         /** Auto-generated files when compiling this file */
         ProjectFilesVector generatedFiles;
+
+        void ResetBookmarks()       { m_bookmarks.clear(); }
+        void AddBookmark(int line)  { m_bookmarks.insert(line); }
+        const BookmarkList & GetBookmarks() const;
+
     protected:
         friend class cbProject;
 
@@ -184,6 +191,7 @@
         wxTreeItemId m_TreeItemId; // set by the project when building the tree
         wxString m_ObjName;
         PFDMap m_PFDMap;
+        mutable BookmarkList m_bookmarks;
 };
 WX_DECLARE_LIST(ProjectFile, FilesList);
 
diff -r 6fcf35fb5ad7 src/plugins/contrib/BrowseTracker/BrowseTrackerLayout.cpp
--- a/src/plugins/contrib/BrowseTracker/BrowseTrackerLayout.cpp    Wed Apr 29 11:33:50 2009 -0400
+++ b/src/plugins/contrib/BrowseTracker/BrowseTrackerLayout.cpp    Thu Apr 30 13:35:54 2009 -0400
@@ -239,11 +239,11 @@
     {
         ProjectFile* f = m_pProject->GetFile(i);
 
-        if (f->editorOpen || f->editorPos || f->editorTopLine || f->editorTabPos)
+        if (f->editorOpen == ProjectFile::eAttached || f->editorPos || f->editorTopLine || f->editorTabPos)
         {
             TiXmlElement* node = static_cast<TiXmlElement*>(rootnode->InsertEndChild(TiXmlElement("File")));
             node->SetAttribute("name", cbU2C(f->relativeFilename));
-            node->SetAttribute("open", f->editorOpen);
+            node->SetAttribute("open", f->editorOpen == ProjectFile::eAttached);
             node->SetAttribute("top", (f == active));
             node->SetAttribute("tabpos", f->editorTabPos);
 
diff -r 6fcf35fb5ad7 src/plugins/contrib/codesnippets/editor/scbeditor.cpp
--- a/src/plugins/contrib/codesnippets/editor/scbeditor.cpp    Wed Apr 29 11:33:50 2009 -0400
+++ b/src/plugins/contrib/codesnippets/editor/scbeditor.cpp    Thu Apr 30 13:35:54 2009 -0400
@@ -434,7 +434,7 @@
     if (m_pControl)
     {
         if (m_pProjectFile)
-            m_pProjectFile->editorOpen = false;
+            m_pProjectFile->editorOpen = ProjectFile::eAttached;
         m_pControl->Destroy();
         m_pControl = 0;
     }
@@ -606,7 +606,7 @@
         m_pControl->ScrollToLine(m_pProjectFile->editorTopLine);
         m_pControl->ScrollToColumn(0);
 
-        m_pProjectFile->editorOpen = true;
+        m_pProjectFile->editorOpen = ProjectFile::eAttached;
 
         if (Manager::Get()->GetConfigManager(_T("editor"))->ReadBool(_T("/tab_text_relative"), true))
download for full patch...
raybert 2009-04-30 17:47

This patch implements the persistent storage of bookmarks. The project layout file is used to store the bookmarks between sessions.

Experience with other editors has taught me that this is a very useful feature and I missed it in CB.

Saving the bookmarks was straightforward but restoring them was a bit more difficult. The problem is that a ProjectFile is not always attached to a cbEditor but the cbEditor (actually scintilla) is the entity that maintains the active bookmarks.

The solution was to create a "cache" of sorts in ProjectFile. I think the implementation, nevertheless, is reasonably clean and efficient. But it required changing the APIs in ProjectFile and cbEditor slightly. Most notably is that I had to change ProjectFile::editorOpen into an enum and this impacted some plugins.

Feedback is welcome...

ollydbg 2009-06-09 16:23

Hi, raybert

The BrowserTracker is already implement some function similar like you patch?

raybert 2009-06-09 20:18

Hi,

I'm not certain what the BrowserTracker can or cannot do. I'm not aware of it being able to save bookmarks, however. Are you saying it can? If so, I'll take a look. My bookmarks were being forgotten before I wrote this.