1// Aseprite
2// Copyright (C) 2019 Igara Studio S.A.
3//
4// This program is distributed under the terms of
5// the End-User License Agreement for Aseprite.
6
7#ifdef HAVE_CONFIG_H
8#include "config.h"
9#endif
10
11#include "app/app.h"
12#include "app/commands/command.h"
13#include "app/commands/commands.h"
14#include "app/doc.h"
15#include "app/ui_context.h"
16
17#include <cstdio>
18
19namespace app {
20
21class ReopenClosedFileCommand : public Command {
22public:
23 ReopenClosedFileCommand();
24protected:
25 bool onEnabled(Context* context) override;
26 void onExecute(Context* context) override;
27};
28
29ReopenClosedFileCommand::ReopenClosedFileCommand()
30 : Command(CommandId::ReopenClosedFile(), CmdUIOnlyFlag)
31{
32}
33
34bool ReopenClosedFileCommand::onEnabled(Context* ctx)
35{
36 if (auto uiCtx = dynamic_cast<UIContext*>(ctx)) {
37 return uiCtx->hasClosedDocs();
38 }
39 return false;
40}
41
42void ReopenClosedFileCommand::onExecute(Context* ctx)
43{
44 if (auto uiCtx = dynamic_cast<UIContext*>(ctx))
45 uiCtx->reopenLastClosedDoc();
46}
47
48Command* CommandFactory::createReopenClosedFileCommand()
49{
50 return new ReopenClosedFileCommand;
51}
52
53} // namespace app
54