Skip to content

Commit c1443d8

Browse files
authored
Merge pull request #60 from tahabasri/release/3.0.0
Release/3.0.0
2 parents 6629670 + 5b5eb53 commit c1443d8

File tree

9 files changed

+142
-7
lines changed

9 files changed

+142
-7
lines changed

CHANGELOG.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,11 @@
11
# Change Log
2+
### 3.0.0
3+
4+
- [[#56](https://github.com/tahabasri/snippets/pull/56)] Added support for drag and drop 🙌.
5+
- Added new command for copying Snippet to clipboard.
6+
- Made configurable the automatic execution of copied commands in terminal.
7+
- Updated vulnerable dependencies.
8+
29
### 2.2.2
310

411
- Update vulnerable dependencies.

README.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,12 @@ alt="Create Snippet Manually">
4040

4141
### Organize Snippets
4242

43-
You have the flexibility to reorder your snippets, there is no default order.
43+
Drag and drop ! That simple !
44+
45+
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/056-drag-and-drop.gif"
46+
alt="Drag and Drop Snippets">
47+
48+
You have the flexibility to reorder your snippets, there is no forced order.
4449

4550
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/04-snippets-reorder.gif"
4651
alt="Reorder Snippets">

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
"name": "snippets",
33
"displayName": "Snippets",
44
"description": "Manage your code snippets without quitting your editor.",
5-
"version": "2.2.2",
6-
"preview": false,
5+
"version": "3.0.0",
6+
"preview": true,
77
"license": "SEE LICENSE IN LICENSE.txt",
88
"publisher": "tahabasri",
99
"author": {
@@ -77,6 +77,11 @@
7777
"title": "Open Snippet in Terminal",
7878
"category": "Snippets"
7979
},
80+
{
81+
"command": "globalSnippetsCmd.copySnippetToClipboard",
82+
"title": "Copy Snippet to Clipboard",
83+
"category": "Snippets"
84+
},
8085
{
8186
"command": "commonSnippetsCmd.addSnippet",
8287
"title": "New Snippet",
@@ -360,6 +365,11 @@
360365
"when": "view == snippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
361366
"group": "1_snippets@2"
362367
},
368+
{
369+
"command": "globalSnippetsCmd.copySnippetToClipboard",
370+
"when": "view == snippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
371+
"group": "1_snippets@3"
372+
},
363373
{
364374
"command": "globalSnippetsCmd.addSnippet",
365375
"when": "view == snippetsExplorer",
@@ -459,6 +469,11 @@
459469
"command": "globalSnippetsCmd.openSnippetInTerminal",
460470
"when": "view == wsSnippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
461471
"group": "1_snippets@2"
472+
},
473+
{
474+
"command": "globalSnippetsCmd.copySnippetToClipboard",
475+
"when": "view == wsSnippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
476+
"group": "1_snippets@3"
462477
}
463478
],
464479
"editor/context": [
@@ -525,6 +540,11 @@
525540
"type": "boolean",
526541
"default": true,
527542
"markdownDescription": "Show a confirmation alert before deleting a snippet/folder."
543+
},
544+
"snippets.runCommandInTerminal": {
545+
"type": "boolean",
546+
"default": false,
547+
"markdownDescription": "Automatically execute open commands in terminal."
528548
}
529549
}
530550
}

src/config/commands.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ export const enum CommandsConsts {
1212
// common commands across global & ws
1313
commonOpenSnippet = "globalSnippetsCmd.openSnippet",
1414
commonOpenSnippetInTerminal = "globalSnippetsCmd.openSnippetInTerminal",
15+
commonCopySnippetToClipboard = "globalSnippetsCmd.copySnippetToClipboard",
1516
commonAddSnippet = "commonSnippetsCmd.addSnippet",
1617
commonAddSnippetFromClipboard = "commonSnippetsCmd.addSnippetFromClipboard",
1718
commonAddSnippetFolder = "commonSnippetsCmd.addSnippetFolder",

src/extension.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { SnippetsProvider } from './provider/snippetsProvider';
66
import { MementoDataAccess } from './data/mementoDataAccess';
77
import { Snippet } from './interface/snippet';
88
import { EditSnippetFolder } from './views/editSnippetFolder';
9+
import { NewRelease } from './views/newRelease';
910
import { SnippetService } from './service/snippetService';
1011
import { UIUtility } from './utility/uiUtility';
1112
import { StringUtility } from './utility/stringUtility';
@@ -17,6 +18,9 @@ import { FileDataAccess } from './data/fileDataAccess';
1718
* @param context
1819
*/
1920
export function activate(context: vscode.ExtensionContext) {
21+
// exact version for which show Changelog panel
22+
const changelogVersion = '3.0.0';
23+
2024
//** variables **//
2125
// global settings
2226
const snippetsConfigKey = "snippets";
@@ -46,6 +50,16 @@ export function activate(context: vscode.ExtensionContext) {
4650
const snippetsProvider = new SnippetsProvider(snippetService, context.extensionPath);
4751
let cipDisposable: { dispose(): any };
4852

53+
// show What's new if it's first time at current release
54+
const currentVersion = context.extension.packageJSON.version;
55+
// generate release identifier for changelog related property
56+
const releaseChangelogId = `skipChangelog_${currentVersion}`;
57+
// if the key is undefined or value is not true, show Changelog window
58+
if (!context.globalState.get(releaseChangelogId) && currentVersion === changelogVersion) {
59+
new NewRelease(context);
60+
context.globalState.update(releaseChangelogId, true);
61+
}
62+
4963
//** upgrade from 1.x to 2.x **//
5064
let oldSnippetsPath: string = vscode.workspace.getConfiguration('snippets').get('snippetsLocation')
5165
|| path.join(context.globalStorageUri.fsPath, "data.json");
@@ -249,7 +263,7 @@ export function activate(context: vscode.ExtensionContext) {
249263
if (!vscode.workspace.getConfiguration(snippetsConfigKey).get("showSuggestions")) {
250264
return;
251265
}
252-
let isTriggeredByChar = triggerCharacter === document.lineAt(position).text.charAt(position.character - 1);
266+
let isTriggeredByChar: boolean = triggerCharacter === document.lineAt(position).text.charAt(position.character - 1);
253267
// append workspace snippets if WS is available
254268
let candidates = snippetService.getAllSnippets();
255269
if (workspaceSnippetsAvailable) {
@@ -333,10 +347,14 @@ export function activate(context: vscode.ExtensionContext) {
333347
if (!snippet) {
334348
return;
335349
}
336-
terminal.sendText(snippet.value);
350+
terminal.sendText(snippet.value, vscode.workspace.getConfiguration('snippets').get('runCommandInTerminal'));
337351
})
338352
));
339353

354+
context.subscriptions.push(vscode.commands.registerCommand(commands.CommandsConsts.commonCopySnippetToClipboard,
355+
async (snippet) => handleCommand(async () => vscode.env.clipboard.writeText(snippet.value))
356+
));
357+
340358
//** COMMAND : ADD SNIPPET **/
341359

342360
context.subscriptions.push(vscode.commands.registerCommand(commands.CommandsConsts.commonAddSnippet,

src/views/newRelease.ts

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
import * as vscode from 'vscode';
2+
import * as path from 'path';
3+
import * as fs from 'fs';
4+
import * as mustache from 'mustache';
5+
6+
export class NewRelease {
7+
private static readonly viewsFolder: string = 'views';
8+
protected readonly _viewType: string = 'newRelease';
9+
protected readonly _iconName: string = 'file';
10+
protected readonly _panel: vscode.WebviewPanel;
11+
12+
constructor(
13+
context: vscode.ExtensionContext,
14+
) {
15+
const title = 'Snippets - What\'s New';
16+
const version = context.extension.packageJSON.version;
17+
this._panel = vscode.window.createWebviewPanel(
18+
this._viewType,
19+
title,
20+
{
21+
viewColumn: vscode.ViewColumn.One,
22+
preserveFocus: true
23+
},
24+
{
25+
retainContextWhenHidden: true,
26+
enableCommandUris: true,
27+
localResourceRoots: [vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder))]
28+
}
29+
);
30+
31+
this._panel.iconPath = {
32+
light: vscode.Uri.file(path.join(__filename, '..', '..', 'resources', 'icons', 'light', `${this._iconName}.svg`)),
33+
dark: vscode.Uri.file(path.join(__filename, '..', '..', 'resources', 'icons', 'dark', `${this._iconName}.svg`))
34+
};
35+
36+
const htmlTemplate = path.join(context.extensionPath, NewRelease.viewsFolder, `${this._viewType}.html`);
37+
this._panel.webview.html = mustache.render(fs.readFileSync(htmlTemplate).toString(),
38+
{
39+
cspSource: this._panel.webview.cspSource,
40+
resetCssUri: this._panel.webview.asWebviewUri(vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder, 'css', 'reset.css'))),
41+
cssUri: this._panel.webview.asWebviewUri(vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder, 'css', 'vscode-custom.css'))),
42+
title: title,
43+
version: version
44+
}
45+
);
46+
}
47+
}

views/css/vscode-custom.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,4 +107,9 @@ textarea {
107107
display: inline;
108108
color: var(--vscode-button-secondaryForeground);
109109
background: var(--vscode-button-secondaryBackground);
110+
}
111+
112+
.changelog-header {
113+
display: inline-block;
114+
position: fixed;
110115
}

views/newRelease.html

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="Content-Security-Policy"
6+
content="default-src 'none'; img-src {{cspSource}} https:; script-src {{cspSource}}; style-src {{cspSource}};">
7+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
8+
<title>{{title}}</title>
9+
<link rel="stylesheet" href="{{resetCssUri}}">
10+
<link rel="stylesheet" href="{{cssUri}}">
11+
</head>
12+
<body>
13+
<h1><img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/logo/logo.png" width="35px"><p class="changelog-header">{{title}} (version {{version}})</p></h1>
14+
<hr style="margin-top: 10px;"/>
15+
<div>
16+
<h2>🎉 Better Late Than Never !</h2>
17+
<h3>You can now drag and drop snippets and folders ✨</h3>
18+
<br/>
19+
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/056-drag-and-drop.gif"
20+
width="400px" alt="Drag and Drop Snippets">
21+
</div>
22+
Check <a href="https://github.com/tahabasri/snippets/blob/main/CHANGELOG.md" target="_blank">CHANGELOG.md</a> for full release notes.
23+
<div>
24+
<h2>✅ Always Backup Your Snippets</h2>
25+
<h3>Don't forget to backup your data using the <b>Export Snippets</b> button before trying out the new release.</h3>
26+
<br/>
27+
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/release/backup-snippets.jpg"
28+
width="500px" alt="Backup Snippets">
29+
</div>
30+
31+
</body>
32+
</html>

0 commit comments

Comments
 (0)