@@ -3,10 +3,10 @@ window.sidebarTabs = {
33}
44
55const treeChangeEvent = ( directoryEl , create ) => {
6- let directoriesInPath = directoryEl . full_path . split ( '\\' ) . length ;
6+ let parentDir = path . dirname ( directoryEl . full_path ) ;
7+ let directoriesInPath = parentDir . split ( '\\' ) . length ;
78 let directoriesInLaunchPath = launchArguments . split ( '\\' ) . length ;
89 let level = directoriesInPath - directoriesInLaunchPath ;
9- let parentDir = path . dirname ( directoryEl . full_path ) ;
1010 let index = directoryEl . index || file_explorer . folders [ parentDir ] . children . findIndex ( child => child . full_path === directoryEl . full_path ) ;
1111
1212 // ${level}_${parentDir}
@@ -15,7 +15,8 @@ const treeChangeEvent = (directoryEl, create) => {
1515 element : directoryEl ,
1616 parentDir,
1717 index,
18- create
18+ create,
19+ level
1920 }
2021 } )
2122}
@@ -155,14 +156,15 @@ window.file_explorer = {
155156
156157 if ( file_explorer . folders [ parentDir ] ) {
157158 if ( new Date ( ) - file_explorer . folders [ parentDir ] . last_sorted >= 500 ) {
158- file_explorer . folders [ parentDir ] . children = file_explorer . sortDirectories ( [ ...file_explorer . folders [ parentDir ] . children , details ] ) ;
159+ file_explorer . folders [ parentDir ] . children = file_explorer . sortDirectories ( [ ...( file_explorer . folders [ parentDir ] ) . children , details ] ) ;
159160 last_sorted = new Date ( ) ;
160161 } else {
161- file_explorer . folders [ parentDir ] . children = [ ...file_explorer . folders [ parentDir ] . children , details ] ;
162+ file_explorer . folders [ parentDir ] . children = [ ...( file_explorer . folders [ parentDir ] ) . children , details ] ;
162163 }
163164 }
164165 } else {
165166 if ( isFolder ) {
167+ console . log ( 'FOLDER GOT DELETED' , filePath ) ;
166168 file_explorer . folders [ filePath ] = undefined ;
167169 }
168170
@@ -183,17 +185,126 @@ window.file_explorer = {
183185 }
184186 // file_explorer.folders
185187 } ,
188+ explorerItemMenuConfig : ( full_path ) => [
189+ {
190+ label : 'Open Preview' ,
191+ name : 'open_preview' ,
192+ custom : ( filePath ) => {
193+ let fileBasename = path . basename ( filePath ) ;
194+ let isAMarkdownFile = fileBasename . includes ( '.md' ) ;
195+
196+ let canPreview = isAMarkdownFile ;
197+
198+ return canPreview ;
199+ }
200+ } ,
201+ {
202+ label : "Run Code" ,
203+ name : "run_code"
204+ } ,
205+ {
206+ label : "Open to the Side" ,
207+ name : "open_to_the_side"
208+ } ,
209+ {
210+ label : "Open With..." ,
211+ name : "open_with"
212+ } ,
213+ {
214+ label : "Reveal in File Explorer" ,
215+ name : "reveal_in_file_explorer"
216+ } ,
217+ {
218+ label : "Open in Integrated Terminal" ,
219+ name : "open_in_integrated_terminal"
220+ } ,
221+ {
222+ separator : true
223+ } ,
224+ {
225+ label : "Select for Compare" ,
226+ name : "select_for_compare"
227+ } ,
228+ {
229+ label : "Find File References" ,
230+ name : "find_file_references"
231+ } ,
232+ {
233+ label : "Open Timeline" ,
234+ name : "open_timeline"
235+ } ,
236+ {
237+ separator : true
238+ } ,
239+ {
240+ label : "Cut" ,
241+ name : "cut"
242+ } ,
243+ {
244+ label : "Copy" ,
245+ name : "copy"
246+ } ,
247+ {
248+ separator : true
249+ } ,
250+ {
251+ label : "Copy Path" ,
252+ name : "copy_path" ,
253+ click : ( ) => {
254+ fsUtils . copyToClipboard ( full_path ) ;
255+ }
256+ } ,
257+ {
258+ label : "Copy Relative Path" ,
259+ name : "copy_relative_path" ,
260+ click : ( ) => {
261+ fsUtils . copyToClipboard ( path . relative ( launchArguments , full_path ) ) ;
262+ }
263+ } ,
264+ {
265+ separator : true
266+ } ,
267+ {
268+ label : "Rename..." ,
269+ name : "rename" ,
270+ click : ( ) => {
271+ isStaging = ! isStaging ;
272+ }
273+ } ,
274+ {
275+ label : "Delete" ,
276+ name : "delete" , //
277+ click : ( ) => {
278+ console . log ( 'Deleting' ) ;
279+
280+ if ( isFolder ) {
281+ fs . rmdirSync ( full_path ) ;
282+ } else {
283+ fs . unlinkSync ( full_path ) ;
284+ }
285+
286+ // file_explorer.rescan();
287+ }
288+ }
289+ ]
186290 } ;
187291
188- const watcher = chokidar . watch ( launchArguments , {
189- ignored : / ( ^ | [ \/ \\ ] ) \. ./ , // ignore dotfiles
190- persistent : true
191- } ) ;
292+ // const watcher = chokidar.watch(launchArguments, {
293+ // ignored: /(^|[\/\\])\../, // ignore dotfiles
294+ // persistent: true
295+ // });
296+
192297
193- watcher . on ( 'addDir' , path => file_explorer . chokidarUpdate ( path , true , true ) ) ;
194- watcher . on ( 'unlinkDir' , path => file_explorer . chokidarUpdate ( path , true , false ) ) ;
298+ xp_chokidar . on ( 'Directory created' , path => file_explorer . chokidarUpdate ( path , true , true ) )
299+ xp_chokidar . on ( 'Directory deleted' , path => file_explorer . chokidarUpdate ( path , true , false ) ) ;
300+ // watcher.on('addDir', path => file_explorer.chokidarUpdate(path, true, true));
301+ // watcher.on('unlinkDir', path => file_explorer.chokidarUpdate(path, true, false));
195302
196- watcher . on ( 'add' , path => file_explorer . chokidarUpdate ( path , false , true ) ) ;
197- watcher . on ( 'unlink' , path => file_explorer . chokidarUpdate ( path , false , false ) ) ;
303+ xp_chokidar . on ( 'File created' , path => file_explorer . chokidarUpdate ( path , false , true ) ) ;
304+ xp_chokidar . on ( 'File deleted' , path => file_explorer . chokidarUpdate ( path , false , false ) ) ;
305+ // watcher.on('add', path => file_explorer.chokidarUpdate(path, false, true));
306+ // watcher.on('unlink', path => file_explorer.chokidarUpdate(path, false, false));
198307
199- watcher . on ( 'change' , path => console . log ( `File ${ path } has been changed` ) ) ;
308+ xp_chokidar . on ( 'File modified' , path => console . log ( `File ${ path } has been changed` ) ) ;
309+ xp_chokidar . watch ( launchArguments )
310+ // watcher.on('change', path => console.log(`File ${path} has been changed`));
0 commit comments