Repository: spyder-ide/spyder

Issue:
Errors triggered when saving "Saving as" a file in latest master
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

I can take a look at this later, but I created a new file with ``Ctrl-N`` in a copy of Spyder 4 ``master`` that I'd just started using with just basic settings applied, and then proceeded to name and save it with the OS file manager. However, when I did, I got this error, which reappeared whenever I did "Save As" on the file, saving it in a variety of names and locations and with the Outline Explorer and the Class/Method browser both open and closed. The file does save successfully and display in the Editor, however.

```python-traceback
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\plugin.py", line 1241, in file_renamed_in_data_in_editorstack
    editorstack.rename_in_data(original_filename, filename)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\editor.py", line 1287, in rename_in_data
    finfo.editor.oe_proxy, finfo.filename)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\outlineexplorer\widgets.py", line 692, in file_renamed
    self.treewidget.file_renamed(editor, new_filename)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\outlineexplorer\widgets.py", line 298, in file_renamed
    editor_id = editor.get_id()
AttributeError: 'NoneType' object has no attribute 'get_id'
```

I *was* able to reproduce this error consistently in a clean (``--safe-mode``) copy of Spyder 4 ``master`` by simply creating a new file with the default template, and attempting to save it somewhere; the error doesn't seem to trigger when saving any file (not save-as), nor when using save-as on a file that was originally opened via ``Open`` rather than ``New file`` (including the same new files that would previously trigger it, once closed and re-opened).

However, when I went back to try Save As again on the original file in the original Spyder 4 copy, it then kept giving me the "NEW FILENAME [the new filename I saved it as] is unavailable/do you want to close it"  warning (except if I kept the same name and location in the Save As dialog) and the file was not saved on disk at that point; I then started getting the same thing on the clean copy. If I clicked as to whether I want to close it, the file *is* then saved to disk and correctly displayed in the Editor as saved, but next time I try to "Save as" I get the message again; if I click "yes" to close the file, I then got an error either after being prompted to save the file before closing and clicking "no" there, or immediately upon clicking "Yes" in the "do you want to close" dialog; 

```python-traceback
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\plugin.py", line 1872, in save_as
    if editorstack.save_as():
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\editor.py", line 1860, in save_as
    ok = self.save(index=new_index, force=True)
  File "C:\Users\C. A. M. Gerlach\Documents\dev\SpyderDev\spyder\spyder\plugins\editor\widgets\editor.py", line 1693, in save
    finfo = self.data[index]
IndexError: list index out of range
```


## Versions

* Spyder version: 4.0.0.dev0 a411d61d7
* Python version: 3.7.2
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 8.1

### Dependencies

```
pygments >=2.0    :  2.3.1 (OK)
qdarkstyle >=2.6.4:  2.6.5 (OK)
sphinx >=0.6.6    :  1.8.4 (OK)
pyls >=0.19.0     :  0.21.5 (OK)
nbconvert >=4.0   :  5.4.0 (OK)
pandas >=0.13.1   :  0.24.1 (OK)
numpy >=1.7       :  1.15.4 (OK)
sympy >=0.7.3     :  1.3 (OK)
cython >=0.21     :  0.29.4 (OK)
qtconsole >=4.2.0 :  4.4.3 (OK)
IPython >=4.0     :  7.2.0 (OK)
matplotlib >=2.0.0:  3.0.2 (OK)
pylint >=0.25     :  2.2.2 (OK)
```

Error while saving a file
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

I was saving a new file. I guess it could be solved by adding a None test?

### Traceback
```python-traceback
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/plugin.py", line 1241, in file_renamed_in_data_in_editorstack
    editorstack.rename_in_data(original_filename, filename)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/editor/widgets/editor.py", line 1287, in rename_in_data
    finfo.editor.oe_proxy, finfo.filename)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/outlineexplorer/widgets.py", line 690, in file_renamed
    self.treewidget.file_renamed(editor, new_filename)
  File "/Users/quentinpeter/pyscripts/spyder/spyder/plugins/outlineexplorer/widgets.py", line 298, in file_renamed
    editor_id = editor.get_id()
AttributeError: 'NoneType' object has no attribute 'get_id'
```

## Versions

* Spyder version: 4.0.0.dev0 86bc6c0d0
* Python version: 3.7.2
* Qt version: 5.9.3
* PyQt5 version: 5.9.2
* Operating System: Darwin 18.2.0

### Dependencies

```
pygments >=2.0    :  2.2.0 (OK)
qdarkstyle >=2.6.4:  2.6.4 (OK)
sphinx >=0.6.6    :  1.8.1 (OK)
psutil >=0.3      :  5.4.7 (OK)
pyls >=0.19.0     :  0.21.2 (OK)
nbconvert >=4.0   :  5.4.0 (OK)
pandas >=0.13.1   :  None (NOK)
numpy >=1.7       :  1.15.2 (OK)
sympy >=0.7.3     :  1.3 (OK)
cython >=0.21     :  0.28.5 (OK)
qtconsole >=4.2.0 :  4.4.1 (OK)
IPython >=4.0     :  7.0.1 (OK)
matplotlib >=2.0.0:  3.0.2 (OK)
pylint >=0.25     :  2.1.1 (OK)
```



Discussion:

> I guess it could be solved by adding a None test?

What do you mean?
I don't know what happened. maybe this error can be avoided with a `if editor is not None`
I see, sure, that's a good idea. Would you like to create a PR for this?

Resolving patch:
diff --git a/spyder/plugins/outlineexplorer/widgets.py b/spyder/plugins/outlineexplorer/widgets.py
--- a/spyder/plugins/outlineexplorer/widgets.py
+++ b/spyder/plugins/outlineexplorer/widgets.py
@@ -295,6 +295,11 @@ def set_current_editor(self, editor, update):
 
     def file_renamed(self, editor, new_filename):
         """File was renamed, updating outline explorer tree"""
+        if editor is None:
+            # This is needed when we can't find an editor to attach
+            # the outline explorer to.
+            # Fix issue 8813
+            return
         editor_id = editor.get_id()
         if editor_id in list(self.editor_ids.values()):
             root_item = self.editor_items[editor_id]


Test patch: