Skip to content

Commit 57c50fe

Browse files
Akos Kittakittaakos
Akos Kitta
authored andcommitted
ATL-885: Refined the 'Close' behavior.
Signed-off-by: Akos Kitta <[email protected]>
1 parent 23877f1 commit 57c50fe

File tree

2 files changed

+42
-12
lines changed

2 files changed

+42
-12
lines changed

Diff for: arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ import { WorkspaceFrontendContribution, ArduinoFileMenuContribution } from './th
8585
import { Contribution } from './contributions/contribution';
8686
import { NewSketch } from './contributions/new-sketch';
8787
import { OpenSketch } from './contributions/open-sketch';
88-
import { CloseSketch } from './contributions/close-sketch';
88+
import { Close } from './contributions/close';
8989
import { SaveAsSketch } from './contributions/save-as-sketch';
9090
import { SaveSketch } from './contributions/save-sketch';
9191
import { VerifySketch } from './contributions/verify-sketch';
@@ -326,7 +326,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
326326

327327
Contribution.configure(bind, NewSketch);
328328
Contribution.configure(bind, OpenSketch);
329-
Contribution.configure(bind, CloseSketch);
329+
Contribution.configure(bind, Close);
330330
Contribution.configure(bind, SaveSketch);
331331
Contribution.configure(bind, SaveAsSketch);
332332
Contribution.configure(bind, VerifySketch);

Diff for: arduino-ide-extension/src/browser/contributions/close-sketch.ts renamed to arduino-ide-extension/src/browser/contributions/close.ts

+40-10
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,50 @@
11
import { inject, injectable } from 'inversify';
2+
import { toArray } from '@phosphor/algorithm';
23
import { remote } from 'electron';
4+
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
5+
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
6+
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
7+
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
38
import { ArduinoMenus } from '../menu/arduino-menus';
4-
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
59
import { SaveAsSketch } from './save-as-sketch';
6-
import { EditorManager } from '@theia/editor/lib/browser';
7-
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
10+
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
811

12+
/**
13+
* Closes the `current` closeable editor, or any closeable current widget from the main area, or the current sketch window.
14+
*/
915
@injectable()
10-
export class CloseSketch extends SketchContribution {
16+
export class Close extends SketchContribution {
1117

1218
@inject(EditorManager)
1319
protected readonly editorManager: EditorManager;
1420

21+
protected shell: ApplicationShell;
22+
23+
onStart(app: FrontendApplication): void {
24+
this.shell = app.shell;
25+
}
26+
1527
registerCommands(registry: CommandRegistry): void {
16-
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
28+
registry.registerCommand(Close.Commands.CLOSE, {
1729
execute: async () => {
30+
31+
// Close current editor if closeable.
32+
const { currentEditor } = this.editorManager;
33+
if (currentEditor && currentEditor.title.closable) {
34+
currentEditor.close();
35+
return;
36+
}
37+
38+
// Close current widget from the main area if possible.
39+
const { currentWidget } = this.shell;
40+
if (currentWidget) {
41+
const currentWidgetInMain = toArray(this.shell.mainPanel.widgets()).find(widget => widget === currentWidget);
42+
if (currentWidgetInMain && currentWidgetInMain.title.closable) {
43+
return currentWidgetInMain.close();
44+
}
45+
}
46+
47+
// Close the sketch (window).
1848
const sketch = await this.sketchServiceClient.currentSketch();
1949
if (!sketch) {
2050
return;
@@ -48,15 +78,15 @@ export class CloseSketch extends SketchContribution {
4878

4979
registerMenus(registry: MenuModelRegistry): void {
5080
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
51-
commandId: CloseSketch.Commands.CLOSE_SKETCH.id,
81+
commandId: Close.Commands.CLOSE.id,
5282
label: 'Close',
5383
order: '5'
5484
});
5585
}
5686

5787
registerKeybindings(registry: KeybindingRegistry): void {
5888
registry.registerKeybinding({
59-
command: CloseSketch.Commands.CLOSE_SKETCH.id,
89+
command: Close.Commands.CLOSE.id,
6090
keybinding: 'CtrlCmd+W'
6191
});
6292
}
@@ -80,10 +110,10 @@ export class CloseSketch extends SketchContribution {
80110

81111
}
82112

83-
export namespace CloseSketch {
113+
export namespace Close {
84114
export namespace Commands {
85-
export const CLOSE_SKETCH: Command = {
86-
id: 'arduino-close-sketch'
115+
export const CLOSE: Command = {
116+
id: 'arduino-close'
87117
};
88118
}
89119
}

0 commit comments

Comments
 (0)