Repository: spyder-ide/spyder

Issue:
Do not reopen Project explorer on startup
## Description

**What steps will reproduce the problem?**

1. Close _Project explorer_ pane
2. Close Spyder
3. Open Spyder

**What is the expected output?** 
No _Project explorer_

**What do you see instead?**
_Project explorer_ is back, however the corresponding checkbox in _Projects_ drop-down menu is unchecked

**Please provide any additional information below**
I don't know if it's a bug or a feature. Anyway, Spyder should not decide for me what to see. Exists since 3.2.4 at least.


## Version and main components

* Spyder Version: 3.2.6 
* Python Version: 3.6.4
* Qt Versions: 5.10.0, PyQt5 5.9.2 on Linux

## Dependencies
```
pyflakes >=0.6.0 :  1.6.0 (OK)
pycodestyle >=2.3:  2.3.1 (OK)
pygments >=2.0   :  2.2.0 (OK)
pandas >=0.13.1  :  0.21.0 (OK)
numpy >=1.7      :  1.14.0 (OK)
sphinx >=0.6.6   :  1.6.6 (OK)
rope >=0.9.4     :  0.10.6 (OK)
jedi >=0.9.0     :  0.11.1 (OK)
psutil >=0.3     :  5.4.3 (OK)
nbconvert >=4.0  :  5.3.1 (OK)
sympy >=0.7.3    :  1.1.1 (OK)
cython >=0.21    :  0.27.3 (OK)
qtconsole >=4.2.0:  4.3.1 (OK)
IPython >=4.0    :  6.2.1 (OK)
pylint >=0.25    :  1.8.1 (OK)

```



Discussion:
@homocomputeris   Thanks for the report!
Thanks @csabella , I've seen this one consistently as well (on Windows) but I didn't want to gum up the works reporting it if it only bothered me...looks like that's not the case. Not sure its truly a bug but rather a side effect of consistent behavior (project explorer always opening on opening a project) that we may want to reconsider, though it has certainly _bug_ ged me, heh.

I guess the broader question is when opening a project (which is the routine underlying this), would we then not want to open project explorer if it isn't already open in the previous project? What if no project was open previously? Just save the last known state and go by that? 

Just some questions to ponder...
It bothered me as well, to be honest. Can we do the same as we do for the Outline panel? I don't know exactly when the Outline panel appears and disappears, but it does not bother me so the rules for the Outline panel are at least sensible for how I use it.
@jitseniesen 

> Can we do the same as we do for the Outline panel?

At least on Windows, I haven't observed any funny business with that in any Spyder version I've used (since 3.2.1).
I think doing the same as we do for the Outline panel means that we do not automatically close the Project Explorer panel when a project is closed; instead we leave the Project Explorer panel empty. Conversely, if a project is opened, the Project Explorer is not automatically opened.

On reflection, I think @CAM-Gerlach 's idea in https://github.com/spyder-ide/spyder/issues/6292#issuecomment-360354115 is better: when closing a project, remember if the Project Explorer was open. When opening a project, only open the Project Explorer if it was open the last time that a project was closed.
Sorry, I closed the issue by accident

Resolving patch:
diff --git a/spyder/config/main.py b/spyder/config/main.py
--- a/spyder/config/main.py
+++ b/spyder/config/main.py
@@ -259,7 +259,8 @@
              {
               'name_filters': NAME_FILTERS,
               'show_all': True,
-              'show_hscrollbar': True
+              'show_hscrollbar': True,
+              'visible_if_project_open': True
               }),
             ('explorer',
              {
diff --git a/spyder/plugins/projects.py b/spyder/plugins/projects.py
--- a/spyder/plugins/projects.py
+++ b/spyder/plugins/projects.py
@@ -230,8 +230,8 @@ def create_new_project(self):
         dlg.sig_project_creation_requested.connect(self._create_project)
         dlg.sig_project_creation_requested.connect(self.sig_project_created)
         if dlg.exec_():
-            pass
-            if active_project is None:
+            if (active_project is None
+                    and self.get_option('visible_if_project_open')):
                 self.show_explorer()
             self.sig_pythonpath_changed.emit()
             self.restart_consoles()
@@ -267,7 +267,8 @@ def open_project(self, path=None, restart_consoles=True,
                 self.editor.save_open_files()
             if self.editor is not None:
                 self.editor.set_option('last_working_dir', getcwd_or_home())
-            self.show_explorer()
+            if self.get_option('visible_if_project_open'):
+                self.show_explorer()
         else:
             # We are switching projects
             if self.editor is not None:
@@ -302,6 +303,8 @@ def close_project(self):
             self.sig_pythonpath_changed.emit()
 
             if self.dockwidget is not None:
+                self.set_option('visible_if_project_open',
+                                self.dockwidget.isVisible())
                 self.dockwidget.close()
 
             self.clear()
@@ -375,11 +378,18 @@ def get_last_working_dir(self):
                                       default=getcwd_or_home())
 
     def save_config(self):
-        """Save configuration: opened projects & tree widget state"""
+        """
+        Save configuration: opened projects & tree widget state.
+
+        Also save whether dock widget is visible if a project is open.
+        """
         self.set_option('recent_projects', self.recent_projects)
         self.set_option('expanded_state', self.treewidget.get_expanded_state())
         self.set_option('scrollbar_position',
                         self.treewidget.get_scrollbar_position())
+        if self.current_active_project and self.dockwidget:
+            self.set_option('visible_if_project_open',
+                            self.dockwidget.isVisible())
 
     def load_config(self):
         """Load configuration: opened projects & tree widget state"""


Test patch:
diff --git a/spyder/plugins/tests/test_projects.py b/spyder/plugins/tests/test_projects.py
--- a/spyder/plugins/tests/test_projects.py
+++ b/spyder/plugins/tests/test_projects.py
@@ -14,6 +14,7 @@
 import pytest
 
 # Local imports
+import spyder.plugins
 from spyder.plugins.projects import Projects
 from spyder.py3compat import to_text_string
 
@@ -29,6 +30,17 @@ def projects(qtbot):
     return projects
 
 
+@pytest.fixture
+def projects_with_dockwindow(projects, mocker):
+    """Fixture for Projects plugin with a dockwindow"""
+    projects.shortcut = None
+    mocker.patch.object(spyder.plugins.SpyderDockWidget,
+                        'install_tab_event_filter')
+    mocker.patch.object(projects, 'toggle_view_action')
+    projects.create_dockwidget()
+    return projects
+
+
 # =============================================================================
 # Tests
 # =============================================================================
@@ -47,5 +59,57 @@ def test_open_project(projects, tmpdir, test_directory):
     # Close project
     projects.close_project()
 
+
+@pytest.mark.parametrize('value', [True, False])
+def test_close_project_sets_visible_config(projects_with_dockwindow, tmpdir,
+                                           value):
+    """Test that when project is closed, the config option
+    visible_if_project_open is set to the correct value."""
+    projects = projects_with_dockwindow
+
+    # Set config to opposite value so that we can check that it's set correctly
+    projects.set_option('visible_if_project_open', not value)
+
+    projects.open_project(path=to_text_string(tmpdir))
+    if value:
+        projects.show_explorer()
+    else:
+        projects.dockwidget.close()
+    projects.close_project()
+    assert projects.get_option('visible_if_project_open') == value
+
+
+@pytest.mark.parametrize('value', [True, False])
+def test_closing_plugin_sets_visible_config(
+        projects_with_dockwindow, tmpdir, value):
+    """Test that closing_plugin() sets config option visible_if_project_open
+    if a project is open."""
+    projects = projects_with_dockwindow
+    projects.set_option('visible_if_project_open', not value)
+    projects.closing_plugin()
+
+    # No project is open so config option should remain unchanged
+    assert projects.get_option('visible_if_project_open') == (not value)
+
+    projects.open_project(path=to_text_string(tmpdir))
+    if value:
+        projects.show_explorer()
+    else:
+        projects.dockwidget.close()
+    projects.close_project()
+    assert projects.get_option('visible_if_project_open') == value
+
+
+@pytest.mark.parametrize('value', [True, False])
+def test_open_project_uses_visible_config(
+        projects_with_dockwindow, tmpdir, value):
+    """Test that when a project is opened, the project explorer is only opened
+    if the config option visible_if_project_open is set."""
+    projects = projects_with_dockwindow
+    projects.set_option('visible_if_project_open', value)
+    projects.open_project(path=to_text_string(tmpdir))
+    assert projects.dockwidget.isVisible() == value
+
+
 if __name__ == "__main__":
     pytest.main()