From 2f21a9056456edd183a4d478ac3517f500e6723f Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 28 Jan 2014 10:20:36 +0000 Subject: [PATCH] Issue #70 work. * Fixed range limits on the priority spinner. * Implemented right-click menu for plugin list, moved "Copy Metadata As Text" into it and added "Copy Name" and "Remove All User-Added Metadata" entries. --- src/gui/editor.cpp | 114 +++++++++++++++++++++++++++++++-------------- src/gui/editor.h | 7 ++- src/gui/ids.h | 4 +- 3 files changed, 88 insertions(+), 37 deletions(-) diff --git a/src/gui/editor.cpp b/src/gui/editor.cpp index 8bbf1b24..f5875734 100644 --- a/src/gui/editor.cpp +++ b/src/gui/editor.cpp @@ -30,6 +30,7 @@ #include #include +#include using namespace std; @@ -121,7 +122,7 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli //Initialise controls. pluginText = new wxStaticText(this, wxID_ANY, ""); prioritySpin = new wxSpinCtrl(this, wxID_ANY, "0"); - prioritySpin->SetRange(-10,10); + prioritySpin->SetRange(std::numeric_limits::min(), std::numeric_limits::max()); enableUserEditsBox = new wxCheckBox(this, wxID_ANY, translate("Enable User Changes")); addBtn = new wxButton(this, BUTTON_AddRow, translate("Add File")); @@ -129,7 +130,6 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli removeBtn = new wxButton(this, BUTTON_RemoveRow, translate("Remove File")); applyBtn = new wxButton(this, BUTTON_Apply, translate("Save Changes")); cancelBtn = new wxButton(this, BUTTON_Cancel, translate("Cancel")); - exportBtn = new wxButton(this, BUTTON_Export, translate("Copy Metadata As Text")); pluginList = new wxListView(this, LIST_Plugins, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL); reqsList = new wxListView(reqsTab, LIST_Reqs, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL); @@ -139,6 +139,8 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli dirtyList = new wxListView(dirtyTab, LIST_DirtyInfo, wxDefaultPosition, wxDefaultSize, wxLC_REPORT|wxLC_SINGLE_SEL); messageList = new MessageList(messagesTab, LIST_Messages, language); + pluginMenu = new wxMenu(); + //Tie together notebooks and panels. listBook->AddPage(reqsTab, translate("Requirements"), true); listBook->AddPage(incsTab, translate("Incompatibilities")); @@ -172,13 +174,17 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli dirtyList->AppendColumn(translate("Deleted Navmesh Count")); dirtyList->AppendColumn(translate("Cleaning Utility")); + //Set up plugin right-click menu. + pluginMenu->Append(MENU_CopyName, translate("Copy Name")); + pluginMenu->Append(MENU_CopyMetadata, translate("Copy Metadata As Text")); + pluginMenu->Append(MENU_ClearMetadata, translate("Remove All User-Added Metadata")); + //Initialise control states. addBtn->Enable(false); editBtn->Enable(false); removeBtn->Enable(false); prioritySpin->Enable(false); enableUserEditsBox->Enable(false); - exportBtn->Enable(false); //Make plugin name bold text. wxFont font = pluginText->GetFont(); @@ -199,7 +205,10 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli Bind(wxEVT_BUTTON, &Editor::OnAddRow, this, BUTTON_AddRow); Bind(wxEVT_BUTTON, &Editor::OnEditRow, this, BUTTON_EditRow); Bind(wxEVT_BUTTON, &Editor::OnRemoveRow, this, BUTTON_RemoveRow); - Bind(wxEVT_BUTTON, &Editor::OnExport, this, BUTTON_Export); + Bind(wxEVT_LIST_ITEM_RIGHT_CLICK, &Editor::OnPluginListRightClick, this); + Bind(wxEVT_MENU, &Editor::OnPluginCopyName, this, MENU_CopyName); + Bind(wxEVT_MENU, &Editor::OnPluginCopyMetadata, this, MENU_CopyMetadata); + Bind(wxEVT_MENU, &Editor::OnPluginClearMetadata, this, MENU_ClearMetadata); //Set up layout. wxBoxSizer * bigBox = new wxBoxSizer(wxHORIZONTAL); @@ -251,8 +260,6 @@ Editor::Editor(wxWindow *parent, const wxString& title, const std::string userli hbox2->Add(removeBtn, 0, wxLEFT, 5); mainBox->Add(hbox2, 0, wxALIGN_RIGHT); - mainBox->Add(exportBtn, 0, wxALIGN_RIGHT|wxTOP, 10); - mainBox->AddSpacer(30); wxBoxSizer * hbox6 = new wxBoxSizer(wxHORIZONTAL); @@ -372,7 +379,66 @@ void Editor::OnPluginSelect(wxListEvent& event) { addBtn->Enable(true); editBtn->Enable(false); removeBtn->Enable(false); - exportBtn->Enable(true); + } +} + +void Editor::OnPluginListRightClick(wxListEvent& event) { + PopupMenu(pluginMenu); +} + +void Editor::OnPluginCopyName(wxCommandEvent& event) { + if (wxTheClipboard->Open()) { + wxTheClipboard->SetData(new wxTextDataObject(pluginList->GetItemText(pluginList->GetFirstSelected()))); + wxTheClipboard->Close(); + } +} + +void Editor::OnPluginCopyMetadata(wxCommandEvent& event) { + wxString selectedPlugin = pluginList->GetItemText(pluginList->GetFirstSelected()); + boss::Plugin plugin = GetUserData(selectedPlugin); + + string text; + if (plugin.HasNameOnly()) + text = "name: " + plugin.Name(); + else { + YAML::Emitter yout; + yout.SetIndent(2); + yout << plugin; + text = yout.c_str(); + } + + BOOST_LOG_TRIVIAL(info) << "Exported userlist metadata text for \"" << selectedPlugin.ToUTF8() << "\": " << text; + + if (!text.empty() && wxTheClipboard->Open()) { + wxTheClipboard->SetData(new wxTextDataObject(FromUTF8(text))); + wxTheClipboard->Close(); + } +} + +void Editor::OnPluginClearMetadata(wxCommandEvent& event) { + wxMessageDialog dialog(this, + translate("Are you sure you want to clear all existing user-added metadata from this plugin?"), + translate("BOSS: Warning"), + wxYES_NO | wxCANCEL | wxICON_EXCLAMATION); + + if (dialog.ShowModal() == wxID_YES) { + long i = pluginList->GetFirstSelected(); + wxString selectedPlugin = pluginList->GetItemText(i); + boss::Plugin p(string(selectedPlugin.ToUTF8())); + + //Need to clear what's currently in the editor and what's from the userlist. + + vector::const_iterator it = std::find(_editedPlugins.begin(), _editedPlugins.end(), p); + + //Delete existing userlist entry. + if (it != _editedPlugins.end()) + _editedPlugins.erase(it); + + //Also clear any unapplied data. Easiest way to do this is to simulate loading the plugin's data again. + pluginText->SetLabelText(""); + pluginList->Select(i, false); + pluginList->Select(i, true); + pluginList->SetItemFont(i, wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); } } @@ -751,27 +817,6 @@ void Editor::OnRowSelect(wxListEvent& event) { } } -void Editor::OnExport(wxCommandEvent& event) { - wxString currentPlugin = pluginText->GetLabelText(); - - boss::Plugin initial = GetMasterData(currentPlugin); - boss::Plugin edited = GetNewData(currentPlugin); - - boss::Plugin diff = edited.DiffMetadata(initial); - - YAML::Emitter yout; - yout.SetIndent(2); - yout << diff; - string text = yout.c_str(); - - BOOST_LOG_TRIVIAL(info) << "Exported metadata text for \"" << currentPlugin.ToUTF8() << "\": " << text; - - if (!text.empty() && wxTheClipboard->Open()) { - wxTheClipboard->SetData( new wxTextDataObject(FromUTF8(text)) ); - wxTheClipboard->Close(); - } -} - void Editor::OnQuit(wxCommandEvent& event) { BOOST_LOG_TRIVIAL(debug) << "Exiting metadata editor."; if (event.GetId() == BUTTON_Apply) { @@ -813,10 +858,12 @@ void Editor::ApplyEdits(const wxString& plugin) { _editedPlugins.push_back(diff); //Also mark plugin as edited in list. - if (!diff.HasNameOnly()) { - long i = pluginList->FindItem(-1, plugin); + long i = pluginList->FindItem(-1, plugin); + if (!diff.HasNameOnly()) pluginList->SetItemFont(i, wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT).Bold()); - } + else + pluginList->SetItemFont(i, wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)); + } boss::Plugin Editor::GetMasterData(const wxString& plugin) const { @@ -834,10 +881,9 @@ boss::Plugin Editor::GetMasterData(const wxString& plugin) const { boss::Plugin Editor::GetUserData(const wxString& plugin) const { BOOST_LOG_TRIVIAL(debug) << "Getting userlist metadata for plugin: " << plugin.ToUTF8(); - boss::Plugin p; - boss::Plugin p_in(string(plugin.ToUTF8())); + boss::Plugin p(string(plugin.ToUTF8())); - vector::const_iterator it = std::find(_editedPlugins.begin(), _editedPlugins.end(), p_in); + vector::const_iterator it = std::find(_editedPlugins.begin(), _editedPlugins.end(), p); if (it != _editedPlugins.end()) p = *it; diff --git a/src/gui/editor.h b/src/gui/editor.h index 5f28c5c1..6a07bef6 100644 --- a/src/gui/editor.h +++ b/src/gui/editor.h @@ -57,24 +57,27 @@ public: Editor(wxWindow *parent, const wxString& title, const std::string userlistPath, const std::vector& basePlugins, std::vector& editedPlugins, const unsigned int language, const boss::Game& game); void OnPluginSelect(wxListEvent& event); + void OnPluginListRightClick(wxListEvent& event); + void OnPluginCopyName(wxCommandEvent& event); + void OnPluginCopyMetadata(wxCommandEvent& event); + void OnPluginClearMetadata(wxCommandEvent& event); void OnEnabledToggle(wxCommandEvent& event); void OnPriorityChange(wxSpinEvent& event); void OnListBookChange(wxBookCtrlEvent& event); void OnAddRow(wxCommandEvent& event); void OnEditRow(wxCommandEvent& event); void OnRemoveRow(wxCommandEvent& event); - void OnExport(wxCommandEvent& event); void OnRecalc(wxCommandEvent& event); void OnRowSelect(wxListEvent& event); void OnQuit(wxCommandEvent& event); private: + wxMenu * pluginMenu; wxButton * addBtn; wxButton * editBtn; wxButton * removeBtn; wxButton * applyBtn; wxButton * cancelBtn; - wxButton * exportBtn; wxListView * pluginList; wxListView * reqsList; wxListView * incsList; diff --git a/src/gui/ids.h b/src/gui/ids.h index ad010602..3a01118f 100644 --- a/src/gui/ids.h +++ b/src/gui/ids.h @@ -63,8 +63,10 @@ enum { BUTTON_RemoveContent, BUTTON_Apply, BUTTON_Cancel, - BUTTON_Export, BOOK_Lists, + MENU_CopyName, + MENU_CopyMetadata, + MENU_ClearMetadata, //Main window - dynamically created IDs. MENU_LowestDynamicGameID, LIST_LoadOrder,