Skip to content

Commit

Permalink
Fix opening image sequences more times from CLI
Browse files Browse the repository at this point in the history
We've also fixed the Agree/Skip dialog to show a checkbox and repeat
the same action for all image sequences.

Fixes:
#2128
#1936 (comment)
  • Loading branch information
dacap committed Jul 30, 2020
1 parent 4cc2c61 commit 1255b17
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 7 deletions.
2 changes: 1 addition & 1 deletion laf
1 change: 1 addition & 0 deletions src/app/app.cpp
Expand Up @@ -347,6 +347,7 @@ int App::initialize(const AppOptions& options)
return code;
}

LOG("APP: Finish launching...\n");
system->finishLaunching();
return 0;
}
Expand Down
38 changes: 36 additions & 2 deletions src/app/cli/cli_processor.cpp
Expand Up @@ -33,6 +33,7 @@
#include "doc/slice.h"
#include "doc/tag.h"
#include "doc/tags.h"
#include "os/system.h"
#include "render/dithering_algorithm.h"

#include <algorithm>
Expand Down Expand Up @@ -576,8 +577,14 @@ int CliProcessor::process(Context* ctx)
else {
cof.document = nullptr;
cof.filename = base::normalize_path(value.value());
if (openFile(ctx, cof))

if (// Check that the filename wasn't used loading a sequence
// of images as one sprite
m_usedFiles.find(cof.filename) == m_usedFiles.end() &&
// Open sprite
openFile(ctx, cof)) {
lastDoc = cof.document;
}
}
}

Expand Down Expand Up @@ -610,13 +617,40 @@ bool CliProcessor::openFile(Context* ctx, CliOpenFile& cof)
m_delegate->beforeOpenFile(cof);

Doc* oldDoc = ctx->activeDocument();
Command* openCommand = Commands::instance()->byId(CommandId::OpenFile());
auto openCommand = static_cast<OpenFileCommand*>(Commands::instance()->byId(CommandId::OpenFile()));
Params params;
params.set("filename", cof.filename.c_str());
if (cof.oneFrame)
params.set("oneframe", "true");
else {
switch (m_lastDecision) {
case OpenFileCommand::SequenceDecision::Ask:
params.set("sequence", "ask");
params.set("repeat_checkbox", "true");
break;
case OpenFileCommand::SequenceDecision::Skip:
params.set("sequence", "skip");
break;
case OpenFileCommand::SequenceDecision::Agree:
params.set("sequence", "agree");
break;
}
}
ctx->executeCommand(openCommand, params);

// Mark used file names as "already processed" so we don't try to
// open then again
for (const auto& usedFn : openCommand->usedFiles()) {
auto fn = base::normalize_path(usedFn);
m_usedFiles.insert(fn);

os::instance()->markCliFileAsProcessed(fn);
}

// Future decision for other files in the CLI
if (openCommand->seqDecision() != OpenFileCommand::SequenceDecision::Ask)
m_lastDecision = openCommand->seqDecision();

Doc* doc = ctx->activeDocument();
// If the active document is equal to the previous one, it
// means that we couldn't open this specific document.
Expand Down
9 changes: 8 additions & 1 deletion src/app/cli/cli_processor.h
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
Expand All @@ -11,10 +11,12 @@

#include "app/cli/cli_delegate.h"
#include "app/cli/cli_open_file.h"
#include "app/commands/cmd_open_file.h"
#include "app/doc_exporter.h"
#include "doc/selected_layers.h"

#include <memory>
#include <set>
#include <string>
#include <vector>

Expand Down Expand Up @@ -58,6 +60,11 @@ namespace app {
CliDelegate* m_delegate;
const AppOptions& m_options;
std::unique_ptr<DocExporter> m_exporter;

// Files already used in the CLI processing (e.g. when used to
// load a sequence of files) so we don't ask for them again.
std::set<std::string> m_usedFiles;
OpenFileCommand::SequenceDecision m_lastDecision = OpenFileCommand::SequenceDecision::Ask;
};

} // namespace app
Expand Down
4 changes: 1 addition & 3 deletions src/app/commands/cmd_open_file.cpp
@@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2019 Igara Studio S.A.
// Copyright (C) 2019-2020 Igara Studio S.A.
// Copyright (C) 2001-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -169,14 +169,12 @@ void OpenFileCommand::onExecute(Context* context)
}
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 {
Expand Down
5 changes: 5 additions & 0 deletions src/app/commands/cmd_open_file.h
@@ -1,4 +1,5 @@
// Aseprite
// Copyright (C) 2020 Igara Studio S.A.
// Copyright (C) 2016-2018 David Capello
//
// This program is distributed under the terms of
Expand Down Expand Up @@ -27,6 +28,10 @@ namespace app {
return m_usedFiles;
}

SequenceDecision seqDecision() const {
return m_seqDecision;
}

protected:
void onLoadParams(const Params& params) override;
void onExecute(Context* context) override;
Expand Down

0 comments on commit 1255b17

Please sign in to comment.