From fa8afc02e925c3a02c655a690abb2f2415c9d34f Mon Sep 17 00:00:00 2001 From: David Capello Date: Mon, 4 May 2015 11:45:08 -0300 Subject: [PATCH] Create new layers above the current one We've added a "top" parameter to have the previous behavior. --- src/app/commands/cmd_new_layer.cpp | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/src/app/commands/cmd_new_layer.cpp b/src/app/commands/cmd_new_layer.cpp index a37848faf..d3dc4ead7 100644 --- a/src/app/commands/cmd_new_layer.cpp +++ b/src/app/commands/cmd_new_layer.cpp @@ -43,6 +43,7 @@ protected: private: bool m_ask; + bool m_top; std::string m_name; }; @@ -55,14 +56,14 @@ NewLayerCommand::NewLayerCommand() CmdRecordableFlag) { m_ask = false; + m_top = false; m_name = ""; } void NewLayerCommand::onLoadParams(const Params& params) { - std::string ask = params.get("ask"); - if (ask == "true") m_ask = true; - + m_ask = (params.get("ask") == "true"); + m_top = (params.get("top") == "true"); m_name = params.get("name"); } @@ -101,10 +102,18 @@ void NewLayerCommand::onExecute(Context* context) name = window->findChild("name")->getText(); } + Layer* activeLayer = writer.layer(); Layer* layer; { Transaction transaction(writer.context(), "New Layer"); - layer = document->getApi(transaction).newLayer(sprite); + DocumentApi api = document->getApi(transaction); + layer = api.newLayer(sprite); + + // If "top" parameter is false, create the layer above the active + // one. + if (activeLayer && !m_top) + api.restackLayerAfter(layer, activeLayer); + transaction.commit(); } layer->setName(name);