diff --git a/aegisub/src/base_grid.cpp b/aegisub/src/base_grid.cpp index 6af26c24f..8f134143b 100644 --- a/aegisub/src/base_grid.cpp +++ b/aegisub/src/base_grid.cpp @@ -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)) { diff --git a/aegisub/src/base_grid.h b/aegisub/src/base_grid.h index 3bbcbf3be..839c7f550 100644 --- a/aegisub/src/base_grid.h +++ b/aegisub/src/base_grid.h @@ -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(); diff --git a/aegisub/src/selection_controller.h b/aegisub/src/selection_controller.h index d9a0751a4..affaba7a3 100644 --- a/aegisub/src/selection_controller.h +++ b/aegisub/src/selection_controller.h @@ -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 *listener) { }