From 4c97ff63b5ecf639cd68310adbd572ac8bd94add Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Thu, 9 May 2013 20:16:35 +0100 Subject: [PATCH] Fixed/Tidied up unicode support, translation support. Swapped out some menu entries for their standard equivalents and replaced all the different readme links with just one item that opens the main readme. --- src/gui/editor.cpp | 98 +++++++++++++++++++++++++------------------- src/gui/editor.h | 2 + src/gui/ids.cpp | 4 +- src/gui/ids.h | 7 ---- src/gui/main.cpp | 69 +++++++++++++------------------ src/gui/main.h | 2 +- src/gui/settings.cpp | 16 ++++---- 7 files changed, 97 insertions(+), 101 deletions(-) diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index a63ff2e6..e0a00b99 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -166,7 +166,7 @@ void Editor::SetList(const std::vector& basePlugins, const std::ve //Fill pluginList with the contents of basePlugins. for (int i=0, max=_basePlugins.size(); i < max; ++i) { - pluginList->InsertItem(i, _basePlugins[i].Name()); + pluginList->InsertItem(i, FromUTF8(_basePlugins[i].Name())); } pluginList->SetColumnWidth(0, wxLIST_AUTOSIZE); Layout(); @@ -174,10 +174,10 @@ void Editor::SetList(const std::vector& basePlugins, const std::ve void Editor::IsSorted(bool sorted) { if (sorted) { - applyBtn->SetLabel("Apply Load Order"); + applyBtn->SetLabel(translate("Apply Load Order")); } else { recalcBtn->Show(false); - applyBtn->SetLabel("Save Changes"); + applyBtn->SetLabel(translate("Save Changes")); } Layout(); } @@ -189,22 +189,13 @@ void Editor::OnPluginSelect(wxListEvent& event) { //Check if the selected plugin is the same as the current plugin. if (currentPlugin != plugin) { //Check if there are edits made to the current plugin compared to its original. - if (IsCurrentPluginEdited()) { - //Save changes. - boss::Plugin diff = currentPlugin.DiffMetadata(GetOriginal(currentPlugin, false)); - - vector::iterator it = std::find(_editedPlugins.begin(), _editedPlugins.end(), diff); - - if (it != _editedPlugins.end()) - *it = diff; - else - _editedPlugins.push_back(diff); - } + if (IsCurrentPluginEdited()) + ApplyCurrentPluginEdits(); plugin = GetOriginal(plugin, true); //Now fill editor fields with new plugin's info. - pluginText->SetLabelText(wxString(plugin.Name().c_str(), wxConvUTF8)); + pluginText->SetLabelText(FromUTF8(plugin.Name())); prioritySpin->SetValue(plugin.Priority()); @@ -219,37 +210,37 @@ void Editor::OnPluginSelect(wxListEvent& event) { set files = plugin.LoadAfter(); int i=0; for (set::const_iterator it=files.begin(), endit=files.end(); it != endit; ++it) { - loadAfterList->InsertItem(i, wxString(it->Name().c_str(), wxConvUTF8)); - loadAfterList->SetItem(i, 1, wxString(it->DisplayName().c_str(), wxConvUTF8)); - loadAfterList->SetItem(i, 2, wxString(it->Condition().c_str(), wxConvUTF8)); + loadAfterList->InsertItem(i, FromUTF8(it->Name())); + loadAfterList->SetItem(i, 1, FromUTF8(it->DisplayName())); + loadAfterList->SetItem(i, 2, FromUTF8(it->Condition())); ++i; } files = plugin.Reqs(); i=0; for (set::const_iterator it=files.begin(), endit=files.end(); it != endit; ++it) { - reqsList->InsertItem(i, wxString(it->Name().c_str(), wxConvUTF8)); - reqsList->SetItem(i, 1, wxString(it->DisplayName().c_str(), wxConvUTF8)); - reqsList->SetItem(i, 2, wxString(it->Condition().c_str(), wxConvUTF8)); + reqsList->InsertItem(i, FromUTF8(it->Name())); + reqsList->SetItem(i, 1, FromUTF8(it->DisplayName())); + reqsList->SetItem(i, 2, FromUTF8(it->Condition())); ++i; } files = plugin.Incs(); i=0; for (set::const_iterator it=files.begin(), endit=files.end(); it != endit; ++it) { - incsList->InsertItem(i, wxString(it->Name().c_str(), wxConvUTF8)); - incsList->SetItem(i, 1, wxString(it->DisplayName().c_str(), wxConvUTF8)); - incsList->SetItem(i, 2, wxString(it->Condition().c_str(), wxConvUTF8)); + incsList->InsertItem(i, FromUTF8(it->Name())); + incsList->SetItem(i, 1, FromUTF8(it->DisplayName())); + incsList->SetItem(i, 2, FromUTF8(it->Condition())); ++i; } list messages = plugin.Messages(); i=0; for (list::const_iterator it=messages.begin(), endit=messages.end(); it != endit; ++it) { - messageList->InsertItem(i, wxString(it->Type().c_str(), wxConvUTF8)); - messageList->SetItem(i, 1, wxString(it->Content().c_str(), wxConvUTF8)); - messageList->SetItem(i, 2, wxString(it->Condition().c_str(), wxConvUTF8)); - messageList->SetItem(i, 2, wxString(it->Language().c_str(), wxConvUTF8)); + messageList->InsertItem(i, FromUTF8(it->Type())); + messageList->SetItem(i, 1, FromUTF8(it->Content())); + messageList->SetItem(i, 2, FromUTF8(it->Condition())); + messageList->SetItem(i, 2, FromUTF8(it->Language())); ++i; } @@ -260,8 +251,8 @@ void Editor::OnPluginSelect(wxListEvent& event) { tagsList->InsertItem(i, translate("Add")); else tagsList->InsertItem(i, translate("Remove")); - tagsList->SetItem(i, 1, wxString(it->Name().c_str(), wxConvUTF8)); - tagsList->SetItem(i, 2, wxString(it->Condition().c_str(), wxConvUTF8)); + tagsList->SetItem(i, 1, FromUTF8(it->Name())); + tagsList->SetItem(i, 2, FromUTF8(it->Condition())); ++i; } @@ -275,21 +266,21 @@ void Editor::OnPriorityChange(wxSpinEvent& event) { void Editor::OnListBookChange(wxBookCtrlEvent& event) { if (event.GetSelection() == 0 || event.GetSelection() == 1) { - addBtn->SetLabel("Add File"); - editBtn->SetLabel("Edit File"); - removeBtn->SetLabel("Remove File"); + addBtn->SetLabel(translate("Add File")); + editBtn->SetLabel(translate("Edit File")); + removeBtn->SetLabel(translate("Remove File")); } else if (event.GetSelection() == 2) { - addBtn->SetLabel("Add Plugin"); - editBtn->SetLabel("Edit Plugin"); - removeBtn->SetLabel("Remove Plugin"); + addBtn->SetLabel(translate("Add Plugin")); + editBtn->SetLabel(translate("Edit Plugin")); + removeBtn->SetLabel(translate("Remove Plugin")); } else if (event.GetSelection() == 3) { - addBtn->SetLabel("Add Message"); - editBtn->SetLabel("Edit Message"); - removeBtn->SetLabel("Remove Message"); + addBtn->SetLabel(translate("Add Message")); + editBtn->SetLabel(translate("Edit Message")); + removeBtn->SetLabel(translate("Remove Message")); } else if (event.GetSelection() == 4) { - addBtn->SetLabel("Add Bash Tag"); - editBtn->SetLabel("Edit Bash Tag"); - removeBtn->SetLabel("Remove Bash Tag"); + addBtn->SetLabel(translate("Add Bash Tag")); + editBtn->SetLabel(translate("Edit Bash Tag")); + removeBtn->SetLabel(translate("Remove Bash Tag")); } Layout(); } @@ -300,10 +291,20 @@ void Editor::OnEnabledToggle(wxCommandEvent& event) { void Editor::OnQuit(wxCommandEvent& event) { if (event.GetId() == BUTTON_Apply) { + //Save edits to userlist. + /* YAML::Emitter yout; + yout.SetIndent(2); + yout << YAML::BeginMap + << YAML::Key << "plugins" << YAML::Value << _editedPlugins + << YAML::EndMap; + + ofstream out(game.UserlistPath().string().c_str()); + out << yout.c_str(); + out.close(); + */ if (recalcBtn->IsShown()) { //Signal that the load order should be written. } - //Save edits to userlist. } Close(); } @@ -337,3 +338,14 @@ boss::Plugin Editor::GetOriginal(const boss::Plugin& plugin, bool withEdits) con return p; } + +void Editor::ApplyCurrentPluginEdits() { + boss::Plugin diff = currentPlugin.DiffMetadata(GetOriginal(currentPlugin, false)); + + vector::iterator it = std::find(_editedPlugins.begin(), _editedPlugins.end(), diff); + + if (it != _editedPlugins.end()) + *it = diff; + else + _editedPlugins.push_back(diff); +} diff --git a/src/gui/editor.h b/src/gui/editor.h index 5e8016ce..5d6a99fa 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -26,6 +26,7 @@ #include "ids.h" #include "../metadata.h" +#include #include #include #include @@ -48,6 +49,7 @@ private: bool IsCurrentPluginEdited() const; boss::Plugin GetOriginal(const boss::Plugin& plugin, bool withEdits) const; + void ApplyCurrentPluginEdits(); wxButton * addBtn; wxButton * editBtn; diff --git a/src/gui/ids.cpp b/src/gui/ids.cpp index df7ec623..4ee03696 100644 --- a/src/gui/ids.cpp +++ b/src/gui/ids.cpp @@ -26,11 +26,11 @@ #include wxString translate(const std::string& str) { - return wxString(boost::locale::translate(str).str().c_str(), wxConvUTF8); + return wxString::FromUTF8(boost::locale::translate(str).str().c_str()); } wxString FromUTF8(const std::string& str) { - return wxString(str.c_str(), wxConvUTF8); + return wxString::FromUTF8(str.c_str()); } wxString FromUTF8(const boost::format& f) { diff --git a/src/gui/ids.h b/src/gui/ids.h index 5125a7da..2c422882 100644 --- a/src/gui/ids.h +++ b/src/gui/ids.h @@ -38,13 +38,6 @@ enum { OPTION_EditMetadata = wxID_HIGHEST + 1, // declares an id which will be used to call our button OPTION_ViewLastReport, OPTION_SortPlugins, - MENU_Quit, - MENU_OpenMainReadMe, - MENU_OpenSyntaxReadMe, - MENU_OpenAPIReadMe, - MENU_OpenVersionHistory, - MENU_OpenLicenses, - MENU_ShowAbout, MENU_ShowSettings, MENU_Oblivion, MENU_Nehrim, diff --git a/src/gui/main.cpp b/src/gui/main.cpp index c5057472..d72eb2ca 100644 --- a/src/gui/main.cpp +++ b/src/gui/main.cpp @@ -48,16 +48,12 @@ #include BEGIN_EVENT_TABLE ( Launcher, wxFrame ) - EVT_MENU ( MENU_Quit, Launcher::OnQuit ) + EVT_MENU ( wxID_EXIT, Launcher::OnQuit ) EVT_MENU ( OPTION_EditMetadata, Launcher::OnEditMetadata ) EVT_MENU ( OPTION_ViewLastReport, Launcher::OnViewLastReport ) EVT_MENU ( OPTION_SortPlugins, Launcher::OnSortPlugins ) - EVT_MENU ( MENU_OpenMainReadMe, Launcher::OnOpenFile ) - EVT_MENU ( MENU_OpenSyntaxReadMe, Launcher::OnOpenFile ) - EVT_MENU ( MENU_OpenAPIReadMe, Launcher::OnOpenFile ) - EVT_MENU ( MENU_OpenVersionHistory, Launcher::OnOpenFile ) - EVT_MENU ( MENU_OpenLicenses, Launcher::OnOpenFile ) - EVT_MENU ( MENU_ShowAbout, Launcher::OnAbout ) + EVT_MENU ( wxID_HELP, Launcher::OnHelp ) + EVT_MENU ( wxID_ABOUT, Launcher::OnAbout ) EVT_MENU ( MENU_ShowSettings, Launcher::OnOpenSettings ) EVT_MENU ( MENU_Oblivion, Launcher::OnGameChange ) EVT_MENU ( MENU_Nehrim, Launcher::OnGameChange ) @@ -153,7 +149,11 @@ bool BossGUI::OnInit() { vector detected, undetected; DetectGames(detected, undetected); if (detected.empty()) - throw error(ERROR_NO_GAME_DETECTED, "None of the supported games were detected."); + wxMessageBox( + translate("Error: None of the supported games were detected."), + translate("BOSS: Error"), + wxOK | wxICON_ERROR, + NULL); string target; unsigned int targetGame; @@ -205,8 +205,8 @@ Launcher::Launcher(const wxChar *title, const YAML::Node& settings, const Game& wxMenu * HelpMenu = new wxMenu(); //Initialise controls. - wxButton * EditButton = new wxButton(this,OPTION_EditMetadata, translate("Edit Metadata")); - wxButton * SortButton = new wxButton(this,OPTION_SortPlugins, translate("Sort Plugins")); + wxButton * EditButton = new wxButton(this, OPTION_EditMetadata, translate("Edit Metadata")); + wxButton * SortButton = new wxButton(this, OPTION_SortPlugins, translate("Sort Plugins")); ViewButton = new wxButton(this,OPTION_ViewLastReport, translate("View Last Report")); //Construct menus. @@ -214,7 +214,7 @@ Launcher::Launcher(const wxChar *title, const YAML::Node& settings, const Game& FileMenu->Append(OPTION_ViewLastReport, translate("&View Last Report"), translate("Opens your last report.")); FileMenu->Append(OPTION_SortPlugins, translate("&Sort Plugins"), translate("Sorts your installed plugins.")); FileMenu->AppendSeparator(); - FileMenu->Append(MENU_Quit, translate("&Quit"), translate("Quit BOSS.")); + FileMenu->Append(wxID_EXIT); MenuBar->Append(FileMenu, translate("&File")); //Edit Menu EditMenu->Append(OPTION_EditMetadata, translate("&Metadata..."), translate("Opens a window where you can edit plugin metadata.")); @@ -228,13 +228,9 @@ Launcher::Launcher(const wxChar *title, const YAML::Node& settings, const Game& GameMenu->AppendRadioItem(MENU_FalloutNewVegas, wxT("&Fallout: New Vegas"), translate("Switch to running BOSS for Fallout: New Vegas.")); MenuBar->Append(GameMenu, translate("&Active Game")); //About menu - HelpMenu->Append(MENU_OpenMainReadMe, translate("Open &Main Readme"), translate("Opens the main BOSS readme in your default web browser.")); - HelpMenu->Append(MENU_OpenSyntaxReadMe, translate("Open &Metadata File Syntax Doc"), translate("Opens the BOSS metadata file syntax documentation in your default web browser.")); - HelpMenu->Append(MENU_OpenAPIReadMe, translate("&Open API Readme"), translate("Opens the BOSS API readme in your default web browser.")); - HelpMenu->Append(MENU_OpenVersionHistory, translate("Open &Version History"), translate("Opens the BOSS version history in your default web browser.")); - HelpMenu->Append(MENU_OpenLicenses, translate("View &Copyright Licenses"), translate("View the GNU General Public License v3.0 and GNU Free Documentation License v1.3.")); + HelpMenu->Append(wxID_HELP); HelpMenu->AppendSeparator(); - HelpMenu->Append(MENU_ShowAbout, translate("&About BOSS..."), translate("Shows information about BOSS.")); + HelpMenu->Append(wxID_ABOUT); MenuBar->Append(HelpMenu, translate("&Help")); //Set up layout. @@ -323,7 +319,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { FromUTF8(format(loc::translate("Error: Masterlist parsing failed. %1%")) % e.what()), translate("BOSS: Error"), wxOK | wxICON_ERROR, - NULL); + this); } if (mlist["globals"]) mlist_messages = mlist["globals"].as< list >(); @@ -346,7 +342,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { FromUTF8(format(loc::translate("Error: Userlist parsing failed. %1%")) % e.what()), translate("BOSS: Error"), wxOK | wxICON_ERROR, - NULL); + this); } if (ulist["globals"]) ulist_messages = ulist["globals"].as< list >(); @@ -399,7 +395,7 @@ void Launcher::OnSortPlugins(wxCommandEvent& event) { FromUTF8(format(loc::translate("Error: Condition evaluation failed. %1%")) % e.what()), translate("BOSS: Error"), wxOK | wxICON_ERROR, - NULL); + this); } } @@ -537,7 +533,7 @@ void Launcher::OnEditMetadata(wxCommandEvent& event) { FromUTF8(format(loc::translate("Error: Masterlist parsing failed. %1%")) % e.what()), translate("BOSS: Error"), wxOK | wxICON_ERROR, - NULL); + this); } if (mlist["plugins"]) mlist_plugins = mlist["plugins"].as< vector >(); @@ -552,7 +548,7 @@ void Launcher::OnEditMetadata(wxCommandEvent& event) { FromUTF8(format(loc::translate("Error: Userlist parsing failed. %1%")) % e.what()), translate("BOSS: Error"), wxOK | wxICON_ERROR, - NULL); + this); } if (ulist["plugins"]) ulist_plugins = ulist["plugins"].as< vector >(); @@ -623,29 +619,22 @@ void Launcher::OnGameChange(wxCommandEvent& event) { break; } } catch (error& e) { - wxMessageBox(e.what(), translate("BOSS: Error"), wxOK | wxICON_ERROR, this); + wxMessageBox( + FromUTF8(format(loc::translate("Error: Game change failed. %1%")) % e.what()), + translate("BOSS: Error"), + wxOK | wxICON_ERROR, + this); } - SetTitle(wxT("BOSS - " + _game.Name())); //Don't need to convert name, known to be only ASCII chars. + SetTitle(FromUTF8("BOSS - " + _game.Name())); } -void Launcher::OnOpenFile(wxCommandEvent& event) { - string file; - if (event.GetId() == MENU_OpenMainReadMe) - file = readme_path.string(); - else if (event.GetId() == MENU_OpenSyntaxReadMe) - file = syntax_doc_path.string(); - else if (event.GetId() == MENU_OpenAPIReadMe) - file = api_doc_path.string(); - else if (event.GetId() == MENU_OpenVersionHistory) - file = version_history_path.string(); - else if (event.GetId() == MENU_OpenLicenses) - file = licenses_path.string(); +void Launcher::OnHelp(wxCommandEvent& event) { //Look for file. - if (fs::exists(file)) { - wxLaunchDefaultApplication(file); + if (fs::exists(readme_path.string())) { + wxLaunchDefaultApplication(readme_path.string()); } else //No ReadMe exists, show a pop-up message saying so. wxMessageBox( - FromUTF8(boost::format(loc::translate("Error: \"%1%\" cannot be found.")) % file), + FromUTF8(format(loc::translate("Error: \"%1%\" cannot be found.")) % readme_path.string()), translate("BOSS: Error"), wxOK | wxICON_ERROR, this); @@ -694,7 +683,7 @@ void Launcher::DisableUndetectedGames() { GameMenu->FindItem(MENU_FalloutNewVegas)->Enable(); } - SetTitle(wxT("BOSS - " + _game.Name())); //Don't need to convert name, known to be only ASCII chars. + SetTitle(FromUTF8("BOSS - " + _game.Name())); } bool Launcher::AlphaSortPlugins(const boss::Plugin& lhs, const boss::Plugin& rhs) { diff --git a/src/gui/main.h b/src/gui/main.h index ffd2dfa4..c6d9fd20 100644 --- a/src/gui/main.h +++ b/src/gui/main.h @@ -48,7 +48,7 @@ public: void OnOpenSettings(wxCommandEvent& event); void OnGameChange(wxCommandEvent& event); - void OnOpenFile(wxCommandEvent& event); + void OnHelp(wxCommandEvent& event); void OnAbout(wxCommandEvent& event); void OnQuit(wxCommandEvent& event); diff --git a/src/gui/settings.cpp b/src/gui/settings.cpp index ef464577..c83a2b15 100644 --- a/src/gui/settings.cpp +++ b/src/gui/settings.cpp @@ -53,10 +53,10 @@ SettingsFrame::SettingsFrame(const wxString title, wxFrame *parent, YAML::Node& wxString Language[] = { wxT("English"), - /* wxString("Español", wxConvUTF8), + /* wxString::FromUTF8("Español"), wxT("Deutsch"), - wxString("Русский", wxConvUTF8), - wxString("简体中文", wxConvUTF8)*/ + wxString::FromUTF8("Русский"), + wxString::FromUTF8("简体中文")*/ }; //Initialise controls. @@ -183,19 +183,19 @@ void SettingsFrame::SetDefaultValues() { YAML::Node urls = _settings["Masterlist URLs"]; if (urls["Oblivion"]) - OblivionURL->SetValue(urls["Oblivion"].as()); + OblivionURL->SetValue(FromUTF8(urls["Oblivion"].as())); if (urls["Nehrim"]) - NehrimURL->SetValue(urls["Nehrim"].as()); + NehrimURL->SetValue(FromUTF8(urls["Nehrim"].as())); if (urls["Skyrim"]) - SkyrimURL->SetValue(urls["Skyrim"].as()); + SkyrimURL->SetValue(FromUTF8(urls["Skyrim"].as())); if (urls["Fallout 3"]) - FO3URL->SetValue(urls["Fallout 3"].as()); + FO3URL->SetValue(FromUTF8(urls["Fallout 3"].as())); if (urls["Fallout New Vegas"]) - FONVURL->SetValue(urls["Fallout New Vegas"].as()); + FONVURL->SetValue(FromUTF8(urls["Fallout New Vegas"].as())); } }