2012-12-02 22:14:24 +01:00
|
|
|
// Copyright (c) 2012, Thomas Goyne <plorkyeran@aegisub.org>
|
2010-08-10 03:47:29 +02:00
|
|
|
//
|
2012-12-02 22:14:24 +01:00
|
|
|
// Permission to use, copy, modify, and distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice appear in all copies.
|
2010-08-10 03:47:29 +02:00
|
|
|
//
|
2012-12-02 22:14:24 +01:00
|
|
|
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
|
|
|
|
// WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
|
|
|
|
// MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
|
|
|
|
// ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
|
|
|
|
// WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
|
|
|
|
// ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
|
|
|
|
// OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
2010-08-10 03:47:29 +02:00
|
|
|
//
|
|
|
|
// Aegisub Project http://www.aegisub.org/
|
|
|
|
|
|
|
|
#include <numeric>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <wx/button.h>
|
2014-05-22 21:07:15 +02:00
|
|
|
#include <wx/choicdlg.h>
|
2013-01-04 16:01:50 +01:00
|
|
|
#include <wx/listbox.h>
|
|
|
|
#include <wx/sizer.h>
|
2010-08-10 03:47:29 +02:00
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
int GetSelectedChoices(wxWindow *parent, wxArrayInt& selections, wxString const& message, wxString const& caption, wxArrayString const& choices) {
|
|
|
|
wxMultiChoiceDialog dialog(parent, message, caption, choices);
|
2014-05-22 21:07:15 +02:00
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
auto selAll = new wxButton(&dialog, -1, _("Select &All"));
|
|
|
|
selAll->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) {
|
2014-06-06 17:39:29 +02:00
|
|
|
wxArrayInt sel(choices.size(), 0);
|
2014-05-31 02:05:25 +02:00
|
|
|
std::iota(sel.begin(), sel.end(), 0);
|
|
|
|
dialog.SetSelections(sel);
|
|
|
|
});
|
2010-08-10 03:47:29 +02:00
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
auto selNone = new wxButton(&dialog, -1, _("Select &None"));
|
|
|
|
selNone->Bind(wxEVT_BUTTON, [&](wxCommandEvent&) { dialog.SetSelections(wxArrayInt()); });
|
2010-08-10 03:47:29 +02:00
|
|
|
|
2013-11-21 18:13:36 +01:00
|
|
|
auto buttonSizer = new wxBoxSizer(wxHORIZONTAL);
|
2010-08-10 03:47:29 +02:00
|
|
|
buttonSizer->Add(selAll, wxSizerFlags(0).Left());
|
|
|
|
buttonSizer->Add(selNone, wxSizerFlags(0).Right());
|
|
|
|
|
2014-05-31 02:05:25 +02:00
|
|
|
auto sizer = dialog.GetSizer();
|
2010-08-10 03:47:29 +02:00
|
|
|
sizer->Insert(2, buttonSizer, wxSizerFlags(0).Center());
|
2014-05-31 02:05:25 +02:00
|
|
|
sizer->Fit(&dialog);
|
2010-08-10 03:47:29 +02:00
|
|
|
|
|
|
|
dialog.SetSelections(selections);
|
|
|
|
|
|
|
|
if (dialog.ShowModal() != wxID_OK) return -1;
|
|
|
|
|
|
|
|
selections = dialog.GetSelections();
|
|
|
|
return selections.GetCount();
|
|
|
|
}
|