Skip to content

Open the sketchbook sidebar at the right location #912

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -91,7 +95,7 @@ export class LocalCacheFsProvider
protected async init(fileService: FileService): Promise<void> {
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);
}
Expand Down
41 changes: 29 additions & 12 deletions arduino-ide-extension/src/browser/theia/core/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand All @@ -33,6 +37,19 @@ export class ApplicationShell extends TheiaApplicationShell {
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;

override async setLayoutData(
layoutData: TheiaApplicationShell.LayoutData
): Promise<void> {
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) {
Expand All @@ -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;
Expand All @@ -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(
Expand Down Expand Up @@ -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);
};
2 changes: 1 addition & 1 deletion arduino-ide-extension/src/browser/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
export const REMOTE_SKETCHBOOK_FOLDER = 'RemoteSketchbook';
export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud';
export const ARDUINO_CLOUD_FOLDER = 'ArduinoCloud';
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
@@ -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)
Expand All @@ -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();
Expand All @@ -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<void> {
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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
};
}
Original file line number Diff line number Diff line change
Expand Up @@ -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',
});
}
Expand Down Expand Up @@ -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, {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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';
Expand Down