Refactor how workspaces are tracked upon workspace context change.
This commit is contained in:
@ -444,9 +444,46 @@ class WorkspacesView extends WorkspacesViewBase {
|
||||
this.set_child_above_sibling(activeWorkspace, null);
|
||||
}
|
||||
|
||||
_refreshMetaWorkspace(metaWorkspace, idx) {
|
||||
|
||||
// If the current element at idx matches metaWorkspace don't do anything
|
||||
if (idx < this._workspaces.length) {
|
||||
if (this._workspaces[idx].metaWorkspace.get_id() === metaWorkspace.get_id()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
let workspace = new Workspace.Workspace(
|
||||
metaWorkspace,
|
||||
this._monitorIndex,
|
||||
this._overviewAdjustment);
|
||||
|
||||
|
||||
if (idx < this._workspaces.length) {
|
||||
// Replace a current entry
|
||||
let old = this._workspaces[idx];
|
||||
this._workspaces[idx] = workspace;
|
||||
this.add_actor(workspace);
|
||||
this.set_child_at_index(workspace, idx);
|
||||
old.destroy();
|
||||
} else {
|
||||
// Append a new entry
|
||||
this.add_actor(workspace);
|
||||
this._workspaces.push(workspace);
|
||||
}
|
||||
}
|
||||
|
||||
_refreshWorkspaces() {
|
||||
for (let ws = this._workspaces.pop(); ws; ws = this._workspaces.pop()) {
|
||||
ws.destroy();
|
||||
let workspaceManager = global.workspace_manager;
|
||||
let nWorkspaces = workspaceManager.n_workspaces;
|
||||
|
||||
for (let i = 0; i < nWorkspaces; i++) {
|
||||
let metaWorkspace = workspaceManager.get_workspace_by_index(i);
|
||||
this._refreshMetaWorkspace(metaWorkspace, i);
|
||||
}
|
||||
for (let i = this._workspaces.length - 1; i >= nWorkspaces; i--) {
|
||||
this._workspaces[i].destroy();
|
||||
this._workspaces.splice(i, 1);
|
||||
}
|
||||
this._updateWorkspaces();
|
||||
}
|
||||
|
Reference in New Issue
Block a user