From 2aac1e9aec95bc34d2ef7c4510869188fca804cd Mon Sep 17 00:00:00 2001 From: Christian Radke Date: Mon, 28 Aug 2023 14:10:11 +0200 Subject: [PATCH 1/3] Create new untitled file when double clicking on the main area or tab bar Signed-off-by: Christian Radke --- packages/core/src/browser/shell/application-shell.ts | 11 +++++++++++ packages/editor/src/browser/editor-manager.ts | 9 ++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/packages/core/src/browser/shell/application-shell.ts b/packages/core/src/browser/shell/application-shell.ts index 5e9449ef5f2d7..ab5de912f3579 100644 --- a/packages/core/src/browser/shell/application-shell.ts +++ b/packages/core/src/browser/shell/application-shell.ts @@ -246,6 +246,9 @@ export class ApplicationShell extends Widget { protected readonly onDidChangeCurrentWidgetEmitter = new Emitter>(); readonly onDidChangeCurrentWidget = this.onDidChangeCurrentWidgetEmitter.event; + protected readonly onDidRequestNewUntitledTextFileEmitter = new Emitter(); + readonly onDidRequestNewUntitledTextFile = this.onDidRequestNewUntitledTextFileEmitter.event; + @inject(TheiaDockPanel.Factory) protected readonly dockPanelFactory: TheiaDockPanel.Factory; @@ -578,6 +581,14 @@ export class ApplicationShell extends Widget { } } }); + + dockPanel.node.addEventListener('dblclick', event => { + const el = event.target as Element; + if (el.id === MAIN_AREA_ID || el.classList.contains('p-TabBar-content')) { + this.onDidRequestNewUntitledTextFileEmitter.fire(); + } + }); + const handler = (e: DragEvent) => { if (e.dataTransfer) { e.dataTransfer.dropEffect = 'link'; diff --git a/packages/editor/src/browser/editor-manager.ts b/packages/editor/src/browser/editor-manager.ts index fd99c3b44be36..1061fe50e9373 100644 --- a/packages/editor/src/browser/editor-manager.ts +++ b/packages/editor/src/browser/editor-manager.ts @@ -16,8 +16,8 @@ import { injectable, postConstruct, inject } from '@theia/core/shared/inversify'; import URI from '@theia/core/lib/common/uri'; -import { RecursivePartial, Emitter, Event, MaybePromise } from '@theia/core/lib/common'; -import { WidgetOpenerOptions, NavigatableWidgetOpenHandler, NavigatableWidgetOptions, Widget, PreferenceService } from '@theia/core/lib/browser'; +import { RecursivePartial, Emitter, Event, MaybePromise, CommandService } from '@theia/core/lib/common'; +import { WidgetOpenerOptions, NavigatableWidgetOpenHandler, NavigatableWidgetOptions, Widget, PreferenceService, CommonCommands } from '@theia/core/lib/browser'; import { EditorWidget } from './editor-widget'; import { Range, Position, Location, TextEditor } from './editor'; import { EditorWidgetFactory } from './editor-widget-factory'; @@ -54,13 +54,16 @@ export class EditorManager extends NavigatableWidgetOpenHandler { */ readonly onCurrentEditorChanged: Event = this.onCurrentEditorChangedEmitter.event; + @inject(CommandService) protected readonly commands: CommandService; @inject(PreferenceService) protected readonly preferenceService: PreferenceService; @postConstruct() protected override init(): void { super.init(); this.shell.onDidChangeActiveWidget(() => this.updateActiveEditor()); - this.shell.onDidChangeCurrentWidget(() => this.updateCurrentEditor()); + this.shell.onDidRequestNewUntitledTextFile(() => + this.commands.executeCommand(CommonCommands.NEW_UNTITLED_TEXT_FILE.id) + ); this.onCreated(widget => { widget.onDidChangeVisibility(() => { if (widget.isVisible) { From e38784297b474ba6e04cfa17bd2b1a7348fd0c93 Mon Sep 17 00:00:00 2001 From: Christian Radke Date: Mon, 11 Sep 2023 12:31:01 +0200 Subject: [PATCH 2/3] Make event naming more generic --- packages/core/src/browser/shell/application-shell.ts | 6 +++--- packages/editor/src/browser/editor-manager.ts | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/core/src/browser/shell/application-shell.ts b/packages/core/src/browser/shell/application-shell.ts index ab5de912f3579..16fbf1663f114 100644 --- a/packages/core/src/browser/shell/application-shell.ts +++ b/packages/core/src/browser/shell/application-shell.ts @@ -246,8 +246,8 @@ export class ApplicationShell extends Widget { protected readonly onDidChangeCurrentWidgetEmitter = new Emitter>(); readonly onDidChangeCurrentWidget = this.onDidChangeCurrentWidgetEmitter.event; - protected readonly onDidRequestNewUntitledTextFileEmitter = new Emitter(); - readonly onDidRequestNewUntitledTextFile = this.onDidRequestNewUntitledTextFileEmitter.event; + protected readonly onDidDoubleClickMainAreaEmitter = new Emitter(); + readonly onDidDoubleClickMainArea = this.onDidDoubleClickMainAreaEmitter.event; @inject(TheiaDockPanel.Factory) protected readonly dockPanelFactory: TheiaDockPanel.Factory; @@ -585,7 +585,7 @@ export class ApplicationShell extends Widget { dockPanel.node.addEventListener('dblclick', event => { const el = event.target as Element; if (el.id === MAIN_AREA_ID || el.classList.contains('p-TabBar-content')) { - this.onDidRequestNewUntitledTextFileEmitter.fire(); + this.onDidDoubleClickMainAreaEmitter.fire(); } }); diff --git a/packages/editor/src/browser/editor-manager.ts b/packages/editor/src/browser/editor-manager.ts index 1061fe50e9373..41a70b104dfa9 100644 --- a/packages/editor/src/browser/editor-manager.ts +++ b/packages/editor/src/browser/editor-manager.ts @@ -61,7 +61,7 @@ export class EditorManager extends NavigatableWidgetOpenHandler { protected override init(): void { super.init(); this.shell.onDidChangeActiveWidget(() => this.updateActiveEditor()); - this.shell.onDidRequestNewUntitledTextFile(() => + this.shell.onDidDoubleClickMainArea(() => this.commands.executeCommand(CommonCommands.NEW_UNTITLED_TEXT_FILE.id) ); this.onCreated(widget => { From d23f0aaf7ad3d779d63357454c5dff467e96446a Mon Sep 17 00:00:00 2001 From: Christian Radke Date: Mon, 11 Sep 2023 14:57:44 +0200 Subject: [PATCH 3/3] Restore accidently deleted line --- packages/editor/src/browser/editor-manager.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/packages/editor/src/browser/editor-manager.ts b/packages/editor/src/browser/editor-manager.ts index 41a70b104dfa9..6b1b2bd8ad7d7 100644 --- a/packages/editor/src/browser/editor-manager.ts +++ b/packages/editor/src/browser/editor-manager.ts @@ -61,6 +61,7 @@ export class EditorManager extends NavigatableWidgetOpenHandler { protected override init(): void { super.init(); this.shell.onDidChangeActiveWidget(() => this.updateActiveEditor()); + this.shell.onDidChangeCurrentWidget(() => this.updateCurrentEditor()); this.shell.onDidDoubleClickMainArea(() => this.commands.executeCommand(CommonCommands.NEW_UNTITLED_TEXT_FILE.id) );