Column: Flat folder level v1.3

Adds a custom common that displays the folder depth while in Flat View.

This was requested by AlbatorV here:

How to use:

  • Download LevelColumn.js.txt (1.1 KB)
  • Drag the downloaded file to the list under Preferences / Toolbars / Scripts.

You will then find the Level column in Folder Options, in the Script category. (You can also right-click the column header, then choose Columns > Scripts > Level.)

Requires DOpus 11.5.1 or later

Script Code:

The contents of the .js.txt file above are reproduced below, for reference:

// The OnInit function is called by Directory Opus to initialize the script add-in
function OnInit(initData) {
  // Provide basic information about the script by initializing the properties of the ScriptInitData object
  initData.name = "Flat View Level Column";
  initData.desc = "Adds column that shows folder depth level for flat view";
  initData.copyright = "2014 wowbagger";
  initData.min_version = "11.5.1"
  initData.version = "1.3";
  initData.default_enable = true;

  var cmd = initData.AddColumn();
  cmd.name = "FlatViewLevel"
  cmd.method = "OnFlatViewLevel";
  cmd.type = "number";
  cmd.label = "Level";
  cmd.autogroup = true;       
  cmd.justify = "left";
}
 
// Implement the OnFlatViewLevel column (this entry point is an OnScriptColumn event).
function OnFlatViewLevel(scriptColData) {
    var itemPath = scriptColData.item.realpath;
    // Remove Tab path from item path
    var diff = itemPath.pathpart.replace(scriptColData.tab.path, "");
    // Count number of folder
    var count = diff.split("\\");
    // Disaply value
    scriptColData.value = count.length -1;
}

It's probably not a good idea to keep copying the sample "Is Modified" column verbatim, since that has some stuff in it that is really only specific to that column.

E.g. in Advanced Find, it sets the match list to either "Yes" or "No" but for this column it would make more sense to treat it as a number (set the type to "number") which would allow searching for all level 5 files, for example.

Also the "autorefresh" flag for makes no sense for this column since the file changing doesn't change what level it's stored in.

Anyway it's just an observation :slight_smile: You can use the New Script helper to create an empty template script that adds columns without all the "baggage" of the example.

ah yer, script updated as recommended. Thanks for feedback

Many thanks for this...
But I have a problem, I copy script, enable it in Prefs, but I can not add 'Level' column. There is no "Script" column category in folder option.

Have you installed Opus 11.5.1 (beta)? You'll need that for script columns.

Yes of course...
If I add script "TheMovieDB Poster&Info Downloader V2.0", I can add their columns, but not this one...

Interesting, This script uses min_version = "11.5.1" to prevent it from loading on earlier version, but that should not impact you.
Can you see the script named Flat View Level Column in the config?
Is it enabled?
Are there any errors in the logs?

Change line 21:

function OnFlatViewLevelColumn(scriptColData) {

to this:

function OnFlatViewLevel(scriptColData) {

:thumbsup:
Thanks

Thanks Kundal, sorry about that AlbatorV. A post code cleanup bug, I will update the original post.