Skip to content
This repository has been archived by the owner on Dec 23, 2024. It is now read-only.

Commit

Permalink
feat: register new command and tree view to extension
Browse files Browse the repository at this point in the history
  • Loading branch information
monstajoe2002 committed Dec 12, 2023
1 parent e9e4dc1 commit 0e81b87
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 15 deletions.
6 changes: 5 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@
{
"id": "projectExplorer.layouts",
"name": "Layouts"
},
{
"id": "projectExplorer.activeEditors",
"name": "Active Editors"
}
]
},
Expand Down Expand Up @@ -72,7 +76,7 @@
"view/title": [
{
"command": "project-explorer.tree.refresh",
"when": "view == projectExplorer.pages || view == projectExplorer.layouts",
"when": "view == projectExplorer.pages || view == projectExplorer.layouts || view == projectExplorer.activeEditors",
"group": "navigation"
}
],
Expand Down
7 changes: 6 additions & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import PagesProvider from "./providers/pages-provider";
import FileTreeItem from "./utils/file-tree-item";
import LayoutsProvider from "./providers/layouts-provider";
import path from "path";
import ActiveEditorsProvider from "./providers/active-editors-provider";

const workspaceUri = vscode.workspace.workspaceFolders![0].uri;
let appDirUri: vscode.Uri;
Expand All @@ -31,7 +32,7 @@ export async function activate(_: vscode.ExtensionContext) {

const pagesTree = new PagesProvider(appDirUri);
const layoutsTree = new LayoutsProvider(appDirUri);

const activeEditorsTree = new ActiveEditorsProvider(appDirUri);
nextSearch.register(_, async () => {
await nextSearch.showDirectoryContents(appDirUri);
});
Expand All @@ -47,9 +48,13 @@ export async function activate(_: vscode.ExtensionContext) {
vscode.window.createTreeView("projectExplorer.layouts", {
treeDataProvider: layoutsTree,
});
vscode.window.createTreeView("projectExplorer.activeEditors", {
treeDataProvider: activeEditorsTree,
});
vscode.commands.registerCommand("project-explorer.tree.refresh", () => {
pagesTree.refresh();
layoutsTree.refresh();
activeEditorsTree.refresh();
});
vscode.commands.registerCommand(
"project-explorer.tree.delete",
Expand Down
25 changes: 12 additions & 13 deletions src/providers/active-editors-provider.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as vscode from "vscode";
import { Provider } from "../utils/base-provider";
import ActiveEditorsTreeItem from "../utils/active-editors-tree-item";
class ActiveEditorsProvider
export default class ActiveEditorsProvider
extends Provider<ActiveEditorsTreeItem>
implements vscode.TreeDataProvider<ActiveEditorsTreeItem>
{
Expand Down Expand Up @@ -33,19 +33,18 @@ class ActiveEditorsProvider
getChildren(
element?: ActiveEditorsTreeItem | undefined
): vscode.ProviderResult<ActiveEditorsTreeItem[]> {
if (!element) {
return null;
try {
const activeEditors = vscode.window.visibleTextEditors;
this.refresh();
return activeEditors.map((editor) => {
return new ActiveEditorsTreeItem(
editor.document!.fileName,
vscode.TreeItemCollapsibleState.None
);
});
} catch (err) {
return [];
}

vscode.window.visibleTextEditors.map((editor) => {
const activeEditor = new ActiveEditorsTreeItem(
editor.document.fileName,
vscode.TreeItemCollapsibleState.None
);
return editor.document.fileName.includes("page" || "layout")
? activeEditor
: null;
});
}
closeEditor(element: ActiveEditorsTreeItem) {
vscode.window.visibleTextEditors.map((editor) => {
Expand Down

0 comments on commit 0e81b87

Please sign in to comment.