8000 Open the sketchbook sidebar at the right location by AlbyIanna · Pull Request #912 · arduino/arduino-ide · GitHub
[go: up one dir, main page]

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 1 commit
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
Prev Previous commit
Next Next commit
always show the correct sketchbook at ide start-up
  • Loading branch information
Alberto Iannaccone committed Mar 16, 2022
commit c8ac75126ec03bb87a8657420e36203bfa86db61
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
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
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
0