-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add an option to show image from editor in folder #3412
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,7 @@ | |
from anki.collection import Collection, HelpPage | ||
from anki.lang import TR, tr_legacyglobal # pylint: disable=unused-import | ||
from anki.utils import ( | ||
call, | ||
invalid_filename, | ||
is_mac, | ||
is_win, | ||
|
@@ -885,6 +886,33 @@ def openFolder(path: str) -> None: | |
QDesktopServices.openUrl(QUrl(f"file://{path}")) | ||
|
||
|
||
def showinFolder(path: str) -> None: | ||
if is_win: | ||
call(["explorer", "/select,", f"file://{path}"]) | ||
elif is_mac: | ||
script = f""" | ||
tell application "Finder" | ||
activate | ||
select POSIX file '{path}' | ||
end tell | ||
""" | ||
call(osascript_to_args(script)) | ||
else: | ||
# Just open the file in any other platform | ||
with no_bundled_libs(): | ||
QDesktopServices.openUrl(QUrl(f"file://{path}")) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have you copied+pasted this code from somewhere? From a quick read of the Qt docs, it looks like openUrl() should do what we want on all platforms? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For local files, openUrl() opens the file in the default viewer if it can. But, we want it to highlight the file even when there is a viewer available. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, I was under the mistaken impression that it would select the file, not open it directly. |
||
|
||
|
||
def osascript_to_args(script: str): | ||
args = [ | ||
item | ||
for line in script.splitlines() | ||
for item in ("-e", line.strip()) | ||
if line.strip() | ||
] | ||
return ["osascript"] + args | ||
|
||
|
||
def shortcut(key: str) -> str: | ||
if is_mac: | ||
return re.sub("(?i)ctrl", "Command", key) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any feature we add should work across all OSes - is there a reason why non-Mac/Windows has been excluded here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would definitely be better to make a feature work on all platforms. But, I have no idea how to make it work with all the different file managers in Linux. Even if this doesn't work on Linux, it is still an improvement over what we currently have, especially when you consider that Windows + Mac users comprise most of the Anki's userbase.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"We can't do it on Linux easily" is a reasonable answer for now :-) Thanks for clarifying.