@@ -55,18 +55,10 @@ void WorkspaceModel::remove(Workspace *workspace)
5555 beginRemoveRows(QModelIndex(), index, index);
5656
5757 m_workspaces.removeAt(index);
58+ insertUnassigned(workspace);
5859
5960 endRemoveRows();
6061
61− m_unassignedWorkspaces.insert(workspace);
62− connect(workspace, &Workspace::assigned, this, [=]() {
63− m_unassignedWorkspaces.remove(workspace);
64− disconnect(workspace, &Workspace::assigned, this, 0);
65− });
66− connect(workspace, &QObject::destroyed, this, [=]() {
67− m_unassignedWorkspaces.remove(workspace);
68− });
69−
7062 Q_EMIT workspaceRemoved(workspace);
7163 Q_EMIT countChanged();
7264}
@@ -195,6 +187,19 @@ void WorkspaceModel::finishSync()
195187 m_unassignedWorkspaces.clear();
196188}
197189
190+void WorkspaceModel::insertUnassigned(Workspace *workspace)
191+{
192+ m_unassignedWorkspaces.insert(workspace);
193+ connect(workspace, &Workspace::assigned, this, [=]() {
194+ m_unassignedWorkspaces.remove(workspace);
195+ disconnect(workspace, &Workspace::assigned, this, 0);
196+ });
197+ connect(workspace, &QObject::destroyed, this, [=]() {
198+ m_unassignedWorkspaces.remove(workspace);
199+ });
200+}
201+
202+
198203ProxyWorkspaceModel::ProxyWorkspaceModel(WorkspaceModel * const model)
199204 : m_original(model)
200205{
@@ -241,7 +246,7 @@ void ProxyWorkspaceModel::move(int from, int to)
241246void ProxyWorkspaceModel::addWorkspace()
242247{
243248 auto newWorkspace = WorkspaceManager::instance()->createWorkspace();
244− m_original->m_unassignedWorkspaces.insert(newWorkspace);
249+ m_original->insertUnassigned(newWorkspace);
245250
246251 (new ProxyWorkspace(newWorkspace))->assign(this);
247252}