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.
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
#ifndef APP_CONTEXT_H_INCLUDED
|
|
|
|
|
#define APP_CONTEXT_H_INCLUDED
|
2014-03-30 06:40:17 +08:00
|
|
|
#pragma once
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2015-03-12 02:40:22 +08:00
|
|
|
#include "app/commands/params.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
#include "app/context_flags.h"
|
|
|
|
|
#include "base/disable_copying.h"
|
|
|
|
|
#include "base/exception.h"
|
2014-07-29 11:53:24 +08:00
|
|
|
#include "base/signal.h"
|
|
|
|
|
#include "doc/context.h"
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
#include <vector>
|
|
|
|
|
|
|
|
|
|
namespace app {
|
|
|
|
|
class Command;
|
|
|
|
|
class Document;
|
|
|
|
|
|
|
|
|
|
class CommandPreconditionException : public base::Exception {
|
|
|
|
|
public:
|
|
|
|
|
CommandPreconditionException() throw()
|
|
|
|
|
: base::Exception("Cannot execute the command because its pre-conditions are false.") { }
|
|
|
|
|
};
|
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
class Context : public doc::Context {
|
2013-08-06 08:20:19 +08:00
|
|
|
public:
|
2014-07-20 09:01:39 +08:00
|
|
|
Context();
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2015-05-19 04:04:31 +08:00
|
|
|
virtual bool isUIAvailable() const { return false; }
|
2013-08-06 08:20:19 +08:00
|
|
|
virtual bool isRecordingMacro() const { return false; }
|
|
|
|
|
virtual bool isExecutingMacro() const { return false; }
|
|
|
|
|
virtual bool isExecutingScript() const { return false; }
|
|
|
|
|
|
|
|
|
|
bool checkFlags(uint32_t flags) const { return m_flags.check(flags); }
|
|
|
|
|
void updateFlags() { m_flags.update(this); }
|
|
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
void sendDocumentToTop(doc::Document* document);
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-07-29 11:53:24 +08:00
|
|
|
app::Document* activeDocument() const;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-11-09 06:57:46 +08:00
|
|
|
void executeCommand(const char* commandName);
|
2015-03-12 02:40:22 +08:00
|
|
|
virtual void executeCommand(Command* command, const Params& params = Params());
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-08-08 12:00:02 +08:00
|
|
|
Signal1<void, Command*> BeforeCommandExecution;
|
|
|
|
|
Signal1<void, Command*> AfterCommandExecution;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
protected:
|
2014-08-15 10:07:47 +08:00
|
|
|
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Last updated flags.
|
|
|
|
|
ContextFlags m_flags;
|
|
|
|
|
|
|
|
|
|
DISABLE_COPYING(Context);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
|
|
#endif
|