Remove the added/removed items arguments from the selection changed signal
They're only used by one thing (the drag visual tool), so calculating them is pointless overhead most of the time, and it simplifies the visual tool code much less than it complicates the grid code.
This commit is contained in:
parent
c3fb54153f
commit
c9582fe7cf
8 changed files with 36 additions and 63 deletions
|
@ -373,9 +373,8 @@ class AudioTimingControllerDialogue : public AudioTimingController {
|
||||||
/// @param user_triggered Is this a user-initiated commit or an autocommit
|
/// @param user_triggered Is this a user-initiated commit or an autocommit
|
||||||
void DoCommit(bool user_triggered);
|
void DoCommit(bool user_triggered);
|
||||||
|
|
||||||
// SubtitleSelectionListener interface
|
void OnActiveLineChanged();
|
||||||
void OnActiveLineChanged(AssDialogue *new_line);
|
void OnSelectedSetChanged();
|
||||||
void OnSelectedSetChanged(const SubtitleSelection &lines_added, const SubtitleSelection &lines_removed);
|
|
||||||
|
|
||||||
// AssFile events
|
// AssFile events
|
||||||
void OnFileChanged(int type);
|
void OnFileChanged(int type);
|
||||||
|
@ -457,12 +456,12 @@ void AudioTimingControllerDialogue::GetMarkers(const TimeRange &range, AudioMark
|
||||||
video_position_provider.GetMarkers(range, out_markers);
|
video_position_provider.GetMarkers(range, out_markers);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioTimingControllerDialogue::OnActiveLineChanged(AssDialogue *new_line)
|
void AudioTimingControllerDialogue::OnActiveLineChanged()
|
||||||
{
|
{
|
||||||
Revert();
|
Revert();
|
||||||
}
|
}
|
||||||
|
|
||||||
void AudioTimingControllerDialogue::OnSelectedSetChanged(SubtitleSelection const&, SubtitleSelection const&)
|
void AudioTimingControllerDialogue::OnSelectedSetChanged()
|
||||||
{
|
{
|
||||||
RegenerateSelectedLines();
|
RegenerateSelectedLines();
|
||||||
RegenerateInactiveLines();
|
RegenerateInactiveLines();
|
||||||
|
|
|
@ -249,15 +249,13 @@ void BaseGrid::UpdateStyle() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::ClearMaps() {
|
void BaseGrid::ClearMaps() {
|
||||||
Selection old_selection(selection);
|
|
||||||
|
|
||||||
index_line_map.clear();
|
index_line_map.clear();
|
||||||
line_index_map.clear();
|
line_index_map.clear();
|
||||||
selection.clear();
|
selection.clear();
|
||||||
yPos = 0;
|
yPos = 0;
|
||||||
AdjustScrollbar();
|
AdjustScrollbar();
|
||||||
|
|
||||||
AnnounceSelectedSetChanged(Selection(), old_selection);
|
AnnounceSelectedSetChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::UpdateMaps() {
|
void BaseGrid::UpdateMaps() {
|
||||||
|
@ -307,10 +305,9 @@ void BaseGrid::EndBatch() {
|
||||||
if (batch_active_line_changed)
|
if (batch_active_line_changed)
|
||||||
AnnounceActiveLineChanged(active_line);
|
AnnounceActiveLineChanged(active_line);
|
||||||
batch_active_line_changed = false;
|
batch_active_line_changed = false;
|
||||||
if (!batch_selection_added.empty() || !batch_selection_removed.empty())
|
if (batch_selection_changed)
|
||||||
AnnounceSelectedSetChanged(batch_selection_added, batch_selection_removed);
|
AnnounceSelectedSetChanged();
|
||||||
batch_selection_added.clear();
|
batch_selection_changed = false;
|
||||||
batch_selection_removed.clear();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
AdjustScrollbar();
|
AdjustScrollbar();
|
||||||
|
@ -339,19 +336,11 @@ void BaseGrid::SelectRow(int row, bool addToSelected, bool select) {
|
||||||
|
|
||||||
if (select && selection.find(line) == selection.end()) {
|
if (select && selection.find(line) == selection.end()) {
|
||||||
selection.insert(line);
|
selection.insert(line);
|
||||||
|
AnnounceSelectedSetChanged();
|
||||||
Selection added;
|
|
||||||
added.insert(line);
|
|
||||||
|
|
||||||
AnnounceSelectedSetChanged(added, Selection());
|
|
||||||
}
|
}
|
||||||
else if (!select && selection.find(line) != selection.end()) {
|
else if (!select && selection.find(line) != selection.end()) {
|
||||||
selection.erase(line);
|
selection.erase(line);
|
||||||
|
AnnounceSelectedSetChanged();
|
||||||
Selection removed;
|
|
||||||
removed.insert(line);
|
|
||||||
|
|
||||||
AnnounceSelectedSetChanged(Selection(), removed);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int w = GetClientSize().GetWidth();
|
int w = GetClientSize().GetWidth();
|
||||||
|
@ -976,11 +965,8 @@ void BaseGrid::SetByFrame(bool state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::SetSelectedSet(const Selection &new_selection) {
|
void BaseGrid::SetSelectedSet(const Selection &new_selection) {
|
||||||
Selection inserted, removed;
|
|
||||||
set_difference(new_selection, selection, inserted);
|
|
||||||
set_difference(selection, new_selection, removed);
|
|
||||||
selection = new_selection;
|
selection = new_selection;
|
||||||
AnnounceSelectedSetChanged(inserted, removed);
|
AnnounceSelectedSetChanged();
|
||||||
Refresh(false);
|
Refresh(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1023,23 +1009,9 @@ void BaseGrid::AnnounceActiveLineChanged(AssDialogue *new_line) {
|
||||||
SubtitleSelectionController::AnnounceActiveLineChanged(new_line);
|
SubtitleSelectionController::AnnounceActiveLineChanged(new_line);
|
||||||
}
|
}
|
||||||
|
|
||||||
void BaseGrid::AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed) {
|
void BaseGrid::AnnounceSelectedSetChanged() {
|
||||||
if (batch_level > 0) {
|
if (batch_level > 0)
|
||||||
// Remove all previously added lines that are now removed
|
batch_selection_changed = true;
|
||||||
Selection temp;
|
else
|
||||||
set_difference(batch_selection_added, lines_removed, temp);
|
SubtitleSelectionController::AnnounceSelectedSetChanged();
|
||||||
std::swap(temp, batch_selection_added);
|
|
||||||
temp.clear();
|
|
||||||
|
|
||||||
// Remove all previously removed lines that are now added
|
|
||||||
set_difference(batch_selection_removed, lines_added, temp);
|
|
||||||
std::swap(temp, batch_selection_removed);
|
|
||||||
|
|
||||||
// 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 {
|
|
||||||
SubtitleSelectionController::AnnounceSelectedSetChanged(lines_added, lines_removed);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -71,12 +71,8 @@ class BaseGrid : public wxWindow, public SubtitleSelectionController {
|
||||||
int batch_level = 0;
|
int batch_level = 0;
|
||||||
/// Has the active line been changed in the current batch?
|
/// Has the active line been changed in the current batch?
|
||||||
bool batch_active_line_changed = false;
|
bool batch_active_line_changed = false;
|
||||||
/// Lines which will be added to the selection when the current batch is
|
/// Has the selection been changed in the current batch?
|
||||||
/// completed; should be disjoint from selection
|
bool batch_selection_changed = false;
|
||||||
Selection batch_selection_added;
|
|
||||||
/// Lines which will be removed from the selection when the current batch
|
|
||||||
/// is completed; should be a subset of selection
|
|
||||||
Selection batch_selection_removed;
|
|
||||||
|
|
||||||
/// Connection for video seek event. Stored explicitly so that it can be
|
/// Connection for video seek event. Stored explicitly so that it can be
|
||||||
/// blocked if the relevant option is disabled
|
/// blocked if the relevant option is disabled
|
||||||
|
@ -121,7 +117,7 @@ class BaseGrid : public wxWindow, public SubtitleSelectionController {
|
||||||
|
|
||||||
// Re-implement functions from BaseSelectionController to add batching
|
// Re-implement functions from BaseSelectionController to add batching
|
||||||
void AnnounceActiveLineChanged(AssDialogue *new_line);
|
void AnnounceActiveLineChanged(AssDialogue *new_line);
|
||||||
void AnnounceSelectedSetChanged(const Selection &lines_added, const Selection &lines_removed);
|
void AnnounceSelectedSetChanged();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
agi::Context *context; ///< Current project context
|
agi::Context *context; ///< Current project context
|
||||||
|
|
|
@ -65,7 +65,7 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
agi::signal::Signal<ItemDataType> AnnounceActiveLineChanged;
|
agi::signal::Signal<ItemDataType> AnnounceActiveLineChanged;
|
||||||
agi::signal::Signal<Selection const&, Selection const&> AnnounceSelectedSetChanged;
|
agi::signal::Signal<> AnnounceSelectedSetChanged;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
/// Virtual destructor for safety
|
/// Virtual destructor for safety
|
||||||
|
|
|
@ -378,7 +378,7 @@ void SubsEditBox::OnActiveLineChanged(AssDialogue *new_line) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SubsEditBox::OnSelectedSetChanged(const SubtitleSelection &, const SubtitleSelection &) {
|
void SubsEditBox::OnSelectedSetChanged() {
|
||||||
sel = c->selectionController->GetSelectedSet();
|
sel = c->selectionController->GetSelectedSet();
|
||||||
initial_times.clear();
|
initial_times.clear();
|
||||||
}
|
}
|
||||||
|
|
|
@ -148,7 +148,7 @@ class SubsEditBox : public wxPanel {
|
||||||
void OnKeyDown(wxKeyEvent &event);
|
void OnKeyDown(wxKeyEvent &event);
|
||||||
|
|
||||||
void OnActiveLineChanged(AssDialogue *new_line);
|
void OnActiveLineChanged(AssDialogue *new_line);
|
||||||
void OnSelectedSetChanged(const SubtitleSelection &, const SubtitleSelection &);
|
void OnSelectedSetChanged();
|
||||||
void OnLineInitialTextChanged(std::string const& new_text);
|
void OnLineInitialTextChanged(std::string const& new_text);
|
||||||
|
|
||||||
void OnFrameTimeRadio(wxCommandEvent &event);
|
void OnFrameTimeRadio(wxCommandEvent &event);
|
||||||
|
|
|
@ -36,6 +36,7 @@
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <boost/format.hpp>
|
#include <boost/format.hpp>
|
||||||
|
#include <boost/range/algorithm/binary_search.hpp>
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#include <wx/toolbar.h>
|
#include <wx/toolbar.h>
|
||||||
|
@ -49,8 +50,9 @@ static const DraggableFeatureType DRAG_END = DRAG_BIG_CIRCLE;
|
||||||
VisualToolDrag::VisualToolDrag(VideoDisplay *parent, agi::Context *context)
|
VisualToolDrag::VisualToolDrag(VideoDisplay *parent, agi::Context *context)
|
||||||
: VisualTool<VisualToolDragDraggableFeature>(parent, context)
|
: VisualTool<VisualToolDragDraggableFeature>(parent, context)
|
||||||
{
|
{
|
||||||
c->selectionController->GetSelectedSet(selection);
|
|
||||||
connections.push_back(c->selectionController->AddSelectionListener(&VisualToolDrag::OnSelectedSetChanged, this));
|
connections.push_back(c->selectionController->AddSelectionListener(&VisualToolDrag::OnSelectedSetChanged, this));
|
||||||
|
auto const& sel_set = c->selectionController->GetSelectedSet();
|
||||||
|
selection.insert(begin(selection), begin(sel_set), end(sel_set));
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualToolDrag::SetToolbar(wxToolBar *tb) {
|
void VisualToolDrag::SetToolbar(wxToolBar *tb) {
|
||||||
|
@ -155,17 +157,20 @@ template<class C, class T> static bool line_not_present(C const& set, T const& i
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualToolDrag::OnSelectedSetChanged(const SubtitleSelection &added, const SubtitleSelection &removed) {
|
void VisualToolDrag::OnSelectedSetChanged() {
|
||||||
c->selectionController->GetSelectedSet(selection);
|
auto const& new_sel_set = c->selectionController->GetSelectedSet();
|
||||||
|
std::vector<AssDialogue *> new_sel(begin(new_sel_set), end(new_sel_set));
|
||||||
|
|
||||||
bool any_changed = false;
|
bool any_changed = false;
|
||||||
for (auto it = features.begin(); it != features.end(); ) {
|
for (auto it = features.begin(); it != features.end(); ) {
|
||||||
if (removed.count(it->line)) {
|
bool was_selected = boost::binary_search(selection, it->line);
|
||||||
|
bool is_selected = boost::binary_search(new_sel, it->line);
|
||||||
|
if (was_selected && !is_selected) {
|
||||||
sel_features.erase(&*it++);
|
sel_features.erase(&*it++);
|
||||||
any_changed = true;
|
any_changed = true;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (added.count(it->line) && it->type == DRAG_START && line_not_present(sel_features, it)) {
|
if (is_selected && !was_selected && it->type == DRAG_START && line_not_present(sel_features, it)) {
|
||||||
sel_features.insert(&*it);
|
sel_features.insert(&*it);
|
||||||
any_changed = true;
|
any_changed = true;
|
||||||
}
|
}
|
||||||
|
@ -175,6 +180,7 @@ void VisualToolDrag::OnSelectedSetChanged(const SubtitleSelection &added, const
|
||||||
|
|
||||||
if (any_changed)
|
if (any_changed)
|
||||||
parent->Render();
|
parent->Render();
|
||||||
|
selection = std::move(new_sel);
|
||||||
}
|
}
|
||||||
|
|
||||||
void VisualToolDrag::Draw() {
|
void VisualToolDrag::Draw() {
|
||||||
|
@ -232,7 +238,7 @@ void VisualToolDrag::MakeFeatures(AssDialogue *diag, feature_list::iterator pos)
|
||||||
feat->type = DRAG_START;
|
feat->type = DRAG_START;
|
||||||
feat->line = diag;
|
feat->line = diag;
|
||||||
|
|
||||||
if (selection.count(diag))
|
if (boost::binary_search(selection, diag))
|
||||||
sel_features.insert(feat.get());
|
sel_features.insert(feat.get());
|
||||||
features.insert(pos, *feat.release());
|
features.insert(pos, *feat.release());
|
||||||
|
|
||||||
|
|
|
@ -45,7 +45,7 @@ class VisualToolDrag : public VisualTool<VisualToolDragDraggableFeature> {
|
||||||
/// longer exists
|
/// longer exists
|
||||||
Feature *primary = nullptr;
|
Feature *primary = nullptr;
|
||||||
/// The last announced selection set
|
/// The last announced selection set
|
||||||
SubtitleSelection selection;
|
std::vector<AssDialogue *> selection;
|
||||||
|
|
||||||
/// When the button is pressed, will it convert the line to a move (vs. from
|
/// When the button is pressed, will it convert the line to a move (vs. from
|
||||||
/// move to pos)? Used to avoid changing the button's icon unnecessarily
|
/// move to pos)? Used to avoid changing the button's icon unnecessarily
|
||||||
|
@ -57,7 +57,7 @@ class VisualToolDrag : public VisualTool<VisualToolDragDraggableFeature> {
|
||||||
void MakeFeatures(AssDialogue *diag, feature_list::iterator pos);
|
void MakeFeatures(AssDialogue *diag, feature_list::iterator pos);
|
||||||
void MakeFeatures(AssDialogue *diag);
|
void MakeFeatures(AssDialogue *diag);
|
||||||
|
|
||||||
void OnSelectedSetChanged(SubtitleSelection const& lines_added, SubtitleSelection const& lines_removed);
|
void OnSelectedSetChanged();
|
||||||
|
|
||||||
void OnFrameChanged() override;
|
void OnFrameChanged() override;
|
||||||
void OnFileChanged() override;
|
void OnFileChanged() override;
|
||||||
|
|
Loading…
Reference in a new issue