// 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) { initData.name = "Confirm Multi-open"; initData.desc = "Ask for confirmation if more than X selected files are attempted to be opened at once."; initData.copyright = "by jsys in 2014"; initData.version = "1.0.0"; initData.default_enable = true; initData.Config["threshold"] = 20; // default } // Called when a file or folder is double-clicked function OnDoubleClick(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)." if (doubleClickData.cont == undefined) return legacy_handleDoubleClick(doubleClickData); else return handleOnDoubleClick(doubleClickData); } // ************************** // * User-defined functions * // ************************** function askConfirmation(doubleClickData, selfiles) { dlg = doubleClickData.tab.Dlg; dlg.title = "Opening Multiple Files"; dlg.message = selfiles + " files are about to be opened."; dlg.buttons = "Proceed|Cancel"; dlg.icon = "warn" return dlg.Show(); } function handleOnDoubleClick(doubleClickData) { // elegant version for Dopus version above 11.5.6 beta doubleClickData.cont = false; var selfiles = doubleClickData.Tab.selstats.selfiles; if (selfiles > Script.Config["threshold"] && askConfirmation(doubleClickData, selfiles) == 0) return true; // 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." else return false; } // LEGACY // function legacy_handleDoubleClick(doubleClickData) { // fallback version for Dopus version 11.5.6 beta or below if (doubleClickData.Tab.selstats.selfiles < 1) return false; // prevent "subscript out of range" log spam by below line on regular file browsing (this causes threshold of 0 being ignored in this version) if (String(doubleClickData.item.realpath) == String(doubleClickData.Tab.selected_files(0).realpath)) { var selfiles = doubleClickData.Tab.selstats.selfiles; Script.vars.Set("allowed", 1); if (selfiles > Script.Config["threshold"]) { if (askConfirmation(doubleClickData, selfiles) == 0) { // 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." Script.vars.Set("allowed", 0); return true; } } } if (Script.vars.Get("allowed") == 0) return true; else return false; }