1 | // Aseprite |
2 | // Copyright (C) 2001-2018 David Capello |
3 | // |
4 | // This program is distributed under the terms of |
5 | // the End-User License Agreement for Aseprite. |
6 | |
7 | #ifndef APP_COMMANDS_COMMAND_H_INCLUDED |
8 | #define APP_COMMANDS_COMMAND_H_INCLUDED |
9 | #pragma once |
10 | |
11 | #include "app/commands/command_factory.h" |
12 | #include "app/commands/command_ids.h" |
13 | |
14 | #include <string> |
15 | |
16 | namespace app { |
17 | |
18 | class Context; |
19 | class Params; |
20 | |
21 | enum CommandFlags { |
22 | CmdUIOnlyFlag = 0x00000001, |
23 | CmdRecordableFlag = 0x00000002, |
24 | }; |
25 | |
26 | class Command { |
27 | public: |
28 | Command(const char* id, CommandFlags flags); |
29 | virtual ~Command(); |
30 | |
31 | const std::string& id() const { return m_id; } |
32 | std::string friendlyName() const; |
33 | |
34 | bool needsParams() const; |
35 | void loadParams(const Params& params); |
36 | bool isEnabled(Context* context); |
37 | bool isChecked(Context* context); |
38 | void generateFriendlyName(); |
39 | |
40 | protected: |
41 | virtual bool onNeedsParams() const; |
42 | virtual void onLoadParams(const Params& params); |
43 | virtual bool onEnabled(Context* context); |
44 | virtual bool onChecked(Context* context); |
45 | virtual void onExecute(Context* context); |
46 | virtual std::string onGetFriendlyName() const; |
47 | |
48 | const std::string& getBaseFriendlyName() const { |
49 | return m_friendlyName; |
50 | } |
51 | |
52 | private: |
53 | friend class Context; |
54 | void execute(Context* context); |
55 | |
56 | std::string m_id; |
57 | std::string m_friendlyName; |
58 | CommandFlags m_flags; |
59 | }; |
60 | |
61 | } // namespace app |
62 | |
63 | #endif |
64 | |