Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

#1016, #1274 Aligned the "Save your sketch" dialog behavior #1351

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Aug 26, 2022
Prev Previous commit
Next Next commit
Moved uncloseable widget tracking to manager.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
  • Loading branch information
Akos Kitta committed Aug 26, 2022
commit 20020dcfc398dccbabee35212d4ff0701c7d7b21
55 changes: 8 additions & 47 deletions 55 arduino-ide-extension/src/browser/theia/core/application-shell.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,30 @@
import { injectable, inject } from '@theia/core/shared/inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { MessageService } from '@theia/core/lib/common/message-service';
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
import {
ConnectionStatusService,
ConnectionStatus,
} from '@theia/core/lib/browser/connection-status-service';
import {
ApplicationShell as TheiaApplicationShell,
DockPanel,
DockPanelRenderer as TheiaDockPanelRenderer,
Panel,
SaveOptions,
SHELL_TABBAR_CONTEXT_MENU,
TabBar,
Widget,
SHELL_TABBAR_CONTEXT_MENU,
SaveOptions,
} from '@theia/core/lib/browser';
import { Sketch } from '../../../common/protocol';
import {
CurrentSketch,
SketchesServiceClientImpl,
} from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/common';
import URI from '@theia/core/lib/common/uri';
ConnectionStatus,
ConnectionStatusService,
} from '@theia/core/lib/browser/connection-status-service';
import { nls } from '@theia/core/lib/common/nls';
import { MessageService } from '@theia/core/lib/common/message-service';
import { inject, injectable } from '@theia/core/shared/inversify';
import { ToolbarAwareTabBar } from './tab-bars';

@injectable()
export class ApplicationShell extends TheiaApplicationShell {
@inject(MessageService)
private readonly messageService: MessageService;

@inject(SketchesServiceClientImpl)
private readonly sketchesServiceClient: SketchesServiceClientImpl;

@inject(ConnectionStatusService)
private readonly connectionStatusService: ConnectionStatusService;

protected override track(widget: Widget): void {
super.track(widget);
if (widget instanceof OutputWidget) {
widget.title.closable = false; // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
}
if (widget instanceof EditorWidget) {
// Make the editor un-closeable asynchronously.
this.sketchesServiceClient.currentSketch().then((sketch) => {
if (CurrentSketch.isValid(sketch)) {
if (!this.isSketchFile(widget.editor.uri, sketch.uri)) {
return;
}
if (Sketch.isInSketch(widget.editor.uri, sketch)) {
widget.title.closable = false;
}
}
});
}
}

private isSketchFile(uri: URI, sketchUriString: string): boolean {
const sketchUri = new URI(sketchUriString);
if (uri.parent.isEqual(sketchUri)) {
return true;
}
return false;
}

override async addWidget(
widget: Widget,
options: Readonly<TheiaApplicationShell.WidgetOptions> = {}
Expand Down
54 changes: 43 additions & 11 deletions 54 arduino-ide-extension/src/browser/theia/core/widget-manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
postConstruct,
} from '@theia/core/shared/inversify';
import { EditorWidget } from '@theia/editor/lib/browser';
import { OutputWidget } from '@theia/output/lib/browser/output-widget';
import deepEqual = require('deep-equal');
import {
CurrentSketch,
Expand All @@ -21,19 +22,50 @@ export class WidgetManager extends TheiaWidgetManager {

@postConstruct()
protected init(): void {
this.sketchesServiceClient.onCurrentSketchDidChange((currentSketch) => {
if (CurrentSketch.isValid(currentSketch)) {
const sketchFileUris = new Set(Sketch.uris(currentSketch));
for (const widget of this.widgets.values()) {
if (widget instanceof EditorWidget) {
const uri = widget.editor.uri.toString();
if (sketchFileUris.has(uri)) {
widget.title.closable = false;
}
}
this.sketchesServiceClient.onCurrentSketchDidChange((sketch) =>
this.maybeSetWidgetUncloseable(
sketch,
...Array.from(this.widgets.values())
)
);
}

override getOrCreateWidget<T extends Widget>(
factoryId: string,
options?: unknown
): Promise<T> {
const unresolvedWidget = super.getOrCreateWidget<T>(factoryId, options);
unresolvedWidget.then(async (widget) => {
const sketch = await this.sketchesServiceClient.currentSketch();
this.maybeSetWidgetUncloseable(sketch, widget);
});
return unresolvedWidget;
}

private maybeSetWidgetUncloseable(
sketch: CurrentSketch,
...widgets: Widget[]
): void {
const sketchFileUris =
CurrentSketch.isValid(sketch) && new Set(Sketch.uris(sketch));
for (const widget of widgets) {
if (widget instanceof OutputWidget) {
this.setWidgetUncloseable(widget); // TODO: https://arduino.slack.com/archives/C01698YT7S4/p1598011990133700
} else if (widget instanceof EditorWidget) {
// Make the editor un-closeable asynchronously.
const uri = widget.editor.uri.toString();
if (!!sketchFileUris && sketchFileUris.has(uri)) {
this.setWidgetUncloseable(widget);
}
}
});
}
}

private setWidgetUncloseable(widget: Widget): void {
const { title } = widget;
if (title.closable) {
title.closable = false;
}
}

/**
Expand Down
Morty Proxy This is a proxified and sanitized view of the page, visit original site.