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 #endif
, m_listLayers(m_po.add("list-layers").description("List layers of the next given sprite\nor include layers in JSON data")) , 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_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_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_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")) , m_help(m_po.add("help").mnemonic('?').description("Display this help and exits"))

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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