@@ -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} ;
0 commit comments