MCPcopy Index your code
hub / github.com/reactide/reactide / setFileTree

Method setFileTree

renderer/components/App.jsx:289–385  ·  view source on GitHub ↗

* calls file-tree module and sets state with file tree object representation in callback

(dirPath)

Source from the content-addressed store, hash-verified

287 * calls file-tree module and sets state with file tree object representation in callback
288 */
289 setFileTree(dirPath) {
290 if (!fs.existsSync(path.join(dirPath, '/reactide.js'))) {
291 exec(`npm i -S reactide-config && echo 'const yes = require("'reactide-config'") \n yes.config()' >> reactide.js && node reactide.js `,{
292 cwd: dirPath
293 });
294 }
295 getTree(dirPath, fileTree => {
296 //if watcher instance already exists close it as it's for the previously opened project
297 if (this.state.watch) {
298 this.state.watch.close();
299 }
300 //Setting up fs.watch to watch for changes that occur anywhere in the filesystem
301 let watch = fs.watch(dirPath, { recursive: true, persistent: true }, (eventType, fileName) => {
302 if (eventType === 'rename') {
303 const fileTree = this.state.fileTree;
304
305 const absPath = path.join(this.state.rootDirPath, fileName);
306 const parentDir = this.findParentDir(path.dirname(absPath), fileTree);
307 const name = path.basename(absPath);
308 const openTabs = this.state.openTabs;
309 //Delete handler
310 if (this.state.fileChangeType === 'delete') {
311 let index;
312 if (this.state.selectedItem.type === 'directory') {
313 index = this.findItemIndex(parentDir.subdirectories, name);
314 parentDir.subdirectories.splice(index, 1);
315 } else {
316 index = this.findItemIndex(parentDir.files, name);
317 parentDir.files.splice(index, 1);
318 }
319 for (var i = 0; i < this.state.openTabs.length; i++) {
320 if (openTabs[i].name === name) {
321 openTabs.splice(i, 1);
322 break;
323 }
324 }
325 } else if (this.state.fileChangeType === 'new') {
326 //new handler
327 if (this.state.createMenuInfo.type === 'directory') {
328 parentDir.subdirectories.push(new Directory(absPath, name));
329 } else {
330 parentDir.files.push(new File(absPath, name, getFileExt));
331 console.log(parentDir.files);
332 }
333 } else if (this.state.fileChangeType === 'rename' && this.state.newName) {
334 //rename handler
335 //fileName has new name, selectedItem has old name and path
336 let index;
337 if (this.state.selectedItem.type === 'directory') {
338 index = this.findItemIndex(parentDir.subdirectories, name);
339 parentDir.subdirectories[index].name = this.state.newName;
340 parentDir.subdirectories[index].path = path.join(path.dirname(absPath), this.state.newName);
341 } else {
342 index = this.findItemIndex(parentDir.files, name);
343 parentDir.files[index].name = this.state.newName;
344 parentDir.files[index].path = path.join(path.dirname(absPath), this.state.newName);
345 }
346 //renames path of selected renamed file so it has the right info

Callers 2

fileTreeInitMethod · 0.95
updateFileDirectoryMethod · 0.95

Calls 5

findParentDirMethod · 0.95
findItemIndexMethod · 0.95
closeMethod · 0.80
getTreeFunction · 0.50

Tested by

no test coverage detected