forked from mia/Aegisub
Make lines_added and lines_removed in SelectionListener::OnSelectedSetChanged mutually exclusive.
Originally committed to SVN as r4629.
This commit is contained in:
parent
574a247559
commit
dfb844b6ab
2 changed files with 23 additions and 31 deletions
|
@ -61,6 +61,13 @@
|
||||||
#include "video_context.h"
|
#include "video_context.h"
|
||||||
#include "video_slider.h"
|
#include "video_slider.h"
|
||||||
|
|
||||||
|
template<class S1, class S2, class D>
|
||||||
|
static inline void set_difference(const S1 &src1, const S2 &src2, D &dst) {
|
||||||
|
std::set_difference(
|
||||||
|
src1.begin(), src1.end(), src2.begin(), src2.end(),
|
||||||
|
std::inserter(dst, dst.begin()));
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/// @brief Constructor
|
/// @brief Constructor
|
||||||
/// @param parent
|
/// @param parent
|
||||||
|
@ -236,12 +243,9 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
||||||
AssDialogue *line = index_line_map[row];
|
AssDialogue *line = index_line_map[row];
|
||||||
|
|
||||||
if (!addToSelected) {
|
if (!addToSelected) {
|
||||||
Selection old_selection(selection);
|
Selection sel;
|
||||||
selection.clear();
|
if (select) sel.insert(line);
|
||||||
if (select) {
|
SetSelectedSet(sel);
|
||||||
selection.insert(line);
|
|
||||||
}
|
|
||||||
AnnounceSelectedSetChanged(selection, old_selection);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (select && selection.find(line) == selection.end()) {
|
else if (select && selection.find(line) == selection.end()) {
|
||||||
|
@ -278,28 +282,22 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
||||||
/// @brief Selects visible lines
|
/// @brief Selects visible lines
|
||||||
///
|
///
|
||||||
void BaseGrid::SelectVisible() {
|
void BaseGrid::SelectVisible() {
|
||||||
Selection lines_removed;
|
Selection new_selection;
|
||||||
GetSelectedSet(lines_removed);
|
|
||||||
|
|
||||||
int rows = GetRows();
|
int rows = GetRows();
|
||||||
bool selectedOne = false;
|
bool selectedOne = false;
|
||||||
for (int i=0;i<rows;i++) {
|
for (int i=0;i<rows;i++) {
|
||||||
if (IsDisplayed(GetDialogue(i))) {
|
AssDialogue *diag = GetDialogue(i);
|
||||||
|
if (IsDisplayed(diag)) {
|
||||||
if (!selectedOne) {
|
if (!selectedOne) {
|
||||||
SelectRow(i,false);
|
|
||||||
MakeCellVisible(i,0);
|
MakeCellVisible(i,0);
|
||||||
selectedOne = true;
|
selectedOne = true;
|
||||||
}
|
}
|
||||||
else {
|
new_selection.insert(diag);
|
||||||
SelectRow(i,true);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Selection lines_added;
|
SetSelectedSet(new_selection);
|
||||||
GetSelectedSet(lines_added);
|
|
||||||
|
|
||||||
AnnounceSelectedSetChanged(lines_added, lines_removed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -1247,9 +1245,12 @@ wxArrayInt BaseGrid::GetRangeArray(int n1,int n2) const {
|
||||||
|
|
||||||
|
|
||||||
void BaseGrid::SetSelectedSet(const Selection &new_selection) {
|
void BaseGrid::SetSelectedSet(const Selection &new_selection) {
|
||||||
Selection old_selection(selection);
|
Selection inserted;
|
||||||
|
Selection removed;
|
||||||
|
set_difference(new_selection, selection, inserted);
|
||||||
|
set_difference(selection, new_selection, removed);
|
||||||
selection = new_selection;
|
selection = new_selection;
|
||||||
AnnounceSelectedSetChanged(new_selection, old_selection);
|
AnnounceSelectedSetChanged(inserted, removed);
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1300,18 +1301,12 @@ void BaseGrid::AnnounceSelectedSetChanged(const Selection &lines_added, const Se
|
||||||
if (batch_level > 0) {
|
if (batch_level > 0) {
|
||||||
// Remove all previously added lines that are now removed
|
// Remove all previously added lines that are now removed
|
||||||
Selection temp;
|
Selection temp;
|
||||||
std::set_difference(
|
set_difference(batch_selection_added, lines_removed, temp);
|
||||||
batch_selection_added.begin(), batch_selection_added.end(),
|
|
||||||
lines_removed.begin(), lines_removed.end(),
|
|
||||||
std::inserter(temp, temp.begin()));
|
|
||||||
std::swap(temp, batch_selection_added);
|
std::swap(temp, batch_selection_added);
|
||||||
temp.clear();
|
temp.clear();
|
||||||
|
|
||||||
// Remove all previously removed lines that are now added
|
// Remove all previously removed lines that are now added
|
||||||
std::set_difference(
|
set_difference(batch_selection_removed, lines_added, temp);
|
||||||
batch_selection_removed.begin(), batch_selection_removed.end(),
|
|
||||||
lines_added.begin(), lines_added.end(),
|
|
||||||
std::inserter(temp, temp.begin()));
|
|
||||||
std::swap(temp, batch_selection_removed);
|
std::swap(temp, batch_selection_removed);
|
||||||
|
|
||||||
// Add new stuff to batch sets
|
// Add new stuff to batch sets
|
||||||
|
|
|
@ -61,10 +61,7 @@ public:
|
||||||
/// @param lines_added Lines added to the selection
|
/// @param lines_added Lines added to the selection
|
||||||
/// @param lines_removed Lines removed from the selection
|
/// @param lines_removed Lines removed from the selection
|
||||||
///
|
///
|
||||||
/// Conceptually, removal happens before addition, for the purpose of this change notification.
|
/// The two sets must not intersect.
|
||||||
///
|
|
||||||
/// In case the two sets overlap, the intersection are lines that were previously selected
|
|
||||||
/// and remain selected.
|
|
||||||
virtual void OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) = 0;
|
virtual void OnSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue