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 Reveal in Explorer option to changed file's context menu #1677
Conversation
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.
A great start @zhuowei! Some feedback to get things moving...
app/src/ui/changes/changed-file.tsx
Outdated
items.push( | ||
{ type: 'separator' }, | ||
{ | ||
label: 'Open in external editor', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/lib/dispatcher/dispatcher.ts
Outdated
public openInExternalEditor(repository: Repository, filepath: string): boolean { | ||
const fullPath = Path.join(repository.path, filepath) | ||
// because Windows uses different path separators here | ||
const normalized = Path.normalize(fullPath) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Pull request updated:
|
app/src/ui/changes/changed-file.tsx
Outdated
action: () => this.props.onOpenInExternalEditor(this.props.path), | ||
}, | ||
{ | ||
label: __DARWIN__ ? 'Reveal in Finder' : 'Reveal in Explorer', |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
In the classic app on Windows we would always open a file with the 'Edit' verb to prevent the user from accidentally executing arbitrary code (like .exe, .js, .com etc). IIRC the default 'Open' action on Windows for .js is the windows script host which will happily run whatever you throw at it. If we couldn't find a registered Edit verb we still wouldn't launch with the 'Open' verb but rather fall back to opening the file in Explorer. I think we need to implement similar safeguards here although I'm not quite sure how to specify a verb in this environment. |
@niik Updated text per comment. For opening with a separate verb, I can't find any npm modules that can do this, so we may either need to write a module that wraps ShellExecute, or use node-ffi to wrap the function through ffi. |
Yeah, I think we should land this PR with just the 'Reveal in Finder/Show in Explorer' menu item and push the open option further down the line. It's tricky to get right and on macOS it seems like although there's an equivalent of the edit verb it can't be trusted to not execute code. I think as we start to get into 'Open in Atom/Open in [insert favorite IDE here]' the need for a generic open item will diminish somewhat. |
@zhuowei this looks like it's close, however there's a merge conflict that needs to be 🔥'd first. |
@shiftkey also #1677 (comment) |
@niik 👍 gonna drop myself off this review, but feel free to pull me in if you want an extra set of 👀 |
@niik Open button removed; only the Reveal in Finder/Open in Explorer menu item is left. Also, conflict resolved. |
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.
Looking good @zhuowei, I had a few questions 👇
app/src/lib/dispatcher/dispatcher.ts
Outdated
function joinAndNormalizePath(repository: Repository, filepath: string): string { | ||
const fullPath = Path.join(repository.path, filepath) | ||
// because Windows uses different path separators here | ||
const normalized = Path.normalize(fullPath) |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/ui/changes/changed-file.tsx
Outdated
@@ -100,6 +101,15 @@ export class ChangedFile extends React.Component<IChangedFileProps, void> { | |||
}) | |||
} | |||
|
|||
if (this.props.status !== FileStatus.Deleted) { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/ui/changes/sidebar.tsx
Outdated
@@ -113,6 +113,10 @@ export class ChangesSidebar extends React.Component<IChangesSidebarProps, void> | |||
this.props.dispatcher.ignore(this.props.repository, pattern) | |||
} | |||
|
|||
private onRevealInFileManager = (path: string) => { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/ui/changes/changes-list.tsx
Outdated
@@ -26,6 +26,7 @@ interface IChangesListProps { | |||
readonly onCreateCommit: (message: ICommitMessage) => Promise<boolean> | |||
readonly onDiscardChanges: (file: WorkingDirectoryFileChange) => void | |||
readonly onDiscardAllChanges: (files: ReadonlyArray<WorkingDirectoryFileChange>) => void | |||
readonly onRevealInFileManager: (path: string) => void |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/ui/changes/changed-file.tsx
Outdated
@@ -16,6 +16,7 @@ interface IChangedFileProps { | |||
readonly include: boolean | null | |||
readonly onIncludeChanged: (path: string, include: boolean) => void | |||
readonly onDiscardChanges: (path: string) => void | |||
readonly onRevealInFileManager: (path: string) => void |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
app/src/lib/dispatcher/dispatcher.ts
Outdated
@@ -841,6 +841,11 @@ export class Dispatcher { | |||
return this.appStore._setConfirmRepoRemoval(value) | |||
} | |||
|
|||
public revealInFileManager(repository: Repository, filepath: string): boolean { |
This comment was marked as spam.
This comment was marked as spam.
Sorry, something went wrong.
Addressed @niik's comments. |
This fixes parts of issue desktop#1566.
Rebased to fix build. |
Nicely done @zhuowei, thank you! |
Fixes #1566.
I tested this on Windows 10; I don't have a Mac, but I think this would still work there since it just uses electron's shell api.
Questions: