CHANGE right-click in the editor to show option to open folder in linux (#4125)

* CHANGE right-click in the editor to show option to open folder in linux

* FIX checks

* Use heuristics

* ./ninja format

* Use fallback from main instead of xdg-open
This commit is contained in:
GithubAnon0000 2025-06-28 18:33:17 +00:00 committed by GitHub
parent aae970bed9
commit cfeb71724d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 32 additions and 8 deletions

View file

@ -36,7 +36,7 @@ from anki.hooks import runFilter
from anki.httpclient import HttpClient
from anki.models import NotetypeDict, NotetypeId, StockNotetype
from anki.notes import Note, NoteFieldsCheckResult, NoteId
from anki.utils import checksum, is_lin, is_mac, is_win, namedtmp
from anki.utils import checksum, is_lin, is_win, namedtmp
from aqt import AnkiQt, colors, gui_hooks
from aqt.operations import QueryOp
from aqt.operations.note import update_note
@ -1735,7 +1735,6 @@ class EditorWebView(AnkiWebView):
assert a is not None
qconnect(a.triggered, lambda: openFolder(path))
if is_win or is_mac:
a = menu.addAction(tr.editing_show_in_folder())
assert a is not None
qconnect(a.triggered, lambda: show_in_folder(path))

View file

@ -935,6 +935,31 @@ def show_in_folder(path: str) -> None:
end tell
"""
call(osascript_to_args(script))
else:
# For linux, there are multiple file managers. Let's test if one of the
# most common file managers is found and use it in case it is installed.
# If none of this list are installed, use a fallback. The fallback
# might open the image in a web browser, image viewer or others,
# depending on the users defaults.
file_managers = [
"nautilus", # GNOME
"dolphin", # KDE
"pcmanfm", # LXDE
"thunar", # XFCE
"nemo", # Cinnamon
"caja", # MATE
]
available_file_manager = None
# Test if a file manager is installed and use it, fallback otherwise
for file_manager in file_managers:
if shutil.which(file_manager):
available_file_manager = file_manager
break
if available_file_manager:
subprocess.run([available_file_manager, path], check=False)
else:
# Just open the file in any other platform
with no_bundled_libs():