Show number of children tasks when parent task/project collapsed


#1

Is there a way to display the number of children tasks a parent task/project has when it is collapsed?

thanks


#2

This is what I came up with:

function TaskPaperContextScript(editor, options) {
var selection = editor.selection.selectedItems.filter(function(x) {
	return x.getAttribute('data-type') === 'project';
});
for(var i in selection) {
	editor.outline.groupUndoAndChanges(function() {
		var item = selection[i];
		var idx = item.bodyString.search(/ \[.+\/.+\]:/);
		if (idx > -1) {
			item.bodyString = item.bodyString.substring(0, idx) + ':';
		}
		else {
			if (item.hasChildren) {
				var done = item.children.filter(function(x) {
					return x.hasAttribute('data-done');
				});
				item.bodyString = item.bodyString.substring(0, item.bodyString.length-1) + " [" + done.length + "/" + item.children.length + "]:";
				//item.appendBody(" [" + done.length + "/" + item.children.length + "]");
			}
		}
	});	
}
}

Application("TaskPaper").documents[0].evaluate({
  script: TaskPaperContextScript.toString()
});

There is a side effect of this code which is quite annoying though: cursor is moved to the next line.


#3

Not really. With a script (as you’ve nicely done) you can insert the answer into your document content. But that’s a big problematic as a general solution, because you likely don’t really want that data saved in your document. Longer term TaskPaper might get the ability to display decorations in the next big release (4) (similar to what FoldingText does) attached to items in your outline. With that in place you could make a pretty nice script to do what you want, but until then the route you’ve taken is best.


#4

Any ideas why the cursor moves to the next line with the code above? (by now this is driving me nuts already :slight_smile:)


#5

… and the solution is:

editor.moveSelectionToItems(startSelection);