2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2016-04-23 00:19:06 +08:00
|
|
|
// Copyright (C) 2001-2016 David Capello
|
2015-02-12 23:16:25 +08:00
|
|
|
//
|
|
|
|
// 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
|
|
|
|
|
|
|
|
#include "app/app.h"
|
|
|
|
#include "app/commands/command.h"
|
|
|
|
#include "app/commands/commands.h"
|
|
|
|
#include "app/context_access.h"
|
|
|
|
#include "app/document_access.h"
|
|
|
|
#include "app/modules/editors.h"
|
|
|
|
#include "app/ui/document_view.h"
|
|
|
|
#include "app/ui/status_bar.h"
|
|
|
|
#include "app/ui/workspace.h"
|
|
|
|
#include "app/ui_context.h"
|
2014-10-21 09:21:31 +08:00
|
|
|
#include "doc/sprite.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "ui/ui.h"
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2012-08-11 21:42:51 +08:00
|
|
|
#include <memory>
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
namespace app {
|
|
|
|
|
2012-06-18 09:02:54 +08:00
|
|
|
using namespace ui;
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class CloseFileCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
CloseFileCommand()
|
|
|
|
: Command("CloseFile",
|
|
|
|
"Close File",
|
2015-02-23 08:18:53 +08:00
|
|
|
CmdUIOnlyFlag) {
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new CloseFileCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2015-02-23 08:18:53 +08:00
|
|
|
bool onEnabled(Context* context) override {
|
2016-04-23 00:19:06 +08:00
|
|
|
Workspace* workspace = App::instance()->workspace();
|
2015-02-23 08:18:53 +08:00
|
|
|
WorkspaceView* view = workspace->activeView();
|
|
|
|
return (view != nullptr);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-02-23 08:18:53 +08:00
|
|
|
void onExecute(Context* context) override {
|
2016-04-23 00:19:06 +08:00
|
|
|
Workspace* workspace = App::instance()->workspace();
|
2014-07-29 11:53:24 +08:00
|
|
|
WorkspaceView* view = workspace->activeView();
|
2015-02-23 08:18:53 +08:00
|
|
|
if (view)
|
2016-06-09 00:27:36 +08:00
|
|
|
workspace->closeView(view, false);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2013-08-06 08:20:19 +08:00
|
|
|
class CloseAllFilesCommand : public Command {
|
2012-01-06 06:45:03 +08:00
|
|
|
public:
|
|
|
|
CloseAllFilesCommand()
|
|
|
|
: Command("CloseAllFiles",
|
|
|
|
"Close All Files",
|
2015-02-23 08:18:53 +08:00
|
|
|
CmdRecordableFlag) {
|
2016-06-09 00:27:36 +08:00
|
|
|
m_quitting = false;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2014-08-15 10:07:47 +08:00
|
|
|
Command* clone() const override { return new CloseAllFilesCommand(*this); }
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
protected:
|
|
|
|
|
2016-06-09 00:27:36 +08:00
|
|
|
void onLoadParams(const Params& params) override {
|
|
|
|
m_quitting = params.get_as<bool>("quitting");
|
|
|
|
}
|
|
|
|
|
2015-02-23 08:18:53 +08:00
|
|
|
void onExecute(Context* context) override {
|
2016-04-23 00:19:06 +08:00
|
|
|
Workspace* workspace = App::instance()->workspace();
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-15 00:06:26 +08:00
|
|
|
// Collect all document views
|
|
|
|
DocumentViews docViews;
|
2015-02-23 08:18:53 +08:00
|
|
|
for (auto view : *workspace) {
|
|
|
|
DocumentView* docView = dynamic_cast<DocumentView*>(view);
|
|
|
|
if (docView)
|
|
|
|
docViews.push_back(docView);
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2015-02-23 08:18:53 +08:00
|
|
|
for (auto docView : docViews) {
|
2016-06-09 00:27:36 +08:00
|
|
|
if (!workspace->closeView(docView, m_quitting))
|
2015-02-23 08:18:53 +08:00
|
|
|
break;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
}
|
2013-01-21 05:40:37 +08:00
|
|
|
|
2016-06-09 00:27:36 +08:00
|
|
|
private:
|
|
|
|
bool m_quitting;
|
2015-02-23 08:18:53 +08:00
|
|
|
};
|
2012-01-06 06:45:03 +08:00
|
|
|
|
|
|
|
Command* CommandFactory::createCloseFileCommand()
|
|
|
|
{
|
|
|
|
return new CloseFileCommand;
|
|
|
|
}
|
|
|
|
|
|
|
|
Command* CommandFactory::createCloseAllFilesCommand()
|
|
|
|
{
|
|
|
|
return new CloseAllFilesCommand;
|
|
|
|
}
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
} // namespace app
|