Skip to content

Commit

Permalink
Made bookmarked lines show up with a highlighted background.
Browse files Browse the repository at this point in the history
Made bookmarked lines show up with a highlighted background.

Made bookmarked lines show up with a highlighted background.
  • Loading branch information
ajpalkovic committed Jun 29, 2010
1 parent b04a781 commit b9d6891
Show file tree
Hide file tree
Showing 7 changed files with 25 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/Bookmarks.cpp
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "Bookmarks.h"
#include "Catalyst.h"
#include "Lines.h"
#include <map>

typedef std::vector<cxBookmark>::iterator bookmark_iter;

Expand Down Expand Up @@ -145,3 +146,9 @@ void Bookmarks::ApplyChanges(const std::vector<cxChange>& changes) {
p->end = lines.GetLineEndpos(p->line_id);
}
}

void Bookmarks::BuildMap(std::map<int, bool>& bookmarksMap) const {
for(unsigned int c = 0; c < bookmarks.size(); c++) {
bookmarksMap[bookmarks[c].line_id] = true;
}
}
3 changes: 3 additions & 0 deletions src/Bookmarks.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
#define __BOOKMARKS_H__

#include <vector>
#include <map>

const unsigned int NO_BOOKMARK = (unsigned int)-1;

Expand Down Expand Up @@ -32,6 +33,8 @@ class Bookmarks {

void ApplyChanges(const std::vector<cxChange>& changes);

void BuildMap(std::map<int, bool>& bookmarksMap) const;

private:
std::vector<cxBookmark> bookmarks;
const ILinePositions& lines;
Expand Down
6 changes: 6 additions & 0 deletions src/EditorCtrl.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -8854,10 +8854,12 @@ void EditorCtrl::ToogleBookmarkOnCurrentLine() {
void EditorCtrl::AddBookmark(unsigned int line_id, bool toggle) {
wxASSERT(line_id < m_lines.GetLineCount());
bookmarks.AddBookmark(line_id, toggle);
DrawLayout();
}

void EditorCtrl::DeleteBookmark(unsigned int line_id) {
bookmarks.DeleteBookmark(line_id);
DrawLayout();
}

void EditorCtrl::GotoNextBookmark() {
Expand All @@ -8878,6 +8880,10 @@ void EditorCtrl::GotoPrevBookmark() {
}
}

void EditorCtrl::BuildBookmarkMap(std::map<int, bool>& bookmarksMap) const {
bookmarks.BuildMap(bookmarksMap);
}

EditorChangeState EditorCtrl::GetChangeState() const {
return EditorChangeState(this->GetId(), this->GetChangeToken());
}
Expand Down
1 change: 1 addition & 0 deletions src/EditorCtrl.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -361,6 +361,7 @@ class EditorCtrl : public KeyHookable<wxControl>,
void GotoNextBookmark();
void GotoPrevBookmark();
const vector<cxBookmark>& GetBookmarks() const;
void BuildBookmarkMap(std::map<int, bool>& bookmarksMap) const;

// Scroll Position
int GetYScrollPos() const { return scrollPos; };
Expand Down
2 changes: 2 additions & 0 deletions src/IFoldingEditor.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <wx/platform.h>
#include <vector>

struct ckBookmark;
struct cxFold;
class interval;
class BracketHighlight;
Expand All @@ -18,6 +19,7 @@ class IFoldingEditor {
// The only pubilc use of this member is in Lines; the underlying EditorCtrl member
// is used internally in the editor control.
virtual const BracketHighlight& GetHlBracket() const = 0;
virtual void BuildBookmarkMap(std::map<int, bool>& bookmarksMap) const = 0;
};

#endif // __IFOLDINGEDITOR_H__
7 changes: 6 additions & 1 deletion src/Lines.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
#include "tmTheme.h"
#include <wx/filename.h>
#include "styler.h"
#include <map>

Lines::Lines(wxDC& dc, DocumentWrapper& dw, IFoldingEditor& editorCtrl, const tmTheme& theme):
dc(dc),
Expand Down Expand Up @@ -1003,6 +1004,10 @@ void Lines::Draw(int xoffset, int yoffset, wxRect& rect) {
dc.DrawRectangle(0, FoldedYPos(ll->height()) + yoffset, rect.width, line.GetCharHeight());
}

//Build a map of the bookmarks for constant time access
std::map<int, bool> bookmarksMap;
m_editorCtrl.BuildBookmarkMap(bookmarksMap);

if (top_ypos < height) {
// Get the first visible line
unsigned int firstline = ll->find_ypos(top_ypos);
Expand All @@ -1019,7 +1024,7 @@ void Lines::Draw(int xoffset, int yoffset, wxRect& rect) {
SetLine(firstline);

// Check if we should highlight the line background
if (firstline == currentLine) {
if (firstline == currentLine || bookmarksMap.find(firstline) != bookmarksMap.end()) {
dc.SetBrush(wxBrush(m_theme.lineHighlightColor));
dc.SetPen(wxPen(m_theme.lineHighlightColor));

Expand Down
Empty file modified src/Lines.h
100644 → 100755
Empty file.

0 comments on commit b9d6891

Please sign in to comment.