Repository: spyder-ide/spyder

Issue:
File save as: file is unavailable
## Description of your problem

**What steps will reproduce the problem?**
1. Open file in Editor
2. File Menu -> Save as 
3. The dialogue betlow appears. 
4. If I click on Yes, the file is never saved
5. If click on NO, the file is kept in Editor

![spyder_file_unavailable](https://cloud.githubusercontent.com/assets/8660305/13496443/80ae9bda-e150-11e5-9190-e6b277589d18.png)

Why does this come up?

**What is the expected output? What do you see instead?**

Expected / desired:
- The file with the new name ("save as") shall be kept in editor.
- A dialogue may ask if the old file can be closed. The file must not be deleted from the disk.

**Please provide any additional information below**
## Versions and main components
- Spyder Version: 3.0.0
- Python Version: 3.5
- Operating system: Windows 7
## Dependencies

Please go to the menu entry `Help > Optional Dependencies` (or
`Help > Dependencies`), press the button `Copy to clipboard`
and paste the contents below:

```
IPython >=3.0      :  4.0.1 (OK)
jedi >=0.8.1;<0.9.0:  0.8.1 (OK)
matplotlib >=1.0   :  1.5.0 (OK)
numpy >=1.7        :  1.9.3 (OK)
pandas >=0.13.1    :  0.17.1 (OK)
pep8 >=0.6         :  1.6.2 (OK)
pyflakes >=0.6.0   :  0.9.2 (OK)
pygments >=1.6     :  2.0.2 (OK)
pylint >=0.25      :  1.5.1 (OK)
qtconsole >=4.0    :  4.1.1 (OK)
rope >=0.9.4       :  0.9.4-1 (OK)
sphinx >=0.6.6     :  1.3.3 (OK)
sympy >=0.7.3      :  0.7.6.1 (OK)
zmq >=13.0.0       :  15.1.0 (OK)
```



Discussion:
@stonebig, can you reproduce this problem?

curious, I would imagine the file is open on internet, on a zip directory or in a read-only directory ?

on the local drive.

Is it a file in a normal directory or in a zipped directory ? which exact version of Spyder 3.0.0 ?

> Is it a file in a normal directory or in a zipped directory ? 

normal, nothing compressed. Windows 7.

> which exact version of Spyder 3.0.0 ?

It does only show 3.0.0dev under the help / info.
(maybe this dialogue could in future show the last git commit tag)

I updated from github middle of the week.

More info on Monday. Please ask what I could provide.

will recheck with spyder-master of the moment. hold on 10 minutes

would be nice for inquiries if when building spyder wheel of today, it would generate a `spyder-3.0.0.b2-py3-none-any.whl` rather than a `spyder-3.0.0.dev0-py3-none-any.whl`

argh, spyder starting method has changed.

I do not notice this 3026 problem with master of today (just before Carlos committed the pygment lexer).

But checking that, I notice all my previous WinPython "spyder" icon will fail, as they were launching 

```
python.exe -m spyderlib.start_app %*
```

Keeping a working `spyderlib.start_app` until spyder 3.1 would be kind.

Next Winpython will of course point to 'spyder.exe' executable

I see this on master (5f7f3754).
It only happens when multiple files are open.
Save as on the first tab works.
Save as on second or later tabs gives error message.

Could you post the error please?

Sorry, I did not mean error message, just the dialog box from first comment "Do you want to close...".

Further investigation:
- Only seems to happen on pyqt5, not pyqt4.
- Blocking tab signals here seems to help. But the code seems a bit convoluted, so there might exist a better fix.

``` diff
--- a/spyderlib/widgets/editor.py
+++ b/spyderlib/widgets/editor.py
@@ -974,7 +974,9 @@ class EditorStack(QWidget):
         new_index = self.data.index(finfo)
         self.__repopulate_stack()
         if set_new_index:
+            self.tabs.blockSignals(True)
             self.set_stack_index(new_index)
+            self.tabs.blockSignals(False)
         else:
             # Fixes Issue 1287
             self.set_current_filename(current_fname)
```

I just wanted to said that I reproduced this bug with a fresh installation of  the last WinPython-64bit-3.5.2.1Qt5.exe

here is my dependency copy-pasted :
jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.2 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
numpy >=1.7      :  1.11.1 (OK)
pandas >=0.13.1  :  0.18.1 (OK)
pep8 >=0.6       :  1.7.0 (OK)
pyflakes >=0.6.0 :  1.2.3 (OK)
pygments >=2.0   :  2.1.3 (OK)
pylint >=0.25    :  1.6.1 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
rope >=0.9.4     :  0.9.4-1 (OK)
sphinx >=0.6.6   :  1.4.5 (OK)
sympy >=0.7.3    :  1.0 (OK)

Yep, still happens with:

## Version and main components
- Spyder Version: 3.0.1 
- Python Version: 2.7.11
- Qt Versions: 5.6.0, PyQt5 5.6 on Windows

## Dependencies

```
pyflakes >=0.5.0 :  1.3.0 (OK)
pep8 >=0.6       :  1.7.0 (OK)
pygments >=2.0   :  2.1.3 (OK)
qtconsole >=4.2.0:  4.2.1 (OK)
nbconvert >=4.0  :  4.2.0 (OK)
pandas >=0.13.1  :  0.18.1 (OK)
numpy >=1.7      :  1.10.4 (OK)
sphinx >=0.6.6   :  1.5a1 (OK)
rope >=0.9.4     :  0.10.3 (OK)
jedi >=0.8.1     :  0.9.0 (OK)
matplotlib >=1.0 :  1.5.1 (OK)
sympy >=0.7.3    :  1.0 (OK)
pylint >=0.25    :  1.6.4 (OK)
```

When I get the dialog shown above in the initial post, if I answer 'no' then it does the 'Save As' operation correctly and leaves the file open, with it properly renamed.  If I answer 'yes,' then it closes the tab and the file with the new name never gets created.


Resolving patch:
diff --git a/spyder/widgets/editor.py b/spyder/widgets/editor.py
--- a/spyder/widgets/editor.py
+++ b/spyder/widgets/editor.py
@@ -1318,6 +1318,10 @@ def save_as(self, index=None):
             # Save the currently edited file
             index = self.get_stack_index()
         finfo = self.data[index]
+        # The next line is necessary to avoid checking if the file exists
+        # While running __check_file_status
+        # See issues 3678 and 3026
+        finfo.newly_created = True
         filename = self.select_savename(finfo.filename)
         if filename:
             ao_index = self.has_filename(filename)


Test patch: