Add button to select interface?

I have an action that offers a select interface (app.selectDraft) with a list of existing drafts in a workspace and then inserts a link to the selected draft at the cursor position.

I wonder if it is possible to add an additional button to the select promt. In case that the item I wanted to add is missing in the list, a “add new item” button would be helpful. But it seems to me that the draft selection interface is not customizable, right?

1 Like

You could create a prompt and present the recent drafts or whatever in the prompt as a simple button :slight_smile:

Thanks, that’s a good idea! In my case, however, the list would become very long and finding the right item would be too difficult.

Another solution that came into my mind is to use the cancel button. I.e. when the action is triggered, the select interface shows, allowing to select an existing draft. If there is no draft in the list, I cancel the select interface what brings up another prompt allowing to create a new draft, then links it and opens it.

That is not a modifiable UI element, correct. As you mention, you could check for if the user does not select a draft (cancels) - alternately, you could create a have a “special” draft in the workspace with just a known title, like “Create New Draft” and check if that draft is selected as a key to create the new one.

2 Likes

should work, great yes.
just check against the return value of app.selectDraft()
if it’s undefined create a new one :slight_smile:

1 Like

I scripted it and it works beautifully. I just put a prompt into the else statement:

let d = app.selectDraft(workspace);
if(d) {
	// selection and
    // do stuff with selection
}
else { // if cancelled
    // show promt and do further stuff
    }

Thanks for your help, this is such a great community!

2 Likes

I revised the whole thing and now I stuck again. I created a promt with some buttons created from the content of a existing draft and a textField. It looks like this:

The last button („zur VKN“) takes the textField entry.

My question: How can I change the order of the buttons? In the script I create the buttons with numbers first, then the textField, then the „zur VKN“ button. Anyway, it is displayed as shown. Can I somehow change that? As it is now, it is not very clear that the last button belongs to the textField…

Then, is it possible to display further text in the prompt window, like between the buttons?

Thank you!

Buttons are always grouped as the last elements in a prompt. Probably the best option for visual separation is to make it the default button, which will pin it with the cancel button, and make it the button that responds to the default (⌘-return) keyboard shortcut. Like:

p.addButton("zur VKN", null, true)

1 Like

If you find the standard prompt options too limiting, you always have the option of builing an HTML-based prompt using the Advanced HTML Previews functionality.

It takes more effort than the standard prompt, but you can lay things out however you want.

There’s an example action in the documentation above that you could use as your starting point.

Hope that helps.

2 Likes