From 4813936a3a7b8bdfc0476296fee47769d77dfa23 Mon Sep 17 00:00:00 2001 From: David Capello Date: Thu, 1 Dec 2016 12:06:35 -0300 Subject: [PATCH] Add --oneframe CLI param to load just one frame --- src/app/cli/app_options.cpp | 1 + src/app/cli/app_options.h | 2 + src/app/cli/cli_open_file.cpp | 1 + src/app/cli/cli_open_file.h | 1 + src/app/cli/cli_processor.cpp | 6 ++ src/app/cli/preview_cli_delegate.cpp | 3 + src/app/commands/cmd_open_file.cpp | 141 ++++++++++++++------------- src/app/commands/cmd_open_file.h | 1 + 8 files changed, 89 insertions(+), 67 deletions(-) diff --git a/src/app/cli/app_options.cpp b/src/app/cli/app_options.cpp index 127cb5e91..beea8d297 100644 --- a/src/app/cli/app_options.cpp +++ b/src/app/cli/app_options.cpp @@ -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")) diff --git a/src/app/cli/app_options.h b/src/app/cli/app_options.h index aeb6c9a13..cec379c06 100644 --- a/src/app/cli/app_options.h +++ b/src/app/cli/app_options.h @@ -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; diff --git a/src/app/cli/cli_open_file.cpp b/src/app/cli/cli_open_file.cpp index 10c9ff1da..4e41a174d 100644 --- a/src/app/cli/cli_open_file.cpp +++ b/src/app/cli/cli_open_file.cpp @@ -30,6 +30,7 @@ CliOpenFile::CliOpenFile() listTags = false; ignoreEmpty = false; trim = false; + oneFrame = false; crop = gfx::Rect(); } diff --git a/src/app/cli/cli_open_file.h b/src/app/cli/cli_open_file.h index 264f89985..d9d1dda67 100644 --- a/src/app/cli/cli_open_file.h +++ b/src/app/cli/cli_open_file.h @@ -34,6 +34,7 @@ namespace app { bool listTags; bool ignoreEmpty; bool trim; + bool oneFrame; gfx::Rect crop; CliOpenFile(); diff --git a/src/app/cli/cli_processor.cpp b/src/app/cli/cli_processor.cpp index 2877345e3..8cf28f8fc 100644 --- a/src/app/cli/cli_processor.cpp +++ b/src/app/cli/cli_processor.cpp @@ -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(); diff --git a/src/app/cli/preview_cli_delegate.cpp b/src/app/cli/preview_cli_delegate.cpp index f58ed6725..6bd617ceb 100644 --- a/src/app/cli/preview_cli_delegate.cpp +++ b/src/app/cli/preview_cli_delegate.cpp @@ -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"; diff --git a/src/app/commands/cmd_open_file.cpp b/src/app/commands/cmd_open_file.cpp index 5038bea76..1d6516880 100644 --- a/src/app/commands/cmd_open_file.cpp +++ b/src/app/commands/cmd_open_file.cpp @@ -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; } @@ -114,81 +116,86 @@ void OpenFileCommand::onExecute(Context* context) m_folder.push_back(base::path_separator); m_filename = app::show_file_selector("Open", m_folder, exts, - FileSelectorType::Open); + FileSelectorType::Open); } - if (!m_filename.empty()) { - int flags = (m_repeatCheckbox ? FILE_LOAD_SEQUENCE_ASK_CHECKBOX: 0); + // The user cancelled the operation through UI or isn't a filename + // specified in params. + if (m_filename.empty()) + return; - switch (m_seqDecision) { - case SequenceDecision::Ask: - flags |= FILE_LOAD_SEQUENCE_ASK; - break; - case SequenceDecision::Agree: - flags |= FILE_LOAD_SEQUENCE_YES; - break; - case SequenceDecision::Skip: - flags |= FILE_LOAD_SEQUENCE_NONE; - break; - } + int flags = (m_repeatCheckbox ? FILE_LOAD_SEQUENCE_ASK_CHECKBOX: 0); - base::UniquePtr fop( - FileOp::createLoadDocumentOperation( - context, m_filename.c_str(), flags)); - bool unrecent = false; + switch (m_seqDecision) { + case SequenceDecision::Ask: + flags |= FILE_LOAD_SEQUENCE_ASK; + break; + case SequenceDecision::Agree: + flags |= FILE_LOAD_SEQUENCE_YES; + break; + case SequenceDecision::Skip: + flags |= FILE_LOAD_SEQUENCE_NONE; + break; + } - if (fop) { - if (fop->hasError()) { - console.printf(fop->error().c_str()); - unrecent = true; + if (m_oneFrame) + flags |= FILE_LOAD_ONE_FRAME; + + base::UniquePtr fop( + FileOp::createLoadDocumentOperation( + context, m_filename.c_str(), flags)); + bool unrecent = false; + + // Do nothing (the user cancelled or something like that) + if (!fop) + return; + + if (fop->hasError()) { + console.printf(fop->error().c_str()); + unrecent = true; + } + else { + if (fop->isSequence()) { + + if (fop->sequenceFlags() & FILE_LOAD_SEQUENCE_YES) { + m_seqDecision = SequenceDecision::Agree; } - else { - if (fop->isSequence()) { - - if (fop->sequenceFlags() & FILE_LOAD_SEQUENCE_YES) { - m_seqDecision = SequenceDecision::Agree; - } - else if (fop->sequenceFlags() & FILE_LOAD_SEQUENCE_NONE) { - m_seqDecision = SequenceDecision::Skip; - } - - m_usedFiles = fop->filenames(); - } - else { - m_usedFiles.push_back(fop->filename()); - } - - OpenFileJob task(fop); - task.showProgressWindow(); - - // Post-load processing, it is called from the GUI because may require user intervention. - fop->postLoad(); - - // Show any error - if (fop->hasError() && !fop->isStop()) - console.printf(fop->error().c_str()); - - Document* document = fop->document(); - if (document) { - if (context->isUIAvailable()) - App::instance()->recentFiles()->addRecentFile(fop->filename().c_str()); - - document->setContext(context); - } - else if (!fop->isStop()) - unrecent = true; + else if (fop->sequenceFlags() & FILE_LOAD_SEQUENCE_NONE) { + m_seqDecision = SequenceDecision::Skip; } - // The file was not found or was loaded loaded with errors, - // so we can remove it from the recent-file list - if (unrecent) { - if (context->isUIAvailable()) - App::instance()->recentFiles()->removeRecentFile(m_filename.c_str()); - } + m_usedFiles = fop->filenames(); } else { - // Do nothing (the user cancelled or something like that) + m_usedFiles.push_back(fop->filename()); } + + OpenFileJob task(fop); + task.showProgressWindow(); + + // Post-load processing, it is called from the GUI because may require user intervention. + fop->postLoad(); + + // Show any error + if (fop->hasError() && !fop->isStop()) + console.printf(fop->error().c_str()); + + Document* document = fop->document(); + if (document) { + if (context->isUIAvailable()) + App::instance()->recentFiles()->addRecentFile(fop->filename().c_str()); + + document->setContext(context); + } + else if (!fop->isStop()) + unrecent = true; + } + + // The file was not found or was loaded loaded with errors, + // so we can remove it from the recent-file list + if (unrecent) { + if (context->isUIAvailable()) + App::instance()->recentFiles()->removeRecentFile(m_filename.c_str()); } } diff --git a/src/app/commands/cmd_open_file.h b/src/app/commands/cmd_open_file.h index 827ed3411..a79c5c14a 100644 --- a/src/app/commands/cmd_open_file.h +++ b/src/app/commands/cmd_open_file.h @@ -36,6 +36,7 @@ namespace app { std::string m_filename; std::string m_folder; bool m_repeatCheckbox; + bool m_oneFrame; std::vector m_usedFiles; SequenceDecision m_seqDecision; };