2 * Copyright (C) 2017 Canonical, Ltd.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 3.
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
13 * You should have received a copy of the GNU General Public License
14 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17#include "WorkspaceManager.h"
19#include "TopLevelWindowModel.h"
22#include <QGuiApplication>
26WorkspaceManager *WorkspaceManager::instance()
28 static WorkspaceManager* workspaceManager(new WorkspaceManager());
29 return workspaceManager;
32WorkspaceManager::WorkspaceManager()
33 : m_activeWorkspace(nullptr)
37Workspace *WorkspaceManager::createWorkspace()
39 auto workspace = new Workspace(this);
40 QQmlEngine::setObjectOwnership(workspace, QQmlEngine::CppOwnership);
41 m_allWorkspaces.insert(workspace);
42 m_floatingWorkspaces.append(workspace);
44 connect(workspace, &Workspace::assigned, this, [this, workspace]() {
45 m_floatingWorkspaces.removeOne(workspace);
46 Q_EMIT floatingWorkspacesChanged();
48 connect(workspace, &Workspace::unassigned, this, [this, workspace]() {
49 m_floatingWorkspaces.append(workspace);
50 Q_EMIT floatingWorkspacesChanged();
53 if (m_allWorkspaces.count() == 0 && m_activeWorkspace) {
54 setActiveWorkspace(nullptr);
55 Q_EMIT activeWorkspaceChanged();
56 } else if (m_allWorkspaces.count() == 1) {
57 setActiveWorkspace(workspace);
63void WorkspaceManager::destroyWorkspace(Workspace *workspace)
65 if (!workspace) return;
67 if (workspace->isAssigned()) {
68 workspace->unassign();
70 m_floatingWorkspaces.removeOne(workspace);
71 m_allWorkspaces.remove(workspace);
72 Q_EMIT floatingWorkspacesChanged();
74 if (m_activeWorkspace == workspace) {
75 Q_ASSERT(false); // Shouldn't happen, should have chosen something by now.
76 // just choose anything.
77 setActiveWorkspace(m_allWorkspaces.count() ? *m_allWorkspaces.begin() : nullptr);
79 if (m_activeWorkspace) {
80 workspace->moveWindowsTo(m_activeWorkspace);
83 disconnect(workspace, 0, this, 0);
87QQmlListProperty<Workspace> WorkspaceManager::floatingWorkspaces()
89 return QQmlListProperty<Workspace>(this, m_floatingWorkspaces);
92void WorkspaceManager::destroyFloatingWorkspaces()
94 QList<Workspace*> dpCpy(m_floatingWorkspaces);
95 Q_FOREACH(auto workspace, dpCpy) {
96 destroyWorkspace(workspace);
100Workspace *WorkspaceManager::activeWorkspace() const
102 return m_activeWorkspace;
105void WorkspaceManager::setActiveWorkspace(Workspace *workspace)
107 if (workspace != m_activeWorkspace) {
108 m_activeWorkspace = workspace;
109 Q_EMIT activeWorkspaceChanged();
keysesc to close
- j k
- move down, up
- enter
- open
- esc
- back, or up a level
- 1 2 3 4
- readme, files, commits, refs
- /
- filter
- y
- copy the clone command
- c
- compare the chosen commit with another (or shift-click both)
- ?
- show or hide this list