forked from aseprite/aseprite
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcontext.h
More file actions
85 lines (64 loc) · 2.16 KB
/
context.h
File metadata and controls
85 lines (64 loc) · 2.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
// Aseprite
// Copyright (C) 2001-2016 David Capello
//
// This program is distributed under the terms of
// the End-User License Agreement for Aseprite.
#ifndef APP_CONTEXT_H_INCLUDED
#define APP_CONTEXT_H_INCLUDED
#pragma once
#include "app/commands/params.h"
#include "app/context_flags.h"
#include "base/disable_copying.h"
#include "base/exception.h"
#include "doc/context.h"
#include "obs/signal.h"
#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.") { }
};
class CommandExecutionEvent {
public:
CommandExecutionEvent(Command* command)
: m_command(command), m_canceled(false) {
}
Command* command() const { return m_command; }
// True if the command was canceled or simulated by an
// observer/signal slot.
bool isCanceled() const { return m_canceled; }
void cancel() {
m_canceled = true;
}
private:
Command* m_command;
bool m_canceled;
};
class Context : public doc::Context {
public:
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; }
bool checkFlags(uint32_t flags) const { return m_flags.check(flags); }
void updateFlags() { m_flags.update(this); }
void sendDocumentToTop(doc::Document* document);
app::Document* activeDocument() const;
bool hasModifiedDocuments() const;
void executeCommand(const char* commandName);
virtual void executeCommand(Command* command, const Params& params = Params());
obs::signal<void (CommandExecutionEvent&)> BeforeCommandExecution;
obs::signal<void (CommandExecutionEvent&)> AfterCommandExecution;
protected:
virtual void onCreateDocument(doc::CreateDocumentArgs* args) override;
private:
// Last updated flags.
ContextFlags m_flags;
DISABLE_COPYING(Context);
};
} // namespace app
#endif