2015-02-12 23:16:25 +08:00
|
|
|
// Aseprite
|
2024-04-18 02:16:01 +08:00
|
|
|
// Copyright (C) 2024 Igara Studio S.A.
|
2018-07-15 09:47:03 +08:00
|
|
|
// Copyright (C) 2001-2018 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.
|
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"
|
2018-07-15 10:24:49 +08:00
|
|
|
#include "app/ui/doc_view.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/ui/workspace.h"
|
|
|
|
#include "app/ui_context.h"
|
2012-08-11 21:42:51 +08:00
|
|
|
|
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:
|
2025-08-06 02:59:31 +08:00
|
|
|
CloseFileCommand() : Command(CommandId::CloseFile()) {}
|
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();
|
2024-04-18 02:16:01 +08:00
|
|
|
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
|
|
|
|
return false;
|
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:
|
2025-08-06 02:59:31 +08:00
|
|
|
CloseAllFilesCommand() : Command(CommandId::CloseAllFiles()) { m_quitting = false; }
|
|
|
|
|
|
|
|
protected:
|
|
|
|
bool onEnabled(Context* context) override
|
2017-12-02 02:10:21 +08:00
|
|
|
{
|
2025-08-06 02:59:31 +08:00
|
|
|
// Null if we are in --batch mode
|
|
|
|
return App::instance()->workspace() != nullptr;
|
2012-01-06 06:45:03 +08:00
|
|
|
}
|
|
|
|
|
2016-06-09 00:27:36 +08:00
|
|
|
void onLoadParams(const Params& params) override { m_quitting = params.get_as<bool>("quitting"); }
|
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();
|
2024-04-18 02:16:01 +08:00
|
|
|
if (!workspace) // Workspace (main window) can be null if we are in --batch mode
|
|
|
|
return;
|
2012-01-06 06:45:03 +08:00
|
|
|
|
2015-08-15 00:06:26 +08:00
|
|
|
// Collect all document views
|
2018-07-15 10:24:49 +08:00
|
|
|
DocViews docViews;
|
2015-02-23 08:18:53 +08:00
|
|
|
for (auto view : *workspace) {
|
2018-07-15 10:24:49 +08:00
|
|
|
DocView* docView = dynamic_cast<DocView*>(view);
|
2015-02-23 08:18:53 +08:00
|
|
|
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
|