Avoid processing the same file two times when it's used to load a sequence

E.g. If we drop three files (1.png, 2.png, and 3.png), and we load 1.png
as a sequence, we don't want to ask for the third file.
This commit is contained in:
David Capello 2016-11-14 19:44:29 -03:00
parent 2216db2d2c
commit 2240742816
3 changed files with 27 additions and 24 deletions

View File

@ -8,6 +8,8 @@
#include "config.h"
#endif
#include "app/commands/cmd_open_file.h"
#include "app/app.h"
#include "app/commands/command.h"
#include "app/commands/params.h"
@ -32,20 +34,6 @@
namespace app {
class OpenFileCommand : public Command {
public:
OpenFileCommand();
Command* clone() const override { return new OpenFileCommand(*this); }
protected:
void onLoadParams(const Params& params) override;
void onExecute(Context* context) override;
private:
std::string m_filename;
std::string m_folder;
};
class OpenFileJob : public Job, public IFileOpProgress
{
public:
@ -104,6 +92,8 @@ void OpenFileCommand::onExecute(Context* context)
{
Console console;
m_usedFiles.clear();
// interactive
if (context->isUIAvailable() && m_filename.empty()) {
std::string exts = get_readable_extensions();
@ -129,6 +119,11 @@ void OpenFileCommand::onExecute(Context* context)
unrecent = true;
}
else {
if (fop->isSequence())
m_usedFiles = fop->filenames();
else
m_usedFiles.push_back(fop->filename());
OpenFileJob task(fop);
task.showProgressWindow();

View File

@ -1,5 +1,5 @@
// Aseprite
// Copyright (C) 2001-2015 David Capello
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
@ -69,6 +69,7 @@ namespace app {
bool isOneFrame() const { return m_oneframe; }
const std::string& filename() const { return m_filename; }
const std::vector<std::string>& filenames() const { return m_seq.filename_list; }
Context* context() const { return m_context; }
Document* document() const { return m_document; }
Document* releaseDocument() {

View File

@ -9,6 +9,7 @@
#endif
#include "app/app.h"
#include "app/commands/cmd_open_file.h"
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/commands/params.h"
@ -345,16 +346,13 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
case kDropFilesMessage:
{
const DropFilesMessage::Files& files = static_cast<DropFilesMessage*>(msg)->files();
// Open all files
Command* cmd_open_file =
CommandsModule::instance()->getCommandByName(CommandId::OpenFile);
Params params;
DropFilesMessage::Files files = static_cast<DropFilesMessage*>(msg)->files();
UIContext* ctx = UIContext::instance();
for (const auto& fn : files) {
while (!files.empty()) {
auto fn = files.front();
files.erase(files.begin());
// If the document is already open, select it.
Document* doc = static_cast<Document*>(ctx->documents().getByFileName(fn));
if (doc) {
@ -367,8 +365,17 @@ bool CustomizedGuiManager::onProcessMessage(Message* msg)
}
// Load the file
else {
OpenFileCommand cmd;
Params params;
params.set("filename", fn.c_str());
ctx->executeCommand(cmd_open_file, params);
ctx->executeCommand(&cmd, params);
// Remove all used file names from the "dropped files"
for (const auto& usedFn : cmd.usedFiles()) {
auto it = std::find(files.begin(), files.end(), usedFn);
if (it != files.end())
files.erase(it);
}
}
}
}