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) 2024 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 "extensionstoolbarmodel.h"
23 :
24 : #include "extensionscommands.h"
25 : #include "uicomponents/qml/Muse/UiComponents/toolbaritem.h"
26 :
27 : using namespace muse::extensions;
28 : using namespace muse::uicomponents;
29 :
30 0 : void ExtensionsToolBarModel::load()
31 : {
32 0 : extensionsRegister()->manifestListChanged().onNotify(this, [this]() {
33 0 : load();
34 0 : }, async::Asyncable::Mode::SetReplace);
35 :
36 0 : extensionsRegister()->enabledChanged().onReceive(this, [this](const Uri&) {
37 0 : load();
38 0 : }, async::Asyncable::Mode::SetReplace);
39 :
40 0 : ToolBarItemList items;
41 0 : ManifestList manifests = extensionsRegister()->manifestList(Filter::Enabled);
42 0 : for (const Manifest& m : manifests) {
43 0 : for (const muse::extensions::Action& a : m.actions) {
44 0 : if (!a.showOnToolbar) {
45 0 : continue;
46 : }
47 :
48 0 : ToolBarItem* item = new ToolBarItem(this);
49 0 : item->setTitle(!a.title.empty()
50 0 : ? TranslatableString::untranslatable(a.title)
51 0 : : TranslatableString::untranslatable(m.title));
52 :
53 0 : item->setCommand(makeCommand(m.uri, a.code));
54 :
55 0 : items << item;
56 : }
57 : }
58 :
59 0 : setItems(items);
60 :
61 0 : AbstractToolBarModel::load();
62 0 : }
|