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 
clone()31     virtual Command* clone() const { return new Command(*this); }
32 
id()33     const std::string& id() const { return m_id; }
34     std::string friendlyName() const;
35 
36     bool needsParams() const;
37     void loadParams(const Params& params);
38     bool isEnabled(Context* context);
39     bool isChecked(Context* context);
40 
41   protected:
42     virtual bool onNeedsParams() const;
43     virtual void onLoadParams(const Params& params);
44     virtual bool onEnabled(Context* context);
45     virtual bool onChecked(Context* context);
46     virtual void onExecute(Context* context);
47     virtual std::string onGetFriendlyName() const;
48 
getBaseFriendlyName()49     const std::string& getBaseFriendlyName() const {
50       return m_friendlyName;
51     }
52 
53   private:
54     friend class Context;
55     void execute(Context* context);
56 
57     std::string m_id;
58     std::string m_friendlyName;
59     CommandFlags m_flags;
60   };
61 
62 } // namespace app
63 
64 #endif
65