texteditoractionhandler.h 7.17 KB
Newer Older
hjk's avatar
hjk committed
1
/****************************************************************************
con's avatar
con committed
2
**
3
** Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies).
hjk's avatar
hjk committed
4
** Contact: http://www.qt-project.org/legal
con's avatar
con committed
5
**
hjk's avatar
hjk committed
6
** This file is part of Qt Creator.
con's avatar
con committed
7
**
hjk's avatar
hjk committed
8
9
10
11
12
13
14
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and Digia.  For licensing terms and
** conditions see http://qt.digia.com/licensing.  For further information
** use the contact form at http://qt.digia.com/contact-us.
15
**
16
** GNU Lesser General Public License Usage
hjk's avatar
hjk committed
17
18
19
20
21
22
23
24
25
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 as published by the Free Software
** Foundation and appearing in the file LICENSE.LGPL included in the
** packaging of this file.  Please review the following information to
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, Digia gives you certain additional
** rights.  These rights are described in the Digia Qt LGPL Exception
con's avatar
con committed
26
27
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
hjk's avatar
hjk committed
28
****************************************************************************/
hjk's avatar
hjk committed
29

con's avatar
con committed
30
31
32
33
34
#ifndef TEXTEDITORACTIONHANDLER_H
#define TEXTEDITORACTIONHANDLER_H

#include "texteditor_global.h"

35
#include <coreplugin/icontext.h>
con's avatar
con committed
36

37
38
39
#include <QObject>
#include <QPointer>
#include <QList>
con's avatar
con committed
40

41
42
43
44
45
QT_FORWARD_DECLARE_CLASS(QAction)

namespace Core {
class ICore;
class IEditor;
46
class ActionContainer;
47
48
}

con's avatar
con committed
49
namespace TextEditor {
50
class BaseTextEditorWidget;
con's avatar
con committed
51
52
53
54
55
56
57
58
59
60
61
62

// Redirects slots from global actions to the respective editor.

class TEXTEDITOR_EXPORT TextEditorActionHandler : public QObject
{
    Q_OBJECT

public:
    enum OptionalActionsMask {
        None = 0,
        Format = 1,
        UnCommentSelection = 2,
63
64
65
        UnCollapseAll = 4,
        FollowSymbolUnderCursor = 8,
        JumpToFileUnderCursor = 16
con's avatar
con committed
66
67
    };

68
    explicit TextEditorActionHandler(const char *context, uint optionalActions = None);
69
70
    ~TextEditorActionHandler();

71
    void setupActions(BaseTextEditorWidget *editor);
con's avatar
con committed
72
73
74
75
76
77
78
79
80
81

    void initializeActions();

public slots:
    void updateActions();
    void updateRedoAction();
    void updateUndoAction();
    void updateCopyAction();

protected:
82
    const QPointer<BaseTextEditorWidget> &currentEditor() const;
83
84
85
86
87
88
89
90

    QAction *registerAction(const Core::Id &id,
                            const char *slot,
                            bool scriptable = false,
                            const QString &title = QString(),
                            const QKeySequence &keySequence = QKeySequence(),
                            const char *menueGroup = 0,
                            Core::ActionContainer *container = 0);
con's avatar
con committed
91

92
    enum UpdateMode { ReadOnlyMode, WriteMode };
con's avatar
con committed
93
94
    UpdateMode updateMode() const;

95
96
    void createActions();
    void updateActions(UpdateMode um);
con's avatar
con committed
97
98
99
100
101
102
103

private slots:
    void undoAction();
    void redoAction();
    void copyAction();
    void cutAction();
    void pasteAction();
104
    void circularPasteAction();
105
    void switchUtf8bomAction();
con's avatar
con committed
106
107
108
109
    void selectAllAction();
    void gotoAction();
    void printAction();
    void formatAction();
110
    void rewrapParagraphAction();
con's avatar
con committed
111
    void setVisualizeWhitespace(bool);
112
    void cleanWhitespace();
con's avatar
con committed
113
114
    void setTextWrapping(bool);
    void unCommentSelection();
mae's avatar
mae committed
115
116
117
    void unfoldAll();
    void fold();
    void unfold();
118
    void cutLine();
119
    void copyLine();
con's avatar
con committed
120
    void deleteLine();
121
122
123
124
    void deleteEndOfWord();
    void deleteEndOfWordCamelCase();
    void deleteStartOfWord();
    void deleteStartOfWordCamelCase();
con's avatar
con committed
125
126
127
    void selectEncoding();
    void increaseFontSize();
    void decreaseFontSize();
mae's avatar
mae committed
128
    void resetFontSize();
129
130
131
132
    void gotoBlockStart();
    void gotoBlockEnd();
    void gotoBlockStartWithSelection();
    void gotoBlockEndWithSelection();
133
134
    void selectBlockUp();
    void selectBlockDown();
135
136
    void moveLineUp();
    void moveLineDown();
137
138
    void copyLineUp();
    void copyLineDown();
139
    void joinLines();
140
141
    void insertLineAbove();
    void insertLineBelow();
142
143
    void uppercaseSelection();
    void lowercaseSelection();
144
    void updateCurrentEditor(Core::IEditor *editor);
145
146
    void indent();
    void unindent();
147
    void openLinkUnderCursor();
148
    void openLinkUnderCursorInNextSplit();
con's avatar
con committed
149

mae's avatar
mae committed
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
    void gotoLineStart();
    void gotoLineStartWithSelection();
    void gotoLineEnd();
    void gotoLineEndWithSelection();
    void gotoNextLine();
    void gotoNextLineWithSelection();
    void gotoPreviousLine();
    void gotoPreviousLineWithSelection();
    void gotoPreviousCharacter();
    void gotoPreviousCharacterWithSelection();
    void gotoNextCharacter();
    void gotoNextCharacterWithSelection();
    void gotoPreviousWord();
    void gotoPreviousWordWithSelection();
    void gotoNextWord();
    void gotoNextWordWithSelection();
mae's avatar
mae committed
166
167
168
169
    void gotoPreviousWordCamelCase();
    void gotoPreviousWordCamelCaseWithSelection();
    void gotoNextWordCamelCase();
    void gotoNextWordCamelCaseWithSelection();
mae's avatar
mae committed
170
171


con's avatar
con committed
172
173
174
175
176
177
private:
    QAction *m_undoAction;
    QAction *m_redoAction;
    QAction *m_copyAction;
    QAction *m_cutAction;
    QAction *m_pasteAction;
178
    QAction *m_circularPasteAction;
179
    QAction *m_switchUtf8bomAction;
con's avatar
con committed
180
181
182
183
    QAction *m_selectAllAction;
    QAction *m_gotoAction;
    QAction *m_printAction;
    QAction *m_formatAction;
184
    QAction *m_rewrapParagraphAction;
con's avatar
con committed
185
    QAction *m_visualizeWhitespaceAction;
186
    QAction *m_cleanWhitespaceAction;
con's avatar
con committed
187
188
    QAction *m_textWrappingAction;
    QAction *m_unCommentSelectionAction;
mae's avatar
mae committed
189
190
191
    QAction *m_unfoldAllAction;
    QAction *m_foldAction;
    QAction *m_unfoldAction;
192
    QAction *m_cutLineAction;
193
    QAction *m_copyLineAction;
con's avatar
con committed
194
    QAction *m_deleteLineAction;
195
196
197
198
    QAction *m_deleteEndOfWordAction;
    QAction *m_deleteEndOfWordCamelCaseAction;
    QAction *m_deleteStartOfWordAction;
    QAction *m_deleteStartOfWordCamelCaseAction;
con's avatar
con committed
199
200
201
    QAction *m_selectEncodingAction;
    QAction *m_increaseFontSizeAction;
    QAction *m_decreaseFontSizeAction;
mae's avatar
mae committed
202
    QAction *m_resetFontSizeAction;
203
204
205
206
    QAction *m_gotoBlockStartAction;
    QAction *m_gotoBlockEndAction;
    QAction *m_gotoBlockStartWithSelectionAction;
    QAction *m_gotoBlockEndWithSelectionAction;
207
208
    QAction *m_selectBlockUpAction;
    QAction *m_selectBlockDownAction;
209
210
    QAction *m_moveLineUpAction;
    QAction *m_moveLineDownAction;
211
212
    QAction *m_copyLineUpAction;
    QAction *m_copyLineDownAction;
213
    QAction *m_joinLinesAction;
214
215
    QAction *m_insertLineAboveAction;
    QAction *m_insertLineBelowAction;
216
217
    QAction *m_upperCaseSelectionAction;
    QAction *m_lowerCaseSelectionAction;
218
219
    QAction *m_indentAction;
    QAction *m_unindentAction;
220
    QAction *m_followSymbolAction;
221
    QAction *m_followSymbolInNextSplitAction;
222
    QAction *m_jumpToFileAction;
223
    QAction *m_jumpToFileInNextSplitAction;
224
    QList<QAction *> m_modifyingActions;
con's avatar
con committed
225
226

    uint m_optionalActions;
227
    QPointer<BaseTextEditorWidget> m_currentEditor;
228
    Core::Context m_contextId;
con's avatar
con committed
229
230
231
232
233
234
    bool m_initialized;
};

} // namespace TextEditor

#endif // TEXTEDITORACTIONHANDLER_H