mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-07-24 11:46:32 +00:00
generalized which widgets are closeable.
instead of a whitelisting, we blacklist the files those belong to sketch Signed-off-by: Akos Kitta <kittaakos@typefox.io>
This commit is contained in:
parent
fc866464ad
commit
3d55aaa875
@ -2,10 +2,11 @@
|
||||
import { injectable, inject } from 'inversify';
|
||||
import { EditorWidget } from '@theia/editor/lib/browser';
|
||||
import { CommandService } from '@theia/core/lib/common/command';
|
||||
import { PreferencesWidget } from '@theia/preferences/lib/browser/views/preference-widget';
|
||||
import { ApplicationShell as TheiaApplicationShell, Widget } from '@theia/core/lib/browser';
|
||||
import { Sketch } from '../../../common/protocol';
|
||||
import { EditorMode } from '../../editor-mode';
|
||||
import { SaveAsSketch } from '../../contributions/save-as-sketch';
|
||||
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
|
||||
|
||||
@injectable()
|
||||
export class ApplicationShell extends TheiaApplicationShell {
|
||||
@ -16,26 +17,33 @@ export class ApplicationShell extends TheiaApplicationShell {
|
||||
@inject(CommandService)
|
||||
protected readonly commandService: CommandService;
|
||||
|
||||
protected track(widget: Widget): void {
|
||||
super.track(widget);
|
||||
if (!this.editorMode.proMode) {
|
||||
if (widget instanceof EditorWidget) {
|
||||
// Always allow closing the whitelisted files.
|
||||
// TODO: It would be better to blacklist the sketch files only.
|
||||
if (['tasks.json',
|
||||
'launch.json',
|
||||
'settings.json',
|
||||
'arduino-cli.yaml'].some(fileName => widget.editor.uri.toString().endsWith(fileName))) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (widget instanceof PreferencesWidget) {
|
||||
return;
|
||||
}
|
||||
widget.title.closable = false;
|
||||
}
|
||||
@inject(SketchesServiceClientImpl)
|
||||
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
|
||||
|
||||
protected sketch?: Sketch;
|
||||
|
||||
async addWidget(widget: Widget, options: Readonly<TheiaApplicationShell.WidgetOptions> = {}): Promise<void> {
|
||||
// Get the current sketch before adding a widget. This wil trigger an update.
|
||||
this.sketch = await this.sketchesServiceClient.currentSketch();
|
||||
super.addWidget(widget, options);
|
||||
}
|
||||
|
||||
async setLayoutData(layoutData: TheiaApplicationShell.LayoutData): Promise<void> {
|
||||
// I could not find other ways to get sketch in async fashion for sync `track`.
|
||||
this.sketch = await this.sketchesServiceClient.currentSketch();
|
||||
super.setLayoutData(layoutData);
|
||||
}
|
||||
|
||||
track(widget: Widget): void {
|
||||
if (!this.editorMode.proMode && this.sketch && widget instanceof EditorWidget) {
|
||||
if (Sketch.isInSketch(widget.editor.uri, this.sketch)) {
|
||||
widget.title.closable = false;
|
||||
}
|
||||
}
|
||||
super.track(widget);
|
||||
}
|
||||
|
||||
|
||||
async saveAll(): Promise<void> {
|
||||
await super.saveAll();
|
||||
await this.commandService.executeCommand(SaveAsSketch.Commands.SAVE_AS_SKETCH.id, { execOnlyIfTemp: true, openAfterMove: true });
|
||||
|
@ -1,3 +1,5 @@
|
||||
import URI from '@theia/core/lib/common/uri';
|
||||
|
||||
export const SketchesServicePath = '/services/sketches-service';
|
||||
export const SketchesService = Symbol('SketchesService');
|
||||
export interface SketchesService {
|
||||
@ -60,9 +62,9 @@ export namespace Sketch {
|
||||
export const ADDITIONAL = ['.h', '.c', '.hpp', '.hh', '.cpp', '.s'];
|
||||
export const ALL = Array.from(new Set([...MAIN, ...SOURCE, ...ADDITIONAL]));
|
||||
}
|
||||
export function isInSketch(uri: string, sketch: Sketch): boolean {
|
||||
export function isInSketch(uri: string | URI, sketch: Sketch): boolean {
|
||||
const { mainFileUri, otherSketchFileUris, additionalFileUris } = sketch;
|
||||
return [mainFileUri, ...otherSketchFileUris, additionalFileUris].indexOf(uri) !== -1;
|
||||
return [mainFileUri, ...otherSketchFileUris, additionalFileUris].indexOf(uri.toString()) !== -1;
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user