Skip to content

Commit f5a1f9e

Browse files
author
Akos Kitta
committed
tracking the sketch files has its own module.
Signed-off-by: Akos Kitta <a.kitta@arduino.cc>
1 parent cba1802 commit f5a1f9e

File tree

3 files changed

+72
-74
lines changed

3 files changed

+72
-74
lines changed

arduino-ide-extension/src/browser/arduino-frontend-contribution.tsx

Lines changed: 1 addition & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,9 @@ import {
55
postConstruct,
66
} from '@theia/core/shared/inversify';
77
import * as React from '@theia/core/shared/react';
8-
import { SketchesService, Sketch } from '../common/protocol';
8+
import { SketchesService } from '../common/protocol';
99

1010
import {
11-
DisposableCollection,
1211
MAIN_MENU_BAR,
1312
MenuContribution,
1413
MenuModelRegistry,
@@ -17,14 +16,11 @@ import {
1716
Dialog,
1817
FrontendApplication,
1918
FrontendApplicationContribution,
20-
LocalStorageService,
2119
OnWillStopAction,
22-
SaveableWidget,
2320
} from '@theia/core/lib/browser';
2421
import { ColorContribution } from '@theia/core/lib/browser/color-application-contribution';
2522
import { ColorRegistry } from '@theia/core/lib/browser/color-registry';
2623
import { CommonMenus } from '@theia/core/lib/browser/common-frontend-contribution';
27-
import { FrontendApplicationStateService } from '@theia/core/lib/browser/frontend-application-state';
2824
import {
2925
TabBarToolbarContribution,
3026
TabBarToolbarRegistry,
@@ -35,11 +31,7 @@ import {
3531
CommandRegistry,
3632
} from '@theia/core/lib/common/command';
3733
import { MessageService } from '@theia/core/lib/common/message-service';
38-
import URI from '@theia/core/lib/common/uri';
3934
import { EditorCommands, EditorMainMenu } from '@theia/editor/lib/browser';
40-
import { FileChangeType } from '@theia/filesystem/lib/browser';
41-
import { FileService } from '@theia/filesystem/lib/browser/file-service';
42-
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
4335
import { MonacoMenus } from '@theia/monaco/lib/browser/monaco-menu';
4436
import { FileNavigatorCommands } from '@theia/navigator/lib/browser/navigator-contribution';
4537
import { TerminalMenus } from '@theia/terminal/lib/browser/terminal-frontend-contribution';
@@ -50,7 +42,6 @@ import {
5042
import { ArduinoPreferences } from './arduino-preferences';
5143
import { BoardsServiceProvider } from './boards/boards-service-provider';
5244
import { BoardsToolBarItem } from './boards/boards-toolbar-item';
53-
import { OpenSketchFiles } from './contributions/open-sketch-files';
5445
import { SaveAsSketch } from './contributions/save-as-sketch';
5546
import { ArduinoMenus } from './menu/arduino-menus';
5647
import { MonitorViewContribution } from './serial/monitor/monitor-view-contribution';
@@ -73,9 +64,6 @@ export class ArduinoFrontendContribution
7364
@inject(BoardsServiceProvider)
7465
private readonly boardsServiceProvider: BoardsServiceProvider;
7566

76-
@inject(FileService)
77-
private readonly fileService: FileService;
78-
7967
@inject(SketchesService)
8068
private readonly sketchService: SketchesService;
8169

@@ -88,17 +76,6 @@ export class ArduinoFrontendContribution
8876
@inject(SketchesServiceClientImpl)
8977
private readonly sketchServiceClient: SketchesServiceClientImpl;
9078

91-
@inject(FrontendApplicationStateService)
92-
private readonly appStateService: FrontendApplicationStateService;
93-
94-
@inject(LocalStorageService)
95-
private readonly localStorageService: LocalStorageService;
96-
97-
@inject(FileSystemFrontendContribution)
98-
private readonly fileSystemFrontendContribution: FileSystemFrontendContribution;
99-
100-
protected toDisposeOnStop = new DisposableCollection();
101-
10279
@postConstruct()
10380
protected async init(): Promise<void> {
10481
if (!window.navigator.onLine) {
@@ -110,39 +87,6 @@ export class ArduinoFrontendContribution
11087
)
11188
);
11289
}
113-
this.appStateService.reachedState('ready').then(async () => {
114-
const sketch = await this.sketchServiceClient.currentSketch();
115-
if (
116-
CurrentSketch.isValid(sketch) &&
117-
!(await this.sketchService.isTemp(sketch))
118-
) {
119-
this.toDisposeOnStop.push(this.fileService.watch(new URI(sketch.uri)));
120-
this.toDisposeOnStop.push(
121-
this.fileService.onDidFilesChange(async (event) => {
122-
for (const { type, resource } of event.changes) {
123-
if (
124-
type === FileChangeType.ADDED &&
125-
resource.parent.toString() === sketch.uri
126-
) {
127-
const reloadedSketch = await this.sketchService.loadSketch(
128-
sketch.uri
129-
);
130-
if (Sketch.isInSketch(resource, reloadedSketch)) {
131-
this.commandRegistry.executeCommand(
132-
OpenSketchFiles.Commands.ENSURE_OPENED.id,
133-
resource.toString(),
134-
true,
135-
{
136-
mode: 'open',
137-
}
138-
);
139-
}
140-
}
141-
}
142-
})
143-
);
144-
}
145-
});
14690
}
14791

14892
async onStart(app: FrontendApplication): Promise<void> {
@@ -171,23 +115,6 @@ export class ArduinoFrontendContribution
171115

172116
// Removes the _Settings_ (cog) icon from the left sidebar
173117
app.shell.leftPanelHandler.removeBottomMenu('settings-menu');
174-
175-
this.fileSystemFrontendContribution.onDidChangeEditorFile(
176-
({ type, editor }) => {
177-
if (type === FileChangeType.DELETED) {
178-
const editorWidget = editor;
179-
if (SaveableWidget.is(editorWidget)) {
180-
editorWidget.closeWithoutSaving();
181-
} else {
182-
editorWidget.close();
183-
}
184-
}
185-
}
186-
);
187-
}
188-
189-
onStop(): void {
190-
this.toDisposeOnStop.dispose();
191118
}
192119

193120
registerToolbarItems(registry: TabBarToolbarRegistry): void {

arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -310,6 +310,7 @@ import { InoLanguage } from './contributions/ino-language';
310310
import { SelectedBoard } from './contributions/selected-board';
311311
import { CheckForUpdates } from './contributions/check-for-updates';
312312
import { OpenBoardsConfig } from './contributions/open-boards-config';
313+
import { SketchFilesTracker } from './contributions/sketch-files-tracker';
313314

314315
MonacoThemingService.register({
315316
id: 'arduino-theme',
@@ -709,6 +710,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
709710
Contribution.configure(bind, SelectedBoard);
710711
Contribution.configure(bind, CheckForUpdates);
711712
Contribution.configure(bind, OpenBoardsConfig);
713+
Contribution.configure(bind, SketchFilesTracker);
712714

713715
// Disabled the quick-pick customization from Theia when multiple formatters are available.
714716
// Use the default VS Code behavior, and pick the first one. In the IDE2, clang-format has `exclusive` selectors.
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { SaveableWidget } from '@theia/core/lib/browser/saveable';
2+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
3+
import { inject, injectable } from '@theia/core/shared/inversify';
4+
import { FileSystemFrontendContribution } from '@theia/filesystem/lib/browser/filesystem-frontend-contribution';
5+
import { FileChangeType } from '@theia/filesystem/lib/common/files';
6+
import { CurrentSketch } from '../../common/protocol/sketches-service-client-impl';
7+
import { Sketch, SketchContribution, URI } from './contribution';
8+
import { OpenSketchFiles } from './open-sketch-files';
9+
10+
@injectable()
11+
export class SketchFilesTracker extends SketchContribution {
12+
@inject(FileSystemFrontendContribution)
13+
private readonly fileSystemFrontendContribution: FileSystemFrontendContribution;
14+
private readonly toDisposeOnStop = new DisposableCollection();
15+
16+
override onStart(): void {
17+
this.fileSystemFrontendContribution.onDidChangeEditorFile(
18+
({ type, editor }) => {
19+
if (type === FileChangeType.DELETED) {
20+
const editorWidget = editor;
21+
if (SaveableWidget.is(editorWidget)) {
22+
editorWidget.closeWithoutSaving();
23+
} else {
24+
editorWidget.close();
25+
}
26+
}
27+
}
28+
);
29+
}
30+
31+
override onReady(): void {
32+
this.sketchServiceClient.currentSketch().then(async (sketch) => {
33+
if (
34+
CurrentSketch.isValid(sketch) &&
35+
!(await this.sketchService.isTemp(sketch))
36+
) {
37+
this.toDisposeOnStop.push(this.fileService.watch(new URI(sketch.uri)));
38+
this.toDisposeOnStop.push(
39+
this.fileService.onDidFilesChange(async (event) => {
40+
for (const { type, resource } of event.changes) {
41+
if (
42+
type === FileChangeType.ADDED &&
43+
resource.parent.toString() === sketch.uri
44+
) {
45+
const reloadedSketch = await this.sketchService.loadSketch(
46+
sketch.uri
47+
);
48+
if (Sketch.isInSketch(resource, reloadedSketch)) {
49+
this.commandService.executeCommand(
50+
OpenSketchFiles.Commands.ENSURE_OPENED.id,
51+
resource.toString(),
52+
true,
53+
{
54+
mode: 'open',
55+
}
56+
);
57+
}
58+
}
59+
}
60+
})
61+
);
62+
}
63+
});
64+
}
65+
66+
onStop(): void {
67+
this.toDisposeOnStop.dispose();
68+
}
69+
}

0 commit comments

Comments
 (0)