Add Select All and Select None buttons to the import style from script dialog.

Originally committed to SVN as r4729.
This commit is contained in:
Thomas Goyne 2010-08-10 01:47:29 +00:00
parent 87fac1c571
commit e7eba4c00d
5 changed files with 140 additions and 1 deletions

View file

@ -1099,6 +1099,14 @@
RelativePath="..\..\src\dialog_search_replace.h"
>
</File>
<File
RelativePath="..\..\src\dialog_selected_choices.cpp"
>
</File>
<File
RelativePath="..\..\src\dialog_selected_choices.h"
>
</File>
<File
RelativePath="..\..\src\dialog_selection.cpp"
>

View file

@ -224,6 +224,7 @@ aegisub_2_2_SOURCES = \
dialog_properties.cpp \
dialog_resample.cpp \
dialog_search_replace.cpp \
dialog_selected_choices.cpp \
dialog_selection.cpp \
dialog_shift_times.cpp \
dialog_spellchecker.cpp \

View file

@ -0,0 +1,76 @@
// Copyright (c) 2010, Thomas Goyne <plorkyeran@aegisub.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
/// @file dialog_selected_choices.cpp
/// @brief wxMultiChoiceDialog with Select All and Select None
/// @ingroup
#include "dialog_selected_choices.h"
#include <numeric>
SelectedChoicesDialog::SelectedChoicesDialog(wxWindow *parent, wxString const& message, wxString const& caption, wxArrayString const& choices) {
Create(parent, message, caption, choices);
wxButton *selAll = new wxButton(this, -1, _("Select All"));
wxButton *selNone = new wxButton(this, -1, _("Select None"));
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SelectedChoicesDialog::SelectAll, this, selAll->GetId());
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SelectedChoicesDialog::SelectNone, this, selNone->GetId());
wxBoxSizer *buttonSizer = new wxBoxSizer(wxHORIZONTAL);
buttonSizer->Add(selAll, wxSizerFlags(0).Left());
buttonSizer->Add(selNone, wxSizerFlags(0).Right());
wxSizer *sizer = GetSizer();
sizer->Insert(2, buttonSizer, wxSizerFlags(0).Center());
sizer->Fit(this);
}
void SelectedChoicesDialog::SelectAll(wxCommandEvent&) {
wxArrayInt sel(m_listbox->GetCount(), 1);
sel[0] = 0;
std::partial_sum(sel.begin(), sel.end(), sel.begin());
SetSelections(sel);
}
void SelectedChoicesDialog::SelectNone(wxCommandEvent&) {
SetSelections(wxArrayInt());
}
int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices) {
SelectedChoicesDialog dialog(parent, message, caption, choices);
dialog.SetSelections(selections);
if (dialog.ShowModal() != wxID_OK) return -1;
selections = dialog.GetSelections();
return selections.GetCount();
}

View file

@ -0,0 +1,53 @@
// Copyright (c) 2010, Thomas Goyne <plorkyeran@aegisub.org>
// All rights reserved.
//
// Redistribution and use in source and binary forms, with or without
// modification, are permitted provided that the following conditions are met:
//
// * Redistributions of source code must retain the above copyright notice,
// this list of conditions and the following disclaimer.
// * Redistributions in binary form must reproduce the above copyright notice,
// this list of conditions and the following disclaimer in the documentation
// and/or other materials provided with the distribution.
// * Neither the name of the Aegisub Group nor the names of its contributors
// may be used to endorse or promote products derived from this software
// without specific prior written permission.
//
// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
// AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
// ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
// LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
// CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
// SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
// INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
// CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
// ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
// POSSIBILITY OF SUCH DAMAGE.
//
// Aegisub Project http://www.aegisub.org/
//
// $Id$
/// @file dialog_selected_choices.cpp
/// @brief wxMultiChoiceDialog with Select All and Select None
/// @ingroup
#ifndef AGI_PRE
#include <wx/choicdlg.h>
#endif
/// @class SelectedChoicesDialog
/// @brief wxMultiChoiceDialog with Select All and Select None
class SelectedChoicesDialog : public wxMultiChoiceDialog {
SelectedChoicesDialog(SelectedChoicesDialog const&);
SelectedChoicesDialog& operator=(SelectedChoicesDialog const&);
void SelectAll(wxCommandEvent&);
void SelectNone(wxCommandEvent&);
public:
SelectedChoicesDialog(wxWindow *parent, wxString const& message, wxString const& caption, wxArrayString const& choices);
};
int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices);

View file

@ -48,6 +48,7 @@
#include "ass_file.h"
#include "ass_style.h"
#include "compat.h"
#include "dialog_selected_choices.h"
#include "dialog_style_editor.h"
#include "dialog_style_manager.h"
#include "help_button.h"
@ -852,7 +853,7 @@ void DialogStyleManager::OnCurrentImport(wxCommandEvent &) {
// Get selection
wxArrayInt selections;
int res = wxGetSelectedChoices(selections,_("Choose styles to import:"),_("Import Styles"),styles);
int res = GetSelectedChoices(this,selections,_("Choose styles to import:"),_("Import Styles"),styles);
if (res == -1 || selections.Count() == 0) return;
bool modified = false;