Repository: spyder-ide/spyder

Issue:
Error when renaming file in the open files dialog 
## Description

### What steps will reproduce the problem?

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

1. Rename the current file in the Editor with the open files dialog.
2. Select another file in the dialog.
3. A message indicating that the current file was change outside Spyder shows up. Click `yes`.
4. Error report dialog pops up.

### Traceback
```python-traceback
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1901, in load
    self.switch_to_plugin()
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 1437, in switch_to_plugin
    super(Editor, self).switch_to_plugin()
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\api\plugins.py", line 355, in switch_to_plugin
    super(BasePluginWidget, self)._switch_to_plugin()
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 290, in _switch_to_plugin
    self._visibility_changed(True)
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 346, in _visibility_changed
    SpyderPluginWidget._visibility_changed(self, enable)
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\base.py", line 388, in _visibility_changed
    self.refresh_plugin()
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\plugin.py", line 360, in refresh_plugin
    editorstack.refresh()
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2404, in refresh
    self._refresh_outlineexplorer(index, update=False)
  File "C:\Users\Daniel\Anaconda3\envs\4v\lib\site-packages\spyder\plugins\editor\widgets\editor.py", line 2283, in _refresh_outlineexplorer
    finfo = self.data[index]
IndexError: list index out of range
```

## Versions

* Spyder version: 4.0.1 
* Python version: 3.7.6
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Windows 10

### Dependencies

```
atomicwrites >=1.2.0         :  1.3.0 (OK)
chardet >=2.0.0              :  3.0.4 (OK)
cloudpickle >=0.5.0          :  1.2.2 (OK)
diff_match_patch >=20181111  :  20181111 (OK)
intervaltree                 :  None (OK)
IPython >=4.0                :  7.11.1 (OK)
jedi =0.14.1                 :  0.14.1 (OK)
nbconvert >=4.0              :  5.6.1 (OK)
numpydoc >=0.6.0             :  0.9.2 (OK)
pexpect >=4.4.0              :  4.7.0 (OK)
pickleshare >=0.4            :  0.7.5 (OK)
psutil >=0.3                 :  5.6.7 (OK)
pygments >=2.0               :  2.5.2 (OK)
pylint >=0.25                :  2.4.4 (OK)
pyls >=0.31.2;<0.32.0        :  0.31.2 (OK)
zmq >=17                     :  18.1.0 (OK)
qdarkstyle >=2.7             :  2.7 (OK)
qtawesome >=0.5.7            :  0.6.0 (OK)
qtconsole >=4.6.0            :  4.6.0 (OK)
qtpy >=1.5.0                 :  1.9.0 (OK)
rtree >=0.8.3                :  0.8.3 (OK)
sphinx >=0.6.6               :  2.3.1 (OK)
spyder_kernels >=1.8.1;<2.0.0:  1.9.0.dev0 (OK)
watchdog                     :  None (OK)
cython >=0.21                :  None (NOK)
matplotlib >=2.0.0           :  3.1.1 (OK)
numpy >=1.7                  :  1.17.4 (OK)
pandas >=0.13.1              :  0.25.3 (OK)
scipy >=0.17.0               :  1.3.2 (OK)
sympy >=0.7.3                :  None (NOK)
```



Discussion:

Resolving patch:
diff --git a/spyder/plugins/editor/widgets/editor.py b/spyder/plugins/editor/widgets/editor.py
--- a/spyder/plugins/editor/widgets/editor.py
+++ b/spyder/plugins/editor/widgets/editor.py
@@ -2286,7 +2286,7 @@ def _refresh_outlineexplorer(self, index=None, update=True, clear=False):
             return
         if index is None:
             index = self.get_stack_index()
-        if self.data:
+        if self.data and len(self.data) > index:
             finfo = self.data[index]
             oe.setEnabled(True)
             if finfo.editor.oe_proxy is None:
@@ -2315,20 +2315,22 @@ def _sync_outlineexplorer_file_order(self):
 
     def __refresh_statusbar(self, index):
         """Refreshing statusbar widgets"""
-        finfo = self.data[index]
-        self.encoding_changed.emit(finfo.encoding)
-        # Refresh cursor position status:
-        line, index = finfo.editor.get_cursor_line_column()
-        self.sig_editor_cursor_position_changed.emit(line, index)
+        if self.data and len(self.data) > index:
+            finfo = self.data[index]
+            self.encoding_changed.emit(finfo.encoding)
+            # Refresh cursor position status:
+            line, index = finfo.editor.get_cursor_line_column()
+            self.sig_editor_cursor_position_changed.emit(line, index)
 
     def __refresh_readonly(self, index):
-        finfo = self.data[index]
-        read_only = not QFileInfo(finfo.filename).isWritable()
-        if not osp.isfile(finfo.filename):
-            # This is an 'untitledX.py' file (newly created)
-            read_only = False
-        finfo.editor.setReadOnly(read_only)
-        self.readonly_changed.emit(read_only)
+        if self.data and len(self.data) > index:
+            finfo = self.data[index]
+            read_only = not QFileInfo(finfo.filename).isWritable()
+            if not osp.isfile(finfo.filename):
+                # This is an 'untitledX.py' file (newly created)
+                read_only = False
+            finfo.editor.setReadOnly(read_only)
+            self.readonly_changed.emit(read_only)
 
     def __check_file_status(self, index):
         """Check if file has been changed in any way outside Spyder:
@@ -2341,6 +2343,9 @@ def __check_file_status(self, index):
             return
         self.__file_status_flag = True
 
+        if len(self.data) <= index:
+            index = self.get_stack_index()
+
         finfo = self.data[index]
         name = osp.basename(finfo.filename)
 


Test patch: