Skip to content

Commit

Permalink
Add fallback search triggers for imported dictionaries
Browse files Browse the repository at this point in the history
  • Loading branch information
mr-pennyworth committed Feb 23, 2024
1 parent e15eab2 commit 1a2a057
Show file tree
Hide file tree
Showing 3 changed files with 68 additions and 2 deletions.
41 changes: 39 additions & 2 deletions info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,19 @@
<string>Tools</string>
<key>connections</key>
<dict>
<key>144E72F0-97B5-44B6-BFB2-163409B9019B</key>
<array>
<dict>
<key>destinationuid</key>
<string>CE509E43-D9A7-4B99-AFA6-6FEEB4D26442</string>
<key>modifiers</key>
<integer>0</integer>
<key>modifiersubtext</key>
<string></string>
<key>vitoclose</key>
<false/>
</dict>
</array>
<key>18D17FBB-4E03-4E94-9802-19E31E8C516C</key>
<array>
<dict>
Expand Down Expand Up @@ -189,6 +202,19 @@
<string>Better Dictionaries</string>
<key>objects</key>
<array>
<dict>
<key>config</key>
<dict>
<key>text</key>
<string>dummy</string>
</dict>
<key>type</key>
<string>alfred.workflow.trigger.fallback</string>
<key>uid</key>
<string>144E72F0-97B5-44B6-BFB2-163409B9019B</string>
<key>version</key>
<integer>1</integer>
</dict>
<dict>
<key>config</key>
<dict>
Expand Down Expand Up @@ -787,6 +813,17 @@ Subsequent searches should be snappy
<key>ypos</key>
<real>195</real>
</dict>
<key>144E72F0-97B5-44B6-BFB2-163409B9019B</key>
<dict>
<key>colorindex</key>
<integer>9</integer>
<key>note</key>
<string>dummy fallback search</string>
<key>xpos</key>
<real>810</real>
<key>ypos</key>
<real>15</real>
</dict>
<key>18D17FBB-4E03-4E94-9802-19E31E8C516C</key>
<dict>
<key>xpos</key>
Expand Down Expand Up @@ -901,7 +938,7 @@ Subsequent searches should be snappy
<key>note</key>
<string>dummy script filter</string>
<key>xpos</key>
<real>840</real>
<real>970</real>
<key>ypos</key>
<real>15</real>
</dict>
Expand Down Expand Up @@ -938,7 +975,7 @@ Subsequent searches should be snappy
<key>variablesdontexport</key>
<array/>
<key>version</key>
<string>0.2.6</string>
<string>0.2.7</string>
<key>webaddress</key>
<string>https://github.com/mr-pennyworth/alfred-better-dictionaries</string>
</dict>
Expand Down
9 changes: 9 additions & 0 deletions pyapp/BetterDict.py
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,10 @@ def create_workflow_objects(dict_name, dict_id):
# Functional:
junction = wf.newJunction()
hotkey = wf.newHotkey(note=dict_name)
fallback_search = wf.newFallbackSearch(
note=dict_name,
title=f'search {dict_name}',
)
script_filter = wf.newBashScriptFilter(
note=dict_name,
title=f'search {dict_name}',
Expand All @@ -270,6 +274,7 @@ def create_workflow_objects(dict_name, dict_id):
ipa_player = wf.getObjWithLabel('Play pronunciation audio')
html_opener = wf.getObjWithLabel('Open definition in browser')
wf.connect(src=hotkey, dst=script_filter)
wf.connect(src=fallback_search, dst=script_filter)
wf.connect(src=junction, dst=script_filter)
wf.connect(src=script_filter, dst=ipa_player, mod=wf.CMD)
wf.connect(src=script_filter, dst=html_opener)
Expand All @@ -278,6 +283,7 @@ def create_workflow_objects(dict_name, dict_id):
# Presentational:
dummy_junction = wf.getObjWithLabel('dummy junction')
dummy_hotkey = wf.getObjWithLabel('dummy hotkey')
dummy_fallback_search = wf.getObjWithLabel('dummy fallback search')
dummy_script_filter = wf.getObjWithLabel('dummy script filter')

row_count = wf.getOutputCount(router)
Expand All @@ -288,6 +294,9 @@ def create_workflow_objects(dict_name, dict_id):
wf.setX(hotkey, wf.x(dummy_hotkey))
wf.setY(hotkey, wf.y(dummy_hotkey) + VERT_OFFSET)

wf.setX(fallback_search, wf.x(dummy_fallback_search))
wf.setY(fallback_search, wf.y(dummy_fallback_search) + VERT_OFFSET)

wf.setX(script_filter, wf.x(dummy_script_filter))
wf.setY(script_filter, wf.y(dummy_script_filter) + VERT_OFFSET)

Expand Down
20 changes: 20 additions & 0 deletions pyapp/WorkflowGraph.py
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,26 @@ def newHotkey(self, note):
self.wf['connections'][hotkey_uuid] = []
return hotkey

def newFallbackSearch(self, note, title):
fallback_search_uuid = mkuid()
fallback_search = {
'type': 'alfred.workflow.trigger.fallback',
'uid': fallback_search_uuid,
'version': 1,
'config': {
'text': title,
},
}
self.wf['objects'].append(fallback_search)
self.wf['uidata'][fallback_search_uuid] = {
'note': note,
'noexport': 1,
'xpos': 0,
'ypos': 0,
}
self.wf['connections'][fallback_search_uuid] = []
return fallback_search

def newBashScriptFilter(self, title, script, note):
script_filter_uuid = mkuid()
script_filter = {
Expand Down

0 comments on commit 1a2a057

Please sign in to comment.