Add "Reload Last Plugin" feature

pull/223/head
Lennart Kats 2015-11-29 14:50:28 +00:00
rodzic d0638febaa
commit ffad1a4a09
1 zmienionych plików z 47 dodań i 1 usunięć

Wyświetl plik

@ -3,7 +3,7 @@ define(function(require, exports, module) {
main.consumes = [
"PreferencePanel", "settings", "ui", "util", "Form", "ext", "c9",
"dialog.alert", "dialog.confirm", "layout", "proc", "menus", "commands",
"dialog.error", "tree.favorites", "fs", "tree", "plugin.debug",
"dialog.error", "dialog.info", "tree.favorites", "fs", "tree", "plugin.debug",
"preferences.experimental"
];
main.provides = ["plugin.manager"];
@ -52,9 +52,11 @@ define(function(require, exports, module) {
var tree = imports.tree;
var proc = imports.proc;
var util = imports.util;
var qs = require("querystring");
var alert = imports["dialog.alert"].show;
var confirm = imports["dialog.confirm"].show;
var showError = imports["dialog.error"].show;
var showInfo = imports["dialog.info"].show;
var favs = imports["tree.favorites"];
var pluginDebug = imports["plugin.debug"];
var experimental = imports["preferences.experimental"];
@ -133,6 +135,33 @@ define(function(require, exports, module) {
// changed = true;
// updateCommandsFromSettings();
// }, plugin);
commands.addCommand({
name: "reloadLastPlugin",
bindKey: {mac: "F4", win: "F4"},
hint: "reload plugin last reloaded in plugin manager",
exec: function() {
var name = getLastReloaded();
name && reload(name);
}
}, plugin);
commands.addCommand({
name: "reloadPlugin",
group: "Plugins",
exec: function(){
commands.exec("openpreferences", null, { panel: plugin });
}
}, plugin);
menus.addItemByPath("Tools/Developer/Reload Built-in Plugin...", new ui.item({
command: "reloadPlugin"
}), 1100, plugin);
menus.addItemByPath("Tools/Developer/Reload Last Plugin", new ui.item({
command: "reloadLastPlugin",
isAvailable: getLastReloaded
}), 1200, plugin);
menus.addItemByPath("File/New Plugin", null, 210, plugin);
Object.keys(TEMPLATES).forEach(function(name){
@ -629,6 +658,19 @@ define(function(require, exports, module) {
}
function reload(name) {
var key = commands.getHotkey("reloadLastPlugin");
if (commands.platform == "mac")
key = apf.hotkeys.toMacNotation(key);
if (!getLastReloaded())
showInfo("Reloaded " + name + ". Press " + key + " to reload again.", 3000);
else
showInfo("Reloaded " + name + ".", 1000);
var href = document.location.href.replace(/[?&]reload=[^&]+/, "")
+ (document.location.href.match(/\?/) ? "&" : "?")
+ "reload=" + name;
window.history.replaceState(window.history.state, null, href);
for (var plugin in architect.lut) {
if (architect.lut[plugin].provides.indexOf(name) < 0)
continue;
@ -637,6 +679,10 @@ define(function(require, exports, module) {
return;
}
}
function getLastReloaded() {
return qs.parse(document.location.href.substr(1)).reload;
}
/***** Lifecycle *****/