Skip to content

Commit

Permalink
Unify go back and go forward implementations (talonhub#1490)
Browse files Browse the repository at this point in the history
This implements standardized go back and go forward voice commands as
well as matching actions to be used in applications system wide

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
AndreasArvidsson and pre-commit-ci[bot] authored Jul 9, 2024
1 parent 2c18a5f commit 9498ffc
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 36 deletions.
6 changes: 0 additions & 6 deletions apps/finder/finder.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,6 @@ class UserActions:
def file_manager_open_parent():
actions.key("cmd-up")

def file_manager_go_forward():
actions.key("cmd-]")

def file_manager_go_back():
actions.key("cmd-[")

def file_manager_current_path():
title = ui.active_window().title

Expand Down
7 changes: 4 additions & 3 deletions apps/nautilus/nautilus.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,14 @@ class UserActions:
def tab_jump(number: int):
actions.key(f"alt-{number}")

# user.file_manager
def file_manager_go_back():
# user.navigation
def go_back():
actions.key("alt-left")

def file_manager_go_forward():
def go_forward():
actions.key("alt-right")

# user.file_manager
def file_manager_open_parent():
actions.key("alt-up")

Expand Down
4 changes: 0 additions & 4 deletions apps/powershell/powershell_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,6 @@ def file_manager_refresh_title():
"$Host.UI.RawUI.WindowTitle = 'Windows PowerShell: ' + $(get-location)"
)
actions.key("enter")
# action(user.file_manager_go_back):
# key("alt-left")
# action(user.file_manager_go_forward):
# key("alt-right")

def file_manager_open_parent():
actions.insert("cd ..")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,6 @@ class UserActions:
def file_manager_refresh_title():
actions.insert("title Command Prompt: %CD%")
actions.key("enter")
# action(user.file_manager_go_back):
# key("alt-left")
# action(user.file_manager_go_forward):
# key("alt-right")

def file_manager_open_parent():
actions.insert("cd ..")
Expand Down
4 changes: 0 additions & 4 deletions apps/windows_command_processor/command_processor_win.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,6 @@ class UserActions:
def file_manager_refresh_title():
actions.insert("title Command Prompt: %CD%")
actions.key("enter")
# action(user.file_manager_go_back):
# key("alt-left")
# action(user.file_manager_go_forward):
# key("alt-right")

def file_manager_open_parent():
actions.insert("cd ..")
Expand Down
5 changes: 0 additions & 5 deletions apps/windows_explorer/windows_explorer.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,11 +86,6 @@

@ctx.action_class("user")
class UserActions:
def file_manager_go_back():
actions.key("alt-left")

def file_manager_go_forward():
actions.key("alt-right")

def file_manager_open_parent():
actions.key("alt-up")
Expand Down
43 changes: 43 additions & 0 deletions core/navigation/navigation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
from talon import Context, Module, actions

mod = Module()
mod.tag("navigation")

ctx_browser = Context()
ctx_browser.matches = r"""
tag: browser
"""

ctx_mac = Context()
ctx_mac.matches = r"""
os: mac
"""


@ctx_browser.action_class("user")
class BrowserActions:
def go_back():
actions.browser.go_back()

def go_forward():
actions.browser.go_forward()


@ctx_mac.action_class("user")
class MacActions:
def go_back():
actions.key("cmd-]")

def go_forward():
actions.key("cmd-[")


@mod.action_class
class Actions:
def go_back():
"""Navigate back"""
actions.key("alt-left")

def go_forward():
"""Navigate forward"""
actions.key("alt-right")
5 changes: 5 additions & 0 deletions core/navigation/navigation.talon
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
tag: user.navigation
-

go back: user.go_back()
go forward: user.go_forward()
4 changes: 2 additions & 2 deletions tags/browser/browser.talon
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
tag: browser
-
tag(): user.navigation

address bar | go address | go url: browser.focus_address()
go page | page focus: browser.focus_page()
address copy | url copy | copy address | copy url:
browser.focus_address()
sleep(50ms)
edit.copy()
go home: browser.go_home()
[go] forward: browser.go_forward()
go (back | backward): browser.go_back()
go to {user.website}: browser.go(website)
go private: browser.open_private_window()

Expand Down
6 changes: 0 additions & 6 deletions tags/file_manager/file_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,6 @@ def file_manager_open_parent():
"""file_manager_open_parent"""
return

def file_manager_go_forward():
"""file_manager_go_forward_directory"""

def file_manager_go_back():
"""file_manager_go_forward_directory"""

def file_manager_open_volume(volume: str):
"""file_manager_open_volume"""

Expand Down
4 changes: 2 additions & 2 deletions tags/file_manager/file_manager.talon
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
tag: user.file_manager
-
tag(): user.navigation

title force: user.file_manager_refresh_title()
manager show: user.file_manager_toggle_pickers()
manager close: user.file_manager_hide_pickers()
manager refresh: user.file_manager_update_lists()
go <user.system_path>: user.file_manager_open_directory(system_path)
go back: user.file_manager_go_back()
go forward: user.file_manager_go_forward()
(go parent | daddy): user.file_manager_open_parent()
^follow numb <number_small>$:
directory = user.file_manager_get_directory_by_index(number_small - 1)
Expand Down

0 comments on commit 9498ffc

Please sign in to comment.