Skip to content

Commit b6af6f3

Browse files
author
Alberto Iannaccone
committed
fix active sketchbook behavior in sidebar
1 parent 8cac087 commit b6af6f3

File tree

4 files changed

+54
-12
lines changed

4 files changed

+54
-12
lines changed

Diff for: arduino-ide-extension/src/browser/local-cache/local-cache-fs-provider.ts

+5-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,10 @@ import {
1616
import { AuthenticationClientService } from '../auth/authentication-client-service';
1717
import { AuthenticationSession } from '../../common/protocol/authentication-service';
1818
import { ConfigService } from '../../common/protocol';
19+
import {
20+
ARDUINO_CLOUD_FOLDER,
21+
REMOTE_SKETCHBOOK_FOLDER,
22+
} from '../utils/constants';
1923

2024
export namespace LocalCacheUri {
2125
export const scheme = 'arduino-local-cache';
@@ -91,7 +95,7 @@ export class LocalCacheFsProvider
9195
protected async init(fileService: FileService): Promise<void> {
9296
const config = await this.configService.getConfiguration();
9397
this._localCacheRoot = new URI(config.dataDirUri);
94-
for (const segment of ['RemoteSketchbook', 'ArduinoCloud']) {
98+
for (const segment of [REMOTE_SKETCHBOOK_FOLDER, ARDUINO_CLOUD_FOLDER]) {
9599
this._localCacheRoot = this._localCacheRoot.resolve(segment);
96100
await fileService.createFolder(this._localCacheRoot);
97101
}

Diff for: arduino-ide-extension/src/browser/utils/constants.ts

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
export const REMOTE_SKETCHBOOK_FOLDER = 'RemoteSketchbook';
2+
export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud';

Diff for: arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx

+14
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,20 @@ export class CloudSketchbookCompositeWidget extends BaseWidget {
5858
);
5959
}
6060

61+
protected onActivateRequest(msg: Message): void {
62+
super.onActivateRequest(msg);
63+
this.cloudSketchbookTreeWidget.activate();
64+
65+
/*
66+
Sending a resize message is needed because otherwise the cloudSketchbookTreeWidget
67+
would render empty
68+
*/
69+
MessageLoop.sendMessage(
70+
this.cloudSketchbookTreeWidget,
71+
Widget.ResizeMessage.UnknownSize
72+
);
73+
}
74+
6175
protected onResize(message: Widget.ResizeMessage): void {
6276
super.onResize(message);
6377
MessageLoop.sendMessage(

Diff for: arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts

+33-11
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,11 @@ import { inject, injectable, postConstruct } from 'inversify';
22
import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget';
33
import { SketchbookWidget } from '../sketchbook/sketchbook-widget';
44
import { ArduinoPreferences } from '../../arduino-preferences';
5+
import { Message } from '@theia/core/shared/@phosphor/messaging';
6+
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
7+
import { SketchControl } from '../../contributions/sketch-control';
8+
import { LocalCacheFsProvider } from '../../local-cache/local-cache-fs-provider';
9+
import { REMOTE_SKETCHBOOK_FOLDER } from '../../utils/constants';
510

611
@injectable()
712
export class CloudSketchbookWidget extends SketchbookWidget {
@@ -11,6 +16,15 @@ export class CloudSketchbookWidget extends SketchbookWidget {
1116
@inject(ArduinoPreferences)
1217
protected readonly arduinoPreferences: ArduinoPreferences;
1318

19+
@inject(SketchControl)
20+
protected readonly sketchControl: SketchControl;
21+
22+
@inject(SketchesServiceClientImpl)
23+
protected readonly sketchesServiceClient: SketchesServiceClientImpl;
24+
25+
@inject(LocalCacheFsProvider)
26+
protected readonly localCacheFsProvider: LocalCacheFsProvider;
27+
1428
@postConstruct()
1529
protected init(): void {
1630
super.init();
@@ -25,33 +39,41 @@ export class CloudSketchbookWidget extends SketchbookWidget {
2539
return widget;
2640
}
2741

28-
checkCloudEnabled() {
29-
if (this.arduinoPreferences['arduino.cloud.enabled']) {
30-
this.sketchbookTreesContainer.activateWidget(this.widget);
31-
} else {
32-
this.sketchbookTreesContainer.activateWidget(
33-
this.localSketchbookTreeWidget
34-
);
35-
}
36-
this.setDocumentMode();
42+
protected onAfterShow(msg: Message): void {
43+
this.checkCloudEnabled();
44+
super.onAfterShow(msg);
3745
}
3846

39-
setDocumentMode() {
47+
async checkCloudEnabled(): Promise<void> {
48+
const currentSketch = await this.sketchesServiceClient.currentSketch();
49+
const isCloudSketch =
50+
currentSketch && currentSketch.uri.includes(REMOTE_SKETCHBOOK_FOLDER);
51+
4052
if (this.arduinoPreferences['arduino.cloud.enabled']) {
4153
this.sketchbookTreesContainer.mode = 'multiple-document';
54+
if (isCloudSketch) {
55+
this.sketchbookTreesContainer.activateWidget(this.widget);
56+
}
4257
} else {
4358
this.sketchbookTreesContainer.mode = 'single-document';
4459
}
60+
61+
if (!isCloudSketch || !this.arduinoPreferences['arduino.cloud.enabled']) {
62+
this.sketchbookTreesContainer.activateWidget(
63+
this.localSketchbookTreeWidget
64+
);
65+
}
4566
}
4667

4768
protected onAfterAttach(msg: any) {
4869
this.sketchbookTreesContainer.addWidget(this.widget);
49-
this.setDocumentMode();
70+
this.sketchbookTreesContainer.mode = 'single-document';
5071
this.arduinoPreferences.onPreferenceChanged((event) => {
5172
if (event.preferenceName === 'arduino.cloud.enabled') {
5273
this.checkCloudEnabled();
5374
}
5475
});
76+
this.checkCloudEnabled();
5577
super.onAfterAttach(msg);
5678
}
5779
}

0 commit comments

Comments
 (0)