forked from qt-creator/qt-creator
Android: Use a BaseEditorFactory derived class for JavaEditor
Change-Id: Ifc923177744af5058b22fac7fff2f2345cc99135 Reviewed-by: Christian Stenger <christian.stenger@digia.com>
This commit is contained in:
@@ -33,11 +33,14 @@
|
||||
#include "androidconstants.h"
|
||||
#include "javacompletionassistprovider.h"
|
||||
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <utils/uncommentselection.h>
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
#include <texteditor/texteditoractionhandler.h>
|
||||
#include <texteditor/texteditorconstants.h>
|
||||
#include <texteditor/normalindenter.h>
|
||||
#include <texteditor/highlighterutils.h>
|
||||
#include <coreplugin/mimedatabase.h>
|
||||
#include <extensionsystem/pluginmanager.h>
|
||||
|
||||
#include <QFileInfo>
|
||||
@@ -49,32 +52,36 @@ namespace Internal {
|
||||
// JavaEditor
|
||||
//
|
||||
|
||||
JavaEditor::JavaEditor()
|
||||
class JavaEditor : public TextEditor::BaseTextEditor
|
||||
{
|
||||
addContext(Constants::C_JAVA_EDITOR);
|
||||
setDuplicateSupported(true);
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
|
||||
setEditorCreator([]() { return new JavaEditor; });
|
||||
setDocumentCreator([]() { return new JavaDocument; });
|
||||
|
||||
setWidgetCreator([]() -> TextEditor::BaseTextEditorWidget * {
|
||||
auto widget = new TextEditor::BaseTextEditorWidget;
|
||||
widget->setAutoCompleter(new JavaAutoCompleter);
|
||||
return widget;
|
||||
});
|
||||
}
|
||||
public:
|
||||
JavaEditor()
|
||||
{
|
||||
addContext(Constants::C_JAVA_EDITOR);
|
||||
setDuplicateSupported(true);
|
||||
setCommentStyle(Utils::CommentDefinition::CppStyle);
|
||||
setCompletionAssistProvider(ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>());
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//
|
||||
// JavaDocument
|
||||
//
|
||||
|
||||
class JavaDocument : public TextEditor::BaseTextDocument
|
||||
{
|
||||
public:
|
||||
JavaDocument();
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
};
|
||||
|
||||
|
||||
JavaDocument::JavaDocument()
|
||||
{
|
||||
setId(Constants::JAVA_EDITOR_ID);
|
||||
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
|
||||
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(Core::MimeDatabase::findByType(QLatin1String(Constants::JAVA_MIMETYPE))));
|
||||
setIndenter(new JavaIndenter);
|
||||
}
|
||||
|
||||
@@ -97,16 +104,17 @@ QString JavaDocument::suggestedFileName() const
|
||||
|
||||
JavaEditorFactory::JavaEditorFactory()
|
||||
{
|
||||
setId(Android::Constants::JAVA_EDITOR_ID);
|
||||
setId(Constants::JAVA_EDITOR_ID);
|
||||
setDisplayName(tr("Java Editor"));
|
||||
addMimeType(Android::Constants::JAVA_MIMETYPE);
|
||||
new TextEditor::TextEditorActionHandler(this, Constants::C_JAVA_EDITOR,
|
||||
TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||
}
|
||||
addMimeType(Constants::JAVA_MIMETYPE);
|
||||
|
||||
Core::IEditor *JavaEditorFactory::createEditor()
|
||||
{
|
||||
return new JavaEditor;
|
||||
setEditorCreator([]() { return new JavaEditor; });
|
||||
setDocumentCreator([]() { return new JavaDocument; });
|
||||
setAutoCompleterCreator([]() { return new JavaAutoCompleter; });
|
||||
setGenericSyntaxHighlighter(QLatin1String(Constants::JAVA_MIMETYPE));
|
||||
|
||||
setEditorActionHandlers(Constants::C_JAVA_EDITOR,
|
||||
TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||
}
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -30,42 +30,17 @@
|
||||
#ifndef JAVAEDITOR_H
|
||||
#define JAVAEDITOR_H
|
||||
|
||||
#include <texteditor/basetextdocument.h>
|
||||
#include <texteditor/basetexteditor.h>
|
||||
#include <utils/uncommentselection.h>
|
||||
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||
|
||||
namespace Android {
|
||||
namespace Internal {
|
||||
|
||||
class JavaEditor : public TextEditor::BaseTextEditor
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JavaEditor();
|
||||
|
||||
TextEditor::CompletionAssistProvider *completionAssistProvider();
|
||||
};
|
||||
|
||||
class JavaDocument : public TextEditor::BaseTextDocument
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JavaDocument();
|
||||
QString defaultPath() const;
|
||||
QString suggestedFileName() const;
|
||||
};
|
||||
|
||||
|
||||
class JavaEditorFactory : public Core::IEditorFactory
|
||||
class JavaEditorFactory : public TextEditor::BaseTextEditorFactory
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JavaEditorFactory();
|
||||
Core::IEditor *createEditor();
|
||||
};
|
||||
|
||||
} // namespace Internal
|
||||
|
||||
@@ -7228,6 +7228,7 @@ BaseTextDocumentPtr BaseTextEditor::ensureDocument()
|
||||
BaseTextEditorFactory::BaseTextEditorFactory(QObject *parent)
|
||||
: IEditorFactory(parent)
|
||||
{
|
||||
m_widgetCreator = []() { return new BaseTextEditorWidget; };
|
||||
}
|
||||
|
||||
void BaseTextEditorFactory::setDocumentCreator(const BaseTextDocumentCreator &creator)
|
||||
@@ -7255,6 +7256,20 @@ void BaseTextEditorFactory::setSyntaxHighlighterCreator(const SyntaxHighLighterC
|
||||
m_syntaxHighlighterCreator = creator;
|
||||
}
|
||||
|
||||
void BaseTextEditorFactory::setGenericSyntaxHighlighter(const QString &mimeType)
|
||||
{
|
||||
m_syntaxHighlighterCreator = [this, mimeType]() -> SyntaxHighlighter * {
|
||||
Highlighter *highlighter = new TextEditor::Highlighter();
|
||||
setMimeTypeForHighlighter(highlighter, Core::MimeDatabase::findByType(mimeType));
|
||||
return highlighter;
|
||||
};
|
||||
}
|
||||
|
||||
void BaseTextEditorFactory::setAutoCompleterCreator(const AutoCompleterCreator &creator)
|
||||
{
|
||||
m_autoCompleterCreator = creator;
|
||||
}
|
||||
|
||||
void BaseTextEditorFactory::setEditorActionHandlers(Id contextId, uint optionalActions)
|
||||
{
|
||||
new TextEditorActionHandler(this, contextId, optionalActions);
|
||||
@@ -7298,6 +7313,9 @@ BaseTextEditor *BaseTextEditorFactory::createEditorHelper(const BaseTextDocument
|
||||
|
||||
widget->d->m_codeAssistant.configure(editor);
|
||||
|
||||
if (m_autoCompleterCreator)
|
||||
widget->setAutoCompleter(m_autoCompleterCreator());
|
||||
|
||||
return editor;
|
||||
}
|
||||
|
||||
|
||||
@@ -623,6 +623,7 @@ private:
|
||||
|
||||
typedef std::function<SyntaxHighlighter *()> SyntaxHighLighterCreator;
|
||||
typedef std::function<Indenter *()> IndenterCreator;
|
||||
typedef std::function<AutoCompleter *()> AutoCompleterCreator;
|
||||
|
||||
class TEXTEDITOR_EXPORT BaseTextEditorFactory : public Core::IEditorFactory
|
||||
{
|
||||
@@ -636,12 +637,13 @@ public:
|
||||
void setEditorCreator(const BaseTextEditorCreator &creator);
|
||||
void setIndenterCreator(const IndenterCreator &creator);
|
||||
void setSyntaxHighlighterCreator(const SyntaxHighLighterCreator &creator);
|
||||
void setGenericSyntaxHighlighter(const QString &mimeType);
|
||||
void setAutoCompleterCreator(const AutoCompleterCreator &creator);
|
||||
|
||||
void setEditorActionHandlers(Core::Id contextId, uint optionalActions);
|
||||
void setEditorActionHandlers(uint optionalActions);
|
||||
|
||||
BaseTextEditor *duplicateTextEditor(BaseTextEditor *);
|
||||
|
||||
private:
|
||||
Core::IEditor *createEditor();
|
||||
BaseTextEditor *createEditorHelper(const BaseTextDocumentPtr &doc);
|
||||
@@ -649,6 +651,7 @@ private:
|
||||
BaseTextDocumentCreator m_documentCreator;
|
||||
BaseTextEditorWidgetCreator m_widgetCreator;
|
||||
BaseTextEditorCreator m_editorCreator;
|
||||
AutoCompleterCreator m_autoCompleterCreator;
|
||||
IndenterCreator m_indenterCreator;
|
||||
SyntaxHighLighterCreator m_syntaxHighlighterCreator;
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user