2015-02-12 12:16:25 -03: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-05 21:20:19 -03:00
|
|
|
|
|
|
|
#ifndef APP_CONTEXT_H_INCLUDED
|
|
|
|
#define APP_CONTEXT_H_INCLUDED
|
2014-03-29 19:40:17 -03:00
|
|
|
#pragma once
|
2013-08-05 21:20:19 -03:00
|
|
|
|
2015-03-11 15:40:22 -03:00
|
|
|
#include "app/commands/params.h"
|
2013-08-05 21:20:19 -03:00
|
|
|
#include "app/context_flags.h"
|
|
|
|
#include "base/disable_copying.h"
|
|
|
|
#include "base/exception.h"
|
2014-07-29 00:53:24 -03:00
|
|
|
#include "base/signal.h"
|
|
|
|
#include "doc/context.h"
|
2013-08-05 21:20:19 -03: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 00:53:24 -03:00
|
|
|
class Context : public doc::Context {
|
2013-08-05 21:20:19 -03:00
|
|
|
public:
|
2014-07-19 22:01:39 -03:00
|
|
|
Context();
|
2013-08-05 21:20:19 -03:00
|
|
|
|
2015-05-18 17:04:31 -03:00
|
|
|
virtual bool isUIAvailable() const { return false; }
|
2013-08-05 21:20:19 -03: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 00:53:24 -03:00
|
|
|
void sendDocumentToTop(doc::Document* document);
|
2013-08-05 21:20:19 -03:00
|
|
|
|
2014-07-29 00:53:24 -03:00
|
|
|
app::Document* activeDocument() const;
|
2013-08-05 21:20:19 -03:00
|
|
|
|
2014-11-08 19:57:46 -03:00
|
|
|
void executeCommand(const char* commandName);
|
2015-03-11 15:40:22 -03:00
|
|
|
virtual void executeCommand(Command* command, const Params& params = Params());
|
2013-08-05 21:20:19 -03:00
|
|
|
|
2014-08-08 01:00:02 -03:00
|
|
|
Signal1<void, Command*> BeforeCommandExecution;
|
|
|
|
Signal1<void, Command*> AfterCommandExecution;
|
2013-08-05 21:20:19 -03:00
|
|
|
|
|
|
|
protected:
|
2014-08-14 23:07:47 -03:00
|
|
|
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
|
2013-08-05 21:20:19 -03:00
|
|
|
|
|
|
|
private:
|
|
|
|
// Last updated flags.
|
|
|
|
ContextFlags m_flags;
|
|
|
|
|
|
|
|
DISABLE_COPYING(Context);
|
|
|
|
};
|
|
|
|
|
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
#endif
|