Skip to content
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion plugin_source/hooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,9 @@ def bulk_suggest_handler(browser: Browser, nids: Sequence[NoteId]) -> None:
return
suggest_notes(nids, 9)

def trigger_bulk_suggest_from_browser(browser: Browser) -> None:
bulk_suggest_handler(browser, browser.selected_notes())

def remove_notes(nids: Sequence[NoteId], window=None) -> None:
if not auth_manager.is_logged_in():
showInfo("Please log in to remove notes.", parent=window if window is not None else mw)
Expand Down Expand Up @@ -283,7 +286,7 @@ def context_menu_bulk_suggest(browser: Browser, context_menu: QMenu) -> None:

context_menu.addSeparator()
context_menu.addAction(
"AnkiCollab: Bulk suggest notes",
"AnkiCollab: Bulk suggest notes\tCtrl+Alt+B",
lambda: bulk_suggest_handler(browser, nids=selected_nids),
)
Comment on lines 288 to 291

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The shortcut string (Ctrl+Alt+B) is now duplicated in two places: embedded in the context menu label and set on the QAction. This can drift over time if the shortcut ever changes. Prefer reusing the same QAction (or a shared constant) for both the menu item and context menu so the displayed shortcut stays consistent automatically.

Copilot uses AI. Check for mistakes.
context_menu.addAction(
Expand Down Expand Up @@ -321,6 +324,13 @@ def context_menu_bulk_suggest(browser: Browser, context_menu: QMenu) -> None:
except Exception:
pass

def add_browser_bulk_suggest_action(browser: Browser) -> None:
action = QAction("AnkiCollab: Bulk suggest notes", browser)
action.setShortcut(QKeySequence("Ctrl+Alt+B"))
action.setShortcutContext(Qt.WidgetWithChildrenShortcut)
action.triggered.connect(lambda: trigger_bulk_suggest_from_browser(browser))

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

QAction.triggered emits a boolean argument (checked). Connecting it to lambda: ... will raise a TypeError at runtime when the shortcut/action is triggered. Use aqt.qt.qconnect(action.triggered, ...) (as in gear_menu_setup.py) or make the slot accept the checked argument (e.g., lambda _=False: ...).

Suggested change
action.triggered.connect(lambda: trigger_bulk_suggest_from_browser(browser))
action.triggered.connect(lambda _checked=False: trigger_bulk_suggest_from_browser(browser))

Copilot uses AI. Check for mistakes.
browser.form.menu_Notes.addAction(action)
Comment on lines +327 to +332

Copilot AI Apr 20, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

add_browser_bulk_suggest_action() adds the menu/shortcut action even when logged out, unlike other browser menu initializers (e.g., add_browser_menu_item() and context_menu_bulk_suggest()) which early-return when not logged in. Consider adding the same auth_manager.is_logged_in() guard here to avoid exposing non-functional menu items/shortcuts to logged-out users.

Copilot uses AI. Check for mistakes.

def create_note_links_handler(browser: Browser, nids: Sequence[NoteId], subscriber_hash: str, base_hash: Optional[str] = None) -> None:
if not auth_manager.is_logged_in():
showInfo("Please log in to link notes.", parent=browser)
Expand Down Expand Up @@ -694,6 +704,7 @@ def hooks_init():
on_deck_browser_will_show_options_menu
)
gui_hooks.browser_menus_did_init.append(add_browser_menu_item)
gui_hooks.browser_menus_did_init.append(add_browser_bulk_suggest_action)

# Context Menus (callbacks have internal checks)
gui_hooks.browser_sidebar_will_show_context_menu.append(add_sidebar_context_menu)
Expand Down