diff --git a/Configuration/UserConfig.cs b/Configuration/UserConfig.cs index ad247eff..cdba3a6c 100644 --- a/Configuration/UserConfig.cs +++ b/Configuration/UserConfig.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Drawing; using System.Globalization; using System.IO; @@ -16,7 +17,7 @@ sealed class UserConfig{ Binder = new SerializationCompatibilityHandler() }; - private const int CurrentFileVersion = 4; + private const int CurrentFileVersion = 5; // START OF CONFIGURATION @@ -116,6 +117,8 @@ private UserConfig(string file){ EnableTrayHighlight = true; Plugins = new PluginConfig(); PluginsWindow = new WindowState(); + + Plugins.DisableOfficialFromConfig("clear-columns"); } private void UpgradeFile(){ @@ -155,6 +158,11 @@ private void UpgradeFile(){ ++fileVersion; } + if (fileVersion == 4){ + Plugins.DisableOfficialFromConfig("clear-columns"); + ++fileVersion; + } + // update the version fileVersion = CurrentFileVersion; Save(); diff --git a/Resources/Plugins/clear-columns/.meta b/Resources/Plugins/clear-columns/.meta new file mode 100644 index 00000000..3b87fc58 --- /dev/null +++ b/Resources/Plugins/clear-columns/.meta @@ -0,0 +1,14 @@ +[name] +Clear columns + +[description] +- Adds buttons and keyboard shortcuts to quickly clear columns + +[author] +chylex + +[version] +1.0 + +[website] +https://tweetduck.chylex.com \ No newline at end of file diff --git a/Resources/Plugins/clear-columns/browser.js b/Resources/Plugins/clear-columns/browser.js new file mode 100644 index 00000000..c8f9cf39 --- /dev/null +++ b/Resources/Plugins/clear-columns/browser.js @@ -0,0 +1,79 @@ +constructor(){ + super({ + requiresPageReload: true + }); +} + +enabled(){ + // prepare variables and functions + var clearColumn = (columnName) => { + TD.controller.columnManager.get(columnName).clear(); + TD.controller.stats.columnActionClick("clear"); + }; + + var clearAllColumns = () => { + Object.keys(TD.controller.columnManager.getAll()).forEach(key => clearColumn(key)); + }; + + var replaceMustache = (key, search, replace) => { + TD.mustaches[key] = TD.mustaches[key].replace(search, replace); + }; + + // prepare event handlers + this.eventClearSingle = function(){ + clearColumn($(this).closest(".js-column").attr("data-column")); + }; + + this.eventClearAll = function(){ + clearAllColumns(); + }; + + this.eventKeys = function(e){ + if (e.keyCode === 46 && (document.activeElement === null || document.activeElement === document.body)){ // 46 = delete + if (e.altKey){ + clearAllColumns(); + } + else{ + var focusedColumn = $(".js-column.is-focused"); + + if (focusedColumn.length){ + clearColumn(focusedColumn.attr("data-column")); + } + } + } + }; + + // add column buttons and keyboard shortcut info to UI + replaceMustache("column/column_header.mustache", "</header>", [ + '<a class="column-header-link" href="#" data-action="td-clearcolumns-dosingle" style="right:34px">', + '<i class="icon icon-clear-timeline"></i>', + '</a></header>' + ].join("")); + + replaceMustache("keyboard_shortcut_list.mustache", "</dl> <dl", [ + '<dd class="keyboard-shortcut-definition" style="white-space:nowrap">', + '<span class="text-like-keyboard-key">1</span> … <span class="text-like-keyboard-key">9</span> + <span class="text-like-keyboard-key">Del</span> Clear column 1-9', + '</dd><dd class="keyboard-shortcut-definition">', + '<span class="text-like-keyboard-key">Alt</span> + <span class="text-like-keyboard-key">Del</span> Clear all', + '</dd></dl><dl' + ].join("")); +} + +ready(){ + // setup events + $(document).on("click", "[data-action='td-clearcolumns-dosingle']", this.eventClearSingle); + $(document).on("click", "[data-action='td-clearcolumns-doall']", this.eventClearAll); + $(document).on("keydown", this.eventKeys); + + // add clear all button + $("nav.app-navigator").first().append([ + '<a class="link-clean cf app-nav-link padding-hl" data-title="Clear all" data-action="td-clearcolumns-doall">', + '<div class="obj-left"><i class="icon icon-large icon-clear-timeline"></i></div>', + '<div class="nbfc padding-ts hide-condensed">Clear all</div>', + '</a></nav>' + ].join("")); +} + +disabled(){ + // not needed, plugin reloads the page when enabled or disabled +}