[ktexteditor] src/view: add context menu to statusbar to toggle show total lines/word count
Christoph Cullmann
null at kde.org
Wed Jun 20 18:42:43 UTC 2018
Git commit 7651b840075f90e2091903e5d918ad03517fee19 by Christoph Cullmann.
Committed on 20/06/2018 at 18:40.
Pushed by cullmann into branch 'master'.
add context menu to statusbar to toggle show total lines/word count
GUI: context menu for status bar to alter settings
Differential Revision: https://phabricator.kde.org/D13442
M +32 -0 src/view/katestatusbar.cpp
M +3 -0 src/view/katestatusbar.h
M +1 -0 src/view/kateview.cpp
https://commits.kde.org/ktexteditor/7651b840075f90e2091903e5d918ad03517fee19
diff --git a/src/view/katestatusbar.cpp b/src/view/katestatusbar.cpp
index 87577ccf..ea7f9ce3 100644
--- a/src/view/katestatusbar.cpp
+++ b/src/view/katestatusbar.cpp
@@ -221,6 +221,28 @@ bool KateStatusBar::eventFilter(QObject *obj, QEvent *event)
return KateViewBarWidget::eventFilter(obj, event);
}
+void KateStatusBar::contextMenuEvent(QContextMenuEvent *event)
+{
+ QMenu menu(this);
+ QAction *showLines = menu.addAction(QStringLiteral("Show Lines Count"), this, &KateStatusBar::toggleShowLines);
+ showLines->setCheckable(true);
+ showLines->setChecked(KateViewConfig::global()->showLinesCount());
+ QAction *showWords = menu.addAction(QStringLiteral("Show word count"), this, &KateStatusBar::toggleShowWords);
+ showWords->setCheckable(true);
+ showWords->setChecked(KateViewConfig::global()->showWordCount());
+ menu.exec(event->globalPos());
+}
+
+void KateStatusBar::toggleShowLines(bool checked)
+{
+ KateViewConfig::global()->setShowLinesCount(checked);
+}
+
+void KateStatusBar::toggleShowWords(bool checked)
+{
+ KateViewConfig::global()->setShowWordCount(checked);
+}
+
void KateStatusBar::updateStatus ()
{
selectionChanged ();
@@ -257,7 +279,17 @@ void KateStatusBar::cursorPositionChanged ()
{
KTextEditor::Cursor position (m_view->cursorPositionVirtual());
+ if( KateViewConfig::global()->showLinesCount() )
m_lineColLabel->setText(
+ i18n("Line %1 of %2, Column %3"
+ , QLocale().toString(position.line() + 1)
+ , QLocale().toString(m_view->doc()->lines())
+ , QLocale().toString(position.column() + 1)
+ )
+ );
+
+ else
+ m_lineColLabel->setText(
i18n("Line %1, Column %2"
, QLocale().toString(position.line() + 1)
, QLocale().toString(position.column() + 1)
diff --git a/src/view/katestatusbar.h b/src/view/katestatusbar.h
index a9e39fb8..c8aedda2 100644
--- a/src/view/katestatusbar.h
+++ b/src/view/katestatusbar.h
@@ -72,6 +72,7 @@ public Q_SLOTS:
protected:
bool eventFilter(QObject *obj, QEvent *event) override;
+ void contextMenuEvent(QContextMenuEvent *event) override;
private:
KTextEditor::ViewPrivate *const m_view;
@@ -104,6 +105,8 @@ public Q_SLOTS:
void slotTabGroup(QAction*);
void slotIndentGroup(QAction*);
void slotIndentTabMode(QAction*);
+ void toggleShowLines(bool checked);
+ void toggleShowWords(bool checked);
};
#endif
diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp
index 201875af..a7fd00f8 100644
--- a/src/view/kateview.cpp
+++ b/src/view/kateview.cpp
@@ -1864,6 +1864,7 @@ void KTextEditor::ViewPrivate::updateConfig()
m_viewInternal->cache()->clear();
tagAll();
updateView(true);
+ m_statusBar->updateStatus();
emit configChanged();
}
More information about the kde-doc-english
mailing list