From 22de62de77dc1ec93bb4e71f2faf27eb860d6645 Mon Sep 17 00:00:00 2001 From: Niels Martin Hansen Date: Sat, 26 Jun 2010 15:40:10 +0000 Subject: [PATCH] Add selection change notification batching to the grid. This doesn't seem to actually improve performance, it might rather be line inserts that are glacial. Originally committed to SVN as r4608. --- aegisub/src/base_grid.cpp | 51 +++++++++++++++++++++++++++++++++++++++ aegisub/src/base_grid.h | 9 +++++++ 2 files changed, 60 insertions(+) diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 04416890f..c2ced4751 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -82,6 +82,9 @@ BaseGrid::BaseGrid(wxWindow* parent, wxWindowID id, const wxPoint& pos, const wx lineHeight = 1; // non-zero to avoid div by 0 active_line = 0; + batch_level = 0; + batch_active_line_changed = false; + // Set scrollbar scrollBar = new wxScrollBar(this,GRID_SCROLLBAR,wxDefaultPosition,wxDefaultSize,wxSB_VERTICAL); scrollBar->SetScrollbar(0,10,100,10); @@ -160,6 +163,8 @@ void BaseGrid::ClearMaps() { /// void BaseGrid::BeginBatch() { //Freeze(); + + ++batch_level; } @@ -167,6 +172,18 @@ void BaseGrid::BeginBatch() { /// @brief End batch /// void BaseGrid::EndBatch() { + --batch_level; + assert(batch_level >= 0); + if (batch_level == 0) { + if (batch_active_line_changed) + AnnounceActiveLineChanged(active_line); + batch_active_line_changed = false; + if (!batch_selection_added.empty() || !batch_selection_removed.empty()) + AnnounceSelectedSetChanged(batch_selection_added, batch_selection_removed); + batch_selection_added.clear(); + batch_selection_removed.clear(); + } + //Thaw(); AdjustScrollbar(); } @@ -1251,3 +1268,37 @@ void BaseGrid::NextLine() { } } + +void BaseGrid::AnnounceActiveLineChanged(AssDialogue *new_line) { + if (batch_level > 0) + batch_active_line_changed = true; + else + BaseSelectionController::AnnounceActiveLineChanged(new_line); +} + +void BaseGrid::AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) { + if (batch_level > 0) { + // Remove all previously added lines that are now removed + for (Selection::iterator it = batch_selection_added.begin(); it != batch_selection_added.end();) { + if (lines_removed.find(*it) != lines_removed.end()) + it = batch_selection_added.erase(it); + else + ++it; + } + // Remove all previously removed lines that are now added + for (Selection::iterator it = batch_selection_removed.begin(); it != batch_selection_removed.end();) { + if (lines_added.find(*it) != lines_added.end()) + it = batch_selection_removed.erase(it); + else + ++it; + } + // Add new stuff to batch sets + batch_selection_added.insert(lines_added.begin(), lines_added.end()); + batch_selection_removed.insert(lines_removed.begin(), lines_removed.end()); + } + else { + BaseSelectionController::AnnounceSelectedSetChanged(lines_added, lines_removed); + } +} + + diff --git a/aegisub/src/base_grid.h b/aegisub/src/base_grid.h index 5bcf08bea..c812901ed 100644 --- a/aegisub/src/base_grid.h +++ b/aegisub/src/base_grid.h @@ -110,6 +110,11 @@ private: std::vector index_line_map; std::map line_index_map; + int batch_level; + bool batch_active_line_changed; + Selection batch_selection_added; + Selection batch_selection_removed; + protected: /// DOCME @@ -129,6 +134,10 @@ protected: /// DOCME int yPos; + // Re-implement functions from BaseSelectionController to add batching + void AnnounceActiveLineChanged(AssDialogue *new_line); + void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed); + public: // SelectionController implementation virtual void SetActiveLine(AssDialogue *new_line);