From c7a57e1db616587f83754bacd9bd7215406e06f2 Mon Sep 17 00:00:00 2001 From: Mirco Wittrien Date: Sun, 24 Feb 2019 10:37:17 +0100 Subject: [PATCH] Update RepoControls.plugin.js --- Plugins/RepoControls/RepoControls.plugin.js | 63 ++++++++++++++++----- 1 file changed, 50 insertions(+), 13 deletions(-) diff --git a/Plugins/RepoControls/RepoControls.plugin.js b/Plugins/RepoControls/RepoControls.plugin.js index b2310348cc..a42ae964c9 100644 --- a/Plugins/RepoControls/RepoControls.plugin.js +++ b/Plugins/RepoControls/RepoControls.plugin.js @@ -3,7 +3,7 @@ class RepoControls { getName () {return "RepoControls";} - getVersion () {return "1.2.6";} + getVersion () {return "1.2.7";} getAuthor () {return "DevilBro";} @@ -11,7 +11,7 @@ class RepoControls { initConstructor () { this.changelog = { - "improved":[["Search Function","Slightly improved the performance of the feature to search for entries"]] + "added":[["Edit Feature","Added the feature to add an edit button to all plugin/theme entries that on click opens the file in your choosen default editor application"]] }; this.patchModules = { @@ -91,27 +91,43 @@ class RepoControls { `; + this.editButtonMarkup = + ` + + + + + + + + `; + this.deleteButtonMarkup = - ` - - + ` + + + + `; this.css = ` + #bd-settingspane-container .editIcon, #bd-settingspane-container .trashIcon { - margin-right: 5px; + margin: 0 5px 0 -2px; cursor: pointer; vertical-align: top; color: #72767d; } + ${BDFDB.dotCN.themedark} #bd-settingspane-container .editIcon, ${BDFDB.dotCN.themedark} #bd-settingspane-container .trashIcon { color: #dcddde; }`; this.defaults = { settings: { - addDeleteButton: {value:true, description:"Add a Delete Button to your Plugin and Theme List."}, - confirmDelete: {value:true, description:"Ask for your confirmation before deleting a File."} + addEditButton: {value:true, description:"Adds an Edit Button to your Plugin and Theme List."}, + addDeleteButton: {value:true, description:"Adds a Delete Button to your Plugin and Theme List."}, + confirmDelete: {value:true, description:"Asks for your confirmation before deleting a File."} }, sortings: { sort: {value:"name"}, @@ -202,22 +218,44 @@ class RepoControls { processV2CPluginCard (instance, wrapper, methodnames) { if (wrapper.querySelector(BDFDB.dotCN._reponame)) { - if (instance.props && BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton("plugin", wrapper); + let settings = BDFDB.getAllData(this, "settings"); + if (instance.props && settings.addDeleteButton) this.addDeleteButton("plugin", wrapper); + if (instance.props && settings.addEditButton) this.addEditButton("plugin", wrapper); if (methodnames.includes("componentDidUpdate")) this.changeTextToHTML(wrapper, ""); } } processV2CThemeCard (instance, wrapper, methodnames) { if (wrapper.querySelector(BDFDB.dotCN._reponame)) { - if (instance.props && BDFDB.getData("addDeleteButton", this, "settings")) this.addDeleteButton("theme", wrapper); + let settings = BDFDB.getAllData(this, "settings"); + if (instance.props && settings.addDeleteButton) this.addDeleteButton("theme", wrapper); + if (instance.props && settings.addEditButton) this.addEditButton("theme", wrapper); if (methodnames.includes("componentDidUpdate")) this.changeTextToHTML(wrapper, ""); } } + addEditButton (type, wrapper) { + if (!type || !wrapper || wrapper.querySelector(".editIcon")) return; + let name = wrapper.getAttribute("data-name"); + let controls = wrapper.querySelector(BDFDB.dotCN._repocontrols); + if (!name || !controls) return; + let path = global[`bd${type}s`] && global[`bd${type}s`][name] ? this.path.join(this.dirs[type], global[`bd${type}s`][name].filename) : null; + if (!path) return; + let button = BDFDB.htmlToElement(this.editButtonMarkup); + button.addEventListener("click", () => { + if (!require("electron").shell.openItem(path)) BDFDB.showToast(`Unable to open ${type} "${name}".`, {type:"danger"});; + }); + button.addEventListener("mouseenter", e => { + BDFDB.createTooltip(`Edit ${type[0].toUpperCase() + type.slice(1)}`, e.currentTarget, {type:"top",selector:"repocontrols-editicon-tooltip"}); + }); + controls.insertBefore(button, controls.firstElementChild); + } + addDeleteButton (type, wrapper) { if (!type || !wrapper || wrapper.querySelector(".trashIcon")) return; let name = wrapper.getAttribute("data-name"); - if (!name) return; + let controls = wrapper.querySelector(BDFDB.dotCN._repocontrols); + if (!name || !controls) return; let path = global[`bd${type}s`] && global[`bd${type}s`][name] ? this.path.join(this.dirs[type], global[`bd${type}s`][name].filename) : null; if (!path) return; let button = BDFDB.htmlToElement(this.deleteButtonMarkup); @@ -236,8 +274,7 @@ class RepoControls { button.addEventListener("mouseenter", e => { BDFDB.createTooltip(`Delete ${type[0].toUpperCase() + type.slice(1)}`, e.currentTarget, {type:"top",selector:"repocontrols-trashicon-tooltip"}); }); - let controls = wrapper.querySelector(BDFDB.dotCN._repocontrols); - if (controls) controls.insertBefore(button, controls.firstElementChild); + controls.insertBefore(button, controls.firstElementChild); } addControls (type, container) {