Add --oneframe CLI param to load just one frame

This commit is contained in:
David Capello 2016-12-01 12:06:35 -03:00
parent 83bd999f41
commit 4813936a3a
8 changed files with 89 additions and 67 deletions

View File

@ -61,6 +61,7 @@ AppOptions::AppOptions(int argc, const char* argv[])
#endif
, m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data"))
, m_listTags(m_po.add("list-tags").description("List tags of the next given sprite sprite\nor include frame tags in JSON data"))
, m_oneFrame(m_po.add("oneframe").description("Load just the first frame"))
, m_verbose(m_po.add("verbose").mnemonic('v').description("Explain what is being done"))
, m_debug(m_po.add("debug").description("Extreme verbose mode and\ncopy log to desktop"))
, m_help(m_po.add("help").mnemonic('?').description("Display this help and exits"))

View File

@ -75,6 +75,7 @@ public:
#endif
const Option& listLayers() const { return m_listLayers; }
const Option& listTags() const { return m_listTags; }
const Option& oneFrame() const { return m_oneFrame; }
bool hasExporterParams() const;
@ -123,6 +124,7 @@ private:
#endif
Option& m_listLayers;
Option& m_listTags;
Option& m_oneFrame;
Option& m_verbose;
Option& m_debug;

View File

@ -30,6 +30,7 @@ CliOpenFile::CliOpenFile()
listTags = false;
ignoreEmpty = false;
trim = false;
oneFrame = false;
crop = gfx::Rect();
}

View File

@ -34,6 +34,7 @@ namespace app {
bool listTags;
bool ignoreEmpty;
bool trim;
bool oneFrame;
gfx::Rect crop;
CliOpenFile();

View File

@ -372,6 +372,10 @@ void CliProcessor::process()
if (m_exporter)
m_exporter->setListFrameTags(true);
}
// --oneframe
else if (opt == &m_options.oneFrame()) {
cof.oneFrame = true;
}
}
// File names aren't associated to any option
else {
@ -412,6 +416,8 @@ bool CliProcessor::openFile(CliOpenFile& cof)
Command* openCommand = CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
Params params;
params.set("filename", cof.filename.c_str());
if (cof.oneFrame)
params.set("oneframe", "true");
ctx->executeCommand(openCommand, params);
app::Document* doc = ctx->activeDocument();

View File

@ -66,6 +66,9 @@ void PreviewCliDelegate::afterOpenFile(const CliOpenFile& cof)
if (cof.listTags)
std::cout << " - List tags\n";
if (cof.oneFrame)
std::cout << " - One frame\n";
if (cof.allLayers)
std::cout << " - Make all layers visible\n";

View File

@ -79,6 +79,7 @@ OpenFileCommand::OpenFileCommand()
"Open Sprite",
CmdRecordableFlag)
, m_repeatCheckbox(false)
, m_oneFrame(false)
, m_seqDecision(SequenceDecision::Ask)
{
}
@ -88,12 +89,13 @@ void OpenFileCommand::onLoadParams(const Params& params)
m_filename = params.get("filename");
m_folder = params.get("folder"); // Initial folder
m_repeatCheckbox = (params.get("repeat_checkbox") == "true");
m_oneFrame = (params.get("oneframe") == "true");
std::string sequence = params.get("sequence");
if (sequence == "agree")
m_seqDecision = SequenceDecision::Agree;
else if (sequence == "skip")
if (m_oneFrame || sequence == "skip")
m_seqDecision = SequenceDecision::Skip;
else if (sequence == "agree")
m_seqDecision = SequenceDecision::Agree;
else
m_seqDecision = SequenceDecision::Ask;
}
@ -117,7 +119,11 @@ void OpenFileCommand::onExecute(Context* context)
FileSelectorType::Open);
}
if (!m_filename.empty()) {
// The user cancelled the operation through UI or isn't a filename
// specified in params.
if (m_filename.empty())
return;
int flags = (m_repeatCheckbox ? FILE_LOAD_SEQUENCE_ASK_CHECKBOX: 0);
switch (m_seqDecision) {
@ -132,12 +138,18 @@ void OpenFileCommand::onExecute(Context* context)
break;
}
if (m_oneFrame)
flags |= FILE_LOAD_ONE_FRAME;
base::UniquePtr<FileOp> fop(
FileOp::createLoadDocumentOperation(
context, m_filename.c_str(), flags));
bool unrecent = false;
if (fop) {
// Do nothing (the user cancelled or something like that)
if (!fop)
return;
if (fop->hasError()) {
console.printf(fop->error().c_str());
unrecent = true;
@ -186,11 +198,6 @@ void OpenFileCommand::onExecute(Context* context)
App::instance()->recentFiles()->removeRecentFile(m_filename.c_str());
}
}
else {
// Do nothing (the user cancelled or something like that)
}
}
}
Command* CommandFactory::createOpenFileCommand()
{

View File

@ -36,6 +36,7 @@ namespace app {
std::string m_filename;
std::string m_folder;
bool m_repeatCheckbox;
bool m_oneFrame;
std::vector<std::string> m_usedFiles;
SequenceDecision m_seqDecision;
};