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 3 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
28 changes: 13 additions & 15 deletions arduino-ide-extension/src/browser/arduino-ide-frontend-module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -420,9 +420,8 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
bind(SerialService)
.toDynamicValue((context) => {
const connection = context.container.get(WebSocketConnectionProvider);
const client = context.container.get<SerialServiceClient>(
SerialServiceClient
);
const client =
context.container.get<SerialServiceClient>(SerialServiceClient);
return connection.createProxy(SerialServicePath, client);
})
.inSingletonScope();
Expand Down Expand Up @@ -486,11 +485,12 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {
.inSingletonScope();
rebind(TheiaEditorWidgetFactory).to(EditorWidgetFactory).inSingletonScope();
rebind(TabBarToolbarFactory).toFactory(
({ container: parentContainer }) => () => {
const container = parentContainer.createChild();
container.bind(TabBarToolbar).toSelf().inSingletonScope();
return container.get(TabBarToolbar);
}
({ container: parentContainer }) =>
() => {
const container = parentContainer.createChild();
container.bind(TabBarToolbar).toSelf().inSingletonScope();
return container.get(TabBarToolbar);
}
);
bind(OutputWidget).toSelf().inSingletonScope();
rebind(TheiaOutputWidget).toService(OutputWidget);
Expand Down Expand Up @@ -655,15 +655,13 @@ export default new ContainerModule((bind, unbind, isBound, rebind) => {

// Enable the dirty indicator on uncloseable widgets.
rebind(TabBarRendererFactory).toFactory((context) => () => {
const contextMenuRenderer = context.container.get<ContextMenuRenderer>(
ContextMenuRenderer
);
const contextMenuRenderer =
context.container.get<ContextMenuRenderer>(ContextMenuRenderer);
const decoratorService = context.container.get<TabBarDecoratorService>(
TabBarDecoratorService
);
const iconThemeService = context.container.get<IconThemeService>(
IconThemeService
);
const iconThemeService =
context.container.get<IconThemeService>(IconThemeService);
return new TabBarRenderer(
contextMenuRenderer,
decoratorService,
Expand Down Expand Up @@ -723,7 +721,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
13 changes: 13 additions & 0 deletions arduino-ide-extension/src/browser/theia/core/application-shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import { Sketch } from '../../../common/protocol';
import { SaveAsSketch } from '../../contributions/save-as-sketch';
import { SketchesServiceClientImpl } from '../../../common/protocol/sketches-service-client-impl';
import { nls } from '@theia/core/lib/common';
import { SketchbookWidget } from '../../widgets/sketchbook/sketchbook-widget';

@injectable()
export class ApplicationShell extends TheiaApplicationShell {
Expand All @@ -31,6 +32,18 @@ export class ApplicationShell extends TheiaApplicationShell {
@inject(ConnectionStatusService)
protected readonly connectionStatusService: ConnectionStatusService;

async setLayoutData(
layoutData: TheiaApplicationShell.LayoutData
): Promise<void> {
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 track(widget: Widget): void {
super.track(widget);
if (widget instanceof OutputWidget) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,19 @@
import { injectable } from 'inversify';
import { FrontendApplication } from '@theia/core/lib/browser/frontend-application';
import { ShellLayoutRestorer as TheiaShellLayoutRestorer } from '@theia/core/lib/browser/shell/shell-layout-restorer';
import { inject } from '@theia/core/shared/inversify';
import { ApplicationShell } from '@theia/core/lib/browser/shell/application-shell';

@injectable()
export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
@inject(ApplicationShell)
protected readonly shell: ApplicationShell;

// Workaround for https://github.com/eclipse-theia/theia/issues/6579.
async storeLayoutAsync(app: FrontendApplication): Promise<void> {
async storeLayoutAsync(): Promise<void> {
if (this.shouldStoreLayout) {
try {
this.logger.info('>>> Storing the layout...');
const layoutData = app.shell.getLayoutData();
const layoutData = this.shell.getLayoutData();
const serializedLayoutData = this.deflate(layoutData);
await this.storageService.setData(
this.storageKey,
Expand All @@ -23,7 +27,7 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
}
}

async restoreLayout(app: FrontendApplication): Promise<boolean> {
async restoreLayout(): Promise<boolean> {
this.logger.info('>>> Restoring the layout state...');
const serializedLayoutData = await this.storageService.getData<string>(
this.storageKey
Expand All @@ -49,7 +53,7 @@ export class ShellLayoutRestorer extends TheiaShellLayoutRestorer {
});
}

await app.shell.setLayoutData(layoutData);
await this.shell.setLayoutData(layoutData);
this.logger.info('<<< The layout has been successfully restored.');
return true;
}
Expand Down
2 changes: 2 additions & 0 deletions arduino-ide-extension/src/browser/utils/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export const REMOTE_SKETCHBOOK_FOLDER = 'RemoteSketchbook';
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 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 onResize(message: Widget.ResizeMessage): void {
super.onResize(message);
MessageLoop.sendMessage(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { inject, injectable, postConstruct } from '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 +19,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 init(): void {
super.init();
Expand All @@ -25,33 +42,44 @@ 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 onAfterShow(msg: Message): void {
this.checkCloudEnabled();
super.onAfterShow(msg);
}

setDocumentMode() {
async checkCloudEnabled(): Promise<void> {
const currentSketch = await this.sketchesServiceClient.currentSketch();
const isCloudSketch =
currentSketch &&
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 onAfterAttach(msg: any) {
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 @@ -68,13 +68,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 @@ -191,7 +191,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