// Confirm multi-open // // // This is a script for Directory Opus. // See http://www.gpsoft.com.au/DScripts/redirect.asp?page=scripts for development information. // Called by Directory Opus to initialize the script function OnInit(initData) { //uid added via script wizard (do not change after publishing this script) var uid = "39CAC04A-02E9-4DFA-9F8D-6B19609A13F3"; //resource center url added via script wizard (required for updating) var url = "http://resource.dopus.com/viewtopic.php?f=35&t=22872"; // ConfirmMultiopen stuff initData.name = "Confirm multi-open"; initData.desc = "Ask before opening more than X selected items by keyboard Enter key."; initData.copyright = "by jsys in 2014-2015"; initData.version = "1.1"; initData.default_enable = true; initData.min_version = "11.10.2"; // settings & defaults initData.config_desc = DOpus.Create.Map(); var option_name = ""; option_name = "Excluded extensions"; initData.Config[option_name] = initData.Config[option_name] = DOpus.NewVector(".mp3 (example)", ".flac (example)", "_comic_page.jpg (example)"); initData.config_desc(option_name) = "Selected items with these extensions (name endings) will not count toward the threshold limit. No wildcards or regex."; option_name = "Focus button"; initData.Config[option_name] = DOpus.NewVector(0, "Proceed", "Cancel"); initData.config_desc(option_name) = "A button on the multi-open confirmation dialog to have initial keyboard focus."; option_name = "Threshold"; initData.Config[option_name] = 20; initData.config_desc(option_name) = "Multi-open confirmation dialog is triggered on attempt to open more than this amount of items."; } // Called when a file or folder is double-clicked function OnDoubleClick(doubleClickData) { if (doubleClickData.mouse != "none") { // ensure we react only when *not* triggered by mouse (such as middle double-click) doubleClickData.call = false; return false; } return handleOnDoubleClick(doubleClickData); // from docs: "If you return True, the double-click will be cancelled and the file will not be opened. If you return False the double-click will be allowed to continue (this is the default)." } // ******************** // * Custom functions * // ******************** String.prototype.endsWith = function(suffix) { // http://stackoverflow.com/a/2548133 return this.indexOf(suffix, this.length - suffix.length) !== -1; } function getExcludedItemsCount(selected) { var count = 0; var enum_selected_items = new Enumerator(selected); for (; !enum_selected_items.atEnd(); enum_selected_items.moveNext()) { var selected_item = enum_selected_items.item(); var enum_excluded_extension = new Enumerator(Script.Config["Excluded extensions"]); for (; !enum_excluded_extension.atEnd(); enum_excluded_extension.moveNext()) { var excluded_extension = enum_excluded_extension.item(); if (String(selected_item).endsWith(excluded_extension)) { count ++; break; } } } return count; } function handleOnDoubleClick(doubleClickData) { if ((doubleClickData.Tab.selstats.selitems - getExcludedItemsCount(doubleClickData.Tab.selected)) > Script.Config["Threshold"] && askConfirmation(doubleClickData.tab) == 0) { doubleClickData.cont = false; // Tells Dopus to stop processing remaining selected files return true; // Cancel current (first) file (i.e., tells Dopus that *we* have handled this file and it doesn't have to do anything else with it) } else { doubleClickData.call = false; // Tells Dopus to continue without calling this script for remaining selected files return false; // Dopus proceeds to handle (current and) remaining selected files } } function askConfirmation(Tab) { var dlg = Tab.Dlg; dlg.title = "Opening Multiple Items"; dlg.icon = "information"; dlg.message = Tab.selstats.selitems + " selected items are to be opened."; dlg.buttons = "Proceed|Cancel"; dlg.defid = Script.Config["Focus button"] == 0; return dlg.Show(); // from docs: "If a dialog has more than one button then by definition the last (right-most) button is the "cancel" button and so this will return index 0." } /////////////////////////////////////////////////////////////////////////////// function OnAboutScript(data){ //v0.1 var cmd = DOpus.Create.Command(); if (!cmd.Commandlist('s').exists("ScriptWizard")){ if (DOpus.Dlg.Request("The 'ScriptWizard' add-in has not been found.\n\n"+ "Install 'ScriptWizard' from [resource.dopus.com].\nThe add-in enables this dialog and also offers "+ "easy updating of scripts and many more.","Yes, take me there!|Cancel", "No About.. ", data.window)) cmd.RunCommand('http://resource.dopus.com/viewtopic.php?f=35&t=23179');} else cmd.RunCommand('ScriptWizard ABOUT WIN='+data.window+' FILE="'+Script.File+'"'); } //MD5 = "6383b0e2f7201fa9a7f741c7db86de17"; DATE = "2015.06.23 - 19:12:11"