Skip to content
This repository was archived by the owner on Dec 12, 2021. It is now read-only.

Commit 2a518e7

Browse files
committed
Merge branch 'dev'
2 parents 9276043 + 216ab0a commit 2a518e7

File tree

6 files changed

+105
-36
lines changed

6 files changed

+105
-36
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,13 @@
66
**latest release**
77
#### Features
88
- Snippet tag functionalities
9+
- Edit option for snippets
910
#### Improvements
10-
11+
- Quick Start Guide enhanced
12+
- `README.md`
1113
#### Patches
1214
- Debug output
15+
- Available debug commands reduced
1316
- Search prompt
1417

1518

HOWTO.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ The snippet is now saved in you local Atom storage.
2424
### Insert
2525
(_[Reference](README.md#commands)_)
2626

27-
Place the marker(s) at the position you want you snippet to be inserted.
27+
Place the marker(s) at the position you want your snippet to be inserted.
2828
Open up the context menu and click on `Insert snippet`.
2929

3030
[ ![](/screenshots/insert_step_1-small.png) (full screenshot)](http://prntscr.com/fzcyrt)
@@ -46,7 +46,7 @@ Open up the context menu and click on `Delete snippet`.
4646

4747
[ ![](/screenshots/delete_step_1-small.png) (full screenshot)](http://prntscr.com/fzczas)
4848

49-
Enter the title of the snippet you want to delete and confirm.
49+
Choose the snippet you want to delete from the dropdown-list. Choosing one confirms the prompt automatically.
5050
*(You will be prompted twice before actual deletion. Bare in mind that deleted snippets are gone forever!)*
5151

5252
[ ![](/screenshots/delete_step_2-small.png) (full screenshot)](http://prntscr.com/fzczf4)

README.md

Lines changed: 15 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ You will be prompted for a snippet title.
2424
*Name in menus:*
2525
> "Create snippet from selection"
2626
27+
*Predefined Hotkey:*
28+
> "Ctrl + Alt + O"
29+
30+
31+
##### **snippet-injector:update**
32+
This command updates an existing snippet's content to the current selection in the current editor.
33+
You will be prompted for choosing an existing snippet.
34+
35+
*Name in menus:*
36+
> "Update existing snippet"
37+
2738

2839
##### **snippet-injector:insert**
2940
This command injects a snippet to the current marker position(s).
@@ -32,6 +43,9 @@ You will be prompted to choose a snippet from a list.
3243
*Name in menus:*
3344
> "Insert snippet"
3445
46+
*Predefined Hotkey:*
47+
> "Ctrl + Alt + I"
48+
3549

3650
##### **snippet-injector:delete**
3751
This command deletes a snippet from the local storage.
@@ -48,22 +62,6 @@ Debug informations are logged in Atom's console.
4862
*Please notice that this command is just available through command palette!*
4963

5064

51-
##### **snippet-injector:toggle-time-debug**
52-
This command toggles debugging of function durations.
53-
Debug informations are logged in Atom's console.
54-
55-
*Name in menus:*
56-
> "Toggle timing debug"
57-
58-
59-
##### **snippet-injector:toggle-object-debug**
60-
This command toggles debugging of the package state.
61-
Debug informations are logged in Atom's console.
62-
63-
*Name in menus:*
64-
> "Toggle object debug"
65-
66-
6765
---
6866

6967
### External Sources
@@ -75,9 +73,8 @@ All external sources used within this package are subject to their licenses and
7573
**This package uses the following libraries or contents:**
7674

7775
- DEVICON | *The list icons in the snippet selection prompt use SVG data from DEVICON*
78-
- [Icon Source](http://konpa.github.io/devicon/)
76+
- [Webpage](http://konpa.github.io/devicon/)
7977
- [Repository](https://github.com/konpa/devicon/)
8078
- jQuery
8179
- [Webpage](https://jquery.com/)
82-
- [NPM](https://www.npmjs.com/package/jquery)
8380
- [Repository](https://github.com/jquery/jquery)

lib/imex.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
'use babel';
2+
3+
export default class IMEX {
4+
5+
constructor(state) {
6+
if(new.target === IMEX) throw TypeError("Cannot instantiate abstract class IMEX.");
7+
}
8+
9+
// Returns an object that represents the current object state
10+
serialize() {
11+
return undefined;
12+
}
13+
14+
// Tear down any state and detach
15+
destroy() {}
16+
}

lib/snippet-injector.js

Lines changed: 60 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ export default {
2020
window.localStorage.setItem('snippet-injector-debug',true.toString());
2121
window.localStorage.setItem('snippet-injector-debug-time',_debug.default.timings.toString());
2222
window.localStorage.setItem('snippet-injector-debug-objl',_debug.default.objectLogging.toString());
23-
window.localStorage.setItem('snippet-injector-debug-group',_debug.groupTitle.main+' ~ '+_debug.groupTitle.timings);
23+
window.localStorage.setItem('snippet-injector-debug-group',_debug.groupTitle.main);
2424
window.localStorage.setItem('snippet-injector-debug-version',Util.getPackageVersion());
2525
}
2626

@@ -43,8 +43,9 @@ export default {
4343
'snippet-injector:create': () => this.create(),
4444
'snippet-injector:insert': () => this.insert(),
4545
'snippet-injector:delete': () => this.delete(),
46-
'snippet-injector:toggle-time-debug': () => this.debugTime(),
47-
'snippet-injector:toggle-object-debug': () => this.debugObjects(),
46+
'snippet-injector:update': () => this.edit(),
47+
// 'snippet-injector:toggle-time-debug': () => this.debugTime(),
48+
// 'snippet-injector:toggle-object-debug': () => this.debugObjects(),
4849
'snippet-injector:toggledebug': () => this.toggleDebug()
4950
}));
5051

@@ -238,7 +239,7 @@ export default {
238239
placeholder: 'Please choose a snippet...',
239240
btnconfirm: 'Delete',
240241
btncancel: 'Cancel',
241-
suremsg: 'Are you sure?',
242+
suremsg: 'Are you sure? <i>This action cannot be undone!</i>',
242243
items: items
243244
},function(element) {
244245
if(Util.isset(element,'string')) {
@@ -258,5 +259,60 @@ export default {
258259
console.timeEnd("snippet-injector:delete duration");
259260
console.groupEnd();
260261
}
262+
},
263+
264+
edit() {
265+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
266+
console.groupCollapsed(window.localStorage.getItem('snippet-injector-debug-group'));
267+
console.time("snippet-injector:update duration");
268+
}
269+
270+
var selection = atom.workspace.getActiveTextEditor().getSelectedText();
271+
var grammar = atom.workspace.getActiveTextEditor().getGrammar().name;
272+
273+
var storage = this.storage;
274+
var filenames = storage.retrieveFiles();
275+
if(filenames.length > 0) {
276+
var listitems = new Array();
277+
var icons = new Array();
278+
filenames.forEach(function(currentValue) {
279+
var elem = new Snippet(JSON.parse(storage.retrieveFile(currentValue.replace('.json',''))));
280+
listitems.push({
281+
title: elem.getTitle(),
282+
uid: elem.getUID(),
283+
tags: elem.getTags()
284+
});
285+
icons.push(elem.getLang());
286+
});
287+
288+
const searchPrompt = Util.promptSearch({
289+
title: 'Choose a snippet to update:',
290+
placeholder: 'Search snippets',
291+
listItems: listitems,
292+
btncancel: 'Cancel',
293+
nothingfound: 'No Snippets found that match you search.',
294+
icons: icons
295+
},function(element) {
296+
if(Util.isset(element,'string')) {
297+
var snippet = new Snippet(JSON.parse(storage.retrieveFile(element)));
298+
snippet.setContent(selection);
299+
snippet.setLang(grammar);
300+
snippet.setUID(snippet.getUID());
301+
302+
if(storage.store(snippet)) {
303+
atom.notifications.addSuccess('Snippet \''+snippet.getTitle()+'\' was successfully updated.', null);
304+
} else {
305+
atom.notifications.addError('An Error occured while updating the snippet "'+snippet.getTitle()+'".', null);
306+
}
307+
}
308+
});
309+
} else {
310+
atom.notifications.addWarning('No snippets found in the local storage directory.', null);
311+
}
312+
313+
if(window.localStorage.getItem('snippet-injector-debug') === 'true' && window.localStorage.getItem('snippet-injector-debug-time') === 'true') {
314+
console.timeEnd("snippet-injector:update duration");
315+
console.groupEnd();
316+
}
261317
}
262318
};

menus/snippet-injector.json

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,10 @@
88
"label": "Create Snippet from selection",
99
"command": "snippet-injector:create"
1010
},
11+
{
12+
"label": "Update existing snippet",
13+
"command": "snippet-injector:update"
14+
},
1115
{
1216
"label": "Insert Snippet",
1317
"command": "snippet-injector:insert"
@@ -32,24 +36,17 @@
3236
"label": "Create Snippet from selection",
3337
"command": "snippet-injector:create"
3438
},
39+
{
40+
"label": "Update existing snippet",
41+
"command": "snippet-injector:update"
42+
},
3543
{
3644
"label": "Insert Snippet",
3745
"command": "snippet-injector:insert"
3846
},
3947
{
4048
"label": "Delete Snippet",
4149
"command": "snippet-injector:delete"
42-
},
43-
{
44-
"type": "separator"
45-
},
46-
{
47-
"label": "Toggle timing debug",
48-
"command": "snippet-injector:toggle-time-debug"
49-
},
50-
{
51-
"label": "Toggle object debug",
52-
"command": "snippet-injector:toggle-object-debug"
5350
}
5451
]
5552
}

0 commit comments

Comments
 (0)