-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6ddd1cf
commit 78920a4
Showing
6 changed files
with
171 additions
and
95 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import * as vscode from "vscode"; | ||
|
||
import { DirectoryController } from "./directoryController"; | ||
import { AddonTreeDataProvider } from "../model/sidebarTreeDataProvider"; | ||
|
||
export class SidebarController { | ||
constructor( | ||
public id: string, | ||
private directoryController: DirectoryController | ||
) {} | ||
|
||
/** | ||
* Fetch the TreeView of addons. | ||
* @returns TreeView and refresh method. | ||
*/ | ||
async getTreeView() { | ||
const rootFolderPath = await this.directoryController.getRootFolderPath(); | ||
const treeProvider = new AddonTreeDataProvider(rootFolderPath); | ||
const refresh = () => { | ||
treeProvider.refresh(); | ||
}; | ||
const treeView = vscode.window.createTreeView(this.id, { | ||
treeDataProvider: treeProvider, | ||
canSelectMany: true, | ||
}); | ||
return { refresh, treeView }; | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,90 @@ | ||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as vscode from "vscode"; | ||
|
||
// Does not use resourceUri to avoid fileDecorationProvider providing to this tree. | ||
export class AddonTreeItem extends vscode.TreeItem { | ||
constructor( | ||
public readonly label: string, | ||
public readonly collapsibleState: vscode.TreeItemCollapsibleState, | ||
public readonly uri: vscode.Uri, | ||
public readonly contextValue: string | undefined, | ||
showIcon?: boolean | ||
) { | ||
super(label, collapsibleState); | ||
this.iconPath = showIcon | ||
? { | ||
dark: path.join( | ||
__filename, | ||
"..", | ||
"..", | ||
"media", | ||
"sidebarIcons", | ||
"puzzle_inverse.svg" | ||
), | ||
light: path.join( | ||
__filename, | ||
"..", | ||
"..", | ||
"media", | ||
"sidebarIcons", | ||
"puzzle.svg" | ||
), | ||
} | ||
: undefined; | ||
} | ||
} | ||
|
||
export class AddonTreeDataProvider | ||
implements vscode.TreeDataProvider<AddonTreeItem> | ||
{ | ||
private _onDidChangeTreeData: vscode.EventEmitter<AddonTreeItem | undefined> = | ||
new vscode.EventEmitter<AddonTreeItem | undefined>(); | ||
readonly onDidChangeTreeData: vscode.Event<AddonTreeItem | undefined> = | ||
this._onDidChangeTreeData.event; | ||
|
||
constructor(private rootPath: string) {} | ||
|
||
getTreeItem(element: AddonTreeItem): vscode.TreeItem { | ||
return element; | ||
} | ||
|
||
getChildren(element?: AddonTreeItem): Thenable<AddonTreeItem[]> { | ||
const itemPath = element?.uri ? element.uri.fsPath : this.rootPath; | ||
const depth = itemPath.split(this.rootPath)?.at(1)?.split("/").length; | ||
return new Promise((resolve) => { | ||
fs.readdir(itemPath, (err, files) => { | ||
if (err || !depth || depth > 2) { | ||
return resolve([]); | ||
} | ||
|
||
const children: AddonTreeItem[] = []; | ||
files.map((file) => { | ||
const filePath = path.join(itemPath, file); | ||
const isDirectory = fs.statSync(filePath).isDirectory(); | ||
if (isDirectory) { | ||
const isGuidFolder = depth < 2; | ||
const contextValue = isGuidFolder ? "guidDirectory" : undefined; | ||
const collapsibleState = isGuidFolder | ||
? vscode.TreeItemCollapsibleState.Expanded | ||
: vscode.TreeItemCollapsibleState.None; | ||
children.push( | ||
new AddonTreeItem( | ||
file, | ||
collapsibleState, | ||
vscode.Uri.file(filePath), | ||
contextValue, | ||
isGuidFolder | ||
) | ||
); | ||
} | ||
}); | ||
return resolve(children); | ||
}); | ||
}); | ||
} | ||
|
||
refresh(): void { | ||
this._onDidChangeTreeData.fire(undefined); | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.