Skip to content

Commit

Permalink
Merge from 3.x: PR #7546
Browse files Browse the repository at this point in the history
Fixes #6292
  • Loading branch information
ccordoba12 committed Jul 25, 2018
2 parents 3cfc663 + 589c940 commit 9c611a1
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 5 deletions.
3 changes: 2 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@
{
'name_filters': NAME_FILTERS,
'show_all': True,
'show_hscrollbar': True
'show_hscrollbar': True,
'visible_if_project_open': True
}),
('explorer',
{
Expand Down
18 changes: 14 additions & 4 deletions spyder/plugins/projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -233,8 +233,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()
Expand Down Expand Up @@ -270,7 +270,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:
Expand Down Expand Up @@ -305,6 +306,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.explorer.clear()
Expand Down Expand Up @@ -378,12 +381,19 @@ 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.explorer.treewidget.get_expanded_state())
self.set_option('scrollbar_position',
self.explorer.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"""
Expand Down
64 changes: 64 additions & 0 deletions spyder/plugins/tests/test_projects.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import pytest

# Local imports
import spyder.plugins.base
from spyder.plugins.projects import Projects
from spyder.py3compat import to_text_string

Expand All @@ -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.base.SpyderDockWidget,
'install_tab_event_filter')
mocker.patch.object(projects, 'toggle_view_action')
projects.create_dockwidget()
return projects


# =============================================================================
# Tests
# =============================================================================
Expand All @@ -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()

0 comments on commit 9c611a1

Please sign in to comment.