Sketchbook sidebar state (#1102)

* add commands to open sketchbook widgets

add commands to show sketchbook widgets

* enable sending commands via query params

* opening sketch in new window will open sketchbook

* requested changes

* add specific method WorkspaceService to open sketch with commands

* add encoded commands contribution

* try merge show sketchbook commands

* pair session changes.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* i18n fixup.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* minimized scope of hacky code.

Signed-off-by: Akos Kitta <a.kitta@arduino.cc>

* clean up OPEN_NEW_WINDOW command

* add comment on workspace-service.ts

* reveal node with URI

Co-authored-by: Akos Kitta <a.kitta@arduino.cc>
This commit is contained in:
Alberto Iannaccone
2022-07-04 15:49:25 +02:00
committed by GitHub
parent 5da558dfd9
commit 087cab177b
7 changed files with 226 additions and 10 deletions

View File

@@ -1,4 +1,8 @@
import { inject, injectable, postConstruct } from '@theia/core/shared/inversify';
import {
inject,
injectable,
postConstruct,
} from '@theia/core/shared/inversify';
import { toArray } from '@theia/core/shared/@phosphor/algorithm';
import { IDragEvent } from '@theia/core/shared/@phosphor/dragdrop';
import { DockPanel, Widget } from '@theia/core/shared/@phosphor/widgets';
@@ -7,6 +11,8 @@ import { Disposable } from '@theia/core/lib/common/disposable';
import { BaseWidget } from '@theia/core/lib/browser/widgets/widget';
import { SketchbookTreeWidget } from './sketchbook-tree-widget';
import { nls } from '@theia/core/lib/common';
import { CloudSketchbookCompositeWidget } from '../cloud-sketchbook/cloud-sketchbook-composite-widget';
import { URI } from '../../contributions/contribution';
@injectable()
export class SketchbookWidget extends BaseWidget {
@@ -45,6 +51,57 @@ export class SketchbookWidget extends BaseWidget {
return this.localSketchbookTreeWidget;
}
activeTreeWidgetId(): string | undefined {
const selectedTreeWidgets = toArray(
this.sketchbookTreesContainer.selectedWidgets()
).map(({ id }) => id);
if (selectedTreeWidgets.length > 1) {
console.warn(
`Found multiple selected tree widgets: ${JSON.stringify(
selectedTreeWidgets
)}. Expected only one.`
);
}
return selectedTreeWidgets.shift();
}
async revealSketchNode(treeWidgetId: string, nodeUri: string): Promise<void> {
const widget = toArray(this.sketchbookTreesContainer.widgets())
.filter(({ id }) => id === treeWidgetId)
.shift();
if (!widget) {
console.warn(`Could not find tree widget with ID: ${widget}`);
return;
}
// TODO: remove this when the remote/local sketchbooks and their widgets are cleaned up.
const findTreeWidget = (
widget: Widget | undefined
): SketchbookTreeWidget | undefined => {
if (widget instanceof SketchbookTreeWidget) {
return widget;
}
if (widget instanceof CloudSketchbookCompositeWidget) {
return widget.getTreeWidget();
}
return undefined;
};
const treeWidget = findTreeWidget(
toArray(this.sketchbookTreesContainer.widgets())
.filter(({ id }) => id === treeWidgetId)
.shift()
);
if (!treeWidget) {
console.warn(`Could not find tree widget with ID: ${treeWidget}`);
return;
}
this.sketchbookTreesContainer.activateWidget(widget);
const treeNode = await treeWidget.model.revealFile(new URI(nodeUri));
if (!treeNode) {
console.warn(`Could not find tree node with URI: ${nodeUri}`);
}
}
protected override onActivateRequest(message: Message): void {
super.onActivateRequest(message);