diff --git a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts index d52969253..d6b4ce428 100644 --- a/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts +++ b/arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts @@ -812,7 +812,7 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => { bindViewContribution(bind, SketchbookWidgetContribution); bind(FrontendApplicationContribution).toService(SketchbookWidgetContribution); bind(WidgetFactory).toDynamicValue(({ container }) => ({ - id: 'arduino-sketchbook-widget', + id: SketchbookWidget.ID, createWidget: () => container.get(SketchbookWidget), })); diff --git a/arduino-ide-extension/src/browser/local-cache/local-cache-fs-provider.ts b/arduino-ide-extension/src/browser/local-cache/local-cache-fs-provider.ts index 96264378a..0400ceba2 100644 --- a/arduino-ide-extension/src/browser/local-cache/local-cache-fs-provider.ts +++ b/arduino-ide-extension/src/browser/local-cache/local-cache-fs-provider.ts @@ -16,6 +16,10 @@ import { import { AuthenticationClientService } from '../auth/authentication-client-service'; import { AuthenticationSession } from '../../common/protocol/authentication-service'; import { ConfigService } from '../../common/protocol'; +import { + ARDUINO_CLOUD_FOLDER, + REMOTE_SKETCHBOOK_FOLDER, +} from '../utils/constants'; export namespace LocalCacheUri { export const scheme = 'arduino-local-cache'; @@ -91,7 +95,7 @@ export class LocalCacheFsProvider protected async init(fileService: FileService): Promise { const config = await this.configService.getConfiguration(); this._localCacheRoot = new URI(config.dataDirUri); - for (const segment of ['RemoteSketchbook', 'ArduinoCloud']) { + for (const segment of [REMOTE_SKETCHBOOK_FOLDER, ARDUINO_CLOUD_FOLDER]) { this._localCacheRoot = this._localCacheRoot.resolve(segment); await fileService.createFolder(this._localCacheRoot); } diff --git a/arduino-ide-extension/src/browser/theia/core/application-shell.ts b/arduino-ide-extension/src/browser/theia/core/application-shell.ts index b9e0d4c67..bfba5dff2 100644 --- a/arduino-ide-extension/src/browser/theia/core/application-shell.ts +++ b/arduino-ide-extension/src/browser/theia/core/application-shell.ts @@ -15,8 +15,12 @@ import { } from '@theia/core/lib/browser'; import { Sketch } from '../../../common/protocol'; import { SaveAsSketch } from '../../contributions/save-as-sketch'; -import { CurrentSketch, SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { + CurrentSketch, + SketchesServiceClientImpl, +} from '../../../common/protocol/sketches-service-client-impl'; import { nls } from '@theia/core/lib/common'; +import { SketchbookWidget } from '../../widgets/sketchbook/sketchbook-widget'; import URI from '@theia/core/lib/common/uri'; @injectable() @@ -33,6 +37,19 @@ export class ApplicationShell extends TheiaApplicationShell { @inject(ConnectionStatusService) protected readonly connectionStatusService: ConnectionStatusService; + override async setLayoutData( + layoutData: TheiaApplicationShell.LayoutData + ): Promise { + if (typeof layoutData.activeWidgetId !== 'undefined') { + layoutData.activeWidgetId = SketchbookWidget.ID; + layoutData.leftPanel?.items?.forEach((item) => { + if (item?.widget?.id === SketchbookWidget.ID) item.expanded = true; + else item.expanded = false; + }); + } + super.setLayoutData(layoutData); + } + protected override track(widget: Widget): void { super.track(widget); if (widget instanceof OutputWidget) { @@ -43,7 +60,7 @@ export class ApplicationShell extends TheiaApplicationShell { this.sketchesServiceClient.currentSketch().then((sketch) => { if (CurrentSketch.isValid(sketch)) { if (!this.isSketchFile(widget.editor.uri, sketch.uri)) { - return; + return; } if (Sketch.isInSketch(widget.editor.uri, sketch)) { widget.title.closable = false; @@ -54,11 +71,11 @@ export class ApplicationShell extends TheiaApplicationShell { } private isSketchFile(uri: URI, sketchUriString: string): boolean { - const sketchUri = new URI(sketchUriString); - if (uri.parent.isEqual(sketchUri)) { - return true; - } - return false; + const sketchUri = new URI(sketchUriString); + if (uri.parent.isEqual(sketchUri)) { + return true; + } + return false; } override async addWidget( @@ -124,11 +141,11 @@ const originalHandleEvent = DockPanel.prototype.handleEvent; DockPanel.prototype.handleEvent = function (event) { switch (event.type) { - case 'p-dragenter': - case 'p-dragleave': - case 'p-dragover': - case 'p-drop': - return; + case 'p-dragenter': + case 'p-dragleave': + case 'p-dragover': + case 'p-drop': + return; } originalHandleEvent.bind(this)(event); }; diff --git a/arduino-ide-extension/src/browser/utils/constants.ts b/arduino-ide-extension/src/browser/utils/constants.ts index f4bf28e31..570929d35 100644 --- a/arduino-ide-extension/src/browser/utils/constants.ts +++ b/arduino-ide-extension/src/browser/utils/constants.ts @@ -1,2 +1,2 @@ export const REMOTE_SKETCHBOOK_FOLDER = 'RemoteSketchbook'; -export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud'; \ No newline at end of file +export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud'; diff --git a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx index 9661c02fe..7cb87c651 100644 --- a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx +++ b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-composite-widget.tsx @@ -58,6 +58,20 @@ export class CloudSketchbookCompositeWidget extends BaseWidget { ); } + protected override onActivateRequest(msg: Message): void { + super.onActivateRequest(msg); + this.cloudSketchbookTreeWidget.activate(); + + /* + Sending a resize message is needed because otherwise the cloudSketchbookTreeWidget + would render empty + */ + MessageLoop.sendMessage( + this.cloudSketchbookTreeWidget, + Widget.ResizeMessage.UnknownSize + ); + } + protected override onResize(message: Widget.ResizeMessage): void { super.onResize(message); MessageLoop.sendMessage( diff --git a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts index 22239a227..e108049d5 100644 --- a/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts +++ b/arduino-ide-extension/src/browser/widgets/cloud-sketchbook/cloud-sketchbook-widget.ts @@ -1,8 +1,20 @@ -import { inject, injectable, postConstruct } from '@theia/core/shared/inversify'; +import { + inject, + injectable, + postConstruct, +} from '@theia/core/shared/inversify'; import { CloudSketchbookCompositeWidget } from './cloud-sketchbook-composite-widget'; import { SketchbookWidget } from '../sketchbook/sketchbook-widget'; import { ArduinoPreferences } from '../../arduino-preferences'; - +import { Message } from '@theia/core/shared/@phosphor/messaging'; +import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl'; +import { SketchControl } from '../../contributions/sketch-control'; +import { LocalCacheFsProvider } from '../../local-cache/local-cache-fs-provider'; +import { + ARDUINO_CLOUD_FOLDER, + REMOTE_SKETCHBOOK_FOLDER, +} from '../../utils/constants'; +import * as path from 'path'; @injectable() export class CloudSketchbookWidget extends SketchbookWidget { @inject(CloudSketchbookCompositeWidget) @@ -11,6 +23,15 @@ export class CloudSketchbookWidget extends SketchbookWidget { @inject(ArduinoPreferences) protected readonly arduinoPreferences: ArduinoPreferences; + @inject(SketchControl) + protected readonly sketchControl: SketchControl; + + @inject(SketchesServiceClientImpl) + protected readonly sketchesServiceClient: SketchesServiceClientImpl; + + @inject(LocalCacheFsProvider) + protected readonly localCacheFsProvider: LocalCacheFsProvider; + @postConstruct() protected override init(): void { super.init(); @@ -25,33 +46,45 @@ export class CloudSketchbookWidget extends SketchbookWidget { return widget; } - checkCloudEnabled() { - if (this.arduinoPreferences['arduino.cloud.enabled']) { - this.sketchbookTreesContainer.activateWidget(this.widget); - } else { - this.sketchbookTreesContainer.activateWidget( - this.localSketchbookTreeWidget - ); - } - this.setDocumentMode(); + protected override onAfterShow(msg: Message): void { + this.checkCloudEnabled(); + super.onAfterShow(msg); } - setDocumentMode(): void { + async checkCloudEnabled(): Promise { + const currentSketch = await this.sketchesServiceClient.currentSketch(); + const isCloudSketch = + currentSketch && + currentSketch !== 'invalid' && + currentSketch.uri.includes( + path.join(REMOTE_SKETCHBOOK_FOLDER, ARDUINO_CLOUD_FOLDER) + ); + if (this.arduinoPreferences['arduino.cloud.enabled']) { this.sketchbookTreesContainer.mode = 'multiple-document'; + if (isCloudSketch) { + this.sketchbookTreesContainer.activateWidget(this.widget); + } } else { this.sketchbookTreesContainer.mode = 'single-document'; } + + if (!isCloudSketch || !this.arduinoPreferences['arduino.cloud.enabled']) { + this.sketchbookTreesContainer.activateWidget( + this.localSketchbookTreeWidget + ); + } } protected override onAfterAttach(msg: any): void { this.sketchbookTreesContainer.addWidget(this.widget); - this.setDocumentMode(); + this.sketchbookTreesContainer.mode = 'single-document'; this.arduinoPreferences.onPreferenceChanged((event) => { if (event.preferenceName === 'arduino.cloud.enabled') { this.checkCloudEnabled(); } }); + this.checkCloudEnabled(); super.onAfterAttach(msg); } } diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts index f8e360650..34abfacb7 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-commands.ts @@ -32,4 +32,8 @@ export namespace SketchbookCommands { id: 'arduino-sketchbook--show-files', label: 'Contextual menu', }; + + export const SKETCHBOOK_TOGGLE_VIEW: Command = { + id: 'arduino-sketchbook-widget:toggle', + }; } diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts index 16b66a26a..bcf03871c 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget-contribution.ts @@ -71,13 +71,13 @@ export class SketchbookWidgetContribution constructor() { super({ - widgetId: 'arduino-sketchbook-widget', + widgetId: SketchbookWidget.ID, widgetName: SketchbookWidget.LABEL, defaultWidgetOptions: { area: 'left', rank: 1, }, - toggleCommandId: 'arduino-sketchbook-widget:toggle', + toggleCommandId: SketchbookCommands.SKETCHBOOK_TOGGLE_VIEW.id, toggleKeybinding: 'CtrlCmd+Shift+B', }); } @@ -197,7 +197,7 @@ export class SketchbookWidgetContribution // unregister main menu action registry.unregisterMenuAction({ - commandId: 'arduino-sketchbook-widget:toggle', + commandId: SketchbookCommands.SKETCHBOOK_TOGGLE_VIEW.id, }); registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, { diff --git a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget.tsx b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget.tsx index f0a427de7..412328f29 100644 --- a/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget.tsx +++ b/arduino-ide-extension/src/browser/widgets/sketchbook/sketchbook-widget.tsx @@ -11,6 +11,7 @@ import { nls } from '@theia/core/lib/common'; @injectable() export class SketchbookWidget extends BaseWidget { static LABEL = nls.localize('arduino/sketch/titleSketchbook', 'Sketchbook'); + static ID = 'arduino-sketchbook-widget'; @inject(SketchbookTreeWidget) protected readonly localSketchbookTreeWidget: SketchbookTreeWidget; @@ -19,7 +20,7 @@ export class SketchbookWidget extends BaseWidget { constructor() { super(); - this.id = 'arduino-sketchbook-widget'; + this.id = SketchbookWidget.ID; this.title.caption = SketchbookWidget.LABEL; this.title.label = SketchbookWidget.LABEL; this.title.iconClass = 'fa fa-arduino-folder';