Changeset View
Changeset View
Standalone View
Standalone View
src/view/katestatusbar.cpp
Show All 25 Lines | |||||
26 | #include "katedocument.h" | 26 | #include "katedocument.h" | ||
27 | #include "kateconfig.h" | 27 | #include "kateconfig.h" | ||
28 | #include "kateabstractinputmode.h" | 28 | #include "kateabstractinputmode.h" | ||
29 | #include "wordcounter.h" | 29 | #include "wordcounter.h" | ||
30 | 30 | | |||
31 | #include <KLocalizedString> | 31 | #include <KLocalizedString> | ||
32 | #include <KIconUtils> | 32 | #include <KIconUtils> | ||
33 | #include <KAcceleratorManager> | 33 | #include <KAcceleratorManager> | ||
34 | #include <Sonnet/Speller> | ||||
34 | 35 | | |||
35 | #include <QHBoxLayout> | 36 | #include <QHBoxLayout> | ||
36 | #include <QInputDialog> | 37 | #include <QInputDialog> | ||
37 | 38 | | |||
38 | //BEGIN menu | 39 | //BEGIN menu | ||
39 | KateStatusBarOpenUpMenu::KateStatusBarOpenUpMenu(QWidget *parent) : QMenu(parent) {} | 40 | KateStatusBarOpenUpMenu::KateStatusBarOpenUpMenu(QWidget *parent) : QMenu(parent) {} | ||
40 | KateStatusBarOpenUpMenu::~KateStatusBarOpenUpMenu() {} | 41 | KateStatusBarOpenUpMenu::~KateStatusBarOpenUpMenu() {} | ||
41 | 42 | | |||
▲ Show 20 Lines • Show All 66 Lines • ▼ Show 20 Line(s) | 77 | { | |||
108 | * show the current mode, like INSERT, OVERWRITE, VI + modifiers like [BLOCK] | 109 | * show the current mode, like INSERT, OVERWRITE, VI + modifiers like [BLOCK] | ||
109 | */ | 110 | */ | ||
110 | m_inputMode = new StatusBarButton(this); | 111 | m_inputMode = new StatusBarButton(this); | ||
111 | topLayout->addWidget(m_inputMode); | 112 | topLayout->addWidget(m_inputMode); | ||
112 | m_inputMode->setWhatsThis(i18n("Insert mode and VI input mode indicator. Click to change the mode.")); | 113 | m_inputMode->setWhatsThis(i18n("Insert mode and VI input mode indicator. Click to change the mode.")); | ||
113 | connect(m_inputMode, &StatusBarButton::clicked, [=] { m_view->currentInputMode()->toggleInsert(); }); | 114 | connect(m_inputMode, &StatusBarButton::clicked, [=] { m_view->currentInputMode()->toggleInsert(); }); | ||
114 | 115 | | |||
115 | /** | 116 | /** | ||
116 | * allow to change indentation configuration | 117 | * Add dictionary button which allows user to switch dictionary of the document | ||
117 | */ | 118 | */ | ||
119 | m_dictionary = new StatusBarButton(this); | ||||
120 | topLayout->addWidget(m_dictionary, 0); | ||||
121 | m_dictionary->setWhatsThis(i18n("Change dictionary")); | ||||
122 | m_dictionaryMenu = new KateStatusBarOpenUpMenu(m_dictionary); | ||||
123 | m_dictionaryMenu->addAction(m_view->action("tools_change_dictionary")); | ||||
124 | m_dictionaryMenu->addAction(m_view->action("tools_clear_dictionary_ranges")); | ||||
125 | m_dictionaryMenu->addAction(m_view->action("tools_toggle_automatic_spell_checking")); | ||||
126 | m_dictionaryMenu->addAction(m_view->action("tools_spelling_from_cursor")); | ||||
127 | m_dictionaryMenu->addAction(m_view->action("tools_spelling")); | ||||
128 | m_dictionaryMenu->addSeparator(); | ||||
129 | m_dictionaryGroup = new QActionGroup(m_dictionaryMenu); | ||||
130 | QMapIterator<QString, QString> i(Sonnet::Speller().preferredDictionaries()); | ||||
131 | while (i.hasNext()) { | ||||
132 | i.next(); | ||||
133 | QAction *action = m_dictionaryGroup->addAction(i.key()); | ||||
134 | action->setData(i.value()); | ||||
135 | action->setToolTip(i.key()); | ||||
136 | action->setCheckable(true); | ||||
137 | m_dictionaryMenu->addAction(action); | ||||
138 | } | ||||
139 | m_dictionary->setMenu(m_dictionaryMenu); | ||||
140 | connect(m_dictionaryGroup, &QActionGroup::triggered, this, &KateStatusBar::changeDictionary); | ||||
118 | 141 | | |||
142 | /** | ||||
143 | * allow to change indentation configuration | ||||
144 | */ | ||||
119 | m_tabsIndent = new StatusBarButton(this); | 145 | m_tabsIndent = new StatusBarButton(this); | ||
120 | topLayout->addWidget(m_tabsIndent); | 146 | topLayout->addWidget(m_tabsIndent); | ||
121 | 147 | | |||
122 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | 148 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | ||
123 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | 149 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | ||
124 | m_tabGroup = new QActionGroup(this); | 150 | m_tabGroup = new QActionGroup(this); | ||
125 | addNumberAction(m_tabGroup, m_indentSettingsMenu, -1); | 151 | addNumberAction(m_tabGroup, m_indentSettingsMenu, -1); | ||
126 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 8); | 152 | addNumberAction(m_tabGroup, m_indentSettingsMenu, 8); | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | |||||
173 | connect(m_view, &KTextEditor::View::cursorPositionChanged, this, &KateStatusBar::cursorPositionChanged); | 199 | connect(m_view, &KTextEditor::View::cursorPositionChanged, this, &KateStatusBar::cursorPositionChanged); | ||
174 | connect(m_view, &KTextEditor::View::viewModeChanged, this, &KateStatusBar::viewModeChanged); | 200 | connect(m_view, &KTextEditor::View::viewModeChanged, this, &KateStatusBar::viewModeChanged); | ||
175 | connect(m_view, &KTextEditor::View::selectionChanged, this, &KateStatusBar::selectionChanged); | 201 | connect(m_view, &KTextEditor::View::selectionChanged, this, &KateStatusBar::selectionChanged); | ||
176 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modifiedChanged, this, &KateStatusBar::modifiedChanged); | 202 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modifiedChanged, this, &KateStatusBar::modifiedChanged); | ||
177 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::modifiedOnDisk, this, &KateStatusBar::modifiedChanged); | 203 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::modifiedOnDisk, this, &KateStatusBar::modifiedChanged); | ||
178 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::configChanged, this, &KateStatusBar::documentConfigChanged); | 204 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::configChanged, this, &KateStatusBar::documentConfigChanged); | ||
179 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modeChanged, this, &KateStatusBar::modeChanged); | 205 | connect(m_view->document(), &KTextEditor::DocumentPrivate::modeChanged, this, &KateStatusBar::modeChanged); | ||
180 | connect(m_view, &KTextEditor::ViewPrivate::configChanged, this, &KateStatusBar::configChanged); | 206 | connect(m_view, &KTextEditor::ViewPrivate::configChanged, this, &KateStatusBar::configChanged); | ||
207 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::defaultDictionaryChanged, this, &KateStatusBar::updateDictionary); | ||||
208 | connect(m_view->doc(), &KTextEditor::DocumentPrivate::dictionaryRangesPresent, this, &KateStatusBar::updateDictionary); | ||||
209 | connect(m_view, &KTextEditor::ViewPrivate::caretChangedRange, this, &KateStatusBar::updateDictionary); | ||||
181 | 210 | | |||
182 | updateStatus(); | 211 | updateStatus(); | ||
183 | toggleWordCount(KateViewConfig::global()->showWordCount()); | 212 | toggleWordCount(KateViewConfig::global()->showWordCount()); | ||
184 | } | 213 | } | ||
185 | 214 | | |||
186 | bool KateStatusBar::eventFilter(QObject *obj, QEvent *event) | 215 | bool KateStatusBar::eventFilter(QObject *obj, QEvent *event) | ||
187 | { | 216 | { | ||
188 | return KateViewBarWidget::eventFilter(obj, event); | 217 | return KateViewBarWidget::eventFilter(obj, event); | ||
Show All 26 Lines | |||||
215 | void KateStatusBar::updateStatus() | 244 | void KateStatusBar::updateStatus() | ||
216 | { | 245 | { | ||
217 | selectionChanged(); | 246 | selectionChanged(); | ||
218 | viewModeChanged(); | 247 | viewModeChanged(); | ||
219 | cursorPositionChanged(); | 248 | cursorPositionChanged(); | ||
220 | modifiedChanged(); | 249 | modifiedChanged(); | ||
221 | documentConfigChanged(); | 250 | documentConfigChanged(); | ||
222 | modeChanged(); | 251 | modeChanged(); | ||
252 | updateDictionary(); | ||||
223 | } | 253 | } | ||
224 | 254 | | |||
225 | void KateStatusBar::selectionChanged() | 255 | void KateStatusBar::selectionChanged() | ||
226 | { | 256 | { | ||
227 | const unsigned int newSelectionMode = m_view->blockSelection(); | 257 | const unsigned int newSelectionMode = m_view->blockSelection(); | ||
228 | if (newSelectionMode == m_selectionMode) { | 258 | if (newSelectionMode == m_selectionMode) { | ||
229 | return; | 259 | return; | ||
230 | } | 260 | } | ||
Show All 12 Lines | 268 | { | |||
243 | 273 | | |||
244 | m_inputMode->setText(text); | 274 | m_inputMode->setText(text); | ||
245 | } | 275 | } | ||
246 | 276 | | |||
247 | void KateStatusBar::cursorPositionChanged() | 277 | void KateStatusBar::cursorPositionChanged() | ||
248 | { | 278 | { | ||
249 | KTextEditor::Cursor position(m_view->cursorPositionVirtual()); | 279 | KTextEditor::Cursor position(m_view->cursorPositionVirtual()); | ||
250 | 280 | | |||
281 | // Update line/column label | ||||
251 | QString text; | 282 | QString text; | ||
252 | | ||||
253 | if (KateViewConfig::global()->showLineCount()) { | 283 | if (KateViewConfig::global()->showLineCount()) { | ||
254 | text = i18n("Line %1 of %2, Column %3", QLocale().toString(position.line() + 1) | 284 | text = i18n("Line %1 of %2, Column %3", QLocale().toString(position.line() + 1) | ||
255 | , QLocale().toString(m_view->doc()->lines()) | 285 | , QLocale().toString(m_view->doc()->lines()) | ||
256 | , QLocale().toString(position.column() + 1) | 286 | , QLocale().toString(position.column() + 1) | ||
257 | ); | 287 | ); | ||
258 | } else { | 288 | } else { | ||
259 | text = i18n("Line %1, Column %2", QLocale().toString(position.line() + 1) | 289 | text = i18n("Line %1, Column %2", QLocale().toString(position.line() + 1) | ||
260 | , QLocale().toString(position.column() + 1) | 290 | , QLocale().toString(position.column() + 1) | ||
261 | ); | 291 | ); | ||
262 | } | 292 | } | ||
263 | | ||||
264 | if (m_wordCounter) { | 293 | if (m_wordCounter) { | ||
265 | text.append(QStringLiteral(", ") + m_wordCount); | 294 | text.append(QStringLiteral(", ") + m_wordCount); | ||
266 | } | 295 | } | ||
267 | | ||||
268 | m_cursorPosition->setText(text); | 296 | m_cursorPosition->setText(text); | ||
269 | } | 297 | } | ||
270 | 298 | | |||
299 | void KateStatusBar::updateDictionary() | ||||
300 | { | ||||
301 | QString newDict; | ||||
302 | // Check if at the current cursor position is a special dictionary in use | ||||
303 | KTextEditor::Cursor position(m_view->cursorPositionVirtual()); | ||||
304 | const QList<QPair<KTextEditor::MovingRange *, QString>> dictRanges = m_view->doc()->dictionaryRanges(); | ||||
305 | for (auto rangeDictPair : dictRanges) { | ||||
306 | const KTextEditor::MovingRange *range = rangeDictPair.first; | ||||
307 | if (range->contains(position) || range->end() == position) { | ||||
308 | newDict = rangeDictPair.second; | ||||
309 | break; | ||||
310 | } | ||||
311 | } | ||||
312 | // Check if the default dictionary is in use | ||||
313 | if (newDict.isEmpty()) { | ||||
314 | newDict = m_view->doc()->defaultDictionary(); | ||||
315 | if (newDict.isEmpty()) { | ||||
316 | newDict = Sonnet::Speller().defaultLanguage(); | ||||
317 | } | ||||
318 | } | ||||
319 | // Update button and menu only on a changed dictionary | ||||
320 | if (!m_dictionaryGroup->checkedAction() || (m_dictionaryGroup->checkedAction()->data().toString() != newDict) || m_dictionary->text().isEmpty()) { | ||||
321 | bool found = false; | ||||
322 | // Remove "-w_accents -variant_0" and such from dict-code to keep it small and clean | ||||
323 | m_dictionary->setText(newDict.section(QLatin1Char('-'), 0, 0)); | ||||
324 | // For maximum user clearness, change the checked menu option | ||||
325 | m_dictionaryGroup->blockSignals(true); | ||||
326 | for (auto a : m_dictionaryGroup->actions()) { | ||||
327 | if (a->data().toString() == newDict) { | ||||
328 | a->setChecked(true); | ||||
329 | found = true; | ||||
330 | break; | ||||
331 | } | ||||
332 | } | ||||
333 | if (!found) { | ||||
334 | // User has chose some other dictionary from combo box, we need to add that | ||||
335 | QString dictName = Sonnet::Speller().availableDictionaries().key(newDict); | ||||
336 | QAction *action = m_dictionaryGroup->addAction(dictName); | ||||
337 | action->setData(newDict); | ||||
338 | action->setCheckable(true); | ||||
339 | action->setChecked(true); | ||||
340 | m_dictionaryMenu->addAction(action); | ||||
341 | } | ||||
342 | m_dictionaryGroup->blockSignals(false); | ||||
343 | } | ||||
344 | } | ||||
345 | | ||||
271 | void KateStatusBar::modifiedChanged() | 346 | void KateStatusBar::modifiedChanged() | ||
272 | { | 347 | { | ||
273 | const bool mod = m_view->doc()->isModified(); | 348 | const bool mod = m_view->doc()->isModified(); | ||
274 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | 349 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | ||
275 | 350 | | |||
276 | /** | 351 | /** | ||
277 | * combine to modified status, update only if changed | 352 | * combine to modified status, update only if changed | ||
278 | */ | 353 | */ | ||
▲ Show 20 Lines • Show All 180 Lines • ▼ Show 20 Line(s) | 528 | { | |||
459 | 534 | | |||
460 | cursorPositionChanged(); | 535 | cursorPositionChanged(); | ||
461 | } | 536 | } | ||
462 | 537 | | |||
463 | void KateStatusBar::configChanged() | 538 | void KateStatusBar::configChanged() | ||
464 | { | 539 | { | ||
465 | toggleWordCount(m_view->config()->showWordCount()); | 540 | toggleWordCount(m_view->config()->showWordCount()); | ||
466 | } | 541 | } | ||
542 | | ||||
543 | void KateStatusBar::changeDictionary(QAction *action) | ||||
544 | { | ||||
545 | const QString dictionary = action->data().toString(); | ||||
546 | m_dictionary->setText(dictionary); | ||||
547 | // Code stolen from KateDictionaryBar::dictionaryChanged | ||||
548 | KTextEditor::Range selection = m_view->selectionRange(); | ||||
549 | if (selection.isValid() && !selection.isEmpty()) { | ||||
550 | m_view->doc()->setDictionary(dictionary, selection); | ||||
551 | } else { | ||||
552 | m_view->doc()->setDefaultDictionary(dictionary); | ||||
553 | } | ||||
554 | } |