@@ -55,10 +55,38 @@ define(['base/js/namespace',
5555 } ) ;
5656 }
5757
58+ function get_snippets ( ) {
59+ var storage = window [ 'localStorage' ] ;
60+ var stored_snippets = storage . getItem ( 'JupyterNotebookSnippets' ) ;
61+ if ( stored_snippets == null ) {
62+ return { } ;
63+ } else {
64+ return JSON . parse ( stored_snippets ) ;
65+ }
66+ }
67+
5868 function add_cell_from_snippet_manager ( ) {
5969 var selected_index = Jupyter . notebook . get_selected_index ( ) ;
6070
6171 var modal_content = $ ( '<p/>' ) . html ( 'Select a snippet to insert.' ) ;
72+ modal_content . append ( '<br><br>' ) ;
73+ var list_content = $ ( '<div id="snippets" style="white-space: pre-wrap;">' ) ;
74+ list_content . append ( '<input class="search" placeholder="Search Snippets">' ) ;
75+ list_content . append ( '<br><br>' ) ;
76+
77+ var table = $ ( '<table class="table"><tbody class="list"></tbody></table>' ) ;
78+ var table_children = table . children ( ) ;
79+ table_children . append ( '<tr><th>Snippet Name</th><th>Snippet Content</th></tr>' ) ;
80+
81+ var snippets = get_snippets ( ) ;
82+ for ( var index in snippets ) {
83+ var snippet = snippets [ index ] ;
84+ table_children . append ( '<tr><td class="name">' + index + '</td>' +
85+ '<td class="content">' + snippet + '</td></tr>' ) ;
86+ }
87+
88+ list_content . append ( table ) ;
89+ modal_content . append ( list_content ) ;
6290
6391 dialog . modal ( {
6492 title : 'Select A Snippet to Include' ,
@@ -114,7 +142,6 @@ define(['base/js/namespace',
114142 'buttons' : { OK : { } }
115143 } ) ;
116144 }
117- console . log ( list ) ;
118145 }
119146
120147 return {
0 commit comments