2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
|
|
|
// Copyright (C) 2001-2015 David Capello
|
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License version 2 as
|
|
|
|
// published by the Free Software Foundation.
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#ifdef HAVE_CONFIG_H
|
2012-01-06 06:45:03 +08:00
|
|
|
#include "config.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#endif
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/context.h"
|
|
|
|
#include "app/document.h"
|
|
|
|
#include "app/ui/main_window.h"
|
2012-06-18 09:49:58 +08:00
|
|
|
#include "ui/alert.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class ExitCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
ExitCommand();
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new ExitCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
void onExecute(Context* context);
|
|
|
|
};
|
|
|
|
|
|
|
|
ExitCommand::ExitCommand()
|
|
|
|
: Command("Exit",
|
|
|
|
"Exit",
|
|
|
|
CmdUIOnlyFlag)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void ExitCommand::onExecute(Context* context)
|
|
|
|
{
|
2014-07-29 11:53:24 +08:00
|
|
|
const doc::Documents& docs = context->documents();
|
2013-03-12 07:29:45 +08:00
|
|
|
bool modifiedFiles = false;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
for (doc::Documents::const_iterator it=docs.begin(), end=docs.end(); it!=end; ++it) {
|
|
|
|
const Document* document = static_cast<Document*>(*it);
|
2012-01-06 06:45:03 +08:00
|
|
|
if (document->isModified()) {
|
2013-03-12 07:29:45 +08:00
|
|
|
modifiedFiles = true;
|
2012-01-06 06:45:03 +08:00
|
|
|
break;
|
|
|
|
}
|
2013-03-12 07:29:45 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
if (modifiedFiles) {
|
|
|
|
if (ui::Alert::show("Warning<<There are sprites with changes.<<Do you want quit anyway?||&Yes||&No") != 1)
|
|
|
|
return; // In this case the user doesn't want to close with modified files
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
// Close the window
|
2012-07-10 00:20:58 +08:00
|
|
|
App::instance()->getMainWindow()->closeWindow(NULL);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createExitCommand()
|
|
|
|
{
|
|
|
|
return new ExitCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|