forked from qt-creator/qt-creator
fakevim: remove core dependencies from fakevimhandler.cpp. breaks
writing of partial files for now.
This commit is contained in:
@@ -40,10 +40,6 @@
|
|||||||
// Qt Creator. The idea is to keep this file here in a "clean" state that
|
// Qt Creator. The idea is to keep this file here in a "clean" state that
|
||||||
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
|
// allows easy reuse with any QTextEdit or QPlainTextEdit derived class.
|
||||||
|
|
||||||
#include <coreplugin/filemanager.h>
|
|
||||||
#include <coreplugin/icore.h>
|
|
||||||
#include <texteditor/basetexteditor.h>
|
|
||||||
|
|
||||||
//#include <indenter.h>
|
//#include <indenter.h>
|
||||||
|
|
||||||
#include <QtCore/QDebug>
|
#include <QtCore/QDebug>
|
||||||
@@ -1200,18 +1196,11 @@ void FakeVimHandler::Private::handleExCommand(const QString &cmd0)
|
|||||||
bool exists = file.exists();
|
bool exists = file.exists();
|
||||||
if (exists && !forced && !noArgs) {
|
if (exists && !forced && !noArgs) {
|
||||||
showRedMessage(tr("File '%1' exists (add ! to override)").arg(fileName));
|
showRedMessage(tr("File '%1' exists (add ! to override)").arg(fileName));
|
||||||
} else if (m_currentFile || file.open(QIODevice::ReadWrite)) {
|
} else if (file.open(QIODevice::ReadWrite)) {
|
||||||
if(m_currentFile) {
|
|
||||||
m_core->fileManager()->blockFileChange(m_currentFile);
|
|
||||||
m_currentFile->save(fileName);
|
|
||||||
m_core->fileManager()->unblockFileChange(m_currentFile);
|
|
||||||
} else {
|
|
||||||
QTextCursor tc = selectRange(beginLine, endLine);
|
QTextCursor tc = selectRange(beginLine, endLine);
|
||||||
qDebug() << "ANCHOR: " << tc.position() << tc.anchor()
|
QString contents = tc.selection().toPlainText();
|
||||||
<< tc.selection().toPlainText();
|
emit q->writeFile(fileName, contents);
|
||||||
{ QTextStream ts(&file); ts << tc.selection().toPlainText(); }
|
// check by reading back
|
||||||
file.close();
|
|
||||||
}
|
|
||||||
file.open(QIODevice::ReadOnly);
|
file.open(QIODevice::ReadOnly);
|
||||||
QByteArray ba = file.readAll();
|
QByteArray ba = file.readAll();
|
||||||
showBlackMessage(tr("\"%1\" %2 %3L, %4C written")
|
showBlackMessage(tr("\"%1\" %2 %3L, %4C written")
|
||||||
@@ -1741,11 +1730,6 @@ void FakeVimHandler::Private::setWidget(QWidget *ob)
|
|||||||
{
|
{
|
||||||
m_textedit = qobject_cast<QTextEdit *>(ob);
|
m_textedit = qobject_cast<QTextEdit *>(ob);
|
||||||
m_plaintextedit = qobject_cast<QPlainTextEdit *>(ob);
|
m_plaintextedit = qobject_cast<QPlainTextEdit *>(ob);
|
||||||
TextEditor::BaseTextEditor* editor = qobject_cast<TextEditor::BaseTextEditor*>(ob);
|
|
||||||
if (editor) {
|
|
||||||
m_currentFile = editor->file();
|
|
||||||
m_currentFileName = m_currentFile->fileName();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
///////////////////////////////////////////////////////////////////////
|
///////////////////////////////////////////////////////////////////////
|
||||||
@@ -1834,3 +1818,8 @@ void FakeVimHandler::quit()
|
|||||||
{
|
{
|
||||||
d->quit();
|
d->quit();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimHandler::setCurrentFileName(const QString &fileName)
|
||||||
|
{
|
||||||
|
d->m_currentFileName = fileName;
|
||||||
|
}
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ public slots:
|
|||||||
// FIXME: good idea?
|
// FIXME: good idea?
|
||||||
void addWidget(QWidget *widget);
|
void addWidget(QWidget *widget);
|
||||||
void removeWidget(QWidget *widget);
|
void removeWidget(QWidget *widget);
|
||||||
|
void setCurrentFileName(const QString &fileName);
|
||||||
|
|
||||||
// This executes an "ex" style command taking context
|
// This executes an "ex" style command taking context
|
||||||
// information from \p widget;
|
// information from \p widget;
|
||||||
@@ -72,6 +73,7 @@ signals:
|
|||||||
void quitRequested(QWidget *);
|
void quitRequested(QWidget *);
|
||||||
void selectionChanged(QWidget *widget,
|
void selectionChanged(QWidget *widget,
|
||||||
const QList<QTextEdit::ExtraSelection> &selection);
|
const QList<QTextEdit::ExtraSelection> &selection);
|
||||||
|
void writeFile(const QString &fileName, const QString &contents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool eventFilter(QObject *ob, QEvent *ev);
|
bool eventFilter(QObject *ob, QEvent *ev);
|
||||||
|
|||||||
@@ -39,7 +39,9 @@
|
|||||||
#include <coreplugin/actionmanager/actionmanager.h>
|
#include <coreplugin/actionmanager/actionmanager.h>
|
||||||
#include <coreplugin/coreconstants.h>
|
#include <coreplugin/coreconstants.h>
|
||||||
#include <coreplugin/editormanager/editormanager.h>
|
#include <coreplugin/editormanager/editormanager.h>
|
||||||
|
#include <coreplugin/filemanager.h>
|
||||||
#include <coreplugin/icore.h>
|
#include <coreplugin/icore.h>
|
||||||
|
#include <coreplugin/ifile.h>
|
||||||
#include <coreplugin/messagemanager.h>
|
#include <coreplugin/messagemanager.h>
|
||||||
#include <coreplugin/modemanager.h>
|
#include <coreplugin/modemanager.h>
|
||||||
#include <coreplugin/uniqueidmanager.h>
|
#include <coreplugin/uniqueidmanager.h>
|
||||||
@@ -117,12 +119,14 @@ private slots:
|
|||||||
void editorAboutToClose(Core::IEditor *);
|
void editorAboutToClose(Core::IEditor *);
|
||||||
void changeSelection(QWidget *widget,
|
void changeSelection(QWidget *widget,
|
||||||
const QList<QTextEdit::ExtraSelection> &selections);
|
const QList<QTextEdit::ExtraSelection> &selections);
|
||||||
|
void writeFile(const QString &fileName, const QString &contents);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
FakeVimPlugin *q;
|
FakeVimPlugin *q;
|
||||||
FakeVimHandler *m_handler;
|
FakeVimHandler *m_handler;
|
||||||
QAction *m_installHandlerAction;
|
QAction *m_installHandlerAction;
|
||||||
Core::ICore *m_core;
|
Core::ICore *m_core;
|
||||||
|
Core::IFile *m_currentFile;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace Internal
|
} // namespace Internal
|
||||||
@@ -134,6 +138,7 @@ FakeVimPluginPrivate::FakeVimPluginPrivate(FakeVimPlugin *plugin)
|
|||||||
m_handler = 0;
|
m_handler = 0;
|
||||||
m_installHandlerAction = 0;
|
m_installHandlerAction = 0;
|
||||||
m_core = 0;
|
m_core = 0;
|
||||||
|
m_currentFile = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
FakeVimPluginPrivate::~FakeVimPluginPrivate()
|
FakeVimPluginPrivate::~FakeVimPluginPrivate()
|
||||||
@@ -206,6 +211,12 @@ void FakeVimPluginPrivate::installHandler(QWidget *widget)
|
|||||||
this, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
|
this, SLOT(changeSelection(QWidget*,QList<QTextEdit::ExtraSelection>)));
|
||||||
|
|
||||||
m_handler->addWidget(widget);
|
m_handler->addWidget(widget);
|
||||||
|
TextEditor::BaseTextEditor* editor =
|
||||||
|
qobject_cast<TextEditor::BaseTextEditor*>(widget);
|
||||||
|
if (editor) {
|
||||||
|
m_currentFile = editor->file();
|
||||||
|
m_handler->setCurrentFileName(editor->file()->fileName());
|
||||||
|
}
|
||||||
|
|
||||||
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(widget);
|
BaseTextEditor *bt = qobject_cast<BaseTextEditor *>(widget);
|
||||||
if (bt) {
|
if (bt) {
|
||||||
@@ -225,12 +236,30 @@ void FakeVimPluginPrivate::installHandler(QWidget *widget)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void FakeVimPluginPrivate::writeFile(const QString &fileName,
|
||||||
|
const QString &contents)
|
||||||
|
{
|
||||||
|
if (m_currentFile && fileName == m_currentFile->fileName()) {
|
||||||
|
// handle that as a special case for nicer interation with
|
||||||
|
// Creator core
|
||||||
|
m_core->fileManager()->blockFileChange(m_currentFile);
|
||||||
|
m_currentFile->save(fileName);
|
||||||
|
m_core->fileManager()->unblockFileChange(m_currentFile);
|
||||||
|
} else {
|
||||||
|
QFile file(fileName);
|
||||||
|
file.open(QIODevice::ReadWrite);
|
||||||
|
{ QTextStream ts(&file); ts << contents; }
|
||||||
|
file.close();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::removeHandler(QWidget *widget)
|
void FakeVimPluginPrivate::removeHandler(QWidget *widget)
|
||||||
{
|
{
|
||||||
Q_UNUSED(widget);
|
Q_UNUSED(widget);
|
||||||
m_handler->removeWidget(widget);
|
m_handler->removeWidget(widget);
|
||||||
Core::EditorManager::instance()->hideEditorInfoBar(
|
Core::EditorManager::instance()->hideEditorInfoBar(
|
||||||
QLatin1String(Constants::MINI_BUFFER));
|
QLatin1String(Constants::MINI_BUFFER));
|
||||||
|
m_currentFile = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
|
void FakeVimPluginPrivate::editorOpened(Core::IEditor *editor)
|
||||||
|
|||||||
Reference in New Issue
Block a user