30
30
// Aegisub Project http://www.aegisub.org/
32
#include "../config.h"
34
32
#include "command.h"
36
34
#include "../include/aegisub/context.h"
35
#include "../libresrc/libresrc.h"
37
36
#include "../options.h"
37
#include "../project.h"
38
38
#include "../utils.h"
39
#include "../video_context.h"
41
#include <libaegisub/util.h>
40
#include <libaegisub/keyframe.h>
41
#include <libaegisub/make_unique.h>
44
44
using cmd::Command;
46
struct keyframe_close : public Command {
46
struct keyframe_close final : public Command {
47
47
CMD_NAME("keyframe/close")
48
CMD_ICON(close_keyframes_menu)
48
49
STR_MENU("Close Keyframes")
49
50
STR_DISP("Close Keyframes")
50
51
STR_HELP("Discard the currently loaded keyframes and use those from the video, if any")
51
52
CMD_TYPE(COMMAND_VALIDATE)
53
54
bool Validate(const agi::Context *c) override {
54
return c->videoController->OverKeyFramesLoaded();
55
return c->project->CanCloseKeyframes();
57
58
void operator()(agi::Context *c) override {
58
c->videoController->CloseKeyframes();
59
c->project->CloseKeyframes();
62
struct keyframe_open : public Command {
63
struct keyframe_open final : public Command {
63
64
CMD_NAME("keyframe/open")
65
CMD_ICON(open_keyframes_menu)
64
66
STR_MENU("Open Keyframes...")
65
67
STR_DISP("Open Keyframes")
66
68
STR_HELP("Open a keyframe list file")
75
77
if (!filename.empty())
76
c->videoController->LoadKeyframes(filename);
78
c->project->LoadKeyframes(filename);
80
struct keyframe_save : public Command {
82
struct keyframe_save final : public Command {
81
83
CMD_NAME("keyframe/save")
84
CMD_ICON(save_keyframes_menu)
82
85
STR_MENU("Save Keyframes...")
83
86
STR_DISP("Save Keyframes")
84
87
STR_HELP("Save the current list of keyframes to a file")
85
88
CMD_TYPE(COMMAND_VALIDATE)
87
90
bool Validate(const agi::Context *c) override {
88
return c->videoController->KeyFramesLoaded();
91
return !c->project->Keyframes().empty();
91
94
void operator()(agi::Context *c) override {
92
95
auto filename = SaveFileSelector(_("Save keyframes file"), "Path/Last/Keyframes", "", "*.key.txt", "Text files (*.txt)|*.txt", c->parent);
93
if (!filename.empty())
94
c->videoController->SaveKeyframes(filename);
96
if (filename.empty()) return;
98
agi::keyframe::Save(filename, c->project->Keyframes());
99
config::mru->Add("Keyframes", filename);
100
105
void init_keyframe() {
101
reg(agi::util::make_unique<keyframe_close>());
102
reg(agi::util::make_unique<keyframe_open>());
103
reg(agi::util::make_unique<keyframe_save>());
106
reg(agi::make_unique<keyframe_close>());
107
reg(agi::make_unique<keyframe_open>());
108
reg(agi::make_unique<keyframe_save>());