Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PR: Do not automatically open Project Explorer when opening project if user closed it #7546

Merged
merged 5 commits into from
Jul 25, 2018
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion spyder/config/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,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 @@ -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()
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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"""
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is only valid in master. For 3.x you need to write:

import spyder.plugins

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I tested against master, then rebased against 3.x, but forgot to run the tests again. Stupid.

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()