2012-10-02 09:12:39 +02:00
|
|
|
/****************************************************************************
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** Copyright (C) 2016 The Qt Company Ltd.
|
|
|
|
|
** Contact: https://www.qt.io/licensing/
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** This file is part of Qt Creator.
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
** Commercial License Usage
|
|
|
|
|
** Licensees holding valid commercial Qt licenses may use this file in
|
|
|
|
|
** accordance with the commercial license agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
2016-01-15 14:57:40 +01:00
|
|
|
** a written agreement between you and The Qt Company. For licensing terms
|
|
|
|
|
** and conditions see https://www.qt.io/terms-conditions. For further
|
|
|
|
|
** information use the contact form at https://www.qt.io/contact-us.
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2016-01-15 14:57:40 +01:00
|
|
|
** GNU General Public License Usage
|
|
|
|
|
** Alternatively, this file may be used under the terms of the GNU
|
|
|
|
|
** General Public License version 3 as published by the Free Software
|
|
|
|
|
** Foundation with exceptions as appearing in the file LICENSE.GPL3-EXCEPT
|
|
|
|
|
** included in the packaging of this file. Please review the following
|
|
|
|
|
** information to ensure the GNU General Public License requirements will
|
|
|
|
|
** be met: https://www.gnu.org/licenses/gpl-3.0.html.
|
2010-12-17 16:01:08 +01:00
|
|
|
**
|
2012-10-02 09:12:39 +02:00
|
|
|
****************************************************************************/
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
#include "fakevimplugin.h"
|
|
|
|
|
|
2013-03-08 17:50:16 +01:00
|
|
|
#include "fakevimactions.h"
|
2009-01-09 16:54:06 +01:00
|
|
|
#include "fakevimhandler.h"
|
2014-08-25 17:05:11 +02:00
|
|
|
#include "fakevimtr.h"
|
2009-03-30 12:40:08 +02:00
|
|
|
#include "ui_fakevimoptions.h"
|
|
|
|
|
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
2010-09-17 13:11:12 +02:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2010-09-17 13:11:12 +02:00
|
|
|
#include <coreplugin/actionmanager/commandmappings.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
2010-09-17 13:11:12 +02:00
|
|
|
#include <coreplugin/dialogs/ioptionspage.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2013-07-05 16:08:38 +02:00
|
|
|
#include <coreplugin/editormanager/documentmodel.h>
|
2014-01-13 16:17:34 +01:00
|
|
|
#include <coreplugin/find/findplugin.h>
|
|
|
|
|
#include <coreplugin/find/textfindconstants.h>
|
|
|
|
|
#include <coreplugin/find/ifindsupport.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/documentmanager.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2012-02-14 16:43:51 +01:00
|
|
|
#include <coreplugin/idocument.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
2011-09-05 16:10:37 +02:00
|
|
|
#include <coreplugin/id.h>
|
2010-09-17 13:11:12 +02:00
|
|
|
#include <coreplugin/statusbarwidget.h>
|
|
|
|
|
#include <coreplugin/statusbarmanager.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
#include <texteditor/displaysettings.h>
|
2014-09-26 09:14:03 +02:00
|
|
|
#include <texteditor/textdocumentlayout.h>
|
|
|
|
|
#include <texteditor/texteditor.h>
|
2014-07-19 11:27:28 +02:00
|
|
|
#include <texteditor/textmark.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/typingsettings.h>
|
2009-01-09 17:31:20 +01:00
|
|
|
#include <texteditor/tabsettings.h>
|
2011-08-16 10:45:23 +02:00
|
|
|
#include <texteditor/icodestylepreferences.h>
|
2009-01-09 17:31:20 +01:00
|
|
|
#include <texteditor/texteditorsettings.h>
|
2010-11-09 10:36:02 +01:00
|
|
|
#include <texteditor/indenter.h>
|
2014-09-04 00:04:18 +02:00
|
|
|
#include <texteditor/codeassist/assistproposalitem.h>
|
|
|
|
|
#include <texteditor/codeassist/genericproposalmodel.h>
|
2011-04-15 16:19:23 +02:00
|
|
|
#include <texteditor/codeassist/completionassistprovider.h>
|
|
|
|
|
#include <texteditor/codeassist/iassistprocessor.h>
|
2014-09-04 00:04:18 +02:00
|
|
|
#include <texteditor/codeassist/assistinterface.h>
|
2011-04-15 16:19:23 +02:00
|
|
|
#include <texteditor/codeassist/genericproposal.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2014-02-18 16:09:39 +01:00
|
|
|
#include <utils/fancylineedit.h>
|
2013-02-14 19:12:30 +01:00
|
|
|
#include <utils/hostosinfo.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2014-02-18 16:09:39 +01:00
|
|
|
#include <utils/pathchooser.h>
|
2009-03-30 12:40:08 +02:00
|
|
|
#include <utils/savedaction.h>
|
2011-07-15 13:22:38 +02:00
|
|
|
#include <utils/stylehelper.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
|
|
|
|
|
2012-08-10 12:39:29 +02:00
|
|
|
#include <extensionsystem/pluginmanager.h>
|
|
|
|
|
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QAbstractTableModel>
|
|
|
|
|
#include <QDebug>
|
|
|
|
|
#include <QFile>
|
2014-10-15 12:46:18 +04:00
|
|
|
#include <QItemDelegate>
|
2014-01-08 21:27:18 +01:00
|
|
|
#include <QPainter>
|
2014-10-15 12:46:18 +04:00
|
|
|
#include <QPlainTextEdit>
|
2013-12-03 14:17:03 +01:00
|
|
|
#include <QPointer>
|
2014-01-08 21:27:18 +01:00
|
|
|
#include <QScrollBar>
|
2014-10-15 12:46:18 +04:00
|
|
|
#include <QSettings>
|
2012-09-10 22:10:23 +02:00
|
|
|
#include <QStackedWidget>
|
2014-08-28 17:33:47 +02:00
|
|
|
#include <QStandardPaths>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTextBlock>
|
|
|
|
|
#include <QTextCursor>
|
|
|
|
|
#include <QTextEdit>
|
2013-11-20 20:16:04 +01:00
|
|
|
#include <QTimer>
|
2012-02-15 10:42:41 +01:00
|
|
|
#include <QTreeWidgetItem>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace Core;
|
2016-03-18 12:10:24 +01:00
|
|
|
using namespace Utils;
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
namespace FakeVim {
|
2012-08-21 19:58:39 +02:00
|
|
|
namespace Internal {
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2011-09-13 09:54:37 +02:00
|
|
|
const char INSTALL_HANDLER[] = "TextEditor.FakeVimHandler";
|
|
|
|
|
const char SETTINGS_CATEGORY[] = "D.FakeVim";
|
2014-06-02 15:47:20 +02:00
|
|
|
const char SETTINGS_CATEGORY_FAKEVIM_ICON[] = ":/fakevim/images/category_fakevim.png";
|
2015-08-05 15:20:14 +02:00
|
|
|
const char SETTINGS_ID[] = "A.FakeVim.General";
|
|
|
|
|
const char SETTINGS_EX_CMDS_ID[] = "B.FakeVim.ExCommands";
|
|
|
|
|
const char SETTINGS_USER_CMDS_ID[] = "C.FakeVim.UserCommands";
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2012-09-10 22:10:23 +02:00
|
|
|
class MiniBuffer : public QStackedWidget
|
2011-07-15 13:22:38 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2013-11-20 20:16:04 +01:00
|
|
|
MiniBuffer()
|
|
|
|
|
: m_label(new QLabel(this))
|
|
|
|
|
, m_edit(new QLineEdit(this))
|
2011-07-15 13:22:38 +02:00
|
|
|
{
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(m_edit, &QLineEdit::textEdited, this, &MiniBuffer::changed);
|
|
|
|
|
connect(m_edit, &QLineEdit::cursorPositionChanged, this, &MiniBuffer::changed);
|
|
|
|
|
connect(m_edit, &QLineEdit::selectionChanged, this, &MiniBuffer::changed);
|
2012-09-10 22:10:23 +02:00
|
|
|
m_label->setTextInteractionFlags(Qt::TextSelectableByMouse);
|
|
|
|
|
|
|
|
|
|
addWidget(m_label);
|
|
|
|
|
addWidget(m_edit);
|
2013-11-20 20:16:04 +01:00
|
|
|
|
|
|
|
|
m_hideTimer.setSingleShot(true);
|
|
|
|
|
m_hideTimer.setInterval(8000);
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(&m_hideTimer, &QTimer::timeout, this, &QWidget::hide);
|
2011-07-15 13:22:38 +02:00
|
|
|
}
|
|
|
|
|
|
2012-10-20 18:48:37 +02:00
|
|
|
void setContents(const QString &contents, int cursorPos, int anchorPos,
|
2016-05-24 23:09:11 +03:00
|
|
|
int messageLevel, FakeVimHandler *eventFilter)
|
2012-09-10 22:10:23 +02:00
|
|
|
{
|
|
|
|
|
if (cursorPos != -1) {
|
|
|
|
|
m_edit->blockSignals(true);
|
|
|
|
|
m_label->clear();
|
|
|
|
|
m_edit->setText(contents);
|
2012-10-20 18:48:37 +02:00
|
|
|
if (anchorPos != -1 && anchorPos != cursorPos)
|
|
|
|
|
m_edit->setSelection(anchorPos, cursorPos - anchorPos);
|
|
|
|
|
else
|
|
|
|
|
m_edit->setCursorPosition(cursorPos);
|
2012-09-10 22:10:23 +02:00
|
|
|
m_edit->blockSignals(false);
|
|
|
|
|
setCurrentWidget(m_edit);
|
|
|
|
|
m_edit->setFocus();
|
|
|
|
|
} else {
|
2013-11-20 20:16:04 +01:00
|
|
|
if (contents.isEmpty()) {
|
|
|
|
|
if (m_lastMessageLevel == MessageMode)
|
|
|
|
|
hide();
|
|
|
|
|
else
|
|
|
|
|
m_hideTimer.start();
|
|
|
|
|
} else {
|
|
|
|
|
m_hideTimer.stop();
|
|
|
|
|
show();
|
|
|
|
|
|
|
|
|
|
m_label->setText(contents);
|
|
|
|
|
|
|
|
|
|
QString css;
|
|
|
|
|
if (messageLevel == MessageError) {
|
2016-03-18 12:10:24 +01:00
|
|
|
css = "border:1px solid rgba(255,255,255,150);"
|
|
|
|
|
"background-color:rgba(255,0,0,100);";
|
2013-11-20 20:16:04 +01:00
|
|
|
} else if (messageLevel == MessageWarning) {
|
2016-03-18 12:10:24 +01:00
|
|
|
css = "border:1px solid rgba(255,255,255,120);"
|
|
|
|
|
"background-color:rgba(255,255,0,20);";
|
2013-11-20 20:16:04 +01:00
|
|
|
} else if (messageLevel == MessageShowCmd) {
|
2016-03-18 12:10:24 +01:00
|
|
|
css = "border:1px solid rgba(255,255,255,120);"
|
|
|
|
|
"background-color:rgba(100,255,100,30);";
|
2013-11-20 20:16:04 +01:00
|
|
|
}
|
|
|
|
|
m_label->setStyleSheet(QString::fromLatin1(
|
|
|
|
|
"*{border-radius:2px;padding-left:4px;padding-right:4px;%1}").arg(css));
|
2012-09-10 22:10:23 +02:00
|
|
|
}
|
2011-07-15 13:22:38 +02:00
|
|
|
|
2012-09-10 22:10:23 +02:00
|
|
|
if (m_edit->hasFocus())
|
2012-12-30 15:19:15 +01:00
|
|
|
emit edited(QString(), -1, -1);
|
2012-09-10 22:10:23 +02:00
|
|
|
|
|
|
|
|
setCurrentWidget(m_label);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (m_eventFilter != eventFilter) {
|
|
|
|
|
if (m_eventFilter != 0) {
|
|
|
|
|
m_edit->removeEventFilter(m_eventFilter);
|
2016-05-24 23:09:11 +03:00
|
|
|
disconnect(this, &MiniBuffer::edited, 0, 0);
|
2012-09-10 22:10:23 +02:00
|
|
|
}
|
|
|
|
|
if (eventFilter != 0) {
|
|
|
|
|
m_edit->installEventFilter(eventFilter);
|
2016-05-24 23:09:11 +03:00
|
|
|
connect(this, &MiniBuffer::edited,
|
|
|
|
|
eventFilter, &FakeVimHandler::miniBufferTextEdited);
|
2012-09-10 22:10:23 +02:00
|
|
|
}
|
|
|
|
|
m_eventFilter = eventFilter;
|
|
|
|
|
}
|
2013-11-20 20:16:04 +01:00
|
|
|
|
|
|
|
|
m_lastMessageLevel = messageLevel;
|
2012-09-10 22:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
QSize sizeHint() const
|
2011-07-15 13:22:38 +02:00
|
|
|
{
|
2012-09-10 22:10:23 +02:00
|
|
|
QSize size = QWidget::sizeHint();
|
|
|
|
|
// reserve maximal width for line edit widget
|
|
|
|
|
return currentWidget() == m_edit ? QSize(maximumWidth(), size.height()) : size;
|
2011-07-15 13:22:38 +02:00
|
|
|
}
|
2012-09-10 22:10:23 +02:00
|
|
|
|
|
|
|
|
signals:
|
2012-12-30 15:19:15 +01:00
|
|
|
void edited(const QString &text, int cursorPos, int anchorPos);
|
2012-09-10 22:10:23 +02:00
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
private:
|
2012-09-10 22:10:23 +02:00
|
|
|
void changed()
|
2011-07-15 13:22:38 +02:00
|
|
|
{
|
2012-12-30 15:19:15 +01:00
|
|
|
const int cursorPos = m_edit->cursorPosition();
|
|
|
|
|
int anchorPos = m_edit->selectionStart();
|
|
|
|
|
if (anchorPos == cursorPos)
|
|
|
|
|
anchorPos = cursorPos + m_edit->selectedText().length();
|
|
|
|
|
emit edited(m_edit->text(), cursorPos, anchorPos);
|
2011-07-15 13:22:38 +02:00
|
|
|
}
|
2012-09-10 22:10:23 +02:00
|
|
|
|
|
|
|
|
QLabel *m_label;
|
|
|
|
|
QLineEdit *m_edit;
|
2015-06-18 13:32:25 +02:00
|
|
|
QObject *m_eventFilter = nullptr;
|
2013-11-20 20:16:04 +01:00
|
|
|
QTimer m_hideTimer;
|
2015-06-18 13:32:25 +02:00
|
|
|
int m_lastMessageLevel = MessageMode;
|
2011-07-15 13:22:38 +02:00
|
|
|
};
|
|
|
|
|
|
2014-01-08 21:27:18 +01:00
|
|
|
class RelativeNumbersColumn : public QWidget
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2014-09-26 11:37:54 +02:00
|
|
|
RelativeNumbersColumn(TextEditorWidget *baseTextEditor)
|
2014-01-08 21:27:18 +01:00
|
|
|
: QWidget(baseTextEditor)
|
|
|
|
|
, m_editor(baseTextEditor)
|
|
|
|
|
{
|
|
|
|
|
setAttribute(Qt::WA_TransparentForMouseEvents, true);
|
|
|
|
|
|
|
|
|
|
m_timerUpdate.setSingleShot(true);
|
|
|
|
|
m_timerUpdate.setInterval(0);
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(&m_timerUpdate, &QTimer::timeout,
|
|
|
|
|
this, &RelativeNumbersColumn::followEditorLayout);
|
|
|
|
|
|
|
|
|
|
auto start = static_cast<void(QTimer::*)()>(&QTimer::start);
|
|
|
|
|
connect(m_editor, &QPlainTextEdit::cursorPositionChanged,
|
|
|
|
|
&m_timerUpdate, start);
|
|
|
|
|
connect(m_editor->verticalScrollBar(), &QAbstractSlider::valueChanged,
|
|
|
|
|
&m_timerUpdate, start);
|
|
|
|
|
connect(m_editor->document(), &QTextDocument::contentsChanged,
|
|
|
|
|
&m_timerUpdate, start);
|
|
|
|
|
connect(TextEditorSettings::instance(), &TextEditorSettings::displaySettingsChanged,
|
|
|
|
|
&m_timerUpdate, start);
|
2014-01-08 21:27:18 +01:00
|
|
|
|
|
|
|
|
m_editor->installEventFilter(this);
|
|
|
|
|
|
|
|
|
|
followEditorLayout();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected:
|
|
|
|
|
void paintEvent(QPaintEvent *event)
|
|
|
|
|
{
|
|
|
|
|
QTextCursor firstVisibleCursor = m_editor->cursorForPosition(QPoint(0, 0));
|
|
|
|
|
QTextBlock firstVisibleBlock = firstVisibleCursor.block();
|
|
|
|
|
if (firstVisibleCursor.positionInBlock() > 0) {
|
|
|
|
|
firstVisibleBlock = firstVisibleBlock.next();
|
|
|
|
|
firstVisibleCursor.setPosition(firstVisibleBlock.position());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Find relative number for the first visible line.
|
|
|
|
|
QTextBlock block = m_editor->textCursor().block();
|
|
|
|
|
bool forward = firstVisibleBlock.blockNumber() > block.blockNumber();
|
|
|
|
|
int n = 0;
|
|
|
|
|
while (block.isValid() && block != firstVisibleBlock) {
|
|
|
|
|
block = forward ? block.next() : block.previous();
|
|
|
|
|
if (block.isVisible())
|
|
|
|
|
n += forward ? 1 : -1;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Copy colors from extra area palette.
|
|
|
|
|
QPainter p(this);
|
|
|
|
|
QPalette pal = m_editor->extraArea()->palette();
|
|
|
|
|
const QColor fg = pal.color(QPalette::Dark);
|
|
|
|
|
const QColor bg = pal.color(QPalette::Background);
|
|
|
|
|
p.setPen(fg);
|
|
|
|
|
|
|
|
|
|
// Draw relative line numbers.
|
|
|
|
|
QRect rect(0, m_editor->cursorRect(firstVisibleCursor).y(), width(), m_lineSpacing);
|
|
|
|
|
bool hideLineNumbers = m_editor->lineNumbersVisible();
|
|
|
|
|
while (block.isValid()) {
|
|
|
|
|
if (block.isVisible()) {
|
|
|
|
|
if (n != 0 && rect.intersects(event->rect())) {
|
|
|
|
|
const int line = qAbs(n);
|
|
|
|
|
const QString number = QString::number(line);
|
|
|
|
|
if (hideLineNumbers)
|
|
|
|
|
p.fillRect(rect, bg);
|
|
|
|
|
if (hideLineNumbers || line < 100)
|
|
|
|
|
p.drawText(rect, Qt::AlignRight | Qt::AlignVCenter, number);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
rect.translate(0, m_lineSpacing * block.lineCount());
|
|
|
|
|
if (rect.y() > height())
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
++n;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool eventFilter(QObject *, QEvent *event)
|
|
|
|
|
{
|
|
|
|
|
if (event->type() == QEvent::Resize || event->type() == QEvent::Move)
|
|
|
|
|
m_timerUpdate.start();
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
2016-05-24 23:09:11 +03:00
|
|
|
private:
|
2014-01-08 21:27:18 +01:00
|
|
|
void followEditorLayout()
|
|
|
|
|
{
|
|
|
|
|
QTextCursor tc = m_editor->textCursor();
|
|
|
|
|
m_currentPos = tc.position();
|
|
|
|
|
m_lineSpacing = m_editor->cursorRect(tc).height();
|
|
|
|
|
setFont(m_editor->extraArea()->font());
|
|
|
|
|
|
|
|
|
|
// Follow geometry of normal line numbers if visible,
|
|
|
|
|
// otherwise follow geometry of marks (breakpoints etc.).
|
|
|
|
|
QRect rect = m_editor->extraArea()->geometry().adjusted(0, 0, -3, 0);
|
|
|
|
|
bool marksVisible = m_editor->marksVisible();
|
|
|
|
|
bool lineNumbersVisible = m_editor->lineNumbersVisible();
|
|
|
|
|
bool foldMarksVisible = m_editor->codeFoldingVisible();
|
|
|
|
|
if (marksVisible && lineNumbersVisible)
|
|
|
|
|
rect.setLeft(m_lineSpacing);
|
|
|
|
|
if (foldMarksVisible && (marksVisible || lineNumbersVisible))
|
|
|
|
|
rect.setRight(rect.right() - (m_lineSpacing + m_lineSpacing % 2));
|
|
|
|
|
setGeometry(rect);
|
|
|
|
|
|
|
|
|
|
update();
|
|
|
|
|
}
|
|
|
|
|
|
2015-06-18 13:32:25 +02:00
|
|
|
int m_currentPos = 0;
|
|
|
|
|
int m_lineSpacing = 0;
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *m_editor;
|
2014-01-08 21:27:18 +01:00
|
|
|
QTimer m_timerUpdate;
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-30 12:40:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimOptionPage
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
typedef QMap<QString, QRegExp> ExCommandMap;
|
|
|
|
|
typedef QMap<int, QString> UserCommandMap;
|
2010-05-19 16:21:42 +02:00
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
class FakeVimOptionPage : public IOptionsPage
|
2009-03-30 12:40:08 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2012-05-22 11:17:13 +02:00
|
|
|
FakeVimOptionPage()
|
|
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId(SETTINGS_ID);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayName(Tr::tr("General"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(SETTINGS_CATEGORY);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayCategory(Tr::tr("FakeVim"));
|
2016-09-20 10:47:09 +02:00
|
|
|
setCategoryIcon(Utils::Icon(SETTINGS_CATEGORY_FAKEVIM_ICON));
|
2012-05-22 11:17:13 +02:00
|
|
|
}
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *widget();
|
|
|
|
|
void apply();
|
|
|
|
|
void finish();
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2016-05-24 23:09:11 +03:00
|
|
|
private:
|
2009-03-30 12:40:08 +02:00
|
|
|
void copyTextEditorSettings();
|
|
|
|
|
void setQtStyle();
|
|
|
|
|
void setPlainStyle();
|
2013-02-14 19:12:30 +01:00
|
|
|
void updateVimRcWidgets();
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QPointer<QWidget> m_widget;
|
2009-03-30 12:40:08 +02:00
|
|
|
Ui::FakeVimOptionPage m_ui;
|
2016-03-18 12:10:24 +01:00
|
|
|
SavedActionSet m_group;
|
2009-03-30 12:40:08 +02:00
|
|
|
};
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *FakeVimOptionPage::widget()
|
2009-03-30 12:40:08 +02:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
|
|
|
|
m_widget = new QWidget;
|
|
|
|
|
m_ui.setupUi(m_widget);
|
2016-03-18 12:10:24 +01:00
|
|
|
const QString vimrcDefault = QLatin1String(HostOsInfo::isAnyUnixHost()
|
|
|
|
|
? "$HOME/.vimrc" : "%USERPROFILE%\\_vimrc");
|
|
|
|
|
m_ui.pathChooserVimRcPath->setExpectedKind(PathChooser::File);
|
2014-08-25 17:05:11 +02:00
|
|
|
m_ui.pathChooserVimRcPath->lineEdit()->setToolTip(Tr::tr("Keep empty to use the default path, i.e. "
|
2014-02-18 16:09:39 +01:00
|
|
|
"%USERPROFILE%\\_vimrc on Windows, ~/.vimrc otherwise."));
|
2014-08-25 17:05:11 +02:00
|
|
|
m_ui.pathChooserVimRcPath->lineEdit()->setPlaceholderText(Tr::tr("Default: %1").arg(vimrcDefault));
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
m_group.clear();
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigUseFakeVim),
|
|
|
|
|
m_ui.checkBoxUseFakeVim);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigReadVimRc),
|
|
|
|
|
m_ui.checkBoxReadVimRc);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigVimRcPath),
|
2014-02-18 16:09:39 +01:00
|
|
|
m_ui.pathChooserVimRcPath);
|
2013-12-03 14:17:03 +01:00
|
|
|
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigExpandTab),
|
|
|
|
|
m_ui.checkBoxExpandTab);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigHlSearch),
|
|
|
|
|
m_ui.checkBoxHlSearch);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigShiftWidth),
|
|
|
|
|
m_ui.spinBoxShiftWidth);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigShowMarks),
|
|
|
|
|
m_ui.checkBoxShowMarks);
|
|
|
|
|
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigSmartTab),
|
|
|
|
|
m_ui.checkBoxSmartTab);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigStartOfLine),
|
|
|
|
|
m_ui.checkBoxStartOfLine);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigPassKeys),
|
|
|
|
|
m_ui.checkBoxPassKeys);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigTabStop),
|
|
|
|
|
m_ui.spinBoxTabStop);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigScrollOff),
|
|
|
|
|
m_ui.spinBoxScrollOff);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigBackspace),
|
|
|
|
|
m_ui.lineEditBackspace);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigIsKeyword),
|
|
|
|
|
m_ui.lineEditIsKeyword);
|
|
|
|
|
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigPassControlKey),
|
|
|
|
|
m_ui.checkBoxPassControlKey);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigAutoIndent),
|
|
|
|
|
m_ui.checkBoxAutoIndent);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigSmartIndent),
|
|
|
|
|
m_ui.checkBoxSmartIndent);
|
|
|
|
|
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigIncSearch),
|
|
|
|
|
m_ui.checkBoxIncSearch);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigUseCoreSearch),
|
|
|
|
|
m_ui.checkBoxUseCoreSearch);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigSmartCase),
|
|
|
|
|
m_ui.checkBoxSmartCase);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigIgnoreCase),
|
|
|
|
|
m_ui.checkBoxIgnoreCase);
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigWrapScan),
|
|
|
|
|
m_ui.checkBoxWrapScan);
|
|
|
|
|
|
|
|
|
|
m_group.insert(theFakeVimSetting(ConfigShowCmd),
|
|
|
|
|
m_ui.checkBoxShowCmd);
|
|
|
|
|
|
2014-01-08 21:27:18 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigRelativeNumber),
|
|
|
|
|
m_ui.checkBoxRelativeNumber);
|
|
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(m_ui.pushButtonCopyTextEditorSettings, &QAbstractButton::clicked,
|
|
|
|
|
this, &FakeVimOptionPage::copyTextEditorSettings);
|
|
|
|
|
connect(m_ui.pushButtonSetQtStyle, &QAbstractButton::clicked,
|
|
|
|
|
this, &FakeVimOptionPage::setQtStyle);
|
|
|
|
|
connect(m_ui.pushButtonSetPlainStyle, &QAbstractButton::clicked,
|
|
|
|
|
this, &FakeVimOptionPage::setPlainStyle);
|
|
|
|
|
connect(m_ui.checkBoxReadVimRc, &QCheckBox::stateChanged,
|
|
|
|
|
this, &FakeVimOptionPage::updateVimRcWidgets);
|
2013-12-03 14:17:03 +01:00
|
|
|
updateVimRcWidgets();
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
}
|
2013-12-03 14:17:03 +01:00
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::apply()
|
|
|
|
|
{
|
|
|
|
|
m_group.apply(ICore::settings());
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::finish()
|
|
|
|
|
{
|
|
|
|
|
m_group.finish();
|
|
|
|
|
delete m_widget;
|
2009-03-30 12:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::copyTextEditorSettings()
|
|
|
|
|
{
|
2013-09-19 17:59:27 +02:00
|
|
|
TabSettings ts = TextEditorSettings::codeStyle()->tabSettings();
|
|
|
|
|
TypingSettings tps = TextEditorSettings::typingSettings();
|
2011-08-16 10:45:23 +02:00
|
|
|
m_ui.checkBoxExpandTab->setChecked(ts.m_tabPolicy != TabSettings::TabsOnlyTabPolicy);
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxTabStop->setValue(ts.m_tabSize);
|
|
|
|
|
m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize);
|
2011-08-17 12:31:15 +02:00
|
|
|
m_ui.checkBoxSmartTab->setChecked(
|
2011-08-16 10:45:23 +02:00
|
|
|
tps.m_smartBackspaceBehavior == TypingSettings::BackspaceFollowsPreviousIndents);
|
2010-01-06 14:57:46 +01:00
|
|
|
m_ui.checkBoxAutoIndent->setChecked(true);
|
2011-08-16 10:45:23 +02:00
|
|
|
m_ui.checkBoxSmartIndent->setChecked(tps.m_autoIndent);
|
2010-04-12 17:54:07 +02:00
|
|
|
m_ui.checkBoxIncSearch->setChecked(true);
|
2009-03-30 12:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::setQtStyle()
|
|
|
|
|
{
|
|
|
|
|
m_ui.checkBoxExpandTab->setChecked(true);
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxTabStop->setValue(4);
|
|
|
|
|
m_ui.spinBoxShiftWidth->setValue(4);
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxSmartTab->setChecked(true);
|
|
|
|
|
m_ui.checkBoxAutoIndent->setChecked(true);
|
2010-01-06 14:57:46 +01:00
|
|
|
m_ui.checkBoxSmartIndent->setChecked(true);
|
2009-06-02 11:56:58 +02:00
|
|
|
m_ui.checkBoxIncSearch->setChecked(true);
|
2016-03-18 12:10:24 +01:00
|
|
|
m_ui.lineEditBackspace->setText("indent,eol,start");
|
2013-04-01 12:03:22 +02:00
|
|
|
m_ui.checkBoxPassKeys->setChecked(true);
|
2009-03-30 12:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::setPlainStyle()
|
|
|
|
|
{
|
|
|
|
|
m_ui.checkBoxExpandTab->setChecked(false);
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxTabStop->setValue(8);
|
|
|
|
|
m_ui.spinBoxShiftWidth->setValue(8);
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxSmartTab->setChecked(false);
|
|
|
|
|
m_ui.checkBoxAutoIndent->setChecked(false);
|
2010-01-06 14:57:46 +01:00
|
|
|
m_ui.checkBoxSmartIndent->setChecked(false);
|
2009-06-02 11:56:58 +02:00
|
|
|
m_ui.checkBoxIncSearch->setChecked(false);
|
2014-07-23 09:53:06 +02:00
|
|
|
m_ui.lineEditBackspace->clear();
|
2013-04-01 12:03:22 +02:00
|
|
|
m_ui.checkBoxPassKeys->setChecked(false);
|
2009-03-30 12:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
2013-02-14 19:12:30 +01:00
|
|
|
void FakeVimOptionPage::updateVimRcWidgets()
|
|
|
|
|
{
|
2014-02-18 16:09:39 +01:00
|
|
|
m_ui.pathChooserVimRcPath->setEnabled(m_ui.checkBoxReadVimRc->isChecked());
|
2013-02-14 19:12:30 +01:00
|
|
|
}
|
|
|
|
|
|
2010-09-17 13:11:12 +02:00
|
|
|
//const char *FAKEVIM_CONTEXT = "FakeVim";
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimExCommandsPage
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2011-03-17 17:46:32 +01:00
|
|
|
enum { CommandRole = Qt::UserRole };
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
class FakeVimExCommandsWidget : public CommandMappings
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2015-04-29 18:01:21 +02:00
|
|
|
FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent = 0);
|
2015-04-27 12:29:55 +02:00
|
|
|
|
|
|
|
|
protected:
|
2015-04-29 18:01:21 +02:00
|
|
|
void commandChanged();
|
|
|
|
|
void resetToDefault();
|
2015-04-27 12:29:55 +02:00
|
|
|
void defaultAction() override;
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
void handleCurrentCommandChanged(QTreeWidgetItem *current);
|
2015-04-27 12:29:55 +02:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void initialize();
|
|
|
|
|
|
|
|
|
|
ExCommandMap &exCommandMap();
|
|
|
|
|
ExCommandMap &defaultExCommandMap();
|
|
|
|
|
|
|
|
|
|
FakeVimPluginPrivate *m_q;
|
2015-04-29 18:01:21 +02:00
|
|
|
QGroupBox *m_commandBox;
|
2016-03-18 12:10:24 +01:00
|
|
|
FancyLineEdit *m_commandEdit;
|
2015-04-27 12:29:55 +02:00
|
|
|
};
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
FakeVimExCommandsWidget::FakeVimExCommandsWidget(FakeVimPluginPrivate *q, QWidget *parent)
|
|
|
|
|
: CommandMappings(parent), m_q(q)
|
|
|
|
|
{
|
|
|
|
|
setPageTitle(Tr::tr("Ex Command Mapping"));
|
|
|
|
|
setTargetHeader(Tr::tr("Ex Trigger Expression"));
|
|
|
|
|
setImportExportEnabled(false);
|
|
|
|
|
|
|
|
|
|
connect(this, &FakeVimExCommandsWidget::currentCommandChanged,
|
|
|
|
|
this, &FakeVimExCommandsWidget::handleCurrentCommandChanged);
|
|
|
|
|
|
|
|
|
|
m_commandBox = new QGroupBox(Tr::tr("Ex Command"), this);
|
|
|
|
|
m_commandBox->setEnabled(false);
|
|
|
|
|
auto boxLayout = new QHBoxLayout(m_commandBox);
|
2016-03-18 12:10:24 +01:00
|
|
|
m_commandEdit = new FancyLineEdit(m_commandBox);
|
2015-04-29 18:01:21 +02:00
|
|
|
m_commandEdit->setFiltering(true);
|
|
|
|
|
m_commandEdit->setPlaceholderText(QString());
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(m_commandEdit, &FancyLineEdit::textChanged,
|
2015-04-29 18:01:21 +02:00
|
|
|
this, &FakeVimExCommandsWidget::commandChanged);
|
|
|
|
|
auto resetButton = new QPushButton(Tr::tr("Reset"), m_commandBox);
|
|
|
|
|
resetButton->setToolTip(Tr::tr("Reset to default."));
|
|
|
|
|
connect(resetButton, &QPushButton::clicked,
|
|
|
|
|
this, &FakeVimExCommandsWidget::resetToDefault);
|
|
|
|
|
boxLayout->addWidget(new QLabel(Tr::tr("Regular expression:")));
|
|
|
|
|
boxLayout->addWidget(m_commandEdit);
|
|
|
|
|
boxLayout->addWidget(resetButton);
|
|
|
|
|
|
|
|
|
|
layout()->addWidget(m_commandBox);
|
|
|
|
|
|
|
|
|
|
initialize();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
class FakeVimExCommandsPage : public IOptionsPage
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2012-05-22 11:17:13 +02:00
|
|
|
FakeVimExCommandsPage(FakeVimPluginPrivate *q)
|
|
|
|
|
: m_q(q)
|
|
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId(SETTINGS_EX_CMDS_ID);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayName(Tr::tr("Ex Command Mapping"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(SETTINGS_CATEGORY);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayCategory(Tr::tr("FakeVim"));
|
2016-09-20 10:47:09 +02:00
|
|
|
setCategoryIcon(Utils::Icon(SETTINGS_CATEGORY_FAKEVIM_ICON));
|
2012-05-22 11:17:13 +02:00
|
|
|
}
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
QWidget *widget() override;
|
|
|
|
|
void apply() override {}
|
|
|
|
|
void finish() override;
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
private:
|
2010-05-19 16:21:42 +02:00
|
|
|
FakeVimPluginPrivate *m_q;
|
2015-04-27 12:29:55 +02:00
|
|
|
QPointer<QWidget> m_widget;
|
2010-01-22 13:56:50 +01:00
|
|
|
};
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *FakeVimExCommandsPage::widget()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2015-04-27 12:29:55 +02:00
|
|
|
if (!m_widget)
|
|
|
|
|
m_widget = new FakeVimExCommandsWidget(m_q);
|
|
|
|
|
return m_widget;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimExCommandsPage::finish()
|
|
|
|
|
{
|
|
|
|
|
delete m_widget;
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
void FakeVimExCommandsWidget::initialize()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2010-03-02 17:51:40 +01:00
|
|
|
QMap<QString, QTreeWidgetItem *> sections;
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
foreach (Command *c, ActionManager::commands()) {
|
2010-01-22 13:56:50 +01:00
|
|
|
if (c->action() && c->action()->isSeparator())
|
|
|
|
|
continue;
|
|
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
auto item = new QTreeWidgetItem;
|
2011-11-11 12:16:20 +01:00
|
|
|
const QString name = c->id().toString();
|
2016-03-18 12:10:24 +01:00
|
|
|
const int pos = name.indexOf('.');
|
2010-03-02 17:51:40 +01:00
|
|
|
const QString section = name.left(pos);
|
2010-05-18 12:58:36 +02:00
|
|
|
const QString subId = name.mid(pos + 1);
|
2011-09-02 14:50:08 +02:00
|
|
|
item->setData(0, CommandRole, name);
|
2010-03-02 17:51:40 +01:00
|
|
|
|
|
|
|
|
if (!sections.contains(section)) {
|
2016-03-18 12:10:24 +01:00
|
|
|
auto categoryItem = new QTreeWidgetItem(commandList(), { section });
|
2010-03-02 17:51:40 +01:00
|
|
|
QFont f = categoryItem->font(0);
|
|
|
|
|
f.setBold(true);
|
|
|
|
|
categoryItem->setFont(0, f);
|
|
|
|
|
sections.insert(section, categoryItem);
|
2010-03-10 11:21:56 +01:00
|
|
|
commandList()->expandItem(categoryItem);
|
2010-03-02 17:51:40 +01:00
|
|
|
}
|
|
|
|
|
sections[section]->addChild(item);
|
|
|
|
|
|
|
|
|
|
item->setText(0, subId);
|
2012-01-06 17:13:18 +01:00
|
|
|
item->setText(1, c->description());
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-03-17 17:46:32 +01:00
|
|
|
QString regex;
|
|
|
|
|
if (exCommandMap().contains(name))
|
|
|
|
|
regex = exCommandMap()[name].pattern();
|
|
|
|
|
item->setText(2, regex);
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2011-03-17 17:46:32 +01:00
|
|
|
if (regex != defaultExCommandMap()[name].pattern())
|
2010-03-29 14:42:46 +02:00
|
|
|
setModified(item, true);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
handleCurrentCommandChanged(0);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
void FakeVimExCommandsWidget::handleCurrentCommandChanged(QTreeWidgetItem *current)
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2015-04-29 18:01:21 +02:00
|
|
|
if (current) {
|
|
|
|
|
m_commandEdit->setText(current->text(2));
|
|
|
|
|
m_commandBox->setEnabled(true);
|
|
|
|
|
} else {
|
|
|
|
|
m_commandEdit->clear();
|
|
|
|
|
m_commandBox->setEnabled(false);
|
|
|
|
|
}
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
void FakeVimExCommandsWidget::commandChanged()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
QTreeWidgetItem *current = commandList()->currentItem();
|
2010-03-04 19:22:06 +01:00
|
|
|
if (!current)
|
|
|
|
|
return;
|
|
|
|
|
|
2011-09-02 14:50:08 +02:00
|
|
|
const QString name = current->data(0, CommandRole).toString();
|
2015-04-29 18:01:21 +02:00
|
|
|
const QString regex = m_commandEdit->text();
|
2010-03-04 19:22:06 +01:00
|
|
|
|
|
|
|
|
if (current->data(0, Qt::UserRole).isValid()) {
|
2011-03-17 17:46:32 +01:00
|
|
|
current->setText(2, regex);
|
|
|
|
|
exCommandMap()[name] = QRegExp(regex);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
setModified(current, regex != defaultExCommandMap()[name].pattern());
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-29 18:01:21 +02:00
|
|
|
void FakeVimExCommandsWidget::resetToDefault()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
QTreeWidgetItem *current = commandList()->currentItem();
|
2011-03-17 17:46:32 +01:00
|
|
|
if (!current)
|
|
|
|
|
return;
|
2011-09-02 14:50:08 +02:00
|
|
|
const QString name = current->data(0, CommandRole).toString();
|
2011-03-17 17:46:32 +01:00
|
|
|
QString regex;
|
|
|
|
|
if (defaultExCommandMap().contains(name))
|
|
|
|
|
regex = defaultExCommandMap()[name].pattern();
|
2015-04-29 18:01:21 +02:00
|
|
|
m_commandEdit->setText(regex);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
void FakeVimExCommandsWidget::defaultAction()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2011-03-17 18:15:34 +01:00
|
|
|
int n = commandList()->topLevelItemCount();
|
|
|
|
|
for (int i = 0; i != n; ++i) {
|
|
|
|
|
QTreeWidgetItem *section = commandList()->topLevelItem(i);
|
|
|
|
|
int m = section->childCount();
|
|
|
|
|
for (int j = 0; j != m; ++j) {
|
|
|
|
|
QTreeWidgetItem *item = section->child(j);
|
2011-09-02 14:50:08 +02:00
|
|
|
const QString name = item->data(0, CommandRole).toString();
|
2011-03-17 18:15:34 +01:00
|
|
|
QString regex;
|
|
|
|
|
if (defaultExCommandMap().contains(name))
|
|
|
|
|
regex = defaultExCommandMap()[name].pattern();
|
|
|
|
|
setModified(item, false);
|
|
|
|
|
item->setText(2, regex);
|
|
|
|
|
if (item == commandList()->currentItem())
|
2015-04-29 18:01:21 +02:00
|
|
|
currentCommandChanged(item);
|
2011-03-17 18:15:34 +01:00
|
|
|
}
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimUserCommandsPage
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
class FakeVimUserCommandsModel : public QAbstractTableModel
|
|
|
|
|
{
|
2011-06-14 12:22:14 +02:00
|
|
|
Q_OBJECT
|
2011-04-05 16:32:18 +02:00
|
|
|
public:
|
|
|
|
|
FakeVimUserCommandsModel(FakeVimPluginPrivate *q) : m_q(q) {}
|
|
|
|
|
~FakeVimUserCommandsModel() {}
|
|
|
|
|
|
|
|
|
|
int rowCount(const QModelIndex &parent) const;
|
|
|
|
|
int columnCount(const QModelIndex &parent) const;
|
|
|
|
|
QVariant data(const QModelIndex &index, int role) const;
|
|
|
|
|
bool setData(const QModelIndex &index, const QVariant &data, int role);
|
|
|
|
|
QVariant headerData(int section, Qt::Orientation orientation, int role) const;
|
|
|
|
|
Qt::ItemFlags flags(const QModelIndex &index) const;
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FakeVimPluginPrivate *m_q;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
int FakeVimUserCommandsModel::rowCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 9;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int FakeVimUserCommandsModel::columnCount(const QModelIndex &parent) const
|
|
|
|
|
{
|
|
|
|
|
return parent.isValid() ? 0 : 2;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
QVariant FakeVimUserCommandsModel::headerData(int section,
|
|
|
|
|
Qt::Orientation orient, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (orient == Qt::Horizontal && role == Qt::DisplayRole) {
|
|
|
|
|
switch (section) {
|
2014-08-25 17:05:11 +02:00
|
|
|
case 0: return Tr::tr("Action");
|
|
|
|
|
case 1: return Tr::tr("Command");
|
2011-04-05 16:32:18 +02:00
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Qt::ItemFlags FakeVimUserCommandsModel::flags(const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
if (index.column() == 1)
|
|
|
|
|
return QAbstractTableModel::flags(index) | Qt::ItemIsEditable;
|
|
|
|
|
return QAbstractTableModel::flags(index);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
class FakeVimUserCommandsDelegate : public QItemDelegate
|
|
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
explicit FakeVimUserCommandsDelegate(QObject *parent)
|
|
|
|
|
: QItemDelegate(parent)
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
QWidget *createEditor(QWidget *parent, const QStyleOptionViewItem &,
|
|
|
|
|
const QModelIndex &) const
|
|
|
|
|
{
|
2016-03-18 12:10:24 +01:00
|
|
|
auto lineEdit = new QLineEdit(parent);
|
2011-04-05 16:32:18 +02:00
|
|
|
lineEdit->setFrame(false);
|
|
|
|
|
return lineEdit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void setModelData(QWidget *editor, QAbstractItemModel *model,
|
|
|
|
|
const QModelIndex &index) const
|
|
|
|
|
{
|
|
|
|
|
QLineEdit *lineEdit = qobject_cast<QLineEdit *>(editor);
|
|
|
|
|
QTC_ASSERT(lineEdit, return);
|
|
|
|
|
model->setData(index, lineEdit->text(), Qt::EditRole);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
class FakeVimUserCommandsPage : public IOptionsPage
|
2011-04-05 16:32:18 +02:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2012-05-22 11:17:13 +02:00
|
|
|
FakeVimUserCommandsPage(FakeVimPluginPrivate *q)
|
|
|
|
|
: m_q(q)
|
|
|
|
|
{
|
2013-01-16 15:22:58 +01:00
|
|
|
setId(SETTINGS_USER_CMDS_ID);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayName(Tr::tr("User Command Mapping"));
|
2012-12-29 03:37:27 +01:00
|
|
|
setCategory(SETTINGS_CATEGORY);
|
2014-08-25 17:05:11 +02:00
|
|
|
setDisplayCategory(Tr::tr("FakeVim"));
|
2016-09-20 10:47:09 +02:00
|
|
|
setCategoryIcon(Utils::Icon(SETTINGS_CATEGORY_FAKEVIM_ICON));
|
2012-05-22 11:17:13 +02:00
|
|
|
}
|
|
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
void apply();
|
|
|
|
|
void finish() {}
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *widget();
|
2011-04-05 16:32:18 +02:00
|
|
|
void initialize() {}
|
|
|
|
|
UserCommandMap &userCommandMap();
|
|
|
|
|
UserCommandMap &defaultUserCommandMap();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FakeVimPluginPrivate *m_q;
|
2014-07-21 13:52:25 +02:00
|
|
|
QPointer<QWidget> m_widget;
|
2011-04-05 16:32:18 +02:00
|
|
|
};
|
|
|
|
|
|
2013-12-03 14:17:03 +01:00
|
|
|
QWidget *FakeVimUserCommandsPage::widget()
|
2011-04-05 16:32:18 +02:00
|
|
|
{
|
2013-12-03 14:17:03 +01:00
|
|
|
if (!m_widget) {
|
2014-07-21 13:52:25 +02:00
|
|
|
m_widget = new QWidget;
|
2011-04-05 16:32:18 +02:00
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
auto model = new FakeVimUserCommandsModel(m_q);
|
|
|
|
|
auto widget = new QTreeView;
|
2013-12-03 14:17:03 +01:00
|
|
|
model->setParent(widget);
|
|
|
|
|
widget->setModel(model);
|
|
|
|
|
widget->resizeColumnToContents(0);
|
2011-04-05 16:32:18 +02:00
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
auto delegate = new FakeVimUserCommandsDelegate(widget);
|
2013-12-03 14:17:03 +01:00
|
|
|
widget->setItemDelegateForColumn(1, delegate);
|
2011-04-05 16:32:18 +02:00
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
auto layout = new QGridLayout(m_widget);
|
2013-12-03 14:17:03 +01:00
|
|
|
layout->addWidget(widget, 0, 0);
|
|
|
|
|
m_widget->setLayout(layout);
|
|
|
|
|
}
|
|
|
|
|
return m_widget;
|
2011-04-05 16:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimUserCommandsPage::apply()
|
|
|
|
|
{
|
|
|
|
|
//m_q->writeSettings();
|
2013-12-03 14:17:03 +01:00
|
|
|
delete m_widget;
|
2011-04-05 16:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
2011-02-18 15:31:31 +01:00
|
|
|
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// WordCompletion
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
class FakeVimCompletionAssistProvider : public CompletionAssistProvider
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
|
|
|
|
public:
|
2014-07-01 11:08:26 +02:00
|
|
|
bool supportsEditor(Id ) const
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return false;
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
IAssistProcessor *createProcessor() const;
|
2011-04-15 16:19:23 +02:00
|
|
|
|
|
|
|
|
void setActive(const QString &needle, bool forward, FakeVimHandler *handler)
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
Q_UNUSED(forward);
|
|
|
|
|
m_handler = handler;
|
|
|
|
|
if (!m_handler)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget());
|
2011-04-15 16:19:23 +02:00
|
|
|
if (!editor)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
//qDebug() << "ACTIVATE: " << needle << forward;
|
|
|
|
|
m_needle = needle;
|
|
|
|
|
editor->invokeAssist(Completion, this);
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
void setInactive()
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
m_needle.clear();
|
|
|
|
|
m_handler = 0;
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
const QString &needle() const
|
2011-02-21 14:02:00 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return m_needle;
|
2011-02-21 14:02:00 +01:00
|
|
|
}
|
2011-02-18 15:31:31 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
void appendNeedle(const QChar &c)
|
2011-02-21 14:02:00 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
m_needle.append(c);
|
2011-02-21 14:02:00 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
FakeVimHandler *handler() const
|
2011-02-21 14:02:00 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return m_handler;
|
2011-02-21 14:02:00 +01:00
|
|
|
}
|
2011-02-18 15:31:31 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
private:
|
2016-12-05 13:47:57 +01:00
|
|
|
FakeVimHandler *m_handler = nullptr;
|
2011-04-15 16:19:23 +02:00
|
|
|
QString m_needle;
|
|
|
|
|
};
|
|
|
|
|
|
2016-02-01 14:51:01 +01:00
|
|
|
class FakeVimAssistProposalItem final : public AssistProposalItem
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
|
|
|
|
public:
|
|
|
|
|
FakeVimAssistProposalItem(const FakeVimCompletionAssistProvider *provider)
|
|
|
|
|
: m_provider(const_cast<FakeVimCompletionAssistProvider *>(provider))
|
|
|
|
|
{}
|
|
|
|
|
|
2015-06-03 15:32:31 +02:00
|
|
|
bool implicitlyApplies() const override
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return false;
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-03 15:32:31 +02:00
|
|
|
bool prematurelyApplies(const QChar &c) const override
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
m_provider->appendNeedle(c);
|
|
|
|
|
return text() == m_provider->needle();
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2016-01-19 14:54:59 +01:00
|
|
|
void applyContextualContent(TextDocumentManipulatorInterface &, int) const override
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
QTC_ASSERT(m_provider->handler(), return);
|
|
|
|
|
m_provider->handler()->handleReplay(text().mid(m_provider->needle().size()));
|
|
|
|
|
const_cast<FakeVimCompletionAssistProvider *>(m_provider)->setInactive();
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
private:
|
|
|
|
|
FakeVimCompletionAssistProvider *m_provider;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
2014-09-04 00:04:18 +02:00
|
|
|
class FakeVimAssistProposalModel : public GenericProposalModel
|
2011-04-15 16:19:23 +02:00
|
|
|
{
|
|
|
|
|
public:
|
2016-02-01 14:51:01 +01:00
|
|
|
FakeVimAssistProposalModel(const QList<AssistProposalItemInterface *> &items)
|
2014-09-13 02:22:24 +02:00
|
|
|
{
|
|
|
|
|
loadContent(items);
|
|
|
|
|
}
|
2011-04-15 16:19:23 +02:00
|
|
|
|
2015-06-03 15:32:31 +02:00
|
|
|
bool supportsPrefixExpansion() const override
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
return false;
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
2011-04-15 16:19:23 +02:00
|
|
|
};
|
2011-02-18 15:31:31 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
class FakeVimCompletionAssistProcessor : public IAssistProcessor
|
|
|
|
|
{
|
|
|
|
|
public:
|
2012-08-21 19:58:39 +02:00
|
|
|
FakeVimCompletionAssistProcessor(const IAssistProvider *provider)
|
2011-04-15 16:19:23 +02:00
|
|
|
: m_provider(static_cast<const FakeVimCompletionAssistProvider *>(provider))
|
|
|
|
|
{}
|
|
|
|
|
|
2015-06-03 15:32:31 +02:00
|
|
|
IAssistProposal *perform(const AssistInterface *interface) override
|
2011-02-18 15:31:31 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
const QString &needle = m_provider->needle();
|
|
|
|
|
|
|
|
|
|
const int basePosition = interface->position() - needle.size();
|
|
|
|
|
|
2012-02-14 16:43:51 +01:00
|
|
|
QTextCursor tc(interface->textDocument());
|
2011-04-15 16:19:23 +02:00
|
|
|
tc.setPosition(interface->position());
|
2011-02-18 15:31:31 +01:00
|
|
|
tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
|
|
|
|
|
2016-02-01 14:51:01 +01:00
|
|
|
QList<AssistProposalItemInterface *> items;
|
2011-02-18 15:31:31 +01:00
|
|
|
QSet<QString> seen;
|
|
|
|
|
QTextDocument::FindFlags flags = QTextDocument::FindCaseSensitively;
|
|
|
|
|
while (1) {
|
2011-04-15 16:19:23 +02:00
|
|
|
tc = tc.document()->find(needle, tc.position(), flags);
|
2011-02-18 15:31:31 +01:00
|
|
|
if (tc.isNull())
|
|
|
|
|
break;
|
|
|
|
|
QTextCursor sel = tc;
|
|
|
|
|
sel.select(QTextCursor::WordUnderCursor);
|
|
|
|
|
QString found = sel.selectedText();
|
|
|
|
|
// Only add "real" completions.
|
2011-04-15 16:19:23 +02:00
|
|
|
if (found.startsWith(needle)
|
2011-02-18 15:31:31 +01:00
|
|
|
&& !seen.contains(found)
|
2011-04-15 16:19:23 +02:00
|
|
|
&& sel.anchor() != basePosition) {
|
2011-02-18 15:31:31 +01:00
|
|
|
seen.insert(found);
|
2016-03-18 12:10:24 +01:00
|
|
|
auto item = new FakeVimAssistProposalItem(m_provider);
|
2011-04-15 16:19:23 +02:00
|
|
|
item->setText(found);
|
|
|
|
|
items.append(item);
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
tc.movePosition(QTextCursor::Right, QTextCursor::MoveAnchor);
|
|
|
|
|
}
|
|
|
|
|
//qDebug() << "COMPLETIONS" << completions->size();
|
|
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
delete interface;
|
|
|
|
|
return new GenericProposal(basePosition, new FakeVimAssistProposalModel(items));
|
2011-02-18 15:31:31 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
2011-04-15 16:19:23 +02:00
|
|
|
const FakeVimCompletionAssistProvider *m_provider;
|
2011-02-18 15:31:31 +01:00
|
|
|
};
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-04-15 16:19:23 +02:00
|
|
|
IAssistProcessor *FakeVimCompletionAssistProvider::createProcessor() const
|
|
|
|
|
{
|
|
|
|
|
return new FakeVimCompletionAssistProcessor(this);
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2008-12-19 12:20:04 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
2009-01-13 16:38:05 +01:00
|
|
|
// FakeVimPluginPrivate
|
2008-12-19 12:20:04 +01:00
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
class FakeVimPluginPrivate : public QObject
|
2008-12-19 12:20:04 +01:00
|
|
|
{
|
2009-01-13 16:38:05 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FakeVimPluginPrivate(FakeVimPlugin *);
|
2016-03-01 23:24:59 +01:00
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
friend class FakeVimPlugin;
|
2015-04-27 12:29:55 +02:00
|
|
|
friend class FakeVimExCommandsWidget;
|
2011-04-05 16:32:18 +02:00
|
|
|
friend class FakeVimUserCommandsPage;
|
|
|
|
|
friend class FakeVimUserCommandsModel;
|
2009-01-13 16:38:05 +01:00
|
|
|
|
2009-01-23 15:12:04 +01:00
|
|
|
bool initialize();
|
2010-04-28 16:59:03 +02:00
|
|
|
void aboutToShutdown();
|
2009-01-13 16:38:05 +01:00
|
|
|
|
2016-05-24 23:09:11 +03:00
|
|
|
private:
|
2010-10-21 09:59:45 +02:00
|
|
|
void onCoreAboutToClose();
|
2009-01-13 16:38:05 +01:00
|
|
|
void editorOpened(Core::IEditor *);
|
|
|
|
|
void editorAboutToClose(Core::IEditor *);
|
2016-12-09 10:10:31 +01:00
|
|
|
void currentEditorAboutToChange(Core::IEditor *);
|
2009-01-23 15:12:04 +01:00
|
|
|
|
2014-08-09 15:42:35 +02:00
|
|
|
void allDocumentsRenamed(const QString &oldName, const QString &newName);
|
|
|
|
|
void documentRenamed(Core::IDocument *document, const QString &oldName, const QString &newName);
|
|
|
|
|
void renameFileNameInEditors(const QString &oldName, const QString &newName);
|
|
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
void setUseFakeVim(const QVariant &value);
|
2011-04-05 16:32:18 +02:00
|
|
|
void setUseFakeVimInternal(bool on);
|
2009-03-31 11:44:18 +02:00
|
|
|
void quitFakeVim();
|
2009-03-25 13:31:30 +01:00
|
|
|
void triggerCompletions();
|
2010-12-21 11:36:42 +01:00
|
|
|
void triggerSimpleCompletions(const QString &needle, bool forward);
|
2013-04-24 18:15:32 +02:00
|
|
|
void windowCommand(const QString &key, int count);
|
2009-05-29 07:45:35 +10:00
|
|
|
void find(bool reverse);
|
2009-05-29 11:34:11 +10:00
|
|
|
void findNext(bool reverse);
|
2012-10-05 17:33:20 +02:00
|
|
|
void foldToggle(int depth);
|
|
|
|
|
void foldAll(bool fold);
|
|
|
|
|
void fold(int depth, bool fold);
|
2012-11-29 20:14:56 +01:00
|
|
|
void foldGoTo(int count, bool current);
|
2012-10-28 14:00:50 +01:00
|
|
|
void jumpToGlobalMark(QChar mark, bool backTickMode, const QString &fileName);
|
2010-04-16 17:47:02 +02:00
|
|
|
void maybeReadVimRc();
|
2014-06-16 14:20:36 +02:00
|
|
|
void disableBlockSelection();
|
|
|
|
|
void setBlockSelection(const QTextCursor&);
|
|
|
|
|
void blockSelection(QTextCursor *);
|
2010-09-13 13:53:18 +02:00
|
|
|
void hasBlockSelection(bool*);
|
2014-01-08 21:27:18 +01:00
|
|
|
void setShowRelativeLineNumbers(const QVariant &value);
|
2009-01-23 15:12:04 +01:00
|
|
|
|
2012-09-10 22:10:23 +02:00
|
|
|
void resetCommandBuffer();
|
2012-10-20 18:48:37 +02:00
|
|
|
void showCommandBuffer(const QString &contents, int cursorPos, int anchorPos,
|
2016-05-24 23:09:11 +03:00
|
|
|
int messageLevel, FakeVimHandler *eventFilter);
|
2009-01-23 15:12:04 +01:00
|
|
|
void showExtraInformation(const QString &msg);
|
|
|
|
|
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
|
2012-09-27 21:09:13 +02:00
|
|
|
void highlightMatches(const QString &needle);
|
2009-01-28 22:03:51 +01:00
|
|
|
void moveToMatchingParenthesis(bool *moved, bool *forward, QTextCursor *cursor);
|
2010-01-06 14:57:46 +01:00
|
|
|
void checkForElectricCharacter(bool *result, QChar c);
|
2012-10-13 09:33:30 +02:00
|
|
|
void indentRegion(int beginBlock, int endBlock, QChar typedChar);
|
2010-05-18 14:48:12 +02:00
|
|
|
void handleExCommand(bool *handled, const ExCommand &cmd);
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2011-03-02 12:31:41 +01:00
|
|
|
void writeSettings();
|
|
|
|
|
void readSettings();
|
|
|
|
|
|
2009-06-15 15:14:16 +02:00
|
|
|
void handleDelayedQuitAll(bool forced);
|
|
|
|
|
void handleDelayedQuit(bool forced, Core::IEditor *editor);
|
2015-02-18 17:22:18 +01:00
|
|
|
void userActionTriggered(int key);
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2010-07-14 14:33:26 +02:00
|
|
|
void switchToFile(int n);
|
|
|
|
|
int currentFile() const;
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2014-01-08 21:27:18 +01:00
|
|
|
void createRelativeNumberWidget(IEditor *editor);
|
|
|
|
|
|
2009-06-15 15:14:16 +02:00
|
|
|
signals:
|
|
|
|
|
void delayedQuitRequested(bool forced, Core::IEditor *editor);
|
|
|
|
|
void delayedQuitAllRequested(bool forced);
|
2009-01-13 16:38:05 +01:00
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
FakeVimPlugin *q;
|
2015-06-18 13:32:25 +02:00
|
|
|
FakeVimOptionPage *m_fakeVimOptionsPage = nullptr;
|
|
|
|
|
FakeVimExCommandsPage *m_fakeVimExCommandsPage = nullptr;
|
|
|
|
|
FakeVimUserCommandsPage *m_fakeVimUserCommandsPage = nullptr;
|
2012-08-21 19:58:39 +02:00
|
|
|
QHash<IEditor *, FakeVimHandler *> m_editorToHandler;
|
2009-05-29 07:45:35 +10:00
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void triggerAction(Id id);
|
|
|
|
|
void setActionChecked(Id id, bool check);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2010-12-13 16:31:20 +01:00
|
|
|
typedef int (*DistFunction)(const QRect &cursor, const QRect &other);
|
2013-04-24 18:15:32 +02:00
|
|
|
void moveSomewhere(DistFunction f, int count);
|
|
|
|
|
|
|
|
|
|
void keepOnlyWindow(); // :only
|
2010-12-13 16:31:20 +01:00
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
ExCommandMap &exCommandMap() { return m_exCommandMap; }
|
|
|
|
|
ExCommandMap &defaultExCommandMap() { return m_defaultExCommandMap; }
|
|
|
|
|
ExCommandMap m_exCommandMap;
|
|
|
|
|
ExCommandMap m_defaultExCommandMap;
|
|
|
|
|
|
|
|
|
|
UserCommandMap &userCommandMap() { return m_userCommandMap; }
|
|
|
|
|
UserCommandMap &defaultUserCommandMap() { return m_defaultUserCommandMap; }
|
|
|
|
|
UserCommandMap m_userCommandMap;
|
|
|
|
|
UserCommandMap m_defaultUserCommandMap;
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
StatusBarWidget *m_statusBar;
|
2011-04-15 16:19:23 +02:00
|
|
|
// @TODO: Delete
|
|
|
|
|
//WordCompletion *m_wordCompletion;
|
2015-06-16 15:24:42 +02:00
|
|
|
FakeVimCompletionAssistProvider *m_wordProvider = nullptr;
|
2009-01-13 16:38:05 +01:00
|
|
|
};
|
|
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
QVariant FakeVimUserCommandsModel::data(const QModelIndex &index, int role) const
|
|
|
|
|
{
|
|
|
|
|
if (!index.isValid())
|
|
|
|
|
return QVariant();
|
|
|
|
|
|
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole) {
|
|
|
|
|
switch (index.column()) {
|
|
|
|
|
case 0: // Action
|
2014-08-25 17:05:11 +02:00
|
|
|
return Tr::tr("User command #%1").arg(index.row() + 1);
|
2011-04-05 16:32:18 +02:00
|
|
|
case 1: // Command
|
|
|
|
|
return m_q->userCommandMap().value(index.row() + 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return QVariant();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bool FakeVimUserCommandsModel::setData(const QModelIndex &index,
|
|
|
|
|
const QVariant &data, int role)
|
|
|
|
|
{
|
|
|
|
|
if (role == Qt::DisplayRole || role == Qt::EditRole)
|
|
|
|
|
if (index.column() == 1)
|
|
|
|
|
m_q->userCommandMap()[index.row() + 1] = data.toString();
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
|
2015-06-18 13:32:25 +02:00
|
|
|
: q(plugin)
|
2010-01-29 21:33:57 +01:00
|
|
|
{
|
2016-03-18 12:10:24 +01:00
|
|
|
defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] =
|
|
|
|
|
QRegExp("^A$");
|
|
|
|
|
defaultExCommandMap()["Coreplugin.OutputPane.previtem"] =
|
|
|
|
|
QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
|
|
|
|
|
defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
|
|
|
|
|
QRegExp("^cn(ext)?!?( (.*))?$");
|
|
|
|
|
defaultExCommandMap()[TextEditor::Constants::FOLLOW_SYMBOL_UNDER_CURSOR] =
|
|
|
|
|
QRegExp("^tag?$");
|
|
|
|
|
defaultExCommandMap()[Core::Constants::GO_BACK] =
|
|
|
|
|
QRegExp("^pop?$");
|
|
|
|
|
defaultExCommandMap()["QtCreator.Locate"] =
|
|
|
|
|
QRegExp("^e$");
|
2011-04-05 16:32:18 +02:00
|
|
|
|
|
|
|
|
for (int i = 1; i < 10; ++i) {
|
|
|
|
|
QString cmd = QString::fromLatin1(":echo User command %1 executed.<CR>");
|
|
|
|
|
defaultUserCommandMap().insert(i, cmd.arg(i));
|
|
|
|
|
}
|
|
|
|
|
|
2010-09-17 13:11:12 +02:00
|
|
|
m_statusBar = 0;
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2015-06-16 15:24:42 +02:00
|
|
|
void FakeVimPluginPrivate::onCoreAboutToClose()
|
|
|
|
|
{
|
|
|
|
|
// Don't attach to editors anymore.
|
|
|
|
|
disconnect(EditorManager::instance(), &EditorManager::editorOpened,
|
|
|
|
|
this, &FakeVimPluginPrivate::editorOpened);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::aboutToShutdown()
|
2008-12-19 12:20:04 +01:00
|
|
|
{
|
2009-03-30 13:59:47 +02:00
|
|
|
q->removeObject(m_fakeVimOptionsPage);
|
|
|
|
|
delete m_fakeVimOptionsPage;
|
|
|
|
|
m_fakeVimOptionsPage = 0;
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
q->removeObject(m_fakeVimExCommandsPage);
|
|
|
|
|
delete m_fakeVimExCommandsPage;
|
|
|
|
|
m_fakeVimExCommandsPage = 0;
|
2011-04-05 16:32:18 +02:00
|
|
|
|
|
|
|
|
q->removeObject(m_fakeVimUserCommandsPage);
|
|
|
|
|
delete m_fakeVimUserCommandsPage;
|
|
|
|
|
m_fakeVimUserCommandsPage = 0;
|
2013-07-16 18:26:47 +02:00
|
|
|
|
2013-11-22 17:19:33 +01:00
|
|
|
delete m_wordProvider;
|
|
|
|
|
m_wordProvider = 0;
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-23 15:12:04 +01:00
|
|
|
bool FakeVimPluginPrivate::initialize()
|
2008-12-19 12:20:04 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
//m_wordCompletion = new WordCompletion;
|
|
|
|
|
//q->addAutoReleasedObject(m_wordCompletion);
|
|
|
|
|
m_wordProvider = new FakeVimCompletionAssistProvider;
|
|
|
|
|
|
2011-02-18 15:31:31 +01:00
|
|
|
/*
|
|
|
|
|
// Set completion settings and keep them up to date.
|
|
|
|
|
TextEditorSettings *textEditorSettings = TextEditorSettings::instance();
|
|
|
|
|
completion->setCompletionSettings(textEditorSettings->completionSettings());
|
2016-05-24 23:09:11 +03:00
|
|
|
connect(textEditorSettings, &TextEditorSettings::completionSettingsChanged,
|
|
|
|
|
completion, &TextEditorWidget::setCompletionSettings);
|
2011-02-18 15:31:31 +01:00
|
|
|
*/
|
|
|
|
|
|
2010-09-08 15:27:32 +02:00
|
|
|
Context globalcontext(Core::Constants::C_GLOBAL);
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2009-03-30 13:59:47 +02:00
|
|
|
m_fakeVimOptionsPage = new FakeVimOptionPage;
|
|
|
|
|
q->addObject(m_fakeVimOptionsPage);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
m_fakeVimExCommandsPage = new FakeVimExCommandsPage(this);
|
2010-01-22 13:56:50 +01:00
|
|
|
q->addObject(m_fakeVimExCommandsPage);
|
2011-04-05 16:32:18 +02:00
|
|
|
|
|
|
|
|
m_fakeVimUserCommandsPage = new FakeVimUserCommandsPage(this);
|
|
|
|
|
q->addObject(m_fakeVimUserCommandsPage);
|
|
|
|
|
|
2011-03-02 12:31:41 +01:00
|
|
|
readSettings();
|
2010-01-29 22:49:55 +01:00
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
Command *cmd = 0;
|
|
|
|
|
cmd = ActionManager::registerAction(theFakeVimSetting(ConfigUseFakeVim),
|
|
|
|
|
INSTALL_HANDLER, globalcontext, true);
|
2015-03-03 15:13:05 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence(UseMacShortcuts ? Tr::tr("Meta+Shift+V,Meta+Shift+V") : Tr::tr("Alt+V,Alt+V")));
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2011-08-15 10:52:28 +02:00
|
|
|
ActionContainer *advancedMenu =
|
2012-08-21 19:58:39 +02:00
|
|
|
ActionManager::actionContainer(Core::Constants::M_EDIT_ADVANCED);
|
2011-08-15 10:52:28 +02:00
|
|
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_EDITOR);
|
|
|
|
|
|
2013-09-03 11:42:35 +02:00
|
|
|
const Id base = "FakeVim.UserAction";
|
2011-04-05 16:32:18 +02:00
|
|
|
for (int i = 1; i < 10; ++i) {
|
2015-02-18 17:22:18 +01:00
|
|
|
auto act = new QAction(this);
|
2014-08-25 17:05:11 +02:00
|
|
|
act->setText(Tr::tr("Execute User Action #%1").arg(i));
|
2015-02-19 11:35:47 +01:00
|
|
|
cmd = ActionManager::registerAction(act, base.withSuffix(i));
|
2015-03-03 15:13:05 +01:00
|
|
|
cmd->setDefaultKeySequence(QKeySequence((UseMacShortcuts ? Tr::tr("Meta+Shift+V,%1") : Tr::tr("Alt+V,%1")).arg(i)));
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(act, &QAction::triggered, this, [this, i] { userActionTriggered(i); });
|
2011-04-05 16:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(ICore::instance(), &ICore::coreAboutToClose,
|
|
|
|
|
this, &FakeVimPluginPrivate::onCoreAboutToClose);
|
2010-10-20 17:10:47 +02:00
|
|
|
|
2009-01-09 17:57:48 +01:00
|
|
|
// EditorManager
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(EditorManager::instance(), &EditorManager::editorAboutToClose,
|
|
|
|
|
this, &FakeVimPluginPrivate::editorAboutToClose);
|
|
|
|
|
connect(EditorManager::instance(), &EditorManager::editorOpened,
|
|
|
|
|
this, &FakeVimPluginPrivate::editorOpened);
|
2016-12-09 10:10:31 +01:00
|
|
|
connect(EditorManager::instance(), &EditorManager::currentEditorAboutToChange,
|
|
|
|
|
this, &FakeVimPluginPrivate::currentEditorAboutToChange);
|
2015-02-18 17:22:18 +01:00
|
|
|
|
|
|
|
|
connect(DocumentManager::instance(), &DocumentManager::allDocumentsRenamed,
|
|
|
|
|
this, &FakeVimPluginPrivate::allDocumentsRenamed);
|
|
|
|
|
connect(DocumentManager::instance(), &DocumentManager::documentRenamed,
|
|
|
|
|
this, &FakeVimPluginPrivate::documentRenamed);
|
|
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
this, &FakeVimPluginPrivate::setUseFakeVim);
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(theFakeVimSetting(ConfigReadVimRc), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
this, &FakeVimPluginPrivate::maybeReadVimRc);
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(theFakeVimSetting(ConfigVimRcPath), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
this, &FakeVimPluginPrivate::maybeReadVimRc);
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
this, &FakeVimPluginPrivate::setShowRelativeLineNumbers);
|
2009-03-30 14:20:46 +02:00
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
// Delayed operations.
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(this, &FakeVimPluginPrivate::delayedQuitRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::handleDelayedQuit, Qt::QueuedConnection);
|
|
|
|
|
connect(this, &FakeVimPluginPrivate::delayedQuitAllRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::handleDelayedQuitAll, Qt::QueuedConnection);
|
2012-08-10 12:39:29 +02:00
|
|
|
|
|
|
|
|
// Vimrc can break test so don't source it if running tests.
|
2013-04-04 14:30:17 +02:00
|
|
|
if (!ExtensionSystem::PluginManager::testRunRequested())
|
2012-08-10 12:39:29 +02:00
|
|
|
maybeReadVimRc();
|
2010-04-16 17:47:02 +02:00
|
|
|
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2008-12-19 12:20:04 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
void FakeVimPluginPrivate::userActionTriggered(int key)
|
2011-04-05 16:32:18 +02:00
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
IEditor *editor = EditorManager::currentEditor();
|
2011-04-05 16:32:18 +02:00
|
|
|
FakeVimHandler *handler = m_editorToHandler[editor];
|
2013-11-20 20:16:04 +01:00
|
|
|
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);
|
2011-04-05 16:32:18 +02:00
|
|
|
handler->handleInput(cmd);
|
2013-11-20 20:16:04 +01:00
|
|
|
|
|
|
|
|
if (enableFakeVim)
|
|
|
|
|
setUseFakeVimInternal(false);
|
|
|
|
|
}
|
2011-04-05 16:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
2014-01-08 21:27:18 +01:00
|
|
|
void FakeVimPluginPrivate::createRelativeNumberWidget(IEditor *editor)
|
|
|
|
|
{
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *textEditor = qobject_cast<TextEditorWidget *>(editor->widget())) {
|
2016-03-18 12:10:24 +01:00
|
|
|
auto relativeNumbers = new RelativeNumbersColumn(textEditor);
|
|
|
|
|
connect(theFakeVimSetting(ConfigRelativeNumber), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
relativeNumbers, &QObject::deleteLater);
|
2016-03-18 12:10:24 +01:00
|
|
|
connect(theFakeVimSetting(ConfigUseFakeVim), &SavedAction::valueChanged,
|
2015-02-18 17:22:18 +01:00
|
|
|
relativeNumbers, &QObject::deleteLater);
|
2014-01-08 21:27:18 +01:00
|
|
|
relativeNumbers->show();
|
|
|
|
|
}
|
|
|
|
|
}
|
2012-08-21 19:58:39 +02:00
|
|
|
|
|
|
|
|
const char exCommandMapGroup[] = "FakeVimExCommand";
|
|
|
|
|
const char userCommandMapGroup[] = "FakeVimUserCommand";
|
|
|
|
|
const char reKey[] = "RegEx";
|
|
|
|
|
const char cmdKey[] = "Cmd";
|
|
|
|
|
const char idKey[] = "Command";
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-03-02 12:31:41 +01:00
|
|
|
void FakeVimPluginPrivate::writeSettings()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2011-03-02 12:31:41 +01:00
|
|
|
|
|
|
|
|
theFakeVimSettings()->writeSettings(settings);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
{ // block
|
2016-03-18 12:10:24 +01:00
|
|
|
settings->beginWriteArray(exCommandMapGroup);
|
2010-01-22 13:56:50 +01:00
|
|
|
int count = 0;
|
2011-04-05 16:32:18 +02:00
|
|
|
typedef ExCommandMap::const_iterator Iterator;
|
2010-05-19 16:21:42 +02:00
|
|
|
const Iterator end = exCommandMap().constEnd();
|
|
|
|
|
for (Iterator it = exCommandMap().constBegin(); it != end; ++it) {
|
2011-03-02 12:31:41 +01:00
|
|
|
const QString id = it.key();
|
|
|
|
|
const QRegExp re = it.value();
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
if ((defaultExCommandMap().contains(id) && defaultExCommandMap()[id] != re)
|
|
|
|
|
|| (!defaultExCommandMap().contains(id) && !re.pattern().isEmpty())) {
|
2010-01-22 13:56:50 +01:00
|
|
|
settings->setArrayIndex(count);
|
2016-03-18 12:10:24 +01:00
|
|
|
settings->setValue(idKey, id);
|
|
|
|
|
settings->setValue(reKey, re.pattern());
|
2010-01-22 13:56:50 +01:00
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2011-04-05 16:32:18 +02:00
|
|
|
settings->endArray();
|
|
|
|
|
} // block
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
{ // block
|
2016-03-18 12:10:24 +01:00
|
|
|
settings->beginWriteArray(userCommandMapGroup);
|
2011-04-05 16:32:18 +02:00
|
|
|
int count = 0;
|
|
|
|
|
typedef UserCommandMap::const_iterator Iterator;
|
|
|
|
|
const Iterator end = userCommandMap().constEnd();
|
|
|
|
|
for (Iterator it = userCommandMap().constBegin(); it != end; ++it) {
|
|
|
|
|
const int key = it.key();
|
|
|
|
|
const QString cmd = it.value();
|
|
|
|
|
|
|
|
|
|
if ((defaultUserCommandMap().contains(key)
|
|
|
|
|
&& defaultUserCommandMap()[key] != cmd)
|
|
|
|
|
|| (!defaultUserCommandMap().contains(key) && !cmd.isEmpty())) {
|
|
|
|
|
settings->setArrayIndex(count);
|
2016-03-18 12:10:24 +01:00
|
|
|
settings->setValue(idKey, key);
|
|
|
|
|
settings->setValue(cmdKey, cmd);
|
2011-04-05 16:32:18 +02:00
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-01-22 13:56:50 +01:00
|
|
|
settings->endArray();
|
2011-04-05 16:32:18 +02:00
|
|
|
} // block
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2011-03-02 12:31:41 +01:00
|
|
|
void FakeVimPluginPrivate::readSettings()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2012-01-24 15:36:40 +01:00
|
|
|
QSettings *settings = ICore::settings();
|
2011-03-02 12:31:41 +01:00
|
|
|
|
|
|
|
|
theFakeVimSettings()->readSettings(settings);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2011-03-02 12:31:41 +01:00
|
|
|
exCommandMap() = defaultExCommandMap();
|
2016-03-18 12:10:24 +01:00
|
|
|
int size = settings->beginReadArray(exCommandMapGroup);
|
2010-04-16 17:47:02 +02:00
|
|
|
for (int i = 0; i < size; ++i) {
|
2010-01-22 13:56:50 +01:00
|
|
|
settings->setArrayIndex(i);
|
2016-03-18 12:10:24 +01:00
|
|
|
const QString id = settings->value(idKey).toString();
|
|
|
|
|
const QString re = settings->value(reKey).toString();
|
2010-05-19 16:21:42 +02:00
|
|
|
exCommandMap()[id] = QRegExp(re);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2011-04-06 13:31:37 +02:00
|
|
|
settings->endArray();
|
2011-04-05 16:32:18 +02:00
|
|
|
|
|
|
|
|
userCommandMap() = defaultUserCommandMap();
|
2016-03-18 12:10:24 +01:00
|
|
|
size = settings->beginReadArray(userCommandMapGroup);
|
2011-04-05 16:32:18 +02:00
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
settings->setArrayIndex(i);
|
2016-03-18 12:10:24 +01:00
|
|
|
const int id = settings->value(idKey).toInt();
|
|
|
|
|
const QString cmd = settings->value(cmdKey).toString();
|
2011-04-05 16:32:18 +02:00
|
|
|
userCommandMap()[id] = cmd;
|
|
|
|
|
}
|
2010-01-22 13:56:50 +01:00
|
|
|
settings->endArray();
|
|
|
|
|
}
|
|
|
|
|
|
2010-04-16 17:47:02 +02:00
|
|
|
void FakeVimPluginPrivate::maybeReadVimRc()
|
|
|
|
|
{
|
2010-04-19 09:56:47 +02:00
|
|
|
//qDebug() << theFakeVimSetting(ConfigReadVimRc)
|
|
|
|
|
// << theFakeVimSetting(ConfigReadVimRc)->value();
|
|
|
|
|
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
2010-04-16 17:47:02 +02:00
|
|
|
if (!theFakeVimSetting(ConfigReadVimRc)->value().toBool())
|
|
|
|
|
return;
|
2013-02-14 19:12:30 +01:00
|
|
|
QString fileName = theFakeVimSetting(ConfigVimRcPath)->value().toString();
|
|
|
|
|
if (fileName.isEmpty()) {
|
2014-08-28 17:33:47 +02:00
|
|
|
fileName = QStandardPaths::writableLocation(QStandardPaths::HomeLocation)
|
2016-05-13 13:58:28 +02:00
|
|
|
+ QLatin1String(HostOsInfo::isWindowsHost() ? "/_vimrc" : "/.vimrc");
|
2013-02-14 19:12:30 +01:00
|
|
|
}
|
2010-04-16 17:47:02 +02:00
|
|
|
//qDebug() << "READING VIMRC: " << fileName;
|
|
|
|
|
// Read it into a temporary handler for effects modifying global state.
|
|
|
|
|
QPlainTextEdit editor;
|
|
|
|
|
FakeVimHandler handler(&editor);
|
2016-03-18 12:10:24 +01:00
|
|
|
handler.handleCommand("source " + fileName);
|
2011-03-02 12:31:41 +01:00
|
|
|
//writeSettings();
|
2010-04-19 09:56:47 +02:00
|
|
|
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
2010-04-16 17:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void FakeVimPluginPrivate::triggerAction(Id id)
|
2009-05-29 07:45:35 +10:00
|
|
|
{
|
2015-02-04 11:00:26 +02:00
|
|
|
Command *cmd = ActionManager::command(id);
|
2011-11-10 11:36:51 +01:00
|
|
|
QTC_ASSERT(cmd, qDebug() << "UNKNOWN CODE: " << id.name(); return);
|
2009-05-29 07:45:35 +10:00
|
|
|
QAction *action = cmd->action();
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
action->trigger();
|
|
|
|
|
}
|
|
|
|
|
|
2014-07-01 11:08:26 +02:00
|
|
|
void FakeVimPluginPrivate::setActionChecked(Id id, bool check)
|
2010-01-21 17:23:32 +01:00
|
|
|
{
|
2015-02-04 11:00:26 +02:00
|
|
|
Command *cmd = ActionManager::command(id);
|
2010-01-21 17:23:32 +01:00
|
|
|
QTC_ASSERT(cmd, return);
|
|
|
|
|
QAction *action = cmd->action();
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
QTC_ASSERT(action->isCheckable(), return);
|
2010-10-26 10:56:32 +02:00
|
|
|
action->setChecked(!check); // trigger negates the action's state
|
2010-01-21 17:23:32 +01:00
|
|
|
action->trigger();
|
|
|
|
|
}
|
|
|
|
|
|
2010-12-13 16:31:20 +01:00
|
|
|
static int moveRightWeight(const QRect &cursor, const QRect &other)
|
|
|
|
|
{
|
2013-04-24 18:15:32 +02:00
|
|
|
if (!cursor.adjusted(999999, 0, 0, 0).intersects(other))
|
2010-12-13 16:31:20 +01:00
|
|
|
return -1;
|
2013-02-04 19:47:36 +01:00
|
|
|
const int dx = other.left() - cursor.right();
|
2013-02-04 14:58:36 +01:00
|
|
|
const int dy = qAbs(cursor.center().y() - other.center().y());
|
|
|
|
|
const int w = 10000 * dx + dy;
|
2010-12-13 16:31:20 +01:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int moveLeftWeight(const QRect &cursor, const QRect &other)
|
|
|
|
|
{
|
2013-04-24 18:15:32 +02:00
|
|
|
if (!cursor.adjusted(-999999, 0, 0, 0).intersects(other))
|
2010-12-13 16:31:20 +01:00
|
|
|
return -1;
|
2013-02-04 19:47:36 +01:00
|
|
|
const int dx = cursor.left() - other.right();
|
2013-02-04 14:58:36 +01:00
|
|
|
const int dy = qAbs(cursor.center().y() -other.center().y());
|
|
|
|
|
const int w = 10000 * dx + dy;
|
2010-12-13 16:31:20 +01:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int moveUpWeight(const QRect &cursor, const QRect &other)
|
|
|
|
|
{
|
2013-04-24 18:15:32 +02:00
|
|
|
if (!cursor.adjusted(0, 0, 0, -999999).intersects(other))
|
2010-12-13 16:31:20 +01:00
|
|
|
return -1;
|
2013-02-04 19:47:36 +01:00
|
|
|
const int dy = cursor.top() - other.bottom();
|
2013-02-04 14:58:36 +01:00
|
|
|
const int dx = qAbs(cursor.center().x() - other.center().x());
|
|
|
|
|
const int w = 10000 * dy + dx;
|
2010-12-13 16:31:20 +01:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
static int moveDownWeight(const QRect &cursor, const QRect &other)
|
|
|
|
|
{
|
2013-04-24 18:15:32 +02:00
|
|
|
if (!cursor.adjusted(0, 0, 0, 999999).intersects(other))
|
2010-12-13 16:31:20 +01:00
|
|
|
return -1;
|
2013-02-04 19:47:36 +01:00
|
|
|
const int dy = other.top() - cursor.bottom();
|
2013-02-04 14:58:36 +01:00
|
|
|
const int dx = qAbs(cursor.center().x() - other.center().x());
|
|
|
|
|
const int w = 10000 * dy + dx;
|
2010-12-13 16:31:20 +01:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
2013-04-24 18:15:32 +02:00
|
|
|
void FakeVimPluginPrivate::windowCommand(const QString &map, int count)
|
2009-04-03 16:33:28 +02:00
|
|
|
{
|
2013-04-24 18:15:32 +02:00
|
|
|
// normalize mapping
|
|
|
|
|
const QString key = map.toUpper();
|
|
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
if (key == "C" || key == "<C-C>")
|
2013-04-24 18:15:32 +02:00
|
|
|
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "N" || key == "<C-N>")
|
2013-04-24 18:15:32 +02:00
|
|
|
triggerAction(Core::Constants::GOTONEXT);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "O" || key == "<C-O>")
|
2013-04-24 18:15:32 +02:00
|
|
|
keepOnlyWindow();
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "P" || key == "<C-P>")
|
2013-04-24 18:15:32 +02:00
|
|
|
triggerAction(Core::Constants::GOTOPREV);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "S" || key == "<C-S>")
|
2013-04-24 18:15:32 +02:00
|
|
|
triggerAction(Core::Constants::SPLIT);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "V" || key == "<C-V>")
|
2013-07-31 20:57:38 -05:00
|
|
|
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key == "W" || key == "<C-W>")
|
2013-05-22 16:00:26 +02:00
|
|
|
triggerAction(Core::Constants::GOTO_NEXT_SPLIT);
|
2016-03-18 12:10:24 +01:00
|
|
|
else if (key.contains("RIGHT") || key == "L" || key == "<S-L>")
|
|
|
|
|
moveSomewhere(&moveRightWeight, key == "<S-L>" ? -1 : count);
|
|
|
|
|
else if (key.contains("LEFT") || key == "H" || key == "<S-H>")
|
|
|
|
|
moveSomewhere(&moveLeftWeight, key == "<S-H>" ? -1 : count);
|
|
|
|
|
else if (key.contains("UP") || key == "K" || key == "<S-K>")
|
|
|
|
|
moveSomewhere(&moveUpWeight, key == "<S-K>" ? -1 : count);
|
|
|
|
|
else if (key.contains("DOWN") || key == "J" || key == "<S-J>")
|
|
|
|
|
moveSomewhere(&moveDownWeight, key == "<S-J>" ? -1 : count);
|
2013-04-24 18:15:32 +02:00
|
|
|
else
|
|
|
|
|
qDebug() << "UNKNOWN WINDOW COMMAND: <C-W>" << map;
|
2010-12-13 16:31:20 +01:00
|
|
|
}
|
|
|
|
|
|
2013-04-24 18:15:32 +02:00
|
|
|
void FakeVimPluginPrivate::moveSomewhere(DistFunction f, int count)
|
2010-12-13 16:31:20 +01:00
|
|
|
{
|
2013-02-04 19:47:36 +01:00
|
|
|
IEditor *currentEditor = EditorManager::currentEditor();
|
|
|
|
|
QWidget *w = currentEditor->widget();
|
2012-05-08 09:43:14 +02:00
|
|
|
QPlainTextEdit *pe = qobject_cast<QPlainTextEdit *>(w);
|
2010-12-13 16:31:20 +01:00
|
|
|
QTC_ASSERT(pe, return);
|
|
|
|
|
QRect rc = pe->cursorRect();
|
|
|
|
|
QRect cursorRect(w->mapToGlobal(rc.topLeft()),
|
|
|
|
|
w->mapToGlobal(rc.bottomRight()));
|
|
|
|
|
//qDebug() << "\nCURSOR: " << cursorRect;
|
|
|
|
|
|
|
|
|
|
IEditor *bestEditor = 0;
|
2013-04-24 18:15:32 +02:00
|
|
|
int repeat = count;
|
|
|
|
|
|
2013-08-29 15:46:04 +02:00
|
|
|
QList<IEditor *> editors = EditorManager::visibleEditors();
|
2013-04-24 18:15:32 +02:00
|
|
|
while (repeat < 0 || repeat-- > 0) {
|
|
|
|
|
editors.removeOne(currentEditor);
|
|
|
|
|
int bestValue = -1;
|
|
|
|
|
foreach (IEditor *editor, editors) {
|
|
|
|
|
QWidget *w = editor->widget();
|
|
|
|
|
QRect editorRect(w->mapToGlobal(w->geometry().topLeft()),
|
|
|
|
|
w->mapToGlobal(w->geometry().bottomRight()));
|
|
|
|
|
//qDebug() << " EDITOR: " << editorRect << editor;
|
|
|
|
|
|
|
|
|
|
int value = f(cursorRect, editorRect);
|
|
|
|
|
if (value != -1 && (bestValue == -1 || value < bestValue)) {
|
|
|
|
|
bestValue = value;
|
|
|
|
|
bestEditor = editor;
|
|
|
|
|
//qDebug() << " BEST SO FAR: " << bestValue << bestEditor;
|
|
|
|
|
}
|
2010-12-13 16:31:20 +01:00
|
|
|
}
|
2013-04-24 18:15:32 +02:00
|
|
|
if (bestValue == -1)
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
|
|
currentEditor = bestEditor;
|
|
|
|
|
//qDebug() << " BEST: " << bestValue << bestEditor;
|
2009-04-03 16:33:28 +02:00
|
|
|
}
|
2010-12-13 16:31:20 +01:00
|
|
|
|
|
|
|
|
// FIME: This is know to fail as the EditorManager will fall back to
|
|
|
|
|
// the current editor's view. Needs additional public API there.
|
|
|
|
|
if (bestEditor)
|
2012-05-08 09:43:14 +02:00
|
|
|
EditorManager::activateEditor(bestEditor);
|
2009-05-29 07:45:35 +10:00
|
|
|
}
|
|
|
|
|
|
2013-04-24 18:15:32 +02:00
|
|
|
void FakeVimPluginPrivate::keepOnlyWindow()
|
|
|
|
|
{
|
|
|
|
|
IEditor *currentEditor = EditorManager::currentEditor();
|
2013-08-29 15:46:04 +02:00
|
|
|
QList<IEditor *> editors = EditorManager::visibleEditors();
|
2013-04-24 18:15:32 +02:00
|
|
|
editors.removeOne(currentEditor);
|
|
|
|
|
|
|
|
|
|
foreach (IEditor *editor, editors) {
|
|
|
|
|
EditorManager::activateEditor(editor);
|
|
|
|
|
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-05-29 07:45:35 +10:00
|
|
|
void FakeVimPluginPrivate::find(bool reverse)
|
|
|
|
|
{
|
2016-03-11 19:12:07 +01:00
|
|
|
Find::setUseFakeVim(true);
|
|
|
|
|
Find::openFindToolBar(reverse ? Find::FindBackwardDirection
|
|
|
|
|
: Find::FindForwardDirection);
|
2009-04-03 16:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
2009-05-29 11:34:11 +10:00
|
|
|
void FakeVimPluginPrivate::findNext(bool reverse)
|
|
|
|
|
{
|
|
|
|
|
if (reverse)
|
2014-01-13 16:17:34 +01:00
|
|
|
triggerAction(Core::Constants::FIND_PREVIOUS);
|
2009-05-29 11:34:11 +10:00
|
|
|
else
|
2014-01-13 16:17:34 +01:00
|
|
|
triggerAction(Core::Constants::FIND_NEXT);
|
2009-05-29 11:34:11 +10:00
|
|
|
}
|
|
|
|
|
|
2012-10-05 17:33:20 +02:00
|
|
|
void FakeVimPluginPrivate::foldToggle(int depth)
|
|
|
|
|
{
|
|
|
|
|
IEditor *ieditor = EditorManager::currentEditor();
|
2013-04-08 20:06:17 +02:00
|
|
|
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0);
|
|
|
|
|
QTC_ASSERT(handler != 0, return);
|
2012-10-05 17:33:20 +02:00
|
|
|
|
2013-04-08 20:06:17 +02:00
|
|
|
QTextBlock block = handler->textCursor().block();
|
2014-09-26 09:14:03 +02:00
|
|
|
fold(depth, !TextDocumentLayout::isFolded(block));
|
2012-10-05 17:33:20 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::foldAll(bool fold)
|
|
|
|
|
{
|
|
|
|
|
IEditor *ieditor = EditorManager::currentEditor();
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(ieditor->widget());
|
2012-10-05 17:33:20 +02:00
|
|
|
QTC_ASSERT(editor != 0, return);
|
|
|
|
|
|
|
|
|
|
QTextDocument *doc = editor->document();
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout *documentLayout =
|
|
|
|
|
qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
2012-10-05 17:33:20 +02:00
|
|
|
QTC_ASSERT(documentLayout != 0, return);
|
|
|
|
|
|
|
|
|
|
QTextBlock block = editor->document()->firstBlock();
|
|
|
|
|
while (block.isValid()) {
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout::doFoldOrUnfold(block, !fold);
|
2012-10-05 17:33:20 +02:00
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
documentLayout->requestUpdate();
|
|
|
|
|
documentLayout->emitDocumentSizeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::fold(int depth, bool fold)
|
|
|
|
|
{
|
|
|
|
|
IEditor *ieditor = EditorManager::currentEditor();
|
2013-04-08 20:06:17 +02:00
|
|
|
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0);
|
|
|
|
|
QTC_ASSERT(handler != 0, return);
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(ieditor->widget());
|
2012-10-05 17:33:20 +02:00
|
|
|
QTC_ASSERT(editor != 0, return);
|
|
|
|
|
|
|
|
|
|
QTextDocument *doc = editor->document();
|
2014-09-26 09:14:03 +02:00
|
|
|
TextDocumentLayout *documentLayout =
|
|
|
|
|
qobject_cast<TextDocumentLayout*>(doc->documentLayout());
|
2012-10-05 17:33:20 +02:00
|
|
|
QTC_ASSERT(documentLayout != 0, return);
|
|
|
|
|
|
2013-04-08 20:06:17 +02:00
|
|
|
QTextBlock block = handler->textCursor().block();
|
2014-09-26 09:14:03 +02:00
|
|
|
int indent = TextDocumentLayout::foldingIndent(block);
|
2012-10-05 17:33:20 +02:00
|
|
|
if (fold) {
|
2014-09-26 09:14:03 +02:00
|
|
|
if (TextDocumentLayout::isFolded(block)) {
|
|
|
|
|
while (block.isValid() && (TextDocumentLayout::foldingIndent(block) >= indent
|
2012-10-05 17:33:20 +02:00
|
|
|
|| !block.isVisible())) {
|
|
|
|
|
block = block.previous();
|
|
|
|
|
}
|
|
|
|
|
}
|
2014-09-26 09:14:03 +02:00
|
|
|
if (TextDocumentLayout::canFold(block))
|
2012-10-05 17:33:20 +02:00
|
|
|
++indent;
|
|
|
|
|
while (depth != 0 && block.isValid()) {
|
2014-09-26 09:14:03 +02:00
|
|
|
const int indent2 = TextDocumentLayout::foldingIndent(block);
|
|
|
|
|
if (TextDocumentLayout::canFold(block) && indent2 < indent) {
|
|
|
|
|
TextDocumentLayout::doFoldOrUnfold(block, false);
|
2012-10-05 17:33:20 +02:00
|
|
|
if (depth > 0)
|
|
|
|
|
--depth;
|
|
|
|
|
indent = indent2;
|
|
|
|
|
}
|
|
|
|
|
block = block.previous();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-09-26 09:14:03 +02:00
|
|
|
if (TextDocumentLayout::isFolded(block)) {
|
2012-10-05 17:33:20 +02:00
|
|
|
if (depth < 0) {
|
|
|
|
|
// recursively open fold
|
|
|
|
|
while (depth < 0 && block.isValid()
|
2014-09-26 09:14:03 +02:00
|
|
|
&& TextDocumentLayout::foldingIndent(block) >= indent) {
|
|
|
|
|
if (TextDocumentLayout::canFold(block)) {
|
|
|
|
|
TextDocumentLayout::doFoldOrUnfold(block, true);
|
2012-10-05 17:33:20 +02:00
|
|
|
if (depth > 0)
|
|
|
|
|
--depth;
|
|
|
|
|
}
|
|
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
} else {
|
2014-09-26 09:14:03 +02:00
|
|
|
if (TextDocumentLayout::canFold(block)) {
|
|
|
|
|
TextDocumentLayout::doFoldOrUnfold(block, true);
|
2012-10-05 17:33:20 +02:00
|
|
|
if (depth > 0)
|
|
|
|
|
--depth;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
documentLayout->requestUpdate();
|
|
|
|
|
documentLayout->emitDocumentSizeChanged();
|
|
|
|
|
}
|
|
|
|
|
|
2012-11-29 20:14:56 +01:00
|
|
|
void FakeVimPluginPrivate::foldGoTo(int count, bool current)
|
2012-11-29 19:04:52 +01:00
|
|
|
{
|
|
|
|
|
IEditor *ieditor = EditorManager::currentEditor();
|
2013-04-08 20:06:17 +02:00
|
|
|
FakeVimHandler *handler = m_editorToHandler.value(ieditor, 0);
|
|
|
|
|
QTC_ASSERT(handler != 0, return);
|
2012-11-29 19:04:52 +01:00
|
|
|
|
2013-04-08 20:06:17 +02:00
|
|
|
QTextCursor tc = handler->textCursor();
|
2012-11-29 19:04:52 +01:00
|
|
|
QTextBlock block = tc.block();
|
|
|
|
|
|
|
|
|
|
int pos = -1;
|
|
|
|
|
if (count > 0) {
|
|
|
|
|
int repeat = count;
|
|
|
|
|
block = block.next();
|
2012-11-29 20:14:56 +01:00
|
|
|
QTextBlock prevBlock = block;
|
2014-09-26 09:14:03 +02:00
|
|
|
int indent = TextDocumentLayout::foldingIndent(block);
|
2012-11-29 20:14:56 +01:00
|
|
|
block = block.next();
|
2012-11-29 19:04:52 +01:00
|
|
|
while (block.isValid()) {
|
2014-09-26 09:14:03 +02:00
|
|
|
int newIndent = TextDocumentLayout::foldingIndent(block);
|
2012-11-29 20:14:56 +01:00
|
|
|
if (current ? indent > newIndent : indent < newIndent) {
|
|
|
|
|
if (prevBlock.isVisible()) {
|
|
|
|
|
pos = prevBlock.position();
|
|
|
|
|
if (--repeat <= 0)
|
|
|
|
|
break;
|
|
|
|
|
} else if (current) {
|
|
|
|
|
indent = newIndent;
|
|
|
|
|
}
|
2012-11-29 19:04:52 +01:00
|
|
|
}
|
2012-11-29 20:14:56 +01:00
|
|
|
if (!current)
|
|
|
|
|
indent = newIndent;
|
2012-11-29 19:04:52 +01:00
|
|
|
prevBlock = block;
|
|
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
} else if (count < 0) {
|
|
|
|
|
int repeat = -count;
|
2014-09-26 09:14:03 +02:00
|
|
|
int indent = TextDocumentLayout::foldingIndent(block);
|
2012-11-29 19:04:52 +01:00
|
|
|
block = block.previous();
|
|
|
|
|
while (block.isValid()) {
|
2014-09-26 09:14:03 +02:00
|
|
|
int newIndent = TextDocumentLayout::foldingIndent(block);
|
2012-11-29 20:14:56 +01:00
|
|
|
if (current ? indent > newIndent : indent < newIndent) {
|
2012-11-29 19:04:52 +01:00
|
|
|
while (block.isValid() && !block.isVisible())
|
|
|
|
|
block = block.previous();
|
|
|
|
|
pos = block.position();
|
|
|
|
|
if (--repeat <= 0)
|
|
|
|
|
break;
|
|
|
|
|
}
|
2012-11-29 20:14:56 +01:00
|
|
|
if (!current)
|
|
|
|
|
indent = newIndent;
|
2012-11-29 19:04:52 +01:00
|
|
|
block = block.previous();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (pos != -1) {
|
|
|
|
|
tc.setPosition(pos, QTextCursor::KeepAnchor);
|
2013-04-08 20:06:17 +02:00
|
|
|
handler->setTextCursor(tc);
|
2012-11-29 19:04:52 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-28 14:00:50 +01:00
|
|
|
void FakeVimPluginPrivate::jumpToGlobalMark(QChar mark, bool backTickMode,
|
|
|
|
|
const QString &fileName)
|
|
|
|
|
{
|
2015-02-04 11:00:26 +02:00
|
|
|
IEditor *iedit = EditorManager::openEditor(fileName);
|
2012-10-28 14:00:50 +01:00
|
|
|
if (!iedit)
|
|
|
|
|
return;
|
|
|
|
|
FakeVimHandler *handler = m_editorToHandler.value(iedit, 0);
|
|
|
|
|
if (handler)
|
|
|
|
|
handler->jumpToLocalMark(mark, backTickMode);
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-26 17:55:43 +01:00
|
|
|
// This class defers deletion of a child FakeVimHandler using deleteLater().
|
2010-01-22 13:56:50 +01:00
|
|
|
class DeferredDeleter : public QObject
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
FakeVimHandler *m_handler;
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
DeferredDeleter(QObject *parent, FakeVimHandler *handler)
|
2010-03-26 17:55:43 +01:00
|
|
|
: QObject(parent), m_handler(handler)
|
2010-01-22 13:56:50 +01:00
|
|
|
{}
|
|
|
|
|
|
2014-02-17 19:23:20 +02:00
|
|
|
~DeferredDeleter()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
|
|
|
|
if (m_handler) {
|
|
|
|
|
m_handler->disconnectFromEditor();
|
|
|
|
|
m_handler->deleteLater();
|
|
|
|
|
m_handler = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
void FakeVimPluginPrivate::editorOpened(IEditor *editor)
|
2009-01-09 17:57:48 +01:00
|
|
|
{
|
2009-02-04 16:42:55 +01:00
|
|
|
if (!editor)
|
|
|
|
|
return;
|
|
|
|
|
|
2009-01-23 15:12:04 +01:00
|
|
|
QWidget *widget = editor->widget();
|
2009-02-04 16:42:55 +01:00
|
|
|
if (!widget)
|
|
|
|
|
return;
|
2009-02-04 16:48:03 +01:00
|
|
|
|
|
|
|
|
// we can only handle QTextEdit and QPlainTextEdit
|
|
|
|
|
if (!qobject_cast<QTextEdit *>(widget) && !qobject_cast<QPlainTextEdit *>(widget))
|
|
|
|
|
return;
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
//qDebug() << "OPENING: " << editor << editor->widget()
|
|
|
|
|
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
|
|
|
|
|
|
2016-03-18 12:10:24 +01:00
|
|
|
auto handler = new FakeVimHandler(widget, 0);
|
2010-01-22 13:56:50 +01:00
|
|
|
// the handler might have triggered the deletion of the editor:
|
|
|
|
|
// make sure that it can return before being deleted itself
|
|
|
|
|
new DeferredDeleter(widget, handler);
|
2009-03-30 16:54:25 +02:00
|
|
|
m_editorToHandler[editor] = handler;
|
2009-01-23 15:12:04 +01:00
|
|
|
|
2015-02-18 17:22:18 +01:00
|
|
|
connect(handler, &FakeVimHandler::extraInformationChanged,
|
|
|
|
|
this, &FakeVimPluginPrivate::showExtraInformation);
|
|
|
|
|
connect(handler, &FakeVimHandler::commandBufferChanged,
|
|
|
|
|
this, &FakeVimPluginPrivate::showCommandBuffer);
|
|
|
|
|
connect(handler, &FakeVimHandler::selectionChanged,
|
|
|
|
|
this, &FakeVimPluginPrivate::changeSelection);
|
|
|
|
|
connect(handler, &FakeVimHandler::highlightMatches,
|
|
|
|
|
this, &FakeVimPluginPrivate::highlightMatches);
|
|
|
|
|
connect(handler, &FakeVimHandler::moveToMatchingParenthesis,
|
|
|
|
|
this, &FakeVimPluginPrivate::moveToMatchingParenthesis, Qt::DirectConnection);
|
|
|
|
|
connect(handler, &FakeVimHandler::indentRegion,
|
|
|
|
|
this, &FakeVimPluginPrivate::indentRegion);
|
|
|
|
|
connect(handler, &FakeVimHandler::checkForElectricCharacter,
|
|
|
|
|
this, &FakeVimPluginPrivate::checkForElectricCharacter, Qt::DirectConnection);
|
|
|
|
|
connect(handler, &FakeVimHandler::requestDisableBlockSelection,
|
|
|
|
|
this, &FakeVimPluginPrivate::disableBlockSelection);
|
|
|
|
|
connect(handler, &FakeVimHandler::requestSetBlockSelection,
|
|
|
|
|
this, &FakeVimPluginPrivate::setBlockSelection);
|
|
|
|
|
connect(handler, &FakeVimHandler::requestBlockSelection,
|
|
|
|
|
this, &FakeVimPluginPrivate::blockSelection, Qt::DirectConnection);
|
|
|
|
|
connect(handler, &FakeVimHandler::requestHasBlockSelection,
|
|
|
|
|
this, &FakeVimPluginPrivate::hasBlockSelection, Qt::DirectConnection);
|
|
|
|
|
connect(handler, &FakeVimHandler::completionRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::triggerCompletions);
|
|
|
|
|
connect(handler, &FakeVimHandler::simpleCompletionRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::triggerSimpleCompletions);
|
|
|
|
|
connect(handler, &FakeVimHandler::windowCommandRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::windowCommand);
|
|
|
|
|
connect(handler, &FakeVimHandler::findRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::find);
|
|
|
|
|
connect(handler, &FakeVimHandler::findNextRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::findNext);
|
|
|
|
|
connect(handler, &FakeVimHandler::foldToggle,
|
|
|
|
|
this, &FakeVimPluginPrivate::foldToggle);
|
|
|
|
|
connect(handler, &FakeVimHandler::foldAll,
|
|
|
|
|
this, &FakeVimPluginPrivate::foldAll);
|
|
|
|
|
connect(handler, &FakeVimHandler::fold,
|
|
|
|
|
this, &FakeVimPluginPrivate::fold);
|
|
|
|
|
connect(handler, &FakeVimHandler::foldGoTo,
|
|
|
|
|
this, &FakeVimPluginPrivate::foldGoTo);
|
|
|
|
|
connect(handler, &FakeVimHandler::jumpToGlobalMark,
|
|
|
|
|
this, &FakeVimPluginPrivate::jumpToGlobalMark);
|
|
|
|
|
|
|
|
|
|
connect(handler, &FakeVimHandler::handleExCommandRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::handleExCommand, Qt::DirectConnection);
|
|
|
|
|
|
|
|
|
|
connect(ICore::instance(), &ICore::saveSettingsRequested,
|
|
|
|
|
this, &FakeVimPluginPrivate::writeSettings);
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2014-12-21 21:54:30 +02:00
|
|
|
handler->setCurrentFileName(editor->document()->filePath().toString());
|
2009-03-30 16:54:25 +02:00
|
|
|
handler->installEventFilter();
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-03-31 11:44:18 +02:00
|
|
|
// pop up the bar
|
2010-04-07 18:08:09 +02:00
|
|
|
if (theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) {
|
2012-09-10 22:10:23 +02:00
|
|
|
resetCommandBuffer();
|
2010-04-07 18:08:09 +02:00
|
|
|
handler->setupWidget();
|
2014-01-08 21:27:18 +01:00
|
|
|
|
2014-12-01 17:43:20 +01:00
|
|
|
if (theFakeVimSetting(ConfigRelativeNumber)->value().toBool())
|
|
|
|
|
createRelativeNumberWidget(editor);
|
|
|
|
|
}
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
void FakeVimPluginPrivate::editorAboutToClose(IEditor *editor)
|
2009-01-26 10:24:36 +01:00
|
|
|
{
|
2009-03-30 16:54:25 +02:00
|
|
|
//qDebug() << "CLOSING: " << editor << editor->widget();
|
|
|
|
|
m_editorToHandler.remove(editor);
|
|
|
|
|
}
|
|
|
|
|
|
2016-12-09 10:10:31 +01:00
|
|
|
void FakeVimPluginPrivate::currentEditorAboutToChange(IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
if (FakeVimHandler *handler = m_editorToHandler.value(editor, 0))
|
|
|
|
|
handler->enterCommandMode();
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-09 15:42:35 +02:00
|
|
|
void FakeVimPluginPrivate::allDocumentsRenamed(const QString &oldName, const QString &newName)
|
|
|
|
|
{
|
|
|
|
|
renameFileNameInEditors(oldName, newName);
|
|
|
|
|
FakeVimHandler::updateGlobalMarksFilenames(oldName, newName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::documentRenamed(
|
|
|
|
|
IDocument *, const QString &oldName, const QString &newName)
|
|
|
|
|
{
|
|
|
|
|
renameFileNameInEditors(oldName, newName);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::renameFileNameInEditors(const QString &oldName, const QString &newName)
|
|
|
|
|
{
|
|
|
|
|
foreach (FakeVimHandler *handler, m_editorToHandler.values()) {
|
|
|
|
|
if (handler->currentFileName() == oldName)
|
|
|
|
|
handler->setCurrentFileName(newName);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
void FakeVimPluginPrivate::setUseFakeVim(const QVariant &value)
|
|
|
|
|
{
|
2009-03-31 11:44:18 +02:00
|
|
|
//qDebug() << "SET USE FAKEVIM" << value;
|
2009-03-30 16:54:25 +02:00
|
|
|
bool on = value.toBool();
|
2016-03-11 19:12:07 +01:00
|
|
|
Find::setUseFakeVim(on);
|
2011-04-05 16:32:18 +02:00
|
|
|
setUseFakeVimInternal(on);
|
2014-12-01 17:43:20 +01:00
|
|
|
setShowRelativeLineNumbers(theFakeVimSetting(ConfigRelativeNumber)->value());
|
2011-04-05 16:32:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::setUseFakeVimInternal(bool on)
|
|
|
|
|
{
|
2009-03-30 16:54:25 +02:00
|
|
|
if (on) {
|
2010-09-17 13:11:12 +02:00
|
|
|
//ICore *core = ICore::instance();
|
2012-08-21 19:58:39 +02:00
|
|
|
//core->updateAdditionalContexts(Context(FAKEVIM_CONTEXT),
|
|
|
|
|
// Context());
|
|
|
|
|
foreach (IEditor *editor, m_editorToHandler.keys())
|
2009-03-30 16:54:25 +02:00
|
|
|
m_editorToHandler[editor]->setupWidget();
|
|
|
|
|
} else {
|
2010-09-17 13:11:12 +02:00
|
|
|
//ICore *core = ICore::instance();
|
2012-08-21 19:58:39 +02:00
|
|
|
//core->updateAdditionalContexts(Context(),
|
|
|
|
|
// Context(FAKEVIM_CONTEXT));
|
2012-09-10 22:10:23 +02:00
|
|
|
resetCommandBuffer();
|
2012-08-21 19:58:39 +02:00
|
|
|
foreach (IEditor *editor, m_editorToHandler.keys()) {
|
2014-09-26 09:14:03 +02:00
|
|
|
if (TextDocument *textDocument = qobject_cast<TextDocument *>(editor->document()))
|
2014-01-17 15:54:59 +01:00
|
|
|
m_editorToHandler[editor]->restoreWidget(textDocument->tabSettings().m_tabSize);
|
2011-02-01 14:13:54 +01:00
|
|
|
}
|
2009-03-30 16:54:25 +02:00
|
|
|
}
|
2009-01-26 10:24:36 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-25 13:31:30 +01:00
|
|
|
void FakeVimPluginPrivate::triggerCompletions()
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *editor = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2011-04-15 16:19:23 +02:00
|
|
|
editor->invokeAssist(Completion, m_wordProvider);
|
|
|
|
|
// CompletionSupport::instance()->complete(editor->editor(), TextCompletion, false);
|
2009-03-25 13:31:30 +01:00
|
|
|
}
|
|
|
|
|
|
2013-05-05 22:43:52 +03:00
|
|
|
void FakeVimPluginPrivate::triggerSimpleCompletions(const QString &needle, bool forward)
|
2010-12-21 11:36:42 +01:00
|
|
|
{
|
2011-04-15 16:19:23 +02:00
|
|
|
// m_wordCompletion->setActive(needle, forward, qobject_cast<FakeVimHandler *>(sender()));
|
|
|
|
|
m_wordProvider->setActive(needle, forward, qobject_cast<FakeVimHandler *>(sender()));
|
2010-12-21 11:36:42 +01:00
|
|
|
}
|
|
|
|
|
|
2014-06-16 14:20:36 +02:00
|
|
|
void FakeVimPluginPrivate::disableBlockSelection()
|
2010-09-13 13:53:18 +02:00
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2014-06-16 14:20:36 +02:00
|
|
|
bt->setBlockSelection(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::setBlockSelection(const QTextCursor &cursor)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2014-06-16 14:20:36 +02:00
|
|
|
bt->setBlockSelection(cursor);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::blockSelection(QTextCursor *cursor)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2014-06-16 14:20:36 +02:00
|
|
|
if (cursor)
|
|
|
|
|
*cursor = bt->blockSelection();
|
2010-09-13 13:53:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::hasBlockSelection(bool *on)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2010-09-13 13:53:18 +02:00
|
|
|
*on = bt->hasBlockSelection();
|
|
|
|
|
}
|
|
|
|
|
|
2014-01-08 21:27:18 +01:00
|
|
|
void FakeVimPluginPrivate::setShowRelativeLineNumbers(const QVariant &value)
|
|
|
|
|
{
|
2014-12-01 17:43:20 +01:00
|
|
|
if (value.toBool() && theFakeVimSetting(ConfigUseFakeVim)->value().toBool()) {
|
2014-01-08 21:27:18 +01:00
|
|
|
foreach (IEditor *editor, m_editorToHandler.keys())
|
|
|
|
|
createRelativeNumberWidget(editor);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:57:46 +01:00
|
|
|
void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
2014-08-01 23:31:56 +02:00
|
|
|
*result = bt->textDocument()->indenter()->isElectricCharacter(c);
|
2010-01-06 14:57:46 +01:00
|
|
|
}
|
|
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
void FakeVimPluginPrivate::handleExCommand(bool *handled, const ExCommand &cmd)
|
2009-06-15 15:14:16 +02:00
|
|
|
{
|
|
|
|
|
using namespace Core;
|
2010-07-14 14:33:26 +02:00
|
|
|
//qDebug() << "PLUGIN HANDLE: " << cmd.cmd << cmd.count;
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
*handled = false;
|
2010-05-18 12:58:36 +02:00
|
|
|
|
2009-06-15 15:14:16 +02:00
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
|
|
|
|
|
2013-04-26 18:07:04 +02:00
|
|
|
// Focus editor first so actions can be executed in correct context.
|
|
|
|
|
QWidget *editor = handler->widget();
|
|
|
|
|
if (editor)
|
|
|
|
|
editor->setFocus();
|
|
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
*handled = true;
|
2016-06-03 13:00:51 +02:00
|
|
|
if ((cmd.matches("w", "write") || cmd.cmd == "wq") && cmd.args.isEmpty()) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :w[rite]
|
2012-08-21 19:58:39 +02:00
|
|
|
IEditor *editor = m_editorToHandler.key(handler);
|
2010-05-18 14:48:12 +02:00
|
|
|
const QString fileName = handler->currentFileName();
|
2014-12-21 21:54:30 +02:00
|
|
|
if (editor && editor->document()->filePath().toString() == fileName) {
|
2010-05-18 14:48:12 +02:00
|
|
|
// Handle that as a special case for nicer interaction with core
|
2012-02-14 16:43:51 +01:00
|
|
|
DocumentManager::saveDocument(editor->document());
|
2010-05-18 14:48:12 +02:00
|
|
|
// Check result by reading back.
|
|
|
|
|
QFile file3(fileName);
|
|
|
|
|
file3.open(QIODevice::ReadOnly);
|
|
|
|
|
QByteArray ba = file3.readAll();
|
2014-08-25 17:05:11 +02:00
|
|
|
handler->showMessage(MessageInfo, Tr::tr("\"%1\" %2 %3L, %4C written")
|
2016-03-18 12:10:24 +01:00
|
|
|
.arg(fileName).arg(' ').arg(ba.count('\n')).arg(ba.size()));
|
|
|
|
|
if (cmd.cmd == "wq")
|
2010-10-11 11:52:49 +02:00
|
|
|
delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
|
2010-05-18 14:48:12 +02:00
|
|
|
} else {
|
2014-08-25 17:05:11 +02:00
|
|
|
handler->showMessage(MessageError, Tr::tr("File not saved"));
|
2010-05-18 14:48:12 +02:00
|
|
|
}
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("wa", "wall")) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :w[all]
|
2012-02-14 16:43:51 +01:00
|
|
|
QList<IDocument *> toSave = DocumentManager::modifiedDocuments();
|
2014-01-21 13:25:19 +01:00
|
|
|
QList<IDocument *> failed;
|
|
|
|
|
bool success = DocumentManager::saveModifiedDocuments(toSave, QString(), 0, QString(), 0, &failed);
|
|
|
|
|
if (!success)
|
2014-08-25 17:05:11 +02:00
|
|
|
handler->showMessage(MessageInfo, Tr::tr("Saving succeeded"));
|
2009-06-15 15:14:16 +02:00
|
|
|
else
|
2014-08-25 17:05:11 +02:00
|
|
|
handler->showMessage(MessageError, Tr::tr("%n files not saved", 0, failed.size()));
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("q", "quit")) {
|
2010-05-18 12:58:36 +02:00
|
|
|
// :q[uit]
|
2010-05-18 14:48:12 +02:00
|
|
|
emit delayedQuitRequested(cmd.hasBang, m_editorToHandler.key(handler));
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("qa", "qall")) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :qa[ll]
|
2010-05-18 14:48:12 +02:00
|
|
|
emit delayedQuitAllRequested(cmd.hasBang);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("sp", "split")) {
|
2010-05-05 16:05:49 +02:00
|
|
|
// :sp[lit]
|
|
|
|
|
triggerAction(Core::Constants::SPLIT);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("vs", "vsplit")) {
|
2010-05-05 16:05:49 +02:00
|
|
|
// :vs[plit]
|
|
|
|
|
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("mak", "make")) {
|
2010-05-18 12:58:36 +02:00
|
|
|
// :mak[e][!] [arguments]
|
|
|
|
|
triggerAction(ProjectExplorer::Constants::BUILD);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("se", "set")) {
|
2010-05-18 14:48:12 +02:00
|
|
|
if (cmd.args.isEmpty()) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :se[t]
|
2015-02-23 11:07:38 +01:00
|
|
|
ICore::showOptionsDialog(SETTINGS_ID);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.args == "ic" || cmd.args == "ignorecase") {
|
2010-10-26 10:56:32 +02:00
|
|
|
// :set nc
|
2014-01-13 16:17:34 +01:00
|
|
|
setActionChecked(Core::Constants::CASE_SENSITIVE, false);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.args == "noic" || cmd.args == "noignorecase") {
|
2010-05-18 14:48:12 +02:00
|
|
|
// :set noic
|
2014-01-13 16:17:34 +01:00
|
|
|
setActionChecked(Core::Constants::CASE_SENSITIVE, true);
|
2010-05-18 14:48:12 +02:00
|
|
|
}
|
2013-03-03 16:33:47 +01:00
|
|
|
*handled = false; // Let the handler see it as well.
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("n", "next")) {
|
2010-07-14 14:33:26 +02:00
|
|
|
// :n[ext]
|
|
|
|
|
switchToFile(currentFile() + cmd.count);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("prev", "previous") || cmd.matches("N", "Next")) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :prev[ious], :N[ext]
|
2010-07-14 14:33:26 +02:00
|
|
|
switchToFile(currentFile() - cmd.count);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("bn", "bnext")) {
|
2010-07-14 14:33:26 +02:00
|
|
|
// :bn[ext]
|
|
|
|
|
switchToFile(currentFile() + cmd.count);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("bp", "bprevious") || cmd.matches("bN", "bNext")) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :bp[revious], :bN[ext]
|
2010-07-14 14:33:26 +02:00
|
|
|
switchToFile(currentFile() - cmd.count);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.matches("on", "only")) {
|
2010-07-14 18:15:17 +02:00
|
|
|
// :on[ly]
|
2013-04-24 18:15:32 +02:00
|
|
|
keepOnlyWindow();
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.cmd == "AS") {
|
2011-02-11 10:59:19 +00:00
|
|
|
triggerAction(Core::Constants::SPLIT);
|
|
|
|
|
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
|
2016-03-18 12:10:24 +01:00
|
|
|
} else if (cmd.cmd == "AV") {
|
2011-02-11 10:59:19 +00:00
|
|
|
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
|
|
|
|
|
triggerAction(CppTools::Constants::SWITCH_HEADER_SOURCE);
|
2009-06-15 15:14:16 +02:00
|
|
|
} else {
|
2010-05-18 14:48:12 +02:00
|
|
|
// Check whether one of the configure commands matches.
|
2011-04-05 16:32:18 +02:00
|
|
|
typedef ExCommandMap::const_iterator Iterator;
|
2010-05-19 16:21:42 +02:00
|
|
|
const Iterator end = exCommandMap().constEnd();
|
|
|
|
|
for (Iterator it = exCommandMap().constBegin(); it != end; ++it) {
|
2010-01-22 13:56:50 +01:00
|
|
|
const QString &id = it.key();
|
2012-04-30 12:01:15 +02:00
|
|
|
QRegExp re = it.value();
|
2010-05-19 16:21:42 +02:00
|
|
|
if (!re.pattern().isEmpty() && re.indexIn(cmd.cmd) != -1) {
|
2015-02-04 11:00:26 +02:00
|
|
|
triggerAction(Id::fromString(id));
|
2010-01-22 13:56:50 +01:00
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-18 14:48:12 +02:00
|
|
|
*handled = false;
|
2010-01-21 17:23:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-08-21 19:58:39 +02:00
|
|
|
void FakeVimPluginPrivate::handleDelayedQuit(bool forced, IEditor *editor)
|
2009-06-15 15:14:16 +02:00
|
|
|
{
|
2010-09-08 15:57:19 +02:00
|
|
|
// This tries to simulate vim behaviour. But the models of vim and
|
|
|
|
|
// Qt Creator core do not match well...
|
2013-08-29 17:17:24 +02:00
|
|
|
if (EditorManager::hasSplitter())
|
2010-09-08 15:57:19 +02:00
|
|
|
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
|
2013-08-06 21:35:06 +03:00
|
|
|
else
|
2013-08-29 17:17:24 +02:00
|
|
|
EditorManager::closeEditor(editor, !forced);
|
2009-06-15 15:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
|
|
|
|
|
{
|
2010-09-08 15:57:19 +02:00
|
|
|
triggerAction(Core::Constants::REMOVE_ALL_SPLITS);
|
2013-08-29 17:17:24 +02:00
|
|
|
EditorManager::closeAllEditors(!forced);
|
2009-06-15 15:14:16 +02:00
|
|
|
}
|
|
|
|
|
|
2009-01-28 22:03:51 +01:00
|
|
|
void FakeVimPluginPrivate::moveToMatchingParenthesis(bool *moved, bool *forward,
|
|
|
|
|
QTextCursor *cursor)
|
|
|
|
|
{
|
|
|
|
|
*moved = false;
|
|
|
|
|
|
|
|
|
|
bool undoFakeEOL = false;
|
|
|
|
|
if (cursor->atBlockEnd() && cursor->block().length() > 1) {
|
|
|
|
|
cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
|
|
|
|
|
undoFakeEOL = true;
|
|
|
|
|
}
|
2011-02-18 15:31:31 +01:00
|
|
|
TextBlockUserData::MatchType match
|
|
|
|
|
= TextBlockUserData::matchCursorForward(cursor);
|
|
|
|
|
if (match == TextBlockUserData::Match) {
|
2009-01-28 22:03:51 +01:00
|
|
|
*moved = true;
|
|
|
|
|
*forward = true;
|
2009-06-15 15:14:16 +02:00
|
|
|
} else {
|
2009-01-28 22:03:51 +01:00
|
|
|
if (undoFakeEOL)
|
|
|
|
|
cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1);
|
2011-02-18 15:31:31 +01:00
|
|
|
if (match == TextBlockUserData::NoMatch) {
|
2010-07-14 13:02:17 +02:00
|
|
|
// Backward matching is according to the character before the cursor.
|
2009-01-28 22:03:51 +01:00
|
|
|
bool undoMove = false;
|
|
|
|
|
if (!cursor->atBlockEnd()) {
|
|
|
|
|
cursor->movePosition(QTextCursor::Right, QTextCursor::KeepAnchor, 1);
|
|
|
|
|
undoMove = true;
|
|
|
|
|
}
|
2011-02-18 15:31:31 +01:00
|
|
|
match = TextBlockUserData::matchCursorBackward(cursor);
|
|
|
|
|
if (match == TextBlockUserData::Match) {
|
2009-01-28 22:03:51 +01:00
|
|
|
*moved = true;
|
|
|
|
|
*forward = false;
|
|
|
|
|
} else if (undoMove) {
|
|
|
|
|
cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2012-10-13 09:33:30 +02:00
|
|
|
void FakeVimPluginPrivate::indentRegion(int beginBlock, int endBlock,
|
2009-02-03 10:39:57 +01:00
|
|
|
QChar typedChar)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
|
|
|
|
|
2014-09-26 11:37:54 +02:00
|
|
|
TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget());
|
2009-02-03 10:39:57 +01:00
|
|
|
if (!bt)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-06-02 15:27:10 +02:00
|
|
|
TabSettings tabSettings;
|
2010-01-15 15:27:42 +01:00
|
|
|
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
|
|
|
|
|
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
|
2011-08-16 10:45:23 +02:00
|
|
|
tabSettings.m_tabPolicy = theFakeVimSetting(ConfigExpandTab)->value().toBool()
|
|
|
|
|
? TabSettings::SpacesOnlyTabPolicy : TabSettings::TabsOnlyTabPolicy;
|
2010-06-02 15:27:10 +02:00
|
|
|
|
|
|
|
|
QTextDocument *doc = bt->document();
|
2012-10-13 09:33:30 +02:00
|
|
|
QTextBlock startBlock = doc->findBlockByNumber(beginBlock);
|
2010-06-02 15:27:10 +02:00
|
|
|
|
|
|
|
|
// Record line lenghts for mark adjustments
|
2012-10-13 09:33:30 +02:00
|
|
|
QVector<int> lineLengths(endBlock - beginBlock + 1);
|
2010-06-02 15:27:10 +02:00
|
|
|
QTextBlock block = startBlock;
|
|
|
|
|
|
2012-10-13 09:33:30 +02:00
|
|
|
for (int i = beginBlock; i <= endBlock; ++i) {
|
|
|
|
|
lineLengths[i - beginBlock] = block.text().length();
|
2016-03-18 12:10:24 +01:00
|
|
|
if (typedChar.unicode() == 0 && block.text().simplified().isEmpty()) {
|
2010-01-05 18:42:26 +01:00
|
|
|
// clear empty lines
|
2010-06-02 15:27:10 +02:00
|
|
|
QTextCursor cursor(block);
|
2010-01-05 18:42:26 +01:00
|
|
|
while (!cursor.atBlockEnd())
|
|
|
|
|
cursor.deleteChar();
|
2009-02-03 10:39:57 +01:00
|
|
|
} else {
|
2014-08-01 23:31:56 +02:00
|
|
|
bt->textDocument()->indenter()->indentBlock(doc, block, typedChar, tabSettings);
|
2009-02-03 10:39:57 +01:00
|
|
|
}
|
2010-06-02 15:27:10 +02:00
|
|
|
block = block.next();
|
2010-01-05 18:42:26 +01:00
|
|
|
}
|
2009-02-03 10:39:57 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-31 11:44:18 +02:00
|
|
|
void FakeVimPluginPrivate::quitFakeVim()
|
2009-01-09 17:57:48 +01:00
|
|
|
{
|
2009-04-14 14:42:46 +02:00
|
|
|
theFakeVimSetting(ConfigUseFakeVim)->setValue(false);
|
2009-01-09 17:57:48 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-10 22:10:23 +02:00
|
|
|
void FakeVimPluginPrivate::resetCommandBuffer()
|
|
|
|
|
{
|
2012-10-20 18:48:37 +02:00
|
|
|
showCommandBuffer(QString(), -1, -1, 0, 0);
|
2012-09-10 22:10:23 +02:00
|
|
|
}
|
|
|
|
|
|
2016-05-24 23:09:11 +03:00
|
|
|
void FakeVimPluginPrivate::showCommandBuffer(const QString &contents, int cursorPos, int anchorPos,
|
|
|
|
|
int messageLevel, FakeVimHandler *eventFilter)
|
2008-12-19 12:20:04 +01:00
|
|
|
{
|
2009-03-30 16:54:25 +02:00
|
|
|
//qDebug() << "SHOW COMMAND BUFFER" << contents;
|
2011-07-15 13:22:38 +02:00
|
|
|
if (MiniBuffer *w = qobject_cast<MiniBuffer *>(m_statusBar->widget()))
|
2012-10-20 18:48:37 +02:00
|
|
|
w->setContents(contents, cursorPos, anchorPos, messageLevel, eventFilter);
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-23 15:12:04 +01:00
|
|
|
void FakeVimPluginPrivate::showExtraInformation(const QString &text)
|
2009-01-09 15:36:02 +01:00
|
|
|
{
|
2014-03-06 19:04:42 +01:00
|
|
|
EditorManager::splitSideBySide();
|
2016-03-18 12:10:24 +01:00
|
|
|
QString title = "stdout.txt";
|
2014-03-06 19:04:42 +01:00
|
|
|
IEditor *iedit = EditorManager::openEditorWithContents(Id(), &title, text.toUtf8());
|
|
|
|
|
EditorManager::activateEditor(iedit);
|
|
|
|
|
FakeVimHandler *handler = m_editorToHandler.value(iedit, 0);
|
2014-04-01 18:42:56 +02:00
|
|
|
QTC_ASSERT(handler, return);
|
2016-03-18 12:10:24 +01:00
|
|
|
handler->handleCommand("0");
|
2009-01-09 15:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-27 21:09:13 +02:00
|
|
|
void FakeVimPluginPrivate::changeSelection(const QList<QTextEdit::ExtraSelection> &selection)
|
2009-01-13 13:47:00 +01:00
|
|
|
{
|
2009-01-23 15:12:04 +01:00
|
|
|
if (FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender()))
|
2014-09-26 11:37:54 +02:00
|
|
|
if (TextEditorWidget *bt = qobject_cast<TextEditorWidget *>(handler->widget()))
|
|
|
|
|
bt->setExtraSelections(TextEditorWidget::FakeVimSelection, selection);
|
2009-01-13 13:47:00 +01:00
|
|
|
}
|
|
|
|
|
|
2012-09-27 21:09:13 +02:00
|
|
|
void FakeVimPluginPrivate::highlightMatches(const QString &needle)
|
|
|
|
|
{
|
2013-08-29 15:46:04 +02:00
|
|
|
foreach (IEditor *editor, EditorManager::visibleEditors()) {
|
2013-08-06 17:13:53 +02:00
|
|
|
QWidget *w = editor->widget();
|
2015-02-04 11:00:26 +02:00
|
|
|
IFindSupport *find = Aggregation::query<IFindSupport>(w);
|
2013-08-06 17:13:53 +02:00
|
|
|
if (find != 0)
|
2014-01-13 16:17:34 +01:00
|
|
|
find->highlightAll(needle, FindRegularExpression | FindCaseSensitively);
|
2013-08-06 17:13:53 +02:00
|
|
|
}
|
2012-09-27 21:09:13 +02:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:33:26 +02:00
|
|
|
int FakeVimPluginPrivate::currentFile() const
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2012-05-08 09:43:14 +02:00
|
|
|
IEditor *editor = EditorManager::currentEditor();
|
2013-07-05 16:00:19 +02:00
|
|
|
if (!editor)
|
|
|
|
|
return -1;
|
2014-05-07 16:25:04 +02:00
|
|
|
return DocumentModel::indexOfDocument(editor->document());
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:33:26 +02:00
|
|
|
void FakeVimPluginPrivate::switchToFile(int n)
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2014-06-13 16:21:25 +02:00
|
|
|
int size = DocumentModel::entryCount();
|
2010-07-14 14:33:26 +02:00
|
|
|
QTC_ASSERT(size, return);
|
|
|
|
|
n = n % size;
|
|
|
|
|
if (n < 0)
|
|
|
|
|
n += size;
|
2014-06-13 16:21:25 +02:00
|
|
|
EditorManager::activateEditorForEntry(DocumentModel::entries().at(n));
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2009-01-13 16:38:05 +01:00
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
ExCommandMap &FakeVimExCommandsWidget::exCommandMap()
|
2010-05-19 16:21:42 +02:00
|
|
|
{
|
|
|
|
|
return m_q->exCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
2015-04-27 12:29:55 +02:00
|
|
|
ExCommandMap &FakeVimExCommandsWidget::defaultExCommandMap()
|
2010-05-19 16:21:42 +02:00
|
|
|
{
|
|
|
|
|
return m_q->defaultExCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
2011-04-05 16:32:18 +02:00
|
|
|
UserCommandMap &FakeVimUserCommandsPage::userCommandMap()
|
|
|
|
|
{
|
|
|
|
|
return m_q->userCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
UserCommandMap &FakeVimUserCommandsPage::defaultUserCommandMap()
|
|
|
|
|
{
|
|
|
|
|
return m_q->defaultUserCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimPlugin
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
FakeVimPlugin::FakeVimPlugin()
|
|
|
|
|
: d(new FakeVimPluginPrivate(this))
|
|
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
FakeVimPlugin::~FakeVimPlugin()
|
|
|
|
|
{
|
|
|
|
|
delete d;
|
|
|
|
|
}
|
|
|
|
|
|
2009-01-23 15:12:04 +01:00
|
|
|
bool FakeVimPlugin::initialize(const QStringList &arguments, QString *errorMessage)
|
2009-01-13 16:38:05 +01:00
|
|
|
{
|
2009-07-13 18:55:11 +02:00
|
|
|
Q_UNUSED(arguments)
|
|
|
|
|
Q_UNUSED(errorMessage)
|
2009-01-23 15:12:04 +01:00
|
|
|
return d->initialize();
|
2009-01-13 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-13 13:36:47 +02:00
|
|
|
ExtensionSystem::IPlugin::ShutdownFlag FakeVimPlugin::aboutToShutdown()
|
2009-01-13 16:38:05 +01:00
|
|
|
{
|
2010-04-28 16:59:03 +02:00
|
|
|
d->aboutToShutdown();
|
2010-07-13 13:36:47 +02:00
|
|
|
return SynchronousShutdown;
|
2009-01-13 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPlugin::extensionsInitialized()
|
|
|
|
|
{
|
2012-08-21 19:58:39 +02:00
|
|
|
d->m_statusBar = new StatusBarWidget;
|
2012-07-20 17:00:49 +02:00
|
|
|
d->m_statusBar->setWidget(new MiniBuffer);
|
2013-03-22 14:11:19 +01:00
|
|
|
d->m_statusBar->setPosition(StatusBarWidget::LastLeftAligned);
|
2010-09-17 13:11:12 +02:00
|
|
|
addAutoReleasedObject(d->m_statusBar);
|
2009-01-13 16:38:05 +01:00
|
|
|
}
|
|
|
|
|
|
2012-10-08 06:57:32 +02:00
|
|
|
#ifdef WITH_TESTS
|
|
|
|
|
void FakeVimPlugin::setupTest(QString *title, FakeVimHandler **handler, QWidget **edit)
|
|
|
|
|
{
|
2012-12-09 22:09:33 +02:00
|
|
|
*title = QString::fromLatin1("test.cpp");
|
2015-02-04 11:00:26 +02:00
|
|
|
IEditor *iedit = EditorManager::openEditorWithContents(Id(), title);
|
|
|
|
|
EditorManager::activateEditor(iedit);
|
2012-10-08 06:57:32 +02:00
|
|
|
*edit = iedit->widget();
|
|
|
|
|
*handler = d->m_editorToHandler.value(iedit, 0);
|
2014-11-18 20:02:22 +01:00
|
|
|
(*handler)->setupWidget();
|
2016-03-18 12:10:24 +01:00
|
|
|
(*handler)->handleCommand("set startofline");
|
2012-11-01 14:52:07 +01:00
|
|
|
|
|
|
|
|
// *handler = 0;
|
|
|
|
|
// m_statusMessage.clear();
|
|
|
|
|
// m_statusData.clear();
|
|
|
|
|
// m_infoMessage.clear();
|
|
|
|
|
// if (m_textedit) {
|
|
|
|
|
// m_textedit->setPlainText(lines);
|
|
|
|
|
// QTextCursor tc = m_textedit->textCursor();
|
|
|
|
|
// tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
|
|
|
|
// m_textedit->setTextCursor(tc);
|
|
|
|
|
// m_textedit->setPlainText(lines);
|
|
|
|
|
// *handler = new FakeVimHandler(m_textedit);
|
|
|
|
|
// } else {
|
|
|
|
|
// m_plaintextedit->setPlainText(lines);
|
|
|
|
|
// QTextCursor tc = m_plaintextedit->textCursor();
|
|
|
|
|
// tc.movePosition(QTextCursor::Start, QTextCursor::MoveAnchor);
|
|
|
|
|
// m_plaintextedit->setTextCursor(tc);
|
|
|
|
|
// m_plaintextedit->setPlainText(lines);
|
|
|
|
|
// *handler = new FakeVimHandler(m_plaintextedit);
|
|
|
|
|
// }
|
|
|
|
|
|
2016-05-24 23:09:11 +03:00
|
|
|
// connect(*handler, &FakeVimHandler::commandBufferChanged,
|
|
|
|
|
// this, &FakeVimPlugin::changeStatusMessage);
|
|
|
|
|
// connect(*handler, &FakeVimHandler::extraInformationChanged,
|
|
|
|
|
// this, &FakeVimPlugin::changeExtraInformation);
|
|
|
|
|
// connect(*handler, &FakeVimHandler::statusDataChanged,
|
|
|
|
|
// this, &FakeVimPlugin::changeStatusData);
|
2012-11-01 14:52:07 +01:00
|
|
|
|
|
|
|
|
// QCOMPARE(EDITOR(toPlainText()), lines);
|
2016-03-18 12:10:24 +01:00
|
|
|
(*handler)->handleCommand("set iskeyword=@,48-57,_,192-255,a-z,A-Z");
|
2012-10-08 06:57:32 +02:00
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
|
2011-02-18 15:31:31 +01:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
#include "fakevimplugin.moc"
|