Implemented copy content to clipboard.

Closes #147. Also fixed the current game not being pointed to in the
game menu.
This commit is contained in:
WrinklyNinja
2014-08-23 22:15:16 +01:00
parent 48f8657f0c
commit 0c127614aa
5 changed files with 110 additions and 28 deletions
+54 -3
View File
@@ -545,6 +545,54 @@ function clearAllMetadata(evt) {
}
});
}
function copyContent(evt) {
var messages = [];
var plugins = [];
if (loot.game) {
loot.game.globalMessages.forEach(function(message){
var m = {};
messages.push({
type: message.type,
content: message.content[0].str
});
});
loot.game.plugins.forEach(function(plugin){
plugins.push({
name: plugin.name,
crc: plugin.crc,
version: plugin.version,
isActive: plugin.isActive,
isDummy: plugin.isDummy,
loadsBSA: plugin.loadsBSA,
modPriority: plugin.modPriority,
isGlobalPriority: plugin.isGlobalPriority,
messages: plugin.messages,
tags: plugin.tags,
isDirty: plugin.isDirty
});
});
} else {
var message = document.getElementById('generalMessagesList').getElementsByTagName('ul')[0].firstElementChild;
if (message) {
messages.push({
type: 'error',
content: message.textContent
});
}
}
var request = JSON.stringify({
name: 'copyContent',
args: [{
messages: messages,
plugins: plugins
}]
});
loot.query(request).catch(processCefError);
}
function handlePluginDrop(evt) {
evt.stopPropagation();
@@ -811,6 +859,7 @@ function setupEventHandlers() {
document.getElementById('redatePluginsButton').addEventListener('click', redatePlugins, false);
document.getElementById('openLogButton').addEventListener('click', openLogLocation, false);
document.getElementById('wipeUserlistButton').addEventListener('click', clearAllMetadata, false);
document.getElementById('copyContentButton').addEventListener('click', copyContent, false);
document.getElementById('gameMenu').addEventListener('click', openMenu, false);
document.getElementById('settingsButton').addEventListener('click', showSettingsDialog, false);
document.getElementById('helpMenu').addEventListener('click', openMenu, false);
@@ -929,6 +978,10 @@ function initVars() {
console.log('getInstalledGames response: ' + results[1]);
}
if (results.length > 3) {
updateInterfaceWithGameInfo(results[3]);
}
try {
loot.settings = JSON.parse(results[2]);
if (loot.settings.filters == undefined) {
@@ -941,9 +994,7 @@ function initVars() {
console.log('getSettings response: ' + results[2]);
}
if (results.length > 3) {
updateInterfaceWithGameInfo(results[3]);
} else {
if (results.length == 3) {
document.getElementById('settingsButton').click();
}
+1
View File
@@ -420,6 +420,7 @@
<li id="redatePluginsButton"><span class="fa fa-fw fa-calendar-o"></span>Redate Plugins <!-- or fa-clock-o fa-history -->
<li id="openLogButton"><span class="fa fa-fw fa-folder-open"></span>Open Debug Log Location
<li id="wipeUserlistButton"><span class="fa fa-fw fa-trash-o"></span>Clear All User Metadata
<li id="copyContentButton"><span class="fa fa-fw fa-copy"></span>Copy Content As Text
</ol>
<li id="gameMenu">Game
<ol class="hidden">
+1 -1
View File
@@ -53,7 +53,7 @@ namespace loot {
// yaml-cpp produces `!<!>` artifacts in its output, so remove them.
std::string json = out.c_str();
boost::replace_all(json, "!<!>", "");
boost::replace_all(json, "!<!> ", "");
// There's also a bit of weirdness where there are some \x escapes and some \u escapes.
// They should all be \u, so transform them.
boost::replace_all(json, "\\x", "\\u00");
+52 -24
View File
@@ -309,6 +309,28 @@ namespace loot {
callback->Success("");
return true;
}
else if (requestName == "copyContent") {
// Has one arg, just convert it to a YAML output string.
try {
YAML::Emitter yout;
yout.SetIndent(2);
yout << request["args"][0];
string text = yout.c_str();
// Get rid of yaml-cpp weirdness.
boost::replace_all(text, "!<!> ", "");
CopyToClipboard(text);
callback->Success("");
}
catch (loot::error &e) {
BOOST_LOG_TRIVIAL(error) << "Failed to copy plugin metadata. Details: " << e.what();
callback->Failure(e.code(), string("Failed to copy plugin metadata. Details: ") + e.what());
}
catch (std::exception& e) {
BOOST_LOG_TRIVIAL(error) << "Failed to copy plugin metadata. Details: " << e.what();
callback->Failure(-1, string("Failed to copy plugin metadata. Details: ") + e.what());
}
return true;
}
return false;
}
@@ -365,32 +387,11 @@ namespace loot {
yout.SetIndent(2);
yout << plugin;
text = yout.c_str();
// Get rid of yaml-cpp weirdness.
boost::replace_all(text, "!<!> ", "");
}
#ifdef _WIN32
if (!OpenClipboard(NULL)) {
throw loot::error(loot::error::windows_error, "Failed to open the Windows clipboard.");
}
if (!EmptyClipboard()) {
throw loot::error(loot::error::windows_error, "Failed to empty the Windows clipboard.");
}
// The clipboard takes a Unicode (ie. UTF-16) string that it then owns and must not
// be destroyed by LOOT. Convert the string, then copy it into a new block of
// memory for the clipboard.
wstring wtext = ToWinWide(text);
wchar_t * wcstr = new wchar_t[wtext.length() + 1];
wcscpy(wcstr, wtext.c_str());
if (SetClipboardData(CF_UNICODETEXT, wcstr) == NULL) {
throw loot::error(loot::error::windows_error, "Failed to copy metadata to the Windows clipboard.");
}
if (!CloseClipboard()) {
throw loot::error(loot::error::windows_error, "Failed to close the Windows clipboard.");
}
#endif
CopyToClipboard(text);
BOOST_LOG_TRIVIAL(info) << "Exported userlist metadata text for \"" << pluginName << "\": " << text;
}
@@ -905,6 +906,33 @@ namespace loot {
return YAML::Node();
}
void Handler::CopyToClipboard(const std::string& text) {
#ifdef _WIN32
if (!OpenClipboard(NULL)) {
throw loot::error(loot::error::windows_error, "Failed to open the Windows clipboard.");
}
if (!EmptyClipboard()) {
throw loot::error(loot::error::windows_error, "Failed to empty the Windows clipboard.");
}
// The clipboard takes a Unicode (ie. UTF-16) string that it then owns and must not
// be destroyed by LOOT. Convert the string, then copy it into a new block of
// memory for the clipboard.
wstring wtext = ToWinWide(text);
wchar_t * wcstr = new wchar_t[wtext.length() + 1];
wcscpy(wcstr, wtext.c_str());
if (SetClipboardData(CF_UNICODETEXT, wcstr) == NULL) {
throw loot::error(loot::error::windows_error, "Failed to copy metadata to the Windows clipboard.");
}
if (!CloseClipboard()) {
throw loot::error(loot::error::windows_error, "Failed to close the Windows clipboard.");
}
#endif
}
// LootHandler methods
//--------------------
+2
View File
@@ -74,6 +74,8 @@ namespace loot {
YAML::Node Handler::GenerateDerivedMetadata(const std::string& pluginName);
YAML::Node Handler::GenerateDerivedMetadata(const Plugin& file, const Plugin& masterlist, const Plugin& userlist);
void CopyToClipboard(const std::string& text);
};
class LootHandler : public CefClient,