Skip to content

Commit

Permalink
Merge pull request #60 from tahabasri/release/3.0.0
Browse files Browse the repository at this point in the history
Release/3.0.0
  • Loading branch information
tahabasri authored Feb 13, 2023
2 parents 6629670 + 5b5eb53 commit c1443d8
Show file tree
Hide file tree
Showing 9 changed files with 142 additions and 7 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
# Change Log
### 3.0.0

- [[#56](https://github.com/tahabasri/snippets/pull/56)] Added support for drag and drop 🙌.
- Added new command for copying Snippet to clipboard.
- Made configurable the automatic execution of copied commands in terminal.
- Updated vulnerable dependencies.

### 2.2.2

- Update vulnerable dependencies.
Expand Down
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ alt="Create Snippet Manually">

### Organize Snippets

You have the flexibility to reorder your snippets, there is no default order.
Drag and drop ! That simple !

<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/056-drag-and-drop.gif"
alt="Drag and Drop Snippets">

You have the flexibility to reorder your snippets, there is no forced order.

<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/04-snippets-reorder.gif"
alt="Reorder Snippets">
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

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

24 changes: 22 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
"name": "snippets",
"displayName": "Snippets",
"description": "Manage your code snippets without quitting your editor.",
"version": "2.2.2",
"preview": false,
"version": "3.0.0",
"preview": true,
"license": "SEE LICENSE IN LICENSE.txt",
"publisher": "tahabasri",
"author": {
Expand Down Expand Up @@ -77,6 +77,11 @@
"title": "Open Snippet in Terminal",
"category": "Snippets"
},
{
"command": "globalSnippetsCmd.copySnippetToClipboard",
"title": "Copy Snippet to Clipboard",
"category": "Snippets"
},
{
"command": "commonSnippetsCmd.addSnippet",
"title": "New Snippet",
Expand Down Expand Up @@ -360,6 +365,11 @@
"when": "view == snippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
"group": "1_snippets@2"
},
{
"command": "globalSnippetsCmd.copySnippetToClipboard",
"when": "view == snippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
"group": "1_snippets@3"
},
{
"command": "globalSnippetsCmd.addSnippet",
"when": "view == snippetsExplorer",
Expand Down Expand Up @@ -459,6 +469,11 @@
"command": "globalSnippetsCmd.openSnippetInTerminal",
"when": "view == wsSnippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
"group": "1_snippets@2"
},
{
"command": "globalSnippetsCmd.copySnippetToClipboard",
"when": "view == wsSnippetsExplorer && viewItem =~ /^snippet(:\\S+)?$/",
"group": "1_snippets@3"
}
],
"editor/context": [
Expand Down Expand Up @@ -525,6 +540,11 @@
"type": "boolean",
"default": true,
"markdownDescription": "Show a confirmation alert before deleting a snippet/folder."
},
"snippets.runCommandInTerminal": {
"type": "boolean",
"default": false,
"markdownDescription": "Automatically execute open commands in terminal."
}
}
}
Expand Down
1 change: 1 addition & 0 deletions src/config/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export const enum CommandsConsts {
// common commands across global & ws
commonOpenSnippet = "globalSnippetsCmd.openSnippet",
commonOpenSnippetInTerminal = "globalSnippetsCmd.openSnippetInTerminal",
commonCopySnippetToClipboard = "globalSnippetsCmd.copySnippetToClipboard",
commonAddSnippet = "commonSnippetsCmd.addSnippet",
commonAddSnippetFromClipboard = "commonSnippetsCmd.addSnippetFromClipboard",
commonAddSnippetFolder = "commonSnippetsCmd.addSnippetFolder",
Expand Down
22 changes: 20 additions & 2 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import { SnippetsProvider } from './provider/snippetsProvider';
import { MementoDataAccess } from './data/mementoDataAccess';
import { Snippet } from './interface/snippet';
import { EditSnippetFolder } from './views/editSnippetFolder';
import { NewRelease } from './views/newRelease';
import { SnippetService } from './service/snippetService';
import { UIUtility } from './utility/uiUtility';
import { StringUtility } from './utility/stringUtility';
Expand All @@ -17,6 +18,9 @@ import { FileDataAccess } from './data/fileDataAccess';
* @param context
*/
export function activate(context: vscode.ExtensionContext) {
// exact version for which show Changelog panel
const changelogVersion = '3.0.0';

//** variables **//
// global settings
const snippetsConfigKey = "snippets";
Expand Down Expand Up @@ -46,6 +50,16 @@ export function activate(context: vscode.ExtensionContext) {
const snippetsProvider = new SnippetsProvider(snippetService, context.extensionPath);
let cipDisposable: { dispose(): any };

// show What's new if it's first time at current release
const currentVersion = context.extension.packageJSON.version;
// generate release identifier for changelog related property
const releaseChangelogId = `skipChangelog_${currentVersion}`;
// if the key is undefined or value is not true, show Changelog window
if (!context.globalState.get(releaseChangelogId) && currentVersion === changelogVersion) {
new NewRelease(context);
context.globalState.update(releaseChangelogId, true);
}

//** upgrade from 1.x to 2.x **//
let oldSnippetsPath: string = vscode.workspace.getConfiguration('snippets').get('snippetsLocation')
|| path.join(context.globalStorageUri.fsPath, "data.json");
Expand Down Expand Up @@ -249,7 +263,7 @@ export function activate(context: vscode.ExtensionContext) {
if (!vscode.workspace.getConfiguration(snippetsConfigKey).get("showSuggestions")) {
return;
}
let isTriggeredByChar = triggerCharacter === document.lineAt(position).text.charAt(position.character - 1);
let isTriggeredByChar: boolean = triggerCharacter === document.lineAt(position).text.charAt(position.character - 1);
// append workspace snippets if WS is available
let candidates = snippetService.getAllSnippets();
if (workspaceSnippetsAvailable) {
Expand Down Expand Up @@ -333,10 +347,14 @@ export function activate(context: vscode.ExtensionContext) {
if (!snippet) {
return;
}
terminal.sendText(snippet.value);
terminal.sendText(snippet.value, vscode.workspace.getConfiguration('snippets').get('runCommandInTerminal'));
})
));

context.subscriptions.push(vscode.commands.registerCommand(commands.CommandsConsts.commonCopySnippetToClipboard,
async (snippet) => handleCommand(async () => vscode.env.clipboard.writeText(snippet.value))
));

//** COMMAND : ADD SNIPPET **/

context.subscriptions.push(vscode.commands.registerCommand(commands.CommandsConsts.commonAddSnippet,
Expand Down
47 changes: 47 additions & 0 deletions src/views/newRelease.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
import * as vscode from 'vscode';
import * as path from 'path';
import * as fs from 'fs';
import * as mustache from 'mustache';

export class NewRelease {
private static readonly viewsFolder: string = 'views';
protected readonly _viewType: string = 'newRelease';
protected readonly _iconName: string = 'file';
protected readonly _panel: vscode.WebviewPanel;

constructor(
context: vscode.ExtensionContext,
) {
const title = 'Snippets - What\'s New';
const version = context.extension.packageJSON.version;
this._panel = vscode.window.createWebviewPanel(
this._viewType,
title,
{
viewColumn: vscode.ViewColumn.One,
preserveFocus: true
},
{
retainContextWhenHidden: true,
enableCommandUris: true,
localResourceRoots: [vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder))]
}
);

this._panel.iconPath = {
light: vscode.Uri.file(path.join(__filename, '..', '..', 'resources', 'icons', 'light', `${this._iconName}.svg`)),
dark: vscode.Uri.file(path.join(__filename, '..', '..', 'resources', 'icons', 'dark', `${this._iconName}.svg`))
};

const htmlTemplate = path.join(context.extensionPath, NewRelease.viewsFolder, `${this._viewType}.html`);
this._panel.webview.html = mustache.render(fs.readFileSync(htmlTemplate).toString(),
{
cspSource: this._panel.webview.cspSource,
resetCssUri: this._panel.webview.asWebviewUri(vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder, 'css', 'reset.css'))),
cssUri: this._panel.webview.asWebviewUri(vscode.Uri.file(path.join(context.extensionPath, NewRelease.viewsFolder, 'css', 'vscode-custom.css'))),
title: title,
version: version
}
);
}
}
5 changes: 5 additions & 0 deletions views/css/vscode-custom.css
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,9 @@ textarea {
display: inline;
color: var(--vscode-button-secondaryForeground);
background: var(--vscode-button-secondaryBackground);
}

.changelog-header {
display: inline-block;
position: fixed;
}
32 changes: 32 additions & 0 deletions views/newRelease.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Content-Security-Policy"
content="default-src 'none'; img-src {{cspSource}} https:; script-src {{cspSource}}; style-src {{cspSource}};">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>{{title}}</title>
<link rel="stylesheet" href="{{resetCssUri}}">
<link rel="stylesheet" href="{{cssUri}}">
</head>
<body>
<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>
<hr style="margin-top: 10px;"/>
<div>
<h2>🎉 Better Late Than Never !</h2>
<h3>You can now drag and drop snippets and folders ✨</h3>
<br/>
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/features/056-drag-and-drop.gif"
width="400px" alt="Drag and Drop Snippets">
</div>
Check <a href="https://github.com/tahabasri/snippets/blob/main/CHANGELOG.md" target="_blank">CHANGELOG.md</a> for full release notes.
<div>
<h2>✅ Always Backup Your Snippets</h2>
<h3>Don't forget to backup your data using the <b>Export Snippets</b> button before trying out the new release.</h3>
<br/>
<img src="https://raw.githubusercontent.com/tahabasri/snippets/main/images/release/backup-snippets.jpg"
width="500px" alt="Backup Snippets">
</div>

</body>
</html>

0 comments on commit c1443d8

Please sign in to comment.