aseprite/src/app/commands/cmd_exit.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

74 lines
1.6 KiB
C++
Raw Normal View History

2015-02-12 23:16:25 +08:00
// Aseprite
// Copyright (C) 2021 Igara Studio S.A.
2017-11-30 22:57:18 +08:00
// Copyright (C) 2001-2017 David Capello
2015-02-12 23:16:25 +08:00
//
2016-08-27 04:02:58 +08:00
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif
#include "app/app.h"
#include "app/commands/command.h"
#include "app/commands/commands.h"
#include "app/context.h"
2018-07-07 22:54:44 +08:00
#include "app/doc.h"
#include "app/job.h"
#include "app/ui/main_window.h"
2012-06-18 09:49:58 +08:00
#include "ui/alert.h"
#ifdef ENABLE_SCRIPTING
#include "app/commands/debugger.h"
#endif
namespace app {
class ExitCommand : public Command {
public:
ExitCommand();
protected:
void onExecute(Context* context) override;
};
2025-07-24 07:00:12 +08:00
ExitCommand::ExitCommand() : Command(CommandId::Exit())
{
}
void ExitCommand::onExecute(Context* ctx)
{
// Ignore ExitCommand when we are saving documents or doing a
// background task
if (Job::runningJobs() > 0)
return;
#ifdef ENABLE_SCRIPTING
if (auto debuggerCommand = dynamic_cast<DebuggerCommand*>(
Commands::instance()->byId(CommandId::Debugger()))) {
debuggerCommand->closeDebugger(ctx);
}
#endif
if (ctx->hasModifiedDocuments()) {
Command* closeAll = Commands::instance()->byId(CommandId::CloseAllFiles());
Params params;
params.set("quitting", "1");
ctx->executeCommand(closeAll, params);
// The user didn't save all documents (canceled the exit)
if (ctx->hasModifiedDocuments())
return;
}
// Close the window
App::instance()->mainWindow()->closeWindow(NULL);
}
Command* CommandFactory::createExitCommand()
{
return new ExitCommand;
}
} // namespace app