Replaced event tables with dynamic binding.

Also added a few error messages and another path global for the l10n
files.
This commit is contained in:
WrinklyNinja
2013-06-16 11:20:57 +01:00
parent 7c49e37c50
commit 0350c6f80a
8 changed files with 39 additions and 32 deletions
+1
View File
@@ -58,4 +58,5 @@ namespace boss {
const boost::filesystem::path polyfill_path = boost::filesystem::current_path() / "resources" / "polyfill.js";
const boost::filesystem::path settings_path = local_path / "settings.yaml";
const boost::filesystem::path log_path = local_path / "BOSSDebugLog.txt";
const boost::filesystem::path l10n_path = "resources/l10n";
}
+1
View File
@@ -59,6 +59,7 @@ namespace boss {
extern const boost::filesystem::path polyfill_path;
extern const boost::filesystem::path svn_path;
extern const boost::filesystem::path log_path;
extern const boost::filesystem::path l10n_path;
}
#endif
+28 -17
View File
@@ -27,21 +27,6 @@
#include <algorithm>
#include <boost/algorithm/string.hpp>
BEGIN_EVENT_TABLE( Editor, wxFrame )
EVT_LIST_ITEM_SELECTED( LIST_Plugins, Editor::OnPluginSelect )
EVT_LIST_ITEM_SELECTED( LIST_Reqs, Editor::OnRowSelect )
EVT_LIST_ITEM_SELECTED( LIST_Incs, Editor::OnRowSelect )
EVT_LIST_ITEM_SELECTED( LIST_LoadAfter, Editor::OnRowSelect )
EVT_LIST_ITEM_SELECTED( LIST_Messages, Editor::OnRowSelect )
EVT_LIST_ITEM_SELECTED( LIST_BashTags, Editor::OnRowSelect )
EVT_NOTEBOOK_PAGE_CHANGED( BOOK_Lists, Editor::OnListBookChange )
EVT_BUTTON ( BUTTON_Apply, Editor::OnQuit )
EVT_BUTTON ( BUTTON_Cancel, Editor::OnQuit )
EVT_BUTTON ( BUTTON_AddRow, Editor::OnAddRow )
EVT_BUTTON ( BUTTON_EditRow, Editor::OnEditRow )
EVT_BUTTON ( BUTTON_RemoveRow, Editor::OnRemoveRow )
END_EVENT_TABLE()
using namespace std;
wxString Language[2] = {
@@ -197,6 +182,20 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli
font.SetWeight(wxFONTWEIGHT_BOLD);
pluginText->SetFont(font);
//Set up event handling.
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnPluginSelect, this, LIST_Plugins);
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnRowSelect, this, LIST_Reqs);
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnRowSelect, this, LIST_Incs);
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnRowSelect, this, LIST_LoadAfter);
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnRowSelect, this, LIST_Messages);
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &Editor::OnRowSelect, this, LIST_BashTags);
Bind(wxEVT_COMMAND_NOTEBOOK_PAGE_CHANGED, &Editor::OnListBookChange, this, BOOK_Lists);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Editor::OnQuit, this, BUTTON_Apply);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Editor::OnQuit, this, BUTTON_Cancel);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Editor::OnAddRow, this, BUTTON_AddRow);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Editor::OnEditRow, this, BUTTON_EditRow);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &Editor::OnRemoveRow, this, BUTTON_RemoveRow);
//Set up layout.
wxBoxSizer * bigBox = new wxBoxSizer(wxHORIZONTAL);
@@ -976,16 +975,28 @@ void MessageEditDialog::OnAdd(wxCommandEvent& event) {
}
void MessageEditDialog::OnEdit(wxCommandEvent& event) {
if (_content->GetFirstSelected() == -1)
if (_content->GetFirstSelected() == -1) {
wxMessageBox(
FromUTF8("Error: No content row selected."),
translate("BOSS: Error"),
wxOK | wxICON_ERROR,
NULL);
return;
}
long i = _content->GetFirstSelected();
_content->SetItem(i, 0, Language[_language->GetSelection()]);
_content->SetItem(i, 1, _str->GetValue());
}
void MessageEditDialog::OnRemove(wxCommandEvent& event) {
if (_content->GetFirstSelected() == -1)
if (_content->GetFirstSelected() == -1) {
wxMessageBox(
FromUTF8("Error: No content row selected."),
translate("BOSS: Error"),
wxOK | wxICON_ERROR,
NULL);
return;
}
_content->DeleteItem(_content->GetFirstSelected());
}
-1
View File
@@ -66,7 +66,6 @@ public:
void OnRecalc(wxCommandEvent& event);
void OnRowSelect(wxListEvent& event);
void OnQuit(wxCommandEvent& event);
DECLARE_EVENT_TABLE()
private:
wxButton * addBtn;
+1 -1
View File
@@ -135,7 +135,7 @@ bool BossGUI::OnInit() {
wxLoc = new wxLocale();
if (!wxLoc->Init(lang, wxLOCALE_LOAD_DEFAULT))
throw runtime_error("System GUI text could not be set.");
wxLocale::AddCatalogLookupPathPrefix(".\\l10n");
wxLocale::AddCatalogLookupPathPrefix(l10n_path.string().c_str());
wxLoc->AddCatalog("wxstd");
} catch(runtime_error &e) {
// LOG_ERROR("could not implement translation: %s", e.what());
+8 -9
View File
@@ -26,14 +26,6 @@
#include <fstream>
#include <boost/algorithm/string.hpp>
BEGIN_EVENT_TABLE ( SettingsFrame, wxDialog )
EVT_BUTTON ( wxID_OK, SettingsFrame::OnQuit)
EVT_LIST_ITEM_SELECTED( LIST_Games, SettingsFrame::OnGameSelect )
EVT_BUTTON ( BUTTON_AddGame, SettingsFrame::OnAddGame )
EVT_BUTTON ( BUTTON_EditGame, SettingsFrame::OnEditGame )
EVT_BUTTON ( BUTTON_RemoveGame, SettingsFrame::OnRemoveGame )
END_EVENT_TABLE()
using namespace std;
SettingsFrame::SettingsFrame(wxWindow *parent, const wxString& title, YAML::Node& settings, std::vector<boss::Game>& games) : wxDialog(parent, wxID_ANY, title, wxDefaultPosition, wxDefaultSize, wxDEFAULT_DIALOG_STYLE|wxRESIZE_BORDER), _settings(settings), _games(games) {
@@ -83,6 +75,13 @@ SettingsFrame::SettingsFrame(wxWindow *parent, const wxString& title, YAML::Node
gamesList->AppendColumn(translate("Install Path"));
gamesList->AppendColumn(translate("Install Path Registry Key"));
//Set up event handling.
Bind(wxEVT_COMMAND_LIST_ITEM_SELECTED, &SettingsFrame::OnGameSelect, this, LIST_Games);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SettingsFrame::OnQuit, this, wxID_OK);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SettingsFrame::OnAddGame, this, BUTTON_AddGame);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SettingsFrame::OnEditGame, this, BUTTON_EditGame);
Bind(wxEVT_COMMAND_BUTTON_CLICKED, &SettingsFrame::OnRemoveGame, this, BUTTON_RemoveGame);
//Set up layout.
wxSizerFlags leftItem(0);
leftItem.Left();
@@ -124,7 +123,7 @@ SettingsFrame::SettingsFrame(wxWindow *parent, const wxString& title, YAML::Node
bigBox->AddSpacer(10);
bigBox->AddStretchSpacer(1);
bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Language changes will be applied after BOSS is restarted.")), wholeItem);
bigBox->Add(new wxStaticText(this, wxID_ANY, translate("Language and game changes will be applied after BOSS is restarted.")), wholeItem);
//Need to add 'OK' and 'Cancel' buttons.
wxSizer * sizer = CreateSeparatedButtonSizer(wxOK|wxCANCEL);
-1
View File
@@ -41,7 +41,6 @@ public:
void OnRemoveGame(wxCommandEvent& event);
void SetDefaultValues();
DECLARE_EVENT_TABLE()
private:
wxChoice *DebugVerbosityChoice;
wxChoice *GameChoice;
-3
View File
@@ -29,9 +29,6 @@
namespace fs = boost::filesystem;
Viewer::Viewer(wxWindow *parent, const wxString& title, const std::string& path) : wxFrame(parent, wxID_ANY, title) {
if (!fs::exists(fs::absolute(path)))
throw boss::error(ERROR_PATH_NOT_FOUND, "The path \"" + path + "\" could not be found.");
wxWebView * web = wxWebView::New(this, wxID_ANY, "file://" + fs::absolute(path).string());
wxBoxSizer* topsizer = new wxBoxSizer(wxVERTICAL);