Add SelectionController::SetSelectionAndActive, which automatically batches the changes to the selection and active line

Originally committed to SVN as r6752.
This commit is contained in:
Thomas Goyne 2012-05-05 02:11:03 +00:00
parent 70abaf75d7
commit f756aa73c1
3 changed files with 18 additions and 0 deletions

View file

@ -1077,6 +1077,13 @@ void BaseGrid::SetActiveLine(AssDialogue *new_line) {
}
}
void BaseGrid::SetSelectionAndActive(Selection const& new_selection, AssDialogue *new_line) {
BeginBatch();
SetSelectedSet(new_selection);
SetActiveLine(new_line);
EndBatch();
}
void BaseGrid::PrevLine() {
int cur_line_i = GetDialogueIndex(GetActiveLine());
if (AssDialogue *prev_line = GetDialogue(cur_line_i-1)) {

View file

@ -149,6 +149,7 @@ public:
void SetSelectedSet(const Selection &new_selection);
void GetSelectedSet(Selection &res) const { res = selection; }
Selection const& GetSelectedSet() const { return selection; }
void SetSelectionAndActive(Selection const& new_selection, AssDialogue *new_line);;
void NextLine();
void PrevLine();

View file

@ -129,6 +129,15 @@ public:
/// @return The selected set
virtual Selection const& GetSelectedSet() const = 0;
/// @brief Set both the selected set and active line
/// @param new_line Subtitle line to become the new active line
/// @param new_selection The set of subtitle lines to become the new selected set
///
/// This sets both the active line and selected set before announcing the
/// change to either of them, and is guaranteed to announce the active line
/// change before the selection change.
virtual void SetSelectionAndActive(Selection const& new_selection, ItemDataType *new_line) = 0;
/// @brief Change the active line to the next in sequence
///
/// If there is no logical next line in sequence, no change happens. This should
@ -212,6 +221,7 @@ public:
virtual ItemDataType * GetActiveLine() const { return 0; }
virtual void SetSelectedSet(const Selection &new_selection) { }
virtual void GetSelectedSet(Selection &selection) const { }
virtual void SetSelectionAndActive(Selection const& new_selection, ItemDataType *new_line) { }
virtual void NextLine() { }
virtual void PrevLine() { }
virtual void AddSelectionListener(SelectionListener<ItemDataType> *listener) { }