Skip to content

Commit

Permalink
Merge pull request desktop#14667 from tsvetilian-ty/copy-miltiple-paths
Browse files Browse the repository at this point in the history
Add copy paths when multiple files are selected
  • Loading branch information
sergiou87 authored Jun 10, 2022
2 parents 51aac17 + 21f95db commit 501c29c
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 4 deletions.
43 changes: 39 additions & 4 deletions app/src/ui/changes/changes-list.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ import {
RevealInFileManagerLabel,
OpenWithDefaultProgramLabel,
CopyRelativeFilePathLabel,
CopySelectedPathsLabel,
CopySelectedRelativePathsLabel,
} from '../lib/context-menu'
import { CommitMessage } from './commit-message'
import { ChangedFile } from './changed-file'
Expand All @@ -51,6 +53,7 @@ import { hasConflictedFiles } from '../../lib/status'
import { createObservableRef } from '../lib/observable-ref'
import { Tooltip, TooltipDirection } from '../lib/tooltip'
import { Popup } from '../../models/popup'
import { EOL } from 'os'

const RowHeight = 29
const StashIcon: OcticonSymbol.OcticonSymbolType = {
Expand Down Expand Up @@ -426,6 +429,32 @@ export class ChangesList extends React.Component<
}
}

private getCopySelectedPathsMenuItem = (
files: WorkingDirectoryFileChange[]
): IMenuItem => {
return {
label: CopySelectedPathsLabel,
action: () => {
const fullPaths = files.map(file =>
Path.join(this.props.repository.path, file.path)
)
clipboard.writeText(fullPaths.join(EOL))
},
}
}

private getCopySelectedRelativePathsMenuItem = (
files: WorkingDirectoryFileChange[]
): IMenuItem => {
return {
label: CopySelectedRelativePathsLabel,
action: () => {
const paths = files.map(file => Path.normalize(file.path))
clipboard.writeText(paths.join(EOL))
},
}
}

private getRevealInFileManagerMenuItem = (
file: WorkingDirectoryFileChange
): IMenuItem => {
Expand Down Expand Up @@ -556,15 +585,21 @@ export class ChangesList extends React.Component<
this.props.onIncludeChanged(file.path, false)
)
},
}
},
{ type: 'separator' },
this.getCopySelectedPathsMenuItem(selectedFiles),
this.getCopySelectedRelativePathsMenuItem(selectedFiles)
)
} else {
items.push(
{ type: 'separator' },
this.getCopyPathMenuItem(file),
this.getCopyRelativePathMenuItem(file)
)
}

const enabled = status.kind !== AppFileStatusKind.Deleted
items.push(
{ type: 'separator' },
this.getCopyPathMenuItem(file),
this.getCopyRelativePathMenuItem(file),
{ type: 'separator' },
this.getRevealInFileManagerMenuItem(file),
this.getOpenInExternalEditorMenuItem(file, enabled),
Expand Down
6 changes: 6 additions & 0 deletions app/src/ui/lib/context-menu.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@ export const CopyRelativeFilePathLabel = __DARWIN__
? 'Copy Relative File Path'
: 'Copy relative file path'

export const CopySelectedPathsLabel = __DARWIN__ ? 'Copy Paths' : 'Copy paths'

export const CopySelectedRelativePathsLabel = __DARWIN__
? 'Copy Relative Paths'
: 'Copy relative paths'

export const DefaultEditorLabel = __DARWIN__
? 'Open in External Editor'
: 'Open in external editor'
Expand Down

0 comments on commit 501c29c

Please sign in to comment.