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

Commit 4400068

Browse files
committed
Added EDIT option & WIP: IMEX module
1 parent 9dc3ce0 commit 4400068

File tree

3 files changed

+81
-1
lines changed

3 files changed

+81
-1
lines changed

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: 57 additions & 1 deletion
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,6 +43,7 @@ export default {
4343
'snippet-injector:create': () => this.create(),
4444
'snippet-injector:insert': () => this.insert(),
4545
'snippet-injector:delete': () => this.delete(),
46+
'snippet-injector:update': () => this.edit(),
4647
// 'snippet-injector:toggle-time-debug': () => this.debugTime(),
4748
// 'snippet-injector:toggle-object-debug': () => this.debugObjects(),
4849
'snippet-injector:toggledebug': () => this.toggleDebug()
@@ -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 & 0 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,6 +36,10 @@
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"

0 commit comments

Comments
 (0)