diff --git a/package.json b/package.json index c7638d3..dd72012 100644 --- a/package.json +++ b/package.json @@ -112,45 +112,85 @@ "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "inline@1" }, + { + "command": "vs_tab_groups.moveUp", + "when": "view == vs_tab_groups && viewItem == vstg_root_item", + "group": "inline@2" + }, + { + "command": "vs_tab_groups.moveDown", + "when": "view == vs_tab_groups && viewItem == vstg_root_item", + "group": "inline@3" + }, { "command": "vs_tab_groups.addEntry", "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "vs_tab_groups_1@0" }, { - "command": "vs_tab_groups.openTabGroup", + "command": "vs_tab_groups.moveUp", "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "vs_tab_groups_2@0" }, { - "command": "vs_tab_groups.closeTabGroup", + "command": "vs_tab_groups.moveDown", "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "vs_tab_groups_2@1" }, { - "command": "vs_tab_groups.editTabGroupIcon", + "command": "vs_tab_groups.openTabGroup", "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "vs_tab_groups_3@0" }, { - "command": "vs_tab_groups.removeTabGroup", + "command": "vs_tab_groups.closeTabGroup", "when": "view == vs_tab_groups && viewItem == vstg_root_item", "group": "vs_tab_groups_3@1" }, { - "command": "vs_tab_groups.openTab", + "command": "vs_tab_groups.editTabGroupIcon", + "when": "view == vs_tab_groups && viewItem == vstg_root_item", + "group": "vs_tab_groups_4@0" + }, + { + "command": "vs_tab_groups.removeTabGroup", + "when": "view == vs_tab_groups && viewItem == vstg_root_item", + "group": "vs_tab_groups_4@1" + }, + { + "command": "vs_tab_groups.moveUp", + "when": "view == vs_tab_groups && viewItem == vstg_child_item", + "group": "inline@0" + }, + { + "command": "vs_tab_groups.moveDown", + "when": "view == vs_tab_groups && viewItem == vstg_child_item", + "group": "inline@1" + }, + { + "command": "vs_tab_groups.moveUp", "when": "view == vs_tab_groups && viewItem == vstg_child_item", "group": "vs_tab_groups_2@0" }, { - "command": "vs_tab_groups.closeTab", + "command": "vs_tab_groups.moveDown", "when": "view == vs_tab_groups && viewItem == vstg_child_item", "group": "vs_tab_groups_2@1" }, { - "command": "vs_tab_groups.removeTab", + "command": "vs_tab_groups.openTab", "when": "view == vs_tab_groups && viewItem == vstg_child_item", "group": "vs_tab_groups_3@0" + }, + { + "command": "vs_tab_groups.closeTab", + "when": "view == vs_tab_groups && viewItem == vstg_child_item", + "group": "vs_tab_groups_3@1" + }, + { + "command": "vs_tab_groups.removeTab", + "when": "view == vs_tab_groups && viewItem == vstg_child_item", + "group": "vs_tab_groups_4@0" } ], "editor/title": [ @@ -224,7 +264,7 @@ }, { "command": "vs_tab_groups.editTabGroupIcon", - "title": "Select Tab Group Icon" + "title": "Edit Tab Group Icon" }, { "command": "vs_tab_groups.removeTabGroup", @@ -234,6 +274,22 @@ "dark": "resources/dark/remove.png" } }, + { + "command": "vs_tab_groups.moveUp", + "title": "Move Up", + "icon": { + "light": "resources/light/up.png", + "dark": "resources/dark/up.png" + } + }, + { + "command": "vs_tab_groups.moveDown", + "title": "Move Down", + "icon": { + "light": "resources/light/down.png", + "dark": "resources/dark/down.png" + } + }, { "command": "vs_tab_groups.openTab", "title": "Open Tab" diff --git a/resources/dark/down.png b/resources/dark/down.png new file mode 100644 index 0000000..f2d53da Binary files /dev/null and b/resources/dark/down.png differ diff --git a/resources/dark/up.png b/resources/dark/up.png new file mode 100644 index 0000000..eb6c57f Binary files /dev/null and b/resources/dark/up.png differ diff --git a/resources/light/down.png b/resources/light/down.png new file mode 100644 index 0000000..5dd2fd3 Binary files /dev/null and b/resources/light/down.png differ diff --git a/resources/light/up.png b/resources/light/up.png new file mode 100644 index 0000000..409d8da Binary files /dev/null and b/resources/light/up.png differ diff --git a/src/TreeDataProvider.ts b/src/TreeDataProvider.ts index 78f8676..3e928a4 100644 --- a/src/TreeDataProvider.ts +++ b/src/TreeDataProvider.ts @@ -47,6 +47,8 @@ export class TreeDataProvider implements vscode.TreeDataProvider { // General vscode.commands.registerCommand("vs_tab_groups.item_clicked", (item) => this.item_clicked(item)); + vscode.commands.registerCommand("vs_tab_groups.moveUp", (item) => this.moveItemUp(item)); + vscode.commands.registerCommand("vs_tab_groups.moveDown", (item) => this.moveItemDown(item)); // Editor vscode.commands.registerCommand("vs_tab_groups.addEntryToGroup", (item) => this.addEntryToGroup(item)); @@ -491,6 +493,53 @@ export class TreeDataProvider implements vscode.TreeDataProvider { /*** LOW LEVEL ***/ + private findParentOfItem(item: TreeItem): TreeItem[] { + console.log(item); + console.log(this.m_data); + console.log(this.m_data.filter(e => e.label === item.parentLabel)) + if (item.isRoot) { + return this.m_data; + } + return this.m_data.filter(e => e.label === item.parentLabel)[0].children; + } + + private array_move(arr: any[], old_index: number, new_index: number): any[] { + arr.splice(new_index, 0, arr.splice(old_index, 1)[0]); + return arr; + }; + + moveItemUp(item: TreeItem): void { + const parent = this.findParentOfItem(item); + const index = parent.indexOf(item); + + if (index <= 0) { + vscode.window.showErrorMessage(`Can't move this item up.`); + return; + } + this.array_move(parent, index, index - 1); + + this.treeView?.reveal(item); + + this.m_onDidChangeTreeData.fire(undefined); + this.save(); + } + + moveItemDown(item: TreeItem): void { + const parent = this.findParentOfItem(item); + const index = parent.indexOf(item); + + if (index === parent.length - 1) { + vscode.window.showErrorMessage(`Can't move this item down.`); + return; + } + this.array_move(parent, index, index + 1); + + this.treeView?.reveal(item); + + this.m_onDidChangeTreeData.fire(undefined); + this.save(); + } + /** * Open a tab in the editor. * @param item The item representing the file to be opened.