Added infrastructure to change multiple files at once.

This commit is contained in:
Erik Verbruggen
2010-06-14 14:52:43 +02:00
parent b57a161101
commit 297b281ced
20 changed files with 638 additions and 84 deletions

View File

@@ -436,7 +436,7 @@ protected:
range.ast = member;
range.begin = QTextCursor(_textDocument);
range.begin.setPosition(ast->lbraceToken.begin());
range.begin.setPosition(member->firstSourceLocation().begin());
range.end = QTextCursor(_textDocument);
range.end.setPosition(ast->rbraceToken.end());

View File

@@ -21,7 +21,8 @@ HEADERS += \
qmljshoverhandler.h \
qmljsmodelmanager.h \
qmljspreviewrunner.h \
qmljsquickfix.h
qmljsquickfix.h \
qmljsrefactoringchanges.h
SOURCES += \
qmljscodecompletion.cpp \
@@ -35,7 +36,8 @@ SOURCES += \
qmljshoverhandler.cpp \
qmljsmodelmanager.cpp \
qmljspreviewrunner.cpp \
qmljsquickfix.cpp
qmljsquickfix.cpp \
qmljsrefactoringchanges.cpp
RESOURCES += qmljseditor.qrc
OTHER_FILES += QmlJSEditor.pluginspec QmlJSEditor.mimetypes.xml

View File

@@ -29,11 +29,19 @@
#include "qmljsquickfix.h"
#include "qmljseditor.h"
#include "qmljsrefactoringchanges.h"
#include "qmljs/parser/qmljsast_p.h"
#include <extensionsystem/pluginmanager.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <QtGui/QApplication>
#include <QtCore/QDebug>
using namespace QmlJSEditor;
using namespace QmlJSEditor::Internal;
using TextEditor::RefactoringChanges;
class QmlJSQuickFixState: public TextEditor::QuickFixState
{
@@ -54,14 +62,6 @@ public:
return QApplication::translate("QmlJSEditor::QuickFix", "Split initializer");
}
virtual Range topLevelRange() const
{
Q_ASSERT(_objectInitializer);
return range(position(_objectInitializer->lbraceToken),
position(_objectInitializer->rbraceToken));
}
virtual void createChangeSet()
{
Q_ASSERT(_objectInitializer != 0);
@@ -77,6 +77,10 @@ public:
// insert a newline before the closing brace
insert(position(_objectInitializer->rbraceToken), QLatin1String("\n"));
reindent(RefactoringChanges::Range(position(_objectInitializer->lbraceToken),
position(_objectInitializer->rbraceToken)));
}
virtual int check()
@@ -112,11 +116,14 @@ private:
QmlJSQuickFixOperation::QmlJSQuickFixOperation(TextEditor::BaseTextEditor *editor)
: TextEditor::QuickFixOperation(editor)
, _refactoringChanges(0)
{
}
QmlJSQuickFixOperation::~QmlJSQuickFixOperation()
{
if (_refactoringChanges)
delete _refactoringChanges;
}
QmlJS::Document::Ptr QmlJSQuickFixOperation::document() const
@@ -136,11 +143,27 @@ const SemanticInfo &QmlJSQuickFixOperation::semanticInfo() const
int QmlJSQuickFixOperation::match(TextEditor::QuickFixState *state)
{
QmlJS::ModelManagerInterface *modelManager = ExtensionSystem::PluginManager::instance()->getObject<QmlJS::ModelManagerInterface>();
QmlJSQuickFixState *s = static_cast<QmlJSQuickFixState *>(state);
_semanticInfo = s->semanticInfo;
if (_refactoringChanges) {
delete _refactoringChanges;
}
_refactoringChanges = new QmlJSRefactoringChanges(modelManager, _semanticInfo.snapshot);
return check();
}
void QmlJSQuickFixOperation::apply()
{
_refactoringChanges->apply();
}
QmlJSRefactoringChanges *QmlJSQuickFixOperation::qmljsRefactoringChanges() const
{ return _refactoringChanges; }
RefactoringChanges *QmlJSQuickFixOperation::refactoringChanges() const
{ return qmljsRefactoringChanges(); }
unsigned QmlJSQuickFixOperation::position(const QmlJS::AST::SourceLocation &loc) const
{
return position(loc.startLine, loc.startColumn);

View File

@@ -31,6 +31,7 @@
#define QMLJSQUICKFIX_H
#include "qmljseditor.h"
#include <texteditor/quickfix.h>
#include <qmljs/parser/qmljsastfwd_p.h>
#include <qmljs/qmljsdocument.h>
@@ -40,6 +41,7 @@ namespace QmlJS {
}
namespace QmlJSEditor {
class QmlJSRefactoringChanges;
namespace Internal {
@@ -69,6 +71,10 @@ protected:
using TextEditor::QuickFixOperation::charAt;
using TextEditor::QuickFixOperation::position;
virtual void apply();
QmlJSRefactoringChanges *qmljsRefactoringChanges() const;
virtual TextEditor::RefactoringChanges *refactoringChanges() const;
unsigned position(const QmlJS::AST::SourceLocation &loc) const;
// token based operations
@@ -79,6 +85,7 @@ protected:
private:
SemanticInfo _semanticInfo;
QmlJSRefactoringChanges *_refactoringChanges;
};
class QmlJSQuickFixCollector: public TextEditor::QuickFixCollector

View File

@@ -0,0 +1,50 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** 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.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#include "qmljsrefactoringchanges.h"
#include <qmljs/qmljsmodelmanagerinterface.h>
using namespace QmlJS;
using namespace QmlJSEditor;
QmlJSRefactoringChanges::QmlJSRefactoringChanges(ModelManagerInterface *modelManager,
const Snapshot &snapshot)
: m_modelManager(modelManager)
, m_snapshot(snapshot)
{
Q_ASSERT(modelManager);
}
QStringList QmlJSRefactoringChanges::apply()
{
const QStringList changedFiles = TextEditor::RefactoringChanges::apply();
m_modelManager->updateSourceFiles(changedFiles, true);
return changedFiles;
}

View File

@@ -0,0 +1,58 @@
/**************************************************************************
**
** This file is part of Qt Creator
**
** Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
**
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** Commercial Usage
**
** 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.
**
** GNU Lesser General Public License Usage
**
** 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.
**
** If you are unsure which license is appropriate for your use, please
** contact the sales department at http://qt.nokia.com/contact.
**
**************************************************************************/
#ifndef QMLREFACTORINGCHANGES_H
#define QMLREFACTORINGCHANGES_H
#include <qmljs/qmljsdocument.h>
#include <texteditor/refactoringchanges.h>
namespace QmlJS {
class ModelManagerInterface;
} // namespace QmlJS
namespace QmlJSEditor {
class QmlJSRefactoringChanges: public TextEditor::RefactoringChanges
{
public:
QmlJSRefactoringChanges(QmlJS::ModelManagerInterface *modelManager,
const QmlJS::Snapshot &snapshot);
virtual QStringList apply();
private:
QmlJS::ModelManagerInterface *m_modelManager;
QmlJS::Snapshot m_snapshot;
};
} // namespace QmlJSEditor
#endif // QMLREFACTORINGCHANGES_H