Implements four new actions to move selected elements to front, to back, forward by one, or backward by one. Currently, these actions can be accessed through a new Edit > Arrange menu item.upstream-master
parent
9158345001
commit
36b5dbfd10
9 changed files with 286 additions and 0 deletions
@ -0,0 +1,44 @@ |
||||
#include "ArrangeUndoAction.h" |
||||
|
||||
#include "model/Element.h" |
||||
#include "model/PageRef.h" |
||||
|
||||
#include "Range.h" |
||||
|
||||
ArrangeUndoAction::ArrangeUndoAction(const PageRef& page, Layer* layer, std::string desc, InsertOrder oldOrder, |
||||
InsertOrder newOrder): |
||||
UndoAction("ArrangeUndoAction"), layer(layer), description(desc), oldOrder(oldOrder), newOrder(newOrder) { |
||||
this->page = page; |
||||
} |
||||
|
||||
ArrangeUndoAction::~ArrangeUndoAction() { this->page = nullptr; } |
||||
|
||||
bool ArrangeUndoAction::undo(Control* control) { |
||||
this->undone = true; |
||||
applyRearrange(); |
||||
return true; |
||||
} |
||||
|
||||
bool ArrangeUndoAction::redo(Control* control) { |
||||
this->undone = false; |
||||
applyRearrange(); |
||||
return true; |
||||
} |
||||
|
||||
void ArrangeUndoAction::applyRearrange() { |
||||
// Convert source order into target order
|
||||
const auto& srcOrder = this->undone ? this->newOrder : this->oldOrder; |
||||
const auto& tgtOrder = this->undone ? this->oldOrder : this->newOrder; |
||||
|
||||
for (const auto& [e, _]: srcOrder) { |
||||
layer->removeElement(e, false); |
||||
} |
||||
|
||||
for (const auto& [e, i]: tgtOrder) { |
||||
layer->insertElement(e, i); |
||||
} |
||||
|
||||
this->page->firePageChanged(); |
||||
} |
||||
|
||||
std::string ArrangeUndoAction::getText() { return this->description; } |
||||
@ -0,0 +1,45 @@ |
||||
/*
|
||||
* Xournal++ |
||||
* |
||||
* Undo move action (EditSelection) |
||||
* |
||||
* @author Xournal++ Team |
||||
* https://github.com/xournalpp/xournalpp
|
||||
* |
||||
* @license GNU GPLv2 or later |
||||
*/ |
||||
|
||||
#pragma once |
||||
|
||||
#include <deque> |
||||
|
||||
#include "model/Layer.h" |
||||
|
||||
#include "UndoAction.h" |
||||
|
||||
class ArrangeUndoAction: public UndoAction { |
||||
public: |
||||
using InsertOrder = std::deque<std::pair<Element*, Layer::ElementIndex>>; |
||||
|
||||
ArrangeUndoAction(const PageRef& page, Layer* layer, std::string desc, InsertOrder oldOrder, InsertOrder newOrder); |
||||
virtual ~ArrangeUndoAction() override; |
||||
|
||||
public: |
||||
virtual bool undo(Control* control) override; |
||||
virtual bool redo(Control* control) override; |
||||
virtual std::string getText() override; |
||||
|
||||
private: |
||||
void applyRearrange(); |
||||
|
||||
private: |
||||
std::vector<Element*> elements; |
||||
Layer* layer; |
||||
|
||||
/** Description of the ordering action. */ |
||||
std::string description; |
||||
|
||||
// These track the ordering of elements
|
||||
InsertOrder oldOrder; |
||||
InsertOrder newOrder; |
||||
}; |
||||
Loading…
Reference in new issue