Commit e1d0a836 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fixed multiple shortcuts bugs

1) Standard actions, like Copy/Paste are now propertized as well.
   Otherwise, their custom shortcuts were never used.

2) ActionInfoItem now has a special field showing that the action
   is explicitly reset to null. This way we will not break it
   accidentally, when refactoring empty strings in the future
   (like it happened this time).

3) Split up KisActionRegistry and KisActionsSnapshot. The former
   is a singleton and used for propertizing the actions, but the
   latter one is just a snapshot used for filling up the settings
   dialog.

BUG:373184,372198
parent 327138fe
......@@ -107,20 +107,6 @@ public:
void loadActions();
};
// Basically, we are going to insert the current UI/MainWindow ActionCollection
// into the KisActionRegistry.
void KisPart::loadActions()
{
d->actionCollection = currentMainwindow()->viewManager()->actionCollection();
KisActionRegistry * actionRegistry = KisActionRegistry::instance();
Q_FOREACH (auto action, d->actionCollection->actions()) {
auto name = action->objectName();
actionRegistry->addAction(action->objectName(), action);
}
};
KisPart* KisPart::instance()
{
return s_instance;
......
......@@ -133,11 +133,6 @@ public:
*/
KisMainWindow *currentMainwindow() const;
/**
* Load actions for currently active main window into KisActionRegistry.
*/
void loadActions();
/**
* @return the application-wide KisIdleWatcher.
*/
......
......@@ -262,6 +262,9 @@ void GeneralTab::clearBackgroundImage()
m_backgroundimage->setText("");
}
#include "kactioncollection.h"
#include "KisActionsSnapshot.h"
ShortcutSettingsTab::ShortcutSettingsTab(QWidget *parent, const char *name)
: QWidget(parent)
{
......@@ -272,8 +275,26 @@ ShortcutSettingsTab::ShortcutSettingsTab(QWidget *parent, const char *name)
m_page = new WdgShortcutSettings(this);
l->addWidget(m_page, 0, 0);
KisPart::instance()->loadActions();
KisActionRegistry::instance()->setupDialog(m_page);
m_snapshot.reset(new KisActionsSnapshot);
KActionCollection *collection =
KisPart::instance()->currentMainwindow()->actionCollection();
Q_FOREACH (QAction *action, collection->actions()) {
m_snapshot->addAction(action->objectName(), action);
}
QMap<QString, KActionCollection*> sortedCollections =
m_snapshot->actionCollections();
for (auto it = sortedCollections.constBegin(); it != sortedCollections.constEnd(); ++it) {
m_page->addCollection(it.value(), it.key());
}
}
ShortcutSettingsTab::~ShortcutSettingsTab()
{
}
void ShortcutSettingsTab::setDefault()
......
......@@ -105,6 +105,8 @@ public:
{ }
};
class KisActionsSnapshot;
class ShortcutSettingsTab : public QWidget
{
Q_OBJECT
......@@ -112,10 +114,12 @@ class ShortcutSettingsTab : public QWidget
public:
ShortcutSettingsTab(QWidget *parent = 0, const char *name = 0);
~ShortcutSettingsTab();
public:
void setDefault();
WdgShortcutSettings *m_page;
QScopedPointer<KisActionsSnapshot> m_snapshot;
public Q_SLOTS:
......
......@@ -62,18 +62,6 @@ KisAction::~KisAction()
delete d;
}
KisAction *makeKisAction(QString name, QObject *parent)
{
KisAction* a = new KisAction(parent);
KisActionRegistry::instance()->propertizeAction(name, a);
KisActionRegistry::instance()->addAction(name, a);
// TODO: Add other static data (activationFlags, etc.) using getActionXml()
return a;
}
// Using a dynamic QObject property is done for compatibility with KAction and
// XmlGui. We may merge KisAction into the XmlGui code to make this unnecessary,
// but that is probably a lot of work for little benefit. We currently store a
......
......@@ -84,11 +84,6 @@ public:
KisAction(const QIcon& icon, const QString& text, QObject* parent = 0);
virtual ~KisAction();
/**
* Produces a new KisAction based on .action data files.
*/
static KisAction *makeKisAction(QString name, QObject *parent);
void setDefaultShortcut(const QKeySequence & shortcut);
QKeySequence defaultShortcut() const;
......
......@@ -129,12 +129,10 @@ void KisActionManager::addAction(const QString& name, KisAction* action)
Q_ASSERT(d->viewManager->actionCollection());
d->viewManager->actionCollection()->addAction(name, action);
action->setObjectName(name);
action->setParent(d->viewManager->actionCollection());
d->viewManager->actionCollection()->setDefaultShortcut(action, action->defaultShortcut());
d->actions.append(action);
action->setActionManager(this);
KisActionRegistry::instance()->addAction(name, action);
}
void KisActionManager::takeAction(KisAction* action)
......@@ -170,11 +168,10 @@ KisAction *KisActionManager::createAction(const QString &name)
// will add them to the KisActionRegistry for the time being so we can get
// properly categorized shortcuts.
a = new KisAction();
auto actionRegistry = KisActionRegistry::instance();
KisActionRegistry *actionRegistry = KisActionRegistry::instance();
// Add extra properties
actionRegistry->propertizeAction(name, a);
actionRegistry->addAction(name, a);
bool ok; // We will skip this check
int activationFlags = actionRegistry->getActionProperty(name, "activationFlags").toInt(&ok, 2);
int activationConditions = actionRegistry->getActionProperty(name, "activationConditions").toInt(&ok, 2);
......@@ -354,6 +351,9 @@ KisAction *KisActionManager::createStandardAction(KStandardAction::StandardActio
}
}
KisActionRegistry *actionRegistry = KisActionRegistry::instance();
actionRegistry->propertizeAction(standardAction->objectName(), action);
addAction(standardAction->objectName(), action);
delete standardAction;
return action;
......
......@@ -11,6 +11,7 @@ set(kritawidgetutils_LIB_SRCS
kis_icon_utils.cpp
kis_action_registry.cpp
KisActionsSnapshot.cpp
KoGroupButton.cpp
KoProgressBar.cpp
KoProgressUpdater.cpp
......
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#include "KisActionsSnapshot.h"
#include "kis_action_registry.h"
#include "kactioncollection.h"
#include "kis_debug.h"
struct KisActionsSnapshot::Private
{
QMap<QString, KActionCollection*> actionCollections;
~Private() {
qDeleteAll(actionCollections);
}
};
KisActionsSnapshot::KisActionsSnapshot()
: m_d(new Private)
{
}
KisActionsSnapshot::~KisActionsSnapshot()
{
}
void KisActionsSnapshot::addAction(const QString &name, QAction *action)
{
KisActionRegistry::ActionCategory cat = KisActionRegistry::instance()->fetchActionCategory(name);
if (!cat.isValid()) {
warnKrita << "WARNING: Uncategorized action" << name << "Dropping...";
return;
}
KActionCollection *collection = m_d->actionCollections[cat.componentName];
if (!collection) {
collection = new KActionCollection(0, cat.componentName);
m_d->actionCollections.insert(cat.componentName, collection);
}
collection->addCategorizedAction(name, action, cat.categoryName);
}
QMap<QString, KActionCollection *> KisActionsSnapshot::actionCollections() const
{
return m_d->actionCollections;
}
/*
* Copyright (c) 2016 Dmitry Kazakov <dimula73@gmail.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* 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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KISACTIONSSNAPSHOT_H
#define KISACTIONSSNAPSHOT_H
#include <kritawidgetutils_export.h>
#include <QScopedPointer>
#include <QMap>
class QAction;
class KActionCollection;
class KRITAWIDGETUTILS_EXPORT KisActionsSnapshot
{
public:
KisActionsSnapshot();
~KisActionsSnapshot();
/**
* @brief registers the action in the snapshot and sorts it into a proper
* category. The action is *not* owned by the snapshot.
*
* @param name id string of the action
* @param action the action itself
*/
void addAction(const QString &name, QAction *action);
/**
* Returns all action collections of the current snapshot
*
* WARNING: the collections are owned by the shapshot! Don't destroy
* the snapshot before you are done with the collections!
*/
QMap<QString, KActionCollection*> actionCollections() const;
private:
struct Private;
const QScopedPointer<Private> m_d;
};
#endif // KISACTIONSSNAPSHOT_H
This diff is collapsed.
......@@ -87,12 +87,6 @@ public:
bool propertizeAction(const QString &name, QAction *a);
/**
* Setup the shortcut configuration widget.
*/
void setupDialog(KisShortcutsDialog *dlg);
/**
* Called when "OK" button is pressed in settings dialog.
*/
......@@ -102,7 +96,7 @@ public:
/**
* Reload custom shortcuts from kritashortcutsrc
*/
void loadCustomShortcuts(const QString &path = QString());
void loadCustomShortcuts();
/**
* Call after settings are changed.
......@@ -112,6 +106,20 @@ public:
// If config == 0, reload defaults
void applyShortcutScheme(const KConfigBase *config = 0);
struct ActionCategory {
ActionCategory();
ActionCategory(const QString &_componentName, const QString &_categoryName);
QString componentName;
QString categoryName;
bool isValid() const;
private:
bool m_isValid = false;
};
ActionCategory fetchActionCategory(const QString &name) const;
/**
* Constructor. Please don't touch!
*/
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment