Fix traceback when the path to a project cannot be found for the last_position and an favorites.

This commit is contained in:
Barry Scott
2019-02-18 10:10:30 +00:00
parent 8d9dd51dca
commit 3555930ac2
3 changed files with 26 additions and 12 deletions
+1 -2
View File
@@ -97,8 +97,7 @@ class Preferences(PreferencesNode):
if project.path == path:
return project
assert False, 'No project with path %r' % (path,)
return None
def getProjectContainingPath( self, path:pathlib.Path ):
for project in self.all_projects.values():
+18 -10
View File
@@ -225,15 +225,20 @@ class WbScmMainWindow(wb_main_window.WbMainWindow):
last_position = self.app.prefs.last_position
if last_position is not None:
project = self.app.prefs.getProjectByPath( last_position.project_path )
index = self.tree_model.indexFromProject( project )
if project is None:
self.log.error( 'Cannot find project: %s' % (last_position.project_path,) )
last_position = None
else:
index = self.tree_model.getFirstProjectIndex()
if project is None:
project_name = self.tree_model.getFirstProjectName()
if project_name is not None:
project = self.app.prefs.getProject( project_name )
self.tree_view.sortByColumn( 0, QtCore.Qt.DescendingOrder )
self.tree_view.setSortingEnabled( True )
if index is not None:
if project is not None:
index = self.tree_model.indexFromProject( project )
index = self.tree_sortfilter.mapFromSource( index )
self.tree_view.setCurrentIndex( index )
@@ -570,13 +575,16 @@ class WbScmMainWindow(wb_main_window.WbMainWindow):
all_submenus[ submenu_fullname ] = submenu
project = prefs.getProjectByPath( favorite.project_path )
if project is None:
self.log.error( 'Cannot find path for favorite: %s' % (favorite.project_path) )
action = submenu.addAction( menu_levels[-1] )
handler = self.app.wrapWithThreadSwitcher( self.gotoFavoriteHandler_bg, 'favorite: %s' % (menu_name,) )
action.triggered.connect( handler )
action.setMenuRole( QtWidgets.QAction.NoRole )
action.setStatusTip( 'Goto Favorite %s - %s' % (project.name, favorite.path) )
action.setData( favorite )
else:
action = submenu.addAction( menu_levels[-1] )
handler = self.app.wrapWithThreadSwitcher( self.gotoFavoriteHandler_bg, 'favorite: %s' % (menu_name,) )
action.triggered.connect( handler )
action.setMenuRole( QtWidgets.QAction.NoRole )
action.setStatusTip( 'Goto Favorite %s - %s' % (project.name, favorite.path) )
action.setData( favorite )
@thread_switcher
def gotoFavoriteHandler_bg( self, clicked=None ):
+7
View File
@@ -121,6 +121,13 @@ class WbScmTreeModel(QtGui.QStandardItemModel):
item = self.invisibleRootItem().child( 0 )
return self.indexFromItem( item )
def getFirstProjectName( self ):
if self.invisibleRootItem().rowCount() == 0:
return None
item = self.invisibleRootItem().child( 0 )
return item.text()
def indexFromProject( self, project ):
item = self.invisibleRootItem()