Skip to content
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

Incremental naming add disabled #160218

Merged
merged 1 commit into from
Sep 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions src/vs/workbench/contrib/files/browser/fileActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,7 +296,7 @@ function containsBothDirectoryAndFile(distinctElements: ExplorerItem[]): boolean
}


export function findValidPasteFileTarget(explorerService: IExplorerService, targetFolder: ExplorerItem, fileToPaste: { resource: URI; isDirectory?: boolean; allowOverwrite: boolean }, incrementalNaming: 'simple' | 'smart'): URI {
export function findValidPasteFileTarget(explorerService: IExplorerService, targetFolder: ExplorerItem, fileToPaste: { resource: URI; isDirectory?: boolean; allowOverwrite: boolean }, incrementalNaming: 'simple' | 'smart' | 'disabled'): URI {
let name = resources.basenameOrAuthority(fileToPaste.resource);

let candidate = resources.joinPath(targetFolder.resource, name);
Expand All @@ -305,7 +305,9 @@ export function findValidPasteFileTarget(explorerService: IExplorerService, targ
break;
}

name = incrementFileName(name, !!fileToPaste.isDirectory, incrementalNaming);
if (incrementalNaming !== 'disabled') {
name = incrementFileName(name, !!fileToPaste.isDirectory, incrementalNaming);
}
candidate = resources.joinPath(targetFolder.resource, name);
}

Expand Down Expand Up @@ -1004,6 +1006,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
const context = explorerService.getContext(true);
const toPaste = resources.distinctParents(await clipboardService.readResources(), r => r);
const element = context.length ? context[0] : explorerService.roots[0];
const incrementalNaming = configurationService.getValue<IFilesConfiguration>().explorer.incrementalNaming;

try {
// Check if target is ancestor of pasted folder
Expand All @@ -1022,8 +1025,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
target = element.isDirectory ? element : element.parent!;
}

const incrementalNaming = configurationService.getValue<IFilesConfiguration>().explorer.incrementalNaming;
const targetFile = findValidPasteFileTarget(explorerService, target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwrite: pasteShouldMove }, incrementalNaming);
const targetFile = findValidPasteFileTarget(explorerService, target, { resource: fileToPaste, isDirectory: fileToPasteStat.isDirectory, allowOverwrite: pasteShouldMove || incrementalNaming === 'disabled' }, incrementalNaming);

return { source: fileToPaste, target: targetFile };
}));
Expand All @@ -1041,7 +1043,7 @@ export const pasteFileHandler = async (accessor: ServicesAccessor) => {
};
await explorerService.applyBulkEdit(resourceFileEdits, options);
} else {
const resourceFileEdits = sourceTargetPairs.map(pair => new ResourceFileEdit(pair.source, pair.target, { copy: true }));
const resourceFileEdits = sourceTargetPairs.map(pair => new ResourceFileEdit(pair.source, pair.target, { copy: true, overwrite: incrementalNaming === 'disabled' }));
const undoLevel = configurationService.getValue<IFilesConfiguration>().explorer.confirmUndo;
const options = {
confirmBeforeUndo: undoLevel === UndoConfirmLevel.Default || undoLevel === UndoConfirmLevel.Verbose,
Expand Down
5 changes: 3 additions & 2 deletions src/vs/workbench/contrib/files/browser/files.contribution.ts
Original file line number Diff line number Diff line change
Expand Up @@ -445,10 +445,11 @@ configurationRegistry.registerConfiguration({
},
'explorer.incrementalNaming': {
'type': 'string',
enum: ['simple', 'smart'],
enum: ['simple', 'smart', 'disabled'],
enumDescriptions: [
nls.localize('simple', "Appends the word \"copy\" at the end of the duplicated name potentially followed by a number"),
nls.localize('smart', "Adds a number at the end of the duplicated name. If some number is already part of the name, tries to increase that number")
nls.localize('smart', "Adds a number at the end of the duplicated name. If some number is already part of the name, tries to increase that number"),
nls.localize('disabled', "Disables incremental naming. If two files with the same name exist you will be prompted to overwrite the existing file")
],
description: nls.localize('explorer.incrementalNaming', "Controls what naming strategy to use when a giving a new name to a duplicated explorer item on paste."),
default: 'simple'
Expand Down
2 changes: 1 addition & 1 deletion src/vs/workbench/contrib/files/common/files.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export interface IFilesConfiguration extends PlatformIFilesConfiguration, IWorkb
colors: boolean;
badges: boolean;
};
incrementalNaming: 'simple' | 'smart';
incrementalNaming: 'simple' | 'smart' | 'disabled';
excludeGitIgnore: boolean;
fileNesting: {
enabled: boolean;
Expand Down