Repository: spyder-ide/spyder

Issue:
Shortcut to go to Project pane is not working
<!--- **PLEASE READ:** When submitting here, please ensure you've completed the following checklist and checked the boxes to confirm. Issue reports without it may be closed. Thanks! --->

### Issue Report Checklist

* [x] Searched the [issues page](https://github.com/spyder-ide/spyder/issues?q=is%3Aissue) for similar reports
* [x] Read the relevant sections of the [Spyder Troubleshooting Guide](https://github.com/spyder-ide/spyder/wiki/Troubleshooting-Guide-and-FAQ) and followed its advice
* [x] Reproduced the issue after updating with ``conda update spyder`` (or ``pip``, if not using Anaconda)
* [ ] Could not reproduce inside ``jupyter qtconsole`` (if console-related)
* [x] Tried basic troubleshooting (if a bug/error)
    * [x] Restarted Spyder
    * [x] Reset preferences with ``spyder --reset``
    * [ ] Reinstalled the latest version of [Anaconda](https://www.anaconda.com/download/)
    * [ ] Tried the other applicable steps from the Troubleshooting Guide
* [x] Completed the **Problem Description**, **Steps to Reproduce** and **Version** sections below


## Problem Description
The issue is with the project explorer shortcut that should be enabled with the shortcut ctrl+shift+P. This shortcut does not work when I am on a certain project and I have to go to the View-Panes to activate it. 
Aside from this, as a side problem of pressing F10, which affects the layout of the screen. I need reset that layout to get the splitter unstuck. However, doing so results in the project explorer being hidden automatically. I found that closing Spyder and relaunching it from anaconda gave back the project explorer (but this doesn't work consistently). In the mean-time I am currently going to the View-Panes and re-selecting the project explorer every time I press F10 by mistake.


### What steps reproduce the problem?

1. Press Ctrl+Shit+P when project explorer is hidden

### What is the expected output? What do you see instead?

Toggle of project explorer pant

### Paste Traceback/Error Below (if applicable)
<!--- Copy from error dialog or View > Panes > Internal Console --->

```python-traceback
NA
```

## Versions
<!--- You can get this information from Help > About Spyder...
or (if Spyder won't launch) the "conda list" command
from the Anaconda Prompt/Terminal/command line. --->

* Spyder version: 4.1.2
* Python version: 3.7.4
* Qt version: 5.9.6
* PyQt version: 5.9.2
* Operating System name/version: Windows 10 

### Dependencies
<!--- Please go to the menu entry Help > Dependencies,
press the Copy to clipboard button and paste below --->

```

# Mandatory:
atomicwrites >=1.2.0           :  1.3.0 (OK)
chardet >=2.0.0                :  3.0.4 (OK)
cloudpickle >=0.5.0            :  1.3.0 (OK)
diff_match_patch >=20181111    :  20181111 (OK)
intervaltree                   :  None (OK)
IPython >=4.0                  :  7.13.0 (OK)
jedi =0.15.2                   :  0.15.2 (OK)
nbconvert >=4.0                :  5.6.1 (OK)
numpydoc >=0.6.0               :  0.9.2 (OK)
paramiko >=2.4.0               :  2.7.1 (OK)
parso =0.5.2                   :  0.5.2 (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 >=0.25                  :  2.4.4 (OK)
pyls >=0.31.9;<0.32.0          :  0.31.9 (OK)
qdarkstyle >=2.8               :  2.8 (OK)
qtawesome >=0.5.7              :  0.7.0 (OK)
qtconsole >=4.6.0              :  4.7.2 (OK)
qtpy >=1.5.0                   :  1.9.0 (OK)
rtree >=0.8.3                  :  0.9.3 (OK)
sphinx >=0.6.6                 :  2.4.4 (OK)
spyder_kernels >=1.9.0;<1.10.0 :  1.9.0 (OK)
watchdog                       :  None (OK)
zmq >=17                       :  18.1.1 (OK)

# Optional:
cython >=0.21                  :  0.29.15 (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.3.1 (OK)
sympy >=0.7.3                  :  1.5.1 (OK)
```



Discussion:
> The issue is with the project explorer shortcut that should be enabled with the shortcut ctrl+shift+P. This shortcut does not work when I am on a certain project and I have to go to the View-Panes to activate it.

@dalthviz, could you verify that our default shortcuts shows the Projects pane on Windows or not? It works for me on Linux.

> Aside from this, as a side problem of pressing F10, which affects the layout of the screen. I need reset that layout to get the splitter unstuck.

I don't understand what you mean by this. Please create an animated gif using the [Licecap](https://www.cockos.com/licecap/) program and upload it here.
so what I meant, is by pressing F10, there is currently a bug, that makes the splitter freeze (the splitter separating the console pane from the code pane). The only way to remove the freeze on the splitter is to reset to default layout. Doing so makes the project pane disappear. Closing and reopening the project does not bring it back. The only way to do so is by doing it manually. I don't know if that is the intended behavior thought.
At the start of the screen I pressed F10, causing the splitter to shift to the left as you can see.

![sample](https://user-images.githubusercontent.com/62237347/80317952-14014e80-8807-11ea-9909-a495ef672590.gif)

The thing with F10 probably refers to the bug in #11875 which should be fixed in the next release.

The Ctrl+Shift+P shortcut does not do anything for me either. It is listed in the menu, so I did not redefine it. I sometimes get the message "QAction::eventFilter: Ambiguous shortcut overload: Ctrl+Shift+P" in the terminal where I start Spyder if I press Ctrl+Shift+P but not always.

The other pane shortcuts all seem to work.

This is on Debian Linux with the dev version of Spyder, master branch.
Thanks @jitseniesen for the confirmation. I have two questions for you:

* Does the problem also happen on 4.x?
* Could you go back in our git history before PR #12177 was merged and check if the problem is present there or not?
Another question:

* Does the problem also happens if you start Spyder with `python bootstrap.py --safe-mode`?
> Does the problem also happen on 4.x?

Yes

> Could you go back in our git history before PR #12177 was merged and check if the problem is present there or not?

Still present. Actually, I went back to 3.x and the problem is also present there. It seems to have appeared between 3.3.0 and 3.3.1 (ancient history!)

> Does the problem also happens if you start Spyder with `python bootstrap.py --safe-mode`?

No, that fixes the problem.

I tried out some stuff and found out that the problem only happens if I quit Spyder with a project opened and the Project pane closed, so that next time when you open Spyder the Project pane is not opened. 

Here is how I can reproduce from a clean install (meaning I delete the spyder config directory), using both 4.x and master:
1. Start Spyder
2. Press Ctrl-Shift-P: The Project pane opens (but is empty)
3. Open a project
4. Close the Project pane
5. Press Ctrl-Shift-P: The Project pane opens
6. Close the Project pane
7. Restart Spyder with the Project pane closed
8. Press Ctrl-Shift-P: The Project pane does **NOT** open
9. Open the Project pane using the menu
10. Restart Spyder with the Project pane opened
11. Close the Project pane
12. Press Ctrl-Shift-P: The Project pane opens

Can you reproduce with these instructions?

The difference with Spyder 3.3.0 is that it always opens the Project pane, even when you restart with the Project pane close. Thus, I suspect the cause may be PR #7546 by yours truly :blush: 
@ccordoba12 I was able to reproduce this (the shortcut not working) with the steps provided by @jitseniesen on Windows

Great! Thanks for the confirmation @dalthviz!

> The difference with Spyder 3.3.0 is that it always opens the Project pane, even when you restart with the Project pane close. Thus, I suspect the cause may be PR #7546 by yours truly

Great to know. Then this one is for you @jitseniesen.
I understand what's going wrong. The function `switch_to_plugin` in the Project Explorer plugin, which is called when Ctrl+Shift+P is pressed, says not to switch to the plugin if Spyder is started with the project pane closed.

@ccordoba12 What is the idea behind your commit 32496f798395b4d83c2176c90f64d757abbddabe? Why do you want should actions in the Project menu switch to the Project pane? I want to make sure that my fix respect this.

Resolving patch:
diff --git a/spyder/plugins/projects/plugin.py b/spyder/plugins/projects/plugin.py
--- a/spyder/plugins/projects/plugin.py
+++ b/spyder/plugins/projects/plugin.py
@@ -199,20 +199,13 @@ def closing_plugin(self, cancelable=False):
         self.explorer.closing_widget()
         return True
 
-    def switch_to_plugin(self):
-        """Switch to plugin."""
-        # Unmaxizime currently maximized plugin
+    def unmaximize(self):
+        """Unmaximize the currently maximized plugin, if not self."""
         if (self.main.last_plugin is not None and
                 self.main.last_plugin._ismaximized and
                 self.main.last_plugin is not self):
             self.main.maximize_dockwidget()
 
-        # Show plugin only if it was already visible
-        if self.get_option('visible_if_project_open'):
-            if not self._toggle_view_action.isChecked():
-                self._toggle_view_action.setChecked(True)
-            self._visibility_changed(True)
-
     def build_opener(self, project):
         """Build function opening passed project"""
         def opener(*args, **kwargs):
@@ -267,7 +260,7 @@ def update_project_actions(self):
     @Slot()
     def create_new_project(self):
         """Create new project"""
-        self.switch_to_plugin()
+        self.unmaximize()
         active_project = self.current_active_project
         dlg = ProjectDialog(self)
         dlg.sig_project_creation_requested.connect(self._create_project)
@@ -287,7 +280,7 @@ def open_project(self, path=None, restart_consoles=True,
                      save_previous_files=True):
         """Open the project located in `path`"""
         self.notify_project_open(path)
-        self.switch_to_plugin()
+        self.unmaximize()
         if path is None:
             basedir = get_home_dir()
             path = getexistingdirectory(parent=self,
@@ -338,7 +331,7 @@ def close_project(self):
         project
         """
         if self.current_active_project:
-            self.switch_to_plugin()
+            self.unmaximize()
             if self.main.editor is not None:
                 self.set_project_filenames(
                     self.main.editor.get_open_filenames())
@@ -365,7 +358,7 @@ def delete_project(self):
         Delete the current project without deleting the files in the directory.
         """
         if self.current_active_project:
-            self.switch_to_plugin()
+            self.unmaximize()
             path = self.current_active_project.root_path
             buttons = QMessageBox.Yes | QMessageBox.No
             answer = QMessageBox.warning(


Test patch:
diff --git a/spyder/plugins/projects/tests/test_plugin.py b/spyder/plugins/projects/tests/test_plugin.py
--- a/spyder/plugins/projects/tests/test_plugin.py
+++ b/spyder/plugins/projects/tests/test_plugin.py
@@ -63,7 +63,6 @@ def __getattr__(self, attr):
     projects.shortcut = None
     mocker.patch.object(spyder.plugins.base.SpyderDockWidget,
                         'install_tab_event_filter')
-    mocker.patch.object(projects, '_toggle_view_action')
     projects._create_dockwidget()
 
     # This can only be done at this point
@@ -175,6 +174,17 @@ def test_open_project_uses_visible_config(projects, tmpdir, value):
     assert projects.dockwidget.isVisible() == value
 
 
+@pytest.mark.parametrize('value', [True, False])
+def test_switch_to_plugin(projects, tmpdir, value):
+    """Test that switch_to_plugin always shows the plugin if a project is
+    opened, regardless of the config option visible_if_project_open.
+    Regression test for spyder-ide/spyder#12491."""
+    projects.set_option('visible_if_project_open', value)
+    projects.open_project(path=to_text_string(tmpdir))
+    projects.switch_to_plugin()
+    assert projects.dockwidget.isVisible()
+
+
 def test_set_get_project_filenames_when_closing_no_files(create_projects,
                                                          tmpdir):
     """