mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-17 08:16:33 +00:00
ATL-885: Refined the 'Close' behavior.
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
23877f162c
commit
57c50fefe3
@ -85,7 +85,7 @@ import { WorkspaceFrontendContribution, ArduinoFileMenuContribution } from './th
|
|||||||
import { Contribution } from './contributions/contribution';
|
import { Contribution } from './contributions/contribution';
|
||||||
import { NewSketch } from './contributions/new-sketch';
|
import { NewSketch } from './contributions/new-sketch';
|
||||||
import { OpenSketch } from './contributions/open-sketch';
|
import { OpenSketch } from './contributions/open-sketch';
|
||||||
import { CloseSketch } from './contributions/close-sketch';
|
import { Close } from './contributions/close';
|
||||||
import { SaveAsSketch } from './contributions/save-as-sketch';
|
import { SaveAsSketch } from './contributions/save-as-sketch';
|
||||||
import { SaveSketch } from './contributions/save-sketch';
|
import { SaveSketch } from './contributions/save-sketch';
|
||||||
import { VerifySketch } from './contributions/verify-sketch';
|
import { VerifySketch } from './contributions/verify-sketch';
|
||||||
@ -326,7 +326,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|||||||
|
|
||||||
Contribution.configure(bind, NewSketch);
|
Contribution.configure(bind, NewSketch);
|
||||||
Contribution.configure(bind, OpenSketch);
|
Contribution.configure(bind, OpenSketch);
|
||||||
Contribution.configure(bind, CloseSketch);
|
Contribution.configure(bind, Close);
|
||||||
Contribution.configure(bind, SaveSketch);
|
Contribution.configure(bind, SaveSketch);
|
||||||
Contribution.configure(bind, SaveAsSketch);
|
Contribution.configure(bind, SaveAsSketch);
|
||||||
Contribution.configure(bind, VerifySketch);
|
Contribution.configure(bind, VerifySketch);
|
||||||
|
@ -1,20 +1,50 @@
|
|||||||
import { inject, injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
|
import { toArray } from '@phosphor/algorithm';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
|
|
||||||
import { SaveAsSketch } from './save-as-sketch';
|
|
||||||
import { EditorManager } from '@theia/editor/lib/browser';
|
|
||||||
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
||||||
|
import { EditorManager } from '@theia/editor/lib/browser/editor-manager';
|
||||||
|
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';
|
||||||
|
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
|
||||||
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
import { SaveAsSketch } from './save-as-sketch';
|
||||||
|
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI } from './contribution';
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closes the `current` closeable editor, or any closeable current widget from the main area, or the current sketch window.
|
||||||
|
*/
|
||||||
@injectable()
|
@injectable()
|
||||||
export class CloseSketch extends SketchContribution {
|
export class Close extends SketchContribution {
|
||||||
|
|
||||||
@inject(EditorManager)
|
@inject(EditorManager)
|
||||||
protected readonly editorManager: EditorManager;
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
|
protected shell: ApplicationShell;
|
||||||
|
|
||||||
|
onStart(app: FrontendApplication): void {
|
||||||
|
this.shell = app.shell;
|
||||||
|
}
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
|
registry.registerCommand(Close.Commands.CLOSE, {
|
||||||
execute: async () => {
|
execute: async () => {
|
||||||
|
|
||||||
|
// Close current editor if closeable.
|
||||||
|
const { currentEditor } = this.editorManager;
|
||||||
|
if (currentEditor && currentEditor.title.closable) {
|
||||||
|
currentEditor.close();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close current widget from the main area if possible.
|
||||||
|
const { currentWidget } = this.shell;
|
||||||
|
if (currentWidget) {
|
||||||
|
const currentWidgetInMain = toArray(this.shell.mainPanel.widgets()).find(widget => widget === currentWidget);
|
||||||
|
if (currentWidgetInMain && currentWidgetInMain.title.closable) {
|
||||||
|
return currentWidgetInMain.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the sketch (window).
|
||||||
const sketch = await this.sketchServiceClient.currentSketch();
|
const sketch = await this.sketchServiceClient.currentSketch();
|
||||||
if (!sketch) {
|
if (!sketch) {
|
||||||
return;
|
return;
|
||||||
@ -48,7 +78,7 @@ export class CloseSketch extends SketchContribution {
|
|||||||
|
|
||||||
registerMenus(registry: MenuModelRegistry): void {
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
registry.registerMenuAction(ArduinoMenus.FILE__SKETCH_GROUP, {
|
||||||
commandId: CloseSketch.Commands.CLOSE_SKETCH.id,
|
commandId: Close.Commands.CLOSE.id,
|
||||||
label: 'Close',
|
label: 'Close',
|
||||||
order: '5'
|
order: '5'
|
||||||
});
|
});
|
||||||
@ -56,7 +86,7 @@ export class CloseSketch extends SketchContribution {
|
|||||||
|
|
||||||
registerKeybindings(registry: KeybindingRegistry): void {
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
registry.registerKeybinding({
|
registry.registerKeybinding({
|
||||||
command: CloseSketch.Commands.CLOSE_SKETCH.id,
|
command: Close.Commands.CLOSE.id,
|
||||||
keybinding: 'CtrlCmd+W'
|
keybinding: 'CtrlCmd+W'
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -80,10 +110,10 @@ export class CloseSketch extends SketchContribution {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace CloseSketch {
|
export namespace Close {
|
||||||
export namespace Commands {
|
export namespace Commands {
|
||||||
export const CLOSE_SKETCH: Command = {
|
export const CLOSE: Command = {
|
||||||
id: 'arduino-close-sketch'
|
id: 'arduino-close'
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user