mirror of
https://github.com/aseprite/aseprite.git
synced 2024-09-15 15:14:16 +00:00
Use ObjectId to identify FrameTags in the Timeline/frame tags commands
This commit is contained in:
parent
1177e02609
commit
6d12deafe6
@ -20,6 +20,7 @@
|
||||
#include "app/loop_tag.h"
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/frame_tag_window.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "doc/anidir.h"
|
||||
#include "doc/frame_tag.h"
|
||||
#include "doc/sprite.h"
|
||||
@ -40,6 +41,7 @@ protected:
|
||||
|
||||
private:
|
||||
std::string m_tagName;
|
||||
ObjectId m_tagId;
|
||||
};
|
||||
|
||||
FrameTagPropertiesCommand::FrameTagPropertiesCommand()
|
||||
@ -52,6 +54,12 @@ FrameTagPropertiesCommand::FrameTagPropertiesCommand()
|
||||
void FrameTagPropertiesCommand::onLoadParams(Params* params)
|
||||
{
|
||||
m_tagName = params->get("name");
|
||||
|
||||
std::string id = params->get("id");
|
||||
if (!id.empty())
|
||||
m_tagId = ObjectId(base::convert_to<ObjectId>(id));
|
||||
else
|
||||
m_tagId = NullId;
|
||||
}
|
||||
|
||||
bool FrameTagPropertiesCommand::onEnabled(Context* context)
|
||||
@ -68,12 +76,10 @@ void FrameTagPropertiesCommand::onExecute(Context* context)
|
||||
|
||||
if (!m_tagName.empty())
|
||||
foundTag = sprite->frameTags().getByName(m_tagName);
|
||||
|
||||
if (!foundTag) {
|
||||
else if (m_tagId != NullId)
|
||||
foundTag = sprite->frameTags().getById(m_tagId);
|
||||
else
|
||||
foundTag = get_shortest_tag(sprite, frame);
|
||||
if (!foundTag)
|
||||
return;
|
||||
}
|
||||
|
||||
FrameTagWindow window(sprite, foundTag);
|
||||
if (!window.show())
|
||||
|
@ -19,6 +19,7 @@
|
||||
#include "app/transaction.h"
|
||||
#include "app/ui/main_window.h"
|
||||
#include "app/ui/timeline.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "doc/frame_tag.h"
|
||||
|
||||
namespace app {
|
||||
@ -35,6 +36,7 @@ protected:
|
||||
|
||||
private:
|
||||
std::string m_tagName;
|
||||
ObjectId m_tagId;
|
||||
};
|
||||
|
||||
RemoveFrameTagCommand::RemoveFrameTagCommand()
|
||||
@ -47,6 +49,12 @@ RemoveFrameTagCommand::RemoveFrameTagCommand()
|
||||
void RemoveFrameTagCommand::onLoadParams(Params* params)
|
||||
{
|
||||
m_tagName = params->get("name");
|
||||
|
||||
std::string id = params->get("id");
|
||||
if (!id.empty())
|
||||
m_tagId = ObjectId(base::convert_to<ObjectId>(id));
|
||||
else
|
||||
m_tagId = NullId;
|
||||
}
|
||||
|
||||
bool RemoveFrameTagCommand::onEnabled(Context* context)
|
||||
@ -64,12 +72,10 @@ void RemoveFrameTagCommand::onExecute(Context* context)
|
||||
|
||||
if (!m_tagName.empty())
|
||||
foundTag = sprite->frameTags().getByName(m_tagName);
|
||||
|
||||
if (!foundTag) {
|
||||
else if (m_tagId != NullId)
|
||||
foundTag = sprite->frameTags().getById(m_tagId);
|
||||
else
|
||||
foundTag = get_shortest_tag(sprite, frame);
|
||||
if (!foundTag)
|
||||
return;
|
||||
}
|
||||
|
||||
if (!foundTag)
|
||||
return;
|
||||
|
@ -36,6 +36,7 @@
|
||||
#include "app/ui/status_bar.h"
|
||||
#include "app/ui_context.h"
|
||||
#include "app/util/clipboard.h"
|
||||
#include "base/convert_to.h"
|
||||
#include "base/memory.h"
|
||||
#include "doc/doc.h"
|
||||
#include "doc/document_event.h"
|
||||
@ -596,11 +597,12 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
|
||||
case PART_FRAME_TAG:
|
||||
if (m_clk.frameTag) {
|
||||
Params params;
|
||||
params.set("id", base::convert_to<std::string>(m_clk.frameTag->id()).c_str());
|
||||
|
||||
if (mouseMsg->right()) {
|
||||
Menu* popup_menu = AppMenus::instance()->getFrameTagPopupMenu();
|
||||
if (popup_menu) {
|
||||
Params params;
|
||||
params.set("name", m_clk.frameTag->name().c_str());
|
||||
CommandsModule::instance()->getCommandByName(CommandId::FrameTagProperties)->loadParams(¶ms);
|
||||
CommandsModule::instance()->getCommandByName(CommandId::RemoveFrameTag)->loadParams(¶ms);
|
||||
popup_menu->showPopup(mouseMsg->position());
|
||||
@ -609,8 +611,6 @@ bool Timeline::onProcessMessage(Message* msg)
|
||||
else if (mouseMsg->left()) {
|
||||
Command* command = CommandsModule::instance()
|
||||
->getCommandByName(CommandId::FrameTagProperties);
|
||||
Params params;
|
||||
params.set("name", m_clk.frameTag->name().c_str());
|
||||
UIContext::instance()->executeCommand(command, ¶ms);
|
||||
}
|
||||
}
|
||||
|
@ -28,6 +28,18 @@ template<> std::string convert_to(const int& from)
|
||||
return buf;
|
||||
}
|
||||
|
||||
template<> uint32_t convert_to(const std::string& from)
|
||||
{
|
||||
return std::strtoul(from.c_str(), NULL, 10);
|
||||
}
|
||||
|
||||
template<> std::string convert_to(const uint32_t& from)
|
||||
{
|
||||
char buf[32];
|
||||
std::sprintf(buf, "%u", from);
|
||||
return buf;
|
||||
}
|
||||
|
||||
template<> double convert_to(const std::string& from)
|
||||
{
|
||||
return std::strtod(from.c_str(), NULL);
|
||||
|
@ -24,6 +24,9 @@ namespace base {
|
||||
template<> int convert_to(const std::string& from);
|
||||
template<> std::string convert_to(const int& from);
|
||||
|
||||
template<> uint32_t convert_to(const std::string& from);
|
||||
template<> std::string convert_to(const uint32_t& from);
|
||||
|
||||
template<> double convert_to(const std::string& from);
|
||||
template<> std::string convert_to(const double& from);
|
||||
|
||||
|
@ -51,4 +51,13 @@ FrameTag* FrameTags::getByName(const std::string& name) const
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
FrameTag* FrameTags::getById(ObjectId id) const
|
||||
{
|
||||
for (FrameTag* tag : *this) {
|
||||
if (tag->id() == id)
|
||||
return tag;
|
||||
}
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
} // namespace doc
|
||||
|
@ -9,6 +9,7 @@
|
||||
#pragma once
|
||||
|
||||
#include "base/disable_copying.h"
|
||||
#include "doc/object_id.h"
|
||||
|
||||
#include <vector>
|
||||
|
||||
@ -32,6 +33,7 @@ namespace doc {
|
||||
void remove(FrameTag* tag);
|
||||
|
||||
FrameTag* getByName(const std::string& name) const;
|
||||
FrameTag* getById(const ObjectId id) const;
|
||||
|
||||
iterator begin() { return m_tags.begin(); }
|
||||
iterator end() { return m_tags.end(); }
|
||||
|
Loading…
Reference in New Issue
Block a user