mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-10 02:48:33 +00:00
PROEDITOR-48: Open last sketch at start-up
Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
@@ -15,8 +15,6 @@ import { BoardsListWidgetFrontendContribution } from './boards/boards-widget-fro
|
||||
import { BoardsServiceClientImpl } from './boards/boards-service-client-impl';
|
||||
import { WorkspaceRootUriAwareCommandHandler, WorkspaceCommands } from '@theia/workspace/lib/browser/workspace-commands';
|
||||
import { SelectionService, MenuContribution, MenuModelRegistry, MAIN_MENU_BAR } from '@theia/core';
|
||||
import { WorkspaceService } from '@theia/workspace/lib/browser/workspace-service';
|
||||
import { SketchFactory } from './sketch-factory';
|
||||
import { ArduinoToolbar } from './toolbar/arduino-toolbar';
|
||||
import { EditorManager, EditorMainMenu } from '@theia/editor/lib/browser';
|
||||
import {
|
||||
@@ -26,8 +24,7 @@ import {
|
||||
StatusBar,
|
||||
ShellLayoutRestorer,
|
||||
StatusBarAlignment,
|
||||
QuickOpenService,
|
||||
LabelProvider
|
||||
QuickOpenService
|
||||
} from '@theia/core/lib/browser';
|
||||
import { OpenFileDialogProps, FileDialogService } from '@theia/filesystem/lib/browser/file-dialog';
|
||||
import { FileSystem, FileStat } from '@theia/filesystem/lib/common';
|
||||
@@ -47,6 +44,7 @@ import { MonitorService } from '../common/protocol/monitor-service';
|
||||
import { ConfigService } from '../common/protocol/config-service';
|
||||
import { MonitorConnection } from './monitor/monitor-connection';
|
||||
import { MonitorViewContribution } from './monitor/monitor-view-contribution';
|
||||
import { ArduinoWorkspaceService } from './arduino-workspace-service';
|
||||
|
||||
export namespace ArduinoMenus {
|
||||
export const SKETCH = [...MAIN_MENU_BAR, '3_sketch'];
|
||||
@@ -61,7 +59,6 @@ export namespace ArduinoAdvancedMode {
|
||||
})();
|
||||
}
|
||||
|
||||
|
||||
@injectable()
|
||||
export class ArduinoFrontendContribution implements TabBarToolbarContribution, CommandContribution, MenuContribution {
|
||||
|
||||
@@ -95,9 +92,6 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
@inject(SelectionService)
|
||||
protected readonly selectionService: SelectionService;
|
||||
|
||||
@inject(SketchFactory)
|
||||
protected readonly sketchFactory: SketchFactory;
|
||||
|
||||
@inject(EditorManager)
|
||||
protected readonly editorManager: EditorManager;
|
||||
|
||||
@@ -117,7 +111,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
protected readonly windowService: WindowService;
|
||||
|
||||
@inject(SketchesService)
|
||||
protected readonly sketches: SketchesService;
|
||||
protected readonly sketchService: SketchesService;
|
||||
|
||||
@inject(BoardsConfigDialog)
|
||||
protected readonly boardsConfigDialog: BoardsConfigDialog;
|
||||
@@ -134,17 +128,15 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
@inject(ShellLayoutRestorer)
|
||||
protected readonly layoutRestorer: ShellLayoutRestorer;
|
||||
|
||||
@inject(LabelProvider)
|
||||
protected readonly labelProvider: LabelProvider;
|
||||
|
||||
@inject(QuickOpenService)
|
||||
protected readonly quickOpenService: QuickOpenService;
|
||||
|
||||
@inject(WorkspaceService)
|
||||
protected readonly workspaceService: WorkspaceService;
|
||||
@inject(ArduinoWorkspaceService)
|
||||
protected readonly workspaceService: ArduinoWorkspaceService;
|
||||
|
||||
@inject(ConfigService)
|
||||
protected readonly configService: ConfigService;
|
||||
|
||||
@inject(MonitorConnection)
|
||||
protected readonly monitorConnection: MonitorConnection;
|
||||
|
||||
@@ -304,7 +296,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
registry.registerCommand(ArduinoCommands.OPEN_SKETCH, {
|
||||
isEnabled: () => true,
|
||||
execute: async (sketch: Sketch) => {
|
||||
this.openSketchFilesInNewWindow(sketch.uri);
|
||||
this.workspaceService.openSketchFilesInNewWindow(sketch.uri);
|
||||
}
|
||||
})
|
||||
registry.registerCommand(ArduinoCommands.SAVE_SKETCH, {
|
||||
@@ -322,7 +314,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
uri = uri.withPath(uri.path.dir.dir);
|
||||
}
|
||||
|
||||
await this.sketchFactory.createNewSketch(uri);
|
||||
const sketch = await this.sketchService.createNewSketch(uri.toString());
|
||||
this.workspaceService.openSketchFilesInNewWindow(sketch.uri);
|
||||
} catch (e) {
|
||||
await this.messageService.error(e.toString());
|
||||
}
|
||||
@@ -397,8 +390,8 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
return menuId;
|
||||
}
|
||||
|
||||
protected registerSketchesInMenu(registry: MenuModelRegistry) {
|
||||
this.getWorkspaceSketches().then(sketches => {
|
||||
protected async registerSketchesInMenu(registry: MenuModelRegistry): Promise<void> {
|
||||
this.sketchService.getSketches().then(sketches => {
|
||||
this.wsSketchCount = sketches.length;
|
||||
sketches.forEach(sketch => {
|
||||
const command: Command = {
|
||||
@@ -416,48 +409,12 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
})
|
||||
}
|
||||
|
||||
protected async getWorkspaceSketches(): Promise<Sketch[]> {
|
||||
|
||||
let sketches: Sketch[] = [];
|
||||
const config = await this.configService.getConfiguration();
|
||||
const stat = await this.fileSystem.getFileStat(config.sketchDirUri);
|
||||
if (!!stat) {
|
||||
sketches = await this.sketches.getSketches(stat);
|
||||
}
|
||||
return sketches;
|
||||
}
|
||||
|
||||
protected async openSketchFilesInNewWindow(uri: string) {
|
||||
const url = new URL(window.location.href);
|
||||
const currentSketch = url.searchParams.get('sketch');
|
||||
// Nothing to do if we want to open the same sketch which is already opened.
|
||||
const sketchUri = new URI(uri);
|
||||
if (!!currentSketch && new URI(currentSketch).toString() === sketchUri.toString()) {
|
||||
this.messageService.info(`The '${this.labelProvider.getLongName(sketchUri)}' is already opened.`);
|
||||
// NOOP.
|
||||
return;
|
||||
}
|
||||
// Preserve the current window if the `sketch` is not in the `searchParams`.
|
||||
url.searchParams.set('sketch', uri);
|
||||
const hash = await this.fileSystem.getFsPath(sketchUri.toString());
|
||||
if (hash) {
|
||||
url.hash = hash;
|
||||
}
|
||||
if (!currentSketch) {
|
||||
setTimeout(() => window.location.href = url.toString(), 100);
|
||||
return;
|
||||
}
|
||||
this.windowService.openNewWindow(url.toString());
|
||||
}
|
||||
|
||||
async openSketchFiles(uri: string) {
|
||||
const fileStat = await this.fileSystem.getFileStat(uri);
|
||||
if (fileStat) {
|
||||
const uris = await this.sketches.getSketchFiles(fileStat);
|
||||
async openSketchFiles(uri: string): Promise<void> {
|
||||
this.sketchService.getSketchFiles(uri).then(uris => {
|
||||
for (const uri of uris) {
|
||||
this.editorManager.open(new URI(uri));
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -481,7 +438,7 @@ export class ArduinoFrontendContribution implements TabBarToolbarContribution, C
|
||||
if (destinationFile && !destinationFile.isDirectory) {
|
||||
const message = await this.validate(destinationFile);
|
||||
if (!message) {
|
||||
await this.openSketchFilesInNewWindow(destinationFileUri.toString());
|
||||
await this.workspaceService.openSketchFilesInNewWindow(destinationFileUri.toString());
|
||||
return destinationFileUri;
|
||||
} else {
|
||||
this.messageService.warn(message);
|
||||
|
||||
Reference in New Issue
Block a user