Repository: spyder-ide/spyder

Issue:
Files are opened twice at startup if a project is active
Reported as part of #3585 



Discussion:

Resolving patch:
diff --git a/spyder/app/mainwindow.py b/spyder/app/mainwindow.py
--- a/spyder/app/mainwindow.py
+++ b/spyder/app/mainwindow.py
@@ -864,12 +864,11 @@ def create_edit_action(text, tr_text, icon):
             self.onlinehelp.register_plugin()
 
         # Project explorer widget
-        if CONF.get('project_explorer', 'enable'):
-            self.set_splash(_("Loading project explorer..."))
-            from spyder.plugins.projects import Projects
-            self.projects = Projects(self)
-            self.projects.register_plugin()
-            self.project_path = self.projects.get_pythonpath(at_start=True)
+        self.set_splash(_("Loading project explorer..."))
+        from spyder.plugins.projects import Projects
+        self.projects = Projects(self)
+        self.projects.register_plugin()
+        self.project_path = self.projects.get_pythonpath(at_start=True)
 
         # External console
         self.set_splash(_("Loading external console..."))
@@ -1261,24 +1260,20 @@ def post_visible_setup(self):
         if not self.extconsole.isvisible and not ipy_visible:
             self.historylog.add_history(get_conf_path('history.py'))
 
-        if self.projects is not None:
-            # Load last project (if a project was active when Spyder
-            # was closed)
-            self.projects.reopen_last_project()
+        # Load last project if a project was active when Spyder
+        # was closed
+        self.projects.reopen_last_project()
 
-            # Open last session files and give focus to the Editor
-            if self.editor.dockwidget.isVisible():
-                self.editor.setup_open_files()
-                try:
-                    self.editor.get_focus_widget().setFocus()
-                except AttributeError:
-                    pass
+        # If no project is active, load last session
+        if self.projects.get_active_project() is None:
+            self.editor.setup_open_files()
 
         # Check for spyder updates
         if DEV is None and CONF.get('main', 'check_updates_on_startup'):
             self.give_updates_feedback = False
             self.check_updates()
 
+        # Show dialog with missing dependencies
         self.report_missing_dependencies()
 
         self.is_setting_up = False
diff --git a/spyder/config/main.py b/spyder/config/main.py
--- a/spyder/config/main.py
+++ b/spyder/config/main.py
@@ -266,7 +266,6 @@
               }),
             ('project_explorer',
              {
-              'enable': True,
               'name_filters': NAME_FILTERS,
               'show_all': True,
               'show_hscrollbar': True
@@ -589,7 +588,7 @@
 #    or if you want to *rename* options, then you need to do a MAJOR update in
 #    version, e.g. from 3.0.0 to 4.0.0
 # 3. You don't need to touch this value if you're just adding a new option
-CONF_VERSION = '28.0.0'
+CONF_VERSION = '29.0.0'
 
 # Main configuration instance
 CONF = UserConfig('spyder', defaults=DEFAULTS, load=(not TEST),
diff --git a/spyder/plugins/projects.py b/spyder/plugins/projects.py
--- a/spyder/plugins/projects.py
+++ b/spyder/plugins/projects.py
@@ -226,7 +226,8 @@ def _create_project(self, path):
         self.setup_menu_actions()
         self.add_to_recent(path)
 
-    def open_project(self, path=None, restart_consoles=True):
+    def open_project(self, path=None, restart_consoles=True,
+                     save_previous_files=True):
         """Open the project located in `path`"""
         if path is None:
             basedir = get_home_dir()
@@ -243,7 +244,8 @@ def open_project(self, path=None, restart_consoles=True):
 
         # A project was not open before
         if self.current_active_project is None:
-            self.editor.save_open_files()
+            if save_previous_files:
+                self.editor.save_open_files()
             self.editor.set_option('last_working_dir', getcwd())
             self.show_explorer()
         else: # we are switching projects
@@ -295,7 +297,8 @@ def reopen_last_project(self):
         if current_project_path and \
           self.is_valid_project(current_project_path):
             self.open_project(path=current_project_path,
-                              restart_consoles=False)
+                              restart_consoles=False,
+                              save_previous_files=False)
             self.load_config()
 
     def get_project_filenames(self):


Test patch: