mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-13 14:26:37 +00:00
fixed close sketch
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
e8c3abd2ec
commit
7873e492d4
@ -107,7 +107,7 @@
|
|||||||
},
|
},
|
||||||
{
|
{
|
||||||
"frontend": "lib/browser/customization/core/browser-menu-module",
|
"frontend": "lib/browser/customization/core/browser-menu-module",
|
||||||
"frontendElectron": "lib/electron-browser/menu/electron-arduino-menu-module"
|
"frontendElectron": "lib/electron-browser/customization/core/electron-menu-module"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"frontend": "lib/browser/boards/quick-open/boards-quick-open-module"
|
"frontend": "lib/browser/boards/quick-open/boards-quick-open-module"
|
||||||
|
@ -37,7 +37,7 @@ import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
|
|||||||
import { ArduinoDaemon } from '../common/protocol/arduino-daemon';
|
import { ArduinoDaemon } from '../common/protocol/arduino-daemon';
|
||||||
import { ConfigService } from '../common/protocol/config-service';
|
import { ConfigService } from '../common/protocol/config-service';
|
||||||
import { BoardsConfigStore } from './boards/boards-config-store';
|
import { BoardsConfigStore } from './boards/boards-config-store';
|
||||||
import { MainMenuManager } from './menu/main-menu-manager';
|
import { MainMenuManager } from '../common/main-menu-manager';
|
||||||
import { FileSystemExt } from '../common/protocol/filesystem-ext';
|
import { FileSystemExt } from '../common/protocol/filesystem-ext';
|
||||||
import { ArduinoMenus } from './menu/arduino-menus';
|
import { ArduinoMenus } from './menu/arduino-menus';
|
||||||
|
|
||||||
|
@ -6,7 +6,7 @@ import { BoardsServiceClientImpl } from './boards-service-client-impl';
|
|||||||
import { Board, ConfigOption } from '../../common/protocol';
|
import { Board, ConfigOption } from '../../common/protocol';
|
||||||
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
|
||||||
import { BoardsConfigStore } from './boards-config-store';
|
import { BoardsConfigStore } from './boards-config-store';
|
||||||
import { MainMenuManager } from '../menu/main-menu-manager';
|
import { MainMenuManager } from '../../common/main-menu-manager';
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
|
@ -1,13 +1,17 @@
|
|||||||
import { injectable } from 'inversify';
|
import { inject, injectable } from 'inversify';
|
||||||
import { remote } from 'electron';
|
import { remote } from 'electron';
|
||||||
import { WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
|
|
||||||
import { ArduinoMenus } from '../menu/arduino-menus';
|
import { ArduinoMenus } from '../menu/arduino-menus';
|
||||||
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry } from './contribution';
|
import { SketchContribution, Command, CommandRegistry, MenuModelRegistry, KeybindingRegistry, URI, Sketch } from './contribution';
|
||||||
import { SaveAsSketch } from './save-as-sketch';
|
import { SaveAsSketch } from './save-as-sketch';
|
||||||
|
import { EditorManager } from '@theia/editor/lib/browser';
|
||||||
|
import { MonacoEditor } from '@theia/monaco/lib/browser/monaco-editor';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class CloseSketch extends SketchContribution {
|
export class CloseSketch extends SketchContribution {
|
||||||
|
|
||||||
|
@inject(EditorManager)
|
||||||
|
protected readonly editorManager: EditorManager;
|
||||||
|
|
||||||
registerCommands(registry: CommandRegistry): void {
|
registerCommands(registry: CommandRegistry): void {
|
||||||
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
|
registry.registerCommand(CloseSketch.Commands.CLOSE_SKETCH, {
|
||||||
execute: async () => {
|
execute: async () => {
|
||||||
@ -16,8 +20,7 @@ export class CloseSketch extends SketchContribution {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const isTemp = await this.sketchService.isTemp(sketch);
|
const isTemp = await this.sketchService.isTemp(sketch);
|
||||||
if (isTemp) {
|
if (isTemp && await this.wasTouched(sketch)) {
|
||||||
// TODO: check monaco model version. If `0` just close the app.
|
|
||||||
const { response } = await remote.dialog.showMessageBox({
|
const { response } = await remote.dialog.showMessageBox({
|
||||||
type: 'question',
|
type: 'question',
|
||||||
buttons: ["Don't Save", 'Cancel', 'Save'],
|
buttons: ["Don't Save", 'Cancel', 'Save'],
|
||||||
@ -34,7 +37,7 @@ export class CloseSketch extends SketchContribution {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
await this.commandService.executeCommand(WorkspaceCommands.CLOSE.id);
|
window.close();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -54,6 +57,23 @@ export class CloseSketch extends SketchContribution {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* If the file was ever touched/modified. We get this based on the `version` of the monaco model.
|
||||||
|
*/
|
||||||
|
protected async wasTouched(sketch: Sketch): Promise<boolean> {
|
||||||
|
const editorWidget = await this.editorManager.getByUri(new URI(sketch.uri).resolve(`${sketch.name}.ino`));
|
||||||
|
if (editorWidget) {
|
||||||
|
const { editor } = editorWidget;
|
||||||
|
if (editor instanceof MonacoEditor) {
|
||||||
|
const versionId = editor.getControl().getModel()?.getVersionId();
|
||||||
|
if (Number.isInteger(versionId) && versionId! > 1) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export namespace CloseSketch {
|
export namespace CloseSketch {
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
import { injectable } from 'inversify';
|
import { injectable } from 'inversify';
|
||||||
import { BrowserMainMenuFactory as TheiaBrowserMainMenuFactory, MenuBarWidget } from '@theia/core/lib/browser/menu/browser-menu-plugin';
|
import { BrowserMainMenuFactory as TheiaBrowserMainMenuFactory, MenuBarWidget } from '@theia/core/lib/browser/menu/browser-menu-plugin';
|
||||||
import { MainMenuManager } from '../../menu/main-menu-manager';
|
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||||
|
|
||||||
@injectable()
|
@injectable()
|
||||||
export class BrowserMainMenuFactory extends TheiaBrowserMainMenuFactory implements MainMenuManager {
|
export class BrowserMainMenuFactory extends TheiaBrowserMainMenuFactory implements MainMenuManager {
|
||||||
|
@ -1,7 +1,7 @@
|
|||||||
import '../../../../src/browser/style/browser-menu.css';
|
import '../../../../src/browser/style/browser-menu.css';
|
||||||
import { ContainerModule } from 'inversify';
|
import { ContainerModule } from 'inversify';
|
||||||
import { BrowserMenuBarContribution, BrowserMainMenuFactory as TheiaBrowserMainMenuFactory } from '@theia/core/lib/browser/menu/browser-menu-plugin';
|
import { BrowserMenuBarContribution, BrowserMainMenuFactory as TheiaBrowserMainMenuFactory } from '@theia/core/lib/browser/menu/browser-menu-plugin';
|
||||||
import { MainMenuManager } from '../../menu/main-menu-manager';
|
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||||
import { ArduinoMenuContribution } from './browser-menu-plugin';
|
import { ArduinoMenuContribution } from './browser-menu-plugin';
|
||||||
import { BrowserMainMenuFactory } from './browser-main-menu-factory';
|
import { BrowserMainMenuFactory } from './browser-main-menu-factory';
|
||||||
|
|
||||||
|
@ -18,17 +18,12 @@ export class WorkspaceFrontendContribution extends TheiaWorkspaceFrontendContrib
|
|||||||
WorkspaceCommands.OPEN_WORKSPACE,
|
WorkspaceCommands.OPEN_WORKSPACE,
|
||||||
WorkspaceCommands.OPEN_RECENT_WORKSPACE,
|
WorkspaceCommands.OPEN_RECENT_WORKSPACE,
|
||||||
WorkspaceCommands.SAVE_WORKSPACE_AS,
|
WorkspaceCommands.SAVE_WORKSPACE_AS,
|
||||||
WorkspaceCommands.SAVE_AS
|
WorkspaceCommands.SAVE_AS,
|
||||||
|
WorkspaceCommands.CLOSE
|
||||||
].filter(commands.has.bind(commands)).forEach(registry.unregisterCommand.bind(registry));
|
].filter(commands.has.bind(commands)).forEach(registry.unregisterCommand.bind(registry));
|
||||||
}
|
}
|
||||||
|
|
||||||
registerMenus(_: MenuModelRegistry): void {
|
registerMenus(_: MenuModelRegistry): void {
|
||||||
// NOOP
|
|
||||||
}
|
|
||||||
|
|
||||||
protected async closeWorkspace(): Promise<void> {
|
|
||||||
// Do not ask to close the workspace, just close it. The dirty/temp state of the sketch is handled somewhere else.
|
|
||||||
await this.workspaceService.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@ import { injectable, inject } from 'inversify';
|
|||||||
import { ApplicationShell, FrontendApplicationContribution, FrontendApplication, Widget } from '@theia/core/lib/browser';
|
import { ApplicationShell, FrontendApplicationContribution, FrontendApplication, Widget } from '@theia/core/lib/browser';
|
||||||
import { EditorWidget } from '@theia/editor/lib/browser';
|
import { EditorWidget } from '@theia/editor/lib/browser';
|
||||||
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
|
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
|
||||||
import { MainMenuManager } from './menu/main-menu-manager';
|
import { MainMenuManager } from '../common/main-menu-manager';
|
||||||
import { BoardsListWidget } from './boards/boards-list-widget';
|
import { BoardsListWidget } from './boards/boards-list-widget';
|
||||||
import { LibraryListWidget } from './library/library-list-widget';
|
import { LibraryListWidget } from './library/library-list-widget';
|
||||||
|
|
||||||
|
@ -0,0 +1,35 @@
|
|||||||
|
import { injectable } from 'inversify';
|
||||||
|
import { CommandRegistry } from '@theia/core/lib/common/command';
|
||||||
|
import { MenuModelRegistry } from '@theia/core/lib/common/menu';
|
||||||
|
import { KeybindingRegistry } from '@theia/core/lib/browser/keybinding';
|
||||||
|
import { ElectronMenuContribution as TheiaElectronMenuContribution, ElectronCommands } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
||||||
|
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||||
|
|
||||||
|
@injectable()
|
||||||
|
export class ElectronMenuContribution extends TheiaElectronMenuContribution implements MainMenuManager {
|
||||||
|
|
||||||
|
protected hideTopPanel(): void {
|
||||||
|
// NOOP
|
||||||
|
// We reuse the `div` for the Arduino toolbar.
|
||||||
|
}
|
||||||
|
|
||||||
|
update(): void {
|
||||||
|
(this as any).setMenu();
|
||||||
|
}
|
||||||
|
|
||||||
|
registerCommands(registry: CommandRegistry): void {
|
||||||
|
super.registerCommands(registry);
|
||||||
|
registry.unregisterCommand(ElectronCommands.CLOSE_WINDOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerMenus(registry: MenuModelRegistry): void {
|
||||||
|
super.registerMenus(registry);
|
||||||
|
registry.unregisterMenuAction(ElectronCommands.CLOSE_WINDOW);
|
||||||
|
}
|
||||||
|
|
||||||
|
registerKeybindings(registry: KeybindingRegistry): void {
|
||||||
|
super.registerKeybindings(registry);
|
||||||
|
registry.unregisterKeybinding(ElectronCommands.CLOSE_WINDOW.id);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,10 @@
|
|||||||
|
import { ContainerModule } from 'inversify';
|
||||||
|
import { ElectronMenuContribution as TheiaElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution'
|
||||||
|
import { ElectronMenuContribution } from './electron-menu-contribution';
|
||||||
|
import { MainMenuManager } from '../../../common/main-menu-manager';
|
||||||
|
|
||||||
|
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
||||||
|
bind(ElectronMenuContribution).toSelf().inSingletonScope();
|
||||||
|
bind(MainMenuManager).toService(ElectronMenuContribution);
|
||||||
|
rebind(TheiaElectronMenuContribution).to(ElectronMenuContribution);
|
||||||
|
});
|
@ -1,17 +0,0 @@
|
|||||||
import { injectable } from 'inversify';
|
|
||||||
import { ElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution';
|
|
||||||
import { MainMenuManager } from '../../browser/menu/main-menu-manager';
|
|
||||||
|
|
||||||
@injectable()
|
|
||||||
export class ElectronArduinoMenuContribution extends ElectronMenuContribution implements MainMenuManager {
|
|
||||||
|
|
||||||
protected hideTopPanel(): void {
|
|
||||||
// NOOP
|
|
||||||
// We reuse the `div` for the Arduino toolbar.
|
|
||||||
}
|
|
||||||
|
|
||||||
update(): void {
|
|
||||||
(this as any).setMenu();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
@ -1,10 +0,0 @@
|
|||||||
import { ContainerModule } from 'inversify';
|
|
||||||
import { ElectronMenuContribution } from '@theia/core/lib/electron-browser/menu/electron-menu-contribution'
|
|
||||||
import { ElectronArduinoMenuContribution } from './electron-arduino-menu-contribution';
|
|
||||||
import { MainMenuManager } from '../../browser/menu/main-menu-manager';
|
|
||||||
|
|
||||||
export default new ContainerModule((bind, unbind, isBound, rebind) => {
|
|
||||||
bind(ElectronArduinoMenuContribution).toSelf().inSingletonScope();
|
|
||||||
bind(MainMenuManager).toService(ElectronArduinoMenuContribution);
|
|
||||||
rebind(ElectronMenuContribution).to(ElectronArduinoMenuContribution);
|
|
||||||
});
|
|
Loading…
x
Reference in New Issue
Block a user