Requires 12.3 or above.
Here's a small script add-in that will add any labels (in the "Tabs" category) from parent folders to the tab text.
Examples:
-
The
C:\Temp
folder has a label of "Hello":C:\\Temp\\Abc\\Def
would show "Hello\Def"C:\Temp\Abc\Def\Pqr
would show "Hello\Pqr" -
The
C:\Users\Fred\Documents
folder has a label of "Docs", and its subdirectoryVisual Studio 2015
has a label of "VS":C:\Users\Fred\Documents\Visual Studio 2015\Projects\MyTestApp
would show "Docs\VS\MyTestApp". -
You have Label Assignments set to give any folder where Name matches
*Dropbox*
a label of '#':D:\odrive\Dropbox (Home)\MyFiles\SomeFolder\Photos
would show "Dropbox (Home)\Photos".D:\odrive\Dropbox (Work)\Business\Purchases\Invoices
would show "Dropbox (Work)\Invoices".
Note the use of the special label '#', which uses the folder name as-is instead of the label name, and is perfect for Label Assignments.
Only labels in the "Tabs" category will be added to the start of your tab labels!
Please let me know what you think, and any suggestions for the code, as it's my first addin
Download:
- PrefixTabsWithLabels.js.txt (2.8 KB)
- Drag the downloaded file to Preferences / Toolbars / Scripts to install it.
Script code:
(This is the same as the download above.)
// Called by Directory Opus to initialize the script
function OnInit(initData)
{
initData.name = "PrefixTabsWithLabels";
initData.version = "1.1";
initData.copyright = "(c) 2016 Tenebrous";
initData.url = "https://resource.dopus.com/viewtopic.php?f=35&t=28208";
initData.desc = "Enhance tab names by including labels set against parent folders.";
initData.default_enable = true;
initData.min_version = "12.2.6";
}
// Called when a tab is activated
function OnActivateTab( activateTabData )
{
Update( activateTabData["new"] );
}
// Called when the source and destination are changed
function OnSourceDestChange(sourceDestChangeData)
{
if( sourceDestChangeData.source )
Update( sourceDestChangeData.tab );
}
// Called after a new folder is read in a tab
function OnAfterFolderChange( afterFolderChangeData )
{
if ( !afterFolderChangeData.result )
return;
Update( afterFolderChangeData.tab );
}
function Update( tab )
{
try
{
PerformUpdate( tab );
}
catch( e )
{
}
}
function PerformUpdate( tab )
{
var path = tab.Path;
var tabLabel = DOpus.FSUtil.GetItem(path).name;
path.Parent();
// DOpus.Output( "Colors for " + path );
// var item = DOpus.FSUtil.GetItem(path);
// for( var label = new Enumerator(item.Labels("Colors")); !label.atEnd(); label.moveNext() )
// {
// DOpus.Output( " " + label.item() );
// }
// DOpus.Output( "Status for " + path );
// var item = DOpus.FSUtil.GetItem(path);
// for( var label = new Enumerator(item.Labels("Status")); !label.atEnd(); label.moveNext() )
// {
// DOpus.Output( " " + label.item() );
// }
// DOpus.Output( "Tabs for " + path );
// var item = DOpus.FSUtil.GetItem(path);
// for( var label = new Enumerator(item.Labels("Tabs")); !label.atEnd(); label.moveNext() )
// {
// DOpus.Output( " " + label.item() );
// }
do
{
var item = DOpus.FSUtil.GetItem(path);
for( var label = new Enumerator(item.Labels("Tabs")); !label.atEnd(); label.moveNext() )
{
var labelText = label.item();
if( labelText == '#' )
tabLabel = item.name + '\\' + tabLabel;
else
tabLabel = label.item() + '\\' + tabLabel;
}
}
while( path.Parent );
SetTabLabel( tab, tabLabel );
}
function SetTabLabel( tab, label )
{
if (label == undefined || !label)
label = "";
var rawCommmand = 'GO TABNAME' + (label != '' ? '="' + label + '"' : '' );
raw( rawCommmand, tab );
}
function raw(rwCommmand, tab)
{
var dopusCommand = DOpus.NewCommand;
if (tab != undefined)
dopusCommand.SetSourceTab(tab);
dopusCommand.RunCommand(rwCommmand);
}