|
From: David H. <no...@so...> - 2013-12-13 17:47:26
|
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "codelite".
The branch, master has been updated
via bdc7c6f06248814df93ef6138fd56f6c6815b1ab (commit)
from 2d67f54bf55800af2866b5dd2b3e7376b3fc05fe (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
https://sourceforge.net/p/codelite/codelitegit/ci/bdc7c6f06248814df93ef6138fd56f6c6815b1ab
commit bdc7c6f06248814df93ef6138fd56f6c6815b1ab
Author: dghart <da...@4P...>
Date: Fri Dec 13 17:36:49 2013 +0000
When saving and reloading a project file, try to reapply its 'fold' state
At present, and bookmarks and breakpoints are stored, then reapplied when a file is reloaded. Do the same for folds too.
I've not (yet) made this too intelligent. It works for unaltered files, and for altered ones providing the folds retain their old line-number. However it will fail downstream of any added/deleted lines. Which is still a lot better than nothing!
diff --git a/CodeLite/archive.cpp b/CodeLite/archive.cpp
index 9f99411..0484045 100644
--- a/CodeLite/archive.cpp
+++ b/CodeLite/archive.cpp
@@ -122,6 +122,7 @@ void TabInfo::DeSerialize(Archive &arch)
arch.Read(wxT("FirstVisibleLine"), m_firstVisibleLine);
arch.Read(wxT("CurrentLine"), m_currentLine);
arch.Read(wxT("Bookmarks"), m_bookmarks);
+ arch.Read(wxT("CollapsedFolds"), m_folds);
}
void TabInfo::Serialize(Archive &arch)
@@ -130,6 +131,7 @@ void TabInfo::Serialize(Archive &arch)
arch.Write(wxT("FirstVisibleLine"), m_firstVisibleLine);
arch.Write(wxT("CurrentLine"), m_currentLine);
arch.Write(wxT("Bookmarks"), m_bookmarks);
+ arch.Write(wxT("CollapsedFolds"), m_folds);
}
// class Archive
@@ -210,6 +212,24 @@ bool Archive::Write(const wxString &name, std::vector<TabInfo>& _vTabInfoArr)
return true;
}
+bool Archive::Write(const wxString &name, std::vector<int>& _vInt)
+{
+ if (!m_root) {
+ return false;
+ }
+ wxXmlNode *node = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("IntVector"));
+ m_root->AddChild(node);
+ node->AddProperty(wxT("Name"), name);
+
+ //add an entry for each int in the vector
+ for (size_t i=0; i<_vInt.size(); ++i) {
+ wxXmlNode *child = new wxXmlNode(NULL, wxXML_ELEMENT_NODE, wxT("IntVectorItem"));
+ node->AddChild(child);
+ child->AddProperty(wxT("Value"), wxString::Format(wxT("%i"), _vInt.at(i)));
+ }
+ return true;
+}
+
bool Archive::Write(const wxString &name, const StringMap &str_map)
{
if (!m_root) {
@@ -319,6 +339,32 @@ bool Archive::Read(const wxString &name, std::vector<TabInfo>& _vTabInfoArr)
return false;
}
+bool Archive::Read(const wxString &name, std::vector<int>& _vInt)
+{
+ if (!m_root) {
+ return false;
+ }
+
+ wxXmlNode *node = FindNodeByName(m_root, wxT("IntVector"), name);
+ if (node) {
+ //fill the output array with the values
+ _vInt.clear();
+ wxXmlNode *child = node->GetChildren();
+ while (child) {
+ if (child->GetName() == wxT("IntVectorItem")) {
+ long value;
+ wxString stringvalue = child->GetPropVal(wxT("Value"), wxEmptyString);
+ if (stringvalue.ToLong(&value)) {
+ _vInt.push_back(value);
+ }
+ }
+ child = child->GetNext();
+ }
+ return true;
+ }
+ return false;
+}
+
bool Archive::Read(const wxString &name, StringMap &str_map)
{
if (!m_root) {
diff --git a/CodeLite/archive.h b/CodeLite/archive.h
index 8a4c8e8..47a9f04 100644
--- a/CodeLite/archive.h
+++ b/CodeLite/archive.h
@@ -79,6 +79,7 @@ public:
bool Write(const wxString &name, const StringMap &str_map);
bool Write(const wxString &name, const wxColour &colour);
bool Write(const wxString &name, std::vector<TabInfo>& _vTabInfoArr);
+ bool Write(const wxString &name, std::vector<int>& _vInt);
bool Write(const wxString &name, const std::map<wxString, wxString> &strinMap);
bool Write(const wxString &name, const std::set<wxString> &s);
bool WriteCData(const wxString &name, const wxString &value);
@@ -99,6 +100,7 @@ public:
bool Read(const wxString &name, SerializedObject *obj);
bool Read(const wxString &name, wxColour &colour);
bool Read(const wxString &name, std::vector<TabInfo>& _vTabInfoArr);
+ bool Read(const wxString &name, std::vector<int>& _vInt);
bool Read(const wxString &name, std::map<wxString, wxString> &strinMap);
bool Read(const wxString &name, std::set<wxString> &s);
bool ReadCData(const wxString &name, wxString &value);
diff --git a/CodeLite/serialized_object.h b/CodeLite/serialized_object.h
index fbfd1c3..0b9ea6a 100644
--- a/CodeLite/serialized_object.h
+++ b/CodeLite/serialized_object.h
@@ -59,6 +59,7 @@ class WXDLLIMPEXP_CL TabInfo : public SerializedObject
int m_firstVisibleLine;
int m_currentLine;
wxArrayString m_bookmarks;
+ std::vector<int> m_folds;
public:
// setters
void SetFileName(const wxString& _fileName) {
@@ -73,6 +74,9 @@ public:
void SetBookmarks(const wxArrayString& _bookmarks) {
this->m_bookmarks = _bookmarks;
}
+ void SetCollapsedFolds(const std::vector<int>& folds) {
+ m_folds = folds;
+ }
//getters
const wxString& GetFileName() const {
return this->m_fileName;
@@ -86,6 +90,9 @@ public:
const wxArrayString& GetBookmarks() const {
return this->m_bookmarks;
}
+ const std::vector<int>& GetCollapsedFolds() const {
+ return m_folds;
+ }
TabInfo();
virtual ~TabInfo();
diff --git a/LiteEditor/cl_editor.cpp b/LiteEditor/cl_editor.cpp
index 970c619..97724b4 100644
--- a/LiteEditor/cl_editor.cpp
+++ b/LiteEditor/cl_editor.cpp
@@ -2245,6 +2245,27 @@ void LEditor::ToggleTopmostFoldsInSelection()
}
}
+void LEditor::StoreCollapsedFoldsToArray(std::vector<int>& folds) const
+{
+ for (int line = 0; line < GetLineCount(); ++line) {
+ if ((GetFoldLevel(line) & wxSTC_FOLDLEVELHEADERFLAG) && (GetFoldExpanded(line) == false)) {
+ folds.push_back(line);
+ }
+ }
+}
+
+void LEditor::LoadCollapsedFoldsFromArray(const std::vector<int>& folds)
+{
+ for (int i = 0; i < folds.size(); ++i) {
+ int line = folds.at(i);
+ // 'line' was collapsed when serialised, so collapse it now. That assumes that the line-numbers haven't changed in the meanwhile.
+ // If we cared enough, we could have saved a fold-level too, and/or the function name +/- the line's displacement within the function. But for now...
+ if (GetFoldLevel(line) & wxSTC_FOLDLEVELHEADERFLAG) {
+ ToggleFold(line);
+ }
+ }
+}
+
//----------------------------------------------
// Bookmarks
//----------------------------------------------
@@ -2499,11 +2520,13 @@ void LEditor::ReloadFile()
return;
}
- // Cache any bookmarks
+ // Store a 'template' of the current file, so that it can be reapplied after
wxArrayString bookmarks;
StoreMarkersToArray(bookmarks);
- // get the pattern of the current file
+ std::vector<int> folds;
+ StoreCollapsedFoldsToArray(folds);
+
int lineNumber = GetCurrentLine();
clMainFrame::Get()->SetStatusMessage(_("Loading file..."), 0, 1);
@@ -2538,8 +2561,11 @@ void LEditor::ReloadFile()
clMainFrame::Get()->GetMainBook()->MarkEditorReadOnly(this, IsFileReadOnly(GetFileName()));
SetReloadingFile( false );
+
+ // Now restore as far as possible the look'n'feel of the file
ManagerST::Get()->GetBreakpointsMgr()->RefreshBreakpointsForEditor(this);
LoadMarkersFromArray(bookmarks);
+ LoadCollapsedFoldsFromArray(folds);
}
void LEditor::SetEditorText(const wxString &text)
diff --git a/LiteEditor/cl_editor.h b/LiteEditor/cl_editor.h
index c010449..759fb7a 100644
--- a/LiteEditor/cl_editor.h
+++ b/LiteEditor/cl_editor.h
@@ -348,6 +348,14 @@ public:
* Find the topmost fold level within the selection, and toggle all selected folds of that level
*/
void ToggleTopmostFoldsInSelection();
+ /**
+ * Load collapsed folds from a vector
+ */
+ void LoadCollapsedFoldsFromArray(const std::vector<int>& folds);
+ /**
+ * Store any collapsed folds to a vector, so they can be serialised
+ */
+ void StoreCollapsedFoldsToArray(std::vector<int>& folds) const;
static FindReplaceDialog* GetFindReplaceDialog() {
diff --git a/LiteEditor/mainbook.cpp b/LiteEditor/mainbook.cpp
index b909ee2..a4c28d4 100644
--- a/LiteEditor/mainbook.cpp
+++ b/LiteEditor/mainbook.cpp
@@ -293,10 +293,15 @@ void MainBook::SaveSession(SessionEntry &session, wxArrayInt& intArr)
oTabInfo.SetFileName(editors[i]->GetFileName().GetFullPath());
oTabInfo.SetFirstVisibleLine(editors[i]->GetFirstVisibleLine());
oTabInfo.SetCurrentLine(editors[i]->GetCurrentLine());
+
wxArrayString astrBookmarks;
editors[i]->StoreMarkersToArray(astrBookmarks);
oTabInfo.SetBookmarks(astrBookmarks);
+ std::vector<int> folds;
+ editors[i]->StoreCollapsedFoldsToArray(folds);
+ oTabInfo.SetCollapsedFolds(folds);
+
vTabInfoArr.push_back(oTabInfo);
}
session.SetTabInfoArr(vTabInfoArr);
@@ -320,6 +325,7 @@ void MainBook::RestoreSession(SessionEntry &session)
editor->ScrollToLine(ti.GetFirstVisibleLine());
editor->SetEnsureCaretIsVisible(editor->PositionFromLine(ti.GetCurrentLine()));
editor->LoadMarkersFromArray(ti.GetBookmarks());
+ editor->LoadCollapsedFoldsFromArray(ti.GetCollapsedFolds());
}
// We can't just use SelectPane() here.
// Notebook::DoPageChangedEvent has posted events to us,
-----------------------------------------------------------------------
Summary of changes:
CodeLite/archive.cpp | 46 ++++++++++++++++++++++++++++++++++++++++++
CodeLite/archive.h | 2 +
CodeLite/serialized_object.h | 7 ++++++
LiteEditor/cl_editor.cpp | 30 +++++++++++++++++++++++++-
LiteEditor/cl_editor.h | 8 +++++++
LiteEditor/mainbook.cpp | 6 +++++
6 files changed, 97 insertions(+), 2 deletions(-)
hooks/post-receive
--
codelite
|