/////////////////////////////////////////////////////////////////////////////// // Tab-Labelizer /////////////////////////////////////////////////////////////////////////////// function OnInit(data) { var uid = "c2fdd0fd-9af6-4134-a0ab-2b2eec8203cc"; var url = "http://resource.dopus.com/viewtopic.php?f=35&t=21890"; data.name = "Tab-Labelizer"; data.desc = "Extend the folder names shown in your tabs with additional path-information."; data.copyright = "tbone, wowbagger"; data.version = "1.5.0"; data.default_enable = true; data.min_version = "11.7" data.config_desc = DOpus.NewMap(); data.config.DEBUG = false; data.config_desc("DEBUG") = "Set DEBUG flag below to true in order to enable logging messages to the Opus Output Window"; data.config.EnableTabUpdate = true; data.config_desc("EnableTabUpdate") = "Set the tab label with the shortened path"; data.config.EnableWindowTitleUpdate = true; data.config_desc("EnableWindowTitleUpdate") = "Set the lister title with the shortened path"; data.config.EnableVieweritleUpdate = true; data.config_desc("EnableVieweritleUpdate") = "Set the standalone viewer title with the shortened path"; data.config.ResolvePaths = true; data.config_desc("ResolvePaths") = "Resolve library names"; data.config.EmptyTabLabel= "Empty Tab"; data.config_desc("EmptyTabLabel") = "Label for empty tabs"; data.config.ExtendedConfig = JSON.stringify(defaultExtendedConfig, undefined, 2).replace(/(\n)+/g,"\r\n"); data.config_desc("ExtendedConfig") = "Extended configuration"; } /////////////////////////////////////////////////////////////////////////////// var defaultExtendedConfig = { /////////////////////////////////////////////////////////////////////////////// /*replace location or sub-paths */ replaceLocations: { /*global switch to en/disable location replacing */ enabled: true, /*pairs of find, replace strings */ locations: [ //shorten common ip addresses in unc location "^\\\\\\\\192.168.0.", "\\\\.", "^\\\\\\\\10.56.142.", "\\\\.", "^\\\\\\\\10.0.0.", "\\\\.", //relabel c: and d: drive roots "^C:\\\\$", "sys:\\\\", "^D:\\\\$", "data:\\\\", //remove credentials from ftp location "^ftp://(.*)@", "ftp://", //shorten common ip addresses in ftp location "//10.0.0.", "//." ] }, /*Show ftp://10.0.0.1 as sitename : */ frendlyFtpHostName: true, /*show root/location - options */ showLocations: { /*show locations */ enabled: true, /*show local drives/letters */ showLetters: true, /*show drive label instead of drive letter */ showDriveLabel: false, /*show unc paths */ showUNC: true }, /*add parent foldername to label - options */ addParentFolder: { /*show parent folder in label */ enabled: true, /*0 or show only if length is less then */ maxLength: 30, /*always cut parent folder name */ cutParent: true, /*0 or how many chars to keep from parent foldername */ cutToLength: 6, /*prefix for cut parent folders */ cutPrefix: ".." } } /////////////////////////////////////////////////////////////////////////////// function OnAfterFolderChange(data) { if (!data.result) //folder not read successfully return; UpdateLister(data.tab); } function OnSourceDestChange(SourceDestData) { if(SourceDestData.source) { UpdateLister(SourceDestData.tab); } } function OnActivateTab(ActivateTabData) { UpdateLister(ActivateTabData["new"]); } function OnViewerEvent(viewerEventData) { if(viewerEventData.event == "load") { UpdateViewer(viewerEventData.viewer); } } function UpdateLister(tab) { out("path original : " + tab.path); var label = GetTabLabelByPath(new String(tab.path), JSON.parse(Script.config.ExtendedConfig)); out("label final : " + label + " - length=" + label.length); //Set Tab label to new shortened path if(Script.config.EnableTabUpdate) { SetTabLabel(label, tab); } else { //Clear if disabled SetTabLabel("", tab); } //Set window title to new shortened path if(Script.config.EnableWindowTitleUpdate) { SetListerTitle(label, tab); } else { //Clear if disabled SetListerTitle("", tab); } } function UpdateViewer(viewer) { out("path original : " + viewer.current); out("title original : " + viewer.title); var label = GetTabLabelByPath(new String(viewer.current.path), JSON.parse(Script.config.ExtendedConfig)); label = label + "\\" + viewer.current.name; out("label final : " + label + " - length=" + label.length); //Set window title to new shortened path if(Script.config.EnableVieweritleUpdate) { SetViewerTitle(label, viewer); } else { //Clear if disabled SetViewerTitle("", viewer); } } /////////////////////////////////////////////////////////////////////////////// function GetTabLabelByPath(path, config) { var pathO = path; var label = ""; out(" GetTabLabelByPath : " + path); if (path=="") return Script.config["EmptyTabLabel"]; //empty tab //this is a class id or virtual windows folder if ((config == undefined) || path.substring(0, 2) == "::") return ""; var fsu = DOpus.fsutil(); out(" DisplayName : " + fsu.DisplayName(new String(path))); out(" DisplayName e: " + fsu.DisplayName(path, "e")); out(" DisplayName f: " + fsu.DisplayName(path, "f")); out(" DisplayName r: " + fsu.DisplayName(path, "r")); out(" Resolved : " + fsu.Resolve(path)); if (Script.config.resolvePaths) { path = new String(fsu.Resolve(path)); } out(" path type : " + Object.prototype.toString.call(path)); //get path info object var pathInfo = GetPathInfo(path); var pathNoLocation = path; //remove locations from path if show locations is disabled if (!config.showLocations.enabled) config.showLocations.showLetters = config.showLocations.showUNC = false; if (pathInfo.isLocalDrive && !config.showLocations.showLetters && pathInfo.root) path = path.replace(new RegExp('^' + pathInfo.root + '\\\\'), ""); if (pathInfo.isUNC && !config.showLocations.showUNC) path = path.replace(new RegExp('^\\\\' + pathInfo.hostname + '\\\\'), ""); if (path == "") { out("Path is empty after updates returning") return ""; } var sep = (pathInfo.isFTP || pathInfo.isLib) ? "/" : "\\"; //add, cut and prefix parent folder if enabled label = pathInfo.folder; if (config.addParentFolder.enabled && pathInfo.parentFolder) { if (config.addParentFolder.maxLength > 0 && (pathInfo.folder + pathInfo.parentFolder).length < config.addParentFolder.maxLength) { label = ""; var parentFolderPart = pathInfo.parentFolder; if (config.addParentFolder.cutToLength > 0 && (parentFolderPart > config.addParentFolder.cutToLength)) parentFolderPart = pathInfo.parentFolder.substring(pathInfo.parentFolder.length - config.addParentFolder.cutToLength); if (config.addParentFolder.cutPrefix && parentFolderPart != pathInfo.parentFolder) label = config.addParentFolder.cutPrefix; label = label + parentFolderPart + sep + pathInfo.folder; } } /////////////////////////////////////////////////////////////////////////// if (pathInfo.isLocalDrive) { if(config.showLocations.showDriveLabel) { //Repalce drive letter with drive label fs = new ActiveXObject("Scripting.FileSystemObject"); d = fs.GetDrive(pathInfo.fullPath.substring(0, 2)); pathInfo.fullPath = pathInfo.fullPath.replace(new RegExp("^(.*(?=:))"), d.VolumeName); pathInfo.fullPathLower = pathInfo.fullPathLower.replace(new RegExp("^(.*(?=:))"), d.VolumeName); pathInfo.root = pathInfo.root.replace(new RegExp("^(.*(?=:))"), d.VolumeName); } if (pathInfo.folderIsRoot) label = pathInfo.fullPath; else if (pathInfo.parentIsRoot) label = pathInfo.fullPath; else if (pathInfo.root + "\\" + label != pathInfo.fullPath) label = pathInfo.root + "\\..\\" + label; else label = pathInfo.root + "\\" + label; } /////////////////////////////////////////////////////////////////////////// if (pathInfo.isUNC) { if (pathInfo.folderIsHost) label = pathInfo.fullPath; else if (pathInfo.folderIsRoot) label = pathInfo.fullPath; else if (pathInfo.parentIsRoot) label = pathInfo.hostname + "\\" + label; else if ((pathInfo.hostname + "\\" + pathInfo.root + "\\" + label != pathInfo.fullPath)) label = pathInfo.hostname + "\\" + pathInfo.root + "\\..\\" + label; else label = pathInfo.hostname + "\\" + pathInfo.root + "\\" + label; } /////////////////////////////////////////////////////////////////////////// if (pathInfo.isFTP) { var hostSeperator = "//"; if(config.frendlyFtpHostName) { var siteName = path.replace(new RegExp("^ftp://SITE=(.*)\\?.*@.*//.*"), "$1"); if(siteName != "") { siteName = decodeURI(siteName); pathInfo.fullPath = pathInfo.fullPath.replace(new RegExp("^ftp://(.*(?=//))"), siteName); pathInfo.fullPathLower = pathInfo.fullPathLower.replace(new RegExp("^ftp://(.*(?=//))"), siteName); pathInfo.hostname = pathInfo.hostname.replace(new RegExp("^ftp://(.*)"), siteName); } hostSeperator = ": "; } if (pathInfo.folderIsHost) label = pathInfo.hostname; else if (pathInfo.folderIsRoot) label = pathInfo.hostname + hostSeperator + pathInfo.root else if (pathInfo.parentIsRoot || pathInfo.parentIsHost) label = pathInfo.hostname + hostSeperator + label; else if ((pathInfo.hostname + "//" + pathInfo.root + "/" + label != pathInfo.fullPath)) label = pathInfo.hostname + hostSeperator + pathInfo.root + "/../" + label; else label = pathInfo.hostname + hostSeperator + pathInfo.root + "/" + label; } if (pathInfo.isLib) { if (pathInfo.folderIsHost) label = ""; else if (pathInfo.folderIsRoot) label = ""; else if (pathInfo.parentIsRoot) label = label; else if ((pathInfo.hostname + pathInfo.root + "/" + label != pathInfo.fullPath)) label = pathInfo.root + "/../" + label; else label = pathInfo.root + "/" + label; } //replace locations if enabled if (config.replaceLocations.enabled) for (var i = 0; i < config.replaceLocations.locations.length; i = i + 2) { label = label.replace(new RegExp(config.replaceLocations.locations[i]), config.replaceLocations.locations[i + 1]); } return label; } /////////////////////////////////////////////////////////////////////////////// function GetPathInfo(path) { out("GetPathInfo :" + path) var fsu = DOpus.fsutil(); _fullPath = fsu.DisplayName(path); var isUNC = (_fullPath.substring(0, 2) == "\\\\"); var isFTP = (_fullPath.substring(0, 6) == "ftp://"); var isLib = (_fullPath.substring(0, 6) == "lib://"); var isLocalDrive = (_fullPath.substring(2, 1) == ":"); var folderIsHost = false; var parentIsHost = false; var folderIsRoot = false; var parentIsRoot = false; var root = ""; var folder = ""; var parentFolder = ""; var hostname = _fullPath; if (isUNC || isLocalDrive) { var doubleSep = "\\\\"; var sep = "\\"; var lastParts = GetPathLastFolder(_fullPath, 1); var parentParts = GetPathLastFolder(lastParts.parentPath, 1); if (isUNC) { var sepShare = _fullPath.substring(4).indexOf(sep); if (sepShare > -1) { //share found var sepAfterShare = _fullPath.substring(sepShare + 5).indexOf(sep); var rootEnd = _fullPath.length; if (sepAfterShare > -1) //folder(s) after share rootEnd = sepShare + sepAfterShare + 5; root = _fullPath.substring(sepShare + 5, rootEnd); hostname = _fullPath.substring(0, _fullPath.substring(4).indexOf(sep) + 4); } parentIsHost = (doubleSep + parentParts.folder == hostname); if (parentIsHost) { parentParts.folder = doubleSep + parentParts.folder; folderIsRoot = true; } folderIsHost = doubleSep + lastParts.folder == hostname; } if (isLocalDrive) { root = _fullPath.substring(0, _fullPath.substring(2).indexOf(sep) + 2); folderIsRoot = (lastParts.folder == root); } parentFolder = parentParts.folder; parentIsRoot = (root == parentParts.folder); folder = lastParts.folder; } if (isFTP) { var doubleSep = "//"; var sep = "/"; var protocal = _fullPath.substring(0, _fullPath.indexOf(doubleSep) + doubleSep.length); // ftp:// hostname = _fullPath.substring(0, _fullPath.indexOf(doubleSep, protocal.length)); // ftp://10.0.0.1 folderIsHost = _fullPath == hostname + doubleSep; if (folderIsHost) { folder = hostname; parentFolder = ""; } else { rootEnd = _fullPath.indexOf(sep, hostname.length + doubleSep.length); if (rootEnd == -1) { rootEnd = _fullPath.length; folderIsRoot = true; } root = _fullPath.substring(hostname.length + doubleSep.length, rootEnd); rootFullPath = hostname + doubleSep + root; //folderIsRoot = (_fullPath == rootFullPath); if (folderIsRoot) { folder = root; parentIsHost = true; parentFolder = hostname; } else { folder = _fullPath.substring(_fullPath.lastIndexOf(sep) + sep.length, _fullPath.length); parentIsRoot = (_fullPath == rootFullPath + sep + folder); if (parentIsRoot) { parentFolder = root; } else { parentFolderFullPath = _fullPath.substring(0, _fullPath.lastIndexOf(sep)); parentFolder = parentFolderFullPath.substring(parentFolderFullPath.lastIndexOf(sep) + sep.length, parentFolderFullPath.length); } } } } if (isLib) { var doubleSep = "//"; var sep = "/"; var hostname = _fullPath.substring(0, _fullPath.indexOf(doubleSep) + doubleSep.length); // lib:// folderIsHost = _fullPath == hostname; if (folderIsHost) { folder = ""; parentFolder = ""; } else { rootEnd = _fullPath.indexOf(sep, hostname.length); if (rootEnd == -1) { rootEnd = _fullPath.length; folderIsRoot = true; } root = _fullPath.substring(hostname.length, rootEnd); // documents rootFullPath = hostname + root; if (folderIsRoot) { folder = root; parentIsHost = true; parentFolder = hostname; } else { folder = _fullPath.substring(_fullPath.lastIndexOf(sep) + sep.length, _fullPath.length); parentIsRoot = (_fullPath == rootFullPath + sep + folder); if (parentIsRoot) { parentFolder = root; } else { parentFolderFullPath = _fullPath.substring(0, _fullPath.lastIndexOf(sep)); parentFolder = parentFolderFullPath.substring(parentFolderFullPath.lastIndexOf(sep) + sep.length, parentFolderFullPath.length); } } } } out(" fullPath" + (isLocalDrive ? " isLocalDrive" : "") + (isUNC ? " isUNC" : "") + (isFTP ? " isFTP" : "") + (isLib ? " isLib" : "") + ": " + _fullPath); out(" hostname: " + hostname); out(" root: " + root); out(" folder" + (folderIsHost ? " IsHost" : "") + (folderIsRoot ? " IsRoot" : "") + ": " + folder); out(" parentFolder" + (parentIsHost ? " IsHost" : "") + (parentIsRoot ? " IsRoot" : "") + ": " + parentFolder); var result = { fullPath: _fullPath, fullPathLower: _fullPath.toLowerCase(), folder: folder, folderLower: folder.toLowerCase(), folderIsRoot: folderIsRoot, folderIsHost: folderIsHost, parentFolder: parentFolder, parentFolderLower: parentFolder.toLowerCase(), parentIsHost: parentIsHost, parentIsRoot: parentIsRoot, isUNC: isUNC, isFTP: isFTP, isLib: isLib, hostname: hostname, root: root, isLocalDrive: isLocalDrive }; out(" pathInfo : " + JSON.stringify(result, undefined, 2).replace(/(\n)+/g,"\r\n")); return result; } /////////////////////////////////////////////////////////////////////////////// function GetPathLastFolder(path) { path = path.replace(/(^(\s|\/|\\)+)|((\s|\/|\\)+$)/g, ""); var lastIndex = path.lastIndexOf('\\'); if (lastIndex == -1 || (lastIndex + 1) == path.length) return { folder: path, parentPath: "" }; return { folder: path.substring(lastIndex + 1), parentPath: path.substring(0, lastIndex) }; } /////////////////////////////////////////////////////////////////////////////// function out(text) { if (Script.config.DEBUG) DOpus.Output(text); } /////////////////////////////////////////////////////////////////////////////// function SetTabLabel(label, tab) { if (label == undefined || !label) label = ""; var rawCommmand = 'GO TABNAME'+(label!=''?'="'+label+'"':''); raw(rawCommmand, tab); } function SetListerTitle(title, tab){ if (title==undefined || !title) title=""; tab.lister.update(); if(tab.lister.custom_title != title) { var cmd = 'Set LISTERTITLE'+(title!=''?' "notoggle:'+title+'"':''); raw(cmd, tab); } } function SetViewerTitle(title, viewer){ if (title==undefined || !title) title=""; viewer.title = title; } /////////////////////////////////////////////////////////////////////////////// function raw(rwCommmand, tab) { var dopusCommand = DOpus.NewCommand; if (tab != undefined) { dopusCommand.SetSourceTab(tab); } dopusCommand.RunCommand(rwCommmand); } /////////////////////////////////////////////////////////////////////////////// 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 = "2a54161c4f92115b6b7d3ede0f2ea299"; DATE = "2015.04.20 - 19:21:04"