Changeset View
Changeset View
Standalone View
Standalone View
src/utils/ktexteditor.cpp
Show All 34 Lines | |||||
35 | #include "inlinenoteinterface.h" | 35 | #include "inlinenoteinterface.h" | ||
36 | #include "inlinenote.h" | 36 | #include "inlinenote.h" | ||
37 | #include "inlinenotedata.h" | 37 | #include "inlinenotedata.h" | ||
38 | #include "inlinenoteprovider.h" | 38 | #include "inlinenoteprovider.h" | ||
39 | #include "markinterface.h" | 39 | #include "markinterface.h" | ||
40 | #include "modificationinterface.h" | 40 | #include "modificationinterface.h" | ||
41 | #include "sessionconfiginterface.h" | 41 | #include "sessionconfiginterface.h" | ||
42 | #include "texthintinterface.h" | 42 | #include "texthintinterface.h" | ||
43 | #include "variable.h" | ||||
43 | 44 | | |||
44 | #include "annotationinterface.h" | 45 | #include "annotationinterface.h" | ||
45 | #include "abstractannotationitemdelegate.h" | 46 | #include "abstractannotationitemdelegate.h" | ||
46 | 47 | | |||
47 | #include "kateglobal.h" | 48 | #include "kateglobal.h" | ||
48 | #include "kateconfig.h" | 49 | #include "kateconfig.h" | ||
49 | #include "katecmd.h" | 50 | #include "katecmd.h" | ||
51 | #include "katemacroexpander.h" | ||||
50 | 52 | | |||
51 | using namespace KTextEditor; | 53 | using namespace KTextEditor; | ||
52 | 54 | | |||
53 | Cursor Cursor::fromString(const QStringRef& str) Q_DECL_NOEXCEPT | 55 | Cursor Cursor::fromString(const QStringRef& str) Q_DECL_NOEXCEPT | ||
54 | { | 56 | { | ||
55 | // parse format "(line, column)" | 57 | // parse format "(line, column)" | ||
56 | const int startIndex = str.indexOf(QLatin1Char('(')); | 58 | const int startIndex = str.indexOf(QLatin1Char('(')); | ||
57 | const int endIndex = str.indexOf(QLatin1Char(')')); | 59 | const int endIndex = str.indexOf(QLatin1Char(')')); | ||
Show All 40 Lines | |||||
98 | QString Editor::defaultEncoding () const | 100 | QString Editor::defaultEncoding () const | ||
99 | { | 101 | { | ||
100 | /** | 102 | /** | ||
101 | * return default encoding in global config object | 103 | * return default encoding in global config object | ||
102 | */ | 104 | */ | ||
103 | return d->documentConfig()->encoding (); | 105 | return d->documentConfig()->encoding (); | ||
104 | } | 106 | } | ||
105 | 107 | | |||
108 | bool Editor::registerVariableMatch(const QString& name, const QString& description, ExpandFunction expansionFunc) | ||||
109 | { | ||||
110 | if (name.isEmpty() || expansionFunc == nullptr) | ||||
111 | return false; | ||||
112 | | ||||
113 | if (d->m_variableExactMatches.contains(name)) | ||||
114 | return false; | ||||
115 | | ||||
116 | d->m_variableExactMatches.insert(name, Variable(name, description, expansionFunc)); | ||||
117 | return true; | ||||
118 | } | ||||
119 | | ||||
120 | bool Editor::registerVariablePrefix(const QString& prefix, const QString& description, ExpandFunction expansionFunc) | ||||
121 | { | ||||
122 | if (prefix.isEmpty() || expansionFunc == nullptr) | ||||
123 | return false; | ||||
124 | | ||||
125 | if (d->m_variablePrefixMatches.contains(prefix)) | ||||
126 | return false; | ||||
127 | | ||||
128 | if (!prefix.contains(QLatin1Char(':'))) | ||||
129 | return false; | ||||
130 | | ||||
131 | d->m_variablePrefixMatches.insert(prefix, Variable(prefix, description, expansionFunc)); | ||||
132 | return true; | ||||
133 | } | ||||
134 | | ||||
135 | bool Editor::unregisterVariableMatch(const QString& variable) | ||||
136 | { | ||||
137 | auto it = d->m_variableExactMatches.find(variable); | ||||
138 | if (it != d->m_variableExactMatches.end()) { | ||||
139 | d->m_variableExactMatches.erase(it); | ||||
140 | return true; | ||||
141 | } | ||||
142 | return false; | ||||
143 | } | ||||
144 | | ||||
145 | bool Editor::unregisterVariablePrefix(const QString& variable) | ||||
146 | { | ||||
147 | auto it = d->m_variablePrefixMatches.find(variable); | ||||
148 | if (it != d->m_variablePrefixMatches.end()) { | ||||
149 | d->m_variablePrefixMatches.erase(it); | ||||
150 | return true; | ||||
151 | } | ||||
152 | return false; | ||||
153 | } | ||||
154 | | ||||
155 | bool Editor::expandVariable(const QString& variable, KTextEditor::View* view, QString& output) const | ||||
156 | { | ||||
157 | // first try exact matches | ||||
158 | const auto it = d->m_variableExactMatches.find(variable); | ||||
159 | if (it != d->m_variableExactMatches.end()) { | ||||
160 | output = it->evaluate(variable, view); | ||||
161 | return true; | ||||
162 | } | ||||
163 | | ||||
164 | // try prefix matching | ||||
165 | const int colonIndex = variable.indexOf(QLatin1Char(':')); | ||||
166 | if (colonIndex >= 0) { | ||||
167 | const QString prefix = variable.left(colonIndex + 1); | ||||
168 | const auto itPrefix = d->m_variablePrefixMatches.find(prefix); | ||||
169 | if (itPrefix != d->m_variablePrefixMatches.end()) { | ||||
170 | output = itPrefix->evaluate(variable, view); | ||||
171 | return true; | ||||
172 | } | ||||
173 | } | ||||
174 | return false; | ||||
175 | } | ||||
176 | | ||||
177 | void Editor::expandText(const QString& text, KTextEditor::View* view, QString& output) const | ||||
178 | { | ||||
179 | output = KateMacroExpander::expandMacro(text, view); | ||||
180 | } | ||||
181 | | ||||
106 | bool View::insertText(const QString &text) | 182 | bool View::insertText(const QString &text) | ||
107 | { | 183 | { | ||
108 | KTextEditor::Document *doc = document(); | 184 | KTextEditor::Document *doc = document(); | ||
109 | if (!doc) { | 185 | if (!doc) { | ||
110 | return false; | 186 | return false; | ||
111 | } | 187 | } | ||
112 | return doc->insertText(cursorPosition(), text, blockSelection()); | 188 | return doc->insertText(cursorPosition(), text, blockSelection()); | ||
113 | } | 189 | } | ||
▲ Show 20 Lines • Show All 292 Lines • Show Last 20 Lines |