mirror of
https://github.com/arduino/arduino-ide.git
synced 2025-11-08 09:58:34 +00:00
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:
committed by
GitHub
parent
5da558dfd9
commit
087cab177b
@@ -29,6 +29,7 @@ import {
|
||||
} from '../../../common/protocol/sketches-service-client-impl';
|
||||
import { FileService } from '@theia/filesystem/lib/browser/file-service';
|
||||
import { URI } from '../../contributions/contribution';
|
||||
import { WorkspaceInput } from '@theia/workspace/lib/browser';
|
||||
|
||||
export const SKETCHBOOK__CONTEXT = ['arduino-sketchbook--context'];
|
||||
|
||||
@@ -77,7 +78,7 @@ export class SketchbookWidgetContribution
|
||||
area: 'left',
|
||||
rank: 1,
|
||||
},
|
||||
toggleCommandId: 'arduino-sketchbook-widget:toggle',
|
||||
toggleCommandId: SketchbookCommands.TOGGLE_SKETCHBOOK_WIDGET.id,
|
||||
toggleKeybinding: 'CtrlCmd+Shift+B',
|
||||
});
|
||||
}
|
||||
@@ -100,11 +101,12 @@ export class SketchbookWidgetContribution
|
||||
|
||||
override registerCommands(registry: CommandRegistry): void {
|
||||
super.registerCommands(registry);
|
||||
|
||||
registry.registerCommand(SketchbookCommands.REVEAL_SKETCH_NODE, {
|
||||
execute: (treeWidgetId: string, nodeUri: string) =>
|
||||
this.revealSketchNode(treeWidgetId, nodeUri),
|
||||
});
|
||||
registry.registerCommand(SketchbookCommands.OPEN_NEW_WINDOW, {
|
||||
execute: async (arg) => {
|
||||
return this.workspaceService.open(arg.node.uri);
|
||||
},
|
||||
execute: (arg) => this.openNewWindow(arg.node),
|
||||
isEnabled: (arg) =>
|
||||
!!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
|
||||
isVisible: (arg) =>
|
||||
@@ -197,7 +199,7 @@ export class SketchbookWidgetContribution
|
||||
|
||||
// unregister main menu action
|
||||
registry.unregisterMenuAction({
|
||||
commandId: 'arduino-sketchbook-widget:toggle',
|
||||
commandId: SketchbookCommands.TOGGLE_SKETCHBOOK_WIDGET.id,
|
||||
});
|
||||
|
||||
registry.registerMenuAction(SKETCHBOOK__CONTEXT__MAIN_GROUP, {
|
||||
@@ -207,6 +209,28 @@ export class SketchbookWidgetContribution
|
||||
});
|
||||
}
|
||||
|
||||
private openNewWindow(node: SketchbookTree.SketchDirNode): void {
|
||||
const widget = this.tryGetWidget();
|
||||
if (widget) {
|
||||
const treeWidgetId = widget.activeTreeWidgetId();
|
||||
if (!treeWidgetId) {
|
||||
console.warn(`Could not retrieve active sketchbook tree ID.`);
|
||||
return;
|
||||
}
|
||||
const nodeUri = node.uri.toString();
|
||||
const options: WorkspaceInput = {};
|
||||
Object.assign(options, {
|
||||
tasks: [
|
||||
{
|
||||
command: SketchbookCommands.REVEAL_SKETCH_NODE.id,
|
||||
args: [treeWidgetId, nodeUri],
|
||||
},
|
||||
],
|
||||
});
|
||||
return this.workspaceService.open(node.uri, options);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reveals and selects node in the file navigator to which given widget is related.
|
||||
* Does nothing if given widget undefined or doesn't have related resource.
|
||||
@@ -230,4 +254,17 @@ export class SketchbookWidgetContribution
|
||||
protected onCurrentWidgetChangedHandler(): void {
|
||||
this.selectWidgetFileNode(this.shell.currentWidget);
|
||||
}
|
||||
|
||||
private async revealSketchNode(
|
||||
treeWidgetId: string,
|
||||
nodeUIri: string
|
||||
): Promise<void> {
|
||||
return this.widget
|
||||
.then((widget) => this.shell.activateWidget(widget.id))
|
||||
.then((widget) => {
|
||||
if (widget instanceof SketchbookWidget) {
|
||||
return widget.revealSketchNode(treeWidgetId, nodeUIri);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user