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 | /** | ||
117 | * Add dictionary button which allows user to switch dictionary of document | ||||
118 | */ | ||||
119 | m_dictionary = new StatusBarButton(this, QString(i18n("Dictionary"))); | ||||
120 | topLayout->addWidget(m_dictionary, 0); | ||||
121 | m_dictionary->setWhatsThis(i18n("Change dictionary")); | ||||
122 | KateStatusBarOpenUpMenu *menu = new KateStatusBarOpenUpMenu(m_dictionary); | ||||
123 | menu->addAction(m_view->action("tools_toggle_automatic_spell_checking")); | ||||
124 | menu->addAction(m_view->action("tools_spelling")); | ||||
125 | menu->addAction(m_view->action("tools_spelling_from_cursor")); | ||||
126 | menu->addAction(m_view->action("tools_spelling_selection")); | ||||
127 | menu->addAction(m_view->action("tools_clear_dictionary_ranges")); | ||||
128 | menu->addAction(m_view->action("tools_change_dictionary")); | ||||
129 | menu->addSection(i18n("Preferred Dictionaries")); | ||||
130 | m_dictionaryGroup = new QActionGroup(menu); | ||||
131 | QMapIterator<QString, QString> i(Sonnet::Speller().preferredDictionaries()); | ||||
132 | QAction *action; | ||||
133 | while (i.hasNext()) { | ||||
134 | i.next(); | ||||
135 | action = m_dictionaryGroup->addAction(i.key()); | ||||
136 | action->setData(i.value()); | ||||
137 | action->setToolTip(i.key()); | ||||
138 | action->setCheckable(true); | ||||
139 | menu->addAction(action); | ||||
140 | } | ||||
141 | action->setChecked(true); | ||||
142 | m_dictionary->setMenu(menu); | ||||
143 | connect(m_dictionaryGroup, &QActionGroup::triggered, this, &KateStatusBar::dictionaryChanged); | ||||
144 | | ||||
145 | /** | ||||
116 | * allow to change indentation configuration | 146 | * allow to change indentation configuration | ||
117 | */ | 147 | */ | ||
118 | 148 | | |||
119 | m_tabsIndent = new StatusBarButton(this); | 149 | m_tabsIndent = new StatusBarButton(this); | ||
120 | topLayout->addWidget(m_tabsIndent); | 150 | topLayout->addWidget(m_tabsIndent); | ||
121 | 151 | | |||
122 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | 152 | m_indentSettingsMenu = new KateStatusBarOpenUpMenu(m_tabsIndent); | ||
123 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | 153 | m_indentSettingsMenu->addSection(i18n("Tab Width")); | ||
▲ Show 20 Lines • Show All 119 Lines • ▼ Show 20 Line(s) | 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); | ||
297 | | ||||
298 | // Update dictionary button | ||||
299 | QString newDict; | ||||
300 | // Check if at the current cursor position is a different dictionary to use | ||||
301 | const QList<QPair<KTextEditor::MovingRange *, QString> > dictRanges = m_view->doc()->dictionaryRanges(); | ||||
302 | for (auto rangeDictPair : dictRanges) { | ||||
303 | if (rangeDictPair.first->contains(position)) { | ||||
304 | newDict = rangeDictPair.second; | ||||
305 | break; | ||||
306 | } | ||||
307 | } | ||||
308 | // Check if the default dictionary is in use | ||||
309 | if (newDict.isEmpty()) { | ||||
310 | newDict = m_view->doc()->defaultDictionary(); // May return an empty string, it's for me a BUG | ||||
311 | if (newDict.isEmpty()) { // This code should be part of KTextEditor::DocumentPrivate | ||||
312 | newDict = Sonnet::Speller().defaultLanguage(); | ||||
313 | } | ||||
314 | } | ||||
315 | // Update button and menu only on a changed dictionary | ||||
316 | if (m_dictionaryGroup->checkedAction()->data().toString() != newDict) { | ||||
317 | bool found = false; | ||||
318 | m_dictionary->setText(newDict); | ||||
319 | // For maximum user clearness, change the checked menu option | ||||
320 | m_dictionaryGroup->blockSignals(true); | ||||
321 | for (auto a : m_dictionaryGroup->actions()) { | ||||
322 | if (a->data().toString() == newDict) { | ||||
323 | a->setChecked(true); | ||||
324 | found = true; | ||||
325 | break; | ||||
326 | } | ||||
327 | } | ||||
328 | if (!found) { | ||||
329 | // User has chose some other dictionary from combo box, we need to add that | ||||
330 | QAction *action = m_dictionaryGroup->addAction(newDict); | ||||
331 | action->setData(newDict); | ||||
332 | action->setCheckable(true); | ||||
333 | action->setChecked(true); | ||||
334 | //menu->addAction(action); TODO or not TODO? | ||||
335 | } | ||||
336 | m_dictionaryGroup->blockSignals(false); | ||||
337 | } | ||||
269 | } | 338 | } | ||
270 | 339 | | |||
271 | void KateStatusBar::modifiedChanged() | 340 | void KateStatusBar::modifiedChanged() | ||
272 | { | 341 | { | ||
273 | const bool mod = m_view->doc()->isModified(); | 342 | const bool mod = m_view->doc()->isModified(); | ||
274 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | 343 | const bool modOnHD = m_view->doc()->isModifiedOnDisc(); | ||
275 | 344 | | |||
276 | /** | 345 | /** | ||
▲ Show 20 Lines • Show All 182 Lines • ▼ Show 20 Line(s) | 522 | { | |||
459 | 528 | | |||
460 | cursorPositionChanged(); | 529 | cursorPositionChanged(); | ||
461 | } | 530 | } | ||
462 | 531 | | |||
463 | void KateStatusBar::configChanged() | 532 | void KateStatusBar::configChanged() | ||
464 | { | 533 | { | ||
465 | toggleWordCount(m_view->config()->showWordCount()); | 534 | toggleWordCount(m_view->config()->showWordCount()); | ||
466 | } | 535 | } | ||
536 | | ||||
537 | void KateStatusBar::dictionaryChanged(QAction *action) | ||||
538 | { | ||||
539 | const QString dictionary = action->data().toString(); | ||||
540 | m_dictionary->setText(dictionary); | ||||
541 | // Code stolen from KateDictionaryBar::dictionaryChanged | ||||
542 | KTextEditor::Range selection = m_view->selectionRange(); | ||||
543 | if (selection.isValid() && !selection.isEmpty()) { | ||||
544 | m_view->doc()->setDictionary(dictionary, selection); | ||||
545 | } else { | ||||
546 | m_view->doc()->setDefaultDictionary(dictionary); | ||||
547 | } | ||||
548 | } |