Skip to content

Commit

Permalink
Remove 'My Workspace' hardcoded option
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 22, 2023
1 parent deedba9 commit bd6529d
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions felt/core/workspaces_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ def _reply_finished(self, reply: QNetworkReply):

workspaces = result.get('data', [])

self.beginInsertRows(QModelIndex(), len(self.workspaces) + 1,
1 + len(self.workspaces) + len(workspaces) - 1)
self.beginInsertRows(QModelIndex(), len(self.workspaces),
len(self.workspaces) + len(workspaces) - 1)

for workspace_json in workspaces:
_workspace = Workspace.from_json(workspace_json)
Expand All @@ -88,7 +88,7 @@ def index(self, row, column, parent=QModelIndex()):
if column < 0 or column >= self.columnCount():
return QModelIndex()

if not parent.isValid() and 0 <= row < 1 + len(self.workspaces):
if not parent.isValid() and 0 <= row < len(self.workspaces):
return self.createIndex(row, column)

return QModelIndex()
Expand All @@ -98,7 +98,7 @@ def parent(self, index):

def rowCount(self, parent=QModelIndex()):
if not parent.isValid():
return 1 + len(self.workspaces)
return len(self.workspaces)
# no child items
return 0

Expand All @@ -110,12 +110,6 @@ def data(self,
index,
role=Qt.DisplayRole):

if index.row() == 0 and not index.parent().isValid():
# special "My workspace" item
if role in (self.NameRole, Qt.DisplayRole, Qt.ToolTipRole):
return self.tr('My Workspace')
return None

_workspace = self.index2workspace(index)
if _workspace:
if role in (self.NameRole, Qt.DisplayRole, Qt.ToolTipRole):
Expand All @@ -141,8 +135,8 @@ def index2workspace(self, index: QModelIndex) -> Optional[Workspace]:
"""
Returns the workspace at the given model index
"""
if not index.isValid() or index.row() < 1 or index.row() >= 1 + len(
if not index.isValid() or index.row() < 0 or index.row() >= len(
self.workspaces):
return None

return self.workspaces[index.row() - 1]
return self.workspaces[index.row()]

0 comments on commit bd6529d

Please sign in to comment.