/src/mozilla-central/editor/libeditor/EditorCommands.h
Line | Count | Source (jump to first uncovered line) |
1 | | /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ |
2 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
3 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
4 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
5 | | |
6 | | #ifndef EditorCommands_h_ |
7 | | #define EditorCommands_h_ |
8 | | |
9 | | #include "nsIControllerCommand.h" |
10 | | #include "nsISupportsImpl.h" |
11 | | #include "nscore.h" |
12 | | |
13 | | class nsICommandParams; |
14 | | class nsISupports; |
15 | | |
16 | | namespace mozilla { |
17 | | |
18 | | /** |
19 | | * This is a virtual base class for commands registered with the editor |
20 | | * controller. Note that such commands can be shared by more than on editor |
21 | | * instance, so MUST be stateless. Any state must be stored via the refCon |
22 | | * (an nsIEditor). |
23 | | */ |
24 | | |
25 | | class EditorCommandBase : public nsIControllerCommand |
26 | | { |
27 | | public: |
28 | | EditorCommandBase(); |
29 | | |
30 | | NS_DECL_ISUPPORTS |
31 | | |
32 | | NS_IMETHOD IsCommandEnabled(const char* aCommandName, |
33 | | nsISupports* aCommandRefCon, |
34 | | bool* aIsEnabled) override = 0; |
35 | | NS_IMETHOD DoCommand(const char* aCommandName, |
36 | | nsISupports* aCommandRefCon) override = 0; |
37 | | |
38 | | protected: |
39 | 0 | virtual ~EditorCommandBase() {} |
40 | | }; |
41 | | |
42 | | |
43 | | #define NS_DECL_EDITOR_COMMAND(_cmd) \ |
44 | | class _cmd final : public EditorCommandBase \ |
45 | | { \ |
46 | | public: \ |
47 | | NS_IMETHOD IsCommandEnabled(const char* aCommandName, \ |
48 | | nsISupports* aCommandRefCon, \ |
49 | | bool* aIsEnabled) override; \ |
50 | | NS_IMETHOD DoCommand(const char* aCommandName, \ |
51 | | nsISupports* aCommandRefCon) override; \ |
52 | | NS_IMETHOD DoCommandParams(const char* aCommandName, \ |
53 | | nsICommandParams* aParams, \ |
54 | | nsISupports* aCommandRefCon) override; \ |
55 | | NS_IMETHOD GetCommandStateParams(const char* aCommandName, \ |
56 | | nsICommandParams* aParams, \ |
57 | | nsISupports* aCommandRefCon) override; \ |
58 | | }; |
59 | | |
60 | | // basic editor commands |
61 | | NS_DECL_EDITOR_COMMAND(UndoCommand) |
62 | | NS_DECL_EDITOR_COMMAND(RedoCommand) |
63 | | NS_DECL_EDITOR_COMMAND(ClearUndoCommand) |
64 | | |
65 | | NS_DECL_EDITOR_COMMAND(CutCommand) |
66 | | NS_DECL_EDITOR_COMMAND(CutOrDeleteCommand) |
67 | | NS_DECL_EDITOR_COMMAND(CopyCommand) |
68 | | NS_DECL_EDITOR_COMMAND(CopyOrDeleteCommand) |
69 | | NS_DECL_EDITOR_COMMAND(CopyAndCollapseToEndCommand) |
70 | | NS_DECL_EDITOR_COMMAND(PasteCommand) |
71 | | NS_DECL_EDITOR_COMMAND(PasteTransferableCommand) |
72 | | NS_DECL_EDITOR_COMMAND(SwitchTextDirectionCommand) |
73 | | NS_DECL_EDITOR_COMMAND(DeleteCommand) |
74 | | NS_DECL_EDITOR_COMMAND(SelectAllCommand) |
75 | | |
76 | | NS_DECL_EDITOR_COMMAND(SelectionMoveCommands) |
77 | | |
78 | | // Insert content commands |
79 | | NS_DECL_EDITOR_COMMAND(InsertPlaintextCommand) |
80 | | NS_DECL_EDITOR_COMMAND(InsertParagraphCommand) |
81 | | NS_DECL_EDITOR_COMMAND(InsertLineBreakCommand) |
82 | | NS_DECL_EDITOR_COMMAND(PasteQuotationCommand) |
83 | | |
84 | | |
85 | | #if 0 |
86 | | // template for new command |
87 | | NS_IMETHODIMP |
88 | | FooCommand::IsCommandEnabled(const char* aCommandName, |
89 | | nsISupports* aCommandRefCon, |
90 | | bool* aIsEnabled) |
91 | | { |
92 | | return NS_ERROR_NOT_IMPLEMENTED; |
93 | | } |
94 | | |
95 | | NS_IMETHODIMP |
96 | | FooCommand::DoCommand(const char* aCommandName, |
97 | | const nsAString& aCommandParams, |
98 | | nsISupports* aCommandRefCon) |
99 | | { |
100 | | return NS_ERROR_NOT_IMPLEMENTED; |
101 | | } |
102 | | #endif |
103 | | |
104 | | } // namespace mozilla |
105 | | |
106 | | #endif // #ifndef EditorCommands_h_ |