File: latexeditorview.h

package info (click to toggle)
texstudio 2.11.2%2Bdebian-1
  • links: PTS
  • area: main
  • in suites: stretch
  • size: 41,292 kB
  • ctags: 12,405
  • sloc: cpp: 93,072; xml: 10,217; ansic: 4,153; sh: 145; makefile: 56
file content (338 lines) | stat: -rw-r--r-- 11,600 bytes parent folder | download
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
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
/***************************************************************************
 *   copyright       : (C) 2008 by Benito van der Zander                   *
 *   http://www.xm1math.net/texmaker/                                      *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of the GNU General Public License as published by  *
 *   the Free Software Foundation; either version 2 of the License, or     *
 *   (at your option) any later version.                                   *
 *                                                                         *
 ***************************************************************************/

#ifndef LATEXEDITORVIEW_H
#define LATEXEDITORVIEW_H
#include "mostQtHeaders.h"
#include "qdocument.h"
#include "syntaxcheck.h"
#include "grammarcheck.h"
#include "bibtexreader.h"
#include "cursorposition.h"
#include "latexcompleter.h"
class QDocumentLineHandle;

class LatexDocument;
class QCodeEdit;
class QEditor;
class QLineMarkPanel;
class QLineNumberPanel;
class QSearchReplacePanel;
class QGotoLinePanel;
class QStatusPanel;
class LatexCompleter;
class SpellerUtility;
class SpellerManager;
class DefaultInputBinding;
class LatexEditorViewConfig;
class Macro;
class MacroExecContext;
/*!
 * \brief represent link overlays
 * When pressing control, some structural elements in the text can be changed to links in order to jump to corresponding places
 *
 */
struct LinkOverlay {
	enum LinkOverlayType {Invalid, RefOverlay, FileOverlay, UrlOverlay, UsepackageOverlay, BibFileOverlay, CiteOverlay};
	// for simpler access everything is public - only access for reading
	LinkOverlayType type;
	QDocumentLine docLine;
	QFormatRange formatRange;

	LinkOverlay() : type(Invalid) {}
	LinkOverlay(const LinkOverlay &o);
	LinkOverlay(const QDocumentCursor &cur, LinkOverlayType ltype);

	bool isValid() const
	{
		return type != Invalid;
	}
	bool operator ==(const LinkOverlay &o) const
	{
		return (docLine == o.docLine) && (formatRange == o.formatRange);
	}
	QString text() const;
};
/*!
 * \brief actual editor widget
 */
class LatexEditorView : public QWidget
{
	Q_OBJECT

public:
	LatexEditorView(QWidget *parent, LatexEditorViewConfig *aconfig, LatexDocument *doc = 0);
	~LatexEditorView();

	QCodeEdit *codeeditor;
	QEditor *editor;

	LatexDocument *document;

	QDateTime lastUsageTime;

	QEditor *getEditor() const
	{
		return editor;
	}
	LatexDocument *getDocument() const { return document; }
	Q_PROPERTY(QEditor *editor READ getEditor);
	Q_PROPERTY(LatexDocument *document READ getDocument);     //<- semicolon necessary due to qt bug 22992

	LatexEditorViewConfig *getConfig() { return config; }

	Q_INVOKABLE	QString displayName() const;
	QString displayNameForUI() const;

	//  FindWidget *findwidget;
	//Functions affecting the editor

    Q_INVOKABLE void complete(int flags); ///< complete text
	bool gotoLineHandleAndSearchCommand(const QDocumentLineHandle *dlh, const QSet<QString> &searchFor, const QString &id);
	Q_INVOKABLE bool gotoToLabel(const QString &label);
	Q_INVOKABLE bool gotoToBibItem(const QString &bibId);

	static QList<QAction *> getBaseActions();
	static void setBaseActions(QList<QAction *> baseActions);
	void setSpellerManager(SpellerManager *manager);
	bool setSpeller(const QString &name);
	Q_INVOKABLE QString getSpeller();

	static void setCompleter(LatexCompleter *newCompleter);
	static LatexCompleter *getCompleter();
	bool containsBibTeXId(QString id);

	void updateCitationFormats();
	void updatePackageFormats();

	void clearLogMarks();
	void addLogEntry(int logEntryNumber, int lineNumber, int markID);
	void setLogMarksVisible(bool visible);
	QMultiHash<QDocumentLineHandle *, int> lineToLogEntries;
	QHash<int, QDocumentLineHandle *> logEntryToLine;
	QHash<int, int> logEntryToMarkID;

	static int hideTooltipWhenLeavingLine;
	static int syntaxErrorFormat;

	void setLineMarkToolTip(const QString &tooltip);
	void updateSettings();
	static void updateFormatSettings();

	QPoint getHoverPosistion() { return m_point; }

	static int deleteFormat, insertFormat, replaceFormat;
	static int preEditFormat;

	Q_INVOKABLE void closeCompleter();
	Q_INVOKABLE void removeBookmark(int lineNr, int bookmarkNumber);
	void removeBookmark(QDocumentLineHandle *dlh, int bookmarkNumber);
	Q_INVOKABLE void addBookmark(int lineNr, int bookmarkNumber);
	Q_INVOKABLE bool hasBookmark(int lineNr, int bookmarkNumber);
	bool hasBookmark(QDocumentLineHandle *dlh, int bookmarkNumber);

	QList<QDocumentCursor> autoPreviewCursor;

	static int bookMarkId(int bookmarkNumber);

	static void selectOptionInLatexArg(QDocumentCursor &cur);

	QDocumentCursor parenthizedTextSelection(const QDocumentCursor &cursor, bool includeParentheses = true);
	QDocumentCursor findFormatsBegin(const QDocumentCursor &cursor, QSet<int> allowedFormats, QSet<int> allowedLineEndFormats);
	void setLatexPackageList(QSet<QString> *lst) { latexPackageList = lst; }

	LatexParser lp;

	QString getSearchText();
	QString getReplaceText();
	bool getSearchIsCase();
	bool getSearchIsRegExp();
	bool getSearchIsWords();

	void updateReplamentList(const LatexParser &cmds, bool forceUpdate = false);

private:
	QAction *lineNumberPanelAction, *lineMarkPanelAction, *lineFoldPanelAction, *lineChangePanelAction,
	        *statusPanelAction, *searchReplacePanelAction, *gotoLinePanelAction;
	QLineMarkPanel *lineMarkPanel;
	QLineNumberPanel *lineNumberPanel;
	QSearchReplacePanel *searchReplacePanel;
	QGotoLinePanel *gotoLinePanel;
	QStatusPanel *statusPanel;

	QPoint m_point;

	static int environmentFormat, referencePresentFormat, referenceMissingFormat, referenceMultipleFormat, citationMissingFormat, citationPresentFormat, structureFormat,
	       packagePresentFormat, packageMissingFormat, packageUndefinedFormat,
	       wordRepetitionFormat, wordRepetitionLongRangeFormat, badWordFormat, grammarMistakeFormat, grammarMistakeSpecial1Format, grammarMistakeSpecial2Format, grammarMistakeSpecial3Format, grammarMistakeSpecial4Format,
	       numbersFormat, verbatimFormat, commentFormat, pictureFormat, pweaveDelimiterFormat, pweaveBlockFormat, sweaveDelimiterFormat, sweaveBlockFormat, math_DelimiterFormat, math_KeywordFormat,
	       asymptoteBlockFormat;
	static QList<int> grammarFormats;
	static QVector<bool> grammarFormatsDisabled;
	static QList<int> formatsList;

	QSet<QString> *latexPackageList;

	friend class DefaultInputBinding;
	friend class SyntaxCheckTest;

	SpellerManager *spellerManager;
	SpellerUtility *speller;
	bool useDefaultSpeller;
	static LatexCompleter *completer;
	QList<CursorPosition> changePositions; //line, index
	int curChangePos;

	LatexEditorViewConfig *config;

	bibtexReader *bibReader;
	QPoint lastPos;

	LinkOverlay linkOverlay;
	QCursor linkOverlayStoredCursor;

	QList<QPair<QDocumentLine, QFormatRange> > tempHighlightQueue;

	QMap<QString, QString> mReplacementList;

private slots:
	void requestCitation(); //emits needCitation with selected text
	void openExternalFile();
	void openPackageDocumentation(QString package = QString());
	void emitChangeDiff();
	void emitGotoDefinitionFromAction();
	void emitFindLabelUsagesFromAction();
	void emitSyncPDFFromAction();
	void lineMarkClicked(int line);
	void lineMarkToolTip(int line, int mark);
	void triggeredThesaurus();
	void reloadSpeller();
	void changeSpellingDict(const QString &name);
	void copyImageFromAction();
	void saveImageFromAction();

public slots:
	void cleanBib();

	void jumpChangePositionBackward();
	void jumpChangePositionForward();

	void jumpToBookmark(int bookmarkNumber);
	bool toggleBookmark(int bookmarkNumber, QDocumentLine line = QDocumentLine());

	void foldEverything(bool unFold);
	void foldLevel(bool unFold, int level);
	void foldBlockAt(bool unFold, int line);

	Q_INVOKABLE void zoomIn();
	Q_INVOKABLE void zoomOut();
	Q_INVOKABLE void resetZoom();

	void mayNeedToOpenCompleter();
	void documentContentChanged(int linenr, int count);

private slots:
	void lineDeleted(QDocumentLineHandle *l);
	void textReplaceFromAction();
	void spellCheckingAlwaysIgnore();
	void populateSpellingMenu();
	void addReplaceActions(QMenu *menu, const QStringList &replacements, bool italic);
	void addSpellingActions(QMenu *menu, QString word, bool dedicatedMenu);

public slots:
	void spellRemoveMarkers(const QString &newIgnoredWord);
	void mouseHovered(QPoint pos);
	bool closeSomething();
	void insertHardLineBreaks(int newLength, bool smartScopeSelection, bool joinLines);
	void viewActivated();
	void clearOverlays();
	void paste();
	void insertSnippet(QString text);

	void deleteLines(bool toStart, bool toEnd);
	void moveLines(int delta);
	QList<QPair<int, int> > getSelectedLineBlocks();
	static QMultiMap<int, QDocumentCursor* > getSelectedLines(QList<QDocumentCursor>& cursors);
	void alignMirrors();

	void checkForLinkOverlay(QDocumentCursor cursor);
	bool hasLinkOverlay() const { return linkOverlay.isValid(); }
	const LinkOverlay &getLinkOverlay() const { return linkOverlay; }

private:
	void setLinkOverlay(const LinkOverlay &overlay);
	void removeLinkOverlay();
	bool isNonTextFormat(int format);
	QString extractMath(QDocumentCursor cursor);
	bool showMathEnvPreview(QDocumentCursor cursor, QString command, QString environment, QPoint pos);

public slots:
	void temporaryHighlight(QDocumentCursor cur);
	void removeTemporaryHighlight();

	void displayLineGrammarErrorsInternal(int lineNr, const QList<GrammarError> &errors);
	void lineGrammarChecked(const void *doc, const void *line, int lineNr, const QList<GrammarError> &errors);
	void updateGrammarOverlays();

	void bibtexSectionFound(QString content);

public:
	static void setGrammarOverlayDisabled(int type, bool show);

	bool isInMathHighlighting(const QDocumentCursor &cursor);
	void checkRTLLTRLanguageSwitching();

signals:
	void lineHandleDeleted(QDocumentLineHandle *l);
	void showMarkTooltipForLogMessage(QList<int> logMessages);
	void needCitation(const QString &id);//request a new citation
	void showPreview(const QString &text);
	void showPreview(const QDocumentCursor &c);
	void showImgPreview(const QString &fileName);
	void openFile(const QString &name);
	void openFile(const QString &baseName, const QString &defaultExtension);
	void openCompleter();
	void thesaurus(int line, int col);
	void changeDiff(QPoint pt);
	void spellerChanged(const QString &name);
	void gotoDefinition(QDocumentCursor c);
	void findLabelUsages(LatexDocument *contextDoc, const QString &labelText);
	void syncPDFRequested(QDocumentCursor c);
	void bookmarkRemoved(QDocumentLineHandle *dlh);
	void bookmarkAdded(QDocumentLineHandle *dlh, int nr);
	void saveCurrentCursorToHistoryRequested();
	void execMacro(const Macro &macro, const MacroExecContext &context);

	void mouseBackPressed();
	void mouseForwardPressed();
	void cursorChangeByMouse();
        void focusReceived();

	void linesChanged(QString language, const void *doc, const QList<LineInfo> &lines, int firstLineNr);
	void searchBibtexSection(QString file, QString bibId);
	void openInternalDocViewer(QString package, QString command = "");

	void showExtendedSearch();

private slots:
	void lineMarkContextMenuRequested(int lineNumber, QPoint globalPos);
	void foldContextMenuRequested(int lineNumber, QPoint globalPos);
};
Q_DECLARE_METATYPE(LatexEditorView *)


class BracketInvertAffector: public PlaceHolder::Affector
{
public:
	virtual QString affect(const QKeyEvent *e, const QString &base, int ph, int mirror) const;
	static BracketInvertAffector *instance();
};
#endif