Drafts: Action Sets

Drafts has a hugely powerful area known as action. Actions are made available through action entries in the action list that can be displayed down one side of the user interface. Actions can also be displayed via an action bar, effectively a toolbar of actions, and can of course be triggered by shortcuts. Yesterday I described an option I referred to as slash commands that could be used to trigger actions, and today I’m going to show how you can in effect overload one action to give you a choice of several.

The Principle

The principle is actually very simple in that when selecting an action, I present a menu-like action to provide a list of actions to choose from. I find this particularly useful for the action bar on i*OS devices. For example if I wanted to have a button to set a Markdown heading level, and I had pre-built actions to set each level, rather than having separate buttons, I could have one button that displays a prompt allowing you to choose from the set. It’s like a poor cousin to a context menu.

Because I felt like short descriptors might be better in such a listing than necessarily having full action names, I decided to use JSON to describe these menu-like options. Each key value would be what is shown to the user, and the value would be the name of the action triggered by selecting it. These are action sets.

Function

The Thought Asylum Drafts Library (TADpoLe) contains an app function called TA_actionSelectAndRun(). This function takes a single parameter and this is the name of the action set to look up in the JSON.

For this function, the JSON is held within the library settings file (held in the Drafts Library/Scripts/ folder as tad.json by default). It is held under the key actions, with each set of options being another key value pair within that.

By default the library sets up a single list that provides two actions. The JSON that describes these looks like this.

"actions" : 
{
  "info" : 
  {
    "Display System & App Settings" : "TAD-Display Drafts and System Information",
    "Display Library Settings" : "TAD-Display Settings"
  }
}

The set is referenced by the name info and consists of two options to display some information.

To create your own lists it is just a case of adding them into the library. If you don’t happen to see the actions key in your JSON, don’t worry. It simply may not have been saved out and the library will be using its own internal defaults. You can just add it in yourself. in fact copying and pasting in the JSON above might make it a bit easier; just don’t forget to add a comma at the start or end if necessary to add it as an additional item an existing JSON file.

Calling this set is therefore pretty simple. With the library loaded, simply make a call like this.

app.TA_actionSelectAndRun('info');

Example Action

In the ThoughtAsylum Action Group, there is an action called TA-Action Set (Info). This action does exactly what is described in the previous section.

when run it displays a list of two action options from the info action set.

When one of the actions is selected, it is queued up in Drafts to run as soon as the current action completes, which is pretty much exactly at that point.

Once you have added your own action sets, the quickest way to set one up is probably to duplicate this action to your own action group, rename it and modify the action set name/function parameter.

Summary

As I noted above, I find this mostly of use on my smaller screen devices from the action bar above the keyboard. In the main, the native action list, keyboard row and keyboard shortcuts serve my needs. The action sets functionality just allows me to cram that extra bit of action choice into smaller spaces.

I’d love to be able to long press and get real context menus to provide a native equivalent of this, but until then, this serves my needs for button overloading.

Author: Stephen Millard
Tags: | drafts | tadpole |

Buy me a coffeeBuy me a coffee



Related posts that you may also like to read