8#include "variablelineedit.h"
10#include "kateautoindent.h"
11#include "katedocument.h"
12#include "kateglobal.h"
13#include "katesyntaxmanager.h"
15#include "variableitem.h"
16#include "variablelistview.h"
18#include <QApplication>
28#include <KLocalizedString>
30#include <sonnet/speller.h>
32VariableLineEdit::VariableLineEdit(
QWidget *parent)
41 m_button->setToolTip(
i18n(
"Show list of valid variables."));
59void VariableLineEdit::editVariables()
61 m_listview =
new VariableListView(m_lineedit->
text(), m_popup.get());
62 addKateItems(m_listview);
63 connect(m_listview, &VariableListView::aboutToHide,
this, &VariableLineEdit::updateVariableLine);
65 m_popup->layout()->addWidget(m_listview);
71 m_popup->setGeometry(
QRect(topLeft,
QSize(w, h)));
76 m_popup->setGeometry(
QRect(topLeft,
QSize(w, h)));
81void VariableLineEdit::updateVariableLine()
85 QString variables = m_listview->variableLine();
88 m_popup->layout()->removeWidget(m_listview);
93void VariableLineEdit::addKateItems(VariableListView *listview)
95 VariableItem *item =
nullptr;
98 KTextEditor::ViewPrivate *activeView =
nullptr;
101 KateDocumentConfig *docConfig = KateDocumentConfig::global();
102 KateViewConfig *viewConfig = KateViewConfig::global();
103 KateRendererConfig *rendererConfig = KateRendererConfig::global();
106 activeDoc = activeView->doc();
107 viewConfig = activeView->config();
108 docConfig = activeDoc->
config();
109 rendererConfig = activeView->rendererConfig();
113 item =
new VariableBoolItem(QStringLiteral(
"auto-brackets"),
false);
114 item->setHelpText(
i18nc(
"short translation please",
"Enable automatic insertion of brackets."));
115 listview->addItem(item);
118 item =
new VariableIntItem(QStringLiteral(
"auto-center-lines"), viewConfig->autoCenterLines());
119 static_cast<VariableIntItem *
>(item)->setRange(1, 100);
120 item->setHelpText(
i18nc(
"short translation please",
"Set the number of autocenter lines."));
121 listview->addItem(item);
124 item =
new VariableColorItem(QStringLiteral(
"background-color"), rendererConfig->backgroundColor());
125 item->setHelpText(
i18nc(
"short translation please",
"Set the document background color."));
126 listview->addItem(item);
129 item =
new VariableBoolItem(QStringLiteral(
"backspace-indents"), docConfig->backspaceIndents());
130 item->setHelpText(
i18nc(
"short translation please",
"Pressing backspace in leading whitespace unindents."));
131 listview->addItem(item);
134 item =
new VariableBoolItem(QStringLiteral(
"block-selection"),
false);
136 static_cast<VariableBoolItem *
>(item)->setValue(activeView->blockSelection());
138 item->setHelpText(
i18nc(
"short translation please",
"Enable block selection mode."));
139 listview->addItem(item);
142 item =
new VariableBoolItem(QStringLiteral(
"byte-order-mark"), docConfig->bom());
143 item->setHelpText(
i18nc(
"short translation please",
"Enable the byte order mark (BOM) when saving Unicode files."));
144 listview->addItem(item);
147 item =
new VariableColorItem(QStringLiteral(
"bracket-highlight-color"), rendererConfig->highlightedBracketColor());
148 item->setHelpText(
i18nc(
"short translation please",
"Set the color for the bracket highlight."));
149 listview->addItem(item);
152 item =
new VariableColorItem(QStringLiteral(
"current-line-color"), rendererConfig->highlightedLineColor());
153 item->setHelpText(
i18nc(
"short translation please",
"Set the background color for the current line."));
154 listview->addItem(item);
158 item =
new VariableSpellCheckItem(QStringLiteral(
"default-dictionary"), speller.defaultLanguage());
159 item->setHelpText(
i18nc(
"short translation please",
"Set the default dictionary used for spell checking."));
160 listview->addItem(item);
163 item =
new VariableBoolItem(QStringLiteral(
"dynamic-word-wrap"), viewConfig->dynWordWrap());
164 item->setHelpText(
i18nc(
"short translation please",
"Enable dynamic word wrap of long lines."));
165 listview->addItem(item);
168 item =
new VariableStringListItem(QStringLiteral(
"end-of-line"),
169 {QStringLiteral(
"unix"), QStringLiteral(
"mac"), QStringLiteral(
"dos")},
170 docConfig->eolString());
171 item->setHelpText(
i18nc(
"short translation please",
"Sets the end of line mode."));
172 listview->addItem(item);
175 item =
new VariableBoolItem(QStringLiteral(
"enter-to-insert-completion"), viewConfig->
value(KateViewConfig::EnterToInsertCompletion).
toBool());
176 item->setHelpText(
i18nc(
"short translation please",
"Enable whether pressing enter will insert selected auto completion item."));
177 listview->addItem(item);
180 item =
new VariableBoolItem(QStringLiteral(
"folding-markers"), viewConfig->foldingBar());
181 item->setHelpText(
i18nc(
"short translation please",
"Enable folding markers in the editor border."));
182 listview->addItem(item);
185 item =
new VariableBoolItem(QStringLiteral(
"folding-preview"), viewConfig->foldingPreview());
186 item->setHelpText(
i18nc(
"short translation please",
"Enable folding preview in the editor border."));
187 listview->addItem(item);
190 item =
new VariableIntItem(QStringLiteral(
"font-size"), rendererConfig->baseFont().
pointSize());
191 static_cast<VariableIntItem *
>(item)->setRange(4, 128);
192 item->setHelpText(
i18nc(
"short translation please",
"Set the point size of the document font."));
193 listview->addItem(item);
196 item =
new VariableFontItem(QStringLiteral(
"font"), rendererConfig->baseFont());
197 item->setHelpText(
i18nc(
"short translation please",
"Set the font of the document."));
198 listview->addItem(item);
203 hls.
reserve(KateHlManager::self()->modeList().
size());
204 const auto modeList = KateHlManager::self()->modeList();
205 for (
const auto &hl : modeList) {
209 item =
new VariableStringListItem(QStringLiteral(
"syntax"), hls, hls.
at(0));
211 static_cast<VariableStringListItem *
>(item)->setValue(activeDoc->
highlightingMode());
213 item->setHelpText(
i18nc(
"short translation please",
"Set the syntax highlighting."));
214 listview->addItem(item);
217 item =
new VariableColorItem(QStringLiteral(
"icon-bar-color"), rendererConfig->iconBarColor());
218 item->setHelpText(
i18nc(
"short translation please",
"Set the icon bar color."));
219 listview->addItem(item);
222 item =
new VariableBoolItem(QStringLiteral(
"icon-border"), viewConfig->iconBar());
223 item->setHelpText(
i18nc(
"short translation please",
"Enable the icon border in the editor view."));
224 listview->addItem(item);
228 item->setHelpText(
i18nc(
"short translation please",
"Set the auto indentation style."));
229 listview->addItem(item);
232 item =
new VariableBoolItem(QStringLiteral(
"indent-pasted-text"), docConfig->indentPastedText());
233 item->setHelpText(
i18nc(
"short translation please",
"Adjust indentation of text pasted from the clipboard."));
234 listview->addItem(item);
237 item =
new VariableIntItem(QStringLiteral(
"indent-width"), docConfig->indentationWidth());
238 static_cast<VariableIntItem *
>(item)->setRange(1, 200);
239 item->setHelpText(
i18nc(
"short translation please",
"Set the indentation depth for each indent level."));
240 listview->addItem(item);
243 item =
new VariableBoolItem(QStringLiteral(
"keep-extra-spaces"), docConfig->keepExtraSpaces());
244 item->setHelpText(
i18nc(
"short translation please",
"Allow odd indentation level (no multiple of indent width)."));
245 listview->addItem(item);
248 item =
new VariableBoolItem(QStringLiteral(
"line-numbers"), viewConfig->lineNumbers());
249 item->setHelpText(
i18nc(
"short translation please",
"Show line numbers."));
250 listview->addItem(item);
253 item =
new VariableBoolItem(QStringLiteral(
"newline-at-eof"), docConfig->ovr());
254 item->setHelpText(
i18nc(
"short translation please",
"Insert newline at end of file on save."));
255 listview->addItem(item);
258 item =
new VariableBoolItem(QStringLiteral(
"overwrite-mode"), docConfig->ovr());
259 item->setHelpText(
i18nc(
"short translation please",
"Enable overwrite mode in the document."));
260 listview->addItem(item);
263 item =
new VariableBoolItem(QStringLiteral(
"persistent-selection"), viewConfig->persistentSelection());
264 item->setHelpText(
i18nc(
"short translation please",
"Enable persistent text selection."));
265 listview->addItem(item);
268 item =
new VariableBoolItem(QStringLiteral(
"replace-tabs-save"),
false);
269 item->setHelpText(
i18nc(
"short translation please",
"Replace tabs with spaces when saving the document."));
270 listview->addItem(item);
273 item =
new VariableBoolItem(QStringLiteral(
"replace-tabs"), docConfig->replaceTabsDyn());
274 item->setHelpText(
i18nc(
"short translation please",
"Replace tabs with spaces."));
275 listview->addItem(item);
278 item =
new VariableRemoveSpacesItem(QStringLiteral(
"remove-trailing-spaces"), docConfig->removeSpaces());
279 item->setHelpText(
i18nc(
"short translation please",
"Remove trailing spaces when saving the document."));
280 listview->addItem(item);
283 item =
new VariableBoolItem(QStringLiteral(
"scrollbar-minimap"), viewConfig->scrollBarMiniMap());
284 item->setHelpText(
i18nc(
"short translation please",
"Show scrollbar minimap."));
285 listview->addItem(item);
288 item =
new VariableBoolItem(QStringLiteral(
"scrollbar-preview"), viewConfig->scrollBarPreview());
289 item->setHelpText(
i18nc(
"short translation please",
"Show scrollbar preview."));
290 listview->addItem(item);
294 const auto sortedThemes = KateHlManager::self()->sortedThemes();
295 themeNames.
reserve(sortedThemes.size());
296 for (
const auto &theme : sortedThemes) {
297 themeNames.
append(theme.name());
299 item =
new VariableStringListItem(QStringLiteral(
"scheme"), themeNames, rendererConfig->schema());
300 item->setHelpText(
i18nc(
"short translation please",
"Set the color scheme."));
301 listview->addItem(item);
304 item =
new VariableColorItem(QStringLiteral(
"selection-color"), rendererConfig->selectionColor());
305 item->setHelpText(
i18nc(
"short translation please",
"Set the text selection color."));
306 listview->addItem(item);
309 item =
new VariableBoolItem(QStringLiteral(
"show-tabs"), docConfig->showTabs());
310 item->setHelpText(
i18nc(
"short translation please",
"Visualize tabs and trailing spaces."));
311 listview->addItem(item);
314 item =
new VariableBoolItem(QStringLiteral(
"smart-home"), docConfig->smartHome());
315 item->setHelpText(
i18nc(
"short translation please",
"Enable smart home navigation."));
316 listview->addItem(item);
319 item =
new VariableBoolItem(QStringLiteral(
"tab-indents"), docConfig->tabIndentsEnabled());
320 item->setHelpText(
i18nc(
"short translation please",
"Pressing TAB key indents."));
321 listview->addItem(item);
324 item =
new VariableIntItem(QStringLiteral(
"tab-width"), docConfig->tabWidth());
325 static_cast<VariableIntItem *
>(item)->setRange(1, 200);
326 item->setHelpText(
i18nc(
"short translation please",
"Set the tab display width."));
327 listview->addItem(item);
330 item =
new VariableIntItem(QStringLiteral(
"undo-steps"), 0);
331 static_cast<VariableIntItem *
>(item)->setRange(0, 100);
332 item->setHelpText(
i18nc(
"short translation please",
"Set the number of undo steps to remember (0 equals infinity)."));
333 listview->addItem(item);
336 item =
new VariableIntItem(QStringLiteral(
"word-wrap-column"), docConfig->wordWrapAt());
337 static_cast<VariableIntItem *
>(item)->setRange(20, 200);
338 item->setHelpText(
i18nc(
"short translation please",
"Set the word wrap column."));
339 listview->addItem(item);
342 item =
new VariableColorItem(QStringLiteral(
"word-wrap-marker-color"), rendererConfig->wordWrapMarkerColor());
343 item->setHelpText(
i18nc(
"short translation please",
"Set the word wrap marker color."));
344 listview->addItem(item);
347 item =
new VariableBoolItem(QStringLiteral(
"word-wrap"), docConfig->wordWrap());
348 item->setHelpText(
i18nc(
"short translation please",
"Enable word wrap while typing text."));
349 listview->addItem(item);
352void VariableLineEdit::setText(
const QString &text)
357void VariableLineEdit::clear()
362QString VariableLineEdit::text()
364 return m_lineedit->
text();
367#include "moc_variablelineedit.cpp"
Backend of KTextEditor::Document related public KTextEditor interfaces.
QString highlightingMode() const override
Return the name of the currently used mode.
KateDocumentConfig * config()
Configuration.
static KTextEditor::EditorPrivate * self()
Kate Part Internal stuff ;)
static QStringList listIdentifiers()
List all possible names, i.e.
QVariant value(const int key) const
Get a config value.
QString i18nc(const char *context, const char *text, const TYPE &arg...)
QString i18n(const char *text, const TYPE &arg...)
virtual void setSpacing(int spacing) override
int pointSize() const const
QIcon fromTheme(const QString &name)
void setContentsMargins(const QMargins &margins)
void textChanged(const QString &text)
void append(QList< T > &&value)
const_reference at(qsizetype i) const const
void reserve(qsizetype size)
QMetaObject::Connection connect(const QObject *sender, PointerToMemberFunction signal, Functor functor)
T qobject_cast(QObject *object)
QFuture< ArgsType< Signal > > connect(Sender *sender, Signal signal)
bool toBool() const const