Use the public tree api

This commit is contained in:
Sandeep Somavarapu
2017-06-02 10:46:57 +02:00
parent f271d1c015
commit ecc6e9df3d
10 changed files with 12 additions and 209 deletions

View File

@ -1,14 +1,12 @@
# Dependency Tree Explorer
# Custom tree view samples
A sample for the Tree Explorer API showing dependencies in a node project.
![tree-explorer](tree-explorer.png)
- Node dependencies view
- Json Outline view
- Ftp file explorer view
## Running the example
Currently, this API is only available in [Insiders](https://code.visualstudio.com/insiders).
- Download Insiders version of VS Code and open this sample
- Open this example in VS Code
- `npm install`
- `npm run compile`
- `F5` to start debugging

View File

@ -5,9 +5,8 @@
"version": "0.0.1",
"publisher": "octref",
"engines": {
"vscode": "^1.12.0"
"vscode": "^1.13.0"
},
"enableProposedApi": true,
"categories": [
"Other"
],

View File

Before

Width:  |  Height:  |  Size: 682 B

After

Width:  |  Height:  |  Size: 682 B

View File

Before

Width:  |  Height:  |  Size: 760 B

After

Width:  |  Height:  |  Size: 760 B

View File

Before

Width:  |  Height:  |  Size: 552 B

After

Width:  |  Height:  |  Size: 552 B

View File

Before

Width:  |  Height:  |  Size: 750 B

After

Width:  |  Height:  |  Size: 750 B

View File

@ -11,7 +11,6 @@ export function activate(context: vscode.ExtensionContext) {
const jsonOutlineProvider = new JsonOutlineProvider(context);
const provider = new FtpTreeDataProvider();
// The `providerId` here must be identical to `contributes.explorer.treeExplorerNodeProviderId` in package.json.
vscode.window.registerTreeDataProvider('nodeDependencies', new DepNodeProvider(rootPath));
vscode.window.registerTreeDataProvider('jsonOutline', jsonOutlineProvider);
vscode.window.registerTreeDataProvider('ftpExplorer', provider);
@ -23,7 +22,6 @@ export function activate(context: vscode.ExtensionContext) {
vscode.commands.registerCommand('extension.openJsonSelection', range => {
jsonOutlineProvider.select(range);
});
vscode.commands.registerCommand('jsonOutline.refreshEntry', () => vscode.window.showInformationMessage('Successfully called refresh'));
vscode.commands.registerCommand('jsonOutline.addEntry', node => vscode.window.showInformationMessage('Successfully called add entry'));
vscode.commands.registerCommand('jsonOutline.deleteEntry', node => {

View File

@ -32,10 +32,8 @@ export class FtpNode {
}
export class FtpModel {
private connection: Thenable<FtpNode[]>;
constructor(private host: string, private user: string, private password: string) {
this.connection = this.connect();
}
public connect(): Thenable<Client> {
@ -45,6 +43,10 @@ export class FtpModel {
c(client);
});
client.on('error', error => {
e('Error while connecting: ' + error.message);
})
client.connect({
host: this.host,
username: this.user,
@ -142,8 +144,8 @@ export class FtpTreeDataProvider implements TreeDataProvider<FtpNode>, TextDocum
title: 'Open FTP Resource'
},
iconPath: {
light: element.isFolder ? path.join(__filename, '..', '..', '..', 'resources', 'Folder_16x.svg') : path.join(__filename, '..', '..', '..', 'resources', 'Document_16x.svg'),
dark: element.isFolder ? path.join(__filename, '..', '..', '..', 'resources', 'Folder_inverse_16x.svg') : path.join(__filename, '..', '..', '..', 'resources', 'Document_inverse_16x.svg')
light: element.isFolder ? path.join(__filename, '..', '..', '..', 'resources', 'light', 'folder.svg') : path.join(__filename, '..', '..', '..', 'resources', 'light', 'document.svg'),
dark: element.isFolder ? path.join(__filename, '..', '..', '..', 'resources', 'dark', 'folder.svg') : path.join(__filename, '..', '..', '..', 'resources', 'dark', 'document.svg')
}
};
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 92 KiB

View File

@ -1,194 +0,0 @@
/*---------------------------------------------------------------------------------------------
* Copyright (c) Microsoft Corporation. All rights reserved.
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
// This is the place for API experiments and proposal.
declare module 'vscode' {
export namespace window {
export function sampleFunction(): Thenable<any>;
}
export namespace window {
/**
* Register a [TreeDataProvider](#TreeDataProvider) for the view contributed using the extension point `views`.
* @param viewId Id of the view contributed using the extension point `views`.
* @param treeDataProvider A [TreeDataProvider](#TreeDataProvider) that provides tree data for the view
*/
export function registerTreeDataProvider<T>(viewId: string, treeDataProvider: TreeDataProvider<T>): Disposable;
}
/**
* A data provider that provides tree data
*/
export interface TreeDataProvider<T> {
/**
* An optional event to signal that an element or root has changed.
* To signal that root has changed, do not pass any argument or pass `undefined` or `null`.
*/
onDidChangeTreeData?: Event<T | undefined | null>;
/**
* Get [TreeItem](#TreeItem) representation of the `element`
*
* @param element The element for which [TreeItem](#TreeItem) representation is asked for.
* @return [TreeItem](#TreeItem) representation of the element
*/
getTreeItem(element: T): TreeItem | Thenable<TreeItem>;
/**
* Get the children of `element` or root if no element is passed.
*
* @param element The element from which the provider gets children. Can be `undefined`.
* @return Children of `element` or root if no element is passed.
*/
getChildren(element?: T): ProviderResult<T[]>;
}
export class TreeItem {
/**
* A human-readable string describing this item
*/
label: string;
/**
* The icon path for the tree item
*/
iconPath?: string | Uri | { light: string | Uri; dark: string | Uri };
/**
* The [command](#Command) which should be run when the tree item is selected.
*/
command?: Command;
/**
* [TreeItemCollapsibleState](#TreeItemCollapsibleState) of the tree item.
*/
collapsibleState?: TreeItemCollapsibleState;
/**
* Context value of the tree item. This can be used to contribute item specific actions in the tree.
* For example, a tree item is given a context value as `folder`. When contributing actions to `view/item/context`
* using `menus` extension point, you can specify context value for key `viewItem` in `when` expression like `viewItem == folder`.
* ```
* "contributes": {
* "menus": {
* "view/item/context": [
* {
* "command": "extension.deleteFolder",
* "when": "viewItem == folder"
* }
* ]
* }
* }
* ```
* This will show action `extension.deleteFolder` only for items with `contextValue` is `folder`.
*/
contextValue?: string;
/**
* @param label A human-readable string describing this item
* @param collapsibleState [TreeItemCollapsibleState](#TreeItemCollapsibleState) of the tree item. Default is [TreeItemCollapsibleState.None](#TreeItemCollapsibleState.None)
*/
constructor(label: string, collapsibleState?: TreeItemCollapsibleState);
}
/**
* Collapsible state of the tree item
*/
export enum TreeItemCollapsibleState {
/**
* Determines an item can be neither collapsed nor expanded. Implies it has no children.
*/
None = 0,
/**
* Determines an item is collapsed
*/
Collapsed = 1,
/**
* Determines an item is expanded
*/
Expanded = 2
}
/**
* The contiguous set of modified lines in a diff.
*/
export interface LineChange {
readonly originalStartLineNumber: number;
readonly originalEndLineNumber: number;
readonly modifiedStartLineNumber: number;
readonly modifiedEndLineNumber: number;
}
export namespace commands {
/**
* Registers a diff information command that can be invoked via a keyboard shortcut,
* a menu item, an action, or directly.
*
* Diff information commands are different from ordinary [commands](#commands.registerCommand) as
* they only execute when there is an active diff editor when the command is called, and the diff
* information has been computed. Also, the command handler of an editor command has access to
* the diff information.
*
* @param command A unique identifier for the command.
* @param callback A command handler function with access to the [diff information](#LineChange).
* @param thisArg The `this` context used when invoking the handler function.
* @return Disposable which unregisters this command on disposal.
*/
export function registerDiffInformationCommand(command: string, callback: (diff: LineChange[], ...args: any[]) => any, thisArg?: any): Disposable;
}
export interface Terminal {
/**
* The name of the terminal.
*/
readonly name: string;
/**
* The process ID of the shell process.
*/
readonly processId: Thenable<number>;
/**
* Send text to the terminal. The text is written to the stdin of the underlying pty process
* (shell) of the terminal.
*
* @param text The text to send.
* @param addNewLine Whether to add a new line to the text being sent, this is normally
* required to run a command in the terminal. The character(s) added are \n or \r\n
* depending on the platform. This defaults to `true`.
*/
sendText(text: string, addNewLine?: boolean): void;
/**
* Show the terminal panel and reveal this terminal in the UI.
*
* @param preserveFocus When `true` the terminal will not take focus.
*/
show(preserveFocus?: boolean): void;
/**
* Hide the terminal panel if this terminal is currently showing.
*/
hide(): void;
/**
* Dispose and free associated resources.
*/
dispose(): void;
/**
* Experimental API that allows listening to the raw data stream coming from the terminal's
* pty process (including ANSI escape sequences).
*
* @param callback The callback that is triggered when data is sent to the terminal.
*/
onData(callback: (data: string) => any): void;
}
}