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 : #include "shortcutsmodule.h"
23 :
24 : #include "modularity/ioc.h"
25 :
26 : #include "internal/commandshortcutsregister.h"
27 : #include "internal/shortcutscontroller.h"
28 : #include "internal/shortcutsconfiguration.h"
29 : #include "internal/shortcutsresolver.h"
30 :
31 : #include "global/api/iapiregister.h"
32 : #include "api/shortcutsapi.h"
33 :
34 : #include "muse_framework_config.h"
35 :
36 : #ifdef MUSE_MODULE_DIAGNOSTICS
37 : #include "diagnostics/idiagnosticspathsregister.h"
38 : #endif
39 :
40 : using namespace muse::shortcuts;
41 : using namespace muse::modularity;
42 : using namespace muse::ui;
43 :
44 : static const std::string mname("shortcuts");
45 :
46 0 : std::string ShortcutsModule::moduleName() const
47 : {
48 0 : return mname;
49 : }
50 :
51 0 : void ShortcutsModule::registerExports()
52 : {
53 0 : m_configuration = std::make_shared<ShortcutsConfiguration>(globalCtx());
54 0 : m_commandShortcutsRegister = std::make_shared<CommandShortcutsRegister>();
55 :
56 0 : globalIoc()->registerExport<IShortcutsConfiguration>(mname, m_configuration);
57 0 : globalIoc()->registerExport<ICommandShortcutsRegister>(mname, m_commandShortcutsRegister);
58 0 : }
59 :
60 0 : void ShortcutsModule::registerApi()
61 : {
62 : using namespace muse::api;
63 :
64 0 : auto api = globalIoc()->resolve<IApiRegister>(mname);
65 0 : if (api) {
66 0 : api->regApiCreator(mname, "MuseInternal.Shortcuts", new ApiCreator<api::ShortcutsApi>());
67 : }
68 0 : }
69 :
70 0 : void ShortcutsModule::onInit(const IApplication::RunMode&)
71 : {
72 0 : m_configuration->init();
73 0 : m_commandShortcutsRegister->init();
74 :
75 : #ifdef MUSE_MODULE_DIAGNOSTICS
76 0 : auto pr = globalIoc()->resolve<muse::diagnostics::IDiagnosticsPathsRegister>(mname);
77 0 : if (pr) {
78 0 : pr->reg("shortcutsUserAppDataPath", m_configuration->shortcutsUserAppDataPath());
79 0 : pr->reg("shortcutsAppDataPath", m_configuration->shortcutsAppDataPath());
80 : }
81 : #endif
82 0 : }
83 :
84 0 : IContextSetup* ShortcutsModule::newContext(const modularity::ContextPtr& ctx) const
85 : {
86 0 : return new ShortcutsContext(ctx);
87 : }
88 :
89 0 : void ShortcutsContext::registerExports()
90 : {
91 0 : m_shortcutsController = std::make_shared<ShortcutsController>(iocContext());
92 :
93 0 : ioc()->registerExport<IShortcutsController>(mname, m_shortcutsController);
94 0 : ioc()->registerExport<IShortcutsResolver>(mname, std::make_shared<ShortcutsResolver>());
95 0 : }
96 :
97 0 : void ShortcutsContext::onInit(const IApplication::RunMode&)
98 : {
99 0 : m_shortcutsController->init();
100 0 : }
|