Skip to content

Commit

Permalink
feat: support sorting by alphabet
Browse files Browse the repository at this point in the history
  • Loading branch information
chouchouji committed Nov 15, 2024
1 parent e7f7bde commit 5e10e9b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 1 deletion.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<div align="center">
<img src="https://github.com/user-attachments/assets/5ccef482-e2f6-410d-bcd5-857450e5c326" alt="logo" />
<h1>Alias Manager</h1>
<p>A tool used to manage your system aliases</p>
<p>A vscode extension used to manage your system aliases</p>
<p>
<img src="https://img.shields.io/github/package-json/v/chouchouji/alias-manager" alt="version">
<img src="https://img.shields.io/github/stars/chouchouji/alias-manager" alt="stars">
Expand Down
17 changes: 17 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@
{
"command": "aliasView.renameGroup",
"title": "Rename Group"
},
{
"command": "aliasView.sortByAlphabet",
"title": "Sort By Alphabet"
}
],
"commandPalette": [
Expand Down Expand Up @@ -178,6 +182,10 @@
{
"submenu": "groupOperation",
"when": "view == aliasView && (viewItem == alias_child || viewItem == alias_system_child)"
},
{
"submenu": "sortAlias",
"when": "view == aliasView && (viewItem == alias_parent || viewItem == alias_system_parent)"
}
],
"groupOperation": [
Expand All @@ -188,12 +196,21 @@
{
"command": "aliasView.addToGroup"
}
],
"sortAlias": [
{
"command": "aliasView.sortByAlphabet"
}
]
},
"submenus": [
{
"id": "groupOperation",
"label": "Group Operation"
},
{
"id": "sortAlias",
"label": "Sort Alias"
}
],
"viewsContainers": {
Expand Down
13 changes: 13 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,10 @@ export function activate(context: vscode.ExtensionContext) {
aliasView.removeFromCurrentGroup(alias),
),
);

context.subscriptions.push(
vscode.commands.registerCommand('aliasView.sortByAlphabet', (alias: AliasItem) => aliasView.sortByAlphabet(alias)),
);
}

class AliasView implements vscode.TreeDataProvider<AliasItem> {
Expand Down Expand Up @@ -366,6 +370,15 @@ class AliasView implements vscode.TreeDataProvider<AliasItem> {
this.refresh();
}

sortByAlphabet(alias: AliasItem) {
const aliases = this.globalState.get(alias.group) as Alias[];
aliases.sort((a, b) => a.aliasName.toLowerCase().localeCompare(b.aliasName.toLowerCase()));

this.globalState.update(alias.group, aliases);

this.refresh();
}

getTreeItem(element: AliasItem): vscode.TreeItem {
return element;
}
Expand Down

0 comments on commit 5e10e9b

Please sign in to comment.