Skip to content

Commit 1ec3663

Browse files
author
Akos Kitta
committed
fix: simplify sketchbook menu enablement
Signed-off-by: Akos Kitta <[email protected]>
1 parent b4701ab commit 1ec3663

File tree

2 files changed

+19
-31
lines changed

2 files changed

+19
-31
lines changed

arduino-ide-extension/src/browser/contributions/sketchbook.ts

Lines changed: 18 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import { injectable } from '@theia/core/shared/inversify';
2-
import { Disposable } from '@theia/core/lib/common/disposable';
32
import { CommandHandler } from '@theia/core/lib/common/command';
3+
import { MenuModelRegistry } from './contribution';
44
import { ArduinoMenus } from '../menu/arduino-menus';
55
import { Examples } from './examples';
6-
import { SketchesError } from '../../common/protocol';
6+
import { SketchContainer, SketchesError } from '../../common/protocol';
77
import { OpenSketch } from './open-sketch';
88
import { nls } from '@theia/core/lib/common/nls';
99

@@ -19,39 +19,27 @@ export class Sketchbook extends Examples {
1919
}
2020

2121
protected override update(): void {
22-
this.toDispose.dispose();
23-
this.menuRegistry.registerSubmenu(
22+
this.sketchService.getSketches({}).then((container) => {
23+
this.register(container);
24+
this.menuManager.update();
25+
});
26+
}
27+
28+
override registerMenus(registry: MenuModelRegistry): void {
29+
registry.registerSubmenu(
2430
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
2531
nls.localize('arduino/sketch/sketchbook', 'Sketchbook'),
2632
{ order: '3' }
2733
);
28-
this.toDispose.push(
29-
Disposable.create(() =>
30-
this.menuRegistry.unregisterMenuNode(
31-
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU[
32-
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU.length - 1
33-
]
34-
// It's not possible to unregister submenu in Theia https://github.com/eclipse-theia/theia/issues/7300
35-
// This workaround relies on how Theia calculates menu ID from the menu path.
36-
)
37-
)
34+
}
35+
36+
private register(container: SketchContainer): void {
37+
this.toDispose.dispose();
38+
this.registerRecursively(
39+
[...container.children, ...container.sketches],
40+
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
41+
this.toDispose
3842
);
39-
const sketchDirUri = this.configService.tryGetSketchDirUri();
40-
const messages = this.configService.tryGetMessages();
41-
if (!sketchDirUri || messages?.length) {
42-
this.menuManager.update();
43-
return;
44-
}
45-
this.sketchService
46-
.getSketches({ uri: sketchDirUri?.toString() })
47-
.then((container) => {
48-
this.registerRecursively(
49-
[...container.children, ...container.sketches],
50-
ArduinoMenus.FILE__SKETCHBOOK_SUBMENU,
51-
this.toDispose
52-
);
53-
this.menuManager.update();
54-
});
5543
}
5644

5745
protected override createHandler(uri: string): CommandHandler {

arduino-ide-extension/src/common/protocol/sketches-service-client-impl.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ import {
1010
DisposableCollection,
1111
} from '@theia/core/lib/common/disposable';
1212
import { FrontendApplicationContribution } from '@theia/core/lib/browser/frontend-application';
13-
import { ConfigServiceClient } from '../../browser/config/config-service-client';
1413
import { Sketch, SketchesService } from '.';
14+
import { ConfigServiceClient } from '../../browser/config/config-service-client';
1515
import { SketchContainer, SketchesError, SketchRef } from './sketches-service';
1616
import {
1717
ARDUINO_CLOUD_FOLDER,

0 commit comments

Comments
 (0)