Added Tab.highlighted property

Continuing the discussion from Directory Opus 13.4.5 (Beta):

Highlighted means FAYT text highlighted or mouse selected?

ps: Sorry for the format of this post, I was in the process of directly replying in the beta-release thread, but that's not possible anymore? I liked it! o)

https://docs.dopus.com/doku.php?id=basic_concepts:selecting_files

Ok, after trying out, it's really the items for which any data is highlighted in the columns ("cells" being the keyword here I need to remember). At first I was expecting the new highlighted property would contain the items being highlighted with the FAYT "text match". The term "highlight/ed" is quite often used in the docs / prefs by now, sorry.

This v13 new menu here is very nice! o)
image
I think an option is missing, an option to copy content of highlighted cells in padded / formatted form. Just like the "Print folder to clipboard" does. Is there a way to get the column IDs for columns containing highlighted cells? Then we could write our own script I guess (not sure if data of scripted columns are accessible by now from a script?) or is there another way to get formatted column data into clipboard (from the highlighted cells menu)?

EDIT: Like this:
image

Thanks! o)

image

var cmd = DOpus.Create.Command();
var lst = DOpus.Listers.lastactive;
cmd.SetSourceTab(lst.activetab);
var	srcTab = lst.activetab;
DOpus.Output("srcTab.highlighted.count: " + srcTab.highlighted.count); // 4

The Item.highlighted property gives you that (along with the text in the column itself).

Phew, ok! I made it!
How do you do this in C++?! It is complicated in JScript already! o))

Thank you! o)

If anyone is interested, here are some function to..

  • get column data from all the highlighted cells / columns (including the gaps).
  • transform column data from highlighted cells into formatted / padded shape
  • print to console or copy to clipboard
Name          *  Files  Size     Modified             Rating  MD5 Checksum                    
P1740482.JPG            2,56 MB  2023_06_11 13:39:41  **      cf39a9bef97ae296a3c7d51fe9a8cd80
P1740482.RW2            18,8 MB                               536961ba4978a485a87a0b8b134994e1
P1740483.JPG            2,41 MB                               d61d13bdb1caaa3ea876d1760e4d528a
P1740483.RW2            18,8 MB  2023_06_11 13:40:03  *****   dde27b68c912e019c0dd9c3b19495550

//##############################################################################
//Added Tab.highlighted property
//https://resource.dopus.com/t/added-tab-highlighted-property/50112/4
//##############################################################################

var result			= getHighlightedCellValues( srcTab );
var formattedText	= formatCellValues( result.columns, result.data );
var lineCount		= doPrintArray( formattedText );

//##############################################################################
// functions
//##############################################################################
function getHighlightedCellValues( srcTab ) { 
	//create map of columns by column ID, add column index of tab
	var mapTabColumnsByID = {};
	var tabColumns = srcTab.format.columns;
	for(var i=0;i<tabColumns.count;i++) {
		var doColumn = tabColumns[i];
		var columnID = doColumn.name; // .name == id
		//DOpus.Output("col.name: " + doColumn.label);
		mapTabColumnsByID[columnID] = {
				id: columnID,
				indexInTab: i,
				indexInHighlight: null,
				charCount: (""+doColumn.header).length,
				doColumn: doColumn
		};
	}
	
	//iterate over each item and their highlighted columns to determine
	//what columns of the tab are actually used
	var tabColumnIndexesUsed = [];
	for(var i=0;i<srcTab.highlighted.count;i++) {
		var itemWithHighlightedCell = srcTab.highlighted[i];
		for(var c=0;c<itemWithHighlightedCell.highlighted.count;c++) {
			var columnHighlight = itemWithHighlightedCell.highlighted[c];
			var columnTab = mapTabColumnsByID[columnHighlight.column]; // .column == id
			if (typeof tabColumnIndexesUsed[columnTab.indexInTab] === "undefined")
				tabColumnIndexesUsed[ columnTab.indexInTab ] = columnTab;
		}
	}
	
	//add highlighted column index to each used column
	for(var c=0;c<tabColumnIndexesUsed.length;c++) {
		var column = tabColumnIndexesUsed[c];
		if (!column) continue;
		column.indexInHighlight = c;
	}
	
	var highlightColumnsUsed = [];
	for(var c=0;c<tabColumnIndexesUsed.length;c++) {
		//skip the gaps in highlighted columns
		if (!tabColumnIndexesUsed[c]) continue;
		highlightColumnsUsed.push(tabColumnIndexesUsed[c]);
	}
	
	//prepare empty array with
	//[total number of items with highlighted cells] and
	//[total number of columns with highlighted cells]
	var columnData = new Array(srcTab.highlighted.count);
	for (var i=0;i<columnData.length;i++) {
	  columnData[i] = new Array(tabColumnIndexesUsed.length);
	}
	
	//iterate over all items with highlighted cells
	for(var i=0;i<srcTab.highlighted.count;i++) {
		var highlightedItem = srcTab.highlighted[i];
	
		//set "" default for item and all affected columns
		for(var c=0;c<tabColumnIndexesUsed.length;c++) {
			columnData[i][c] = "";
		}
	
		//iterate over highlighted columns of item
		for(var c=0;c<highlightedItem.highlighted.count;c++) {
			var highlightedColumn = highlightedItem.highlighted[c];
			//determine index of highlighted column in data set
			var colID = highlightedColumn.column; //.column == id
			var tabCol = mapTabColumnsByID[colID];
			var colIndex = tabCol.indexInHighlight;
			var value = highlightedColumn.value;
			columnData[i][colIndex] = value;
			tabCol.charCount = Math.max( (value+"").length, tabCol.charCount );
		}
	}
	return { columns: highlightColumnsUsed, data: columnData };
} 
//##############################################################################
function formatCellValues( highlightColumnsUsed, columnData ) {
	function padLeft( s, len) {
		while (s.length < len) s = " "+s; return s;
	}
	function padRight( s, len) {
		while (s.length < len) s = s+" "; return s;
	}
	
	var textOutput = [];
	var columnSeparator = "  ";
	
	//create header line
	var header = "";
	for(var c=0;c<columnData[0].length;c++) {
		var column = highlightColumnsUsed[c];
		if (c!=0 && (c<columnData[0].length)) header += columnSeparator;
		header += padRight(column.doColumn.header, column.charCount);
	}
	textOutput.push(header);
	
	//create item lines
	for(var i=0;i<columnData.length;i++) {
		var line = "";
		for(var c=0;c<columnData[0].length;c++) {
			var column = highlightColumnsUsed[c];
			var itemData = columnData[i][c];
			if (c!=0 && (c<columnData[0].length)) line += columnSeparator;
			line += padRight(itemData, column.charCount);
		}
		textOutput.push(line);
	}
	return textOutput;
}

//##############################################################################
function doPrintArray( textArray ) {
	for(var t=0;t<textArray.length;t++) {
		DOpus.Output(textArray[t]);
	}
	return textArray.length;
}

//##############################################################################
// eof
//##############################################################################

@tbone thanks. I added this line above:
var srcTab = DOpus.Listers.lastactive.activetab;

to be able to test your code, but it throws an error on this line:
header += padRight(column.doColumn.header, column.charCount);

('doColumn' is null or not an object)
Since it seems that column is an empty object sometimes.

(I wanted to test if with this I'm able to get values when in a library, since it seems that there item.highlighted.count is always 0 there)

But you get expected results in a regular folder?

With your code, no, it doesn't go beyond that line.

With a more simple version, yes, except in libraries, that's why I want to try with yours.
I guess item.highlighted doesn't work in libraries, no matter how you use it, or can you confirm the opposite?

Please try this in a regular folder with highlighted cells and in a library with highlighted cells.
If only the regular folder prints item names and the columns with highlights, there might be something to look into for Jon. I don't use libraries for specific reasons, I can't test.. o)

var lst = DOpus.Listers.lastactive;
var	srcTab = lst.activetab;

for(var i=0;i<srcTab.highlighted.count;i++) {
	var itemWithHighlightedCell = srcTab.highlighted[i];
	DOpus.Output("Highlighted cell(s) on item: " + itemWithHighlightedCell.name );
	for(var c=0;c<itemWithHighlightedCell.highlighted.count;c++) {
		var highlight = itemWithHighlightedCell.highlighted[c];
		DOpus.Output("    Highlighted column: " + highlight.column );
	}
}

Thanks. That was bascially the same I was using, and yes, it does work in regular folders and collections, but not in libraries.

So this is a bug report then I guess? o)