1 : /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
2 : /* ***** BEGIN LICENSE BLOCK *****
3 : * Version: MPL 1.1/GPL 2.0/LGPL 2.1
4 : *
5 : * The contents of this file are subject to the Mozilla Public License Version
6 : * 1.1 (the "License"); you may not use this file except in compliance with
7 : * the License. You may obtain a copy of the License at
8 : * http://www.mozilla.org/MPL/
9 : *
10 : * Software distributed under the License is distributed on an "AS IS" basis,
11 : * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
12 : * for the specific language governing rights and limitations under the
13 : * License.
14 : *
15 : * The Original Code is Mozilla Communicator client code.
16 : *
17 : * The Initial Developer of the Original Code is
18 : * Netscape Communications Corporation.
19 : * Portions created by the Initial Developer are Copyright (C) 1998
20 : * the Initial Developer. All Rights Reserved.
21 : *
22 : * Contributor(s):
23 : * Pierre Phaneuf <pp@ludusdesign.com>
24 : * Ryan Cassin <rcassin@supernova.org>
25 : *
26 : * Alternatively, the contents of this file may be used under the terms of
27 : * either of the GNU General Public License Version 2 or later (the "GPL"),
28 : * or the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
29 : * in which case the provisions of the GPL or the LGPL are applicable instead
30 : * of those above. If you wish to allow use of your version of this file only
31 : * under the terms of either the GPL or the LGPL, and not to allow others to
32 : * use your version of this file under the terms of the MPL, indicate your
33 : * decision by deleting the provisions above and replace them with the notice
34 : * and other provisions required by the GPL or the LGPL. If you do not delete
35 : * the provisions above, a recipient may use your version of this file under
36 : * the terms of any one of the MPL, the GPL or the LGPL.
37 : *
38 : * ***** END LICENSE BLOCK ***** */
39 :
40 : #include "nsString.h"
41 : #include "nsIComponentManager.h"
42 : #include "nsEditorController.h"
43 : #include "nsEditorCommands.h"
44 : #include "nsIControllerCommandTable.h"
45 :
46 :
47 :
48 : #define NS_REGISTER_ONE_COMMAND(_cmdClass, _cmdName) \
49 : { \
50 : _cmdClass* theCmd = new _cmdClass(); \
51 : NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY); \
52 : inCommandTable->RegisterCommand(_cmdName, \
53 : static_cast<nsIControllerCommand *>(theCmd)); \
54 : }
55 :
56 : #define NS_REGISTER_FIRST_COMMAND(_cmdClass, _cmdName) \
57 : { \
58 : _cmdClass* theCmd = new _cmdClass(); \
59 : NS_ENSURE_TRUE(theCmd, NS_ERROR_OUT_OF_MEMORY); \
60 : inCommandTable->RegisterCommand(_cmdName, \
61 : static_cast<nsIControllerCommand *>(theCmd));
62 :
63 : #define NS_REGISTER_NEXT_COMMAND(_cmdClass, _cmdName) \
64 : inCommandTable->RegisterCommand(_cmdName, \
65 : static_cast<nsIControllerCommand *>(theCmd));
66 :
67 : #define NS_REGISTER_LAST_COMMAND(_cmdClass, _cmdName) \
68 : inCommandTable->RegisterCommand(_cmdName, \
69 : static_cast<nsIControllerCommand *>(theCmd)); \
70 : }
71 :
72 :
73 : // static
74 0 : nsresult nsEditorController::RegisterEditingCommands(nsIControllerCommandTable *inCommandTable)
75 : {
76 : // now register all our commands
77 : // These are commands that will be used in text widgets, and in composer
78 :
79 0 : NS_REGISTER_ONE_COMMAND(nsUndoCommand, "cmd_undo");
80 0 : NS_REGISTER_ONE_COMMAND(nsRedoCommand, "cmd_redo");
81 0 : NS_REGISTER_ONE_COMMAND(nsClearUndoCommand, "cmd_clearUndo");
82 :
83 0 : NS_REGISTER_ONE_COMMAND(nsCutCommand, "cmd_cut");
84 0 : NS_REGISTER_ONE_COMMAND(nsCutOrDeleteCommand, "cmd_cutOrDelete");
85 0 : NS_REGISTER_ONE_COMMAND(nsCopyCommand, "cmd_copy");
86 0 : NS_REGISTER_ONE_COMMAND(nsCopyOrDeleteCommand, "cmd_copyOrDelete");
87 0 : NS_REGISTER_ONE_COMMAND(nsSelectAllCommand, "cmd_selectAll");
88 :
89 0 : NS_REGISTER_ONE_COMMAND(nsPasteCommand, "cmd_paste");
90 0 : NS_REGISTER_ONE_COMMAND(nsPasteTransferableCommand, "cmd_pasteTransferable");
91 :
92 0 : NS_REGISTER_ONE_COMMAND(nsSwitchTextDirectionCommand, "cmd_switchTextDirection");
93 :
94 0 : NS_REGISTER_FIRST_COMMAND(nsDeleteCommand, "cmd_delete");
95 0 : NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharBackward");
96 0 : NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteCharForward");
97 0 : NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteWordBackward");
98 0 : NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteWordForward");
99 0 : NS_REGISTER_NEXT_COMMAND(nsDeleteCommand, "cmd_deleteToBeginningOfLine");
100 0 : NS_REGISTER_LAST_COMMAND(nsDeleteCommand, "cmd_deleteToEndOfLine");
101 :
102 : // Insert content
103 0 : NS_REGISTER_ONE_COMMAND(nsInsertPlaintextCommand, "cmd_insertText");
104 0 : NS_REGISTER_ONE_COMMAND(nsPasteQuotationCommand, "cmd_pasteQuote");
105 :
106 0 : return NS_OK;
107 : }
108 :
109 :
110 : // static
111 0 : nsresult nsEditorController::RegisterEditorCommands(nsIControllerCommandTable *inCommandTable)
112 : {
113 : // These are commands that will be used in text widgets only.
114 :
115 0 : NS_REGISTER_FIRST_COMMAND(nsSelectionMoveCommands, "cmd_scrollTop");
116 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollBottom");
117 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveTop");
118 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_moveBottom");
119 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectTop");
120 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectBottom");
121 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_lineNext");
122 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_linePrevious");
123 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLineNext");
124 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectLinePrevious");
125 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_charPrevious");
126 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_charNext");
127 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectCharPrevious");
128 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectCharNext");
129 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_beginLine");
130 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_endLine");
131 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectBeginLine");
132 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectEndLine");
133 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_wordPrevious");
134 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_wordNext");
135 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectWordPrevious");
136 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectWordNext");
137 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageUp");
138 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollPageDown");
139 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineUp");
140 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_scrollLineDown");
141 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageUp");
142 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_movePageDown");
143 0 : NS_REGISTER_NEXT_COMMAND(nsSelectionMoveCommands, "cmd_selectPageUp");
144 0 : NS_REGISTER_LAST_COMMAND(nsSelectionMoveCommands, "cmd_selectPageDown");
145 :
146 0 : return NS_OK;
147 : }
148 :
|