Skip to content
This repository has been archived by the owner on Dec 15, 2022. It is now read-only.

Add package level ignoredNames #698

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
10 changes: 8 additions & 2 deletions lib/tree-view.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,10 @@ 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', =>
@updateRoots() if atom.config.get('tree-view.hideIgnoredNames')
@disposables.add atom.config.onDidChange 'tree-view.showOnRightSide', ({newValue}) =>
Expand Down Expand Up @@ -248,8 +252,10 @@ 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') ? []
if atom.config.get('tree-view.mergeIgnoredNames')
ignoredNames = ignoredNames.concat(atom.config.get('core.ignoredNames') ? [])

for ignoredName in ignoredNames when ignoredName
try
@ignoredPatterns.push(new Minimatch(ignoredName, matchBase: true, dot: true))
Expand Down
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,17 @@
"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 `Merge Ignored Names` setting is on. Example: `.git, ._*, Thumbs.db`."
},
"showOnRightSide": {
"type": "boolean",
Expand Down
20 changes: 20 additions & 0 deletions spec/tree-view-spec.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -2212,6 +2212,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
Expand All @@ -2226,6 +2227,25 @@ 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("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("core.ignoredNames", ["*.js"])
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

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", ->
beforeEach ->
rootDirPath = fs.absolute(temp.mkdirSync('tree-view'))
Expand Down