Skip to content

Commit

Permalink
Exposed the tree model to the command service.
Browse files Browse the repository at this point in the history
Signed-off-by: Akos Kitta <[email protected]>
  • Loading branch information
Akos Kitta committed Apr 26, 2021
1 parent eabfeb7 commit 7f2c0b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,17 @@ export class SketchbookTreeWidget extends FileTreeWidget {
return undefined;
}

protected renderInlineCommand(commandId: string, arg: SketchbookTree.SketchDirNode): React.ReactNode {
protected renderInlineCommand(commandId: string, node: SketchbookTree.SketchDirNode): React.ReactNode {
const command = this.commandRegistry.getCommand(commandId);
const icon = command?.iconClass;
if (command && icon && this.commandRegistry.isEnabled(commandId, arg) && this.commandRegistry.isVisible(commandId, arg)) {
const args = { model: this.model, node: node };
if (command && icon && this.commandRegistry.isEnabled(commandId, args) && this.commandRegistry.isVisible(commandId, args)) {
const className = [TREE_NODE_SEGMENT_CLASS, TREE_NODE_TAIL_CLASS, icon, 'theia-tree-view-inline-action'].join(' ');
return <div
key={`${commandId}--${arg.id}`}
key={`${commandId}--${node.id}`}
className={className}
title={command?.label || command.id}
onClick={() => this.commandRegistry.executeCommand(commandId, arg)}
onClick={event => this.commandRegistry.executeCommand(commandId, Object.assign(args, { event }))}
/>;
}
return undefined;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,14 +65,14 @@ export class SketchbookWidgetContribution extends AbstractViewContribution<Sketc
isVisible: () => this.arduinoPreferences['arduino.sketchbook.showAllFiles']
});
registry.registerCommand(SketchbookCommands.OPEN, {
execute: (arg) => this.workspaceService.open(arg.uri, { preserveWindow: true }),
isEnabled: (arg) => SketchbookTree.SketchDirNode.is(arg),
isVisible: (arg) => SketchbookTree.SketchDirNode.is(arg),
execute: arg => this.workspaceService.open(arg.node.uri, { preserveWindow: true }),
isEnabled: arg => !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
isVisible: arg => !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node)
});
registry.registerCommand(SketchbookCommands.OPEN_NEW_WINDOW, {
execute: (arg) => this.workspaceService.open(arg.uri),
isEnabled: (arg) => SketchbookTree.SketchDirNode.is(arg),
isVisible: (arg) => SketchbookTree.SketchDirNode.is(arg),
execute: arg => this.workspaceService.open(arg.node.uri),
isEnabled: arg => !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node),
isVisible: arg => !!arg && 'node' in arg && SketchbookTree.SketchDirNode.is(arg.node)
});
}

Expand Down

0 comments on commit 7f2c0b0

Please sign in to comment.