Commit 3ac0668d authored by hjk's avatar hjk

QmlJSEditor: General editor related code consolidation

Merge editor files, sort #includes, namespaces.
This does not yet use the new editor construction scheme.

Change-Id: Idb1171389858c4470d7a4ec9441fb25e6d157400
Reviewed-by: default avatarChristian Stenger <christian.stenger@digia.com>
parent ba512405
......@@ -30,14 +30,13 @@
#include "qmljseditor.h"
#include "qmljsautocompleter.h"
#include "qmljseditoreditable.h"
#include "qmljscompletionassist.h"
#include "qmljseditorconstants.h"
#include "qmljseditordocument.h"
#include "qmljseditorplugin.h"
#include "qmloutlinemodel.h"
#include "qmljsfindreferences.h"
#include "qmljscompletionassist.h"
#include "qmljsquickfixassist.h"
#include "qmloutlinemodel.h"
#include <qmljs/qmljsbind.h>
#include <qmljs/qmljsevaluate.h>
......@@ -46,15 +45,22 @@
#include <qmljs/qmljsutils.h>
#include <qmljstools/qmljstoolsconstants.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/id.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/designmode.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/modemanager.h>
#include <extensionsystem/pluginmanager.h>
#include <texteditor/basetextdocument.h>
#include <texteditor/fontsettings.h>
#include <texteditor/tabsettings.h>
......@@ -63,25 +69,23 @@
#include <texteditor/refactoroverlay.h>
#include <texteditor/codeassist/genericproposal.h>
#include <texteditor/codeassist/basicproposalitemlistmodel.h>
#include <qmldesigner/qmldesignerconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <texteditor/texteditoractionhandler.h>
#include <utils/changeset.h>
#include <utils/uncommentselection.h>
#include <utils/qtcassert.h>
#include <utils/annotateditemdelegate.h>
#include <QComboBox>
#include <QCoreApplication>
#include <QFileInfo>
#include <QSignalMapper>
#include <QTimer>
#include <QHeaderView>
#include <QMenu>
#include <QPointer>
#include <QScopedPointer>
#include <QSignalMapper>
#include <QTextCodec>
#include <QMenu>
#include <QComboBox>
#include <QHeaderView>
#include <QInputDialog>
#include <QToolBar>
#include <QTimer>
#include <QTreeView>
enum {
......@@ -93,11 +97,16 @@ using namespace Core;
using namespace QmlJS;
using namespace QmlJS::AST;
using namespace QmlJSTools;
using namespace TextEditor;
namespace QmlJSEditor {
namespace Internal {
QmlJSTextEditorWidget::QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr doc)
//
// QmlJSEditorWidget
//
QmlJSTextEditorWidget::QmlJSTextEditorWidget(BaseTextDocumentPtr doc)
{
setTextDocument(doc);
setAutoCompleter(new AutoCompleter);
......@@ -175,7 +184,7 @@ IEditor *QmlJSEditor::duplicate()
bool QmlJSEditor::open(QString *errorString, const QString &fileName, const QString &realFileName)
{
bool b = TextEditor::BaseTextEditor::open(errorString, fileName, realFileName);
bool b = BaseTextEditor::open(errorString, fileName, realFileName);
textDocument()->setMimeType(MimeDatabase::findByFile(QFileInfo(fileName)).type());
return b;
}
......@@ -288,10 +297,10 @@ namespace QmlJSEditor {
namespace Internal {
template <class T>
static QList<TextEditor::RefactorMarker> removeMarkersOfType(const QList<TextEditor::RefactorMarker> &markers)
static QList<RefactorMarker> removeMarkersOfType(const QList<RefactorMarker> &markers)
{
QList<TextEditor::RefactorMarker> result;
foreach (const TextEditor::RefactorMarker &marker, markers) {
QList<RefactorMarker> result;
foreach (const RefactorMarker &marker, markers) {
if (!marker.data.canConvert<T>())
result += marker;
}
......@@ -311,14 +320,14 @@ void QmlJSTextEditorWidget::updateContextPane()
if (m_contextPane->isAvailable(editor(), info.document, newNode) &&
!m_contextPane->widget()->isVisible()) {
QList<TextEditor::RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
QList<RefactorMarker> markers = removeMarkersOfType<QtQuickToolbarMarker>(refactorMarkers());
if (UiObjectMember *m = newNode->uiObjectMemberCast()) {
const int start = qualifiedTypeNameId(m)->identifierToken.begin();
for (UiQualifiedId *q = qualifiedTypeNameId(m); q; q = q->next) {
if (! q->next) {
const int end = q->identifierToken.end();
if (position() >= start && position() <= end) {
TextEditor::RefactorMarker marker;
RefactorMarker marker;
QTextCursor tc(document());
tc.setPosition(end);
marker.cursor = tc;
......@@ -496,7 +505,7 @@ void QmlJSTextEditorWidget::setSelectedElements()
void QmlJSTextEditorWidget::applyFontSettings()
{
TextEditor::BaseTextEditorWidget::applyFontSettings();
BaseTextEditorWidget::applyFontSettings();
if (!m_qmlJsEditorDocument->isSemanticInfoOutdated())
updateUses();
}
......@@ -527,7 +536,7 @@ bool QmlJSTextEditorWidget::isClosingBrace(const QList<Token> &tokens) const
return false;
}
TextEditor::BaseTextEditor *QmlJSTextEditorWidget::createEditor()
BaseTextEditor *QmlJSTextEditorWidget::createEditor()
{
return new QmlJSEditor;
}
......@@ -566,12 +575,12 @@ void QmlJSTextEditorWidget::createToolBar()
connect(this, SIGNAL(cursorPositionChanged()), m_updateOutlineIndexTimer, SLOT(start()));
insertExtraToolBarWidget(TextEditor::BaseTextEditorWidget::Left, m_outlineCombo);
insertExtraToolBarWidget(BaseTextEditorWidget::Left, m_outlineCombo);
}
TextEditor::BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const QTextCursor &cursor,
bool /*resolveTarget*/,
bool /*inNextSplit*/)
BaseTextEditorWidget::Link QmlJSTextEditorWidget::findLinkAt(const QTextCursor &cursor,
bool /*resolveTarget*/,
bool /*inNextSplit*/)
{
const SemanticInfo semanticInfo = m_qmlJsEditorDocument->semanticInfo();
if (! semanticInfo.isValid())
......@@ -678,7 +687,7 @@ void QmlJSTextEditorWidget::showContextPane()
void QmlJSTextEditorWidget::performQuickFix(int index)
{
TextEditor::QuickFixOperation::Ptr op = m_quickFixes.at(index);
QuickFixOperation::Ptr op = m_quickFixes.at(index);
op->perform();
}
......@@ -691,20 +700,16 @@ void QmlJSTextEditorWidget::contextMenuEvent(QContextMenuEvent *e)
QSignalMapper mapper;
connect(&mapper, SIGNAL(mapped(int)), this, SLOT(performQuickFix(int)));
if (!m_qmlJsEditorDocument->isSemanticInfoOutdated()) {
TextEditor::IAssistInterface *interface =
createAssistInterface(TextEditor::QuickFix, TextEditor::ExplicitlyInvoked);
IAssistInterface *interface = createAssistInterface(QuickFix, ExplicitlyInvoked);
if (interface) {
QScopedPointer<TextEditor::IAssistProcessor> processor(
QScopedPointer<IAssistProcessor> processor(
QmlJSEditorPlugin::instance()->quickFixAssistProvider()->createProcessor());
QScopedPointer<TextEditor::IAssistProposal> proposal(processor->perform(interface));
QScopedPointer<IAssistProposal> proposal(processor->perform(interface));
if (!proposal.isNull()) {
TextEditor::BasicProposalItemListModel *model =
static_cast<TextEditor::BasicProposalItemListModel *>(proposal->model());
BasicProposalItemListModel *model = static_cast<BasicProposalItemListModel *>(proposal->model());
for (int index = 0; index < model->size(); ++index) {
TextEditor::BasicProposalItem *item =
static_cast<TextEditor::BasicProposalItem *>(model->proposalItem(index));
TextEditor::QuickFixOperation::Ptr op =
item->data().value<TextEditor::QuickFixOperation::Ptr>();
BasicProposalItem *item = static_cast<BasicProposalItem *>(model->proposalItem(index));
QuickFixOperation::Ptr op = item->data().value<QuickFixOperation::Ptr>();
m_quickFixes.append(op);
QAction *action = refactoringMenu->addAction(op->description());
mapper.setMapping(action, index);
......@@ -809,7 +814,7 @@ void QmlJSTextEditorWidget::semanticInfoUpdated(const SemanticInfo &semanticInfo
updateUses();
}
void QmlJSTextEditorWidget::onRefactorMarkerClicked(const TextEditor::RefactorMarker &marker)
void QmlJSTextEditorWidget::onRefactorMarkerClicked(const RefactorMarker &marker)
{
if (marker.data.canConvert<QtQuickToolbarMarker>())
showContextPane();
......@@ -847,7 +852,7 @@ bool QmlJSTextEditorWidget::hideContextPane()
return b;
}
TextEditor::IAssistInterface *QmlJSTextEditorWidget::createAssistInterface(
IAssistInterface *QmlJSTextEditorWidget::createAssistInterface(
TextEditor::AssistKind assistKind,
TextEditor::AssistReason reason) const
{
......@@ -879,5 +884,56 @@ QString QmlJSTextEditorWidget::foldReplacementText(const QTextBlock &block) cons
return TextEditor::BaseTextEditorWidget::foldReplacementText(block);
}
//
// QmlJSEditor
//
QmlJSEditor::QmlJSEditor()
{
addContext(Constants::C_QMLJSEDITOR_ID);
addContext(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
bool QmlJSEditor::isDesignModePreferred() const
{
// stay in design mode if we are there
IMode *mode = ModeManager::currentMode();
return mode && mode->id() == Core::Constants::MODE_DESIGN;
}
//
// QmlJSEditorFactory
//
QmlJSEditorFactory::QmlJSEditorFactory()
{
setId(Constants::C_QMLJSEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::C_QMLJSEDITOR_DISPLAY_NAME));
addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
addMimeType(QmlJSTools::Constants::QBS_MIMETYPE);
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
addMimeType(QmlJSTools::Constants::JSON_MIMETYPE);
new TextEditorActionHandler(this, Constants::C_QMLJSEDITOR_ID,
TextEditorActionHandler::Format
| TextEditorActionHandler::UnCommentSelection
| TextEditorActionHandler::UnCollapseAll
| TextEditorActionHandler::FollowSymbolUnderCursor);
}
IEditor *QmlJSEditorFactory::createEditor()
{
QmlJSTextEditorWidget *rc = new QmlJSTextEditorWidget(BaseTextDocumentPtr(new QmlJSEditorDocument));
return rc->editor();
}
} // namespace Internal
} // namespace QmlJSEditor
......@@ -34,41 +34,32 @@
#include <qmljs/qmljsscanner.h>
#include <qmljstools/qmljssemanticinfo.h>
#include <coreplugin/editormanager/ieditorfactory.h>
#include <texteditor/basetexteditor.h>
#include <texteditor/quickfix.h>
#include <texteditor/texteditorconstants.h>
#include <utils/uncommentselection.h>
#include <QSharedPointer>
#include <QModelIndex>
#include <QTextLayout>
#include <QVector>
QT_BEGIN_NAMESPACE
class QComboBox;
class QTimer;
QT_END_NAMESPACE
namespace Core { class ICore; }
namespace QmlJS {
class ModelManagerInterface;
class IContextPane;
class LookupContext;
namespace AST { class UiObjectMember; }
}
/*!
The top-level namespace of the QmlJSEditor plug-in.
*/
namespace QmlJSEditor {
class QmlJSEditorDocument;
class FindReferences;
namespace Internal {
class QmlJSEditor;
class QmlOutlineModel;
class QmlJSTextEditorWidget : public TextEditor::BaseTextEditorWidget
{
Q_OBJECT
......@@ -147,6 +138,29 @@ private:
FindReferences *m_findReferences;
};
class QmlJSEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
QmlJSEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const;
};
class QmlJSEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
QmlJSEditorFactory();
Core::IEditor *createEditor();
};
} // namespace Internal
} // namespace QmlJSEditor
......
......@@ -8,7 +8,6 @@ HEADERS += \
qmljseditor.h \
qmljseditor_global.h \
qmljseditorconstants.h \
qmljseditorfactory.h \
qmljseditorplugin.h \
qmlexpressionundercursor.h \
qmlfilewizard.h \
......@@ -24,7 +23,6 @@ HEADERS += \
quicktoolbar.h \
qmljscomponentnamedialog.h \
qmljsfindreferences.h \
qmljseditoreditable.h \
qmljsautocompleter.h \
jsfilewizard.h \
qmljssnippetprovider.h \
......@@ -40,7 +38,6 @@ HEADERS += \
SOURCES += \
qmljseditor.cpp \
qmljseditorfactory.cpp \
qmljseditorplugin.cpp \
qmlexpressionundercursor.cpp \
qmlfilewizard.cpp \
......@@ -57,7 +54,6 @@ SOURCES += \
quicktoolbar.cpp \
qmljscomponentnamedialog.cpp \
qmljsfindreferences.cpp \
qmljseditoreditable.cpp \
qmljsautocompleter.cpp \
jsfilewizard.cpp \
qmljssnippetprovider.cpp \
......
......@@ -41,10 +41,6 @@ QtcPlugin {
"qmljseditordocument.cpp",
"qmljseditordocument.h",
"qmljseditordocument_p.h",
"qmljseditoreditable.cpp",
"qmljseditoreditable.h",
"qmljseditorfactory.cpp",
"qmljseditorfactory.h",
"qmljseditorplugin.cpp",
"qmljseditorplugin.h",
"qmljsfindreferences.cpp",
......
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qmljseditoreditable.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljscompletionassist.h"
#include "qmljsautocompleter.h"
#include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditorconstants.h>
#include <projectexplorer/projectexplorerconstants.h>
#include <coreplugin/mimedatabase.h>
#include <coreplugin/icore.h>
#include <coreplugin/designmode.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/coreconstants.h>
#include <extensionsystem/pluginmanager.h>
namespace QmlJSEditor {
namespace Internal {
QmlJSEditor::QmlJSEditor()
{
m_context.add(Constants::C_QMLJSEDITOR_ID);
m_context.add(TextEditor::Constants::C_TEXTEDITOR);
m_context.add(ProjectExplorer::Constants::LANG_QMLJS);
setDuplicateSupported(true);
setCommentStyle(Utils::CommentDefinition::CppStyle);
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<Internal::QmlJSCompletionAssistProvider>());
}
bool QmlJSEditor::isDesignModePreferred() const
{
// stay in design mode if we are there
Core::IMode *mode = Core::ModeManager::currentMode();
if (mode && mode->id() == Core::Constants::MODE_DESIGN)
return true;
return false;
}
} // namespace Internal
} // namespace QmlJSEditor
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#ifndef QMLJSEDITOREDITABLE_H
#define QMLJSEDITOREDITABLE_H
#include "qmljseditor_global.h"
#include <utils/uncommentselection.h>
#include <texteditor/basetexteditor.h>
namespace QmlJSEditor {
namespace Internal {
class QmlJSTextEditorWidget;
class QmlJSEditor : public TextEditor::BaseTextEditor
{
Q_OBJECT
public:
QmlJSEditor();
Core::IEditor *duplicate();
bool open(QString *errorString, const QString &fileName, const QString &realFileName);
bool isDesignModePreferred() const;
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLJSEDITOREDITABLE_H
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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.
**
** In addition, as a special exception, Digia gives you certain additional
** rights. These rights are described in the Digia Qt LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "qmljseditorfactory.h"
#include "qmljseditordocument.h"
#include "qmljseditoreditable.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljseditorplugin.h"
#include <qmljstools/qmljstoolsconstants.h>
#include <texteditor/texteditoractionhandler.h>
#include <QCoreApplication>
namespace QmlJSEditor {
namespace Internal {
QmlJSEditorFactory::QmlJSEditorFactory(QObject *parent)
: Core::IEditorFactory(parent)
{
setId(Constants::C_QMLJSEDITOR_ID);
setDisplayName(qApp->translate("OpenWith::Editors", Constants::C_QMLJSEDITOR_DISPLAY_NAME));
addMimeType(QmlJSTools::Constants::QML_MIMETYPE);
addMimeType(QmlJSTools::Constants::QMLPROJECT_MIMETYPE);
addMimeType(QmlJSTools::Constants::QBS_MIMETYPE);
addMimeType(QmlJSTools::Constants::QMLTYPES_MIMETYPE);
addMimeType(QmlJSTools::Constants::JS_MIMETYPE);
addMimeType(QmlJSTools::Constants::JSON_MIMETYPE);
new TextEditor::TextEditorActionHandler(this, Constants::C_QMLJSEDITOR_ID,
TextEditor::TextEditorActionHandler::Format
| TextEditor::TextEditorActionHandler::UnCommentSelection
| TextEditor::TextEditorActionHandler::UnCollapseAll
| TextEditor::TextEditorActionHandler::FollowSymbolUnderCursor);
}
Core::IEditor *QmlJSEditorFactory::createEditor()
{
QmlJSTextEditorWidget *rc = new QmlJSTextEditorWidget(TextEditor::BaseTextDocumentPtr(new QmlJSEditorDocument));
return rc->editor();
}
} // namespace Internal
} // namespace QmlJSEditor
/****************************************************************************
**
** Copyright (C) 2014 Digia Plc and/or its subsidiary(-ies).
** Contact: http://www.qt-project.org/legal
**
** This file is part of Qt Creator.
**
** 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
** a written agreement between you and Digia. For licensing terms and
** conditions see http://qt.digia.com/licensing. For further information
** use the contact form at http://qt.digia.com/contact-us.
**
** 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
** Foundati