Commit 413c1900 authored by Dmitry Kazakov's avatar Dmitry Kazakov
Browse files

Added a sanity check for actions, fixed composition actions

To enable sanity check, uncomment the corresponding define in
KisActionsSnapshot.cpp
parent f85b84fe
......@@ -189,6 +189,18 @@
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
<Action name="update_composition">
<icon></icon>
<text>Update Composition</text>
<whatsThis></whatsThis>
<toolTip>Update Composition</toolTip>
<iconText>Update Composition</iconText>
<activationFlags>0</activationFlags>
<activationConditions>0</activationConditions>
<shortcut></shortcut>
<isCheckable>false</isCheckable>
<statusTip></statusTip>
</Action>
</Actions>
<Actions category="Painting">
......
......@@ -19,10 +19,12 @@
#include "KisActionsSnapshot.h"
#include "kis_action_registry.h"
#include "kactioncollection.h"
#include "./kactioncollection.h"
#include "kis_debug.h"
//#define ACTIONS_CHECKSUM_SANITY_CHECK
struct KisActionsSnapshot::Private
{
......@@ -52,6 +54,12 @@ void KisActionsSnapshot::addAction(const QString &name, QAction *action)
return;
}
#ifdef ACTIONS_CHECKSUM_SANITY_CHECK
if (!KisActionRegistry::instance()->sanityCheckPropertized(action->objectName())) {
warnKrita << "WARNING: action" << name << "was not propertized!" << ppVar(action->property("isShortcutConfigurable").toBool());
}
#endif /* ACTIONS_CHECKSUM_SANITY_CHECK */
KActionCollection *collection = m_d->actionCollections[cat.componentName];
if (!collection) {
......
......@@ -125,6 +125,7 @@ public:
}
KisActionRegistry *q;
QSet<QString> sanityPropertizedShortcuts;
};
......@@ -228,6 +229,13 @@ void KisActionRegistry::updateShortcut(const QString &name, QAction *action)
action->setShortcuts(info.effectiveShortcuts());
action->setProperty("defaultShortcuts", qVariantFromValue(info.defaultShortcuts()));
d->sanityPropertizedShortcuts.insert(name);
}
bool KisActionRegistry::sanityCheckPropertized(const QString &name)
{
return d->sanityPropertizedShortcuts.contains(name);
}
bool KisActionRegistry::propertizeAction(const QString &name, QAction * a)
......
......@@ -16,6 +16,8 @@
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/
#ifndef KIS_ACTION_REGISTRY_H
#define KIS_ACTION_REGISTRY_H
#include <QString>
#include <QKeySequence>
......@@ -135,6 +137,8 @@ public:
// Undocumented
void updateShortcut(const QString &name, QAction *ac);
bool sanityCheckPropertized(const QString &name);
Q_SIGNALS:
void shortcutsUpdated();
......@@ -143,3 +147,5 @@ private:
class Private;
Private * const d;
};
#endif /* KIS_ACTION_REGISTRY_H */
......@@ -68,6 +68,7 @@ AnimationDocker::AnimationDocker()
m_animationWidget->setupUi(mainWidget);
// TODO: create all the actions using action manager!
m_previousFrameAction = new KisAction(i18n("Previous Frame"), m_animationWidget->btnPreviousFrame);
m_previousFrameAction->setActivationFlags(KisAction::ACTIVE_IMAGE);
m_animationWidget->btnPreviousFrame->setDefaultAction(m_previousFrameAction);
......
......@@ -44,6 +44,7 @@
#include <kis_paint_layer.h>
#include <kis_action.h>
#include <kis_action_manager.h>
#include <kis_action_registry.h>
#include "compositionmodel.h"
......@@ -78,14 +79,7 @@ CompositionDockerDock::CompositionDockerDock( ) : QDockWidget(i18n("Compositions
connect( exportButton, SIGNAL(clicked(bool)), this, SLOT(exportClicked()));
saveNameEdit->setPlaceholderText(i18n("Insert Name"));
updateAction = new KisAction(i18n("Update Composition"), this);
updateAction->setObjectName("update_composition");
connect(updateAction, SIGNAL(triggered()), this, SLOT(updateComposition()));
renameAction = new KisAction(i18n("Rename Composition..."), this);
renameAction->setObjectName("rename_composition");
connect(renameAction, SIGNAL(triggered()), this, SLOT(renameComposition()));
m_actions.append(renameAction);
}
CompositionDockerDock::~CompositionDockerDock()
......@@ -106,6 +100,16 @@ void CompositionDockerDock::setCanvas(KoCanvasBase * canvas)
m_canvas = dynamic_cast<KisCanvas2*>(canvas);
if (m_canvas && m_canvas->viewManager()) {
if (m_actions.isEmpty()) {
KisAction *updateAction = m_canvas->viewManager()->actionManager()->createAction("update_composition");
connect(updateAction, SIGNAL(triggered()), this, SLOT(updateComposition()));
m_actions.append(updateAction);
KisAction *renameAction = m_canvas->viewManager()->actionManager()->createAction("rename_composition");
connect(renameAction, SIGNAL(triggered()), this, SLOT(renameComposition()));
m_actions.append(renameAction);
}
Q_FOREACH (KisAction *action, m_actions) {
m_canvas->viewManager()->actionManager()->addAction(action->objectName(), action);
}
......@@ -260,9 +264,13 @@ void CompositionDockerDock::activateCurrentIndex()
void CompositionDockerDock::customContextMenuRequested(QPoint pos)
{
if (m_actions.isEmpty()) return;
QMenu menu;
menu.addAction(updateAction);
menu.addAction(renameAction);
Q_FOREACH (KisAction *action, m_actions) {
menu.addAction(action);
}
menu.exec(compositionView->mapToGlobal(pos));
}
......
......@@ -55,8 +55,6 @@ private:
CompositionModel *m_model;
QVector<KisAction*> m_actions;
KisAction* updateAction;
KisAction* renameAction;
};
......
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