Skip to content

Commit

Permalink
feat: ✨ add option to open project in new window if reviewing when st…
Browse files Browse the repository at this point in the history
…alled
  • Loading branch information
ksalzke committed May 31, 2024
1 parent 23238fc commit b48ff18
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions CustomComplete.omnifocusjs/Resources/customCompleteLib.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,13 @@
return selectNextNodePref
}

customCompleteLib.onComplete = async (task) => {
customCompleteLib.openInNewWindowPref = () => {
const preferences = customCompleteLib.loadSyncedPrefs()
const openInNewWindowPref = preferences.read('openInNewWindowPref') || false
return openInNewWindowPref
}

customCompleteLib.onComplete = async (task) => {
const lib = customCompleteLib
await lib.selectNextNode(task)
const completedTask = task.markComplete()
Expand All @@ -46,7 +51,6 @@
lib.removeDueSoonTag(completedTask)
await lib.checkWorkOnTask(task)
await lib.promptIfStalled(task)

}

customCompleteLib.selectNextNode = async (task) => {
Expand Down Expand Up @@ -138,6 +142,7 @@

switch (form.values.action) {
case 'Yes':
if (customCompleteLib.openInNewWindowPref()) await document.newWindow()
const urlStr = 'omnifocus:///task/' + task.parent.id.primaryKey
URL.fromString(urlStr).open()
break
Expand Down
3 changes: 3 additions & 0 deletions CustomComplete.omnifocusjs/Resources/preferences.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,19 @@
// get current preferences or set defaults if they don't yet exist
const tagsToRemove = this.customCompleteLib.tagsToRemove()
const selectNextNode = this.customCompleteLib.selectNextNodePref()
const openInNewWindow = this.customCompleteLib.openInNewWindowPref()

// create and show form
const form = new Form()
form.addField(new Form.Field.Checkbox('selectNextNode', 'Select next task when completing', selectNextNode))
form.addField(new Form.Field.Checkbox('openInNewWindow', 'Open in new window', openInNewWindow))
form.addField(new Form.Field.MultipleOptions('tagsToRemove', 'Tag(s) to remove when a task is completed', flattenedTags, flattenedTags.map(t => t.name), tagsToRemove))
await form.show('Preferences: Custom Complete', 'OK')

// save preferences
syncedPrefs.write('selectNextNode', form.values.selectNextNode)
syncedPrefs.write('tagsToRemoveIDs', form.values.tagsToRemove.map(tag => tag.id.primaryKey))
syncedPrefs.write('openInNewWindowPref', form.values.openInNewWindow)
})

action.validate = function (selection, sender) {
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ This action runs the `onComplete` function on one selected task or project, usin

This action allows you to:
* select whether the next task in a perspective should automatically be selected when 'custom complete' is run (this will only apply when there is a single task selected)
* select whether the project will be shown in a new window, when the last task in a project or action group is completed and the user chooses to 'review' the project
* configure one or more tags that should be removed from tasks after they have been completed.

# Functions
Expand All @@ -53,6 +54,10 @@ Returns an array of tags to be removed from tasks when they are completed, as co

Returns 'true' or 'false' depending on whether the 'select next task' option is checked in the preferences.

## `openInNewWindowPref () : Boolean`

Returns 'true' or 'false' depending on whether the 'open in new window' option is checked in the preferences.

## `unschedule (task: Task)`

If the task is a repeating task, removes any 'absolute' notifications (i.e. those that are not set relative to the defer or due date)
Expand Down

0 comments on commit b48ff18

Please sign in to comment.