1 | // SPDX-FileCopyrightText: 2023 UnionTech Software Technology Co., Ltd. |
2 | // |
3 | // SPDX-License-Identifier: GPL-3.0-or-later |
4 | |
5 | #ifndef SCINTILLAEDITEXTERN_H |
6 | #define SCINTILLAEDITEXTERN_H |
7 | |
8 | #include "ScintillaEdit.h" |
9 | #include "style/stylelsp.h" |
10 | #include "style/stylesci.h" |
11 | #include <QString> |
12 | |
13 | class ScintillaEditExternPrivate; |
14 | class ScintillaEditExtern : public ScintillaEdit |
15 | { |
16 | Q_OBJECT |
17 | ScintillaEditExternPrivate *const d; |
18 | public: |
19 | explicit ScintillaEditExtern(QWidget *parent = nullptr); |
20 | virtual ~ScintillaEditExtern(); |
21 | |
22 | virtual QString supportLanguage(){return "" ;} // 当前编辑器支持的语言类型 |
23 | static QString fileLanguage(const QString &path); // 获取注册文件中语言支持 |
24 | virtual void setFile(const QString &filePath); |
25 | virtual QString file() const; |
26 | virtual void setProjectKey(const newlsp::ProjectKey &key); |
27 | virtual newlsp::ProjectKey projectKey() const; |
28 | /** |
29 | * @brief language get value from projectKey |
30 | * extension: shuold used to mimetype, not from outside setting |
31 | * @return if unset return default "" |
32 | */ |
33 | virtual QString language() const; |
34 | /** |
35 | * @brief workspace get value from projectKey |
36 | * @return if unset return default "" |
37 | */ |
38 | virtual QString workspace() const; // from projectKey, |
39 | |
40 | void addDebugPoint(int line); |
41 | void removeDebugPoint(int line); |
42 | void debugPointAllDelete(); |
43 | void jumpToLine(int line); |
44 | void jumpToRange(Scintilla::Position start, Scintilla::Position end); |
45 | void runningToLine(int line); |
46 | void runningEnd(); |
47 | void saveText(); |
48 | bool isLeave(); |
49 | void replaceRange(Scintilla::Position start, Scintilla::Position end, const QString &text); |
50 | QPair<long int, long int> findText(long int start, long int end, const QString &text); |
51 | void findText(const QString &srcText, bool reverse); |
52 | void findText(const QString &srcText, long int startPos, long int endPos); |
53 | void replaceAll(const QString &srcText, const QString &destText); |
54 | void setLineBackground(int line, const QColor &color); |
55 | void delLineBackground(int line); |
56 | void cleanLineBackground(); |
57 | void setAnnotation(int line, const QString &title, const AnnotationInfo &info); |
58 | void cleanAnnotation(const QString &title); |
59 | void updateFile(); |
60 | void saveAsText(); |
61 | bool isSaveText(); |
62 | void cleanIsSaveText(); |
63 | void find(const QString &srcText, int operateType); |
64 | void replace(const QString &srcText, const QString &destText, int operateType); |
65 | |
66 | signals: |
67 | void hovered(Scintilla::Position position); |
68 | void hoverCleaned(Scintilla::Position position); |
69 | void definitionHover(Scintilla::Position position); |
70 | void definitionHoverCleaned(Scintilla::Position position); |
71 | void textInserted(Scintilla::Position position, |
72 | Scintilla::Position length, Scintilla::Position linesAdded, |
73 | const QByteArray &text, Scintilla::Position line); |
74 | void textDeleted(Scintilla::Position position, |
75 | Scintilla::Position length, Scintilla::Position linesAdded, |
76 | const QByteArray &text, Scintilla::Position line); |
77 | void completed(Scintilla::Position position); |
78 | void completeCleaned(); |
79 | void indicClicked(Scintilla::Position position); |
80 | void indicReleased(Scintilla::Position position); |
81 | void saved(const QString &file); |
82 | void replaceed(const QString &file, Scintilla::Position start, |
83 | Scintilla::Position end, const QString &text); |
84 | void (QContextMenuEvent *event); |
85 | void fileChanged(const QString &file); |
86 | void fileClosed(const QString &file); |
87 | void fileSaved(const QString &file); |
88 | |
89 | private slots: |
90 | void sciModified(Scintilla::ModificationFlags type, Scintilla::Position position, |
91 | Scintilla::Position length, Scintilla::Position linesAdded, |
92 | const QByteArray &text, Scintilla::Position line, |
93 | Scintilla::FoldLevel foldNow, Scintilla::FoldLevel foldPrev); |
94 | void sciNotify(Scintilla::NotificationData *data); |
95 | void sciUpdateUi(Scintilla::Update update); |
96 | void sciDwellStart(int x, int y); |
97 | void sciDwellEnd(int x, int y); |
98 | void sciUpdateAnnotation(); |
99 | |
100 | protected: |
101 | virtual void keyReleaseEvent(QKeyEvent *event) override; |
102 | virtual void keyPressEvent(QKeyEvent *event) override; |
103 | virtual void enterEvent(QEvent *event) override; |
104 | virtual void leaveEvent(QEvent *event) override; |
105 | virtual void focusInEvent(QFocusEvent *event) override; |
106 | virtual void focusOutEvent(QFocusEvent *event) override; |
107 | virtual void (QContextMenuEvent *event) override; |
108 | virtual void sciMarginClicked(Scintilla::Position position, Scintilla::KeyMod modifiers, int margin); |
109 | }; |
110 | |
111 | #endif // SCINTILLAEDITEXTERN_H |
112 | |