Skip to content

Commit

Permalink
- Added: Set alias for pinned files to distinguish the same name to e…
Browse files Browse the repository at this point in the history
…ach other. (Resolve Feature Request of #7)

- Fixed: The icon button of `pin outside` can be displayed on the right position now.
  • Loading branch information
SaekiRaku committed Sep 1, 2020
1 parent cfa2edd commit e8a7cc0
Show file tree
Hide file tree
Showing 9 changed files with 90 additions and 40 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ All notable changes to the "vscode-pin-up" extension will be documented in this

Check [Keep a Changelog](http://keepachangelog.com/) for recommendations on how to structure this file.

## [1.3.0] - 2020-09-01

- Added: Set alias for pinned files to distinguish the same name to each other. (Resolve Feature Request of #7)
- Fixed: The icon button of `pin outside` can be displayed on the right position now.

## [1.2.0] - 2020-06-05

- Added: Create file/folder and delete it in Pinned List.
Expand Down
Binary file modified docs/vscode-pin-up.sketch
Binary file not shown.
1 change: 1 addition & 0 deletions i18n/package.nls.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"pin-up": "📌 Pin Up",
"pin-up-outside": "📌 Pin Up (From outside files)",
"set-alias": "Set Alias",
"remove-pin": "Remove Pin",
"remove-all": "Remove All",

Expand Down
1 change: 1 addition & 0 deletions i18n/package.nls.zh.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

"pin-up": "📌 固定",
"pin-up-outside": "📌 固定外部文件",
"set-alias": "设置别名",
"remove-pin": "移除固定",
"remove-all": "移除全部",

Expand Down
29 changes: 4 additions & 25 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

36 changes: 24 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@
"publisher": "saekiraku",
"icon": "resources/logo.png",
"name": "pin-up",
"displayName": "Pin Up",
"description": "Pin up files and folders that was frequently opened in your project.",
"version": "1.2.0",
"displayName": "📌 Pin Up",
"description": "Pin up files and folders that frequently opened in your project.",
"version": "1.3.0",
"engines": {
"vscode": "^1.44.0"
},
Expand All @@ -22,21 +22,26 @@
"commands": [
{
"command": "pin-up.add-pin",
"category": "Pin Up",
"category": "pin-up",
"title": "%pin-up%"
},
{
"command": "pin-up.add-pin-outside",
"category": "Pin Up",
"category": "pin-up",
"title": "%pin-up-outside%",
"icon": {
"light": "resources/add-light.svg",
"dark": "resources/add-dark.svg"
}
},
{
"command": "pin-up.alias-pin",
"category": "pin-up",
"title": "%set-alias%"
},
{
"command": "pin-up.remove-pin",
"category": "Pin Up",
"category": "pin-up",
"title": "%remove-pin%",
"icon": {
"light": "resources/remove-light.svg",
Expand All @@ -45,22 +50,22 @@
},
{
"command": "pin-up.clear-pin",
"category": "Pin Up",
"category": "pin-up",
"title": "%remove-all%"
},
{
"command": "pin-up.fs-create-file",
"category": "Pin Up",
"category": "pin-up",
"title": "%fs-create-file%"
},
{
"command": "pin-up.fs-create-folder",
"category": "Pin Up",
"category": "pin-up",
"title": "%fs-create-folder%"
},
{
"command": "pin-up.fs-delete",
"category": "Pin Up",
"category": "pin-up",
"title": "%fs-delete%"
}
],
Expand Down Expand Up @@ -126,7 +131,8 @@
"view/title": [
{
"command": "pin-up.add-pin-outside",
"group": "navigation"
"group": "navigation",
"when": "view == view-activitybar || view == view-explorer"
},
{
"when": "view == view-activitybar || view == view-explorer",
Expand All @@ -141,7 +147,13 @@
},
{
"when": "viewItem == pinned",
"command": "pin-up.remove-pin"
"command": "pin-up.alias-pin",
"group": "pins-operation@1"
},
{
"when": "viewItem == pinned",
"command": "pin-up.remove-pin",
"group": "pins-operation@2"
},
{
"command": "pin-up.fs-create-file",
Expand Down
47 changes: 44 additions & 3 deletions src/PinDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ class PinnedItem {
class PinDataProvider {

_pinnedList = [];
_aliasMap = {};

_onDidChangeTreeData = new vscode.EventEmitter();
onDidChangeTreeData = this._onDidChangeTreeData.event;
Expand All @@ -32,9 +33,24 @@ class PinDataProvider {
} catch (e) {
return;
}
for (let i in config) {
this.AddPin(config[i], true);

if (Array.isArray(config)) {
// Transform V1 config to the latest structure.
config = {
"version": "2",
"pinnedList": JSON.parse(JSON.stringify(config)),
"aliasMap": {}
}
fs.writeFileSync(CONFIG_PATH, JSON.stringify(config));
}


for (let i in config.pinnedList) {
this.AddPin(config.pinnedList[i], true);
}

this._aliasMap = config.aliasMap

this.refresh();
}

Expand Down Expand Up @@ -62,6 +78,17 @@ class PinDataProvider {
const treeItem = new vscode.TreeItem(element.uri, element.type === vscode.FileType.Directory ? vscode.TreeItemCollapsibleState.Collapsed : vscode.TreeItemCollapsibleState.None);
if (element.isRoot) {
treeItem.contextValue = 'pinned';

if (this._aliasMap[element.uri.path]) {
treeItem.description = this._aliasMap[element.uri.path];
} else {
const fileName = path.basename(element.uri.path);
this._pinnedList.forEach(filePath => {
if (fileName === path.basename(filePath) && element.uri.path != utils.fixedPath(filePath)) {
treeItem.description = path.basename(path.dirname(element.uri.path));
}
});
}
}
if (element.type === vscode.FileType.File) {
treeItem.command = { command: 'pin-up.open-resource-uri', title: "Open File", arguments: [element.uri], };
Expand All @@ -78,7 +105,11 @@ class PinDataProvider {
if (!fs.existsSync(configDir)) {
fs.mkdirSync(configDir);
}
fs.writeFileSync(CONFIG_PATH, JSON.stringify(this._pinnedList));
fs.writeFileSync(CONFIG_PATH, JSON.stringify({
"version": "2",
"pinnedList": this._pinnedList,
"aliasMap": this._aliasMap
}));
} else {
if (fs.existsSync(CONFIG_PATH)) {
fs.unlinkSync(CONFIG_PATH);
Expand All @@ -105,6 +136,16 @@ class PinDataProvider {
RemovePin(element) {
let index = this._pinnedList.indexOf(element.uri.path);
this._pinnedList.splice(index, 1);
delete this._aliasMap[element.uri.path];
this.refresh();
}

AliasPin(element, alias) {
if (alias) {
this._aliasMap[element.uri.path] = alias;
} else {
delete this._aliasMap[element.uri.path];
}
this.refresh();
}

Expand Down
9 changes: 9 additions & 0 deletions src/commands.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,15 @@ module.exports = function (context) {
share.pindata.ClearPin();
}));

context.subscriptions.push(registerCommand('pin-up.alias-pin', async function (element) {
let input = await vscode.window.showInputBox({
"placeHolder": i18n("input-alias"),
"value": path.basename(path.dirname(element.uri.path))
});

share.pindata.AliasPin(element, input);
}));

/******* Files Operation *******/

context.subscriptions.push(registerCommand('pin-up.fs-create-file', async function (element) {
Expand Down
2 changes: 2 additions & 0 deletions src/i18n.runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,15 @@ const translate = {
"no": "No",
"input-file-name": "Please input file name",
"input-folder-name": "Please input folder name",
"input-alias": "Please input alias",
"file-exists": "Directory/File is already exists, do you want to overwrite it?"
},
"zh": {
"yes": "是",
"no": "否",
"input-file-name": "请输入文件名",
"input-folder-name": "请输入目录名",
"input-alias": "请输入别名",
"file-exists": "文件或目录已存在,是否覆盖?"
}
}
Expand Down

0 comments on commit e8a7cc0

Please sign in to comment.