Commit c68c245f authored by hluk's avatar hluk Committed by hjk

FakeVim: Reset FakeVim properly after user command

If FakeVim mode is disabled, enable it just for the single requested
user command.

Keep useful messages shown for few seconds.

Task-number: QTCREATORBUG-10460
Change-Id: I89c1722542f47befbf2c24a663bf3d1c455b77d9
Reviewed-by: default avatarMitch Curtis <mitch.curtis@digia.com>
Reviewed-by: default avatarhjk <hjk121@nokiamail.com>
parent 790b9763
...@@ -99,6 +99,7 @@ ...@@ -99,6 +99,7 @@
#include <QTextBlock> #include <QTextBlock>
#include <QTextCursor> #include <QTextCursor>
#include <QTextEdit> #include <QTextEdit>
#include <QTimer>
#include <QTreeWidgetItem> #include <QTreeWidgetItem>
using namespace TextEditor; using namespace TextEditor;
...@@ -120,7 +121,11 @@ class MiniBuffer : public QStackedWidget ...@@ -120,7 +121,11 @@ class MiniBuffer : public QStackedWidget
Q_OBJECT Q_OBJECT
public: public:
MiniBuffer() : m_label(new QLabel(this)), m_edit(new QLineEdit(this)), m_eventFilter(0) MiniBuffer()
: m_label(new QLabel(this))
, m_edit(new QLineEdit(this))
, m_eventFilter(0)
, m_lastMessageLevel(MessageMode)
{ {
connect(m_edit, SIGNAL(textEdited(QString)), SLOT(changed())); connect(m_edit, SIGNAL(textEdited(QString)), SLOT(changed()));
connect(m_edit, SIGNAL(cursorPositionChanged(int,int)), SLOT(changed())); connect(m_edit, SIGNAL(cursorPositionChanged(int,int)), SLOT(changed()));
...@@ -129,6 +134,10 @@ public: ...@@ -129,6 +134,10 @@ public:
addWidget(m_label); addWidget(m_label);
addWidget(m_edit); addWidget(m_edit);
m_hideTimer.setSingleShot(true);
m_hideTimer.setInterval(8000);
connect(&m_hideTimer, SIGNAL(timeout()), SLOT(hide()));
} }
void setContents(const QString &contents, int cursorPos, int anchorPos, void setContents(const QString &contents, int cursorPos, int anchorPos,
...@@ -145,25 +154,32 @@ public: ...@@ -145,25 +154,32 @@ public:
m_edit->blockSignals(false); m_edit->blockSignals(false);
setCurrentWidget(m_edit); setCurrentWidget(m_edit);
m_edit->setFocus(); m_edit->setFocus();
} else if (contents.isEmpty() && messageLevel != MessageShowCmd) {
hide();
} else { } else {
show(); if (contents.isEmpty()) {
m_label->setText(contents); if (m_lastMessageLevel == MessageMode)
hide();
QString css; else
if (messageLevel == MessageError) { m_hideTimer.start();
css = _("border:1px solid rgba(255,255,255,150);" } else {
"background-color:rgba(255,0,0,100);"); m_hideTimer.stop();
} else if (messageLevel == MessageWarning) { show();
css = _("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(255,255,0,20);"); m_label->setText(contents);
} else if (messageLevel == MessageShowCmd) {
css = _("border:1px solid rgba(255,255,255,120);" QString css;
"background-color:rgba(100,255,100,30);"); if (messageLevel == MessageError) {
css = _("border:1px solid rgba(255,255,255,150);"
"background-color:rgba(255,0,0,100);");
} else if (messageLevel == MessageWarning) {
css = _("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(255,255,0,20);");
} else if (messageLevel == MessageShowCmd) {
css = _("border:1px solid rgba(255,255,255,120);"
"background-color:rgba(100,255,100,30);");
}
m_label->setStyleSheet(QString::fromLatin1(
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
} }
m_label->setStyleSheet(QString::fromLatin1(
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
if (m_edit->hasFocus()) if (m_edit->hasFocus())
emit edited(QString(), -1, -1); emit edited(QString(), -1, -1);
...@@ -183,6 +199,8 @@ public: ...@@ -183,6 +199,8 @@ public:
} }
m_eventFilter = eventFilter; m_eventFilter = eventFilter;
} }
m_lastMessageLevel = messageLevel;
} }
QSize sizeHint() const QSize sizeHint() const
...@@ -209,6 +227,8 @@ private: ...@@ -209,6 +227,8 @@ private:
QLabel *m_label; QLabel *m_label;
QLineEdit *m_edit; QLineEdit *m_edit;
QObject *m_eventFilter; QObject *m_eventFilter;
QTimer m_hideTimer;
int m_lastMessageLevel;
}; };
/////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////
...@@ -1124,11 +1144,20 @@ void FakeVimPluginPrivate::userActionTriggered() ...@@ -1124,11 +1144,20 @@ void FakeVimPluginPrivate::userActionTriggered()
const int key = act->data().toInt(); const int key = act->data().toInt();
if (!key) if (!key)
return; return;
QString cmd = userCommandMap().value(key);
IEditor *editor = EditorManager::currentEditor(); IEditor *editor = EditorManager::currentEditor();
FakeVimHandler *handler = m_editorToHandler[editor]; FakeVimHandler *handler = m_editorToHandler[editor];
if (handler) if (handler) {
// If disabled, enable FakeVim mode just for single user command.
bool enableFakeVim = !theFakeVimSetting(ConfigUseFakeVim)->value().toBool();
if (enableFakeVim)
setUseFakeVimInternal(true);
const QString cmd = userCommandMap().value(key);
handler->handleInput(cmd); handler->handleInput(cmd);
if (enableFakeVim)
setUseFakeVimInternal(false);
}
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment