diff --git a/src/control/Control.cpp b/src/control/Control.cpp index 43e3b4ff..67fe050d 100644 --- a/src/control/Control.cpp +++ b/src/control/Control.cpp @@ -37,9 +37,7 @@ #include "undo/AddUndoAction.h" #include "undo/DeleteUndoAction.h" #include "undo/InsertDeletePageUndoAction.h" -#include "undo/InsertLayerUndoAction.h" #include "undo/InsertUndoAction.h" -#include "undo/RemoveLayerUndoAction.h" #include "view/DocumentView.h" #include diff --git a/src/control/layer/LayerController.cpp b/src/control/layer/LayerController.cpp index 1b242f83..7e613d7d 100644 --- a/src/control/layer/LayerController.cpp +++ b/src/control/layer/LayerController.cpp @@ -2,6 +2,8 @@ #include "LayerCtrlListener.h" #include "control/Control.h" #include "gui/XournalView.h" +#include "undo/RemoveLayerUndoAction.h" +#include "undo/InsertLayerUndoAction.h" #include @@ -122,31 +124,32 @@ bool LayerController::actionPerformed(ActionType type) return true; case ACTION_GOTO_NEXT_LAYER: -// { -// int layer = this->win->getCurrentLayer(); -// PageRef p = getCurrentPage(); -// if (layer < (int)p->getLayerCount()) -// { -// switchToLay(layer + 1); -// } -// } + { + PageRef p = getCurrentPage(); + int layer = p->getSelectedLayerId(); + if (layer < (int)p->getLayerCount()) + { + switchToLay(layer + 1); + } + } return true; case ACTION_GOTO_PREVIOUS_LAYER: -// { -// int layer = this->win->getCurrentLayer(); -// if (layer > 0) -// { -// switchToLay(layer - 1); -// } -// } + { + PageRef p = getCurrentPage(); + int layer = p->getSelectedLayerId(); + if (layer > 0) + { + switchToLay(layer - 1); + } + } return true; case ACTION_GOTO_TOP_LAYER: -// { -// PageRef p = getCurrentPage(); -// switchToLay(p->getLayerCount()); -// } + { + PageRef p = getCurrentPage(); + switchToLay(p->getLayerCount()); + } return true; default: return false; @@ -190,51 +193,54 @@ void LayerController::addNewLayer() { XOJ_CHECK_TYPE(LayerController); -// clearSelectionEndText(); -// PageRef p = getCurrentPage(); -// if (!p.isValid()) -// { -// return; -// } -// -// Layer* l = new Layer(); -// p->insertLayer(l, p->getSelectedLayerId()); -// if (win) -// { -// win->updateLayerCombobox(); -// } -// -// undoRedo->addUndoAction(new InsertLayerUndoAction(p, l)); + control->clearSelectionEndText(); + PageRef p = getCurrentPage(); + if (!p.isValid()) + { + return; + } + + Layer* l = new Layer(); + p->insertLayer(l, p->getSelectedLayerId()); + + control->getUndoRedoHandler()->addUndoAction(new InsertLayerUndoAction(this, p, l)); + + fireRebuildLayerMenu(); + // Repaint is not needed here - the new layer is empty } void LayerController::deleteCurrentLayer() { XOJ_CHECK_TYPE(LayerController); -// clearSelectionEndText(); -// PageRef p = getCurrentPage(); -// int pId = getCurrentPageNo(); -// if (!p.isValid()) -// { -// return; -// } -// -// int lId = p->getSelectedLayerId(); -// if (lId < 1) -// { -// return; -// } -// Layer* l = p->getSelectedLayer(); -// -// p->removeLayer(l); -// if (win) -// { -// win->getXournal()->layerChanged(pId); -// win->updateLayerCombobox(); -// } -// -// undoRedo->addUndoAction(new RemoveLayerUndoAction(p, l, lId - 1)); -// this->resetShapeRecognizer(); + control->clearSelectionEndText(); + + PageRef p = getCurrentPage(); + int pId = selectedPage; + if (!p.isValid()) + { + return; + } + + int lId = p->getSelectedLayerId(); + if (lId < 1) + { + return; + } + Layer* l = p->getSelectedLayer(); + + p->removeLayer(l); + + MainWindow* win = control->getWindow(); + if (win) + { + win->getXournal()->layerChanged(pId); + } + + control->getUndoRedoHandler()->addUndoAction(new RemoveLayerUndoAction(this, p, l, lId - 1)); + control->resetShapeRecognizer(); + + fireRebuildLayerMenu(); } PageRef LayerController::getCurrentPage()