Eliminate implicit std::string <-> wxString conversions

On Windows these don't use UTF-8 and so are broken.
This commit is contained in:
Thomas Goyne 2014-12-31 19:41:56 -08:00
parent 26050bd4e0
commit ef4424f5e2
17 changed files with 34 additions and 29 deletions

View file

@ -112,8 +112,9 @@ std::string AegisubLocale::PickLanguage() {
style); style);
if (dialog.ShowModal() == wxID_OK) { if (dialog.ShowModal() == wxID_OK) {
int picked = dialog.GetSelection(); int picked = dialog.GetSelection();
if (langs[picked] != active_language) auto new_lang = from_wx(langs[picked]);
return from_wx(langs[picked]); if (new_lang != active_language)
return new_lang;
} }
return ""; return "";

View file

@ -461,8 +461,8 @@ namespace Automation4 {
auto dialog = static_cast<wxDialog *>(parent); auto dialog = static_cast<wxDialog *>(parent);
auto bs = new wxStdDialogButtonSizer; auto bs = new wxStdDialogButtonSizer;
auto make_button = [&](wxWindowID id, int button_pushed, wxString const& text) -> wxButton *{ auto make_button = [&](wxWindowID id, int button_pushed, std::string const& text) -> wxButton *{
auto button = new wxButton(window, id, text); auto button = new wxButton(window, id, to_wx(text));
button->Bind(wxEVT_BUTTON, [=](wxCommandEvent &evt) { button->Bind(wxEVT_BUTTON, [=](wxCommandEvent &evt) {
this->button_pushed = button_pushed; this->button_pushed = button_pushed;
dialog->TransferDataFromWindow(); dialog->TransferDataFromWindow();

View file

@ -159,10 +159,10 @@ struct app_language final : public Command {
void operator()(agi::Context *c) override { void operator()(agi::Context *c) override {
// Get language // Get language
wxString new_language = wxGetApp().locale.PickLanguage(); auto new_language = wxGetApp().locale.PickLanguage();
if (!new_language) return; if (new_language.empty()) return;
OPT_SET("App/Language")->SetString(from_wx(new_language)); OPT_SET("App/Language")->SetString(new_language);
// Ask to restart program // Ask to restart program
int result = wxMessageBox("Aegisub needs to be restarted so that the new language can be applied. Restart now?", "Restart Aegisub?", wxYES_NO | wxICON_QUESTION | wxCENTER); int result = wxMessageBox("Aegisub needs to be restarted so that the new language can be applied. Restart now?", "Restart Aegisub?", wxYES_NO | wxICON_QUESTION | wxCENTER);

View file

@ -37,6 +37,7 @@
#include "../audio_controller.h" #include "../audio_controller.h"
#include "../audio_karaoke.h" #include "../audio_karaoke.h"
#include "../audio_timing.h" #include "../audio_timing.h"
#include "../compat.h"
#include "../include/aegisub/context.h" #include "../include/aegisub/context.h"
#include "../libresrc/libresrc.h" #include "../libresrc/libresrc.h"
#include "../options.h" #include "../options.h"
@ -79,9 +80,9 @@ struct audio_open final : public Command {
STR_HELP("Open an audio file") STR_HELP("Open an audio file")
void operator()(agi::Context *c) override { void operator()(agi::Context *c) override {
wxString str = _("Audio Formats") + " (*.aac,*.ac3,*.ape,*.dts,*.flac,*.m4a,*.mka,*.mp3,*.mp4,*.ogg,*.w64,*.wav,*.wma)|*.aac;*.ac3;*.ape;*.dts;*.flac;*.m4a;*.mka;*.mp3;*.mp4;*.ogg;*.w64;*.wav;*.wma|" auto str = from_wx(_("Audio Formats") + " (*.aac,*.ac3,*.ape,*.dts,*.flac,*.m4a,*.mka,*.mp3,*.mp4,*.ogg,*.w64,*.wav,*.wma)|*.aac;*.ac3;*.ape;*.dts;*.flac;*.m4a;*.mka;*.mp3;*.mp4;*.ogg;*.w64;*.wav;*.wma|"
+ _("Video Formats") + " (*.asf,*.avi,*.avs,*.d2v,*.m2ts,*.m4v,*.mkv,*.mov,*.mp4,*.mpeg,*.mpg,*.ogm,*.webm,*.wmv,*.ts)|*.asf;*.avi;*.avs;*.d2v;*.m2ts;*.m4v;*.mkv;*.mov;*.mp4;*.mpeg;*.mpg;*.ogm;*.webm;*.wmv;*.ts|" + _("Video Formats") + " (*.asf,*.avi,*.avs,*.d2v,*.m2ts,*.m4v,*.mkv,*.mov,*.mp4,*.mpeg,*.mpg,*.ogm,*.webm,*.wmv,*.ts)|*.asf;*.avi;*.avs;*.d2v;*.m2ts;*.m4v;*.mkv;*.mov;*.mp4;*.mpeg;*.mpg;*.ogm;*.webm;*.wmv;*.ts|"
+ _("All Files") + " (*.*)|*.*"; + _("All Files") + " (*.*)|*.*");
auto filename = OpenFileSelector(_("Open Audio File"), "Path/Last/Audio", "", "", str, c->parent); auto filename = OpenFileSelector(_("Open Audio File"), "Path/Last/Audio", "", "", str, c->parent);
if (!filename.empty()) if (!filename.empty())
c->project->LoadAudio(filename); c->project->LoadAudio(filename);

View file

@ -31,6 +31,7 @@
#include "command.h" #include "command.h"
#include "../compat.h"
#include "../include/aegisub/context.h" #include "../include/aegisub/context.h"
#include "../libresrc/libresrc.h" #include "../libresrc/libresrc.h"
#include "../options.h" #include "../options.h"
@ -71,7 +72,9 @@ struct keyframe_open final : public Command {
auto filename = OpenFileSelector( auto filename = OpenFileSelector(
_("Open keyframes file"), _("Open keyframes file"),
"Path/Last/Keyframes", "" ,".txt", "Path/Last/Keyframes", "" ,".txt",
_("All Supported Formats") + " (*.txt, *.pass, *.stats, *.log)|*.txt;*.pass;*.stats;*.log|" + _("All Files") + " (*.*)|*.*", from_wx(_("All Supported Formats") +
" (*.txt, *.pass, *.stats, *.log)|*.txt;*.pass;*.stats;*.log|" +
_("All Files") + " (*.*)|*.*"),
c->parent); c->parent);
if (!filename.empty()) if (!filename.empty())

View file

@ -71,7 +71,7 @@ struct timecode_open final : public Command {
STR_HELP("Open a VFR timecodes v1 or v2 file") STR_HELP("Open a VFR timecodes v1 or v2 file")
void operator()(agi::Context *c) override { void operator()(agi::Context *c) override {
auto str = _("All Supported Formats") + " (*.txt)|*.txt|" + _("All Files") + " (*.*)|*.*"; auto str = from_wx(_("All Supported Formats") + " (*.txt)|*.txt|" + _("All Files") + " (*.*)|*.*");
auto filename = OpenFileSelector(_("Open Timecodes File"), "Path/Last/Timecodes", "", "", str, c->parent); auto filename = OpenFileSelector(_("Open Timecodes File"), "Path/Last/Timecodes", "", "", str, c->parent);
if (!filename.empty()) if (!filename.empty())
c->project->LoadTimecodes(filename); c->project->LoadTimecodes(filename);
@ -91,7 +91,7 @@ struct timecode_save final : public Command {
} }
void operator()(agi::Context *c) override { void operator()(agi::Context *c) override {
auto str = _("All Supported Formats") + " (*.txt)|*.txt|" + _("All Files") + " (*.*)|*.*"; auto str = from_wx(_("All Supported Formats") + " (*.txt)|*.txt|" + _("All Files") + " (*.*)|*.*");
auto filename = SaveFileSelector(_("Save Timecodes File"), "Path/Last/Timecodes", "", "", str, c->parent); auto filename = SaveFileSelector(_("Save Timecodes File"), "Path/Last/Timecodes", "", "", str, c->parent);
if (filename.empty()) return; if (filename.empty()) return;

View file

@ -564,8 +564,8 @@ struct video_open final : public Command {
STR_HELP("Open a video file") STR_HELP("Open a video file")
void operator()(agi::Context *c) override { void operator()(agi::Context *c) override {
auto str = _("Video Formats") + " (*.asf,*.avi,*.avs,*.d2v,*.m2ts,*.m4v,*.mkv,*.mov,*.mp4,*.mpeg,*.mpg,*.ogm,*.webm,*.wmv,*.ts,*.y4m,*.yuv)|*.asf;*.avi;*.avs;*.d2v;*.m2ts;*.m4v;*.mkv;*.mov;*.mp4;*.mpeg;*.mpg;*.ogm;*.webm;*.wmv;*.ts;*.y4m;*.yuv|" auto str = from_wx(_("Video Formats") + " (*.asf,*.avi,*.avs,*.d2v,*.m2ts,*.m4v,*.mkv,*.mov,*.mp4,*.mpeg,*.mpg,*.ogm,*.webm,*.wmv,*.ts,*.y4m,*.yuv)|*.asf;*.avi;*.avs;*.d2v;*.m2ts;*.m4v;*.mkv;*.mov;*.mp4;*.mpeg;*.mpg;*.ogm;*.webm;*.wmv;*.ts;*.y4m;*.yuv|"
+ _("All Files") + " (*.*)|*.*"; + _("All Files") + " (*.*)|*.*");
auto filename = OpenFileSelector(_("Open video file"), "Path/Last/Video", "", "", str, c->parent); auto filename = OpenFileSelector(_("Open video file"), "Path/Last/Video", "", "", str, c->parent);
if (!filename.empty()) if (!filename.empty())
c->project->LoadVideo(filename); c->project->LoadVideo(filename);

View file

@ -126,7 +126,7 @@ void DialogAttachments::AttachFile(wxFileDialog &diag, wxString const& commit_ms
diag.GetPaths(paths); diag.GetPaths(paths);
for (auto const& fn : paths) for (auto const& fn : paths)
ass->InsertAttachment(agi::fs::path(fn)); ass->InsertAttachment(agi::fs::path(fn.wx_str()));
ass->Commit(commit_msg, AssFile::COMMIT_ATTACHMENT); ass->Commit(commit_msg, AssFile::COMMIT_ATTACHMENT);

View file

@ -231,7 +231,7 @@ void DialogAutomation::OnAdd(wxCommandEvent &)
diag.GetPaths(fnames); diag.GetPaths(fnames);
for (auto const& fname : fnames) { for (auto const& fname : fnames) {
agi::fs::path fnpath(fname); agi::fs::path fnpath(fname.wx_str());
OPT_SET("Path/Last/Automation")->SetString(fnpath.parent_path().string()); OPT_SET("Path/Last/Automation")->SetString(fnpath.parent_path().string());
if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) { if (has_file(local_manager->GetScripts(), fnpath) || has_file(global_manager->GetScripts(), fnpath)) {

View file

@ -186,7 +186,7 @@ DialogExport::~DialogExport() {
void DialogExport::OnProcess(wxCommandEvent &) { void DialogExport::OnProcess(wxCommandEvent &) {
if (!d.TransferDataFromWindow()) return; if (!d.TransferDataFromWindow()) return;
auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", to_wx(SubtitleFormat::GetWildcards(1)), &d); auto filename = SaveFileSelector(_("Export subtitles file"), "", "", "", SubtitleFormat::GetWildcards(1), &d);
if (filename.empty()) return; if (filename.empty()) return;
for (size_t i = 0; i < filter_list->GetCount(); ++i) { for (size_t i = 0; i < filter_list->GetCount(); ++i) {

View file

@ -123,7 +123,7 @@ DialogProperties::DialogProperties(agi::Context *c)
res_sizer->Add(ResY, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5); res_sizer->Add(ResY, 1, wxRIGHT | wxALIGN_CENTER_VERTICAL, 5);
res_sizer->Add(FromVideo, 1, 0, 0); res_sizer->Add(FromVideo, 1, 0, 0);
YCbCrMatrix = new wxComboBox(&d, -1, c->ass->GetScriptInfo("YCbCr Matrix"), YCbCrMatrix = new wxComboBox(&d, -1, to_wx(c->ass->GetScriptInfo("YCbCr Matrix")),
wxDefaultPosition, wxDefaultSize, to_wx(MatrixNames()), wxCB_READONLY); wxDefaultPosition, wxDefaultSize, to_wx(MatrixNames()), wxCB_READONLY);
auto matrix_sizer = new wxBoxSizer(wxHORIZONTAL); auto matrix_sizer = new wxBoxSizer(wxHORIZONTAL);

View file

@ -430,7 +430,7 @@ void DialogStyleManager::LoadCatalog() {
// Get saved style catalogs // Get saved style catalogs
auto catalogs = AssStyleStorage::GetCatalogs(); auto catalogs = AssStyleStorage::GetCatalogs();
for (auto const& c : catalogs) for (auto const& c : catalogs)
CatalogList->Append(c); CatalogList->Append(to_wx(c));
// Create a default storage if there are none // Create a default storage if there are none
if (CatalogList->IsListEmpty()) { if (CatalogList->IsListEmpty()) {

View file

@ -138,7 +138,7 @@ int FFmpegSourceProvider::AskForTrackSelection(const std::map<int, std::string>
wxArrayString Choices; wxArrayString Choices;
for (auto const& track : TrackList) { for (auto const& track : TrackList) {
Choices.Add(agi::format(_("Track %02d: %s"), track.first, to_wx(track.second))); Choices.Add(agi::wxformat(_("Track %02d: %s"), track.first, track.second));
TrackNumbers.push_back(track.first); TrackNumbers.push_back(track.first);
} }

View file

@ -446,5 +446,5 @@ int AegisubApp::OnRun() {
void AegisubApp::MacOpenFile(const wxString &filename) { void AegisubApp::MacOpenFile(const wxString &filename) {
if (frame && !filename.empty()) if (frame && !filename.empty())
frame->context->project->LoadSubtitles(agi::fs::path(filename)); frame->context->project->LoadSubtitles(agi::fs::path(filename.wx_str()));
} }

View file

@ -250,21 +250,21 @@ wxString FontFace(std::string opt_prefix) {
return to_wx(value); return to_wx(value);
} }
static agi::fs::path FileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, int flags, wxWindow *parent) { static agi::fs::path FileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, std::string const& wildcard, int flags, wxWindow *parent) {
wxString path; wxString path;
if (!option_name.empty()) if (!option_name.empty())
path = to_wx(OPT_GET(option_name)->GetString()); path = to_wx(OPT_GET(option_name)->GetString());
agi::fs::path filename = wxFileSelector(message, path, to_wx(default_filename), to_wx(default_extension), wildcard, flags, parent).wx_str(); agi::fs::path filename = wxFileSelector(message, path, to_wx(default_filename), to_wx(default_extension), to_wx(wildcard), flags, parent).wx_str();
if (!filename.empty() && !option_name.empty()) if (!filename.empty() && !option_name.empty())
OPT_SET(option_name)->SetString(filename.parent_path().string()); OPT_SET(option_name)->SetString(filename.parent_path().string());
return filename; return filename;
} }
agi::fs::path OpenFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent) { agi::fs::path OpenFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, std::string const& wildcard, wxWindow *parent) {
return FileSelector(message, option_name, default_filename, default_extension, wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST, parent); return FileSelector(message, option_name, default_filename, default_extension, wildcard, wxFD_OPEN | wxFD_FILE_MUST_EXIST, parent);
} }
agi::fs::path SaveFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent) { agi::fs::path SaveFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, std::string const& wildcard, wxWindow *parent) {
return FileSelector(message, option_name, default_filename, default_extension, wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT, parent); return FileSelector(message, option_name, default_filename, default_extension, wildcard, wxFD_SAVE | wxFD_OVERWRITE_PROMPT, parent);
} }

View file

@ -94,8 +94,8 @@ void SetClipboard(wxBitmap const& new_value);
wxString FontFace(std::string opt_prefix); wxString FontFace(std::string opt_prefix);
agi::fs::path OpenFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent); agi::fs::path OpenFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, std::string const& wildcard, wxWindow *parent);
agi::fs::path SaveFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, wxString const& wildcard, wxWindow *parent); agi::fs::path SaveFileSelector(wxString const& message, std::string const& option_name, std::string const& default_filename, std::string const& default_extension, std::string const& wildcard, wxWindow *parent);
wxString LocalizedLanguageName(wxString const& lang); wxString LocalizedLanguageName(wxString const& lang);

View file

@ -69,7 +69,7 @@ void IntValidator::OnChar(wxKeyEvent& event) {
auto ctrl = static_cast<wxTextCtrl *>(GetWindow()); auto ctrl = static_cast<wxTextCtrl *>(GetWindow());
auto str = new_value(ctrl, chr); auto str = new_value(ctrl, chr);
int parsed; int parsed;
if (allow_negative && str == '-') if (allow_negative && str == "-")
event.Skip(); event.Skip();
else if (agi::util::try_parse(str, &parsed) && (allow_negative || parsed >= 0)) else if (agi::util::try_parse(str, &parsed) && (allow_negative || parsed >= 0))
event.Skip(); event.Skip();
@ -121,7 +121,7 @@ void DoubleValidator::OnChar(wxKeyEvent& event) {
double parsed; double parsed;
bool can_parse = agi::util::try_parse(str, &parsed); bool can_parse = agi::util::try_parse(str, &parsed);
if ((min < 0 && str == '-') || str == '.') if ((min < 0 && str == "-") || str == ".")
event.Skip(); event.Skip();
else if (can_parse && parsed >= min && parsed <= max) else if (can_parse && parsed >= min && parsed <= max)
event.Skip(); event.Skip();