Add support to jump to a frame tag on "Go to Frame"

This commit is contained in:
David Capello 2017-06-19 11:23:40 -03:00
parent a370a6e719
commit b7d6311c4c
3 changed files with 64 additions and 13 deletions

View File

@ -156,7 +156,7 @@ cancel = &Cancel
[goto_frame]
title = Go to Frame
frame_number = Frame number:
frame_or_tags = Frame number or tag name:
[grid_settings]
title = Grid Settings

View File

@ -1,18 +1,17 @@
<!-- Aseprite -->
<!-- Copyright (C) 2001-2016 by David Capello -->
<!-- Copyright (C) 2001-2017 by David Capello -->
<gui>
<window id="goto_frame" text="@.title">
<grid columns="3">
<label text="@.frame_number" />
<entry expansive="true" maxsize="4" id="frame" magnet="true" />
<box cell_align="horizontal" />
<vbox>
<label text="@.frame_or_tags" />
<vbox id="frame_placeholder" />
<separator horizontal="true" cell_hspan="3" />
<separator horizontal="true" />
<box horizontal="true" homogeneous="true" cell_hspan="3" cell_align="right">
<hbox homogeneous="true" cell_align="right">
<button text="@general.ok" closewindow="true" id="ok" magnet="true" minwidth="60" />
<button text="@general.cancel" closewindow="true" />
</box>
</grid>
</hbox>
</vbox>
</window>
</gui>

View File

@ -11,10 +11,12 @@
#include "app/commands/command.h"
#include "app/commands/params.h"
#include "app/loop_tag.h"
#include "app/match_words.h"
#include "app/modules/editors.h"
#include "app/modules/gui.h"
#include "app/ui/editor/editor.h"
#include "app/ui/editor/editor_customization_delegate.h"
#include "app/ui/search_entry.h"
#include "doc/frame_tag.h"
#include "doc/sprite.h"
#include "ui/window.h"
@ -147,7 +149,35 @@ public:
, m_showUI(true) { }
Command* clone() const override { return new GotoFrameCommand(*this); }
protected:
private:
// TODO this combobox is similar to FileSelector::CustomFileNameEntry
class TagsEntry : public ComboBox {
public:
TagsEntry(FrameTags& frameTags)
: m_frameTags(frameTags) {
setEditable(true);
getEntryWidget()->Change.connect(&TagsEntry::onEntryChange, this);
}
private:
void onEntryChange() {
removeAllItems();
closeListBox();
MatchWords match(getEntryWidget()->text());
for (const auto& frameTag : m_frameTags) {
if (match(frameTag->name()))
addItem(frameTag->name());
}
if (getItemCount() > 0)
openListBox();
}
FrameTags& m_frameTags;
};
void onLoadParams(const Params& params) override {
std::string frame = params.get("frame");
if (!frame.empty()) {
@ -163,13 +193,35 @@ protected:
if (m_showUI) {
app::gen::GotoFrame window;
window.frame()->setTextf(
TagsEntry combobox(editor->sprite()->frameTags());
window.framePlaceholder()->addChild(&combobox);
combobox.setFocusMagnet(true);
combobox.getEntryWidget()->setTextf(
"%d", editor->frame()+docPref.timeline.firstFrame());
window.openWindowInForeground();
if (window.closer() != window.ok())
return editor->frame();
m_frame = window.frame()->textInt();
std::string text = combobox.getEntryWidget()->text();
frame_t frameNum = base::convert_to<int>(text);
std::string textFromInt = base::convert_to<std::string>(frameNum);
if (text == textFromInt) {
m_frame = frameNum;
}
// Search a tag name
else {
MatchWords match(text);
for (const auto& frameTag : editor->sprite()->frameTags()) {
if (match(frameTag->name())) {
m_frame =
frameTag->fromFrame()+docPref.timeline.firstFrame();
break;
}
}
}
}
return MID(0, m_frame-docPref.timeline.firstFrame(), editor->sprite()->lastFrame());