// (2022-09-26) v2.0 Posted.
// (2022-09-26) Add (isspecial) test for button activation/deactivation.
// (2022-09-26) Wrap try/catch around dlg.watchtab(srcTab,"stop") in processanchor, just in case!
// (2022-09-27) Improve debug trace information regarding special folders such as My PC.
// (2022-09-27) Suppress left and right click actions for special folders.
// (2022-09-28) Add version information to the starting/ending debug trace messages.
// (2022-09-28) Add missing comma to "esc/s" switch in command template definition.
// (2022-09-28) Remove redundant Go CURRENT EXISTINGLISTER statement from processanchor function.
// (2022-09-29) Improve handling of ±Coll and ±Colls toggles.
// (2022-09-29) v2.1 Posted.
// (2022-09-30) v2.2 Add trace information about precisely what triggered debug mode.
// (2022-09-29) v2.2 Posted.
// Global variables
var me = {
name:"filtermenu",
desc:"Filter Menu",
version:"2.2 (2022-09-30 18:43:00)",
copyright:"(c) @aussieboykie",
id:"aussieboykie",
minver:"12.26"
}
var backfromcoll = DOpus.Create().Map();
var backfromcolls = DOpus.Create().Map();
var candidates = DOpus.Create().Vector();
var cmd;
var colblack = "#FFFFFF";
var colblue = "#0000FF";
var colqual = "#4060C0";
var colred = "#FF0000";
var coltoggle = "#FFFF00";
var colwhite = "#000000";
var colyellow = "#FFFF00";
var defaultcollname;
var dlg; // Detached dialog object
var fltr = "";
var hidefilespattern = DOpus.Create().Map();
var hideflatfolders = DOpus.Create().Map();
var hidefolderspattern = DOpus.Create().Map();
var isqualified;
var isspecial;
var iteration = 0;
var msg_obj;
var promptdlg; // Pop up dialog object
var regexpattern = DOpus.Create().Map();
var simplepattern = DOpus.Create().Map();
var srcPathStr;
var srcTab;
var timername;
var tmpcoll = String(DOpus.FSUtil.Resolve("/temp\\"+me.name+"_coll.tmp"));
var tsexit = DOpus.Create().Map();
var v = DOpus.Create().Vector();
// User settable variables
var clearoutput = false;
var collname;
var dbg = false;
var defaulthidefilespattern = "~(grp:images)";
var defaulthidefolderspattern = "*";
var defaultregexpattern = "\\.(jpg|jpeg|png)$";
var defaultsimplepattern = "*.(jpg|jpeg|png)";
var dlgname = me.name;
var esc = false;
var files = true;
var folders = false;
var fastclickms = 350;
var promptsel = false;
var qualifiers = true;
var showcommands = false;
var timerms = 50;
String.prototype.trim = function(s){s=s||"\\s";return this.replace(new RegExp("^("+s+"){1,}\|("+s+"){1,}$","g"),"");}
function OnInit(initData)
{
initData.name = me.name;
initData.vars("name") = initData.name;
initData.version = me.version;
initData.vars("version") = initData.version;
initData.copyright = me.copyright;
initData.desc = me.desc;
initData.default_enable = true;
var cmd = initData.AddCommand();
cmd.name = initData.name;
cmd.method = "do_main";
cmd.desc = initData.desc;
cmd.label = initData.name;
var str = "both/s,";
str+="clearoutput/s,";
str+="collname/o,";
str+="debug/s,";
str+="dlgname/o,";
str+="esc/s,";
str+="fastclickms/n,";
str+="files/s,folders/s,";
str+="maxiteration/n,"; // Intended for developer use.
str+="promptsel/s,";
str+="qualifiers/s,";
str+="showcommands/s,";
str+="test/s,"; // Intended for developer use.
str+="timerms/n";
cmd.template = str;
initData.config_desc = DOpus.Create().Map();
initData.config.clearoutput = clearoutput;
initData.config_desc("clearoutput") = "Activate debug mode and clear \"Other\" log on startup.";
initData.config.collname = me.name;
initData.config_desc("collname") = "Default target collection.";
initData.config.debug = dbg;
initData.config_desc("debug") = "Write debug information to \"Other\" log.";
initData.config.defaulthidefilespattern = defaulthidefilespattern;
initData.config_desc("defaulthidefilespattern") = "Default hide files filter pattern when prompted.";
initData.config.defaulthidefolderspattern = defaulthidefolderspattern;
initData.config_desc("defaulthidefolderspattern") = "Default hide folders filter pattern when prompted.";
initData.config.defaultregexpattern = defaultregexpattern;
initData.config_desc("defaultregexpattern") = "Default regular expression filter pattern.";
initData.config.defaultsimplepattern = defaultsimplepattern;
initData.config_desc("defaultsimplepattern") = "Default simple filter pattern.";
initData.config.esc = esc;
initData.config_desc("esc") = "Whether to enable ESC as a hotkey to exit the dialog.";
initData.config.fastclickms = fastclickms;
initData.config_desc("fastclickms") = "Minimum milliseconds between recognised clicks of the same button.";
initData.config.files = files;
initData.config_desc("files") = "Apply selection to files.";
initData.config.folders = folders;
initData.config_desc("folders") = "Apply selection to folders.";
initData.config.promptsel = promptsel;
initData.config_desc("promptsel") = "Whether to select the default string in text prompts.";
initData.config.qualifiers = qualifiers;
initData.config_desc("qualifiers") = "Use Alt, Ctrl or Shift qualifier to temporarily reverse Add/Replace or FIles/Folders.";
initData.config.showcommands = showcommands;
initData.config_desc("showcommands") = "Display commnands in the GUI as they are executed.";
initData.config.timerms = timerms;
initData.config_desc("timerms") = "Milliseconds before timer expires.";
}
function do_main(ScriptCommandData)
{
cmd = ScriptCommandData.func.command;
cmd.deselect = false; // Prevent automatic deselection
var bool1 = ((ScriptCommandData.func.args.got_arg.clearoutput) || (Script.config.clearoutput));
var bool2 = ((ScriptCommandData.func.args.got_arg.debug) | (Script.config.debug) || (ScriptCommandData.func.args.got_arg.test));
var bool3 = (ScriptCommandData.func.qualifiers!="none");
if ((bool1) || (bool2) || (bool3)) {cmd.runcommand("Set UTILITY=OtherLog,On");dbg = true;}
if (bool1) clearoutput = true;
if (clearoutput) DOpus.Clearoutput();
logSecMs(me.desc+" v"+me.version+" starting","do_main",colblue);
log("Command line = "+ScriptCommandData.cmdline,"do_main",colred);
if (ScriptCommandData.func.args.got_arg.clearoutput) log("Debug mode activated by \"clearoutput\" command line option","do_main",colred);
else if (Script.config.clearoutput) log("Debug mode activated by \"clearoutput\" option in Preferences","do_main",colred);
else if (ScriptCommandData.func.args.got_arg.test) log("Debug mode activated by \"test\" command line option","do_main",colred);
else if (ScriptCommandData.func.args.got_arg.debug) log("Debug mode activated by \"debug\" command line option","do_main",colred);
else if (Script.config.debug) log("Debug mode activated by \"debug\" option in Preferences","do_main",colred);
else if (bool3) log("Debug mode activated by \""+ScriptCommandData.func.qualifiers+"\" qualifier key(s)","do_main",colred);
defaultcollname = (ScriptCommandData.func.args.got_arg.collname) ? ScriptCommandData.func.args.collname : Script.config.collname;
collname = defaultcollname.trim();
log("Default target collection = "+collname,"do_main");
defaulthidefilespattern = Script.config.defaulthidefilespattern;
log("Default hide files pattern = "+defaulthidefilespattern,"do_main");
defaulthidefolderspattern = Script.config.defaulthidefolderspattern;
log("Default hide folders pattern = "+defaulthidefolderspattern,"do_main");
defaultregexpattern = Script.config.defaultregexpattern;
log("Default regular expression pattern = "+defaultregexpattern,"do_main");
defaultsimplepattern = Script.config.defaultsimplepattern;
log("Default simple pattern = "+defaultsimplepattern,"do_main");
esc = (ScriptCommandData.func.args.got_arg.esc) ? true : Script.config.esc;
log("Esc hotkey available = "+esc,"do_main");
fastclickms = (ScriptCommandData.func.args.got_arg.fastclickms) ? ScriptCommandData.func.args.fastclickms : Script.config.fastclickms;
log("fastclickms = "+fastclickms,"do_main");
if (ScriptCommandData.func.args.got_arg.both) {
files = true;
folders = true;
}
else if ((ScriptCommandData.func.args.got_arg.files) && (ScriptCommandData.func.args.got_arg.folders)) {
files = true;
folders = true;
}
else if (ScriptCommandData.func.args.got_arg.files) {
files = true;
folders = false;
}
else if (ScriptCommandData.func.args.got_arg.folders) {
files = false;
folders = true;
}
else {
files = Script.config.files;
folders = Script.config.folders;
if (files==folders) {files = true; folders = true;}
}
log("files = "+files,"do_main");
log("folders = "+folders,"do_main");
maxiteration = (ScriptCommandData.func.args.got_arg.maxiteration) ? ScriptCommandData.func.args.maxiteration : 0;
log("maxiteration = "+maxiteration,"do_main");
promptsel = (ScriptCommandData.func.args.got_arg.promptsel) ? true : Script.config.promptsel;
log("promptsel = "+promptsel,"do_main");
qualifiers = (ScriptCommandData.func.args.got_arg.qualifiers) ? true : Script.config.qualifiers;
log("qualifiers = "+qualifiers,"do_main");
log("test = "+ScriptCommandData.func.args.got_arg.test,"do_main");
showcommands = (ScriptCommandData.func.args.got_arg.showcommands) ? true : Script.config.showcommands;
log("showcommands = "+showcommands,"do_main");
timerms = (ScriptCommandData.func.args.got_arg.timerms) ? ScriptCommandData.func.args.timerms : Script.config.timerms;
log("timerms = "+timerms,"do_main");
// Establish a detached dialog
promptdlg = cmd.Dlg();
promptdlg.select = promptsel;
dlg = cmd.Dlg();
if (ScriptCommandData.func.args.got_arg.dlgname) dlgname = ScriptCommandData.func.args.dlgname;
dlg.template = dlgname;
dlg.title = me.desc+" "+me.version; // Title has to be defined before dlg.create
dlg.detach = true;
dlg.loadposition(me.name);
try {dlg.create;}
catch(err) {
log("Detached dialog template \""+dlg.template+"\" not found.");
return;
}
// Detached dialog loop
do {
if (msg_obj==undefined) {processfirsttime(ScriptCommandData); dlg.show(); continue;} // On first entry just switch the first time flag off
msg_obj = dlg.getmsg(); // Otherwise detect what action triggered the detached loop
if (msg_obj.event=="focus") continue; // Ignore focus changes
iteration++; // Keep count of trigger events
var str = "control = "+msg_obj.control;
try {var label = dlg.control(msg_obj.control).label;}
catch(err) {var label = false;}
if (typeof label=="string") str =str+", label = "+dlg.control(msg_obj.control).label;
if ((typeof msg_obj.event=="string") && (msg_obj.event.length>0)) str = str+", event = "+msg_obj.event;
if ((typeof msg_obj.value=="string") && (msg_obj.value.length>0)) str = str+", value = "+msg_obj.value;
log(str,"do_main",colblue);
if ((msg_obj==false) || (label=="Quit") || (msg_obj.control=="escape") || (iteration==maxiteration)) break;
else processdlgaction();
}
while (msg_obj);
dlg.saveposition(me.name);
// All done
logSecMs(me.desc+" v"+me.version+" ending","do_main",colblue);
// --------------------------------------------------------
}
function colladd(str,replace)
{
var target = "\""+str+"\"";
var exists = DOpus.FSUtil.Exists("coll://"+str);
if ((!exists) || (replace)) {
run("@sync:/home\\dopusrt.exe /col create "+target,"colladd");
collscount()
if (!exists) refresh_box("combo1","coll://");
}
for (var i = 0; i < srcTab.selected.count; i++) {
cmdstr = "@sync:/home\\dopusrt.exe /col add "+target+" \""+ srcTab.selected(i)+"\"";
run(cmdstr,"colladd");
}
collcount(str);
}
function collscount()
{
var src = "coll://";
var exists = DOpus.FSUtil.Exists(src);
var n = 0;
if (exists) {
var fe = DOpus.FSUtil.ReadDir(src);
if (fe.error!=0) log("fe.error = "+fe.error,"collscount",colred);
else {
v = fe.Next(-1);
fe.Close();
try {var str = String(v(0))}
catch(err) {}
if (str!=undefined) n = v.count;
}
}
dlg.control("Colls").label = "±Colls ("+n+")";
}
function collcount(str,noretry)
{
var src = "coll://"+str;
var fe, n = 0, retrycount = 5, retrydelay = 50;
var exists = DOpus.FSUtil.Exists(src);
log("src = "+src+", exists = "+(exists),"collcount");
if (exists) {
for (var i = 0; i < retrycount; i++) { // When the collection was just populated with an item from a non local source - e.g. a NAS
fe = DOpus.FSUtil.ReadDir(src); // ReadDir can sometimes fail
if (fe.error==0) break;
else if (noretry) break;
DOpus.Delay(retrydelay);
log("fe.error = "+fe.error+" : src = "+src+", retry count = "+i,"collcount",colred);
}
if (fe.error==0) {
v = fe.Next(-1);
fe.Close();
try {var str = String(v(0))}
catch(err) {}
if (str!=undefined) n = v.count;
}
else if (noretry) n = 0;
else log("fe.error = "+fe.error+" : src = "+src+", count of "+n+" is unreliable","collcount",colred);
}
dlg.control("CollShow").label = "±Coll ("+n+")";
return n;
}
function colldelete(str)
{
var n = collcount(str,true);
var msg = "Really delete \""+str+"\" collection? It contains "+n+" item";
msg = (n==1) ? msg+="." : msg+="s.";
var result = promptdlg.Request(msg,"OK|Cancel","Confirm Deletion");
if (result!=0) {
run("@sync:/home\\dopusrt.exe /col delete \""+str+"\"","colldelete");
collscount();
refresh_box("combo1","coll://");
}
}
function colldup(str)
{
var target = promptdlg.GetString("Duplicate collection name:",DOpus.Create().Date().Format("D#yyyyMMdd_T#HHmmss"),0,"OK|Cancel","Duplicate \""+str+"\" collection?");
if (promptdlg.result!=0) {
run("@sync:/home\\dopusrt.exe /col export /utf8 \""+str+"\" \""+tmpcoll+"\"","colldup");
run("@sync:/home\\dopusrt.exe /col import /clear /create /utf8 "+"\""+target+"\" \""+tmpcoll+"\"","colldup");
collscount(str);
refresh_box("combo1","coll://");
}
}
function collremove(str)
{
var target = "\""+str+"\"";
for (var i = 0; i < srcTab.selected.count; i++) {
cmdstr = "@sync:/home\\dopusrt.exe /col remove "+target+" \""+ srcTab.selected(i)+"\"";
run(cmdstr,"collremove");
}
collcount(str,true);
}
function collrename(str)
{
var target = promptdlg.GetString("New name:",DOpus.Create().Date().Format("D#yyyyMMdd_T#HHmmss"),0,"OK|Cancel","Rename \""+str+"\" collection?");
if (promptdlg.result!=0) {
if (!DOpus.FSUtil.Exists("coll://"+target)) {
run("@sync:/home\\dopusrt.exe /col rename \""+str+"\" \""+target+"\"","collrename");
dlg.control("CollName").value = target;
refresh_box("combo1","coll://");
}
}
}
function collshow(ctl)
{
var b1 = ((ctl=="Colls") & (backfromcolls.exists(srcTab)));
var b2 = ((ctl=="CollShow") & (backfromcoll.exists(srcTab)));
if ((b1) || (b2)) colltogglefrom(ctl);
else colltoggleto(ctl);
}
function colltogglefrom(ctl)
{
var cmdstr, target;
if (backfromcolls.exists(srcTab)) {
target = backfromcolls(srcTab);
backfromcolls.erase(srcTab);
}
else if (backfromcoll.exists(srcTab)) {
target = backfromcoll(srcTab);
backfromcoll.erase(srcTab);
}
if (target!=undefined) {
if (srcTab.backlist.count==undefined) cmdstr = "Go \""+target+"\" NEWTAB=findexisting";
else if (String(srcTab.backlist(0))==String(target)) cmdstr = "Go BACK";
else cmdstr = "Go \""+target+"\" NEWTAB=findexisting";
run(cmdstr,"colltogglefrom");
}
}
function colltoggleto(ctl)
{
var cmdstr, target;
target = (ctl=="Colls") ? "coll://" : "coll://"+dlg.control("CollName").value;
cmdstr = "Go \""+target+"\"";
if (isqualified) cmdstr+=" NEWTAB=findexisting";
run(cmdstr,"colltoggleto");
var newTab = DOpus.listers.lastactive.activetab;
if (ctl=="Colls") backfromcolls(newTab) = srcPathStr;
else backfromcoll(newTab) = srcPathStr;
}
function flagqualified()
{
dlg.control("alll").bg = colqual;
dlg.control("allr").bg = colqual;
dlg.control("nonel").bg = colqual;
dlg.control("noner").bg = colqual;
dlg.control("invertl").bg = colqual;
dlg.control("invertr").bg = colqual;
dlg.control("hsell").bg = colqual;
dlg.control("hselr").bg = colqual;
dlg.control("hunsell").bg = colqual;
dlg.control("hunselr").bg = colqual;
dlg.control("hfiles1l").bg = colqual;
dlg.control("hfiles1r").bg = colqual;
dlg.control("hfolders1l").bg = colqual;
dlg.control("hfolders1r").bg = colqual;
dlg.control("dell").bg = colqual;
dlg.control("delr").bg = colqual;
dlg.control("regexpl").bg = colqual;
dlg.control("regexpr").bg = colqual;
dlg.control("simplel").bg = colqual;
dlg.control("simpler").bg = colqual;
dlg.control("editl").bg = colqual;
dlg.control("editr").bg = colqual;
dlg.control("qual1l").bg = colqual;
dlg.control("qual1r").bg = colqual;
dlg.control("collshow1l").bg = colqual;
dlg.control("collshow1r").bg = colqual;
dlg.control("colls1l").bg = colqual;
dlg.control("colls1r").bg = colqual;
}
function flagtoggles()
{
dlg.control("hfilesl").bg = coltoggle;
dlg.control("hfilesr").bg = coltoggle;
dlg.control("hfoldersl").bg = coltoggle;
dlg.control("hfoldersr").bg = coltoggle;
dlg.control("quall").bg = coltoggle;
dlg.control("qualr").bg = coltoggle;
dlg.control("collshowl").bg = coltoggle;
dlg.control("collshowr").bg = coltoggle;
dlg.control("collsl").bg = coltoggle;
dlg.control("collsr").bg = coltoggle;
}
function log(msg,pfx,colour) {
if (dbg) {
var str = iteration+": ";
if (pfx!=undefined) str = String(str)+"("+pfx+") ";
str = str+msg;
if (colour!=undefined) str = ""+str+"";
DOpus.output(str.trim());
}
}
function logSecMs(msg,pfx,colour)
{
log(String(msg)+" @ "+DOpus.Create().Date().Format("D#yyyy-MM-dd T#MHH:mm:ss","M"),pfx,colour);
}
function processanchor()
{
var str;
if (srcTab!=undefined) {
str = (isspecial) ? srcTab.Path+" aka \""+srcTab.displayed_label+"\"" : srcTab.Path;
if (String(srcTab)==String(DOpus.listers.lastactive.activetab)) { // No change
log("Continue watching tab ("+srcTab+") "+str,"processanchor");
return;
}
try {dlg.watchtab(srcTab,"stop");log("Stop watching tab ("+srcTab+") "+str,"processanchor");}
catch(err) {log("dlg.watchtab("+srcTab+",stop) failed. err.number = "+err.number,"processanchor",colred);}
}
srcTab = DOpus.listers.lastactive.activetab;
srcPathStr = String(srcTab.path);
isspecial = (srcPathStr.slice(0,2)=="::");
str = (isspecial) ? srcTab.Path+" aka \""+srcTab.displayed_label+"\"" : srcTab.Path;
dlg.control("Cmd").label = "Left click a named filter to add to or replace; right click to remove.";
dlg.control("Path").label = (isspecial) ? srcTab.displayed_label : srcTab.Path;
var iscoll = (srcPathStr.slice(0,7).toLowerCase()=="coll://");
dlg.control("Path").fg = (iscoll) ? colwhite : colblue;
dlg.control("Path").bg = (iscoll) ? colyellow : colblack;
dlg.control("All").enabled = (!isspecial);
dlg.control("None").enabled = (!isspecial);
dlg.control("Invert").enabled = (!isspecial);
dlg.control("HideSelected").enabled = (!isspecial);
dlg.control("HideUnselected").enabled = (!isspecial);
dlg.control("Show").enabled = (!isspecial);
dlg.control("HideFiles").enabled = (!isspecial);
dlg.control("HideFolders").enabled = (!isspecial);
dlg.control("Delete").enabled = (!isspecial);
dlg.control("Regexp").enabled = (!isspecial);
dlg.control("Simple").enabled = (!isspecial);
dlg.control("Advanced").enabled = (!isspecial);
dlg.control("CollAdd").enabled = (!isspecial);
dlg.control("CollRepl").enabled = (!isspecial);
dlg.control("CollRemove").enabled = (!isspecial);
log("Start watching tab ("+srcTab+") "+str,"processanchor");
dlg.watchtab(srcTab,"select,navigate,add,delete,activate,srcdst,filter");
cmd.SetSourceTab(srcTab);
}
function processclick(ctl)
{
var label = dlg.control(ctl).label.trim();
if ((label=="Files") || (label=="Folders") || (label=="Both")) {showqualified(); return;}
if (withintolerance(label)) {
var coll = dlg.control("CollName").value;
if (ctl=="All") runselect("ALL",ctl);
else if (ctl=="None") runselect("NONE",ctl);
else if (ctl=="Invert") runselect("INVERT",ctl);
else if ((ctl=="HideSelected") || (ctl=="HideUnselected")) runhide(label,ctl);
else if (ctl=="Show") showall(ctl);
else if ((ctl=="HideFiles") || (ctl=="HideFolders")) togglehide(label,ctl);
else if (ctl=="Delete") rundelete(ctl);
else if (ctl=="Qualifiers") {qualifiers = (!qualifiers); showqualified();}
else if (ctl=="Prefs") run("Prefs PAGE=scripts:"+me.name+".js",ctl);
else if (ctl=="Test") test();
else if ((ctl=="Regexp") || (ctl=="Simple")) runselectprompt(label,ctl);
else if (ctl=="Advanced") run("Select ADVANCED",ctl);
else if (ctl=="Edit") {
if (isqualified) run("Prefs Page=FILTERS",ctl);
else run("Select ADVANCED=\""+fltr+"\"",ctl);
refresh_box("listbox1","/dopusdata\\filters");
}
else if ((ctl=="CollShow") || (ctl=="Colls")) collshow(ctl);
else if (ctl=="CollAdd") colladd(coll);
else if (ctl=="CollRepl") colladd(coll,true);
else if (ctl=="CollRemove") collremove(coll);
else if (ctl=="CollRename") collrename(coll);
else if (ctl=="CollDelete") colldelete(coll);
else if (ctl=="CollDup") colldup(coll);
}
tsexit(label) = new Date().getTime();
}
function processdlgaction()
{
isqualified = ((qualifiers) && (msg_obj.qualifiers!="none"));
if (msg_obj.control=="test") test();
else if (msg_obj.event=="click") processclick(msg_obj.control);
else if (msg_obj.event=="editchange") processeditchange();
else if (msg_obj.event=="rclick") processrclick();
else if (msg_obj.event=="selchange") processselchange(msg_obj.control);
else if (msg_obj.event=="tab") processtab(msg_obj.value);
else if (msg_obj.event=="timer") processlclick();
srcTab.Update();
}
function processeditchange()
{
var newcollname = dlg.control("CollName").value.trim();
if (newcollname!=collname) {
if (newcollname=="") {
newcollname = defaultcollname;
dlg.control("CollName").value = defaultcollname;
}
collname = newcollname;
collscount();
collcount(collname,true);
var n = dlg.control("combo1").GetItemByName(collname);
if (n!=undefined) dlg.control("combo1").SelectItem(n);
else refresh_box("combo1","coll://");
}
}
function processfirsttime(ScriptCommandData)
{
msg_obj = true;
if (esc) dlg.AddHotKey("escape","escape"); // Enable the use of the ESC key to quit dialog
if (ScriptCommandData.func.args.got_arg.test) dlg.AddHotKey("test","ctrl+alt+t");
if (files==folders) {if (!dlg.control("Both").value) dlg.control("Both").value = true;}
else if ((files) && (!dlg.control("Files").value)) dlg.control("Files").value = true;
else if ((folders) && (!dlg.control("Folders").value)) dlg.control("Folders").value = true;
flagtoggles();
flagqualified();
showqualified();
processanchor();
refresh_box("listbox1","/dopusdata\\filters");
refresh_box("combo1","coll://");
dlg.control("CollName").value = "";
}
function processlclick()
{
log(timername+" expired, fltr = "+fltr,"processlclick");
dlg.KillTimer(timername);
timername = "";
if (isspecial) return;
var str = "\""+fltr+"\" FILTER";
var b1 = ((isqualified) && (dlg.control("Add").value));
var b2 = ((!isqualified) && (dlg.control("Replace").value));
if ((b1) || (b2)) str = str+" DESELECTNOMATCH";
if (dlg.control("Files").value) str+=" TYPE=files";
else if (dlg.control("Folders").value) str+=" TYPE=dirs";
run("Select "+str,"processlclick");
}
function processrclick()
{
dlg.KillTimer(timername);
timername = "";
if (isspecial) return;
var str = "\""+fltr+"\" FILTER FILTERFLAGS=deselect";
if (dlg.control("Files").value) str+=" TYPE=files";
else if (dlg.control("Folders").value) str+=" TYPE=dirs";
run("Select "+str,"processrclick");
}
function processselchange(ctl)
{
if (ctl=="listbox1") {
fltr = msg_obj.value;
timername = dlg.SetTimer(timerms);
log(timername+" set for "+timerms+" milliseconds, fltr = "+fltr,ctl);
}
else if (ctl=="combo1") dlg.control("CollName").value = msg_obj.value;
}
function processtab(value)
{
if (value=="activate") processanchor();
else if (value=="srcdst") processanchor();
else if (value=="select") srcTab.Update();
else if (value=="navigate") srcTab.Update();
else if (value=="add") srcTab.Update();
else if (value=="delete") srcTab.Update();
}
function refresh_box(boxname,source)
{
var next, needsrefresh = true, src = DOpus.FSUtil.readdir(source);
candidates.clear();
while (!src.complete){
next = src.next;
candidates.push_back(next.name_stem);
}
if (candidates.count==dlg.control(boxname).count) {
for (var i = 0; i < candidates.count; i++) {
needsrefresh = (dlg.control(boxname).GetItemAt(i).name!=candidates(i));
if (needsrefresh) break;
}
}
if (needsrefresh) {
dlg.control(boxname).removeItem(-1);
for (var i = 0; i < candidates.count; i++) dlg.control(boxname).additem(candidates(i));
}
}
function run(str,caller)
{
if (caller==undefined) log(str);
else log(str,caller);
if (showcommands) dlg.control("Cmd").label = str;
cmd.runcommand(str);
}
function rundelete(caller)
{
if (dlg.control("Files").value) candidates = (isqualified) ? srcTab.selected_dirs : srcTab.selected_files;
else if (dlg.control("Folders").value) candidates = (isqualified) ? srcTab.selected_files : srcTab.selected_dirs;
else candidates = srcTab.selected;
if (candidates.count==0) {log("Nothing selected; request ignored.",caller); return;}
cmd.Clear();
cmd.AddLine("Delete");
cmd.ClearFailed();
cmd.ClearFiles();
cmd.AddFiles(candidates);
cmd.Run();
}
function runhide(str,caller)
{
var sfx = "";
if (dlg.control("Files").value) sfx = (isqualified) ? "=dirs" : "=files";
else if (dlg.control("Folders").value) sfx = (isqualified) ? "=files" : "=dirs";
var cmdstr = "Select NOPATTERN HIDE";
var cmdstr = (str=="Hide Selected") ? cmdstr+="SEL" : cmdstr+="UNSEL";
run(cmdstr+sfx);
}
function runselect(str,caller)
{
var sfx = "";
if (dlg.control("Files").value) sfx = (isqualified) ? "dirs" : "files";
else if (dlg.control("Folders").value) sfx = (isqualified) ? "files" : "dirs";
if (sfx!="") sfx = " TYPE="+sfx;
run("Select "+str+sfx);
}
function runselectprompt(str,caller)
{
var title = "Select ? using a ! expression";
if (dlg.control("Both").value) title = title.replace("?","FILES and FOLDERS");
else if (dlg.control("Files").value) title = (isqualified) ? title.replace("?","FOLDERS") : title.replace("?","FILES");
else title = (isqualified) ? title.replace("?","FILES") : title.replace("?","FOLDERS");
title = (str=="Regexp") ? title.replace("!","regular") : title.replace("!","simple");
if (str=="Regexp") var promptstr = (regexpattern.exists(srcTab)) ? regexpattern(srcTab) : defaultregexpattern;
else var promptstr = (simplepattern.exists(srcTab)) ? simplepattern(srcTab) : defaultsimplepattern;
var pattern = promptdlg.GetString(title,promptstr,0,"Add|Replace|Remove|Cancel","String to Match?");
if (promptdlg.result==0) return;
if (typeof pattern!="string") pattern = (str=="Regexp") ? ".*" : "*";
else if (str=="Regexp") regexpattern(srcTab) = pattern;
else simplepattern(srcTab) = pattern;
if (str=="Regexp") pattern+=" REGEXP";
if (promptdlg.result==2) pattern+=" DESELECTNOMATCH";
else if (promptdlg.result==3) pattern+=" DESELECT";
runselect(pattern,caller);
}
function showall(caller)
{
run("Set CLEARFILTERS",caller);
srcTab.Update();
var n = srcTab.hidden_dirs.count+srcTab.hidden_files.count;
if (n>0) {run("Select NOPATTERN SHOWHIDDEN",caller); srcTab.Update(); n = srcTab.hidden_dirs.count+srcTab.hidden_files.count;}
if (n>0) run("Set QUICKFILTERCLEAR",caller);
}
function showqualified()
{
var both = (dlg.control("Both").value);
var show = ((qualifiers) && (!both));
log("qualifiers = "+qualifiers+", both = "+both+", show = "+show,"showqualified");
dlg.control("alll").visible = (show);
dlg.control("allr").visible = (show);
dlg.control("nonel").visible = (show);
dlg.control("noner").visible = (show);
dlg.control("invertl").visible = (show);
dlg.control("invertr").visible = (show);
dlg.control("hsell").visible = (show);
dlg.control("hselr").visible = (show);
dlg.control("hunsell").visible = (show);
dlg.control("hunselr").visible = (show);
dlg.control("hfiles1l").visible = (qualifiers);
dlg.control("hfiles1r").visible = (qualifiers);
dlg.control("hfolders1l").visible = (qualifiers);
dlg.control("hfolders1r").visible = (qualifiers);
dlg.control("dell").visible = (show);
dlg.control("delr").visible = (show);
dlg.control("regexpl").visible = (show);
dlg.control("regexpr").visible = (show);
dlg.control("simplel").visible = (show);
dlg.control("simpler").visible = (show);
dlg.control("editl").visible = (show);
dlg.control("editr").visible = (show);
dlg.control("qual1l").visible = (qualifiers);
dlg.control("qual1r").visible = (qualifiers);
dlg.control("collshow1l").visible = (qualifiers);
dlg.control("collshow1r").visible = (qualifiers);
dlg.control("colls1l").visible = (qualifiers);
dlg.control("colls1r").visible = (qualifiers);
}
function test()
{
dbg = true;
showcommands = true;
log("Just Testing",msg_obj.control,colred);
}
function togglehide(str,caller)
{
var scope = str.split(" ");
var key = String(srcTab);
if ((scope[1]=="Folders") && (cmd.isset("FLATVIEW=On"))) {
var defaultflatview = "Mixed";
var previousstate = (hideflatfolders.Exists(key)) ? hideflatfolders(key) : defaultflatview;
if (cmd.isset("FLATVIEW=On,MixedNoFolders")) run("Set FLATVIEW=On,"+previousstate,caller);
else {
hideflatfolders(key) = (cmd.isset("FLATVIEW=On,Grouped")) ? "Grouped" : "Mixed";
run("Set FLATVIEW=On,MixedNoFolders",caller);
}
}
else {
var pattern = "*";
if (cmd.isset("FLATVIEW=On")) hideflatfolders(key) = (cmd.isset("FLATVIEW=On,Grouped")) ? "Grouped" : "Mixed";
else hideflatfolders.erase(key);
if (isqualified) {
if (scope[1]=="Files") pattern = (hidefilespattern.exists(srcTab)) ? hidefilespattern(srcTab) : defaulthidefilespattern;
else pattern = (hidefolderspattern.exists(srcTab)) ? hidefolderspattern(srcTab) : defaulthidefolderspattern;
pattern = promptdlg.GetString("Hide "+scope[1],pattern,0,"OK|Cancel","Hide Filter Pattern?");
if (promptdlg.result==0) return;
if (typeof pattern!="string") pattern = "*";
else if (scope[1]=="Files") hidefilespattern(srcTab) = pattern;
else hidefolderspattern(srcTab) = pattern;
}
if (scope[1]=="Files") run("Set HIDEFILTERFILENAME "+pattern,caller);
else run("Set HIDEFILTERFOLDERS "+pattern,caller);
}
}
function withintolerance(item,ms)
{
var result, n = (ms==undefined) ? fastclickms : ms;
if (tsexit.Exists(item)) {
var elapsed = new Date().getTime() - tsexit(item);
}
else elapsed = n + 1;
result = (elapsed>n); // true = more than n milliseconds have elapsed
if (!result) log(item+": "+elapsed+" milliseconds elapsed : tolerance = "+n+" : result = "+result,"withintolerance");
return result;
}
==SCRIPT RESOURCES