shortcut template
This commit is contained in:
parent
136f68fcd4
commit
cf18d82356
4 changed files with 59 additions and 39 deletions
|
@ -173,6 +173,9 @@ public:
|
|||
const QString &offText);
|
||||
|
||||
std::string getIdFromAction(QAction *action);
|
||||
|
||||
// load user defined shortcuts
|
||||
void loadShortcuts();
|
||||
};
|
||||
|
||||
//-----------------------------------------------------------------------------
|
||||
|
|
|
@ -522,8 +522,8 @@ int main(int argc, char *argv[]) {
|
|||
|
||||
loadShaderInterfaces(ToonzFolder::getLibraryFolder() + TFilePath("shaders"));
|
||||
|
||||
splash.showMessage(offsetStr + "Initializing OpenToonz ...",
|
||||
Qt::AlignCenter, Qt::white);
|
||||
splash.showMessage(offsetStr + "Initializing OpenToonz ...", Qt::AlignCenter,
|
||||
Qt::white);
|
||||
a.processEvents();
|
||||
|
||||
TTool::setApplication(TApp::instance());
|
||||
|
|
|
@ -380,6 +380,8 @@ MainWindow::MainWindow(const QString &argumentLayoutFileName, QWidget *parent,
|
|||
m_toolsActionGroup->setExclusive(true);
|
||||
m_currentRoomsChoice = Preferences::instance()->getCurrentRoomChoice();
|
||||
defineActions();
|
||||
// user defined shortcuts will be loaded here
|
||||
CommandManager::instance()->loadShortcuts();
|
||||
TApp::instance()->getCurrentScene()->setDirtyFlag(false);
|
||||
|
||||
// La menuBar altro non è che una toolbar
|
||||
|
@ -2357,9 +2359,9 @@ RecentFiles::~RecentFiles() {}
|
|||
|
||||
void RecentFiles::addFilePath(QString path, FileType fileType) {
|
||||
QList<QString> files =
|
||||
(fileType == Scene) ? m_recentScenes : (fileType == Level)
|
||||
? m_recentLevels
|
||||
: m_recentFlipbookImages;
|
||||
(fileType == Scene)
|
||||
? m_recentScenes
|
||||
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
|
||||
int i;
|
||||
for (i = 0; i < files.size(); i++)
|
||||
if (files.at(i) == path) files.removeAt(i);
|
||||
|
@ -2484,9 +2486,9 @@ void RecentFiles::saveRecentFiles() {
|
|||
|
||||
QList<QString> RecentFiles::getFilesNameList(FileType fileType) {
|
||||
QList<QString> files =
|
||||
(fileType == Scene) ? m_recentScenes : (fileType == Level)
|
||||
? m_recentLevels
|
||||
: m_recentFlipbookImages;
|
||||
(fileType == Scene)
|
||||
? m_recentScenes
|
||||
: (fileType == Level) ? m_recentLevels : m_recentFlipbookImages;
|
||||
QList<QString> names;
|
||||
int i;
|
||||
for (i = 0; i < files.size(); i++) {
|
||||
|
@ -2513,9 +2515,9 @@ void RecentFiles::refreshRecentFilesMenu(FileType fileType) {
|
|||
menu->setEnabled(false);
|
||||
else {
|
||||
CommandId clearActionId =
|
||||
(fileType == Scene) ? MI_ClearRecentScene : (fileType == Level)
|
||||
? MI_ClearRecentLevel
|
||||
: MI_ClearRecentImage;
|
||||
(fileType == Scene)
|
||||
? MI_ClearRecentScene
|
||||
: (fileType == Level) ? MI_ClearRecentLevel : MI_ClearRecentImage;
|
||||
menu->setActions(names);
|
||||
menu->addSeparator();
|
||||
QAction *clearAction = CommandManager::instance()->getAction(clearActionId);
|
||||
|
|
|
@ -5,6 +5,7 @@
|
|||
#include "toonzqt/dvdialog.h"
|
||||
#include "toonzqt/gutil.h"
|
||||
#include "toonz/toonzfolders.h"
|
||||
#include "tsystem.h"
|
||||
#include <assert.h>
|
||||
#include <QObject>
|
||||
#include <QAction>
|
||||
|
@ -130,36 +131,12 @@ void CommandManager::define(CommandId id, CommandType type,
|
|||
|
||||
m_qactionTable[qaction] = node;
|
||||
qaction->setShortcutContext(Qt::ApplicationShortcut);
|
||||
|
||||
TFilePath fp = ToonzFolder::getModuleFile("shortcuts.ini");
|
||||
QSettings settings(toQString(fp), QSettings::IniFormat);
|
||||
settings.beginGroup("shortcuts");
|
||||
// user defined shortcuts will be loaded afterwards in loadShortcuts()
|
||||
QString defaultShortcutQString =
|
||||
QString::fromStdString(defaultShortcutString);
|
||||
/*-
|
||||
Some shortcuts may just removed from the default settings.
|
||||
So you need to distinguish between "shortcut is not defined by user"
|
||||
and "shortcut is removed (i.e. defined as "") by user".
|
||||
-*/
|
||||
QString shortcutString = settings.value(id, "undefined").toString();
|
||||
settings.endGroup();
|
||||
|
||||
if (shortcutString != "" && shortcutString != "undefined") {
|
||||
// User-defined shortcuts. It may have been assigned as a shortcut by
|
||||
// default to some other command
|
||||
QAction *other = getActionFromShortcut(shortcutString.toStdString());
|
||||
if (other) other->setShortcut(QKeySequence());
|
||||
} else if (defaultShortcutQString != "" && shortcutString == "undefined") {
|
||||
// Shortcut key set by default. Check if the key already been assigned to
|
||||
// another action
|
||||
QAction *other =
|
||||
getActionFromShortcut(defaultShortcutQString.toStdString());
|
||||
if (!other) shortcutString = defaultShortcutQString;
|
||||
}
|
||||
|
||||
if (shortcutString != "" && shortcutString != "undefined") {
|
||||
qaction->setShortcut(QKeySequence(shortcutString));
|
||||
m_shortcutTable[shortcutString.toStdString()] = node;
|
||||
if (!defaultShortcutQString.isEmpty()) {
|
||||
qaction->setShortcut(QKeySequence(defaultShortcutQString));
|
||||
m_shortcutTable[defaultShortcutString] = node;
|
||||
}
|
||||
|
||||
if (type == ToolCommandType) updateToolTip(qaction);
|
||||
|
@ -407,6 +384,44 @@ std::string CommandManager::getIdFromAction(QAction *action) {
|
|||
return "";
|
||||
}
|
||||
|
||||
//---------------------------------------------------------
|
||||
// load user defined shortcuts
|
||||
|
||||
void CommandManager::loadShortcuts() {
|
||||
TFilePath fp = ToonzFolder::getMyModuleDir() + TFilePath("shortcuts.ini");
|
||||
if (!TFileStatus(fp).doesExist()) {
|
||||
// if user shortcut file does not exist, then try to load from template
|
||||
TFilePath tmplFp =
|
||||
ToonzFolder::getTemplateModuleDir() + TFilePath("shortcuts.ini");
|
||||
if (TFileStatus(tmplFp).doesExist()) TSystem::copyFile(fp, tmplFp);
|
||||
// if neither settings exist, do nothing and return
|
||||
else
|
||||
return;
|
||||
}
|
||||
|
||||
QSettings settings(toQString(fp), QSettings::IniFormat);
|
||||
settings.beginGroup("shortcuts");
|
||||
QStringList ids = settings.allKeys();
|
||||
for (int i = 0; i < ids.size(); i++) {
|
||||
std::string id = ids.at(i).toStdString();
|
||||
QString shortcut = settings.value(ids.at(i), "").toString();
|
||||
QAction *action = getAction(&id[0], false);
|
||||
if (action) {
|
||||
QString oldShortcut = action->shortcut().toString();
|
||||
if (oldShortcut == shortcut) continue;
|
||||
if (!oldShortcut.isEmpty())
|
||||
m_shortcutTable.erase(oldShortcut.toStdString());
|
||||
if (!shortcut.isEmpty()) {
|
||||
QAction *other = getActionFromShortcut(shortcut.toStdString());
|
||||
if (other) other->setShortcut(QKeySequence());
|
||||
m_shortcutTable[shortcut.toStdString()] = getNode(&id[0]);
|
||||
}
|
||||
action->setShortcut(QKeySequence(shortcut));
|
||||
}
|
||||
}
|
||||
settings.endGroup();
|
||||
}
|
||||
|
||||
/*
|
||||
//---------------------------------------------------------
|
||||
|
||||
|
|
Loading…
Reference in a new issue