Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2021 MuseScore Limited and others
9 : *
10 : * This program is free software: you can redistribute it and/or modify
11 : * it under the terms of the GNU General Public License version 3 as
12 : * published by the Free Software Foundation.
13 : *
14 : * This program is distributed in the hope that it will be useful,
15 : * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 : * GNU General Public License for more details.
18 : *
19 : * You should have received a copy of the GNU General Public License
20 : * along with this program. If not, see <https://www.gnu.org/licenses/>.
21 : */
22 : #ifndef MUSE_WORKSPACE_WORKSPACEMANAGER_H
23 : #define MUSE_WORKSPACE_WORKSPACEMANAGER_H
24 :
25 : #include "async/asyncable.h"
26 :
27 : #include "modularity/ioc.h"
28 : #include "io/ifilesystem.h"
29 : #include "interactive/iinteractive.h"
30 : #include "../iworkspaceconfiguration.h"
31 :
32 : #include "workspace.h"
33 :
34 : #include "iworkspacemanager.h"
35 :
36 : namespace muse::workspace {
37 : class WorkspaceManager : public IWorkspaceManager, public Contextable, public async::Asyncable
38 : {
39 : GlobalInject<io::IFileSystem> fileSystem;
40 : GlobalInject<IWorkspaceConfiguration> configuration;
41 : ContextInject<IInteractive> interactive = { this };
42 :
43 : public:
44 :
45 3 : WorkspaceManager(const modularity::ContextPtr& iocCtx)
46 3 : : Contextable(iocCtx) {}
47 :
48 : void init();
49 : void deinit();
50 : bool isInited() const;
51 :
52 : IWorkspacePtr defaultWorkspace() const override;
53 :
54 : IWorkspacePtr currentWorkspace() const override;
55 : async::Notification currentWorkspaceAboutToBeChanged() const override;
56 : async::Notification currentWorkspaceChanged() const override;
57 :
58 : IWorkspacePtrList workspaces() const override;
59 : Ret setWorkspaces(const IWorkspacePtrList& workspaces) override;
60 : async::Notification workspacesListChanged() const override;
61 :
62 : IWorkspacePtr cloneWorkspace(const IWorkspacePtr& workspace, const std::string& newWorkspaceName) const override;
63 :
64 : void changeCurrentWorkspace(const std::string& newWorkspaceName) override;
65 : void createAndAppendNewWorkspace() override;
66 : void openConfigureWorkspacesDialog() override;
67 :
68 : private:
69 : void load();
70 : void reloadWorkspaceFiles();
71 :
72 : io::paths_t findWorkspaceFiles() const;
73 :
74 : WorkspacePtr doNewWorkspace(const std::string& workspaceName) const;
75 : io::path_t makeNewWorkspacePath(const std::string& workspaceName) const;
76 :
77 : void doChangeCurrentWorkspace(const std::string& newWorkspaceName);
78 :
79 : void appendNewWorkspace(WorkspacePtr workspace);
80 : void setupConnectionsToNewWorkspace(const IWorkspacePtr workspace);
81 :
82 : void setupDefaultWorkspace();
83 : void setupCurrentWorkspace();
84 : void saveCurrentWorkspace();
85 : void prepareCurrentWorkspaceForChange();
86 :
87 : Ret removeMissingWorkspaces(const IWorkspacePtrList& newWorkspaceList);
88 : Ret removeWorkspace(const IWorkspacePtr& workspace);
89 : bool canRemoveWorkspace(const IWorkspacePtr& workspace) const;
90 :
91 : Ret addNonExistentWorkspaces(const IWorkspacePtrList& newWorkspaceList);
92 : Ret addWorkspace(IWorkspacePtr workspace);
93 :
94 : WorkspacePtr findByName(const std::string& name) const;
95 : WorkspacePtr findAndInit(const std::string& name) const;
96 :
97 : WorkspacePtr m_defaultWorkspace;
98 : WorkspacePtr m_currentWorkspace;
99 : async::Notification m_currentWorkspaceAboutToBeChanged;
100 : async::Notification m_currentWorkspaceChanged;
101 :
102 : std::vector<WorkspacePtr> m_workspaces;
103 : async::Notification m_workspacesListChanged;
104 : };
105 : }
106 :
107 : #endif // MUSE_WORKSPACE_WORKSPACEMANAGER_H
|