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
This diff is collapsed.
......@@ -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
** 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 QMLJSEDITORFACTORY_H
#define QMLJSEDITORFACTORY_H
#include <coreplugin/editormanager/ieditorfactory.h>
namespace QmlJSEditor {
namespace Internal {
class QmlJSEditorFactory : public Core::IEditorFactory
{
Q_OBJECT
public:
QmlJSEditorFactory(QObject *parent);
Core::IEditor *createEditor();
};
} // namespace Internal
} // namespace QmlJSEditor
#endif // QMLJSEDITORFACTORY_H
......@@ -32,7 +32,6 @@
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include "qmljseditordocument.h"
#include "qmljseditorfactory.h"
#include "qmljshoverhandler.h"
#include "qmlfilewizard.h"
#include "jsfilewizard.h"
......@@ -93,7 +92,6 @@ QmlJSEditorPlugin *QmlJSEditorPlugin::m_instance = 0;
QmlJSEditorPlugin::QmlJSEditorPlugin() :
m_modelManager(0),
m_editor(0),
m_quickFixAssistProvider(0),
m_reformatFileAction(0),
m_currentDocument(0),
......@@ -106,7 +104,6 @@ QmlJSEditorPlugin::QmlJSEditorPlugin() :
QmlJSEditorPlugin::~QmlJSEditorPlugin()
{
removeObject(m_editor);
m_instance = 0;
}
......@@ -142,8 +139,7 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
Core::Context context(Constants::C_QMLJSEDITOR_ID);
m_editor = new QmlJSEditorFactory(this);
addObject(m_editor);
addAutoReleasedObject(new QmlJSEditorFactory);
IWizardFactory *wizard = new QmlFileWizard;
wizard->setWizardKind(Core::IWizardFactory::FileWizard);
......
......@@ -43,23 +43,17 @@ namespace Utils { class JsonSchemaManager; }
namespace Core {
class Command;
class ActionContainer;
class ActionManager;
class IEditor;
}
namespace TextEditor { class BaseTextEditor; }
namespace QmlJS { class ModelManagerInterface; }
namespace QmlJSEditor {
class QmlFileWizard;
class QmlJSEditorDocument;
namespace Internal {
class QmlJSEditorFactory;
class QmlJSPreviewRunner;
class QmlJSQuickFixAssistProvider;
class QmlTaskManager;
......@@ -102,7 +96,6 @@ private:
static QmlJSEditorPlugin *m_instance;
QmlJS::ModelManagerInterface *m_modelManager;
QmlJSEditorFactory *m_editor;
QmlJSQuickFixAssistProvider *m_quickFixAssistProvider;
QmlTaskManager *m_qmlTaskManager;
......
......@@ -30,7 +30,6 @@
#include "qmljshoverhandler.h"
#include "qmljseditor.h"
#include "qmljseditordocument.h"
#include "qmljseditoreditable.h"
#include "qmlexpressionundercursor.h"
#include <coreplugin/editormanager/ieditor.h>
......
......@@ -29,7 +29,7 @@
#include "qmljsoutline.h"
#include "qmloutlinemodel.h"
#include "qmljseditoreditable.h"
#include "qmljseditor.h"
#include "qmljsoutlinetreeview.h"
#include <coreplugin/find/itemviewfind.h>
......
......@@ -28,6 +28,7 @@
****************************************************************************/
#include "qmltaskmanager.h"
#include "qmljseditor.h"
#include "qmljseditorconstants.h"
#include <coreplugin/idocument.h>
......@@ -35,16 +36,17 @@
#include <projectexplorer/taskhub.h>
#include <qmljs/qmljsmodelmanagerinterface.h>
#include <qmljs/qmljscontext.h>
#include <qmljs/qmljsconstants.h>
#include <qmljs/qmljslink.h>
#include <qmljs/qmljscheck.h>
#include <qmljseditor/qmljseditor.h>
#include <qmljseditor/qmljseditoreditable.h>
#include <utils/runextensions.h>
#include <QDebug>
#include <QtConcurrentRun>
#include <utils/runextensions.h>
using namespace ProjectExplorer;
using namespace QmlJS;
using namespace Utils;
namespace QmlJSEditor {
namespace Internal {
......@@ -65,23 +67,18 @@ QmlTaskManager::QmlTaskManager(QObject *parent) :
SLOT(updateMessagesNow()));
}
static QList<ProjectExplorer::Task> convertToTasks(const QList<DiagnosticMessage> &messages, const Utils::FileName &fileName, Core::Id category)
static QList<Task> convertToTasks(const QList<DiagnosticMessage> &messages, const FileName &fileName, Core::Id category)
{
QList<ProjectExplorer::Task> result;
QList<Task> result;
foreach (const DiagnosticMessage &msg, messages) {
ProjectExplorer::Task::TaskType type
= msg.isError() ? ProjectExplorer::Task::Error
: ProjectExplorer::Task::Warning;
ProjectExplorer::Task task(type, msg.message, fileName, msg.loc.startLine,
category);
Task::TaskType type = msg.isError() ? Task::Error : Task::Warning;
Task task(type, msg.message, fileName, msg.loc.startLine, category);
result += task;
}
return result;
}
static QList<ProjectExplorer::Task> convertToTasks(const QList<StaticAnalysis::Message> &messages, const Utils::FileName &fileName, Core::Id category)
static QList<Task> convertToTasks(const QList<StaticAnalysis::Message> &messages, const FileName &fileName, Core::Id category)
{
QList<DiagnosticMessage> diagnostics;
foreach (const StaticAnalysis::Message &msg, messages)
......@@ -111,18 +108,18 @@ void QmlTaskManager::collectMessages(
result.fileName = fileName;
if (document->language().isFullySupportedLanguage()) {
result.tasks = convertToTasks(document->diagnosticMessages(),
Utils::FileName::fromString(fileName),
Core::Id(Constants::TASK_CATEGORY_QML));
FileName::fromString(fileName),
Constants::TASK_CATEGORY_QML);
if (updateSemantic) {
result.tasks += convertToTasks(linkMessages.value(fileName),
Utils::FileName::fromString(fileName),
Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS));
FileName::fromString(fileName),
Constants::TASK_CATEGORY_QML_ANALYSIS);
Check checker(document, context);
result.tasks += convertToTasks(checker(),
Utils::FileName::fromString(fileName),
Core::Id(Constants::TASK_CATEGORY_QML_ANALYSIS));
FileName::fromString(fileName),
Constants::TASK_CATEGORY_QML_ANALYSIS);
}
}
......@@ -175,7 +172,7 @@ void QmlTaskManager::displayResults(int begin, int end)
{
for (int i = begin; i < end; ++i) {
FileErrorMessages result = m_messageCollector.resultAt(i);
foreach (const ProjectExplorer::Task &task, result.tasks) {
foreach (const Task &task, result.tasks) {
insertTask(task);
}
}
......@@ -187,29 +184,29 @@ void QmlTaskManager::displayAllResults()
m_updatingSemantic = false;
}
void QmlTaskManager::insertTask(const ProjectExplorer::Task &task)
void QmlTaskManager::insertTask(const Task &task)
{
QList<ProjectExplorer::Task> tasks = m_docsWithTasks.value(task.file.toString());
QList<Task> tasks = m_docsWithTasks.value(task.file.toString());
tasks.append(task);
m_docsWithTasks.insert(task.file.toString(), tasks);
ProjectExplorer::TaskHub::addTask(task);
TaskHub::addTask(task);
}
void QmlTaskManager::removeTasksForFile(const QString &fileName)
{
if (m_docsWithTasks.contains(fileName)) {
const QList<ProjectExplorer::Task> tasks = m_docsWithTasks.value(fileName);
foreach (const ProjectExplorer::Task &task, tasks)
ProjectExplorer::TaskHub::removeTask(task);
const QList<Task> tasks = m_docsWithTasks.value(fileName);
foreach (const Task &task, tasks)
TaskHub::removeTask(task);
m_docsWithTasks.remove(fileName);
}
}
void QmlTaskManager::removeAllTasks(bool clearSemantic)
{
ProjectExplorer::TaskHub::clearTasks(Constants::TASK_CATEGORY_QML);
TaskHub::clearTasks(Constants::TASK_CATEGORY_QML);
if (clearSemantic)
ProjectExplorer::TaskHub::clearTasks(Constants::TASK_CATEGORY_QML_ANALYSIS);
TaskHub::clearTasks(Constants::TASK_CATEGORY_QML_ANALYSIS);
m_docsWithTasks.clear();
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment