29#include <QDomDocument>
39 qDeleteAll(uiRegistry.values());
65 if ((
d->actions.size() > 0)) {
68 QDomElement e = doc.createElement(
"Actions");
69 e.setAttribute(
"version",
"2");
73 QDomElement a = doc.createElement(
"Action");
74 a.setAttribute(
"name", action->objectName());
77 auto addElement = [&](QString title, QString content) {
78 QDomElement newNode = doc.createElement(title);
79 QDomText newText = doc.createTextNode(content);
80 newNode.appendChild(newText);
81 a.appendChild(newNode);
84 addElement(
"icon", action->icon().name());
85 addElement(
"text", action->text());
86 addElement(
"whatsThis" , action->whatsThis());
87 addElement(
"toolTip" , action->toolTip());
88 addElement(
"iconText" , action->iconText());
89 addElement(
"shortcut" , action->shortcut().toString());
90 addElement(
"activationFlags" , QString::number(action->
activationFlags(),2));
93 addElement(
"isCheckable" , QString((action->isChecked() ?
"true" :
"false")));
94 addElement(
"statusTip", action->statusTip());
97 QFile f(
"ActionManager.action");
98 f.open(QFile::WriteOnly);
99 f.write(doc.toString().toUtf8());
125 Q_ASSERT(!name.isEmpty());
127 Q_ASSERT(
d->viewManager);
128 Q_ASSERT(
d->actionCollection);
130 d->actionCollection->addAction(name, action);
131 action->setParent(
d->actionCollection);
133 d->actions.append(action);
139 d->actions.removeOne(action);
141 if (!action->objectName().isEmpty()) {
143 d->actionCollection->takeAction(action);
150 if (action->objectName() == name) {
178 int activationFlags = actionRegistry->
getActionProperty(name,
"activationFlags").toInt(&ok, 2);
179 int activationConditions = actionRegistry->
getActionProperty(name,
"activationConditions").toInt(&ok, 2);
190 KisAction::ActivationFlags flags;
199 if (
d->viewManager) {
200 node =
d->viewManager->activeNode();
201 selectionManager =
d->viewManager->selectionManager();
205 if (
d->viewManager->viewCount() > 0 )
207 image =
d->viewManager->image();
215 if (document && document->isReadWrite()) {
219 if (
d->viewManager->viewCount() > 1) {
223 if (
d->viewManager->document() &&
d->viewManager->document()->isModified()) {
227 if (
d->viewManager->activeDevice()) {
232 if (
d->viewManager->selectionEditable()) {
245 layer = qobject_cast<KisLayer*>(node.
data());
250 if (node->inherits(
"KisTransparencyMask")) {
255 if (layer && layer->inherits(
"KisShapeLayer")) {
263 if (selectionManager) {
320 enable = action->activationFlags() & flags;
323 enable = enable && (int)(action->activationConditions() & conditions) == (
int)action->activationConditions();
325 if (node && enable) {
326 Q_FOREACH (
const QString &type, action->excludedNodeTypes()) {
327 if (node->inherits(type.toLatin1())) {
334 action->setActionEnabled(enable);
345 const QKeySequence defaultShortcut = defaultShortcuts.isEmpty() ? QKeySequence() : defaultShortcuts.at(0);
349 action->setShortcut(QKeySequence(
"CTRL+SHIFT+S"));
352 action->setCheckable(standardAction->isCheckable());
353 if (action->isCheckable()) {
354 action->setChecked(standardAction->isChecked());
356 action->setMenuRole(standardAction->menuRole());
357 action->setText(standardAction->text());
358 action->setToolTip(standardAction->toolTip());
360 if (receiver && member) {
362 QObject::connect(action, SIGNAL(urlSelected(QUrl)), receiver, member);
365 QObject::connect(action, SIGNAL(triggered(
bool)), receiver, member, Qt::QueuedConnection);
368 QObject::connect(action, SIGNAL(triggered(
bool)), receiver, member);
375 addAction(standardAction->objectName(), action);
376 delete standardAction;
387 menu->addAction(action);
392 d->uiRegistry.add(factory);
397 d->operationRegistry.add(operation);
417 KisOperation* operation =
d->operationRegistry.get(config->id());
424 QFile data(
"actions.txt");
425 if (data.open(QFile::WriteOnly | QFile::Truncate)) {
426 QTextStream out(&data);
431 out <<
"-------- " << action->text() <<
" --------\n";
432 out <<
"Action will activate on: \n";
435 out <<
" Active image\n";
438 out <<
" More than one image open\n";
441 out <<
" Active image modified\n";
444 out <<
" Active device\n";
447 out <<
" Active layer\n";
450 out <<
" Active transparency mask\n";
453 out <<
" Active node\n";
456 out <<
" Active shape layer\n";
459 out <<
" Pixels selected\n";
462 out <<
" Shapes selected\n";
465 out <<
" Any selection with pixels\n";
468 out <<
" Pixels in clipboard\n";
471 out <<
" Shape in clipboard\n";
474 out <<
" Image has animation\n";
478 out <<
"Action will only activate if the following conditions are met: \n";
480 if ((
int)conditions == 0) {
484 out <<
" Active Node editable\n";
487 out <<
" Active Node has editable paint device\n";
490 out <<
" Selection is editable\n";
493 out <<
" OpenGL is enabled\n";
connect(this, SIGNAL(optionsChanged()), this, SLOT(saveOptions()))
A KisActionManager class keeps track of KisActions. These actions are always associated with the GUI....
void setView(QPointer< KisView > imageView)
KisOperationRegistry operationRegistry
void runOperation(const QString &id)
KisAction * createAction(const QString &name)
KisAction * actionByName(const QString &name) const
~KisActionManager() override
KisActionManager(KisViewManager *viewManager, KisKActionCollection *actionCollection)
QList< QPointer< KisAction > > actions
void takeAction(KisAction *action)
KisViewManager * viewManager
void slotActionAddedToCollection(QAction *action)
KisKActionCollection * actionCollection
void registerOperationUIFactory(KisOperationUIFactory *factory)
static void safePopulateMenu(QMenu *menu, const QString &actionId, KisActionManager *actionManager)
KoGenericRegistry< KisOperationUIFactory * > uiRegistry
void addAction(const QString &name, KisAction *action)
void runOperationFromConfiguration(KisOperationConfigurationSP config)
KisAction * createStandardAction(KStandardAction::StandardAction, const QObject *receiver, const char *member)
void registerOperation(KisOperation *operation)
void updateShortcut(const QString &name, QAction *ac)
bool propertizeAction(const QString &name, QAction *a)
static KisActionRegistry * instance()
QString getActionProperty(const QString &name, const QString &property)
void setActivationFlags(ActivationFlags flags)
void setActivationConditions(ActivationConditions conditions)
@ PIXELS_IN_CLIPBOARD
Activate if the clipboard contains pixels.
@ SHAPES_IN_CLIPBOARD
Activate if the clipboard contains vector data.
@ CURRENT_IMAGE_MODIFIED
Activate if the current image is modified.
@ ACTIVE_IMAGE
Activate if there is at least one image.
@ ACTIVE_NODE
Activate if there's an active node (layer or mask)
@ SHAPE_SELECTION_WITH_SHAPES
Activate there is a vector selection active.
@ IMAGE_IS_WRITABLE
Activate KisDocument::isReadWrite() is active.
@ ANY_SELECTION_WITH_PIXELS
???
@ ACTIVE_TRANSPARENCY_MASK
Activate if the current node is a transparency mask.
@ IMAGE_HAS_ANIMATION
Activate if the image has an animation.
@ SHAPES_SELECTED
Activate if any vector shape is selected.
@ PIXELS_SELECTED
Activate if any pixels are selected (with any kind of selection)
@ ACTIVE_SHAPE_LAYER
Activate if the current node is a vector layer.
@ IMAGE_CAN_RESELECT
Activate there is a deselected selection in the image.
@ PIXEL_SELECTION_WITH_PIXELS
Activate there is a raster selection active.
@ ACTIVE_LAYER
Activate if the current node is a layer (vector or pixel)
@ MULTIPLE_IMAGES
Activate if there is more than one image open.
@ ACTIVE_DEVICE
Activate if the active node has a paint device, i.e. there are pixels to be modified.
@ ACTIVE_NODE_EDITABLE_PAINT_DEVICE
void setActionManager(KisActionManager *actionManager)
ActivationFlags activationFlags()
void setDefaultShortcut(const QKeySequence &shortcut)
ActivationConditions activationConditions()
QKeySequence defaultShortcut() const
static KisClipboard * instance()
bool useOpenGL(bool defaultValue=false) const
bool hasAnimation() const
KisImageAnimationInterface * animationInterface() const
A container for a set of QAction objects.
virtual bool fetchConfiguration(KisViewManager *view, KisOperationConfigurationSP configuration)=0
virtual void runFromXML(KisViewManager *view, const KisOperationConfiguration &config)
bool haveShapeSelectionWithShapes()
bool haveAnySelectionWithPixels()
Checks if the current selection is editable and has some pixels selected in the pixel selection.
bool canReselectDeactivatedSelection()
bool havePixelsInClipboard()
bool haveShapesInClipboard()
bool haveRasterSelectionWithPixels()
bool haveShapesSelected()
#define KIS_SAFE_ASSERT_RECOVER_RETURN(cond)
#define KIS_ASSERT_RECOVER_RETURN(cond)
QAction * create(StandardAction id, const QObject *recvr, const char *slot, QObject *parent)
void setUtf8OnStream(QTextStream &stream)
bool isEditable(bool checkVisibility=true) const
bool hasEditablePaintDevice() const