added load shortcuts.xml
This commit is contained in:
parent
eb79e735d7
commit
83ca802073
14 changed files with 285 additions and 15 deletions
|
@ -25,6 +25,8 @@ include(${CMAKE_CURRENT_LIST_DIR}/async/async.cmake)
|
|||
set(MODULE_SRC
|
||||
${MODULARITY_SRC}
|
||||
${ASYNC_SRC}
|
||||
${CMAKE_CURRENT_LIST_DIR}/globalmodule.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/globalmodule.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/log.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/dataformatter.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/dataformatter.h
|
||||
|
@ -35,6 +37,9 @@ set(MODULE_SRC
|
|||
${CMAKE_CURRENT_LIST_DIR}/version.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/stringutils.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/stringutils.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/iglobalconfiguration.h
|
||||
${CMAKE_CURRENT_LIST_DIR}/internal/globalconfiguration.cpp
|
||||
${CMAKE_CURRENT_LIST_DIR}/internal/globalconfiguration.h
|
||||
)
|
||||
|
||||
include(${PROJECT_SOURCE_DIR}/build/module.cmake)
|
||||
|
|
34
framework/global/globalmodule.cpp
Normal file
34
framework/global/globalmodule.cpp
Normal file
|
@ -0,0 +1,34 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 MuseScore BVBA and others
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#include "globalmodule.h"
|
||||
|
||||
#include "modularity/ioc.h"
|
||||
#include "internal/globalconfiguration.h"
|
||||
|
||||
using namespace mu::framework;
|
||||
|
||||
std::string GlobalModule::moduleName() const
|
||||
{
|
||||
return "global";
|
||||
}
|
||||
|
||||
void GlobalModule::registerExports()
|
||||
{
|
||||
framework::ioc()->registerExport<IGlobalConfiguration>(moduleName(), new GlobalConfiguration());
|
||||
}
|
38
framework/global/globalmodule.h
Normal file
38
framework/global/globalmodule.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 MuseScore BVBA and others
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_FRAMEWORK_GLOBALMODULE_H
|
||||
#define MU_FRAMEWORK_GLOBALMODULE_H
|
||||
|
||||
#include "modularity/imodulesetup.h"
|
||||
|
||||
namespace mu {
|
||||
namespace framework {
|
||||
class GlobalModule : public IModuleSetup
|
||||
{
|
||||
public:
|
||||
|
||||
std::string moduleName() const override;
|
||||
void registerExports() override;
|
||||
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MU_FRAMEWORK_GLOBALMODULE_H
|
38
framework/global/iglobalconfiguration.h
Normal file
38
framework/global/iglobalconfiguration.h
Normal file
|
@ -0,0 +1,38 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 MuseScore BVBA and others
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_FRAMEWORK_IGLOBALCONFIGURATION_H
|
||||
#define MU_FRAMEWORK_IGLOBALCONFIGURATION_H
|
||||
|
||||
#include "modularity/imoduleexport.h"
|
||||
|
||||
namespace mu {
|
||||
namespace framework {
|
||||
class IGlobalConfiguration : MODULE_EXPORT_INTERFACE
|
||||
{
|
||||
INTERFACE_ID(IGlobalConfiguration)
|
||||
public:
|
||||
|
||||
virtual ~IGlobalConfiguration() = default;
|
||||
|
||||
virtual std::string dataPath() const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
#endif // MU_FRAMEWORK_IGLOBALCONFIGURATION_H
|
33
framework/global/internal/globalconfiguration.cpp
Normal file
33
framework/global/internal/globalconfiguration.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 MuseScore BVBA and others
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#include "globalconfiguration.h"
|
||||
|
||||
#include <QString>
|
||||
#include <QStandardPaths>
|
||||
|
||||
using namespace mu::framework;
|
||||
|
||||
std::string GlobalConfiguration::dataPath() const
|
||||
{
|
||||
if (m_dataPath.empty()) {
|
||||
m_dataPath = QStandardPaths::writableLocation(QStandardPaths::DataLocation).toStdString();
|
||||
}
|
||||
|
||||
return m_dataPath;
|
||||
}
|
39
framework/global/internal/globalconfiguration.h
Normal file
39
framework/global/internal/globalconfiguration.h
Normal file
|
@ -0,0 +1,39 @@
|
|||
//=============================================================================
|
||||
// MuseScore
|
||||
// Music Composition & Notation
|
||||
//
|
||||
// Copyright (C) 2020 MuseScore BVBA and others
|
||||
//
|
||||
// This program is free software; you can redistribute it and/or modify
|
||||
// it under the terms of the GNU General Public License version 2.
|
||||
//
|
||||
// This program is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
// GNU General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU General Public License
|
||||
// along with this program; if not, write to the Free Software
|
||||
// Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
||||
//=============================================================================
|
||||
#ifndef MU_FRAMEWORK_GLOBALCONFIGURATION_H
|
||||
#define MU_FRAMEWORK_GLOBALCONFIGURATION_H
|
||||
|
||||
#include "../iglobalconfiguration.h"
|
||||
|
||||
namespace mu {
|
||||
namespace framework {
|
||||
class GlobalConfiguration : public IGlobalConfiguration
|
||||
{
|
||||
public:
|
||||
GlobalConfiguration() = default;
|
||||
|
||||
std::string dataPath() const override;
|
||||
|
||||
private:
|
||||
|
||||
mutable std::string m_dataPath;
|
||||
};
|
||||
}
|
||||
}
|
||||
#endif // MU_FRAMEWORK_GLOBALCONFIGURATION_H
|
|
@ -20,6 +20,7 @@
|
|||
#include "modulessetup.h"
|
||||
#include "config.h"
|
||||
|
||||
#include "framework/global/globalmodule.h"
|
||||
#include "framework/ui/uimodule.h"
|
||||
#include "framework/uicomponents/uicomponentsmodule.h"
|
||||
#include "framework/actions/actionsmodule.h"
|
||||
|
@ -70,6 +71,7 @@ ModulesSetup::ModulesSetup()
|
|||
#ifndef BUILD_UI_MU4
|
||||
<< new InspectorsSetup()
|
||||
#endif
|
||||
<< new mu::framework::GlobalModule()
|
||||
<< new mu::framework::UiModule()
|
||||
<< new mu::framework::UiComponentsModule()
|
||||
;
|
||||
|
|
|
@ -27,7 +27,7 @@ void ShortcutsController::activate(const std::string& sequence)
|
|||
{
|
||||
LOGD() << "activate: " << sequence;
|
||||
|
||||
std::vector<Shortcut> shortcuts = shortcutsRegister()->shortcutsForSequence(sequence);
|
||||
std::list<Shortcut> shortcuts = shortcutsRegister()->shortcutsForSequence(sequence);
|
||||
IF_ASSERT_FAILED(!shortcuts.empty()) {
|
||||
return;
|
||||
}
|
||||
|
@ -39,4 +39,7 @@ void ShortcutsController::activate(const std::string& sequence)
|
|||
}
|
||||
|
||||
//! NOTE One shortcut for several action
|
||||
for (const Shortcut& sc: shortcuts) {
|
||||
LOGI() << sc.action;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@ void ShortcutsInstanceModel::load()
|
|||
{
|
||||
m_shortcuts.clear();
|
||||
|
||||
const std::vector<Shortcut>& shortcuts = shortcutsRegister()->shortcuts();
|
||||
const std::list<Shortcut>& shortcuts = shortcutsRegister()->shortcuts();
|
||||
for (const Shortcut& sh : shortcuts) {
|
||||
QString sequence = QString::fromStdString(sh.sequence);
|
||||
|
||||
|
|
|
@ -18,22 +18,84 @@
|
|||
//=============================================================================
|
||||
#include "shortcutsregister.h"
|
||||
|
||||
#include <QFile>
|
||||
#include <QXmlStreamReader>
|
||||
|
||||
#include "log.h"
|
||||
|
||||
using namespace mu::shortcuts;
|
||||
|
||||
void ShortcutsRegister::load()
|
||||
{
|
||||
m_shortcuts.push_back(Shortcut { "1", "sample/1" });
|
||||
m_shortcuts.push_back(Shortcut { "2", "sample/2" });
|
||||
// m_shortcuts.push_back(Shortcut { "1", "sample/1" });
|
||||
// m_shortcuts.push_back(Shortcut { "2", "sample/2" });
|
||||
|
||||
m_shortcuts.clear();
|
||||
|
||||
std::string userPath = globalConfiguration()->dataPath() + "/shortcuts.xml";
|
||||
bool ok = loadFromFile(m_shortcuts, userPath);
|
||||
if (!ok) {
|
||||
ok = loadFromFile(m_shortcuts, ":/data/shortcuts.xml");
|
||||
}
|
||||
|
||||
if (!ok) {
|
||||
LOGE() << "Failed load shortcuts.xml";
|
||||
}
|
||||
}
|
||||
|
||||
const std::vector<Shortcut>& ShortcutsRegister::shortcuts() const
|
||||
bool ShortcutsRegister::loadFromFile(std::list<Shortcut>& shortcuts, const std::string& path) const
|
||||
{
|
||||
QFile f(QString::fromStdString(path));
|
||||
if (!f.exists()) {
|
||||
LOGE() << "Not exists shortcuts file: " << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!f.open(QIODevice::ReadOnly)) {
|
||||
LOGE() << "Cannot open shortcuts file: " << path;
|
||||
return false;
|
||||
}
|
||||
|
||||
QXmlStreamReader xml(&f);
|
||||
|
||||
while (xml.readNextStartElement()) {
|
||||
if (xml.name() == "Shortcuts") {
|
||||
while (xml.readNextStartElement()) {
|
||||
if (xml.name() == "SC") {
|
||||
Shortcut shortcut;
|
||||
while (xml.readNextStartElement()) {
|
||||
const QStringRef& tag(xml.name());
|
||||
if (tag == "key") {
|
||||
shortcut.action = xml.readElementText().toStdString();
|
||||
} else if (tag == "std") {
|
||||
shortcut.standartKey = QKeySequence::StandardKey(xml.readElementText().toInt());
|
||||
} else if (tag == "seq") {
|
||||
shortcut.sequence = xml.readElementText().toStdString();
|
||||
} else {
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
shortcuts.push_back(shortcut);
|
||||
} else {
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
} else {
|
||||
xml.skipCurrentElement();
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
const std::list<Shortcut>& ShortcutsRegister::shortcuts() const
|
||||
{
|
||||
return m_shortcuts;
|
||||
}
|
||||
|
||||
std::vector<Shortcut> ShortcutsRegister::shortcutsForSequence(const std::string& sequence) const
|
||||
std::list<Shortcut> ShortcutsRegister::shortcutsForSequence(const std::string& sequence) const
|
||||
{
|
||||
std::vector<Shortcut> list;
|
||||
std::list<Shortcut> list;
|
||||
for (const Shortcut& sh : m_shortcuts) {
|
||||
if (sh.sequence == sequence) {
|
||||
list.push_back(sh);
|
||||
|
|
|
@ -19,24 +19,31 @@
|
|||
#ifndef MU_SHORTCUTS_SHORTCUTSREGISTER_H
|
||||
#define MU_SHORTCUTS_SHORTCUTSREGISTER_H
|
||||
|
||||
#include <QString>
|
||||
|
||||
#include "../ishortcutsregister.h"
|
||||
#include "modularity/ioc.h"
|
||||
#include "iglobalconfiguration.h"
|
||||
|
||||
namespace mu {
|
||||
namespace shortcuts {
|
||||
class ShortcutsRegister : public IShortcutsRegister
|
||||
{
|
||||
INJECT(shortcut, framework::IGlobalConfiguration, globalConfiguration)
|
||||
public:
|
||||
|
||||
ShortcutsRegister() = default;
|
||||
|
||||
void load();
|
||||
|
||||
const std::vector<Shortcut>& shortcuts() const override;
|
||||
std::vector<Shortcut> shortcutsForSequence(const std::string& sequence) const override;
|
||||
const std::list<Shortcut>& shortcuts() const override;
|
||||
std::list<Shortcut> shortcutsForSequence(const std::string& sequence) const override;
|
||||
|
||||
private:
|
||||
|
||||
std::vector<Shortcut> m_shortcuts;
|
||||
bool loadFromFile(std::list<Shortcut>& shortcuts, const std::string& path) const;
|
||||
|
||||
std::list<Shortcut> m_shortcuts;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,6 +22,8 @@
|
|||
#include <string>
|
||||
|
||||
#include "modularity/imoduleexport.h"
|
||||
#include "shortcutstypes.h"
|
||||
#include "actions/action.h"
|
||||
|
||||
namespace mu {
|
||||
namespace shortcuts {
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#ifndef MU_SHORTCUTS_ISHORTCUTSREGISTER_H
|
||||
#define MU_SHORTCUTS_ISHORTCUTSREGISTER_H
|
||||
|
||||
#include <vector>
|
||||
#include <list>
|
||||
|
||||
#include "modularity/imoduleexport.h"
|
||||
#include "shortcutstypes.h"
|
||||
|
@ -32,8 +32,8 @@ class IShortcutsRegister : MODULE_EXPORT_INTERFACE
|
|||
public:
|
||||
virtual ~IShortcutsRegister() = default;
|
||||
|
||||
virtual const std::vector<Shortcut>& shortcuts() const = 0;
|
||||
virtual std::vector<Shortcut> shortcutsForSequence(const std::string& sequence) const = 0;
|
||||
virtual const std::list<Shortcut>& shortcuts() const = 0;
|
||||
virtual std::list<Shortcut> shortcutsForSequence(const std::string& sequence) const = 0;
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,14 +20,21 @@
|
|||
#define MU_SHORTCUTS_SHORTCUTSTYPES_H
|
||||
|
||||
#include <string>
|
||||
#include "actions/action.h"
|
||||
#include <QKeySequence>
|
||||
|
||||
namespace mu {
|
||||
namespace shortcuts {
|
||||
struct Shortcut
|
||||
{
|
||||
std::string action;
|
||||
std::string sequence;
|
||||
actions::ActionName action;
|
||||
QKeySequence::StandardKey standartKey;
|
||||
};
|
||||
|
||||
enum class ShortcutContext {
|
||||
Undefined = 0,
|
||||
NotationView,
|
||||
Playing
|
||||
};
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue