LCOV - code coverage report
Current view: top level - muse/framework/shortcuts_v2/internal - commandshortcutsregister.h Coverage Total Hit
Test: filtered_coverage.info Lines: 100.0 % 2 2
Test Date: 2026-11-05 04:07:02

            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) 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              : #pragma once
      23              : 
      24              : #include <unordered_map>
      25              : 
      26              : #include "../icommandshortcutsregister.h"
      27              : 
      28              : #include "global/async/asyncable.h"
      29              : 
      30              : #include "modularity/ioc.h"
      31              : #include "ishortcutsconfiguration.h"
      32              : #include "rcommand/commandtypes.h"
      33              : #include "rcommand/icommandsregister.h"
      34              : #include "multiwindows/imultiwindowsprovider.h"
      35              : 
      36              : namespace muse::shortcuts {
      37              : class CommandShortcutsRegister : public ICommandShortcutsRegister, public async::Asyncable
      38              : {
      39              :     GlobalInject<IShortcutsConfiguration> configuration;
      40              :     GlobalInject<mi::IMultiWindowsProvider> multiwindowsProvider;
      41              :     GlobalInject<rcommand::ICommandsRegister> commandsRegister;
      42              : 
      43              : public:
      44           15 :     CommandShortcutsRegister() = default;
      45           30 :     ~CommandShortcutsRegister() override = default;
      46              : 
      47              :     void init();
      48              : 
      49              :     const ShortcutList& shortcuts() const override;
      50              :     Ret updateShortcuts(const ShortcutList& shortcuts) override;
      51              :     void resetShortcuts() override;
      52              :     async::Notification shortcutsChanged() const override;
      53              : 
      54              :     Ret setAdditionalShortcuts(const std::string& context, const ShortcutList& shortcuts) override;
      55              : 
      56              :     ShortcutList shortcutsForSequence(const std::string& sequence) const override;
      57              :     const Shortcut& shortcut(const rcommand::Command& command) const override;
      58              :     const Shortcut& defaultShortcut(const rcommand::Command& command) const override;
      59              : 
      60              :     Ret importFromFile(const io::path_t& filePath) override;
      61              :     Ret exportToFile(const io::path_t& filePath) const override;
      62              : 
      63              :     std::vector<std::string> availablePresets() const override;
      64              : 
      65              :     std::string currentPresetName() const override;
      66              :     void setCurrentPresetName(const std::string& presetName) override;
      67              :     async::Channel<std::string> currentPresetNameChanged() const override;
      68              : 
      69              :     bool isPresetEdited(const std::string& presetName) const override;
      70              :     bool canDeletePreset(const std::string& presetName) const override;
      71              :     void deletePreset(const std::string& presetName) override;
      72              : 
      73              :     // for testflow tests
      74              :     void reload(bool onlyDef = false) override;
      75              : 
      76              : private:
      77              : 
      78              :     std::string activeShortcutsName() const;
      79              :     io::path_t userShortcutsPath() const;
      80              : 
      81              :     std::string makeScope(const rcommand::Command& command) const;
      82              : 
      83              :     void applyShortcutsDiff(const std::string& shortcutsName, ShortcutList& shortcuts) const;
      84              :     ShortcutList makeDiff(const ShortcutList& shortcuts, const ShortcutList& defaultShortcuts) const;
      85              : 
      86              :     bool removeUserFile();
      87              : 
      88              :     bool readFromFile(ShortcutList& shortcuts, const io::path_t& path) const;
      89              :     bool writeToFile(const ShortcutList& shortcuts, const io::path_t& path) const;
      90              : 
      91              :     void mergeShortcuts(ShortcutList& shortcuts, const ShortcutList& defaultShortcuts) const;
      92              :     void mergeAdditionalShortcuts(ShortcutList& shortcuts);
      93              : 
      94              :     void removeNotAvailableCommands(ShortcutList& shortcuts);
      95              :     void makeUnique(ShortcutList& shortcuts);
      96              : 
      97              :     ShortcutList filterAndUpdateAdditionalShortcuts(const ShortcutList& shortcuts);
      98              : 
      99              :     ShortcutList m_shortcuts;
     100              :     ShortcutList m_defaultShortcuts;
     101              :     std::unordered_map<std::string, ShortcutList> m_additionalShortcutsMap;
     102              :     async::Notification m_shortcutsChanged;
     103              : };
     104              : }
        

Generated by: LCOV version 2.0-1