78
101
DialogExport::DialogExport(agi::Context *c)
79
: wxDialog(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
102
: d(c->parent, -1, _("Export"), wxDefaultPosition, wxSize(200, 100), wxCAPTION | wxCLOSE_BOX)
81
, exporter(agi::util::make_unique<AssExporter>(c))
83
SetIcon(GETICON(export_menu_16));
84
SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
106
d.SetIcon(GETICON(export_menu_16));
107
d.SetExtraStyle(wxWS_EX_VALIDATE_RECURSIVELY);
86
std::vector<std::string> filters = exporter->GetAllFilterNames();
87
filter_list = new wxCheckListBox(this, -1, wxDefaultPosition, wxSize(200, 100), to_wx(filters));
109
std::vector<std::string> filters = exporter.GetAllFilterNames();
110
filter_list = new wxCheckListBox(&d, -1, wxDefaultPosition, wxSize(200, 100), to_wx(filters));
88
111
filter_list->Bind(wxEVT_CHECKLISTBOX, [=](wxCommandEvent&) { RefreshOptions(); });
89
112
filter_list->Bind(wxEVT_LISTBOX, &DialogExport::OnChange, this);
91
114
// Get selected filters
92
std::string selected = c->ass->GetScriptInfo("Export filters");
115
std::string const& selected = c->ass->Properties.export_filters;
93
116
boost::char_separator<char> sep("|");
94
117
for (auto const& token : boost::tokenizer<boost::char_separator<char>>(selected, sep)) {
95
118
auto it = find(begin(filters), end(filters), token);
97
120
filter_list->Check(distance(begin(filters), it));
100
wxButton *btn_up = new wxButton(this, -1, _("Move &Up"), wxDefaultPosition, wxSize(90, -1));
101
wxButton *btn_down = new wxButton(this, -1, _("Move &Down"), wxDefaultPosition, wxSize(90, -1));
102
wxButton *btn_all = new wxButton(this, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
103
wxButton *btn_none = new wxButton(this, -1, _("Select &None"), wxDefaultPosition, wxSize(80, -1));
123
wxButton *btn_up = new wxButton(&d, -1, _("Move &Up"), wxDefaultPosition, wxSize(90, -1));
124
wxButton *btn_down = new wxButton(&d, -1, _("Move &Down"), wxDefaultPosition, wxSize(90, -1));
125
wxButton *btn_all = new wxButton(&d, -1, _("Select &All"), wxDefaultPosition, wxSize(80, -1));
126
wxButton *btn_none = new wxButton(&d, -1, _("Select &None"), wxDefaultPosition, wxSize(80, -1));
105
128
btn_up->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
106
129
btn_down->Bind(wxEVT_BUTTON, [=](wxCommandEvent&) { swap(filter_list, filter_list->GetSelection() - 1, 0); });
113
136
top_buttons->Add(btn_all, wxSizerFlags(1).Expand());
114
137
top_buttons->Add(btn_none, wxSizerFlags(1).Expand());
116
filter_description = new wxTextCtrl(this, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
139
filter_description = new wxTextCtrl(&d, -1, "", wxDefaultPosition, wxSize(200, 60), wxTE_MULTILINE | wxTE_READONLY);
118
141
// Charset dropdown list
119
wxStaticText *charset_list_label = new wxStaticText(this, -1, _("Text encoding:"));
120
charset_list = new wxChoice(this, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
142
wxStaticText *charset_list_label = new wxStaticText(&d, -1, _("Text encoding:"));
143
charset_list = new wxChoice(&d, -1, wxDefaultPosition, wxDefaultSize, agi::charset::GetEncodingsList<wxArrayString>());
121
144
wxSizer *charset_list_sizer = new wxBoxSizer(wxHORIZONTAL);
122
145
charset_list_sizer->Add(charset_list_label, wxSizerFlags().Center().Border(wxRIGHT));
123
146
charset_list_sizer->Add(charset_list, wxSizerFlags(1).Expand());
124
if (!charset_list->SetStringSelection(to_wx(c->ass->GetScriptInfo("Export Encoding"))))
147
if (!charset_list->SetStringSelection(to_wx(c->ass->Properties.export_encoding)))
125
148
charset_list->SetStringSelection("Unicode (UTF-8)");
127
wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, this, _("Filters"));
150
wxSizer *top_sizer = new wxStaticBoxSizer(wxVERTICAL, &d, _("Filters"));
128
151
top_sizer->Add(filter_list, wxSizerFlags(1).Expand());
129
152
top_sizer->Add(top_buttons, wxSizerFlags(0).Expand());
130
153
top_sizer->Add(filter_description, wxSizerFlags(0).Expand().Border(wxTOP));
131
154
top_sizer->Add(charset_list_sizer, wxSizerFlags(0).Expand().Border(wxTOP));
133
wxStdDialogButtonSizer *btn_sizer = CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
156
auto btn_sizer = d.CreateStdDialogButtonSizer(wxOK | wxCANCEL | wxHELP);
134
157
btn_sizer->GetAffirmativeButton()->SetLabelText(_("Export..."));
135
Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
136
Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Export"), wxID_HELP);
158
d.Bind(wxEVT_BUTTON, &DialogExport::OnProcess, this, wxID_OK);
159
d.Bind(wxEVT_BUTTON, std::bind(&HelpButton::OpenPage, "Export"), wxID_HELP);
138
161
wxSizer *horz_sizer = new wxBoxSizer(wxHORIZONTAL);
139
162
opt_sizer = new wxBoxSizer(wxVERTICAL);
140
exporter->DrawSettings(this, opt_sizer);
163
exporter.DrawSettings(&d, opt_sizer);
141
164
horz_sizer->Add(top_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxRIGHT));
142
165
horz_sizer->Add(opt_sizer, wxSizerFlags(1).Expand().Border(wxALL & ~wxLEFT));
144
167
wxSizer *main_sizer = new wxBoxSizer(wxVERTICAL);
145
168
main_sizer->Add(horz_sizer, wxSizerFlags(1).Expand());
146
169
main_sizer->Add(btn_sizer, wxSizerFlags().Expand().Border(wxALL & ~wxTOP));
147
SetSizerAndFit(main_sizer);
170
d.SetSizerAndFit(main_sizer);
148
171
RefreshOptions();
152
175
DialogExport::~DialogExport() {
153
std::string infoList;
176
c->ass->Properties.export_filters.clear();
154
177
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
155
178
if (filter_list->IsChecked(i)) {
156
if (!infoList.empty())
158
infoList += from_wx(filter_list->GetString(i));
179
if (!c->ass->Properties.export_filters.empty())
180
c->ass->Properties.export_filters += "|";
181
c->ass->Properties.export_filters += from_wx(filter_list->GetString(i));
161
c->ass->SetScriptInfo("Export filters", infoList);
164
186
void DialogExport::OnProcess(wxCommandEvent &) {
165
if (!TransferDataFromWindow()) return;
187
if (!d.TransferDataFromWindow()) return;
167
auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), this);
189
auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), &d);
168
190
if (filename.empty()) return;
170
192
for (size_t i = 0; i < filter_list->GetCount(); ++i) {
171
193
if (filter_list->IsChecked(i))
172
exporter->AddFilter(from_wx(filter_list->GetString(i)));
194
exporter.AddFilter(from_wx(filter_list->GetString(i)));
176
198
wxBusyCursor busy;
177
c->ass->SetScriptInfo("Export Encoding", from_wx(charset_list->GetStringSelection()));
178
exporter->Export(filename, from_wx(charset_list->GetStringSelection()), this);
180
catch (agi::UserCancelException const&) {
182
catch (const char *error) {
183
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
185
catch (wxString const& error) {
186
wxMessageBox(error, "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
199
c->ass->Properties.export_encoding = from_wx(charset_list->GetStringSelection());
200
exporter.Export(filename, from_wx(charset_list->GetStringSelection()), &d);
202
catch (agi::UserCancelException const&) { }
188
203
catch (agi::Exception const& err) {
189
wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
204
wxMessageBox(to_wx(err.GetMessage()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
191
206
catch (std::exception const& err) {
192
wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
207
wxMessageBox(to_wx(err.what()), "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
195
wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, this);
210
wxMessageBox("Unknown error", "Error exporting subtitles", wxOK | wxICON_ERROR | wxCENTER, &d);
201
216
void DialogExport::OnChange(wxCommandEvent &) {
202
217
wxString sel = filter_list->GetStringSelection();
203
218
if (!sel.empty())
204
filter_description->SetValue(to_wx(exporter->GetDescription(from_wx(sel))));
219
filter_description->SetValue(to_wx(exporter.GetDescription(from_wx(sel))));
207
222
void DialogExport::SetAll(bool new_value) {