Commit e35c0127 authored by Dmitry Kazakov's avatar Dmitry Kazakov

Fix auto-opening of the editor dialog in the text tool

When we create a text shape, Krita may automatically create a new
shape layer for it. It means that a new shape manager and selection
will be created. Therefore KoKeepShapesSelectedCommand should point
not to KoSelection object, but to KoSelectedShapesProxy, which is
kept unchanged when the layers are switched.
parent a42c7e91
......@@ -20,30 +20,33 @@
#include <KoShape.h>
#include <KoSelection.h>
#include <KoSelectedShapesProxy.h>
KoKeepShapesSelectedCommand::KoKeepShapesSelectedCommand(const QList<KoShape*> &selectedBefore,
const QList<KoShape*> &selectedAfter,
KoSelection *selection,
KoSelectedShapesProxy *selectionProxy,
bool isFinalizing,
KUndo2Command *parent)
: KisCommandUtils::FlipFlopCommand(isFinalizing, parent),
m_selectedBefore(selectedBefore),
m_selectedAfter(selectedAfter),
m_selection(selection)
m_selectionProxy(selectionProxy)
{
}
void KoKeepShapesSelectedCommand::end()
{
m_selection->deselectAll();
KoSelection *selection = m_selectionProxy->selection();
selection->deselectAll();
const QList<KoShape*> newSelectedShapes =
isFinalizing() ? m_selectedAfter : m_selectedBefore;
Q_FOREACH (KoShape *shape, newSelectedShapes) {
m_selection->select(shape);
selection->select(shape);
}
}
......@@ -22,6 +22,7 @@
#include "kis_command_utils.h"
#include <kritaflake_export.h>
class KoSelectedShapesProxy;
class KoSelection;
class KoShape;
......@@ -30,7 +31,7 @@ class KRITAFLAKE_EXPORT KoKeepShapesSelectedCommand : public KisCommandUtils::Fl
public:
KoKeepShapesSelectedCommand(const QList<KoShape*> &selectedBefore,
const QList<KoShape*> &selectedAfter,
KoSelection *selection,
KoSelectedShapesProxy *selectionProxy,
bool isFinalizing,
KUndo2Command *parent);
......@@ -40,7 +41,7 @@ protected:
private:
QList<KoShape*> m_selectedBefore;
QList<KoShape*> m_selectedAfter;
KoSelection *m_selection;
KoSelectedShapesProxy *m_selectionProxy;
};
#endif // KOKEEPSHAPESSELECTEDCOMMAND_H
......@@ -391,7 +391,7 @@ void KoPathTool::convertToPath()
const QList<KoShape*> oldSelectedShapes = implicitCastList<KoShape*>(textShapes);
new KoKeepShapesSelectedCommand(oldSelectedShapes, {}, selection, false, cmd);
new KoKeepShapesSelectedCommand(oldSelectedShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
QList<KoShape*> newSelectedShapes;
Q_FOREACH (KoSvgTextShape *shape, textShapes) {
......@@ -413,7 +413,7 @@ void KoPathTool::convertToPath()
canvas()->shapeController()->removeShapes(oldSelectedShapes, cmd);
new KoKeepShapesSelectedCommand({}, newSelectedShapes, selection, true, cmd);
new KoKeepShapesSelectedCommand({}, newSelectedShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
}
......
......@@ -206,10 +206,10 @@ void KisToolShape::addShape(KoShape* shape)
// reset selection on the newly added shape :)
// TODO: think about moving this into controller->addShape?
new KoKeepShapesSelectedCommand(oldSelectedShapes, {shape}, selection, false, parentCommand);
new KoKeepShapesSelectedCommand(oldSelectedShapes, {shape}, canvas()->selectedShapesProxy(), false, parentCommand);
KUndo2Command *cmd = canvas()->shapeController()->addShape(shape, 0, parentCommand);
parentCommand->setText(cmd->text());
new KoKeepShapesSelectedCommand(oldSelectedShapes, {shape}, selection, true, parentCommand);
new KoKeepShapesSelectedCommand(oldSelectedShapes, {shape}, canvas()->selectedShapesProxy(), true, parentCommand);
canvas()->addCommand(parentCommand);
}
......
......@@ -1049,10 +1049,10 @@ void DefaultTool::selectionGroup()
group->setZIndex(groupZIndex);
// TODO what if only one shape is left?
KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Group shapes"));
new KoKeepShapesSelectedCommand(selectedShapes, {}, selection, false, cmd);
new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
canvas()->shapeController()->addShapeDirect(group, 0, cmd);
new KoShapeGroupCommand(group, selectedShapes, true, cmd);
new KoKeepShapesSelectedCommand({}, {group}, selection, true, cmd);
new KoKeepShapesSelectedCommand({}, {group}, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
// update selection so we can ungroup immediately again
......@@ -1077,7 +1077,7 @@ void DefaultTool::selectionUngroup()
if (group) {
if (!cmd) {
cmd = new KUndo2Command(kundo2_i18n("Ungroup shapes"));
new KoKeepShapesSelectedCommand(selectedShapes, {}, selection, false, cmd);
new KoKeepShapesSelectedCommand(selectedShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
}
newShapes << group->shapes();
new KoShapeUngroupCommand(group, group->shapes(),
......@@ -1087,7 +1087,7 @@ void DefaultTool::selectionUngroup()
}
}
if (cmd) {
new KoKeepShapesSelectedCommand({}, newShapes, selection, true, cmd);
new KoKeepShapesSelectedCommand({}, newShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
}
}
......@@ -1231,7 +1231,7 @@ void DefaultTool::selectionBooleanOp(int booleanOp)
KUndo2Command *cmd = new KUndo2Command(actionName);
new KoKeepShapesSelectedCommand(editableShapes, {}, selection, false, cmd);
new KoKeepShapesSelectedCommand(editableShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
QList<KoShape*> newSelectedShapes;
......@@ -1248,7 +1248,7 @@ void DefaultTool::selectionBooleanOp(int booleanOp)
canvas()->shapeController()->removeShapes(editableShapes, cmd);
new KoKeepShapesSelectedCommand({}, newSelectedShapes, selection, true, cmd);
new KoKeepShapesSelectedCommand({}, newSelectedShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
}
......@@ -1265,7 +1265,7 @@ void DefaultTool::selectionSplitShapes()
KUndo2Command *cmd = new KUndo2Command(kundo2_i18n("Split Shapes"));
new KoKeepShapesSelectedCommand(editableShapes, {}, selection, false, cmd);
new KoKeepShapesSelectedCommand(editableShapes, {}, canvas()->selectedShapesProxy(), false, cmd);
QList<KoShape*> newShapes;
Q_FOREACH (KoShape *shape, editableShapes) {
......@@ -1283,7 +1283,7 @@ void DefaultTool::selectionSplitShapes()
}
}
new KoKeepShapesSelectedCommand({}, newShapes, selection, true, cmd);
new KoKeepShapesSelectedCommand({}, newShapes, canvas()->selectedShapesProxy(), true, cmd);
canvas()->addCommand(cmd);
}
......
......@@ -363,19 +363,17 @@ void SvgTextTool::mouseReleaseEvent(KoPointerEvent *event)
}
KoShape *textShape = factory->createShape( params, canvas()->shapeController()->resourceManager());
KoSelection *selection = koSelection();
KUndo2Command *parentCommand = new KUndo2Command();
new KoKeepShapesSelectedCommand(selection->selectedShapes(), {}, selection, false, parentCommand);
new KoKeepShapesSelectedCommand(koSelection()->selectedShapes(), {}, canvas()->selectedShapesProxy(), false, parentCommand);
KUndo2Command *cmd = canvas()->shapeController()->addShape(textShape, 0, parentCommand);
parentCommand->setText(cmd->text());
new KoKeepShapesSelectedCommand({}, {textShape}, selection, true, parentCommand);
new KoKeepShapesSelectedCommand({}, {textShape}, canvas()->selectedShapesProxy(), true, parentCommand);
canvas()->addCommand(parentCommand);
showEditor();
}
event->accept();
......
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