Repository navigation
Expand file tree
/
Copy pathTextEditor.h
More file actions
219 lines (187 loc) · 5.09 KB
/
Copy pathTextEditor.h
File metadata and controls
219 lines (187 loc) · 5.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
//
// Copyright (c) 2016, Scientific Toolworks, Inc.
//
// This software is licensed under the MIT License. The LICENSE.md file
// describes the conditions under which this software may be distributed.
//
// Author: Jason Haslam
//
#ifndef TEXT_EDITOR_H
#define TEXT_EDITOR_H
// Do not reorder.
#include <cstdint>
#include <cstddef>
#include <cstring>
#include <vector>
#include <QMenu>
#include <ILexer.h>
#include <LexerModule.h>
#include <CatalogueModules.h>
#include <SciLexer.h>
#include <ScintillaEdit.h>
#include <ScintillaQt.h>
#include <Platform.h>
class TextEditor : public ScintillaEdit {
Q_OBJECT
public:
enum Margin {
Staged, // indicates staged or not
LineNumber,
LineNumbers,
ErrorMargin,
};
enum Marker {
Context,
Ours,
Theirs,
Addition,
Deletion,
NoteMarker,
WarningMarker,
ErrorMarker,
StagedMarker,
UnstagedMarker,
DiscardMarker,
};
enum Indicator {
FindAll = INDIC_CONTAINER,
FindCurrent,
WordAddition,
WordDeletion,
NoteIndicator,
WarningIndicator,
ErrorIndicator
};
enum Style {
EofNewline = STYLE_MAX - 4,
CommentBody,
CommentAuthor,
CommentTimestamp
};
enum DiagnosticKind { Note, Warning, Error };
struct Range {
int pos;
int len;
};
struct Diagnostic {
DiagnosticKind kind;
QString message;
QString description;
Range range;
QString replacement;
};
enum MenuAction {
None,
Undo,
Redo,
Cut,
Copy,
Paste,
Delete,
StageSelected,
UnstageSelected,
DiscardSelected,
SelectAll,
};
Q_ENUM(MenuAction);
TextEditor(QWidget *parent = nullptr);
void applySettings();
QString lexer() const;
void setLineCount(int lines);
void setLexer(const QString &path);
void load(const QString &path, const QString &text);
/*!
* sets the statusDiff flag
* \brief setStatusDiff
* \param statusDiff See \variable mStatusDiff for more information
*/
void setStatusDiff(bool statusDiff);
void clearHighlights();
int highlightAll(const QString &text);
int find(const QString &text, bool forward = true, bool indicator = true);
QList<Diagnostic> diagnostics(int line);
void addDiagnostic(int line, const Diagnostic &diag);
// Make wheel event public.
// FIXME: This should be an event filter?
void wheelEvent(QWheelEvent *event) override {
ScintillaEdit::wheelEvent(event);
}
void keyPressEvent(QKeyEvent *ke) override;
QRect textRectangle() const {
// Approximates Editor::GetTextRectangle, which isn't accessible with
// Scintilla 5.x: the client area minus the margins.
int left = marginLeft();
for (int i = 0, count = margins(); i < count; ++i)
left += marginWidthN(i);
QRect rc = contentsRect();
rc.adjust(left, 0, -marginRight(), 0);
return rc;
};
QFont styleGetQFont(int style);
QPoint pointFromPosition(int pos);
void showEvent(QShowEvent *event) override {
QAbstractScrollArea::showEvent(event);
emit onVisible();
}
signals:
void onVisible();
void settingsChanged();
void highlightActivated(bool active);
void diagnosticAdded(int line, const Diagnostic &diag);
/*!
* Emitted when in the context menu "stage selected" is triggered
* \brief stageSelectedSignal
* \param startPos Start line of selection
* \param end End line of selection + 1
*/
void stageSelectedSignal(int startPos, int end, bool emitSignal = true);
/*!
* Emitted when in the context menu "unstage selected" is triggered
* \brief unstageSelectedSignal
* \param startPos Start line of selection
* \param end End line of selection + 1
*/
void unstageSelectedSignal(int startPos, int end, bool emitSignal = true);
/*!
* Emitted when in the context menu "revert selected" is triggered
* \brief discardSelectedSignal
* \param startPos Start line of selection
* \param end End line of selection + 1
*/
void discardSelectedSignal(int startPos, int end);
protected:
QSize viewportSizeHint() const override;
void Command(MenuAction action);
void contextMenuEvent(QContextMenuEvent *event) override;
private:
int diagnosticMarker(int line);
void loadMarkerIcon(Marker marker, const QIcon &icon);
void loadMarkerPixmap(Marker marker, const QPixmap &pixmap);
void AddToPopUp(const QString &label, MenuAction cmd = None,
bool enabled = true);
void StyleSetQFont(int style, const QFont &font);
void markerDefineImage(int markerNumber, const QImage &image);
void applyLexerStyles();
QString mPath;
QString mLexerName;
int mLineCount = -1;
/*!
* statusDiff Flag which determines if in the contextmenu stage actions are
* shown or not Because when checking out commits, it should not possible to
* select these actions. true: not commited diff. false: already commited
* diff.
*/
bool mStatusDiff{false};
QColor mOursColor;
QColor mTheirsColor;
QColor mAdditionColor;
QColor mDeletionColor;
QIcon mNoteIcon;
QIcon mWarningIcon;
QIcon mErrorIcon;
QPixmap mStagedIcon;
QPixmap mUnStagedIcon;
QMap<int, QList<Diagnostic>> mDiagnostics;
QMenu mPopup;
};
#endif