42IN13SAh/Ivy — pull request #71 by slemmen (2014-12-18 22:27:07+00:00)
Title: Added smart open file & new file support, minor changes to save file

De story is " Als gebruiker wil ik op een knop (en eventueel een hotkey) kunnen drukken zodat ik een bestaand bestand met broncode kan openen.". De taak was alleen om de hotkey voor openen te doen, maar ik heb alle gerelateerde code even ge-refactored zodat ze nu allemaal hetzelfde gedrag hebben (zelfde checks).

Let bij reviewen vooral aub. op code helderheid (zijn comments nodig?) en op structuur (hoort code die nu bijv. in een view staan niet in een controller?).

Review voor @stijn22 & @rbsloot

txt file van testcases is [hier](https://dl.dropboxusercontent.com/u/39722120/ivy%20open%20%26%20new%20testcases.txt) te downloaden. Ik stel voor dat jullie die plakken in je comment zodra je gaat testen en dan kun je daarna aanvinken welke slagen (of je kunt in de txt zelf de - [ ] vervangen voor - [X]).

Hieronder zie je hoe dit er dan uitziet (plus je krijgt idee van waar ik aan gedacht heb + getest heb):

# What to do when?
| | No existing file | Existing file |
|---------|------------------|------------------------|
| New | Show open file dialog | Prompt to save, save if desired, show open file dialog |
| Open | Show open file dialog | Prompt to save, save if desired, show open file dialog |

# Where to start with dialog?
| | No existing file | Existing file |
|---------|-----------------------|---------------------------|
| Open | Ivy default directory | Existing file's directory |

# TestCases:
## 1. Open file dialog location
### Steps:
- Don't type anything in the editor
- Press ctrl + o

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] I do _NOT_ get prompted for a save file location
- [ ] The starting dir of the dialog is the Ivy folder that always get's created in the user's documents dir (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)

### Actions to do after test:
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 2. Open file dialog behavior with unsaved changes
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + o

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] After pressing ctrl + o, you get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 3. Open file dialog behavior with saved changes
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + s or use the menu to save the file, doesn't matter where to
- Press ctrl + o

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] After pressing ctrl + o, you do _NOT_ get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 4. Open file dialog behavior after changing a saved file
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + s or use the menu to save the file, doesn't matter where to
- Change the code, doesn't matter what
- Press ctrl + o

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] After pressing ctrl + o, you do get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 5. Open file dialog behavior after changing and unchanging a saved file
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + s or use the menu to save the file, doesn't matter where to
- Change the code, I'd suggest to:
```javascript
var y = 1;
```
- Press ctrl + o (first time)
- Press cancel in the dialog that should appear (if it doesn't, the test failed so skip the rest and leave the the second and third expected output boxes blank)
- Now undo the changes so that the code is now ```javascript var x = 1;``` again.
- Press ctrl + o (second time)

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] After pressing ctrl + o (first time), you do get prompted to save your current file.
- [ ] After pressing ctrl + o (second time), you do _NOT_ get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 6. Opening file
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + s or use the menu to save the file, doesn't matter where to
- Change the code, I'd suggest to (so you can see the change):
```javascript
var y = 1;
```
- Press ctrl + o (don't save changes) and open the saved file from before

### Expected output:
- [ ] If this was the first open file operation I have ever ran, I should now have an Ivy directory in (windows: C:/Users/< username >/My Documents/Ivy, Linux: usr/home/Ivy, OSX: ??)
- [ ] After opening the file, the editor now has ```javascript var x = 1;``` again, and not ```javascript var y = 1;```

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the open file function in menu > file instead of ctrl + o

## 7. New file
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Press ctrl + n

### Expected output:
- [ ] The editor is clear after ctrl + n (if you did not press cancel)
- [ ] After pressing ctrl + n, you do get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the new file function in menu > file instead of ctrl + n

## 8. New file after saving
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Save the file via ctrl + s or the menu option, doesn't matter where to
- Press ctrl + n

### Expected output:
- [ ] The editor is clear after ctrl + n
- [ ] After pressing ctrl + n, you do _NOT_ get prompted to save your current file

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the new file function in menu > file instead of ctrl + n

## 9. New file after opening a saved file and changing it
### Steps:
- Type the following code in the editor:
```javascript
var x = 1;
```
- Save the file via ctrl + s or the menu option, doesn't matter where to
- Create a new file (to reset)
- Open the saved file from before
- Change the code, doesn't matter to what
- Press ctrl + n

### Expected output:
- [ ] After pressing ctrl + n, you do get prompted to save your current file
- [ ] The editor is clear after ctrl + n (if you did not press cancel)

### Actions to do after test:
- Create new file in the IDE
- Repeat the test, but now use the new file function in menu > file instead of ctrl + n