atom/tree-view — pull request #82 by izuzak (2014-03-11 16:59:21+00:00)
Title: Separate adding files from adding folders

Fixes https://github.com/atom/tree-view/issues/54

Currently, the "Add File" and "Add Folder" menu options bring up the same dialog. Whether a file or folder is crated depends on whether the entered name ends with a "/" character. While the dialog is explicit on this behavior, this is still confusing for a number of users.

This pull request separates these two options so that "Add File" always creates a file, and "Add Folder" always creates a folder.

Summary of changes:
* `tree-view:add` command is [separated into `tree-view:add-file` and `tree-view:add-folder`](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-f049b863c82da90d4121eb1493c2855fL45).
* `tree-view:add-file` is still bound to the `a` keystroke, while [`tree-view:add-folder` is bound to `shift-a`](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-e3341fae8a6fb67a89cdae6f990cc2fcL21).

![screen shot 2014-03-11 at 5 16 51 pm](https://f.cloud.github.com/assets/38924/2387934/9f380616-a93c-11e3-8d5a-a5b8a64b14d7.png)

* the AddDialog class is extended to receive [information about whether a file or a folder should be created](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-209b990806d69cc7e0d87b6f4e18ecb1L7).

![screen shot 2014-03-11 at 5 36 49 pm](https://f.cloud.github.com/assets/38924/2387939/a8c1c30c-a93c-11e3-94b3-d7563e0c79a6.png)
![screen shot 2014-03-11 at 5 36 38 pm](https://f.cloud.github.com/assets/38924/2387940/a8c1eca6-a93c-11e3-8267-edb91c16f681.png)

* the AddDialog additionally checks for the situation when a file is being created that ends in "/", and [shows a user-friendly error message](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-209b990806d69cc7e0d87b6f4e18ecb1R31). Without this check, creating a file fails with a ENOENT error being shown, which is not really helpful.

![screen shot 2014-03-11 at 5 37 00 pm](https://f.cloud.github.com/assets/38924/2387946/b6886d4c-a93c-11e3-9789-c9149a18b9f0.png)

* tests are refactored to match the new commands and creation flow. The old `tree-view:add` tests are split into [`tree-view:add-file` tests](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-ddd2fe70381e781d323bc21251794b7aL840) and [`tree-view:add-folder` tests](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-ddd2fe70381e781d323bc21251794b7aR960). Most of the tests have not been touched, and I think I added just two new ones: [testing for the situation when a file name ends with "/"](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-ddd2fe70381e781d323bc21251794b7aR904), and testing that [creating a folder works when the name doesn't end with "/"](https://github.com/atom/tree-view/commit/6a459856ef907ba6776ac01e47facd783e9725d5#diff-ddd2fe70381e781d323bc21251794b7aR982) (creating a folder named `foo` is the same as creating `foo/`). I did my best to keep test duplication to a minimum, since both add-file and add-folder use the same AddDialog dialog.