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)
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)
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:
Thanks! o)
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
//##############################################################################
//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
//##############################################################################
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 );
}
}