From 93d0b94929d8260c0a70aaa4b187e2641915d40b Mon Sep 17 00:00:00 2001 From: Gaspar Capello Date: Fri, 24 Aug 2018 15:03:48 -0300 Subject: [PATCH] Enhancement new layer below (issue #1822) --- data/gui.xml | 7 +++++-- data/strings/en.ini | 3 +++ src/app/commands/cmd_new_layer.cpp | 30 +++++++++++++++++++++++++++++- 3 files changed, 37 insertions(+), 3 deletions(-) diff --git a/data/gui.xml b/data/gui.xml index 9c7606644..3a13b7be2 100644 --- a/data/gui.xml +++ b/data/gui.xml @@ -65,6 +65,9 @@ + + + @@ -740,7 +743,7 @@ - + @@ -906,7 +909,7 @@ - + diff --git a/data/strings/en.ini b/data/strings/en.ini index 9db2e4746..24002d7c9 100644 --- a/data/strings/en.ini +++ b/data/strings/en.ini @@ -307,6 +307,9 @@ NewFrame_DuplicateCels = Duplicate Linked Cels NewFrame_DuplicateCelsBlock = Duplicate Cels NewFrameTag = New Frame Tag NewLayer = New Layer +NewLayer_BeforeActiveLayer = New Layer Below +NewLayer_Group = New Group +NewLayer_ReferenceLayer = New Reference Layer NewSpriteFromSelection = New Sprite From Selection OpenBrowser = Open Browser OpenFile = Open Sprite diff --git a/src/app/commands/cmd_new_layer.cpp b/src/app/commands/cmd_new_layer.cpp index 8703c8acd..d835e3164 100644 --- a/src/app/commands/cmd_new_layer.cpp +++ b/src/app/commands/cmd_new_layer.cpp @@ -16,6 +16,7 @@ #include "app/context_access.h" #include "app/doc_api.h" #include "app/find_widget.h" +#include "app/i18n/strings.h" #include "app/load_widget.h" #include "app/modules/gui.h" #include "app/tx.h" @@ -42,7 +43,7 @@ using namespace ui; class NewLayerCommand : public Command { public: enum class Type { Layer, Group, ReferenceLayer }; - enum class Place { AfterActiveLayer, Top }; + enum class Place { AfterActiveLayer, BeforeActiveLayer, Top }; NewLayerCommand(); Command* clone() const override { return new NewLayerCommand(*this); } @@ -51,6 +52,7 @@ protected: void onLoadParams(const Params& params) override; bool onEnabled(Context* context) override; void onExecute(Context* context) override; + std::string onGetFriendlyName() const override; private: std::string getUniqueLayerName(const Sprite* sprite) const; @@ -87,6 +89,8 @@ void NewLayerCommand::onLoadParams(const Params& params) m_place = Place::AfterActiveLayer; if (params.get("top") == "true") m_place = Place::Top; + else if (params.get("before") == "true") + m_place = Place::BeforeActiveLayer; } bool NewLayerCommand::onEnabled(Context* context) @@ -186,6 +190,8 @@ void NewLayerCommand::onExecute(Context* context) switch (m_type) { case Type::Layer: layer = api.newLayer(parent, name); + if (m_place == Place::BeforeActiveLayer) + api.restackLayerBefore(layer, parent, activeLayer); break; case Type::Group: layer = api.newGroup(parent, name); @@ -324,6 +330,28 @@ void NewLayerCommand::onExecute(Context* context) App::instance()->mainWindow()->popTimeline(); } +std::string NewLayerCommand::onGetFriendlyName() const +{ + std::string text; + + switch (m_type) { + case Type::Layer: + if (m_place == Place::BeforeActiveLayer) + text = Strings::commands_NewLayer_BeforeActiveLayer(); + else + text = Strings::commands_NewLayer(); + break; + case Type::Group: + text = Strings::commands_NewLayer_Group(); + break; + case Type::ReferenceLayer: + text = Strings::commands_NewLayer_ReferenceLayer(); + break; + } + + return text; +} + std::string NewLayerCommand::getUniqueLayerName(const Sprite* sprite) const { char buf[1024];