forked from apache/daffodil-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create view container with a view of commands.
- Create initial view container with a single view. - Create command view that displays a tree of our custom commands that can be ran. - Add play button to commands in view to be able to run them. - Update list of commands based on if debug mode or not. - Bump macos-12 to macos-14 to unbreak CI. - Not using macos-13 as it doesn't have sbt installed by default. - Configure daffodil-icon to look good for view container. Closes apache#1129
- Loading branch information
Showing
8 changed files
with
382 additions
and
112 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -319,4 +319,5 @@ | |
/* padding-top: -10px; */ | ||
margin-top: 0px; | ||
/* cursor: pointer; */ | ||
fill: #000000; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You under the Apache License, Version 2.0 | ||
* (the "License"); you may not use this file except in compliance with | ||
* the License. You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
import * as vscode from 'vscode' | ||
|
||
const viewName = 'commandsView' | ||
const packageCommands = require('../../package.json').contributes.commands | ||
|
||
// Custom class to hold attributes of the commands | ||
class CommandItem extends vscode.TreeItem { | ||
constructor( | ||
public readonly label: string, | ||
public readonly commandName: string, | ||
public readonly category: string, | ||
public readonly enablement: string, | ||
public readonly collapsibleState: vscode.TreeItemCollapsibleState | ||
) { | ||
super(label, collapsibleState) | ||
this.tooltip = `${this.category}: ${this.label}` | ||
this.description = this.commandName | ||
} | ||
|
||
iconPath = new vscode.ThemeIcon('bracket') | ||
} | ||
|
||
// Class that will create the tree of commands in our view container | ||
export class CommandsProvider implements vscode.TreeDataProvider<CommandItem> { | ||
private commands: Array<CommandItem> | ||
constructor() { | ||
this.commands = getCommands('!inDebugMode') | ||
} | ||
|
||
private _onDidChangeTreeData: vscode.EventEmitter< | ||
CommandItem | undefined | null | void | ||
> = new vscode.EventEmitter<CommandItem | undefined | null | void>() | ||
readonly onDidChangeTreeData: vscode.Event< | ||
CommandItem | undefined | null | void | ||
> = this._onDidChangeTreeData.event | ||
|
||
getTreeItem = (element: CommandItem): vscode.TreeItem => element | ||
|
||
getChildren = (): vscode.ProviderResult<CommandItem[]> => this.commands | ||
|
||
refresh = (): void => this._onDidChangeTreeData.fire() | ||
|
||
public register(context: vscode.ExtensionContext): any { | ||
vscode.window.registerTreeDataProvider(viewName, this) | ||
|
||
const tree = vscode.window.createTreeView(viewName, { | ||
treeDataProvider: this, | ||
showCollapseAll: true, | ||
}) | ||
|
||
// Create command that allows for the execution of our other commands | ||
// when the command items play icon is clicked | ||
vscode.commands.registerCommand( | ||
`${viewName}.runCommand`, | ||
async (commandItem: CommandItem) => | ||
vscode.commands.executeCommand(commandItem.commandName) | ||
) | ||
|
||
// Create command that will refresh the list of commands | ||
vscode.commands.registerCommand(`${viewName}.refresh`, () => { | ||
this.refresh() | ||
}) | ||
|
||
// Create listeners to update the commands based on if a debug session is happening | ||
vscode.debug.onDidStartDebugSession(() => { | ||
this.commands = getCommands('inDebugMode') | ||
this.refresh() | ||
}) | ||
vscode.debug.onDidTerminateDebugSession(() => { | ||
this.commands = getCommands('!inDebugMode') | ||
this.refresh() | ||
}) | ||
|
||
context.subscriptions.push(tree) | ||
} | ||
} | ||
|
||
// Function to parse all the commands from the package.json, that currently enabled, | ||
// to an array of CommandItems | ||
function getCommands(enablement: String): Array<CommandItem> { | ||
const commands = Array<CommandItem>() | ||
|
||
packageCommands | ||
.filter( | ||
(c) => | ||
!c.command.startsWith(viewName) && | ||
(enablement === c.enablement || c.enablement === undefined) | ||
) | ||
.forEach((command) => { | ||
commands.push( | ||
new CommandItem( | ||
command.title, | ||
command.command, | ||
command.category, | ||
command.enablement ?? '', | ||
vscode.TreeItemCollapsibleState.None | ||
) | ||
) | ||
}) | ||
|
||
return commands | ||
} |
Oops, something went wrong.