From f6baeffcb2b04cf6ee3077115e56fb0c5fc36f31 Mon Sep 17 00:00:00 2001 From: Adam Buczynski Date: Thu, 14 Jan 2016 11:12:02 +1300 Subject: [PATCH 1/5] Add package level ignoredNames --- README.md | 5 +++++ lib/main.coffee | 4 ++++ lib/tree-view.coffee | 7 +++++-- spec/tree-view-spec.coffee | 5 +++++ 4 files changed, 19 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 1a9b156a..e334b6a4 100644 --- a/README.md +++ b/README.md @@ -9,6 +9,11 @@ or delete files and folders. ![](https://f.cloud.github.com/assets/671378/2241932/6d9cface-9ceb-11e3-9026-31d5011d889d.png) +This package uses both the `core.ignoredNames` and `tree-view.ignoredNames` +config settings to filter out files and folders that will not be shown. +Both of those config settings are interpreted as arrays of +[minimatch](https://github.com/isaacs/minimatch) glob patterns. + ## API The Tree View displays icons next to files. These icons are customizable by installing a package that provides an `atom.file-icons` service. diff --git a/lib/main.coffee b/lib/main.coffee index aca11519..9fed7267 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -19,6 +19,10 @@ module.exports = type: 'boolean' default: false description: 'Don\'t show items matched by the `Ignored Names` core config setting.' + ignoredNames: + type: 'array' + default: [] + description: 'List of string glob patterns. Files and directories matching these patterns will be ignored. This list is merged with the list defined by the core `Ignored Names` config setting, if the `Hide Ignored Names` setting is on. Example: `.git, ._*, Thumbs.db`.' showOnRightSide: type: 'boolean' default: false diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index e18e14ad..3203de0f 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -143,6 +143,8 @@ class TreeView extends View @updateRoots() @disposables.add atom.config.onDidChange 'tree-view.hideIgnoredNames', => @updateRoots() + @disposables.add atom.config.onDidChange 'tree-view.ignoredNames', => + @updateRoots() if atom.config.get('tree-view.hideIgnoredNames') @disposables.add atom.config.onDidChange 'core.ignoredNames', => @updateRoots() if atom.config.get('tree-view.hideIgnoredNames') @disposables.add atom.config.onDidChange 'tree-view.showOnRightSide', ({newValue}) => @@ -241,8 +243,9 @@ class TreeView extends View Minimatch ?= require('minimatch').Minimatch - ignoredNames = atom.config.get('core.ignoredNames') ? [] - ignoredNames = [ignoredNames] if typeof ignoredNames is 'string' + ignoredNames = atom.config.get('tree-view.ignoredNames') ? [] + ignoredNames = ignoredNames.concat(atom.config.get('core.ignoredNames') ? []) + for ignoredName in ignoredNames when ignoredName try @ignoredPatterns.push(new Minimatch(ignoredName, matchBase: true, dot: true)) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 5051a90a..e0a62c7f 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -2124,6 +2124,11 @@ describe "TreeView", -> expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 1 + it "ignores paths that match entries in config.tree-view.ignoredNames" + atom.config.set("tree-view.ignoredNames", ["sample.js", "*.txt"]) + expect(treeView.find('.directory .name:contains(sample.js)').length).toBe 0 + expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 + describe "the squashedDirectoryName config option", -> beforeEach -> rootDirPath = fs.absolute(temp.mkdirSync('tree-view')) From ed401b764f70c573f2d06337467230286536a944 Mon Sep 17 00:00:00 2001 From: Adam Buczynski Date: Thu, 14 Jan 2016 11:38:44 +1300 Subject: [PATCH 2/5] Add toggle for merge behaviour --- lib/main.coffee | 8 ++++++-- lib/tree-view.coffee | 5 ++++- spec/tree-view-spec.coffee | 16 ++++++++++++++-- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lib/main.coffee b/lib/main.coffee index 9fed7267..7d15d9c3 100644 --- a/lib/main.coffee +++ b/lib/main.coffee @@ -18,11 +18,15 @@ module.exports = hideIgnoredNames: type: 'boolean' default: false - description: 'Don\'t show items matched by the `Ignored Names` core config setting.' + description: 'Don\'t show items matched by the `Ignored Names` config setting.' + mergeIgnoredNames: + type: 'boolean' + default: true + description: 'Merge the `Ignored Names` of this package with the `Ignored Names` from the core configuration setting.' ignoredNames: type: 'array' default: [] - description: 'List of string glob patterns. Files and directories matching these patterns will be ignored. This list is merged with the list defined by the core `Ignored Names` config setting, if the `Hide Ignored Names` setting is on. Example: `.git, ._*, Thumbs.db`.' + description: 'List of string glob patterns. Files and directories matching these patterns will be ignored. This list is merged with the list defined by the core `Ignored Names` config setting, if the `Merge Ignored Names` setting is on. Example: `.git, ._*, Thumbs.db`.' showOnRightSide: type: 'boolean' default: false diff --git a/lib/tree-view.coffee b/lib/tree-view.coffee index 3203de0f..63745a23 100644 --- a/lib/tree-view.coffee +++ b/lib/tree-view.coffee @@ -143,6 +143,8 @@ class TreeView extends View @updateRoots() @disposables.add atom.config.onDidChange 'tree-view.hideIgnoredNames', => @updateRoots() + @disposables.add atom.config.onDidChange 'tree-view.mergeIgnoredNames', => + @updateRoots() if atom.config.get('tree-view.hideIgnoredNames') @disposables.add atom.config.onDidChange 'tree-view.ignoredNames', => @updateRoots() if atom.config.get('tree-view.hideIgnoredNames') @disposables.add atom.config.onDidChange 'core.ignoredNames', => @@ -244,7 +246,8 @@ class TreeView extends View Minimatch ?= require('minimatch').Minimatch ignoredNames = atom.config.get('tree-view.ignoredNames') ? [] - ignoredNames = ignoredNames.concat(atom.config.get('core.ignoredNames') ? []) + if atom.config.get('tree-view.mergeIgnoredNames') + ignoredNames = ignoredNames.concat(atom.config.get('core.ignoredNames') ? []) for ignoredName in ignoredNames when ignoredName try diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index e0a62c7f..03700e95 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -2110,6 +2110,7 @@ describe "TreeView", -> atom.config.set "tree-view.hideIgnoredNames", false it "hides ignored files if the option is set, but otherwise shows them", -> + atom.config.set("tree-view.mergeIgnoredNames", true) expect(treeView.find('.directory .name:contains(.git)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 1 @@ -2125,8 +2126,19 @@ describe "TreeView", -> expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 1 it "ignores paths that match entries in config.tree-view.ignoredNames" - atom.config.set("tree-view.ignoredNames", ["sample.js", "*.txt"]) - expect(treeView.find('.directory .name:contains(sample.js)').length).toBe 0 + atom.config.set("tree-view.ignoredNames", ["*.txt"]) + expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 + expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 + + it "does not ignore paths that match entries from config.core.ignoredNames if the setting to merge them is off, otherwise it does ignore them" + atom.config.set("tree-view.hideIgnoredNames", true) + atom.config.set("tree-view.ignoredNames", ["*.txt"]) + atom.config.set("tree-view.mergeIgnoredNames", true) + expect(treeView.find('.directory .name:contains(test.js)').length).toBe 0 + expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 + + atom.config.set("tree-view.mergeIgnoredNames", false) + expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 describe "the squashedDirectoryName config option", -> From 453319454c45e439b179c396d8743850e1f6e7f3 Mon Sep 17 00:00:00 2001 From: Adam Buczynski Date: Thu, 14 Jan 2016 11:47:03 +1300 Subject: [PATCH 3/5] Fix spec file --- spec/tree-view-spec.coffee | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 03700e95..ceb3f2e3 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -2125,12 +2125,12 @@ describe "TreeView", -> expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 1 - it "ignores paths that match entries in config.tree-view.ignoredNames" + it "ignores paths that match entries in config.tree-view.ignoredNames", -> atom.config.set("tree-view.ignoredNames", ["*.txt"]) expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 - it "does not ignore paths that match entries from config.core.ignoredNames if the setting to merge them is off, otherwise it does ignore them" + it "does not ignore paths that match entries from config.core.ignoredNames if the setting to merge them is off, otherwise it does ignore them", -> atom.config.set("tree-view.hideIgnoredNames", true) atom.config.set("tree-view.ignoredNames", ["*.txt"]) atom.config.set("tree-view.mergeIgnoredNames", true) From d67a849683fb2e46374fd292b5a318d4b1f36659 Mon Sep 17 00:00:00 2001 From: Adam Buczynski Date: Thu, 14 Jan 2016 11:52:49 +1300 Subject: [PATCH 4/5] Update spec to reset core.ignoredNames before test --- spec/tree-view-spec.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index ceb3f2e3..3d50287e 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -2126,12 +2126,14 @@ describe "TreeView", -> expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 1 it "ignores paths that match entries in config.tree-view.ignoredNames", -> + atom.config.set("core.ignoredNames", []) atom.config.set("tree-view.ignoredNames", ["*.txt"]) expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 it "does not ignore paths that match entries from config.core.ignoredNames if the setting to merge them is off, otherwise it does ignore them", -> atom.config.set("tree-view.hideIgnoredNames", true) + atom.config.set("core.ignoredNames", ["*.js"]) atom.config.set("tree-view.ignoredNames", ["*.txt"]) atom.config.set("tree-view.mergeIgnoredNames", true) expect(treeView.find('.directory .name:contains(test.js)').length).toBe 0 From fb68b3de5103b686f259fd23dc3bf1201e8629c7 Mon Sep 17 00:00:00 2001 From: Adam Buczynski Date: Thu, 14 Jan 2016 11:58:12 +1300 Subject: [PATCH 5/5] Toggle hideIgnoredNames to true before test --- spec/tree-view-spec.coffee | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/spec/tree-view-spec.coffee b/spec/tree-view-spec.coffee index 3d50287e..17e41250 100644 --- a/spec/tree-view-spec.coffee +++ b/spec/tree-view-spec.coffee @@ -2127,15 +2127,16 @@ describe "TreeView", -> it "ignores paths that match entries in config.tree-view.ignoredNames", -> atom.config.set("core.ignoredNames", []) + atom.config.set("tree-view.hideIgnoredNames", true) atom.config.set("tree-view.ignoredNames", ["*.txt"]) expect(treeView.find('.directory .name:contains(test.js)').length).toBe 1 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0 it "does not ignore paths that match entries from config.core.ignoredNames if the setting to merge them is off, otherwise it does ignore them", -> - atom.config.set("tree-view.hideIgnoredNames", true) atom.config.set("core.ignoredNames", ["*.js"]) - atom.config.set("tree-view.ignoredNames", ["*.txt"]) + atom.config.set("tree-view.hideIgnoredNames", true) atom.config.set("tree-view.mergeIgnoredNames", true) + atom.config.set("tree-view.ignoredNames", ["*.txt"]) expect(treeView.find('.directory .name:contains(test.js)').length).toBe 0 expect(treeView.find('.directory .name:contains(test.txt)').length).toBe 0