From d53acba795613b4adea62017561599fbf1d6d96d Mon Sep 17 00:00:00 2001 From: Carl Hetherington Date: Sun, 15 Nov 2020 22:36:59 +0100 Subject: [PATCH] Add Remove button to language tag dialogue. --- src/wx/language_tag_dialog.cc | 26 ++++++++++++++++++++++++++ src/wx/language_tag_dialog.h | 2 ++ 2 files changed, 28 insertions(+) diff --git a/src/wx/language_tag_dialog.cc b/src/wx/language_tag_dialog.cc index 2854479a7..0d0203e90 100644 --- a/src/wx/language_tag_dialog.cc +++ b/src/wx/language_tag_dialog.cc @@ -37,6 +37,7 @@ #include +using std::min; using std::pair; using std::string; using std::vector; @@ -197,6 +198,8 @@ LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag) button_sizer->Add (_add_variant, 0, wxTOP | wxBOTTOM | wxEXPAND, 2); _add_external = new wxButton(this, wxID_ANY, "Add external"); button_sizer->Add (_add_external, 0, wxTOP | wxBOTTOM | wxEXPAND, 2); + _remove = new wxButton(this, wxID_ANY, "Remove"); + button_sizer->Add (_remove, 0, wxTOP | wxBOTTOM | wxEXPAND, 2); _choose_subtag_panel = new LanguageSubtagPanel (this); _choose_subtag_panel->set (dcp::LanguageTag::LANGUAGE, ""); @@ -233,6 +236,7 @@ LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag) _add_region->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_to_current_tag, this, dcp::LanguageTag::REGION, boost::optional())); _add_variant->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_to_current_tag, this, dcp::LanguageTag::VARIANT, boost::optional())); _add_external->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::add_to_current_tag, this, dcp::LanguageTag::EXTLANG, boost::optional())); + _remove->Bind (wxEVT_BUTTON, boost::bind(&LanguageTagDialog::remove_from_current_tag, this)); _choose_subtag_panel->SelectionChanged.connect(bind(&LanguageTagDialog::chosen_subtag_changed, this, _1)); _choose_subtag_panel->SearchChanged.connect(bind(&LanguageTagDialog::search_changed, this, _1)); _current_tag_list->Bind (wxEVT_LIST_ITEM_SELECTED, boost::bind(&LanguageTagDialog::current_tag_selection_changed, this)); @@ -240,6 +244,24 @@ LanguageTagDialog::LanguageTagDialog (wxWindow* parent, dcp::LanguageTag tag) } +void +LanguageTagDialog::remove_from_current_tag () +{ + long int selected = _current_tag_list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + if (selected <= 0) { + return; + } + + _current_tag_subtags.erase (_current_tag_subtags.begin() + selected); + _current_tag_list->DeleteItem (selected); + + _current_tag_list->SetItemState (min(selected, _current_tag_list->GetItemCount() - 1L), wxLIST_STATE_SELECTED, wxLIST_STATE_SELECTED); + + setup_sensitivity (); + current_tag_selection_changed (); +} + + dcp::LanguageTag LanguageTagDialog::get () const { dcp::LanguageTag tag; @@ -354,6 +376,8 @@ LanguageTagDialog::chosen_subtag_changed (optional _current_tag_list->SetItem (selected, 0, subtag_type_name(_current_tag_subtags[selected].type)); _current_tag_list->SetItem (selected, 1, selection->description); } + + setup_sensitivity (); } void @@ -381,6 +405,8 @@ LanguageTagDialog::setup_sensitivity () break; } } + long int selected = _current_tag_list->GetNextItem (-1, wxLIST_NEXT_ALL, wxLIST_STATE_SELECTED); + _remove->Enable (selected > 0); } diff --git a/src/wx/language_tag_dialog.h b/src/wx/language_tag_dialog.h index 1199e2d53..cd6f2c8b3 100644 --- a/src/wx/language_tag_dialog.h +++ b/src/wx/language_tag_dialog.h @@ -56,6 +56,7 @@ private: std::string subtag_type_name (dcp::LanguageTag::SubtagType type); void search_changed (std::string search); void add_to_current_tag (dcp::LanguageTag::SubtagType type, boost::optional subtag); + void remove_from_current_tag (); void current_tag_selection_changed (); void chosen_subtag_changed (boost::optional selection); void setup_sensitivity (); @@ -67,6 +68,7 @@ private: wxButton* _add_region; wxButton* _add_variant; wxButton* _add_external; + wxButton* _remove; }; -- 2.30.2