@@ -347,24 +347,63 @@ ipc.on('closeFile',function(event){
347347 closeCurrentFile ( file ) ;
348348} ) ;
349349
350+ // generate valid ID from path
351+
352+ function pathToId ( filepath ) {
353+ filepath = filepath . replace ( / / g, '_' ) ;
354+ filepath = filepath . replace ( / : / g, '' ) ;
355+ let tokens = filepath . split ( path . sep ) ;
356+ let ID = '' ;
357+ for ( let i = 0 ; i < tokens . length ; i ++ ) {
358+ ID += tokens [ i ] ;
359+ }
360+ // console.log(ID);
361+ return ID ;
362+ }
363+
364+
350365
351366// open folder
352367ipc . on ( 'openFolder' , function ( event , structure ) {
353368 let response = '<ul class="file-tree"><li><a href="#"><span class = "label">' + structure . name + '</span></a><ul>' ;
354369 response += makeDirectoryTree ( structure . children ) ;
355370 response += '</ul>' ;
356371 $ ( '#project-structure' ) . html ( response ) ;
372+ // console.log($('#project-structure'));
357373 $ ( ".file-tree" ) . filetree ( ) ;
358374 openProjectStructure ( true ) ;
359375} ) ;
360376
377+ // create directory for specific Dirpath
378+
379+ function createDirectoryForSpecificDirpath ( folder ) {
380+ // console.log(folder.getAttribute('data-path'));
381+ // console.log($('#' + pathToId(folder.getAttribute('data-path'))).length);
382+ // console.log($('#' + pathToId(folder.getAttribute('data-path'))).children());
383+
384+ if ( $ ( '#' + pathToId ( folder . getAttribute ( 'data-path' ) ) ) . children ( ) . length == 0 ) {
385+ ipc . send ( 'createDirectoryForSpecificDirpath' , folder . getAttribute ( 'data-path' ) ) ;
386+ }
387+ }
388+
389+ ipc . on ( 'getDirectroyForSpecificDirpath' , function ( event , structure ) {
390+ // console.log(structure);
391+ // console.log(structure.path);
392+ // console.log(makeDirectoryTree(structure.children));
393+ // console.log($('#' + structure.path.replace(/ /g, '_')));
394+ // console.log($('#askdfhkjashdfkjasdf'))
395+
396+ $ ( '#' + pathToId ( structure . path ) ) . html ( makeDirectoryTree ( structure . children ) ) ;
397+ $ ( '#' + pathToId ( structure . path ) ) . filetree ( ) ;
398+ } ) ;
361399// create tree structure for opened folder
362400
363401function makeDirectoryTree ( structure ) {
364402 var response = "" ;
365403 structure . forEach ( function ( obj ) {
366404 if ( obj . type == "folder" ) {
367- response += '<li><a href="#"><span class = "label">' + obj . name + '</span></a><ul>' + makeDirectoryTree ( obj . children ) + '</ul></li>' ;
405+ // response += '<li><a href="#"><span class = "label">'+ obj.name + '</span></a><ul>' + makeDirectoryTree(obj.children) + '</ul></li>';
406+ response += '<li><a href="#"><span class = "label" onclick = "createDirectoryForSpecificDirpath(this)" data-path = "' + obj . path + '">' + obj . name + '</span></a><ul id = "' + pathToId ( obj . path ) + '"></ul></li>' ;
368407 } else {
369408 response += '<li data-extension = "' + obj . name + '"><a href="#"><span onclick = "openFileFromSidebar(this)" class = "label" data-name = "' + obj . name + '" data-path = "' + obj . path + '">' + obj . name + '</span></a></li>' ;
370409 }
@@ -591,19 +630,19 @@ $(".panel-middle").resizable({
591630// create directory tree structure
592631
593632
594- $ ( document ) . ready ( function ( ) {
595- $ ( ".file-tree" ) . filetree ( ) ;
596- } ) ;
597- var _gaq = _gaq || [ ] ;
598- _gaq . push ( [ '_setAccount' , 'UA-36251023-1' ] ) ;
599- _gaq . push ( [ '_setDomainName' , 'jqueryscript.net' ] ) ;
600- _gaq . push ( [ '_trackPageview' ] ) ;
601-
602- ( function ( ) {
603- var ga = document . createElement ( 'script' ) ; ga . type = 'text/javascript' ; ga . async = true ;
604- ga . src = ( 'https:' == document . location . protocol ? 'https://ssl' : 'http://www' ) + '.google-analytics.com/ga.js' ;
605- var s = document . getElementsByTagName ( 'script' ) [ 0 ] ; s . parentNode . insertBefore ( ga , s ) ;
606- } ) ( ) ;
633+ // $(document).ready(function() {
634+ // $(".file-tree").filetree();
635+ // });
636+ // var _gaq = _gaq || [];
637+ // _gaq.push(['_setAccount', 'UA-36251023-1']);
638+ // _gaq.push(['_setDomainName', 'jqueryscript.net']);
639+ // _gaq.push(['_trackPageview']);
640+
641+ // (function() {
642+ // var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
643+ // ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
644+ // var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
645+ // })();
607646
608647// run program
609648function run ( ) {
0 commit comments