From 4c64da1d9f3d208372c2e3a0217289f978771d59 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Sat, 24 Jun 2017 16:39:23 +0200 Subject: [PATCH 1/9] Update README.md --- README.md | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) 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 + ``` From 6a896a66253a76375a75a03f90faeabf7e0f86a8 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Sat, 24 Jun 2017 16:40:00 +0200 Subject: [PATCH 2/9] Update index.coffee --- index.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/index.coffee b/index.coffee index 9c18d08..5f5319e 100644 --- a/index.coffee +++ b/index.coffee @@ -1,4 +1,5 @@ HideItems = require "./lib/hide_items.coffee" +require "./lib/hideFilesNamedInTxtFile.js" module.exports = activate: (state) -> From 1754878dc436d5915d8e74d5f06e35fdf545b069 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Sat, 24 Jun 2017 16:40:44 +0200 Subject: [PATCH 3/9] Create hideFilesNamedInTxtFile.js --- lib/hideFilesNamedInTxtFile.js | 67 ++++++++++++++++++++++++++++++++++ 1 file changed, 67 insertions(+) create mode 100644 lib/hideFilesNamedInTxtFile.js diff --git a/lib/hideFilesNamedInTxtFile.js b/lib/hideFilesNamedInTxtFile.js new file mode 100644 index 0000000..f27f9bd --- /dev/null +++ b/lib/hideFilesNamedInTxtFile.js @@ -0,0 +1,67 @@ +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 $spans = treeView.find('span.icon-file-directory, span.icon-file-text'); + for (let i=0;i<$spans.length;++i) { + let $span = $spans.eq(i); + $span.parents('li').eq(0).toggleClass('hide-files-hide', pathsToHide.indexOf($span.data('path'))>-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 (buf.file!==undefined && buf.file.path!==undefined && path.basename(buf.file.path)===hidingFileName && buf.onDidSave!==undefined) { + buf.onDidSave(() => treeView!==null && scanPaths(allProjPaths)); + } +}); From 350002921c1839f106f2465c4eca53fcd4cfeace Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Sat, 24 Jun 2017 16:41:28 +0200 Subject: [PATCH 4/9] Update index.coffee --- index.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/index.coffee b/index.coffee index 5f5319e..b36dd44 100644 --- a/index.coffee +++ b/index.coffee @@ -1,5 +1,5 @@ HideItems = require "./lib/hide_items.coffee" -require "./lib/hideFilesNamedInTxtFile.js" +require "./lib/hideFilesNamedInTxtFiles.js" module.exports = activate: (state) -> From 9203d6a179fdb95f8d59a1235f85267dc287f215 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Sat, 24 Jun 2017 16:41:51 +0200 Subject: [PATCH 5/9] Rename hideFilesNamedInTxtFile.js to hideFilesNamedInTxtFiles.js --- lib/{hideFilesNamedInTxtFile.js => hideFilesNamedInTxtFiles.js} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename lib/{hideFilesNamedInTxtFile.js => hideFilesNamedInTxtFiles.js} (100%) diff --git a/lib/hideFilesNamedInTxtFile.js b/lib/hideFilesNamedInTxtFiles.js similarity index 100% rename from lib/hideFilesNamedInTxtFile.js rename to lib/hideFilesNamedInTxtFiles.js From d8c3d6d3186cf773df4dd2b15deb36b47f0a10f6 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Mon, 26 Jun 2017 06:39:28 +0200 Subject: [PATCH 6/9] Update hideFilesNamedInTxtFiles.js fixed error --- lib/hideFilesNamedInTxtFiles.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/hideFilesNamedInTxtFiles.js b/lib/hideFilesNamedInTxtFiles.js index f27f9bd..8d32a13 100644 --- a/lib/hideFilesNamedInTxtFiles.js +++ b/lib/hideFilesNamedInTxtFiles.js @@ -61,7 +61,7 @@ atom.project.onDidChangePaths(newPaths => { }); atom.project.onDidAddBuffer(buf => { - if (buf.file!==undefined && buf.file.path!==undefined && path.basename(buf.file.path)===hidingFileName && buf.onDidSave!==undefined) { + 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)); } }); From 190008522c6fb45868e33d58c74491ae57fd347d Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Tue, 27 Jun 2017 02:47:12 +0200 Subject: [PATCH 7/9] Update hideFilesNamedInTxtFiles.js --- lib/hideFilesNamedInTxtFiles.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/hideFilesNamedInTxtFiles.js b/lib/hideFilesNamedInTxtFiles.js index 8d32a13..c00fd8f 100644 --- a/lib/hideFilesNamedInTxtFiles.js +++ b/lib/hideFilesNamedInTxtFiles.js @@ -21,10 +21,11 @@ function lookForStuffToHide(curPath) { } function addClasses(treeView) { - const $spans = treeView.find('span.icon-file-directory, span.icon-file-text'); - for (let i=0;i<$spans.length;++i) { - let $span = $spans.eq(i); - $span.parents('li').eq(0).toggleClass('hide-files-hide', pathsToHide.indexOf($span.data('path'))>-1); + const spanA = treeView.element.querySelectorAll('span.icon-file-directory, span.icon-file-text'); + for (let i=0;i-1); } } From d1315a8627a19d413318f85eb84bffc9f291d905 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Tue, 27 Jun 2017 02:51:39 +0200 Subject: [PATCH 8/9] Update CHANGELOG.md --- CHANGELOG.md | 5 +++++ 1 file changed, 5 insertions(+) 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 From ad66db8b825fac2820af1375ebd0ce08e3bd7651 Mon Sep 17 00:00:00 2001 From: softwarecreations Date: Tue, 27 Jun 2017 02:55:37 +0200 Subject: [PATCH 9/9] Update package.json --- package.json | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) 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" }