somewhat better intergration of fakevim into creator

This commit is contained in:
hjk
2009-01-07 17:41:09 +01:00
parent db595e2f41
commit 634edf2aab
5 changed files with 45 additions and 40 deletions

View File

@@ -65,6 +65,7 @@ enum MakeWritableResult {
}; };
struct EditorManagerPrivate; struct EditorManagerPrivate;
namespace Internal { namespace Internal {
class OpenEditorsWindow; class OpenEditorsWindow;
class EditorSplitter; class EditorSplitter;
@@ -224,7 +225,8 @@ private:
namespace Internal { namespace Internal {
class EditorClosingCoreListener : public ICoreListener { class EditorClosingCoreListener : public ICoreListener
{
Q_OBJECT Q_OBJECT
public: public:

View File

@@ -2983,6 +2983,7 @@ void GdbEngine::runCustomDumper(const WatchData & data0, bool dumpChildren)
nodetype = m_namespace + "QMapNode"; nodetype = m_namespace + "QMapNode";
nodetype += data.type.mid(outertype.size()); nodetype += data.type.mid(outertype.size());
} else { } else {
// FIXME: doesn't work for QMultiMap
nodetype = data.type + "::Node"; nodetype = data.type + "::Node";
} }
//qDebug() << "OUTERTYPE: " << outertype << " NODETYPE: " << nodetype //qDebug() << "OUTERTYPE: " << outertype << " NODETYPE: " << nodetype

View File

@@ -75,6 +75,7 @@ namespace FakeVim {
namespace Constants { namespace Constants {
const char * const INSTALL_HANDLER = "FakeVim.InstallHandler"; const char * const INSTALL_HANDLER = "FakeVim.InstallHandler";
const char * const MINI_BUFFER = "FakeVim.MiniBuffer";
const char * const INSTALL_KEY = "Alt+V,Alt+V"; const char * const INSTALL_KEY = "Alt+V,Alt+V";
} // namespace Constants } // namespace Constants
@@ -89,7 +90,7 @@ const char * const INSTALL_KEY = "Alt+V,Alt+V";
FakeVimPlugin::FakeVimPlugin() FakeVimPlugin::FakeVimPlugin()
{ {
m_pm = 0; m_core = 0;
m_handler = 0; m_handler = 0;
} }
@@ -109,12 +110,10 @@ bool FakeVimPlugin::initialize(const QStringList &arguments, QString *error_mess
m_handler = new FakeVimHandler; m_handler = new FakeVimHandler;
m_pm = ExtensionSystem::PluginManager::instance(); m_core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>();
QTC_ASSERT(m_core, return false);
ICore *core = m_pm->getObject<Core::ICore>(); Core::ActionManagerInterface *actionManager = m_core->actionManager();
QTC_ASSERT(core, return false);
Core::ActionManagerInterface *actionManager = core->actionManager();
QTC_ASSERT(actionManager, return false); QTC_ASSERT(actionManager, return false);
QList<int> globalcontext; QList<int> globalcontext;
@@ -143,44 +142,32 @@ void FakeVimPlugin::extensionsInitialized()
void FakeVimPlugin::installHandler() void FakeVimPlugin::installHandler()
{ {
ICore *core = m_pm->getObject<Core::ICore>(); if (!m_core || !m_core->editorManager())
if (!core || !core->editorManager())
return; return;
Core::IEditor *editor = core->editorManager()->currentEditor(); Core::IEditor *editor = m_core->editorManager()->currentEditor();
ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor); ITextEditor *textEditor = qobject_cast<ITextEditor*>(editor);
if (!textEditor) if (!textEditor)
return; return;
QWidget *widget = textEditor->widget();
QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(widget);
if (!plainTextEdit)
return;
plainTextEdit->removeEventFilter(m_handler);
plainTextEdit->installEventFilter(m_handler);
QFont font = plainTextEdit->font();
//font.setFamily("Monospace");
m_savedCursorWidth = plainTextEdit->cursorWidth();
plainTextEdit->setCursorWidth(QFontMetrics(font).width(QChar('x')));
//QMainWindow mw;
connect(m_handler, SIGNAL(commandBufferChanged(QString)), connect(m_handler, SIGNAL(commandBufferChanged(QString)),
this, SLOT(showCommandBuffer(QString))); this, SLOT(showCommandBuffer(QString)));
connect(m_handler, SIGNAL(quitRequested(QWidget *)), connect(m_handler, SIGNAL(quitRequested(QWidget *)),
this, SLOT(removeHandler(QWidget *))); this, SLOT(removeHandler(QWidget *)));
m_handler->addWidget(textEditor->widget());
} }
void FakeVimPlugin::removeHandler(QWidget *widget) void FakeVimPlugin::removeHandler(QWidget *widget)
{ {
widget->removeEventFilter(m_handler); m_handler->removeWidget(widget);
QPlainTextEdit *plainTextEdit = qobject_cast<QPlainTextEdit *>(widget); Core::EditorManager::instance()
if (!plainTextEdit) ->hideEditorInfoBar(QLatin1String(Constants::MINI_BUFFER));
return;
plainTextEdit->setCursorWidth(m_savedCursorWidth);
} }
void FakeVimPlugin::showCommandBuffer(const QString &contents) void FakeVimPlugin::showCommandBuffer(const QString &contents)
{ {
//qDebug() << "CMD: " << contents; Core::EditorManager::instance()
->showEditorInfoBar(QLatin1String(Constants::MINI_BUFFER), contents);
} }

View File

@@ -44,8 +44,21 @@ class QCursor;
class QAbstractItemView; class QAbstractItemView;
QT_END_NAMESPACE QT_END_NAMESPACE
namespace Core { class IEditor; }
namespace TextEditor { class ITextEditor; } namespace Core {
class ICore;
class IEditor;
} // namespace Core
namespace TextEditor {
class ITextEditor;
} // namespace TextEditor
namespace FakeVim { namespace FakeVim {
namespace Internal { namespace Internal {
@@ -72,9 +85,8 @@ private slots:
private: private:
FakeVimHandler *m_handler; FakeVimHandler *m_handler;
ExtensionSystem::PluginManager *m_pm;
QAction *m_installHandlerAction; QAction *m_installHandlerAction;
int m_savedCursorWidth; Core::ICore *m_core;
}; };
} // namespace Internal } // namespace Internal

View File

@@ -152,10 +152,7 @@ private:
void handleRegisterMode(int key, const QString &text); void handleRegisterMode(int key, const QString &text);
void handleMiniBufferModes(int key, const QString &text); void handleMiniBufferModes(int key, const QString &text);
void finishMovement(const QString &text = QString()); void finishMovement(const QString &text = QString());
void updateMiniBuffer();
void updateSelection();
void search(const QString &needle, bool forward); void search(const QString &needle, bool forward);
void showMessage(const QString &msg);
int mvCount() const { return m_mvcount.isEmpty() ? 1 : m_mvcount.toInt(); } int mvCount() const { return m_mvcount.isEmpty() ? 1 : m_mvcount.toInt(); }
int opCount() const { return m_opcount.isEmpty() ? 1 : m_opcount.toInt(); } int opCount() const { return m_opcount.isEmpty() ? 1 : m_opcount.toInt(); }
@@ -186,9 +183,12 @@ private:
int readLineCode(QString &cmd); int readLineCode(QString &cmd);
QTextCursor selectRange(int beginLine, int endLine); QTextCursor selectRange(int beginLine, int endLine);
void enterInsertMode();
public: public:
void enterInsertMode();
void enterCommandMode(); void enterCommandMode();
void showMessage(const QString &msg);
void updateMiniBuffer();
void updateSelection();
public: public:
QTextEdit *m_textedit; QTextEdit *m_textedit;
@@ -816,7 +816,6 @@ void FakeVimHandler::Private::handleMiniBufferModes(int key, const QString &text
m_commandHistory.append(m_commandBuffer); m_commandHistory.append(m_commandBuffer);
handleExCommand(m_commandBuffer); handleExCommand(m_commandBuffer);
} }
enterCommandMode();
} else if (key == Key_Return && isSearchMode()) { } else if (key == Key_Return && isSearchMode()) {
if (!m_commandBuffer.isEmpty()) { if (!m_commandBuffer.isEmpty()) {
m_searchHistory.takeLast(); m_searchHistory.takeLast();
@@ -941,7 +940,7 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
endLine = line; endLine = line;
} }
//qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0; qDebug() << "RANGE: " << beginLine << endLine << cmd << cmd0;
static QRegExp reWrite("^w!?( (.*))?$"); static QRegExp reWrite("^w!?( (.*))?$");
static QRegExp reDelete("^d( (.*))?$"); static QRegExp reDelete("^d( (.*))?$");
@@ -950,8 +949,9 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
m_tc.setPosition(positionForLine(beginLine)); m_tc.setPosition(positionForLine(beginLine));
showMessage(QString()); showMessage(QString());
} else if (cmd == "q!" || cmd == "q") { // :q } else if (cmd == "q!" || cmd == "q") { // :q
q->quitRequested(editor());
showMessage(QString()); showMessage(QString());
EDITOR(setOverwriteMode(false));
q->quitRequested(editor());
} else if (reDelete.indexIn(cmd) != -1) { // :d } else if (reDelete.indexIn(cmd) != -1) { // :d
if (beginLine == -1) if (beginLine == -1)
beginLine = cursorLineInDocument(); beginLine = cursorLineInDocument();
@@ -1369,11 +1369,14 @@ void FakeVimHandler::addWidget(QWidget *widget)
//ed->setCursorWidth(QFontMetrics(ed->font()).width(QChar('x'))); //ed->setCursorWidth(QFontMetrics(ed->font()).width(QChar('x')));
ed->setLineWrapMode(QPlainTextEdit::NoWrap); ed->setLineWrapMode(QPlainTextEdit::NoWrap);
} }
d->showMessage("vi emulation mode. Hit <Shift+Esc>:q<Return> to quit");
d->updateMiniBuffer();
} }
void FakeVimHandler::removeWidget(QWidget *widget) void FakeVimHandler::removeWidget(QWidget *widget)
{ {
d->enterCommandMode(); d->showMessage(QString());
d->updateMiniBuffer();
widget->removeEventFilter(this); widget->removeEventFilter(this);
} }