From 88a65f038e447c99f909fac4f95264e398195d54 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Wed, 22 Feb 2017 13:15:26 +0100 Subject: [PATCH] Add a "close plugin library" button (#2072) * provides a "close plugin library" button * starting from #1718 by @inmysocks * possibly fixes all of #1718, #1597, and #2067 * corrected code comment * add back title No idea why I overlooked this beforehand. Next time I will not suggest such changes that have little to do with the PR, but rather just comment the code. * ah, sorry, "fixed" wrong spot now ``` <$action-sendmessage $message="tm-load-plugin-from-library" url={{!!url}} title={{$(assetInfo)$!!original-title}}/> ``` ...should be back at the right spot. * mhhh... still fixing the mess load, unload, puh... let's see if I got it now * added unloadIFrame and minor syntax fixes --- core/language/en-GB/ControlPanel.multids | 1 + core/modules/startup/browser-messaging.js | 40 ++++++++++++++++++---- core/ui/ControlPanel/Modals/AddPlugins.tid | 14 ++++++++ 3 files changed, 49 insertions(+), 6 deletions(-) diff --git a/core/language/en-GB/ControlPanel.multids b/core/language/en-GB/ControlPanel.multids index dafce002e..3907bda98 100644 --- a/core/language/en-GB/ControlPanel.multids +++ b/core/language/en-GB/ControlPanel.multids @@ -74,6 +74,7 @@ Plugins/NoInfoFound/Hint: No ''"<$text text=<>/>"'' found Plugins/NoInformation/Hint: No information provided Plugins/NotInstalled/Hint: This plugin is not currently installed Plugins/OpenPluginLibrary: open plugin library +Plugins/ClosePluginLibrary: close plugin library Plugins/Plugins/Caption: Plugins Plugins/Plugins/Hint: Plugins Plugins/Reinstall/Caption: reinstall diff --git a/core/modules/startup/browser-messaging.js b/core/modules/startup/browser-messaging.js index c38ba7b85..c67090464 100644 --- a/core/modules/startup/browser-messaging.js +++ b/core/modules/startup/browser-messaging.js @@ -29,16 +29,17 @@ function loadIFrame(url,callback) { callback(null,iframeInfo); } else { // Create the iframe and save it in the list - var iframe = document.createElement("iframe"), - iframeInfo = { - url: url, - status: "loading", - domNode: iframe - }; + var iframe = document.createElement("iframe"); + iframeInfo = { + url: url, + status: "loading", + domNode: iframe + }; $tw.browserMessaging.iframeInfoMap[url] = iframeInfo; saveIFrameInfoTiddler(iframeInfo); // Add the iframe to the DOM and hide it iframe.style.display = "none"; + iframe.setAttribute("library","true"); document.body.appendChild(iframe); // Set up onload iframe.onload = function() { @@ -57,6 +58,18 @@ function loadIFrame(url,callback) { } } +/* +Unload library iframe for given url +*/ +function unloadIFrame(url){ + $tw.utils.each(document.getElementsByTagName('iframe'), function(iframe) { + if(iframe.getAttribute("library") === "true" && + iframe.getAttribute("src") === url) { + iframe.parentNode.removeChild(iframe); + } + }); +} + function saveIFrameInfoTiddler(iframeInfo) { $tw.wiki.addTiddler(new $tw.Tiddler($tw.wiki.getCreationFields(),{ title: "$:/temp/ServerConnection/" + iframeInfo.url, @@ -93,6 +106,21 @@ exports.startup = function() { }); } }); + // Listen for widget messages to control unloading the plugin library + $tw.rootWidget.addEventListener("tm-unload-plugin-library",function(event) { + var paramObject = event.paramObject || {}, + url = paramObject.url; + $tw.browserMessaging.iframeInfoMap[url] = undefined; + if(url) { + unloadIFrame(url); + $tw.utils.each( + $tw.wiki.filterTiddlers("[[$:/temp/ServerConnection/" + url + "]] [prefix[$:/temp/RemoteAssetInfo/" + url + "/]]"), + function(title) { + $tw.wiki.deleteTiddler(title); + } + ); + } + }); $tw.rootWidget.addEventListener("tm-load-plugin-from-library",function(event) { var paramObject = event.paramObject || {}, url = paramObject.url, diff --git a/core/ui/ControlPanel/Modals/AddPlugins.tid b/core/ui/ControlPanel/Modals/AddPlugins.tid index 76305e4ed..b86f5351f 100644 --- a/core/ui/ControlPanel/Modals/AddPlugins.tid +++ b/core/ui/ControlPanel/Modals/AddPlugins.tid @@ -90,6 +90,16 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$ \end +\define close-library-button() +<$reveal type='nomatch' state='$:/temp/ServerConnection/$(PluginLibraryURL)$' text=''> +<$button class='tc-btn-big-green'> +<$action-sendmessage $message="tm-unload-plugin-library" url={{!!url}}/> +{{$:/core/images/chevron-left}} {{$:/language/ControlPanel/Plugins/ClosePluginLibrary}} +<$action-deletetiddler $filter="[prefix[$:/temp/ServerConnection/$(PluginLibraryURL)$]][prefix[$:/temp/RemoteAssetInfo/$(PluginLibraryURL)$]]"/> + + +\end + \define plugin-library-listing() <$list filter="[all[tiddlers+shadows]tag[$:/tags/PluginLibrary]]">
@@ -100,6 +110,10 @@ $:/state/add-plugin-info/$(connectionTiddler)$/$(assetInfo)$ <$transclude/> +<$set name=PluginLibraryURL value={{!!url}}> +<> + + <>