From 9579440ad49a178f8a2ad0e5fa352e4e10f0a55f Mon Sep 17 00:00:00 2001 From: WrinklyNinja Date: Tue, 12 Aug 2014 13:07:40 +0100 Subject: [PATCH] Implemented "Clear All User Metadata" feature. --- resources/report/js/script.js | 11 ++++++++++- src/backend/game.cpp | 5 +++++ src/backend/game.h | 1 + src/gui/handler.cpp | 5 +++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/resources/report/js/script.js b/resources/report/js/script.js index 1e9ba99b..5e9e25a4 100644 --- a/resources/report/js/script.js +++ b/resources/report/js/script.js @@ -306,7 +306,16 @@ function redatePlugins(evt) { //showMessageBox('info', 'Redate Plugins', 'Plugins were successfully redated.'); } function clearAllMetadata(evt) { - showMessageDialog('Clear All Metadata', 'Are you sure you want to clear all existing user-added metadata from all plugins?'); + showMessageDialog('Clear All Metadata', 'Are you sure you want to clear all existing user-added metadata from all plugins?', function(result){ + if (result) { + loot.query('clearAllMetadata').then(function(result){ + /* Need to also empty the UI-side user metadata. */ + loot.game.plugins.forEach(function(plugin){ + plugin.userlist = undefined; + }); + }).catch(processCefError); + } + }); } function handlePluginDrop(evt) { evt.stopPropagation(); diff --git a/src/backend/game.cpp b/src/backend/game.cpp index ea0620ac..0c5dad26 100644 --- a/src/backend/game.cpp +++ b/src/backend/game.cpp @@ -116,6 +116,11 @@ namespace loot { uout.close(); } + void MetadataList::clear() { + plugins.clear(); + messages.clear(); + } + bool MetadataList::operator == (const MetadataList& rhs) const { if (this->plugins.size() != rhs.plugins.size() || this->messages.size() != rhs.messages.size()) { BOOST_LOG_TRIVIAL(info) << "Metadata edited for some plugin, new and old userlists differ in size."; diff --git a/src/backend/game.h b/src/backend/game.h index ee3bcbe2..5a903445 100644 --- a/src/backend/game.h +++ b/src/backend/game.h @@ -57,6 +57,7 @@ namespace loot { public: void Load(const boost::filesystem::path& filepath); void Save(const boost::filesystem::path& filepath); + void clear(); bool operator == (const MetadataList& rhs) const; //Compares content. diff --git a/src/gui/handler.cpp b/src/gui/handler.cpp index fb616359..ea4a5a8c 100644 --- a/src/gui/handler.cpp +++ b/src/gui/handler.cpp @@ -130,6 +130,11 @@ namespace loot { callback->Success(""); return true; } + else if (request == "clearAllMetadata") { + g_app_state.CurrentGame().userlist.clear(); + callback->Success(""); + return true; + } else { // May be a request with arguments. YAML::Node req;