Shortcut to Fold/Unfold all items in a document (TP3)


#1

I am sure I must have overlooked this. But I searched high and low. Does it exist?


#2

It is not there, but I remember reading somewhere that it was in the roadmap ( Is that true @jessegrosjean?) If you are good at applescript, I believe you might be able to get it done with it (Sorry, I am cannot figure it out myself). There are a couple of Script masters here. @complexpoint might be able to help if you ask very nicely :slight_smile:


#3

Thanks @Victor. My abilities with AppleScript are quite limited, but I am not a complete beginner. Time is more of an issue. Perhaps I’ll just wait for @jessegrosjean to get around to it, if it is in the roadmap.


#4

You can do this, I think, with ⌘A ⌘.
or, more directly, with ⌘ ⌥ . Fold Items Completely

(Both toggle between full expansion and full fold)

See under Help > Search > Fold

Does that match what you are after ?


#5

Hi Thanks @complexpoint. What I am looking for is a way to toggle unfolding/enfolding all the projects on a page at once, so I see only the projects with their dots. This command only seems to do unfold/enfold the selected project?.


#6

Note you can do this by doing Select All and then toggling folding.


#7

Now why didn’t I think of that?
[Hangs head in shame.]
Thanks Jesse.


#8

Various approaches come to mind:

  1. Preface the fold shortcut with ⌘A to select everything
  2. Use a saved search like //@type=project to get a project headers only view
  3. Use something like Keyboard Maestro to bundle the ⌘A and ⌘. into a single keystroke

(One could of course write a brief script, but perhaps that might be overkill)

Option 2 may be good if you use subprojects (lines ending in a colon which are nested under other projects)

As in:

@search(//@type=project)

#9

Thanks @complexpoint. That search works great. The disadvantage of that being I have to create that list item in all of my different documents. OK that’s no big deal. I should stop whinging and be happy. The more I use TaskPaper the more I like it!


#10

create a list item in all of my different documents

Something like a TextExpander or Keyboard Maestro shortcut ?


#11

Yeah I guess. Or maybe @jessegrosjean could be persuaded to include a ‘Collapse all projects in document’ menu item/shortcut? :smiley: I mean, it looks pretty!


#12

I’m not sure. One one hand it’s of course easy to add. On the other hand if I add all the different expand/collapse enumerations that are possible that view menu starts getting really big. At the moment I just can’t decide and so I’m leaving them out until I’m sure I want them in.


#13

Of course it would not make sense to list all the different enumerations in the View menu (or should it be in the Items menu?), but my argument in favour of adding “Collapse All” would be: It is so neat and satisfying to see just a list of all your project items. Suddenly your tasks don’t look so complex! :smiley:


#14

I understand thought i’m still not sure. In the meantime I think this script will do what you want:

var TaskPaper = Application('TaskPaper')

function TPContext(editor, options) {
  var projects = editor.outline.evaluateItemPath('//@type=project');
  var anyCollapsed = false;
  
  projects.forEach(function (each) {
    if (editor.isCollapsed(each)) {
      anyCollapsed = true;
    }
  });
  
  if (anyCollapsed) {
    editor.setExpanded(projects);
  } else {
    editor.setCollapsed(projects);
  }
}

TaskPaper.documents[0].evaluate({
  script: TPContext.toString()
});

#15

You could also see it, I guess, as the question of how to easily make sure that all your working documents contain a particular custom set of saved searches, including something like:

Projects @search(//@type=project)

Cut and paste is probably not a bad approach, but if you wanted, you could also keep the list in a script which took over:

  • Wrapping the paths in @search( ... ) and checking for \) escapes
  • Checking which searches a document already has, and only adding the missing ones.

Maybe something roughly along these lines :

// MAKE SURE THE THE CURRENT TASKPAPER 3 DOCUMENT
// CONTAINS ALL THE ELEMENTS YOUR USUAL MENU
// OF SAVED SEARCHES

(function () {
    
    var dctMenu = {
        'Project list': '//@type=project',
        'Inbox': '//Inbox',
        'Soon': '//@due <=[d] next week +14d',
        'Overdue':'//@due <[d] now'
    }


    function fn(editor, options) {

        var outline = editor.outline,
            root = outline.root,
            strText = outline.toString(),
            dctSearch = options.menu;
            
            // Any search menu items not found in this document ?
            lstMissing = Object.keys(dctSearch).filter(function (k) {
                return strText.indexOf(dctSearch[k]) === -1;
            })
            .map(function (k) {
                return k + ' @search(' + dctSearch[k].replace(/\)/g,
                    '\\)') + ')';
            })
            .sort();

        // Add any missing searches to this document's search menu
        if (lstMissing.length > 0) {
            outline.groupUndoAndChanges(function () {
                root.insertChildrenBefore(
                    ItemSerializer.deserializeItems(
                        lstMissing.join('\n'),
                        outline,
                        ItemSerializer.TEXTMimeType
                    ),
                    root.firstChild
                )
            })
        }
    }

    var ds = Application("TaskPaper")
        .documents;

    return ds.length ? ds[0].evaluate({
        script: fn.toString(),
        withOptions: {
            menu: dctMenu
        }
    }) : undefined;
    
})()

#16

that works perfectly. thanks @jessegrosjean!


#17

Thanks @complexpoint. Scripting genius!! I can see this could easily be tweaked to be useful for a range of different scenarios.


#18

Hard to tell exactly when the Rube Goldberg / Heath Robinson line has been crossed, but it would also be possible to save the saved searches of one document, (e.g. as a small JSON file) and load them into another, or choose a selection of them from a menu.

But perhaps this is what cut and paste is for : - )


#19

I need to know where that line is - and fast. :neutral_face:


#20

A TextExpander solution works well here, I think – two or three chars which are instantly replaced by a group of your preferred searches, when you start a new TaskPaper 3 document, or want to add searches to an existing one.