2009-02-25 09:15:00 +01:00
|
|
|
/**************************************************************************
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
|
|
|
|
** This file is part of Qt Creator
|
|
|
|
|
**
|
2010-03-05 11:25:49 +01:00
|
|
|
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-06-17 00:01:27 +10:00
|
|
|
** Contact: Nokia Corporation (qt-info@nokia.com)
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Commercial Usage
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Licensees holding valid Qt Commercial licenses may use this file in
|
|
|
|
|
** accordance with the Qt Commercial License Agreement provided with the
|
|
|
|
|
** Software or, alternatively, in accordance with the terms contained in
|
|
|
|
|
** a written agreement between you and Nokia.
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** GNU Lesser General Public License Usage
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** Alternatively, this file may be used under the terms of the GNU Lesser
|
|
|
|
|
** General Public License version 2.1 as published by the Free Software
|
|
|
|
|
** Foundation and appearing in the file LICENSE.LGPL included in the
|
|
|
|
|
** packaging of this file. Please review the following information to
|
|
|
|
|
** ensure the GNU Lesser General Public License version 2.1 requirements
|
|
|
|
|
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
** If you are unsure which license is appropriate for your use, please
|
2009-08-14 09:30:56 +02:00
|
|
|
** contact the sales department at http://qt.nokia.com/contact.
|
2008-12-19 12:20:04 +01:00
|
|
|
**
|
2009-02-25 09:15:00 +01:00
|
|
|
**************************************************************************/
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
#include "fakevimplugin.h"
|
|
|
|
|
|
2009-01-09 16:54:06 +01:00
|
|
|
#include "fakevimhandler.h"
|
2009-03-30 12:40:08 +02:00
|
|
|
#include "ui_fakevimoptions.h"
|
|
|
|
|
|
2009-01-13 13:39:31 +01:00
|
|
|
#include <coreplugin/actionmanager/actionmanager.h>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <coreplugin/actionmanager/actioncontainer.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
|
|
|
|
#include <coreplugin/actionmanager/command.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/coreconstants.h>
|
|
|
|
|
#include <coreplugin/editormanager/editormanager.h>
|
2010-01-22 13:56:50 +01:00
|
|
|
#include <coreplugin/editormanager/openeditorsmodel.h>
|
2009-01-15 15:27:14 +01:00
|
|
|
#include <coreplugin/filemanager.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/icore.h>
|
2009-01-15 15:27:14 +01:00
|
|
|
#include <coreplugin/ifile.h>
|
2009-03-30 12:40:08 +02:00
|
|
|
#include <coreplugin/dialogs/ioptionspage.h>
|
2010-03-10 11:21:56 +01:00
|
|
|
#include <coreplugin/actionmanager/commandmappings.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <coreplugin/messagemanager.h>
|
|
|
|
|
#include <coreplugin/uniqueidmanager.h>
|
|
|
|
|
|
|
|
|
|
#include <projectexplorer/projectexplorerconstants.h>
|
|
|
|
|
#include <projectexplorer/session.h>
|
|
|
|
|
|
2010-04-26 14:02:09 +02:00
|
|
|
#include <texteditor/basetextdocumentlayout.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <texteditor/basetexteditor.h>
|
|
|
|
|
#include <texteditor/basetextmark.h>
|
2009-03-25 14:52:13 +01:00
|
|
|
#include <texteditor/completionsupport.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <texteditor/texteditorconstants.h>
|
2009-01-09 17:31:20 +01:00
|
|
|
#include <texteditor/tabsettings.h>
|
|
|
|
|
#include <texteditor/texteditorsettings.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2010-01-21 17:23:31 +01:00
|
|
|
#include <find/findplugin.h>
|
2009-05-29 07:45:35 +10:00
|
|
|
#include <find/textfindconstants.h>
|
|
|
|
|
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <utils/qtcassert.h>
|
2009-03-30 12:40:08 +02:00
|
|
|
#include <utils/savedaction.h>
|
2010-03-02 17:51:40 +01:00
|
|
|
#include <utils/treewidgetcolumnstretcher.h>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2010-03-18 13:15:59 +01:00
|
|
|
#include <cppeditor/cppeditorconstants.h>
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
#include <cpptools/cpptoolsconstants.h>
|
|
|
|
|
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <QtCore/QDebug>
|
2010-05-18 14:48:12 +02:00
|
|
|
#include <QtCore/QFile>
|
2009-01-13 16:38:05 +01:00
|
|
|
#include <QtCore/QtPlugin>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <QtCore/QObject>
|
|
|
|
|
#include <QtCore/QSettings>
|
2009-11-24 15:05:02 +01:00
|
|
|
#include <QtCore/QTextStream>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2010-04-16 17:47:02 +02:00
|
|
|
#include <QtGui/QDesktopServices>
|
2009-01-09 15:36:02 +01:00
|
|
|
#include <QtGui/QMessageBox>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <QtGui/QPlainTextEdit>
|
2010-01-22 13:56:50 +01:00
|
|
|
#include <QtGui/QShortcut>
|
2008-12-19 12:20:04 +01:00
|
|
|
#include <QtGui/QTextBlock>
|
|
|
|
|
#include <QtGui/QTextCursor>
|
2009-01-13 17:41:23 +01:00
|
|
|
#include <QtGui/QTextEdit>
|
2010-03-18 10:59:06 +01:00
|
|
|
#include <QtGui/QTreeWidgetItem>
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
using namespace FakeVim::Internal;
|
|
|
|
|
using namespace TextEditor;
|
|
|
|
|
using namespace Core;
|
|
|
|
|
using namespace ProjectExplorer;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Constants {
|
|
|
|
|
|
2010-05-14 11:03:30 +02:00
|
|
|
const char * const INSTALL_HANDLER = "TextEditor.FakeVimHandler";
|
|
|
|
|
const char * const MINI_BUFFER = "TextEditor.FakeVimMiniBuffer";
|
|
|
|
|
const char * const INSTALL_KEY = "Alt+V,Alt+V";
|
|
|
|
|
const char * const SETTINGS_CATEGORY = "D.FakeVim";
|
|
|
|
|
const char * const SETTINGS_CATEGORY_FAKEVIM_ICON = ":/core/images/category_fakevim.png";
|
|
|
|
|
const char * const SETTINGS_ID = "A.General";
|
|
|
|
|
const char * const SETTINGS_EX_CMDS_ID = "B.ExCommands";
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
} // namespace Constants
|
|
|
|
|
} // namespace FakeVim
|
|
|
|
|
|
|
|
|
|
|
2009-03-30 12:40:08 +02:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimOptionPage
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
typedef QMap<QString, QRegExp> CommandMap;
|
2010-07-14 13:46:20 +02:00
|
|
|
typedef QLatin1String _;
|
2010-05-19 16:21:42 +02:00
|
|
|
|
2009-03-30 12:40:08 +02:00
|
|
|
class FakeVimOptionPage : public Core::IOptionsPage
|
|
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
FakeVimOptionPage() {}
|
|
|
|
|
|
|
|
|
|
// IOptionsPage
|
2010-07-14 13:46:20 +02:00
|
|
|
QString id() const { return _(Constants::SETTINGS_ID); }
|
2010-01-07 18:17:24 +01:00
|
|
|
QString displayName() const { return tr("General"); }
|
2010-07-14 13:46:20 +02:00
|
|
|
QString category() const { return _(Constants::SETTINGS_CATEGORY); }
|
2010-01-07 18:17:24 +01:00
|
|
|
QString displayCategory() const { return tr("FakeVim"); }
|
2010-07-14 13:46:20 +02:00
|
|
|
QIcon categoryIcon() const
|
|
|
|
|
{ return QIcon(_(Constants::SETTINGS_CATEGORY_FAKEVIM_ICON)); }
|
2009-03-30 12:40:08 +02:00
|
|
|
|
|
|
|
|
QWidget *createPage(QWidget *parent);
|
|
|
|
|
void apply() { m_group.apply(ICore::instance()->settings()); }
|
|
|
|
|
void finish() { m_group.finish(); }
|
2009-11-24 15:05:02 +01:00
|
|
|
virtual bool matches(const QString &) const;
|
2009-03-30 12:40:08 +02:00
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void copyTextEditorSettings();
|
|
|
|
|
void setQtStyle();
|
|
|
|
|
void setPlainStyle();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
friend class DebuggerPlugin;
|
|
|
|
|
Ui::FakeVimOptionPage m_ui;
|
2009-11-24 15:05:02 +01:00
|
|
|
QString m_searchKeywords;
|
2009-10-05 11:06:05 +02:00
|
|
|
Utils::SavedActionSet m_group;
|
2009-03-30 12:40:08 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QWidget *FakeVimOptionPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
|
|
|
|
QWidget *w = new QWidget(parent);
|
|
|
|
|
m_ui.setupUi(w);
|
|
|
|
|
|
|
|
|
|
m_group.clear();
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigUseFakeVim),
|
2010-03-26 11:53:49 +01:00
|
|
|
m_ui.checkBoxUseFakeVim);
|
2010-04-16 17:47:02 +02:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigReadVimRc),
|
|
|
|
|
m_ui.checkBoxReadVimRc);
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigExpandTab),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxExpandTab);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigHlSearch),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxHlSearch);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigShiftWidth),
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxShiftWidth);
|
2010-05-10 16:30:46 +02:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigShowMarks),
|
|
|
|
|
m_ui.checkBoxShowMarks);
|
2010-08-11 13:41:54 +02:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigExportSelection),
|
|
|
|
|
m_ui.checkBoxExportSelection);
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigSmartTab),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxSmartTab);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigStartOfLine),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxStartOfLine);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigTabStop),
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxTabStop);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigBackspace),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.lineEditBackspace);
|
2010-04-28 11:35:07 +02:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigIsKeyword),
|
|
|
|
|
m_ui.lineEditIsKeyword);
|
2009-03-30 12:40:08 +02:00
|
|
|
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigAutoIndent),
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxAutoIndent);
|
2010-01-29 22:49:55 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigSmartIndent),
|
2010-01-06 14:57:46 +01:00
|
|
|
m_ui.checkBoxSmartIndent);
|
2010-01-29 21:33:57 +01:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigIncSearch),
|
2009-06-02 11:56:58 +02:00
|
|
|
m_ui.checkBoxIncSearch);
|
2010-04-08 08:34:55 +02:00
|
|
|
m_group.insert(theFakeVimSetting(ConfigUseCoreSearch),
|
|
|
|
|
m_ui.checkBoxUseCoreSearch);
|
2009-03-30 12:40:08 +02:00
|
|
|
|
|
|
|
|
connect(m_ui.pushButtonCopyTextEditorSettings, SIGNAL(clicked()),
|
2009-03-30 13:59:47 +02:00
|
|
|
this, SLOT(copyTextEditorSettings()));
|
2009-03-30 12:40:08 +02:00
|
|
|
connect(m_ui.pushButtonSetQtStyle, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(setQtStyle()));
|
|
|
|
|
connect(m_ui.pushButtonSetPlainStyle, SIGNAL(clicked()),
|
|
|
|
|
this, SLOT(setPlainStyle()));
|
2009-11-24 15:05:02 +01:00
|
|
|
if (m_searchKeywords.isEmpty()) {
|
|
|
|
|
QTextStream(&m_searchKeywords)
|
2010-04-12 17:42:29 +02:00
|
|
|
<< ' ' << m_ui.checkBoxAutoIndent->text()
|
|
|
|
|
<< ' ' << m_ui.checkBoxExpandTab->text()
|
2010-05-10 16:30:46 +02:00
|
|
|
<< ' ' << m_ui.checkBoxShowMarks->text()
|
2010-04-12 17:42:29 +02:00
|
|
|
<< ' ' << m_ui.checkBoxSmartIndent->text()
|
|
|
|
|
<< ' ' << m_ui.checkBoxHlSearch->text()
|
|
|
|
|
<< ' ' << m_ui.checkBoxIncSearch->text()
|
|
|
|
|
<< ' ' << m_ui.checkBoxSmartTab->text()
|
|
|
|
|
<< ' ' << m_ui.checkBoxStartOfLine->text()
|
2010-01-07 16:32:30 +01:00
|
|
|
<< ' ' << m_ui.labelShiftWidth->text()
|
2010-04-12 17:42:29 +02:00
|
|
|
<< ' ' << m_ui.labelTabulator->text()
|
2010-01-07 16:32:30 +01:00
|
|
|
<< ' ' << m_ui.labelBackspace->text();
|
2009-11-24 15:05:02 +01:00
|
|
|
m_searchKeywords.remove(QLatin1Char('&'));
|
|
|
|
|
}
|
2009-03-30 12:40:08 +02:00
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimOptionPage::copyTextEditorSettings()
|
|
|
|
|
{
|
2010-01-29 21:33:57 +01:00
|
|
|
TextEditor::TabSettings ts =
|
2009-03-30 12:40:08 +02:00
|
|
|
TextEditor::TextEditorSettings::instance()->tabSettings();
|
2010-01-29 21:33:57 +01:00
|
|
|
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxExpandTab->setChecked(ts.m_spacesForTabs);
|
2010-04-12 17:42:29 +02:00
|
|
|
m_ui.spinBoxTabStop->setValue(ts.m_tabSize);
|
|
|
|
|
m_ui.spinBoxShiftWidth->setValue(ts.m_indentSize);
|
2009-03-30 12:40:08 +02:00
|
|
|
m_ui.checkBoxSmartTab->setChecked(ts.m_smartBackspace);
|
2010-01-06 14:57:46 +01:00
|
|
|
m_ui.checkBoxAutoIndent->setChecked(true);
|
|
|
|
|
m_ui.checkBoxSmartIndent->setChecked(ts.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);
|
2010-07-14 13:46:20 +02:00
|
|
|
m_ui.lineEditBackspace->setText(_("indent,eol,start"));
|
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);
|
2009-03-30 13:59:47 +02:00
|
|
|
m_ui.lineEditBackspace->setText(QString());
|
2009-03-30 12:40:08 +02:00
|
|
|
}
|
|
|
|
|
|
2009-11-24 15:05:02 +01:00
|
|
|
bool FakeVimOptionPage::matches(const QString &s) const
|
|
|
|
|
{
|
|
|
|
|
return m_searchKeywords.contains(s, Qt::CaseInsensitive);
|
|
|
|
|
}
|
|
|
|
|
|
2009-03-30 12:40:08 +02:00
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|
|
|
|
|
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
//
|
|
|
|
|
// FakeVimExCommandsPage
|
|
|
|
|
//
|
|
|
|
|
///////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
struct CommandItem
|
|
|
|
|
{
|
|
|
|
|
Command *m_cmd;
|
|
|
|
|
QString m_regex;
|
|
|
|
|
QTreeWidgetItem *m_item;
|
|
|
|
|
};
|
|
|
|
|
|
2010-07-14 13:46:20 +02:00
|
|
|
Q_DECLARE_METATYPE(CommandItem *);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
2010-03-10 11:21:56 +01:00
|
|
|
class FakeVimExCommandsPage : public Core::CommandMappings
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
|
|
public:
|
2010-05-19 16:21:42 +02:00
|
|
|
FakeVimExCommandsPage(FakeVimPluginPrivate *q) : m_q(q) {}
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
// IOptionsPage
|
2010-07-14 13:46:20 +02:00
|
|
|
QString id() const { return _(Constants::SETTINGS_EX_CMDS_ID); }
|
2010-01-22 13:56:50 +01:00
|
|
|
QString displayName() const { return tr("Ex Command Mapping"); }
|
2010-07-14 13:46:20 +02:00
|
|
|
QString category() const { return _(Constants::SETTINGS_CATEGORY); }
|
2010-01-22 13:56:50 +01:00
|
|
|
QString displayCategory() const { return tr("FakeVim"); }
|
2010-03-26 17:34:10 +01:00
|
|
|
QIcon categoryIcon() const { return QIcon(); } // TODO: Icon for FakeVim
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
QWidget *createPage(QWidget *parent);
|
|
|
|
|
void initialize();
|
2010-05-19 16:21:42 +02:00
|
|
|
CommandMap &exCommandMap();
|
|
|
|
|
CommandMap &defaultExCommandMap();
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
public slots:
|
|
|
|
|
void commandChanged(QTreeWidgetItem *current);
|
2010-03-10 11:21:56 +01:00
|
|
|
void targetIdentifierChanged();
|
|
|
|
|
void resetTargetIdentifier();
|
|
|
|
|
void removeTargetIdentifier();
|
2010-01-22 13:56:50 +01:00
|
|
|
void defaultAction();
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
void setRegex(const QString ®ex);
|
|
|
|
|
QList<CommandItem *> m_citems;
|
2010-05-19 16:21:42 +02:00
|
|
|
FakeVimPluginPrivate *m_q;
|
2010-01-22 13:56:50 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
QWidget *FakeVimExCommandsPage::createPage(QWidget *parent)
|
|
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
QWidget *w = CommandMappings::createPage(parent);
|
|
|
|
|
setPageTitle(tr("Ex Command Mapping"));
|
|
|
|
|
setTargetHeader(tr("Ex Trigger Expression"));
|
2010-04-14 18:00:59 +02:00
|
|
|
setTargetLabelText(tr("Regular expression:"));
|
2010-03-10 11:21:56 +01:00
|
|
|
setTargetEditTitle(tr("Ex Command"));
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2010-03-10 11:21:56 +01:00
|
|
|
setImportExportEnabled(false);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
return w;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimExCommandsPage::initialize()
|
|
|
|
|
{
|
|
|
|
|
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
|
|
|
|
QTC_ASSERT(am, return);
|
|
|
|
|
UniqueIDManager *uidm = UniqueIDManager::instance();
|
|
|
|
|
QTC_ASSERT(uidm, return);
|
|
|
|
|
|
2010-03-02 17:51:40 +01:00
|
|
|
QMap<QString, QTreeWidgetItem *> sections;
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
foreach (Command *c, am->commands()) {
|
|
|
|
|
if (c->action() && c->action()->isSeparator())
|
|
|
|
|
continue;
|
|
|
|
|
|
|
|
|
|
CommandItem *ci = new CommandItem;
|
2010-03-02 17:51:40 +01:00
|
|
|
QTreeWidgetItem *item = new QTreeWidgetItem;
|
2010-01-22 13:56:50 +01:00
|
|
|
ci->m_cmd = c;
|
|
|
|
|
ci->m_item = item;
|
2010-05-05 16:05:49 +02:00
|
|
|
m_citems.append(ci);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
const QString name = uidm->stringForUniqueIdentifier(c->id());
|
2010-03-02 17:51:40 +01:00
|
|
|
const int pos = name.indexOf(QLatin1Char('.'));
|
|
|
|
|
const QString section = name.left(pos);
|
2010-05-18 12:58:36 +02:00
|
|
|
const QString subId = name.mid(pos + 1);
|
2010-03-02 17:51:40 +01:00
|
|
|
|
|
|
|
|
if (!sections.contains(section)) {
|
2010-05-05 16:05:49 +02:00
|
|
|
QTreeWidgetItem *categoryItem =
|
|
|
|
|
new QTreeWidgetItem(commandList(), QStringList() << 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);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
if (c->action()) {
|
2010-05-05 16:05:49 +02:00
|
|
|
QString text = c->hasAttribute(Command::CA_UpdateText)
|
|
|
|
|
&& !c->defaultText().isNull()
|
|
|
|
|
? c->defaultText() : c->action()->text();
|
2010-01-22 13:56:50 +01:00
|
|
|
text.remove(QRegExp("&(?!&)"));
|
|
|
|
|
item->setText(1, text);
|
|
|
|
|
} else {
|
|
|
|
|
item->setText(1, c->shortcut()->whatsThis());
|
|
|
|
|
}
|
2010-05-19 16:21:42 +02:00
|
|
|
if (exCommandMap().contains(name)) {
|
|
|
|
|
ci->m_regex = exCommandMap()[name].pattern();
|
2010-01-22 13:56:50 +01:00
|
|
|
} else {
|
2010-01-22 16:51:04 +01:00
|
|
|
ci->m_regex.clear();
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
item->setText(2, ci->m_regex);
|
|
|
|
|
item->setData(0, Qt::UserRole, qVariantFromValue(ci));
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
if (ci->m_regex != defaultExCommandMap()[name].pattern())
|
2010-03-29 14:42:46 +02:00
|
|
|
setModified(item, true);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
commandChanged(0);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimExCommandsPage::commandChanged(QTreeWidgetItem *current)
|
|
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
CommandMappings::commandChanged(current);
|
|
|
|
|
|
|
|
|
|
if (!current || !current->data(0, Qt::UserRole).isValid())
|
2010-01-22 13:56:50 +01:00
|
|
|
return;
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
CommandItem *citem = qVariantValue<CommandItem *>(current->data(0, Qt::UserRole));
|
2010-03-10 11:21:56 +01:00
|
|
|
targetEdit()->setText(citem->m_regex);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 11:21:56 +01:00
|
|
|
void FakeVimExCommandsPage::targetIdentifierChanged()
|
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;
|
|
|
|
|
|
|
|
|
|
UniqueIDManager *uidm = UniqueIDManager::instance();
|
|
|
|
|
CommandItem *citem = qVariantValue<CommandItem *>(current->data(0, Qt::UserRole));
|
|
|
|
|
const QString name = uidm->stringForUniqueIdentifier(citem->m_cmd->id());
|
|
|
|
|
|
|
|
|
|
if (current->data(0, Qt::UserRole).isValid()) {
|
2010-03-10 11:21:56 +01:00
|
|
|
citem->m_regex = targetEdit()->text();
|
2010-01-22 13:56:50 +01:00
|
|
|
current->setText(2, citem->m_regex);
|
2010-05-19 16:21:42 +02:00
|
|
|
exCommandMap()[name] = QRegExp(citem->m_regex);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
if (citem->m_regex != defaultExCommandMap()[name].pattern())
|
2010-03-29 14:42:46 +02:00
|
|
|
setModified(current, true);
|
|
|
|
|
else
|
|
|
|
|
setModified(current, false);
|
2010-03-04 19:22:06 +01:00
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimExCommandsPage::setRegex(const QString ®ex)
|
|
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
targetEdit()->setText(regex);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
2010-03-10 11:21:56 +01:00
|
|
|
void FakeVimExCommandsPage::resetTargetIdentifier()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
|
|
|
|
UniqueIDManager *uidm = UniqueIDManager::instance();
|
2010-03-10 11:21:56 +01:00
|
|
|
QTreeWidgetItem *current = commandList()->currentItem();
|
2010-01-22 13:56:50 +01:00
|
|
|
if (current && current->data(0, Qt::UserRole).isValid()) {
|
|
|
|
|
CommandItem *citem = qVariantValue<CommandItem *>(current->data(0, Qt::UserRole));
|
|
|
|
|
const QString &name = uidm->stringForUniqueIdentifier(citem->m_cmd->id());
|
2010-05-19 16:21:42 +02:00
|
|
|
if (defaultExCommandMap().contains(name))
|
|
|
|
|
setRegex(defaultExCommandMap()[name].pattern());
|
2010-01-22 13:56:50 +01:00
|
|
|
else
|
2010-01-22 16:51:04 +01:00
|
|
|
setRegex(QString());
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-03-10 11:21:56 +01:00
|
|
|
void FakeVimExCommandsPage::removeTargetIdentifier()
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2010-03-10 11:21:56 +01:00
|
|
|
targetEdit()->clear();
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimExCommandsPage::defaultAction()
|
|
|
|
|
{
|
|
|
|
|
UniqueIDManager *uidm = UniqueIDManager::instance();
|
|
|
|
|
foreach (CommandItem *item, m_citems) {
|
|
|
|
|
const QString &name = uidm->stringForUniqueIdentifier(item->m_cmd->id());
|
2010-05-19 16:21:42 +02:00
|
|
|
if (defaultExCommandMap().contains(name)) {
|
|
|
|
|
item->m_regex = defaultExCommandMap()[name].pattern();
|
2010-01-22 13:56:50 +01:00
|
|
|
} else {
|
2010-01-22 16:51:04 +01:00
|
|
|
item->m_regex.clear();
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2010-03-29 14:42:46 +02:00
|
|
|
setModified(item->m_item, false);
|
2010-01-22 13:56:50 +01:00
|
|
|
item->m_item->setText(2, item->m_regex);
|
2010-03-10 11:21:56 +01:00
|
|
|
if (item->m_item == commandList()->currentItem())
|
2010-01-22 13:56:50 +01:00
|
|
|
commandChanged(item->m_item);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|
|
|
|
|
|
|
|
|
|
|
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
|
|
|
namespace FakeVim {
|
|
|
|
|
namespace Internal {
|
|
|
|
|
|
|
|
|
|
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 *);
|
|
|
|
|
~FakeVimPluginPrivate();
|
|
|
|
|
friend class FakeVimPlugin;
|
2010-05-19 16:21:42 +02:00
|
|
|
friend class FakeVimExCommandsPage;
|
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
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
|
void editorOpened(Core::IEditor *);
|
|
|
|
|
void editorAboutToClose(Core::IEditor *);
|
2009-01-23 15:12:04 +01:00
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
void setUseFakeVim(const QVariant &value);
|
2009-03-31 11:44:18 +02:00
|
|
|
void quitFakeVim();
|
2009-03-25 13:31:30 +01:00
|
|
|
void triggerCompletions();
|
2009-04-03 16:33:28 +02:00
|
|
|
void windowCommand(int key);
|
2009-05-29 07:45:35 +10:00
|
|
|
void find(bool reverse);
|
2009-05-29 11:34:11 +10:00
|
|
|
void findNext(bool reverse);
|
2009-03-30 14:20:46 +02:00
|
|
|
void showSettingsDialog();
|
2010-04-16 17:47:02 +02:00
|
|
|
void maybeReadVimRc();
|
2009-01-23 15:12:04 +01:00
|
|
|
|
|
|
|
|
void showCommandBuffer(const QString &contents);
|
|
|
|
|
void showExtraInformation(const QString &msg);
|
|
|
|
|
void changeSelection(const QList<QTextEdit::ExtraSelection> &selections);
|
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);
|
2010-06-02 15:27:10 +02:00
|
|
|
void indentRegion(int beginLine, int endLine, 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
|
|
|
|
|
|
|
|
void handleDelayedQuitAll(bool forced);
|
|
|
|
|
void handleDelayedQuit(bool forced, Core::IEditor *editor);
|
|
|
|
|
|
2010-07-14 14:33:26 +02:00
|
|
|
void switchToFile(int n);
|
|
|
|
|
int currentFile() const;
|
2010-01-22 13:56:50 +01:00
|
|
|
|
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;
|
2009-03-30 13:59:47 +02:00
|
|
|
FakeVimOptionPage *m_fakeVimOptionsPage;
|
2010-01-22 13:56:50 +01:00
|
|
|
FakeVimExCommandsPage *m_fakeVimExCommandsPage;
|
2009-03-30 16:54:25 +02:00
|
|
|
QHash<Core::IEditor *, FakeVimHandler *> m_editorToHandler;
|
2010-07-14 13:46:20 +02:00
|
|
|
QPointer<EditorManager> m_editorManager;
|
|
|
|
|
EditorManager *editorManager() const { return m_editorManager; }
|
2009-05-29 07:45:35 +10:00
|
|
|
|
2010-05-06 14:46:08 +02:00
|
|
|
void triggerAction(const QString &code);
|
|
|
|
|
void setActionChecked(const QString &code, bool check);
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
void readSettings(QSettings *settings);
|
|
|
|
|
void writeSettings(QSettings *settings);
|
2010-05-19 16:21:42 +02:00
|
|
|
|
|
|
|
|
CommandMap &exCommandMap() { return m_exCommandMap; }
|
|
|
|
|
CommandMap &defaultExCommandMap() { return m_exCommandMap; }
|
|
|
|
|
CommandMap m_exCommandMap;
|
|
|
|
|
CommandMap m_defaultExCommandMap;
|
2009-01-13 16:38:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
} // namespace Internal
|
|
|
|
|
} // namespace FakeVim
|
|
|
|
|
|
|
|
|
|
FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
|
2010-01-29 21:33:57 +01:00
|
|
|
{
|
2009-01-13 16:38:05 +01:00
|
|
|
q = plugin;
|
2009-03-30 13:59:47 +02:00
|
|
|
m_fakeVimOptionsPage = 0;
|
2010-01-22 13:56:50 +01:00
|
|
|
m_fakeVimExCommandsPage = 0;
|
2010-05-19 16:21:42 +02:00
|
|
|
defaultExCommandMap()[CppTools::Constants::SWITCH_HEADER_SOURCE] =
|
2010-04-16 17:47:02 +02:00
|
|
|
QRegExp("^A$");
|
2010-05-19 16:21:42 +02:00
|
|
|
defaultExCommandMap()["Coreplugin.OutputPane.previtem"] =
|
2010-04-16 17:47:02 +02:00
|
|
|
QRegExp("^(cN(ext)?|cp(revious)?)!?( (.*))?$");
|
2010-05-19 16:21:42 +02:00
|
|
|
defaultExCommandMap()["Coreplugin.OutputPane.nextitem"] =
|
2010-04-16 17:47:02 +02:00
|
|
|
QRegExp("^cn(ext)?!?( (.*))?$");
|
2010-05-19 16:21:42 +02:00
|
|
|
defaultExCommandMap()[CppEditor::Constants::JUMP_TO_DEFINITION] =
|
2010-04-16 17:47:02 +02:00
|
|
|
QRegExp("^tag?$");
|
2010-05-19 16:21:42 +02:00
|
|
|
defaultExCommandMap()[Core::Constants::GO_BACK] =
|
2010-04-16 17:47:02 +02:00
|
|
|
QRegExp("^pop?$");
|
2010-07-14 13:46:20 +02:00
|
|
|
defaultExCommandMap()[_("QtCreator.Locate")] =
|
2010-05-06 14:46:08 +02:00
|
|
|
QRegExp("^e$");
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
FakeVimPluginPrivate::~FakeVimPluginPrivate()
|
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;
|
2009-06-03 13:53:45 +02:00
|
|
|
delete theFakeVimSettings();
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
q->removeObject(m_fakeVimExCommandsPage);
|
|
|
|
|
delete m_fakeVimExCommandsPage;
|
|
|
|
|
m_fakeVimExCommandsPage = 0;
|
2010-04-29 13:38:32 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::aboutToShutdown()
|
|
|
|
|
{
|
|
|
|
|
theFakeVimSettings()->writeSettings(Core::ICore::instance()->settings());
|
2010-01-22 13:56:50 +01:00
|
|
|
writeSettings(Core::ICore::instance()->settings());
|
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
|
|
|
{
|
2010-07-14 13:46:20 +02:00
|
|
|
m_editorManager = Core::ICore::instance()->editorManager();
|
2009-01-28 12:44:46 +01:00
|
|
|
Core::ActionManager *actionManager = Core::ICore::instance()->actionManager();
|
2008-12-19 12:20:04 +01:00
|
|
|
QTC_ASSERT(actionManager, return false);
|
|
|
|
|
|
2010-06-28 14:30:03 +02:00
|
|
|
Core::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);
|
|
|
|
|
theFakeVimSettings()->readSettings(Core::ICore::instance()->settings());
|
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);
|
|
|
|
|
readSettings(Core::ICore::instance()->settings());
|
2010-01-29 22:49:55 +01:00
|
|
|
|
2009-01-14 13:17:53 +01:00
|
|
|
Core::Command *cmd = 0;
|
2009-03-30 16:54:25 +02:00
|
|
|
cmd = actionManager->registerAction(theFakeVimSetting(ConfigUseFakeVim),
|
2008-12-19 12:20:04 +01:00
|
|
|
Constants::INSTALL_HANDLER, globalcontext);
|
|
|
|
|
cmd->setDefaultKeySequence(QKeySequence(Constants::INSTALL_KEY));
|
|
|
|
|
|
2009-01-14 12:39:59 +01:00
|
|
|
ActionContainer *advancedMenu =
|
2008-12-19 12:20:04 +01:00
|
|
|
actionManager->actionContainer(Core::Constants::M_EDIT_ADVANCED);
|
2009-01-20 09:48:50 +01:00
|
|
|
advancedMenu->addAction(cmd, Core::Constants::G_EDIT_EDITOR);
|
2008-12-19 12:20:04 +01:00
|
|
|
|
2009-01-09 17:57:48 +01:00
|
|
|
// EditorManager
|
2010-07-14 13:46:20 +02:00
|
|
|
connect(editorManager(), SIGNAL(editorAboutToClose(Core::IEditor*)),
|
2009-01-09 17:57:48 +01:00
|
|
|
this, SLOT(editorAboutToClose(Core::IEditor*)));
|
2010-07-14 13:46:20 +02:00
|
|
|
connect(editorManager(), SIGNAL(editorOpened(Core::IEditor*)),
|
2009-01-09 17:57:48 +01:00
|
|
|
this, SLOT(editorOpened(Core::IEditor*)));
|
|
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
connect(theFakeVimSetting(ConfigUseFakeVim), SIGNAL(valueChanged(QVariant)),
|
|
|
|
|
this, SLOT(setUseFakeVim(QVariant)));
|
2010-04-16 17:47:02 +02:00
|
|
|
connect(theFakeVimSetting(ConfigReadVimRc), SIGNAL(valueChanged(QVariant)),
|
|
|
|
|
this, SLOT(maybeReadVimRc()));
|
2009-03-30 14:20:46 +02:00
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
// Delayed operations.
|
2009-06-15 15:14:16 +02:00
|
|
|
connect(this, SIGNAL(delayedQuitRequested(bool,Core::IEditor*)),
|
|
|
|
|
this, SLOT(handleDelayedQuit(bool,Core::IEditor*)), Qt::QueuedConnection);
|
|
|
|
|
connect(this, SIGNAL(delayedQuitAllRequested(bool)),
|
|
|
|
|
this, SLOT(handleDelayedQuitAll(bool)), Qt::QueuedConnection);
|
2010-04-16 17:47:02 +02:00
|
|
|
maybeReadVimRc();
|
|
|
|
|
// << "MODE: " << theFakeVimSetting(ConfigUseFakeVim)->value();
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2008-12-19 12:20:04 +01:00
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
static const char *exCommandMapGroup = "FakeVimExCommand";
|
|
|
|
|
static const char *reKey = "RegEx";
|
|
|
|
|
static const char *idKey = "Command";
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::writeSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-07-14 13:46:20 +02:00
|
|
|
settings->beginWriteArray(_(exCommandMapGroup));
|
2010-01-22 13:56:50 +01:00
|
|
|
|
|
|
|
|
int count = 0;
|
2010-05-19 16:21:42 +02:00
|
|
|
typedef CommandMap::const_iterator Iterator;
|
|
|
|
|
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();
|
|
|
|
|
const QRegExp &re = it.value();
|
|
|
|
|
|
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);
|
2010-07-14 13:46:20 +02:00
|
|
|
settings->setValue(_(idKey), id);
|
|
|
|
|
settings->setValue(_(reKey), re.pattern());
|
2010-01-22 13:56:50 +01:00
|
|
|
++count;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
settings->endArray();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::readSettings(QSettings *settings)
|
|
|
|
|
{
|
2010-05-19 16:21:42 +02:00
|
|
|
exCommandMap() = defaultExCommandMap();
|
2010-01-22 13:56:50 +01:00
|
|
|
|
2010-07-14 13:46:20 +02: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);
|
2010-07-14 13:46:20 +02: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
|
|
|
}
|
|
|
|
|
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;
|
|
|
|
|
QString fileName =
|
|
|
|
|
QDesktopServices::storageLocation(QDesktopServices::HomeLocation)
|
|
|
|
|
+ "/.vimrc";
|
|
|
|
|
//qDebug() << "READING VIMRC: " << fileName;
|
|
|
|
|
// Read it into a temporary handler for effects modifying global state.
|
|
|
|
|
QPlainTextEdit editor;
|
|
|
|
|
FakeVimHandler handler(&editor);
|
|
|
|
|
handler.handleCommand("source " + fileName);
|
|
|
|
|
theFakeVimSettings()->writeSettings(Core::ICore::instance()->settings());
|
2010-04-19 09:56:47 +02:00
|
|
|
//qDebug() << theFakeVimSetting(ConfigShiftWidth)->value();
|
2010-04-16 17:47:02 +02:00
|
|
|
}
|
|
|
|
|
|
2009-03-30 14:20:46 +02:00
|
|
|
void FakeVimPluginPrivate::showSettingsDialog()
|
|
|
|
|
{
|
2010-04-16 17:47:02 +02:00
|
|
|
Core::ICore::instance()->showOptionsDialog(
|
2010-07-14 13:46:20 +02:00
|
|
|
_(Constants::SETTINGS_CATEGORY),
|
|
|
|
|
_(Constants::SETTINGS_ID));
|
2009-03-30 14:20:46 +02:00
|
|
|
}
|
|
|
|
|
|
2010-05-06 14:46:08 +02:00
|
|
|
void FakeVimPluginPrivate::triggerAction(const QString &code)
|
2009-05-29 07:45:35 +10:00
|
|
|
{
|
|
|
|
|
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
|
|
|
|
QTC_ASSERT(am, return);
|
|
|
|
|
Core::Command *cmd = am->command(code);
|
2010-05-10 13:01:18 +02:00
|
|
|
QTC_ASSERT(cmd, qDebug() << "UNKNOW CODE: " << code; return);
|
2009-05-29 07:45:35 +10:00
|
|
|
QAction *action = cmd->action();
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
action->trigger();
|
|
|
|
|
}
|
|
|
|
|
|
2010-05-06 14:46:08 +02:00
|
|
|
void FakeVimPluginPrivate::setActionChecked(const QString &code, bool check)
|
2010-01-21 17:23:32 +01:00
|
|
|
{
|
|
|
|
|
Core::ActionManager *am = Core::ICore::instance()->actionManager();
|
|
|
|
|
QTC_ASSERT(am, return);
|
|
|
|
|
Core::Command *cmd = am->command(code);
|
|
|
|
|
QTC_ASSERT(cmd, return);
|
|
|
|
|
QAction *action = cmd->action();
|
|
|
|
|
QTC_ASSERT(action, return);
|
|
|
|
|
QTC_ASSERT(action->isCheckable(), return);
|
|
|
|
|
action->setChecked(check);
|
|
|
|
|
action->trigger();
|
|
|
|
|
}
|
|
|
|
|
|
2009-04-03 16:33:28 +02:00
|
|
|
void FakeVimPluginPrivate::windowCommand(int key)
|
|
|
|
|
{
|
2010-06-10 13:12:12 +02:00
|
|
|
# define control(n) (256 + n)
|
2009-04-03 16:33:28 +02:00
|
|
|
QString code;
|
|
|
|
|
switch (key) {
|
|
|
|
|
case 'c': case 'C': case control('c'):
|
|
|
|
|
code = Core::Constants::CLOSE;
|
|
|
|
|
break;
|
|
|
|
|
case 'n': case 'N': case control('n'):
|
|
|
|
|
code = Core::Constants::GOTONEXT;
|
|
|
|
|
break;
|
|
|
|
|
case 'o': case 'O': case control('o'):
|
|
|
|
|
code = Core::Constants::REMOVE_ALL_SPLITS;
|
|
|
|
|
code = Core::Constants::REMOVE_CURRENT_SPLIT;
|
|
|
|
|
break;
|
|
|
|
|
case 'p': case 'P': case control('p'):
|
|
|
|
|
code = Core::Constants::GOTOPREV;
|
|
|
|
|
break;
|
|
|
|
|
case 's': case 'S': case control('s'):
|
|
|
|
|
code = Core::Constants::SPLIT;
|
|
|
|
|
break;
|
|
|
|
|
case 'w': case 'W': case control('w'):
|
|
|
|
|
code = Core::Constants::GOTO_OTHER_SPLIT;
|
|
|
|
|
break;
|
|
|
|
|
}
|
2010-06-10 13:12:12 +02:00
|
|
|
# undef control
|
2010-04-06 15:07:22 +02:00
|
|
|
//qDebug() << "RUNNING WINDOW COMMAND: " << key << code;
|
2009-04-03 16:33:28 +02:00
|
|
|
if (code.isEmpty()) {
|
2010-04-06 15:07:22 +02:00
|
|
|
//qDebug() << "UNKNOWN WINDOWS COMMAND: " << key;
|
2009-04-03 16:33:28 +02:00
|
|
|
return;
|
|
|
|
|
}
|
2009-05-29 07:45:35 +10:00
|
|
|
triggerAction(code);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::find(bool reverse)
|
|
|
|
|
{
|
2010-03-24 10:43:01 +01:00
|
|
|
if (Find::FindPlugin *plugin = Find::FindPlugin::instance()) {
|
2010-01-21 17:23:31 +01:00
|
|
|
plugin->setUseFakeVim(true);
|
|
|
|
|
plugin->openFindToolBar(reverse
|
2010-03-24 10:43:01 +01:00
|
|
|
? Find::FindPlugin::FindBackward
|
|
|
|
|
: Find::FindPlugin::FindForward);
|
2010-01-21 17:23:31 +01:00
|
|
|
}
|
2009-04-03 16:33:28 +02:00
|
|
|
}
|
|
|
|
|
|
2009-05-29 11:34:11 +10:00
|
|
|
void FakeVimPluginPrivate::findNext(bool reverse)
|
|
|
|
|
{
|
|
|
|
|
if (reverse)
|
|
|
|
|
triggerAction(Find::Constants::FIND_PREVIOUS);
|
|
|
|
|
else
|
|
|
|
|
triggerAction(Find::Constants::FIND_NEXT);
|
|
|
|
|
}
|
|
|
|
|
|
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
|
|
|
{}
|
|
|
|
|
|
|
|
|
|
virtual ~DeferredDeleter()
|
|
|
|
|
{
|
|
|
|
|
if (m_handler) {
|
|
|
|
|
m_handler->disconnectFromEditor();
|
|
|
|
|
m_handler->deleteLater();
|
|
|
|
|
m_handler = 0;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
void FakeVimPluginPrivate::editorOpened(Core::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();
|
|
|
|
|
|
2010-01-22 13:56:50 +01:00
|
|
|
FakeVimHandler *handler = new FakeVimHandler(widget, 0);
|
|
|
|
|
// 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
|
|
|
|
|
|
|
|
connect(handler, SIGNAL(extraInformationChanged(QString)),
|
|
|
|
|
this, SLOT(showExtraInformation(QString)));
|
|
|
|
|
connect(handler, SIGNAL(commandBufferChanged(QString)),
|
2008-12-19 12:20:04 +01:00
|
|
|
this, SLOT(showCommandBuffer(QString)));
|
2009-01-23 15:12:04 +01:00
|
|
|
connect(handler, SIGNAL(selectionChanged(QList<QTextEdit::ExtraSelection>)),
|
|
|
|
|
this, SLOT(changeSelection(QList<QTextEdit::ExtraSelection>)));
|
2009-01-28 22:03:51 +01:00
|
|
|
connect(handler, SIGNAL(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)),
|
|
|
|
|
this, SLOT(moveToMatchingParenthesis(bool*,bool*,QTextCursor*)));
|
2010-06-02 15:27:10 +02:00
|
|
|
connect(handler, SIGNAL(indentRegion(int,int,QChar)),
|
|
|
|
|
this, SLOT(indentRegion(int,int,QChar)));
|
2010-01-06 14:57:46 +01:00
|
|
|
connect(handler, SIGNAL(checkForElectricCharacter(bool*,QChar)),
|
|
|
|
|
this, SLOT(checkForElectricCharacter(bool*,QChar)));
|
2009-03-25 13:31:30 +01:00
|
|
|
connect(handler, SIGNAL(completionRequested()),
|
|
|
|
|
this, SLOT(triggerCompletions()));
|
2009-04-03 16:33:28 +02:00
|
|
|
connect(handler, SIGNAL(windowCommandRequested(int)),
|
|
|
|
|
this, SLOT(windowCommand(int)));
|
2009-05-29 07:45:35 +10:00
|
|
|
connect(handler, SIGNAL(findRequested(bool)),
|
|
|
|
|
this, SLOT(find(bool)));
|
2009-05-29 11:34:11 +10:00
|
|
|
connect(handler, SIGNAL(findNextRequested(bool)),
|
|
|
|
|
this, SLOT(findNext(bool)));
|
2009-01-23 15:12:04 +01:00
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
connect(handler, SIGNAL(handleExCommandRequested(bool*,ExCommand)),
|
|
|
|
|
this, SLOT(handleExCommand(bool*,ExCommand)));
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2009-03-30 13:59:47 +02:00
|
|
|
handler->setCurrentFileName(editor->file()->fileName());
|
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()) {
|
2010-01-22 16:51:04 +01:00
|
|
|
showCommandBuffer(QString());
|
2010-04-07 18:08:09 +02:00
|
|
|
handler->setupWidget();
|
|
|
|
|
}
|
2008-12-19 12:20:04 +01:00
|
|
|
}
|
|
|
|
|
|
2009-03-30 16:54:25 +02:00
|
|
|
void FakeVimPluginPrivate::editorAboutToClose(Core::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);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
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();
|
2010-03-24 10:43:01 +01:00
|
|
|
if (Find::FindPlugin::instance())
|
|
|
|
|
Find::FindPlugin::instance()->setUseFakeVim(on);
|
2009-03-30 16:54:25 +02:00
|
|
|
if (on) {
|
2010-07-14 13:46:20 +02:00
|
|
|
editorManager()->showEditorStatusBar(
|
|
|
|
|
_(Constants::MINI_BUFFER),
|
2009-03-30 16:54:25 +02:00
|
|
|
"vi emulation mode. Type :q to leave. Use , Ctrl-R to trigger run.",
|
2009-03-31 11:44:18 +02:00
|
|
|
tr("Quit FakeVim"), this, SLOT(quitFakeVim()));
|
2009-03-30 16:54:25 +02:00
|
|
|
foreach (Core::IEditor *editor, m_editorToHandler.keys())
|
|
|
|
|
m_editorToHandler[editor]->setupWidget();
|
|
|
|
|
} else {
|
2010-07-14 13:46:20 +02:00
|
|
|
editorManager()->hideEditorStatusBar(
|
|
|
|
|
_(Constants::MINI_BUFFER));
|
2010-03-26 17:55:43 +01:00
|
|
|
TextEditor::TabSettings ts =
|
|
|
|
|
TextEditor::TextEditorSettings::instance()->tabSettings();
|
2009-03-30 16:54:25 +02:00
|
|
|
foreach (Core::IEditor *editor, m_editorToHandler.keys())
|
2010-03-26 17:55:43 +01:00
|
|
|
m_editorToHandler[editor]->restoreWidget(ts.m_tabSize);
|
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;
|
|
|
|
|
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget()))
|
2009-03-25 14:52:13 +01:00
|
|
|
TextEditor::Internal::CompletionSupport::instance()->
|
|
|
|
|
autoComplete(bt->editableInterface(), false);
|
|
|
|
|
// bt->triggerCompletions();
|
2009-03-25 13:31:30 +01:00
|
|
|
}
|
|
|
|
|
|
2010-01-06 14:57:46 +01:00
|
|
|
void FakeVimPluginPrivate::checkForElectricCharacter(bool *result, QChar c)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
|
|
|
|
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget()))
|
|
|
|
|
*result = bt->isElectricCharacter(c);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
|
2010-07-14 13:46:20 +02:00
|
|
|
QTC_ASSERT(editorManager(), return);
|
2009-06-15 15:14:16 +02:00
|
|
|
|
2010-05-18 14:48:12 +02:00
|
|
|
*handled = true;
|
2010-07-14 18:15:17 +02:00
|
|
|
if (cmd.matches("w", "write")) {
|
|
|
|
|
// :w[rite]
|
2010-05-18 14:48:12 +02:00
|
|
|
Core::IEditor *editor = m_editorToHandler.key(handler);
|
|
|
|
|
const QString fileName = handler->currentFileName();
|
|
|
|
|
if (editor && editor->file()->fileName() == fileName) {
|
|
|
|
|
// Handle that as a special case for nicer interaction with core
|
|
|
|
|
Core::IFile *file = editor->file();
|
|
|
|
|
Core::ICore::instance()->fileManager()->blockFileChange(file);
|
|
|
|
|
file->save(fileName);
|
|
|
|
|
Core::ICore::instance()->fileManager()->unblockFileChange(file);
|
|
|
|
|
// Check result by reading back.
|
|
|
|
|
QFile file3(fileName);
|
|
|
|
|
file3.open(QIODevice::ReadOnly);
|
|
|
|
|
QByteArray ba = file3.readAll();
|
|
|
|
|
handler->showBlackMessage(FakeVimHandler::tr("\"%1\" %2 %3L, %4C written")
|
|
|
|
|
.arg(fileName).arg(" ")
|
|
|
|
|
.arg(ba.count('\n')).arg(ba.size()));
|
|
|
|
|
} else {
|
|
|
|
|
handler->showRedMessage(tr("File not saved"));
|
|
|
|
|
}
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("wa", "wall")) {
|
|
|
|
|
// :w[all]
|
2009-06-15 15:14:16 +02:00
|
|
|
FileManager *fm = ICore::instance()->fileManager();
|
|
|
|
|
QList<IFile *> toSave = fm->modifiedFiles();
|
|
|
|
|
QList<IFile *> failed = fm->saveModifiedFilesSilently(toSave);
|
|
|
|
|
if (failed.isEmpty())
|
|
|
|
|
handler->showBlackMessage(tr("Saving succeeded"));
|
|
|
|
|
else
|
2009-07-31 16:41:12 +02:00
|
|
|
handler->showRedMessage(tr("%n files not saved", 0, failed.size()));
|
2010-07-14 18:15:17 +02: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));
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("qa", "qall")) {
|
|
|
|
|
// :qa[ll]
|
2010-05-18 14:48:12 +02:00
|
|
|
emit delayedQuitAllRequested(cmd.hasBang);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("sp", "split")) {
|
2010-05-05 16:05:49 +02:00
|
|
|
// :sp[lit]
|
|
|
|
|
triggerAction(Core::Constants::SPLIT);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("vs", "vsplit")) {
|
2010-05-05 16:05:49 +02:00
|
|
|
// :vs[plit]
|
|
|
|
|
triggerAction(Core::Constants::SPLIT_SIDE_BY_SIDE);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("mak", "make")) {
|
2010-05-18 12:58:36 +02:00
|
|
|
// :mak[e][!] [arguments]
|
|
|
|
|
triggerAction(ProjectExplorer::Constants::BUILD);
|
2010-07-14 18:15:17 +02: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]
|
2010-05-18 14:48:12 +02:00
|
|
|
showSettingsDialog();
|
|
|
|
|
} else if (cmd.args == "ic" || cmd.args == "ignorecase") {
|
|
|
|
|
// :set noic
|
|
|
|
|
setActionChecked(Find::Constants::CASE_SENSITIVE, false);
|
|
|
|
|
*handled = false; // Let the handler see it as well.
|
|
|
|
|
} else if (cmd.args == "noic" || cmd.args == "noignorecase") {
|
|
|
|
|
// :set noic
|
|
|
|
|
setActionChecked(Find::Constants::CASE_SENSITIVE, true);
|
|
|
|
|
*handled = false; // Let the handler see it as well.
|
|
|
|
|
}
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("n", "next")) {
|
2010-07-14 14:33:26 +02:00
|
|
|
// :n[ext]
|
|
|
|
|
switchToFile(currentFile() + cmd.count);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("prev", "previous") || cmd.matches("N", "Next")) {
|
|
|
|
|
// :prev[ious], :N[ext]
|
2010-07-14 14:33:26 +02:00
|
|
|
switchToFile(currentFile() - cmd.count);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("bn", "bnext")) {
|
2010-07-14 14:33:26 +02:00
|
|
|
// :bn[ext]
|
|
|
|
|
switchToFile(currentFile() + cmd.count);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("bp", "bprevious") || cmd.matches("bN", "bNext")) {
|
|
|
|
|
// :bp[revious], :bN[ext]
|
2010-07-14 14:33:26 +02:00
|
|
|
switchToFile(currentFile() - cmd.count);
|
2010-07-14 18:15:17 +02:00
|
|
|
} else if (cmd.matches("on", "only")) {
|
|
|
|
|
// :on[ly]
|
2010-07-14 17:59:48 +02:00
|
|
|
//triggerAction(Core::Constants::REMOVE_ALL_SPLITS);
|
|
|
|
|
triggerAction(Core::Constants::REMOVE_CURRENT_SPLIT);
|
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.
|
2010-05-19 16:21:42 +02:00
|
|
|
typedef CommandMap::const_iterator Iterator;
|
|
|
|
|
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();
|
|
|
|
|
const QRegExp &re = it.value();
|
2010-05-19 16:21:42 +02:00
|
|
|
if (!re.pattern().isEmpty() && re.indexIn(cmd.cmd) != -1) {
|
2010-01-22 13:56:50 +01:00
|
|
|
triggerAction(id);
|
|
|
|
|
return;
|
|
|
|
|
}
|
|
|
|
|
}
|
2010-05-18 14:48:12 +02:00
|
|
|
*handled = false;
|
2010-01-21 17:23:32 +01:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2009-06-15 15:14:16 +02:00
|
|
|
void FakeVimPluginPrivate::handleDelayedQuit(bool forced, Core::IEditor *editor)
|
|
|
|
|
{
|
|
|
|
|
QList<Core::IEditor *> editors;
|
|
|
|
|
editors.append(editor);
|
|
|
|
|
Core::EditorManager::instance()->closeEditors(editors, !forced);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void FakeVimPluginPrivate::handleDelayedQuitAll(bool forced)
|
|
|
|
|
{
|
|
|
|
|
Core::EditorManager::instance()->closeAllEditors(!forced);
|
|
|
|
|
}
|
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
TextEditor::TextBlockUserData::MatchType match
|
|
|
|
|
= TextEditor::TextBlockUserData::matchCursorForward(cursor);
|
|
|
|
|
if (match == TextEditor::TextBlockUserData::Match) {
|
|
|
|
|
*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);
|
|
|
|
|
if (match == TextEditor::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;
|
|
|
|
|
}
|
|
|
|
|
match = TextEditor::TextBlockUserData::matchCursorBackward(cursor);
|
|
|
|
|
if (match == TextEditor::TextBlockUserData::Match) {
|
|
|
|
|
*moved = true;
|
|
|
|
|
*forward = false;
|
|
|
|
|
} else if (undoMove) {
|
|
|
|
|
cursor->movePosition(QTextCursor::Left, QTextCursor::KeepAnchor, 1);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2010-06-02 15:27:10 +02:00
|
|
|
void FakeVimPluginPrivate::indentRegion(int beginLine, int endLine,
|
2009-02-03 10:39:57 +01:00
|
|
|
QChar typedChar)
|
|
|
|
|
{
|
|
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (!handler)
|
|
|
|
|
return;
|
|
|
|
|
|
|
|
|
|
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget());
|
|
|
|
|
if (!bt)
|
|
|
|
|
return;
|
|
|
|
|
|
2010-06-02 15:27:10 +02:00
|
|
|
const TextEditor::TabSettings oldTabSettings = bt->tabSettings();
|
|
|
|
|
|
|
|
|
|
TabSettings tabSettings;
|
2010-01-15 15:27:42 +01:00
|
|
|
tabSettings.m_indentSize = theFakeVimSetting(ConfigShiftWidth)->value().toInt();
|
|
|
|
|
tabSettings.m_tabSize = theFakeVimSetting(ConfigTabStop)->value().toInt();
|
|
|
|
|
tabSettings.m_spacesForTabs = theFakeVimSetting(ConfigExpandTab)->value().toBool();
|
2010-06-02 15:27:10 +02:00
|
|
|
bt->setTabSettings(tabSettings);
|
|
|
|
|
|
|
|
|
|
QTextDocument *doc = bt->document();
|
|
|
|
|
QTextBlock startBlock = doc->findBlockByNumber(beginLine);
|
|
|
|
|
|
|
|
|
|
// Record line lenghts for mark adjustments
|
|
|
|
|
QVector<int> lineLengths(endLine - beginLine + 1);
|
|
|
|
|
QTextBlock block = startBlock;
|
|
|
|
|
|
2010-06-01 16:39:03 +02:00
|
|
|
for (int i = beginLine; i <= endLine; ++i) {
|
2010-06-02 15:27:10 +02:00
|
|
|
lineLengths[i - beginLine] = block.text().length();
|
|
|
|
|
if (typedChar == 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 {
|
2010-06-02 15:27:10 +02:00
|
|
|
bt->indentBlock(doc, block, typedChar);
|
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
|
|
|
}
|
2010-06-02 15:27:10 +02:00
|
|
|
|
|
|
|
|
// Adjust marks.
|
|
|
|
|
block = startBlock;
|
|
|
|
|
for (int i = beginLine; i <= endLine; ++i) {
|
|
|
|
|
const int amount = block.text().length() - lineLengths[i - beginLine];
|
|
|
|
|
handler->fixMarks(block.position(), amount);
|
|
|
|
|
block = block.next();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
bt->setTabSettings(oldTabSettings);
|
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
|
|
|
}
|
|
|
|
|
|
2009-01-13 16:38:05 +01:00
|
|
|
void FakeVimPluginPrivate::showCommandBuffer(const QString &contents)
|
2008-12-19 12:20:04 +01:00
|
|
|
{
|
2009-03-30 16:54:25 +02:00
|
|
|
//qDebug() << "SHOW COMMAND BUFFER" << contents;
|
2010-07-14 13:46:20 +02:00
|
|
|
editorManager()->showEditorStatusBar(
|
|
|
|
|
_(Constants::MINI_BUFFER), contents,
|
2009-03-31 11:44:18 +02:00
|
|
|
tr("Quit FakeVim"), this, SLOT(quitFakeVim()));
|
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
|
|
|
{
|
2009-01-23 15:12:04 +01:00
|
|
|
FakeVimHandler *handler = qobject_cast<FakeVimHandler *>(sender());
|
|
|
|
|
if (handler)
|
|
|
|
|
QMessageBox::information(handler->widget(), tr("FakeVim Information"), text);
|
2009-01-09 15:36:02 +01:00
|
|
|
}
|
|
|
|
|
|
2009-01-23 15:12:04 +01: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()))
|
|
|
|
|
if (BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(handler->widget()))
|
|
|
|
|
bt->setExtraSelections(BaseTextEditor::FakeVimSelection, selection);
|
2009-01-13 13:47:00 +01:00
|
|
|
}
|
|
|
|
|
|
2010-07-14 14:33:26 +02:00
|
|
|
int FakeVimPluginPrivate::currentFile() const
|
2010-01-22 13:56:50 +01:00
|
|
|
{
|
2010-07-14 13:46:20 +02:00
|
|
|
Core::OpenEditorsModel *model = editorManager()->openedEditorsModel();
|
2010-01-22 13:56:50 +01:00
|
|
|
IEditor *cur = Core::EditorManager::instance()->currentEditor();
|
2010-07-14 14:33:26 +02:00
|
|
|
return model->indexOf(cur).row();
|
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
|
|
|
{
|
2010-07-14 14:33:26 +02:00
|
|
|
Core::OpenEditorsModel *model = editorManager()->openedEditorsModel();
|
|
|
|
|
int size = model->rowCount();
|
|
|
|
|
QTC_ASSERT(size, return);
|
|
|
|
|
n = n % size;
|
|
|
|
|
if (n < 0)
|
|
|
|
|
n += size;
|
|
|
|
|
editorManager()->activateEditor(model->index(n, 0), 0);
|
2010-01-22 13:56:50 +01:00
|
|
|
}
|
2009-01-13 16:38:05 +01:00
|
|
|
|
2010-05-19 16:21:42 +02:00
|
|
|
CommandMap &FakeVimExCommandsPage::exCommandMap()
|
|
|
|
|
{
|
|
|
|
|
return m_q->exCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
CommandMap &FakeVimExCommandsPage::defaultExCommandMap()
|
|
|
|
|
{
|
|
|
|
|
return m_q->defaultExCommandMap();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
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()
|
|
|
|
|
{
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#include "fakevimplugin.moc"
|
2008-12-19 12:20:04 +01:00
|
|
|
|
|
|
|
|
Q_EXPORT_PLUGIN(FakeVimPlugin)
|