Line data Source code
1 : /*
2 : * SPDX-License-Identifier: GPL-3.0-only
3 : * MuseScore-Studio-CLA-applies
4 : *
5 : * MuseScore Studio
6 : * Music Composition & Notation
7 : *
8 : * Copyright (C) 2026 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 :
23 : #pragma once
24 :
25 : #include "icloseprojectscenario.h"
26 :
27 : #include <set>
28 :
29 : #include "modularity/ioc.h"
30 : #include "async/asyncable.h"
31 : #include "async/promise.h"
32 : #include "project/iprojectsession.h"
33 : #include "interactive/iinteractive.h"
34 : #include "rcommand/icommanddispatcher.h"
35 : #include "playback/iplaybackcontroller.h"
36 :
37 : #include "inotationproject.h"
38 : #include "isaveprojectscenario.h"
39 :
40 : namespace mu::project {
41 : class CloseProjectScenario : public ICloseProjectScenario, public muse::Contextable, public muse::async::Asyncable
42 : {
43 : public:
44 : muse::ContextInject<ISaveProjectScenario> saveProjectScenario = { this };
45 : muse::ContextInject<muse::rcommand::ICommandDispatcher> commandDispatcher = { this };
46 : muse::ContextInject<muse::IInteractive> interactive = { this };
47 : muse::ContextInject<project::IProjectSession> projectSession = { this };
48 : muse::ContextInject<playback::IPlaybackState> playbackState = { this };
49 :
50 13 : CloseProjectScenario(const muse::modularity::ContextPtr& iocCtx)
51 13 : : muse::Contextable(iocCtx) {}
52 :
53 : muse::async::Promise<muse::Ret> closeOpenedProject(bool goToHome = true) override;
54 :
55 : bool isBusy(BusyStatus status) const override;
56 : muse::async::Notification busyChanged() const override;
57 :
58 : private:
59 : static muse::async::Promise<muse::Ret> resolvedPromise(const muse::Ret& ret);
60 :
61 : INotationProjectPtr currentNotationProject() const;
62 :
63 : void setBusy(BusyStatus status, bool isBusy);
64 : muse::async::Promise<muse::Ret> runIfNotBusy(BusyStatus status, const std::function<muse::async::Promise<muse::Ret>()>& flow);
65 :
66 : muse::async::Promise<muse::IInteractive::Result> askAboutSavingScore(const INotationProjectPtr& project);
67 :
68 : //! NOTE Lets go of the score, and of everything that was opened for it
69 : muse::async::Promise<muse::Ret> doCloseProject(bool goToHome);
70 :
71 : void openHomePageIfNeed();
72 :
73 : std::set<BusyStatus> m_busyStatuses;
74 : muse::async::Notification m_busyChanged;
75 : };
76 : }
|