summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristoph Cullmann <cullmann@kde.org>2014-01-21 15:55:15 (GMT)
committerChristoph Cullmann <cullmann@kde.org>2014-01-21 15:55:15 (GMT)
commiteac65e431524eea2c2e8fc48b8bb1e0b2378f27f (patch)
tree3b8e7899ac3723e1ffae9535f19add786b842a04
parentccd7be29a41122857a734dfc5a44a48eb3c2a995 (diff)
finally: sane switch of mode & encoding via status bar
-rw-r--r--src/view/katestatusbar.cpp37
-rw-r--r--src/view/katestatusbar.h6
-rw-r--r--src/view/kateview.cpp23
-rw-r--r--src/view/kateview.h28
4 files changed, 76 insertions, 18 deletions
diff --git a/src/view/katestatusbar.cpp b/src/view/katestatusbar.cpp
index a40e67b..97a2249 100644
--- a/src/view/katestatusbar.cpp
+++ b/src/view/katestatusbar.cpp
@@ -20,6 +20,8 @@
#include "katestatusbar.h"
+#include "katemodemenu.h"
+
#include <KIconUtils>
#include <KLocalizedString>
@@ -68,11 +70,25 @@ KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view)
m_infoLabel->setAlignment(Qt::AlignVCenter | Qt::AlignRight);
m_infoLabel->installEventFilter( this );
+ /**
+ * add mode button which allows user to switch mode of document
+ * this will reuse the mode action menu of the view
+ */
+ m_mode = new QPushButton( QString(), m_statusBar );
+ m_mode->setFlat(true);
+ m_statusBar->addPermanentWidget( m_mode, 0 );
+ m_mode->setMenu(m_view->modeAction()->menu());
+ m_mode->installEventFilter( this );
- m_encodingLabel = new QLabel( QString(), m_statusBar );
- m_statusBar->addPermanentWidget( m_encodingLabel, 0 );
- m_encodingLabel->setAlignment( Qt::AlignCenter );
- m_encodingLabel->installEventFilter( this );
+ /**
+ * add encoding button which allows user to switch encoding of document
+ * this will reuse the encoding action menu of the view
+ */
+ m_encoding = new QPushButton( QString(), m_statusBar );
+ m_encoding->setFlat(true);
+ m_statusBar->addPermanentWidget( m_encoding, 0 );
+ m_encoding->setMenu(m_view->encodingAction()->menu());
+ m_encoding->installEventFilter( this );
#ifdef Q_WS_MAC
m_statusBar->setSizeGripEnabled( false );
@@ -95,15 +111,18 @@ KateStatusBar::KateStatusBar(KTextEditor::ViewPrivate *view)
connect(m_view->document(), SIGNAL(modifiedChanged(KTextEditor::Document*)), this, SLOT(modifiedChanged()));
connect(m_view->document(), SIGNAL(modifiedOnDisk(KTextEditor::Document*,bool,KTextEditor::ModificationInterface::ModifiedOnDiskReason)), this, SLOT(modifiedChanged()) );
connect(m_view->document(), SIGNAL(configChanged()), this, SLOT(documentConfigChanged()));
+ connect(m_view->document(), SIGNAL(modeChanged(KTextEditor::Document*)), this, SLOT(modeChanged()));
updateStatus ();
}
bool KateStatusBar::eventFilter(QObject*, QEvent *e)
{
+ /**
+ * we forward focus always
+ */
if (e->type() == QEvent::MouseButtonPress) {
m_view->setFocus();
- return true;
}
return false;
@@ -117,6 +136,7 @@ void KateStatusBar::updateStatus ()
modifiedChanged ();
documentConfigChanged ();
m_infoLabel->clear ();
+ modeChanged();
}
void KateStatusBar::viewModeChanged ()
@@ -170,5 +190,10 @@ void KateStatusBar::modifiedChanged()
void KateStatusBar::documentConfigChanged ()
{
- m_encodingLabel->setText( QString::fromLatin1(" %1 ").arg (m_view->document()->encoding()) );
+ m_encoding->setText( m_view->document()->encoding() );
+}
+
+void KateStatusBar::modeChanged ()
+{
+ m_mode->setText( m_view->document()->mode() );
}
diff --git a/src/view/katestatusbar.h b/src/view/katestatusbar.h
index 3afc6ec..c7195f0 100644
--- a/src/view/katestatusbar.h
+++ b/src/view/katestatusbar.h
@@ -28,6 +28,7 @@
#include <QLabel>
#include <QPixmap>
+#include <QPushButton>
#include <QStatusBar>
class KateStatusBar : public KateViewBarWidget
@@ -52,6 +53,8 @@ public Q_SLOTS:
void informationMessage (KTextEditor::View *view, const QString &message);
+ void modeChanged ();
+
protected:
virtual bool eventFilter (QObject*, QEvent *);
@@ -62,7 +65,8 @@ private:
QLabel* m_modifiedLabel;
QLabel* m_insertModeLabel;
QLabel* m_selectModeLabel;
- QLabel* m_encodingLabel;
+ QPushButton* m_mode;
+ QPushButton* m_encoding;
KSqueezedTextLabel* m_infoLabel;
QPixmap m_modPm, m_modDiscPm, m_modmodPm;
};
diff --git a/src/view/kateview.cpp b/src/view/kateview.cpp
index 0dc4a22..8b73866 100644
--- a/src/view/kateview.cpp
+++ b/src/view/kateview.cpp
@@ -220,11 +220,6 @@ KTextEditor::ViewPrivate::ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget
m_vBox->addWidget(m_bottomViewBar);
}
- /**
- * create the status bar of this view
- */
- toggleStatusBar();
-
// add layout for floating message widgets to KateViewInternal
m_notificationLayout = new QVBoxLayout(m_viewInternal);
m_notificationLayout->setContentsMargins(20, 20, 20, 20);
@@ -249,6 +244,12 @@ KTextEditor::ViewPrivate::ViewPrivate(KTextEditor::DocumentPrivate *doc, QWidget
// update the enabled state of the undo/redo actions...
slotUpdateUndo();
+ /**
+ * create the status bar of this view
+ * do this after action creation, we use some of them!
+ */
+ toggleStatusBar();
+
m_startingUp = false;
updateConfig();
@@ -480,10 +481,10 @@ void KTextEditor::ViewPrivate::setupActions()
a->setWhatsThis(i18n("Configure various aspects of this editor."));
connect(a, SIGNAL(triggered(bool)), SLOT(slotConfigDialog()));
- KateModeMenu *ftm = new KateModeMenu(i18n("&Mode"), this);
- ac->addAction(QLatin1String("tools_mode"), ftm);
- ftm->setWhatsThis(i18n("Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
- ftm->updateMenu(m_doc);
+ m_modeAction = new KateModeMenu(i18n("&Mode"), this);
+ ac->addAction(QLatin1String("tools_mode"), m_modeAction);
+ m_modeAction->setWhatsThis(i18n("Here you can choose which mode should be used for the current document. This will influence the highlighting and folding being used, for example."));
+ m_modeAction->updateMenu(m_doc);
KateHighlightingMenu *menu = new KateHighlightingMenu(i18n("&Highlighting"), this);
ac->addAction(QLatin1String("tools_highlighting"), menu);
@@ -624,8 +625,8 @@ void KTextEditor::ViewPrivate::setupActions()
a->setWhatsThis(i18n("Enable/disable adding of byte order markers for UTF-8/UTF-16 encoded files while saving"));
connect(m_addBom, SIGNAL(triggered(bool)), this, SLOT(setAddBom(bool)));
// encoding menu
- KateViewEncodingAction *encodingAction = new KateViewEncodingAction(m_doc, this, i18n("E&ncoding"), this);
- ac->addAction(QLatin1String("set_encoding"), encodingAction);
+ m_encodingAction = new KateViewEncodingAction(m_doc, this, i18n("E&ncoding"), this);
+ ac->addAction(QLatin1String("set_encoding"), m_encodingAction);
a = ac->addAction(KStandardAction::Find, this, SLOT(find()));
a->setWhatsThis(i18n("Look up the first occurrence of a piece of text or regular expression."));
diff --git a/src/view/kateview.h b/src/view/kateview.h
index 6865c67..7dc8521 100644
--- a/src/view/kateview.h
+++ b/src/view/kateview.h
@@ -65,6 +65,8 @@ class KateSpellingMenu;
class KateMessageWidget;
class KateIconBorder;
class KateStatusBar;
+class KateViewEncodingAction;
+class KateModeMenu;
class KToggleAction;
class KSelectAction;
@@ -949,11 +951,37 @@ public:
*/
void toggleStatusBar ();
+ /**
+ * Get the encoding menu
+ * @return the encoding menu
+ */
+ KateViewEncodingAction *encodingAction () const {
+ return m_encodingAction;
+ }
+
+ /**
+ * Get the mode menu
+ * @return the mode menu
+ */
+ KateModeMenu *modeAction () const {
+ return m_modeAction;
+ }
+
private:
/**
* the status bar of this view
*/
KateStatusBar *m_statusBar;
+
+ /**
+ * the encoding selection menu, used by view + status bar
+ */
+ KateViewEncodingAction *m_encodingAction;
+
+ /**
+ * the mode selection menu, used by view + status bar
+ */
+ KateModeMenu *m_modeAction;
};
}