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
|
|
|
|
|
|
|
|
#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 DocumentLocation;
|
|
|
|
|
class ISettings;
|
|
|
|
|
class Params;
|
|
|
|
|
|
|
|
|
|
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();
|
|
|
|
|
// The "settings" are deleted automatically in the ~Context destructor
|
|
|
|
|
Context(ISettings* settings);
|
2013-08-06 08:20:19 +08:00
|
|
|
virtual ~Context();
|
|
|
|
|
|
|
|
|
|
virtual bool isUiAvailable() const { return false; }
|
|
|
|
|
virtual bool isRecordingMacro() const { return false; }
|
|
|
|
|
virtual bool isExecutingMacro() const { return false; }
|
|
|
|
|
virtual bool isExecutingScript() const { return false; }
|
|
|
|
|
|
2015-01-19 09:05:33 +08:00
|
|
|
app::ISettings* settings() { return m_settings; }
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
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;
|
|
|
|
|
DocumentLocation activeLocation() const;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
2014-11-09 06:57:46 +08:00
|
|
|
void executeCommand(const char* commandName);
|
2013-08-06 08:20:19 +08:00
|
|
|
virtual void executeCommand(Command* command, Params* params = NULL);
|
|
|
|
|
|
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;
|
2014-07-20 09:01:39 +08:00
|
|
|
virtual void onGetActiveLocation(DocumentLocation* location) const;
|
2013-08-06 08:20:19 +08:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
// Settings in this context.
|
|
|
|
|
ISettings* m_settings;
|
|
|
|
|
|
|
|
|
|
// Last updated flags.
|
|
|
|
|
ContextFlags m_flags;
|
|
|
|
|
|
|
|
|
|
DISABLE_COPYING(Context);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace app
|
|
|
|
|
|
|
|
|
|
#endif
|