Skip to content

Commit 4adf008

Browse files
author
Akos Kitta
committed
fix: pulled up code
Signed-off-by: Akos Kitta <[email protected]>
1 parent d775c7d commit 4adf008

File tree

8 files changed

+143
-92
lines changed

8 files changed

+143
-92
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,7 @@ import { DebugConfigurationWidget } from '@theia/debug/lib/browser/view/debug-co
346346
import { ConfigServiceClient } from './config/config-service-client';
347347
import { ValidateSketch } from './contributions/validate-sketch';
348348
import { RenameCloudSketch } from './contributions/rename-cloud-sketch';
349+
import { CreateFeatures } from './create/create-features';
349350

350351
export default new ContainerModule((bind, unbind, isBound, rebind) => {
351352
// Commands and toolbar items
@@ -893,6 +894,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
893894
);
894895
bind(CreateApi).toSelf().inSingletonScope();
895896
bind(SketchCache).toSelf().inSingletonScope();
897+
bind(CreateFeatures).toSelf().inSingletonScope();
898+
bind(FrontendApplicationContribution).toService(CreateFeatures);
896899

897900
bind(ShareSketchDialog).toSelf().inSingletonScope();
898901
bind(AuthenticationClientService).toSelf().inSingletonScope();

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

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,6 @@ import { MessageType } from '@theia/core/lib/common/message-service-protocol';
6363
import { WorkspaceService } from '../theia/workspace/workspace-service';
6464
import { MainMenuManager } from '../../common/main-menu-manager';
6565
import { ConfigServiceClient } from '../config/config-service-client';
66-
import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider';
67-
import { CreateApi } from '../create/create-api';
6866

6967
export {
7068
Command,
@@ -200,18 +198,6 @@ export abstract class SketchContribution extends Contribution {
200198
}
201199
}
202200

203-
@injectable()
204-
export abstract class CloudSketchContribution extends SketchContribution {
205-
@inject(CreateApi)
206-
protected readonly createApi: CreateApi;
207-
@inject(LocalCacheFsProvider)
208-
protected readonly localCacheFsProvider: LocalCacheFsProvider;
209-
210-
protected cloudUri(sketch: Sketch): URI | undefined {
211-
return this.localCacheFsProvider.from(new URI(sketch.uri));
212-
}
213-
}
214-
215201
@injectable()
216202
export abstract class CoreServiceContribution extends SketchContribution {
217203
@inject(BoardsDataStore)
Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
import URI from '@theia/core/lib/common/uri';
2+
import { inject, injectable } from '@theia/core/shared/inversify';
3+
import { Sketch } from '../../common/protocol';
4+
import { CreateApi } from '../create/create-api';
5+
import { CreateFeatures } from '../create/create-features';
6+
import { LocalCacheFsProvider } from '../local-cache/local-cache-fs-provider';
7+
import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model';
8+
import { CloudSketchbookTreeWidget } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-widget';
9+
import { SketchbookWidget } from '../widgets/sketchbook/sketchbook-widget';
10+
import { SketchbookWidgetContribution } from '../widgets/sketchbook/sketchbook-widget-contribution';
11+
import { SketchContribution } from './contribution';
12+
13+
@injectable()
14+
export abstract class CloudSketchContribution extends SketchContribution {
15+
@inject(LocalCacheFsProvider)
16+
private readonly localCacheFsProvider: LocalCacheFsProvider;
17+
@inject(SketchbookWidgetContribution)
18+
private readonly widgetContribution: SketchbookWidgetContribution;
19+
@inject(CreateApi)
20+
protected readonly createApi: CreateApi;
21+
@inject(CreateFeatures)
22+
protected readonly createFeatures: CreateFeatures;
23+
24+
protected cloudUri(sketch: Sketch): URI | undefined {
25+
return this.localCacheFsProvider.from(new URI(sketch.uri));
26+
}
27+
28+
protected async treeModel(): Promise<CloudSketchbookTreeModel | undefined> {
29+
const { enabled, session } = this.createFeatures;
30+
if (enabled && session) {
31+
const widget = await this.widgetContribution.widget;
32+
const treeModel = this.treeModelFrom(widget);
33+
if (treeModel) {
34+
return treeModel;
35+
}
36+
}
37+
return undefined;
38+
}
39+
40+
treeModelFrom(
41+
widget: SketchbookWidget
42+
): CloudSketchbookTreeModel | undefined {
43+
for (const treeWidget of widget.getTreeWidgets()) {
44+
if (treeWidget instanceof CloudSketchbookTreeWidget) {
45+
const model = treeWidget.model;
46+
if (model instanceof CloudSketchbookTreeModel) {
47+
return model;
48+
}
49+
}
50+
}
51+
return undefined;
52+
}
53+
}

arduino-ide-extension/src/browser/contributions/delete-sketch.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,8 @@ import { inject, injectable } from '@theia/core/shared/inversify';
1111
import { SketchesError } from '../../common/protocol';
1212
import { Sketch } from '../contributions/contribution';
1313
import { isNotFound } from '../create/typings';
14-
import {
15-
Command,
16-
CommandRegistry,
17-
CloudSketchContribution,
18-
} from './contribution';
14+
import { Command, CommandRegistry } from './contribution';
15+
import { CloudSketchContribution } from './create-contribution';
1916

2017
export interface DeleteSketchParams {
2118
/**

arduino-ide-extension/src/browser/contributions/new-cloud-sketch.ts

Lines changed: 10 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -14,65 +14,29 @@ import {
1414
ProgressUpdate,
1515
} from '@theia/core/lib/common/message-service-protocol';
1616
import { nls } from '@theia/core/lib/common/nls';
17-
import { inject, injectable } from '@theia/core/shared/inversify';
17+
import { injectable } from '@theia/core/shared/inversify';
1818
import { WorkspaceInputDialogProps } from '@theia/workspace/lib/browser/workspace-input-dialog';
1919
import { v4 } from 'uuid';
20-
import type { AuthenticationSession } from '../../node/auth/types';
21-
import { AuthenticationClientService } from '../auth/authentication-client-service';
22-
import { CreateApi } from '../create/create-api';
2320
import { CreateUri } from '../create/create-uri';
2421
import { Create, isConflict, isNotFound } from '../create/typings';
2522
import { ArduinoMenus } from '../menu/arduino-menus';
2623
import { WorkspaceInputDialog } from '../theia/workspace/workspace-input-dialog';
2724
import { CloudSketchbookTree } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree';
2825
import { CloudSketchbookTreeModel } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-model';
29-
import { CloudSketchbookTreeWidget } from '../widgets/cloud-sketchbook/cloud-sketchbook-tree-widget';
3026
import { SketchbookCommands } from '../widgets/sketchbook/sketchbook-commands';
31-
import { SketchbookWidget } from '../widgets/sketchbook/sketchbook-widget';
32-
import { SketchbookWidgetContribution } from '../widgets/sketchbook/sketchbook-widget-contribution';
33-
import {
34-
Command,
35-
CommandRegistry,
36-
Contribution,
37-
Sketch,
38-
URI,
39-
} from './contribution';
27+
import { Command, CommandRegistry, Sketch, URI } from './contribution';
28+
import { CloudSketchContribution } from './create-contribution';
4029

4130
@injectable()
42-
export class NewCloudSketch extends Contribution {
43-
@inject(CreateApi)
44-
private readonly createApi: CreateApi;
45-
@inject(SketchbookWidgetContribution)
46-
private readonly widgetContribution: SketchbookWidgetContribution;
47-
@inject(AuthenticationClientService)
48-
private readonly authenticationService: AuthenticationClientService;
49-
31+
export class NewCloudSketch extends CloudSketchContribution {
5032
private readonly toDispose = new DisposableCollection();
51-
private _session: AuthenticationSession | undefined;
52-
private _enabled: boolean;
5333

5434
override onReady(): void {
5535
this.toDispose.pushAll([
56-
this.authenticationService.onSessionDidChange((session) => {
57-
const oldSession = this._session;
58-
this._session = session;
59-
if (!!oldSession !== !!this._session) {
60-
this.menuManager.update();
61-
}
62-
}),
63-
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
64-
if (preferenceName === 'arduino.cloud.enabled') {
65-
const oldEnabled = this._enabled;
66-
this._enabled = Boolean(newValue);
67-
if (this._enabled !== oldEnabled) {
68-
this.menuManager.update();
69-
}
70-
}
71-
}),
36+
this.createFeatures.onDidChangeEnabled(() => this.menuManager.update()),
37+
this.createFeatures.onDidChangeSession(() => this.menuManager.update()),
7238
]);
73-
this._enabled = this.preferences['arduino.cloud.enabled'];
74-
this._session = this.authenticationService.session;
75-
if (this._session) {
39+
if (this.createFeatures.session) {
7640
this.menuManager.update();
7741
}
7842
}
@@ -84,8 +48,8 @@ export class NewCloudSketch extends Contribution {
8448
override registerCommands(registry: CommandRegistry): void {
8549
registry.registerCommand(NewCloudSketch.Commands.NEW_CLOUD_SKETCH, {
8650
execute: () => this.createNewSketch(),
87-
isEnabled: () => !!this._session,
88-
isVisible: () => this._enabled,
51+
isEnabled: () => Boolean(this.createFeatures.session),
52+
isVisible: () => this.createFeatures.enabled,
8953
});
9054
}
9155

@@ -107,8 +71,7 @@ export class NewCloudSketch extends Contribution {
10771
private async createNewSketch(
10872
initialValue?: string | undefined
10973
): Promise<unknown> {
110-
const widget = await this.widgetContribution.widget;
111-
const treeModel = this.treeModelFrom(widget);
74+
const treeModel = await this.treeModel();
11275
if (!treeModel) {
11376
return undefined;
11477
}
@@ -202,20 +165,6 @@ export class NewCloudSketch extends Contribution {
202165
);
203166
}
204167

205-
private treeModelFrom(
206-
widget: SketchbookWidget
207-
): CloudSketchbookTreeModel | undefined {
208-
for (const treeWidget of widget.getTreeWidgets()) {
209-
if (treeWidget instanceof CloudSketchbookTreeWidget) {
210-
const model = treeWidget.model;
211-
if (model instanceof CloudSketchbookTreeModel) {
212-
return model;
213-
}
214-
}
215-
}
216-
return undefined;
217-
}
218-
219168
private async openWizard(
220169
rootNode: CompositeTreeNode,
221170
treeModel: CloudSketchbookTreeModel,

arduino-ide-extension/src/browser/contributions/rename-cloud-sketch.ts

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,21 @@
11
import { injectable } from '@theia/core/shared/inversify';
2-
import {
3-
Command,
4-
CommandRegistry,
5-
Sketch,
6-
SketchContribution,
7-
URI,
8-
} from './contribution';
2+
import { Command, CommandRegistry, Sketch, URI } from './contribution';
3+
import { CloudSketchContribution } from './create-contribution';
94

105
export interface RenameCloudSketchParams {
116
readonly cloudUri: URI;
127
readonly sketch: Sketch;
138
}
149

1510
@injectable()
16-
export class RenameCloudSketch extends SketchContribution {
11+
export class RenameCloudSketch extends CloudSketchContribution {
1712
override registerCommands(registry: CommandRegistry): void {
1813
registry.registerCommand(RenameCloudSketch.Commands.RENAME_CLOUD_SKETCH, {
19-
execute: (params: RenameCloudSketchParams) =>
20-
this.renameCloudSketch(params),
14+
execute: (params: RenameCloudSketchParams) => this.rename(params),
2115
});
2216
}
2317

24-
private async renameCloudSketch(
18+
private async rename(
2519
params: RenameCloudSketchParams
2620
): Promise<URI | undefined> {
2721
return undefined;

arduino-ide-extension/src/browser/contributions/save-as-sketch.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,13 @@ import * as dateFormat from 'dateformat';
44
import { ArduinoMenus } from '../menu/arduino-menus';
55
import {
66
Sketch,
7-
CloudSketchContribution,
87
URI,
98
Command,
109
CommandRegistry,
1110
MenuModelRegistry,
1211
KeybindingRegistry,
1312
} from './contribution';
13+
import { CloudSketchContribution } from "./create-contribution";
1414
import { nls } from '@theia/core/lib/common';
1515
import { ApplicationShell, NavigatableWidget, Saveable } from '@theia/core/lib/browser';
1616
import { WindowService } from '@theia/core/lib/browser/window/window-service';
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
import { FrontendApplicationContribution } from '@theia/core/lib/browser';
2+
import { DisposableCollection } from '@theia/core/lib/common/disposable';
3+
import { Emitter, Event } from '@theia/core/lib/common/event';
4+
import { inject, injectable } from '@theia/core/shared/inversify';
5+
import { AuthenticationSession } from '../../node/auth/types';
6+
import { ArduinoPreferences } from '../arduino-preferences';
7+
import { AuthenticationClientService } from '../auth/authentication-client-service';
8+
9+
@injectable()
10+
export class CreateFeatures implements FrontendApplicationContribution {
11+
@inject(ArduinoPreferences)
12+
private readonly preferences: ArduinoPreferences;
13+
@inject(AuthenticationClientService)
14+
private readonly authenticationService: AuthenticationClientService;
15+
16+
private readonly onDidChangeSessionEmitter = new Emitter<
17+
AuthenticationSession | undefined
18+
>();
19+
private readonly onDidChangeEnabledEmitter = new Emitter<boolean>();
20+
private readonly toDispose = new DisposableCollection(
21+
this.onDidChangeSessionEmitter,
22+
this.onDidChangeEnabledEmitter
23+
);
24+
private _enabled: boolean;
25+
private _session: AuthenticationSession | undefined;
26+
27+
onStart(): void {
28+
this.toDispose.pushAll([
29+
this.authenticationService.onSessionDidChange((session) => {
30+
const oldSession = this._session;
31+
this._session = session;
32+
if (!!oldSession !== !!this._session) {
33+
this.onDidChangeSessionEmitter.fire(this._session);
34+
}
35+
}),
36+
this.preferences.onPreferenceChanged(({ preferenceName, newValue }) => {
37+
if (preferenceName === 'arduino.cloud.enabled') {
38+
const oldEnabled = this._enabled;
39+
this._enabled = Boolean(newValue);
40+
if (this._enabled !== oldEnabled) {
41+
this.onDidChangeEnabledEmitter.fire(this._enabled);
42+
}
43+
}
44+
}),
45+
]);
46+
this._enabled = this.preferences['arduino.cloud.enabled'];
47+
this._session = this.authenticationService.session;
48+
}
49+
50+
onStop(): void {
51+
this.toDispose.dispose();
52+
}
53+
54+
get onDidChangeSession(): Event<AuthenticationSession | undefined> {
55+
return this.onDidChangeSessionEmitter.event;
56+
}
57+
58+
get onDidChangeEnabled(): Event<boolean> {
59+
return this.onDidChangeEnabledEmitter.event;
60+
}
61+
62+
get enabled(): boolean {
63+
return this._enabled;
64+
}
65+
66+
get session(): AuthenticationSession | undefined {
67+
return this._session;
68+
}
69+
}

0 commit comments

Comments
 (0)