Repository: spyder-ide/spyder

Issue:
Segmentation fault when requesting context menu for a one file in project explorer
## Description

### What steps will reproduce the problem?

<!--- You can use Markdown here --->

A segmentation fault occurs when I request the context menu for a one file in project explorer. But It works well in Files.


![segmentation_fault](https://user-images.githubusercontent.com/22970578/86145288-b7395180-bb31-11ea-906e-4a2533174126.gif)

https://github.com/spyder-ide/spyder/blob/fa39a2f4fd460bc6448ffc4845c3af95e539877b/spyder/plugins/explorer/widgets/explorer.py#L580
If I comment out "self.fsmodel.type(rows[0]) == 'Folder'", it works well.

## Versions

* Spyder version: 4.2.0.dev0 adbf95fd1
* Python version: 3.7.6
* Qt version: 5.9.6
* PyQt5 version: 5.9.2
* Operating System: Linux 4.15.0-108-generic

### Dependencies

```

# Mandatory:
atomicwrites >=1.2.0           :  1.4.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.4.1 (OK)
diff_match_patch >=20181111    :  20181111 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.13.0 (OK)
jedi =0.17.1                   :  0.17.1 (OK)
keyring                        :  None (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  0.9.2 (OK)
parso =0.7.0                   :  0.7.0 (OK)
pexpect >=4.4.0                :  4.8.0 (OK)
pickleshare >=0.4              :  0.7.5 (OK)
psutil >=5.3                   :  5.7.0 (OK)
pygments >=2.0                 :  2.6.1 (OK)
pylint >=1.0                   :  2.5.2 (OK)
pyls >=0.33.0;<0.34.0          :  v4.1.3+337.gadbf95fd1 (OK)
qdarkstyle >=2.8               :  2.8.1 (OK)
qtawesome >=0.5.7              :  0.7.0 (OK)
qtconsole >=4.6.0              :  4.7.4 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.4 (OK)
sphinx >=0.6.6                 :  3.0.4 (OK)
spyder_kernels >=1.9.1;<1.10.0 :  1.10.0.dev0 (OK)
watchdog                       :  None (OK)
xdg >=0.26                     :  0.26 (OK)
zmq >=17                       :  18.1.1 (OK)

# Optional:
cython >=0.21                  :  0.29.17 (OK)
matplotlib >=2.0.0             :  3.1.3 (OK)
numpy >=1.7                    :  1.18.1 (OK)
pandas >=0.13.1                :  1.0.3 (OK)
scipy >=0.17.0                 :  1.4.1 (OK)
sympy >=0.7.3                  :  1.5.1 (OK)

# Spyder plugins:
spyder_vim                     :  0.1.0.dev0 (OK)
```



Discussion:
Hi @ok97465,

I could reproduce this issue, thanks for reporting!!

@andfoy please take a look of this one!

Resolving patch:
diff --git a/spyder/plugins/explorer/widgets/explorer.py b/spyder/plugins/explorer/widgets/explorer.py
--- a/spyder/plugins/explorer/widgets/explorer.py
+++ b/spyder/plugins/explorer/widgets/explorer.py
@@ -576,9 +576,9 @@ def create_file_manage_actions(self, fnames):
         # Needed to disable actions in the context menu if there's an
         # empty folder. See spyder-ide/spyder#13004
         if len(fnames) == 1 and self.selectionModel():
-            rows = self.selectionModel().selectedRows()
-            if (self.fsmodel.type(rows[0]) == 'Folder' and
-                    self.fsmodel.rowCount(rows[0]) == 0):
+            current_index = self.selectionModel().currentIndex()
+            if (self.model().type(current_index) == 'Folder' and
+                    self.model().rowCount(current_index) == 0):
                 fnames = []
         if not fnames:
             for action in actions:
@@ -1405,6 +1405,10 @@ def data(self, index, role):
                 return osp.join(self.root_path, root_dir)
         return QSortFilterProxyModel.data(self, index, role)
 
+    def type(self, index):
+        """Returns the type of file for the given index."""
+        return self.sourceModel().type(self.mapToSource(index))
+
 
 class FilteredDirView(DirView):
     """Filtered file/directory tree view"""


Test patch: