1// Aseprite
2// Copyright (C) 2020-2021 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifndef APP_UTIL_OPEN_BATCH_H_INCLUDED
8#define APP_UTIL_OPEN_BATCH_H_INCLUDED
9#pragma once
10
11#include "app/commands/cmd_open_file.h"
12#include "app/context.h"
13
14namespace app {
15
16 // Helper class to a batch of files and handle the loading of image
17 // sequences and repeat the selected action of the user (Agree/Skip
18 // to open the sequence, and Repeat the action for all other
19 // elements)
20 class OpenBatchOfFiles {
21 public:
22 void open(Context* ctx,
23 const std::string& fn,
24 const bool oneFrame) {
25 Params params;
26 params.set("filename", fn.c_str());
27
28 if (oneFrame)
29 params.set("oneframe", "true");
30 else {
31 switch (m_lastDecision) {
32 case gen::SequenceDecision::ASK:
33 params.set("sequence", "ask");
34 params.set("repeat_checkbox", "true");
35 break;
36 case gen::SequenceDecision::NO:
37 params.set("sequence", "skip");
38 break;
39 case gen::SequenceDecision::YES:
40 params.set("sequence", "agree");
41 break;
42 }
43 }
44
45 if (ctx->isUIAvailable())
46 ctx->executeCommandFromMenuOrShortcut(&m_cmd, params);
47 else
48 ctx->executeCommand(&m_cmd, params);
49
50 // Future decision for other files in the CLI
51 auto d = m_cmd.seqDecision();
52 if (d != gen::SequenceDecision::ASK)
53 m_lastDecision = d;
54 }
55
56 const base::paths& usedFiles() const {
57 return m_cmd.usedFiles();
58 }
59
60 private:
61 OpenFileCommand m_cmd;
62 gen::SequenceDecision m_lastDecision = gen::SequenceDecision::ASK;
63 };
64
65} // namespace app
66
67#endif
68