OSDN Git Service

It's 2011 now.
[qt-creator-jp/qt-creator-jp.git] / src / plugins / fakevim / fakevimhandler.h
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file.  Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 **
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights.  These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #ifndef FAKEVIM_HANDLER_H
35 #define FAKEVIM_HANDLER_H
36
37 #include "fakevimactions.h"
38
39 #include <QtCore/QObject>
40 #include <QtGui/QTextEdit>
41
42 namespace FakeVim {
43 namespace Internal {
44
45 enum RangeMode
46 {
47     RangeCharMode,         // v
48     RangeLineMode,         // V
49     RangeLineModeExclusive,
50     RangeBlockMode,        // Ctrl-v
51     RangeBlockAndTailMode // Ctrl-v for D and X
52 };
53
54 struct Range
55 {
56     Range();
57     Range(int b, int e, RangeMode m = RangeCharMode);
58     QString toString() const;
59
60     int beginPos;
61     int endPos;
62     RangeMode rangemode;
63 };
64
65 struct ExCommand
66 {
67     ExCommand() : hasBang(false), count(1) {}
68     ExCommand(const QString &cmd, const QString &args = QString(),
69         const Range &range = Range());
70
71     bool matches(const QString &min, const QString &full) const;
72
73     QString cmd;
74     bool hasBang;
75     QString args;
76     Range range;
77     int count;
78 };
79
80 class FakeVimHandler : public QObject
81 {
82     Q_OBJECT
83
84 public:
85     explicit FakeVimHandler(QWidget *widget, QObject *parent = 0);
86     ~FakeVimHandler();
87
88     QWidget *widget();
89
90     // call before widget is deleted
91     void disconnectFromEditor();
92
93 public slots:
94     void setCurrentFileName(const QString &fileName);
95     QString currentFileName() const;
96
97     void showBlackMessage(const QString &msg);
98     void showRedMessage(const QString &msg);
99
100     // This executes an "ex" style command taking context
101     // information from the current widget.
102     void handleCommand(const QString &cmd);
103
104     void installEventFilter();
105
106     // Convenience
107     void setupWidget();
108     void restoreWidget(int tabSize);
109
110     // Test only
111     int physicalIndentation(const QString &line) const;
112     int logicalIndentation(const QString &line) const;
113     QString tabExpand(int n) const;
114
115 signals:
116     void commandBufferChanged(const QString &msg);
117     void statusDataChanged(const QString &msg);
118     void extraInformationChanged(const QString &msg);
119     void selectionChanged(const QList<QTextEdit::ExtraSelection> &selection);
120     void writeAllRequested(QString *error);
121     void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
122     void checkForElectricCharacter(bool *result, QChar c);
123     void indentRegion(int beginLine, int endLine, QChar typedChar);
124     void completionRequested();
125     void simpleCompletionRequested(const QString &needle, bool forward);
126     void windowCommandRequested(int key);
127     void findRequested(bool reverse);
128     void findNextRequested(bool reverse);
129     void handleExCommandRequested(bool *handled, const ExCommand &cmd);
130     void requestSetBlockSelection(bool on);
131     void requestHasBlockSelection(bool *on);
132
133 public:
134     class Private;
135
136 private:
137     bool eventFilter(QObject *ob, QEvent *ev);
138
139     Private *d;
140 };
141
142 } // namespace Internal
143 } // namespace FakeVim
144
145 Q_DECLARE_METATYPE(FakeVim::Internal::ExCommand)
146
147
148 #endif // FAKEVIM_HANDLER_H