Skip to content

Commit

Permalink
add actions to move tabs and groups up and down in the tree
Browse files Browse the repository at this point in the history
  • Loading branch information
bentodaniel committed Mar 15, 2024
1 parent 4a6e49a commit 3f22168
Show file tree
Hide file tree
Showing 6 changed files with 113 additions and 8 deletions.
72 changes: 64 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": [
Expand Down Expand Up @@ -224,7 +264,7 @@
},
{
"command": "vs_tab_groups.editTabGroupIcon",
"title": "Select Tab Group Icon"
"title": "Edit Tab Group Icon"
},
{
"command": "vs_tab_groups.removeTabGroup",
Expand All @@ -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"
Expand Down
Binary file added resources/dark/down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/dark/up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/light/down.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added resources/light/up.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
49 changes: 49 additions & 0 deletions src/TreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {

// 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));
Expand Down Expand Up @@ -491,6 +493,53 @@ export class TreeDataProvider implements vscode.TreeDataProvider<TreeItem> {

/*** 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.
Expand Down

0 comments on commit 3f22168

Please sign in to comment.