From 3078b5251ee70f17fcd25fcf08e3676d6551cbd2 Mon Sep 17 00:00:00 2001
From: Simon Siefke <simon.siefke@gmail.com>
Date: Mon, 22 Jul 2024 22:41:49 +0200
Subject: [PATCH] feature: add setting whether or not to auto open a file after
 dropping it into the explorer (#213498)

* feature: add setting whether or not to auto open a file after dropping it into the explorer

* use setting

* fix property

* format code

---------

Co-authored-by: Logan Ramos <lramos15@gmail.com>
---
 src/vs/workbench/contrib/files/browser/fileImportExport.ts   | 3 ++-
 src/vs/workbench/contrib/files/browser/files.contribution.ts | 5 +++++
 src/vs/workbench/contrib/files/common/files.ts               | 1 +
 3 files changed, 8 insertions(+), 1 deletion(-)

diff --git a/src/vs/workbench/contrib/files/browser/fileImportExport.ts b/src/vs/workbench/contrib/files/browser/fileImportExport.ts
index 86f4f2285806a..4f3a858af617a 100644
--- a/src/vs/workbench/contrib/files/browser/fileImportExport.ts
+++ b/src/vs/workbench/contrib/files/browser/fileImportExport.ts
@@ -564,7 +564,8 @@ export class ExternalFileImport {
 			});
 
 			// if we only add one file, just open it directly
-			if (resourceFileEdits.length === 1) {
+			const autoOpen = this.configurationService.getValue<IFilesConfiguration>().explorer.autoOpenDroppedFile;
+			if (autoOpen && resourceFileEdits.length === 1) {
 				const item = this.explorerService.findClosest(resourceFileEdits[0].newResource!);
 				if (item && !item.isDirectory) {
 					this.editorService.openEditor({ resource: item.resource, options: { pinned: true } });
diff --git a/src/vs/workbench/contrib/files/browser/files.contribution.ts b/src/vs/workbench/contrib/files/browser/files.contribution.ts
index d525ba5860c80..a7edb2ec8e3e9 100644
--- a/src/vs/workbench/contrib/files/browser/files.contribution.ts
+++ b/src/vs/workbench/contrib/files/browser/files.contribution.ts
@@ -554,6 +554,11 @@ configurationRegistry.registerConfiguration({
 			description: nls.localize('explorer.incrementalNaming', "Controls which naming strategy to use when giving a new name to a duplicated Explorer item on paste."),
 			default: 'simple'
 		},
+		'explorer.autoOpenDroppedFile': {
+			'type': 'boolean',
+			'description': nls.localize('autoOpenDroppedFile', "Controls whether the Explorer should automatically open a file when it is dropped into the explorer"),
+			'default': true
+		},
 		'explorer.compactFolders': {
 			'type': 'boolean',
 			'description': nls.localize('compressSingleChildFolders', "Controls whether the Explorer should render folders in a compact form. In such a form, single child folders will be compressed in a combined tree element. Useful for Java package structures, for example."),
diff --git a/src/vs/workbench/contrib/files/common/files.ts b/src/vs/workbench/contrib/files/common/files.ts
index edf32a0e1895c..bd0c7a7b52544 100644
--- a/src/vs/workbench/contrib/files/common/files.ts
+++ b/src/vs/workbench/contrib/files/common/files.ts
@@ -108,6 +108,7 @@ export interface IFilesConfiguration extends PlatformIFilesConfiguration, IWorkb
 			expand: boolean;
 			patterns: { [parent: string]: string };
 		};
+		autoOpenDroppedFile: boolean;
 	};
 	editor: IEditorOptions;
 }