Skip to content

Commit

Permalink
Release 1.2.0
Browse files Browse the repository at this point in the history
  • Loading branch information
SaekiRaku committed Jun 5, 2020
1 parent b7e8134 commit 3d9ba0b
Show file tree
Hide file tree
Showing 8 changed files with 216 additions and 12 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.2.0] - 2020-06-06

- Added: Create file/folder and delete it in Pinned List.
- Fixed: Add category property to each commands.

## [1.1.1] - 2020-05-29

- Added: I18N Support of Chinese.
Expand Down
11 changes: 8 additions & 3 deletions i18n/package.nls.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"pinned-files": "📌 Pinned Files",
"welcome": "An extension that allows you to pin up some frequently opened files to here. \n Right click your files, and go for \"📌Pin Up\"! \n [Learn More](https://github.com/SaekiRaku/vscode-pin-up)",
"pinned-files": "📌 Pinned Files",

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

"fs-create-file": "New File",
"fs-create-folder": "New Folder",
"fs-delete": "Delete to Trash"
}
11 changes: 8 additions & 3 deletions i18n/package.nls.zh.json
Original file line number Diff line number Diff line change
@@ -1,8 +1,13 @@
{
"pinned-files": "📌 已固定文件",
"welcome": "该扩展可以将一些经常打开的文件固定到此处。\n 右键单击文件然后选择 \"📌 固定\"! \n [了解更多](https://github.com/SaekiRaku/vscode-pin-up)",
"pinned-files": "📌 已固定文件",

"pin-up": "📌 固定",
"pin-up-outside": "📌 固定外部文件",
"remove": "移除",
"remove-all": "移除全部"
"remove-pin": "移除固定",
"remove-all": "移除全部",

"fs-create-file": "新建文件",
"fs-create-folder": "新建目录",
"fs-delete": "删除到回收站"
}
60 changes: 57 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
"name": "pin-up",
"displayName": "Pin Up",
"description": "Pin up files and folders that was frequently opened in your project.",
"version": "1.1.1",
"version": "1.2.0",
"engines": {
"vscode": "^1.44.0"
},
Expand All @@ -22,10 +22,12 @@
"commands": [
{
"command": "pin-up.add-pin",
"category": "Pin Up",
"title": "%pin-up%"
},
{
"command": "pin-up.add-pin-outside",
"category": "Pin Up",
"title": "%pin-up-outside%",
"icon": {
"light": "resources/add-light.svg",
Expand All @@ -34,15 +36,32 @@
},
{
"command": "pin-up.remove-pin",
"title": "%remove%",
"category": "Pin Up",
"title": "%remove-pin%",
"icon": {
"light": "resources/remove-light.svg",
"dark": "resources/remove-dark.svg"
}
},
{
"command": "pin-up.clear-pin",
"category": "Pin Up",
"title": "%remove-all%"
},
{
"command": "pin-up.fs-create-file",
"category": "Pin Up",
"title": "%fs-create-file%"
},
{
"command": "pin-up.fs-create-folder",
"category": "Pin Up",
"title": "%fs-create-folder%"
},
{
"command": "pin-up.fs-delete",
"category": "Pin Up",
"title": "%fs-delete%"
}
],
"viewsContainers": {
Expand Down Expand Up @@ -76,9 +95,32 @@
]
},
"menus": {
"commandPalette": [
{
"command": "pin-up.add-pin",
"when": "filesExplorerFocus"
},
{
"command": "pin-up.remove-pin",
"when": "filesExplorerFocus"
},
{
"command": "pin-up.fs-create-file",
"when": "filesExplorerFocus"
},
{
"command": "pin-up.fs-create-folder",
"when": "filesExplorerFocus"
},
{
"command": "pin-up.fs-delete",
"when": "filesExplorerFocus"
}
],
"explorer/context": [
{
"command": "pin-up.add-pin"
"command": "pin-up.add-pin",
"group": "pin-up"
}
],
"view/title": [
Expand All @@ -100,6 +142,18 @@
{
"when": "viewItem == pinned",
"command": "pin-up.remove-pin"
},
{
"command": "pin-up.fs-create-file",
"group": "files-operation@1"
},
{
"command": "pin-up.fs-create-folder",
"group": "files-operation@2"
},
{
"command": "pin-up.fs-delete",
"group": "files-operation@3"
}
]
}
Expand Down
4 changes: 4 additions & 0 deletions src/PinDataProvider.js
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,10 @@ class PinDataProvider {
}
this.refresh();
}

HavePin(filepath) {
return (this._pinnedList.indexOf(filepath) !== -1)
}
}

module.exports = PinDataProvider;
70 changes: 70 additions & 0 deletions src/commands.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
const fs = require("fs");
const path = require("path");
const vscode = require('vscode');
const { registerCommand, executeCommand } = vscode.commands;
const utils = require("./utils.js");
const i18n = require("./i18n.runtime.js");

var share = require("./share.js");

Expand Down Expand Up @@ -31,6 +34,73 @@ module.exports = function (context) {
share.pindata.ClearPin();
}));

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

context.subscriptions.push(registerCommand('pin-up.fs-create-file', async function (element) {
let input = await vscode.window.showInputBox({
"placeHolder": i18n("input-file-name")
})

if (!input) {
return;
}

let basepath = utils.fixedPath(element.uri.path);
let finalpath;
if (fs.statSync(basepath).isDirectory()) {
finalpath = path.resolve(basepath, input);
} else {
finalpath = path.resolve(path.dirname(basepath), input);
}

if (fs.existsSync(finalpath)) {
let overwrite = await utils.uiConfirm(i18n("file-exists"));
if (!overwrite) {
return;
}
}

fs.writeFileSync(finalpath, "");
share.pindata.refresh();
}));

context.subscriptions.push(registerCommand('pin-up.fs-create-folder', async function (element) {
let input = await vscode.window.showInputBox({
"placeHolder": i18n("input-folder-name")
})

if (!input) {
return;
}

let basepath = utils.fixedPath(element.uri.path);
let finalpath;
if (fs.statSync(basepath).isDirectory()) {
finalpath = path.resolve(basepath, input);
} else {
finalpath = path.resolve(path.dirname(basepath), input);
}

if (fs.existsSync(finalpath)) {
let overwrite = await utils.uiConfirm(i18n("file-exists"));
if (!overwrite) {
return;
}
}

fs.mkdirSync(finalpath, { recursive: true });
share.pindata.refresh();
}));

context.subscriptions.push(registerCommand('pin-up.fs-delete', async function (element) {
let filepath = utils.fixedPath(element.uri.path);
if (share.pindata.HavePin(filepath)) {
share.pindata.RemovePin(element)
}
vscode.workspace.fs.delete(element.uri, { recursive: true, useTrash: true });
share.pindata.refresh();
}));

/******* Common Commands *******/

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

module.exports = function (message) {
let locale = JSON.parse(process.env.VSCODE_NLS_CONFIG).locale;
if (locale.indexOf("zh") == 0) {
locale = "zh"
}
let t = translate[locale] || translate["en"];
return t[message] || message;
}
42 changes: 39 additions & 3 deletions src/utils.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,46 @@
const os = require("os");
const vscode = require('vscode');
const i18n = require("./i18n.runtime.js");

exports.fixedPath = function(thepath){
if(os.type() == "Windows_NT"){
if(thepath[0]==="/"){
exports.fixedPath = function (thepath) {
if (os.type() == "Windows_NT") {
if (thepath[0] === "/") {
return thepath.slice(1, thepath.length);
}
}
return thepath;
}

exports.uiConfirm = async function (title) {
let YES = i18n("yes");
let NO = i18n("no");
let quickpick = vscode.window.createQuickPick();
quickpick.title = title;
quickpick.items = [{
label: YES
}, {
label: NO
}];

quickpick.show();

let pick = await new Promise((resolve, reject) => {
let select = "";

quickpick.onDidChangeSelection((evt) => {
select = evt[0].label;
});

quickpick.onDidAccept((evt) => {
quickpick.hide();
resolve(select);
})
})

quickpick.dispose();

if (!pick || pick === NO) {
return false;
}
return true;
}

0 comments on commit 3d9ba0b

Please sign in to comment.