Changeset View
Changeset View
Standalone View
Standalone View
krita/ui/kis_action_manager.cpp
Show All 25 Lines | |||||
26 | #include "kis_action.h" | 26 | #include "kis_action.h" | ||
27 | #include "KisViewManager.h" | 27 | #include "KisViewManager.h" | ||
28 | #include "kis_selection_manager.h" | 28 | #include "kis_selection_manager.h" | ||
29 | #include "operations/kis_operation_ui_factory.h" | 29 | #include "operations/kis_operation_ui_factory.h" | ||
30 | #include "operations/kis_operation_registry.h" | 30 | #include "operations/kis_operation_registry.h" | ||
31 | #include "operations/kis_operation.h" | 31 | #include "operations/kis_operation.h" | ||
32 | #include "kis_layer.h" | 32 | #include "kis_layer.h" | ||
33 | #include "KisDocument.h" | 33 | #include "KisDocument.h" | ||
34 | #include "kis_action_registry.h" | ||||
35 | | ||||
36 | #include "QFile" | ||||
37 | #include <QDomDocument> | ||||
38 | #include <QDomElement> | ||||
39 | | ||||
40 | #include "QFile" | ||||
41 | #include <QDomDocument> | ||||
42 | #include <QDomElement> | ||||
34 | 43 | | |||
35 | 44 | | |||
36 | class Q_DECL_HIDDEN KisActionManager::Private { | 45 | class Q_DECL_HIDDEN KisActionManager::Private { | ||
37 | 46 | | |||
38 | public: | 47 | public: | ||
39 | Private() | 48 | Private() | ||
40 | : viewManager(0) | 49 | : viewManager(0) | ||
41 | {} | 50 | {} | ||
Show All 10 Lines | |||||
52 | { | 61 | { | ||
53 | d->viewManager = viewManager; | 62 | d->viewManager = viewManager; | ||
54 | 63 | | |||
55 | 64 | | |||
56 | } | 65 | } | ||
57 | 66 | | |||
58 | KisActionManager::~KisActionManager() | 67 | KisActionManager::~KisActionManager() | ||
59 | { | 68 | { | ||
69 | | ||||
70 | #if 0 | ||||
71 | if ((d->actions.size() > 0)) { | ||||
72 | | ||||
73 | QDomDocument doc; | ||||
74 | QDomElement e = doc.createElement("Actions"); | ||||
75 | e.setAttribute("version", "2"); | ||||
76 | doc.appendChild(e); | ||||
77 | | ||||
78 | foreach(KisAction *action, d->actions) { | ||||
79 | QDomElement a = doc.createElement("Action"); | ||||
80 | a.setAttribute("name", action->objectName()); | ||||
81 | | ||||
82 | // But seriously, XML is the worst format ever designed | ||||
83 | auto addElement = [&](QString title, QString content) { | ||||
84 | QDomElement newNode = doc.createElement(title); | ||||
85 | QDomText newText = doc.createTextNode(content); | ||||
86 | newNode.appendChild(newText); | ||||
87 | a.appendChild(newNode); | ||||
88 | }; | ||||
89 | | ||||
90 | addElement("icon", action->icon().name()); | ||||
91 | addElement("text", action->text()); | ||||
92 | addElement("whatsThis" , action->whatsThis()); | ||||
93 | addElement("toolTip" , action->toolTip()); | ||||
94 | addElement("iconText" , action->iconText()); | ||||
95 | addElement("shortcut" , action->shortcut().toString()); | ||||
96 | addElement("activationFlags" , QString::number(action->activationFlags(),2));; | ||||
97 | addElement("activationConditions" , QString::number(action->activationConditions(),2)); | ||||
98 | addElement("defaultShortcut" , action->defaultShortcut().toString()); | ||||
99 | addElement("isCheckable" , QString((action->isChecked() ? "true" : "false"))); | ||||
100 | addElement("statusTip", action->statusTip()); | ||||
101 | e.appendChild(a); | ||||
102 | } | ||||
103 | QFile f("ActionManager.action"); | ||||
104 | f.open(QFile::WriteOnly); | ||||
105 | f.write(doc.toString().toUtf8()); | ||||
106 | f.close(); | ||||
107 | | ||||
108 | } | ||||
109 | #endif | ||||
60 | delete d; | 110 | delete d; | ||
61 | } | 111 | } | ||
62 | 112 | | |||
63 | void KisActionManager::setView(QPointer<KisView> imageView) | 113 | void KisActionManager::setView(QPointer<KisView> imageView) | ||
64 | { | 114 | { | ||
65 | Q_UNUSED(imageView); | 115 | Q_UNUSED(imageView); | ||
66 | } | 116 | } | ||
67 | 117 | | |||
68 | void KisActionManager::addAction(const QString& name, KisAction* action) | 118 | void KisActionManager::addAction(const QString& name, KisAction* action) | ||
69 | { | 119 | { | ||
70 | Q_ASSERT(!name.isEmpty()); | 120 | Q_ASSERT(!name.isEmpty()); | ||
71 | Q_ASSERT(action); | 121 | Q_ASSERT(action); | ||
72 | Q_ASSERT(d->viewManager); | 122 | Q_ASSERT(d->viewManager); | ||
73 | Q_ASSERT(d->viewManager->actionCollection()); | 123 | Q_ASSERT(d->viewManager->actionCollection()); | ||
74 | 124 | | |||
75 | d->viewManager->actionCollection()->addAction(name, action); | 125 | d->viewManager->actionCollection()->addAction(name, action); | ||
76 | action->setObjectName(name); | 126 | action->setObjectName(name); | ||
77 | action->setParent(d->viewManager->actionCollection()); | 127 | action->setParent(d->viewManager->actionCollection()); | ||
78 | d->viewManager->actionCollection()->setDefaultShortcut(action, action->defaultShortcut()); | 128 | d->viewManager->actionCollection()->setDefaultShortcut(action, action->defaultShortcut()); | ||
79 | d->actions.append(action); | 129 | d->actions.append(action); | ||
80 | action->setActionManager(this); | 130 | action->setActionManager(this); | ||
131 | KisActionRegistry::instance()->addAction(name, action); | ||||
81 | } | 132 | } | ||
82 | 133 | | |||
83 | void KisActionManager::takeAction(KisAction* action) | 134 | void KisActionManager::takeAction(KisAction* action) | ||
84 | { | 135 | { | ||
85 | d->actions.removeOne(action); | 136 | d->actions.removeOne(action); | ||
86 | 137 | | |||
87 | if (!action->objectName().isEmpty()) { | 138 | if (!action->objectName().isEmpty()) { | ||
88 | KIS_ASSERT_RECOVER_RETURN(d->viewManager->actionCollection()); | 139 | KIS_ASSERT_RECOVER_RETURN(d->viewManager->actionCollection()); | ||
89 | d->viewManager->actionCollection()->takeAction(action); | 140 | d->viewManager->actionCollection()->takeAction(action); | ||
90 | } | 141 | } | ||
91 | } | 142 | } | ||
92 | 143 | | |||
93 | KisAction *KisActionManager::actionByName(const QString &name) const | 144 | KisAction *KisActionManager::actionByName(const QString &name) const | ||
94 | { | 145 | { | ||
95 | foreach(KisAction *action, d->actions) { | 146 | foreach(KisAction *action, d->actions) { | ||
96 | if (action->objectName() == name) { | 147 | if (action->objectName() == name) { | ||
97 | return action; | 148 | return action; | ||
98 | } | 149 | } | ||
99 | } | 150 | } | ||
100 | return 0; | 151 | return 0; | ||
101 | } | 152 | } | ||
102 | 153 | | |||
154 | | ||||
155 | KisAction *KisActionManager::createAction(const QString &name) | ||||
156 | { | ||||
157 | KisAction *a = actionByName(name); // Check if the action already exists | ||||
158 | if (a) { | ||||
159 | return a; | ||||
160 | } | ||||
161 | | ||||
162 | // There is some tension here. KisActionManager is supposed to be in control | ||||
163 | // of global actions, but these actions are supposed to be duplicated. We | ||||
164 | // will add them to the KisActionRegistry for the time being so we can get | ||||
165 | // properly categorized shortcuts. | ||||
166 | a = new KisAction(); | ||||
167 | KisActionRegistry::instance()->propertizeAction(name, a); | ||||
168 | KisActionRegistry::instance()->addAction(name, a); | ||||
169 | | ||||
170 | // TODO: Add other static data (activationFlags, etc.) using getActionXml(); | ||||
171 | | ||||
172 | addAction(name, a); | ||||
173 | | ||||
174 | return a; | ||||
175 | } | ||||
176 | | ||||
103 | void KisActionManager::updateGUI() | 177 | void KisActionManager::updateGUI() | ||
104 | { | 178 | { | ||
105 | //TODO other flags | 179 | //TODO other flags | ||
106 | KisAction::ActivationFlags flags; | 180 | KisAction::ActivationFlags flags; | ||
107 | 181 | | |||
108 | KisImageWSP image; | 182 | KisImageWSP image; | ||
109 | KisNodeSP node; | 183 | KisNodeSP node; | ||
110 | KisLayerSP layer; | 184 | KisLayerSP layer; | ||
▲ Show 20 Lines • Show All 258 Lines • Show Last 20 Lines |