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) 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 : #include "extensionscommandsregister.h"
24 :
25 : #include "../extensionscommands.h"
26 :
27 : using namespace muse;
28 : using namespace muse::rcommand;
29 : using namespace muse::extensions;
30 :
31 : static const std::vector<CommandInfo> s_commandInfos = {
32 : CommandInfo{
33 : OPEN_APIDUMP_COMMAND,
34 : TranslatableString("extensions", "Show API dump"),
35 : TranslatableString("extensions", "Show API dump"),
36 : InputSchema(),
37 : Decoration(),
38 : Availability::Dispatch
39 : },
40 : };
41 :
42 0 : std::string ExtensionsCommandsRegister::moduleName() const
43 : {
44 0 : return "extensions";
45 : }
46 :
47 0 : void ExtensionsCommandsRegister::init()
48 : {
49 0 : extensionsRegister()->manifestListChanged().onNotify(this, [this]() {
50 0 : reload();
51 0 : });
52 :
53 0 : reload();
54 0 : }
55 :
56 0 : void ExtensionsCommandsRegister::reload()
57 : {
58 0 : m_commandInfos.clear();
59 0 : m_commands.clear();
60 :
61 0 : const auto manifests = extensionsRegister()->manifestList();
62 :
63 0 : m_commandInfos.reserve(manifests.size() + s_commandInfos.size());
64 0 : m_commandInfos.insert(m_commandInfos.end(), s_commandInfos.begin(), s_commandInfos.end());
65 :
66 0 : for (const auto& manifest : manifests) {
67 0 : for (const auto& action : manifest.actions) {
68 : CommandInfo info(
69 0 : makeCommand(manifest.uri, action.code),
70 0 : TranslatableString::untranslatable(action.title.empty() ? manifest.title : action.title),
71 0 : TranslatableString::untranslatable(manifest.description),
72 0 : InputSchema(),
73 0 : Decoration(action.icon)
74 0 : );
75 0 : m_commandInfos.push_back(std::move(info));
76 0 : }
77 : }
78 :
79 0 : m_commandListChanged.notify();
80 0 : }
81 :
82 0 : const std::vector<muse::rcommand::Command>& ExtensionsCommandsRegister::commandList() const
83 : {
84 0 : if (m_commands.empty()) {
85 0 : m_commands.reserve(m_commandInfos.size());
86 0 : for (const auto& info : m_commandInfos) {
87 0 : m_commands.push_back(info.command);
88 : }
89 : }
90 0 : return m_commands;
91 : }
92 :
93 0 : const std::vector<CommandInfo>& ExtensionsCommandsRegister::commandInfoList() const
94 : {
95 0 : return m_commandInfos;
96 : }
97 :
98 0 : async::Notification ExtensionsCommandsRegister::commandListChanged() const
99 : {
100 0 : return m_commandListChanged;
101 : }
|