Merge pull request #14667 from tsvetilian-ty/copy-miltiple-paths

Add copy paths when multiple files are selected
This commit is contained in:
Sergio Padrino 2022-06-10 15:37:49 +02:00 committed by GitHub
commit 501c29cc68
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 45 additions and 4 deletions

View file

@ -27,6 +27,8 @@ import {
RevealInFileManagerLabel,
OpenWithDefaultProgramLabel,
CopyRelativeFilePathLabel,
CopySelectedPathsLabel,
CopySelectedRelativePathsLabel,
} from '../lib/context-menu'
import { CommitMessage } from './commit-message'
import { ChangedFile } from './changed-file'
@ -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 = {
@ -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 => {
@ -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),

View file

@ -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'