diff --git a/CHANGELOG.md b/CHANGELOG.md index b9aef50..37ae2bd 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ # Change Log +## 0.3.0 + +* Automatically hide files/directories that are named with relative paths in .hideInTxtEd + + ## 0.2.0 * fixed files/directories not rehiding after their parent directory is closed and expended diff --git a/README.md b/README.md index 960316f..bd0958d 100644 --- a/README.md +++ b/README.md @@ -19,5 +19,17 @@ Easily focus on the task at hand by hiding irrelevantly files and directories. * Unhide children of a directory * unhide by right clicking a directory and selecting "Unhide Children" -## Todos -* add ability to save state of hidden files/folders and rehide files/folders when the project is reopened. +* Hide files specified in .hideInTxtEd + ``` + #this is an example .hideInTxtEd file + #empty lines are ignored + + #any matching file/dir path (relative to the current dir) will be hidden: + somedir + foo.txt + bar.txt + otherdir/baz.txt + otherdir/yetanotherdir + #hide this file also + .hideInTxtEd + ``` diff --git a/index.coffee b/index.coffee index 9c18d08..b36dd44 100644 --- a/index.coffee +++ b/index.coffee @@ -1,4 +1,5 @@ HideItems = require "./lib/hide_items.coffee" +require "./lib/hideFilesNamedInTxtFiles.js" module.exports = activate: (state) -> diff --git a/lib/hideFilesNamedInTxtFiles.js b/lib/hideFilesNamedInTxtFiles.js new file mode 100644 index 0000000..c00fd8f --- /dev/null +++ b/lib/hideFilesNamedInTxtFiles.js @@ -0,0 +1,68 @@ +const hidingFileName = '.hideInTxtEd'; + +const fs = require('fs'); +const path = require('path') +const getDirectories = rootDir => fs.readdirSync(rootDir).map(file => path.join(rootDir,file)).filter(filePath => fs.lstatSync(filePath).isDirectory()); +const fileExists = path => fs.existsSync(path) && fs.lstatSync(path).isFile(); +const dirExists = path => fs.existsSync(path) && fs.lstatSync(path).isDirectory(); + +let pathsToHide=[], addedListenerOnPath=[], allProjPaths=[]; + +function lookForStuffToHide(curPath) { + getDirectories(curPath).forEach(lookForStuffToHide); + const hideListFilePath = path.join(curPath, hidingFileName); + if (fileExists(hideListFilePath)) { + const subFilesToHide = fs.readFileSync(hideListFilePath).toString().split('\n').filter(s => s.length && s[0]!=='#'); + subFilesToHide.forEach(file => { + const fullPath = path.join(curPath, file); + pathsToHide.push(fullPath); + }); + } +} + +function addClasses(treeView) { + const spanA = treeView.element.querySelectorAll('span.icon-file-directory, span.icon-file-text'); + for (let i=0;i-1); + } +} + +function addListenerToDirEntry(treeView, entryDir) { + if (entryDir.entries!==undefined) Object.keys(entryDir.entries).forEach(subEntry => { + addListenerToDirEntry(treeView, entryDir.entries[subEntry]) + }); + if (addedListenerOnPath.indexOf(entryDir.path)===-1 && entryDir.onDidExpand!==undefined) { + addedListenerOnPath.push(entryDir.path); + entryDir.onDidExpand(()=>{ + addClasses(treeView); + addListenerToDirEntry(treeView, entryDir); + }); + } +} + +function scanPaths(paths) { + pathsToHide=[]; + addedListenerOnPath=[]; + paths.forEach(lookForStuffToHide); + pathsToHide = pathsToHide.filter(itemPath => fs.existsSync(itemPath)); + let expandableDirs = pathsToHide.map(curPath => fs.lstatSync(curPath).isFile() ? path.dirname(curPath) : curPath); + expandableDirs = expandableDirs.filter((dir,pos) => expandableDirs.indexOf(dir)===pos); + atom.packages.activatePackage('tree-view').then(result => { + treeView = result.mainModule.treeView + expandableDirs.forEach(dir => addListenerToDirEntry(treeView, treeView.entryForPath(dir).directory)); + addClasses(treeView); + }); +} + +atom.project.onDidChangePaths(newPaths => { + allProjPaths = newPaths; + scanPaths(allProjPaths); +}); + +atom.project.onDidAddBuffer(buf => { + if (typeof buf.file==='object' && buf.file!==null && typeof buf.file.path==='string' && path.basename(buf.file.path)===hidingFileName && typeof buf.onDidSave==='function') { + buf.onDidSave(() => treeView!==null && scanPaths(allProjPaths)); + } +}); diff --git a/package.json b/package.json index c1ac7ad..3c130f4 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "hide-files", "main": "index.coffee", - "version": "0.2.0", + "version": "0.3.0", "description": "Hide files and folders in the file tree", "repository": "https://github.com/imamathwiz/atom-hide-files", "license": "MIT", @@ -9,6 +9,10 @@ "name": "Brian Weiser", "url": "https://github.com/imamathwiz" }, + "contributors": { + "name": "ESC", + "url": "https://github.com/softwarecreations" + }, "bugs": { "url": "https://github.com/imamathwiz/atom-hide-files/issues" }