Busy indicator include file for script columns

Having the possibility to implement custom script columns is a great thing. But sometimes processing all items in a folder can take a lot of time (i have folders containing ~90k files). To know how far the process has come, I created a script template that implements the busy indicator to show the progress in the path display. It needs very few changes to your code and doesn't need modifications of the actual column handlers.

Fully working column script (without include) Column.BusyIndicatorImplementation.js.txt (3.4 KB)

2025-12-26T00:00:00Z
Originally I thought it was not possible to move the code to an include file but I was wrong. So you only need to include the class file to put the UserColumns dictionary in your code plus all the OnAddColumns and OnColumnBusyIndicator functions in your script addin.

inc_ColumnBusyIndicator.opusscriptinstall (1.5 KB)

So now it is enough to have this code in your script

@include inc_ColumnBusyIndicator.js


//This is your column handler, no need to change anything here
function OnYourScriptColumnFunction(scriptColData)
{
	var item = scriptColData.item;
	if (item.is_dir)
		scriptColData.value = "Directory";
	else
		scriptColData.value = "File";
}


//Put yor columns here
//Key must match Column name
var UserColumns =
{
	//			    Column(name, label, header, multicol, justify, userdata, columnHandler)
	ColumnName: new Column("ColumnName", "ColumnLabel", "ColumnHeader", false, "left", 0, OnYourScriptColumnFunction)
};

// This is the default Dopus call to add columns to Opus
function OnAddColumns(addColData)
{
	for(var key in UserColumns)
		UserColumns[key].AddColumn(addColData);
}

//This is called for all colums first and does its magic before calling your column handler
function OnColumnBusyIndicator(scriptColData)
{
	UserColumns[scriptColData.col].Intercept(scriptColData);
}

Complete Code for one script file (without include)
//This is your column handler, no need to change anything here
function OnYourScriptColumnFunction(scriptColData)
{
	var item = scriptColData.item;
	if (item.is_dir)
		scriptColData.value = "Directory";
	else
		scriptColData.value = "File";
}


//Put yor columns here
//Key must match Column name
var UserColumns =
{
	//			    Column(name, label, header, multicol, justify, userdata, columnHandler)
	ColumnName: new Column("ColumnName", "ColumnLabel", "ColumnHeader", false, "left", 0, OnYourScriptColumnFunction)
};

// This is the default Dopus call to add columns to Opus
function OnAddColumns(addColData)
{
	for(var key in UserColumns)
		UserColumns[key].AddColumn(addColData);
}

//This is called for all colums first and does its magic before calling your column handler
function OnColumnBusyIndicator(scriptColData)
{
	UserColumns[scriptColData.col].Intercept(scriptColData);
}


//class representing a custom column
function Column(name, label, header, multicol, justify, userdata, columnHandler)
{
	this.Name			= name;
	this.Label			= label || name;
	this.Header 		= header || name;
	this.MultiCol		= multicol || false;
	this.Justify		= justify;
	this.UserData		= userdata;
	this.ColumnCallback	= columnHandler;

	this.HasRunOnce 	= false;
	this.Indicator 		= null;
	this.ItemsInFolder	= 0;
	this.CurrentItemCount = 0;

	this.AddColumn = function(addColData)
	{
		var col = addColData.AddColumn();
		col.name = this.Name;
		col.header = this.Header;
		col.label = this.Label;
		col.autogroup = this.Autogroup || true;
		col.multicol = this.Multicol || false;
		col.justify = this.Justify;
		col.userdata = this.UserData;
		col.method = "OnColumnBusyIndicator";//Same for all to intercept all columns
	};

	//Intercept a column call, update indicator, redirect to user column handler
	this.Intercept = function(scriptColData)
	{
		if(!this.HasRunOnce)
		{
			var tab = scriptColData.tab;
			tab.Update();

			this.ItemsInFolder = tab.stats.items;
			this.Indicator = DOpus.Create.BusyIndicator();
			this.Indicator.Init(tab, "");
			this.Indicator.Show();

			this.HasRunOnce = true;
		}

		//calculate progress and update indicator
		var percent = (this.CurrentItemCount * 100) / this.ItemsInFolder;
		var strPercent = " (" + String(percent.toFixed(2)) + "%)";
		var info = this.CurrentItemCount + 1 + "/" + this.ItemsInFolder + strPercent + " " + scriptColData.item.name;
		this.Indicator.Update(info, percent);

		if(this.CurrentItemCount == this.ItemsInFolder)
		{
			//reset everything in case we need to restart
			this.Indicator.Hide();
			this.Indicator.Destroy();
			this.HasRunOnce = false;
			this.CurrentItemCount = 0;
		}
		else
		{
			//Call actual column handler
			this.ColumnCallback(scriptColData);
			this.CurrentItemCount++;
		}
	};
}
4 Likes

Moved code to an include file (for DOpus 13+).