forked from qt-creator/qt-creator
Android: Add minimal Java editing support
Indentation for blocks '{'. '}' and completion for keywords. TODO: "New File" is missing, TODO: probably needs some tweaks to the indentation. Task-number: QTCREATORBUG-11220 Change-Id: I758b3815e47d1427d39c0248eb16e39ffb7a29fb Reviewed-by: Eskil Abrahamsen Blomfeldt <eskil.abrahamsen-blomfeldt@digia.com>
This commit is contained in:
8
src/plugins/android/Java.mimetypes.xml
Normal file
8
src/plugins/android/Java.mimetypes.xml
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
|
||||||
|
<mime-type type="text/x-java">
|
||||||
|
<sub-class-of type="text/x-csrc"/>
|
||||||
|
<comment>Java Source file</comment>
|
||||||
|
<glob pattern="*.java"/>
|
||||||
|
</mime-type>
|
||||||
|
</mime-info>
|
@@ -49,7 +49,12 @@ HEADERS += \
|
|||||||
createandroidmanifestwizard.h \
|
createandroidmanifestwizard.h \
|
||||||
androidpotentialkit.h \
|
androidpotentialkit.h \
|
||||||
androidextralibrarylistmodel.h \
|
androidextralibrarylistmodel.h \
|
||||||
androidsignaloperation.h
|
androidsignaloperation.h \
|
||||||
|
javaeditor.h \
|
||||||
|
javaeditorfactory.h \
|
||||||
|
javaindenter.h \
|
||||||
|
javaautocompleter.h \
|
||||||
|
javacompletionassistprovider.h
|
||||||
|
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
androidconfigurations.cpp \
|
androidconfigurations.cpp \
|
||||||
@@ -93,7 +98,12 @@ SOURCES += \
|
|||||||
createandroidmanifestwizard.cpp \
|
createandroidmanifestwizard.cpp \
|
||||||
androidpotentialkit.cpp \
|
androidpotentialkit.cpp \
|
||||||
androidextralibrarylistmodel.cpp \
|
androidextralibrarylistmodel.cpp \
|
||||||
androidsignaloperation.cpp
|
androidsignaloperation.cpp \
|
||||||
|
javaeditor.cpp \
|
||||||
|
javaeditorfactory.cpp \
|
||||||
|
javaindenter.cpp \
|
||||||
|
javaautocompleter.cpp \
|
||||||
|
javacompletionassistprovider.cpp
|
||||||
|
|
||||||
FORMS += \
|
FORMS += \
|
||||||
androidsettingswidget.ui \
|
androidsettingswidget.ui \
|
||||||
|
@@ -112,6 +112,16 @@ QtcPlugin {
|
|||||||
"certificatesmodel.h",
|
"certificatesmodel.h",
|
||||||
"createandroidmanifestwizard.cpp",
|
"createandroidmanifestwizard.cpp",
|
||||||
"createandroidmanifestwizard.h",
|
"createandroidmanifestwizard.h",
|
||||||
|
"javaautocompleter.cpp",
|
||||||
|
"javaautocompleter.h",
|
||||||
|
"javacompletionassistprovider.cpp",
|
||||||
|
"javacompletionassistprovider.h",
|
||||||
|
"javaeditor.cpp",
|
||||||
|
"javaeditor.h",
|
||||||
|
"javaeditorfactory.cpp",
|
||||||
|
"javaeditorfactory.h",
|
||||||
|
"javaindenter.cpp",
|
||||||
|
"javaindenter.h",
|
||||||
"javaparser.cpp",
|
"javaparser.cpp",
|
||||||
"javaparser.h",
|
"javaparser.h",
|
||||||
]
|
]
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
<RCC>
|
<RCC>
|
||||||
<qresource prefix="/android">
|
<qresource prefix="/android">
|
||||||
<file>images/QtAndroid.png</file>
|
<file>images/QtAndroid.png</file>
|
||||||
|
<file>Java.mimetypes.xml</file>
|
||||||
</qresource>
|
</qresource>
|
||||||
</RCC>
|
</RCC>
|
||||||
|
@@ -67,6 +67,9 @@ const char ANDROID_MANIFEST_EDITOR_ID[] = "Android.AndroidManifestEditor.Id";
|
|||||||
const char ANDROID_MANIFEST_EDITOR_CONTEXT[] = "Android.AndroidManifestEditor.Id";
|
const char ANDROID_MANIFEST_EDITOR_CONTEXT[] = "Android.AndroidManifestEditor.Id";
|
||||||
|
|
||||||
const char ANDROID_BUILDDIRECTORY[] = "android-build";
|
const char ANDROID_BUILDDIRECTORY[] = "android-build";
|
||||||
|
const char JAVA_EDITOR_ID[] = "java.editor";
|
||||||
|
const char C_JAVA_EDITOR[] = "Java Editor";
|
||||||
|
const char JAVA_MIMETYPE[] = "text/x-java";
|
||||||
} // namespace Constants;
|
} // namespace Constants;
|
||||||
} // namespace Android
|
} // namespace Android
|
||||||
|
|
||||||
|
@@ -46,6 +46,8 @@
|
|||||||
#include "androidgdbserverkitinformation.h"
|
#include "androidgdbserverkitinformation.h"
|
||||||
#include "androidmanifesteditorfactory.h"
|
#include "androidmanifesteditorfactory.h"
|
||||||
#include "androidpotentialkit.h"
|
#include "androidpotentialkit.h"
|
||||||
|
#include "javaeditorfactory.h"
|
||||||
|
#include "javacompletionassistprovider.h"
|
||||||
#ifdef HAVE_QBS
|
#ifdef HAVE_QBS
|
||||||
# include "androidqbspropertyprovider.h"
|
# include "androidqbspropertyprovider.h"
|
||||||
#endif
|
#endif
|
||||||
@@ -83,6 +85,8 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
|
|||||||
addAutoReleasedObject(new Internal::AndroidDeployConfigurationFactory);
|
addAutoReleasedObject(new Internal::AndroidDeployConfigurationFactory);
|
||||||
addAutoReleasedObject(new Internal::AndroidDeviceFactory);
|
addAutoReleasedObject(new Internal::AndroidDeviceFactory);
|
||||||
addAutoReleasedObject(new Internal::AndroidPotentialKit);
|
addAutoReleasedObject(new Internal::AndroidPotentialKit);
|
||||||
|
addAutoReleasedObject(new Internal::JavaEditorFactory);
|
||||||
|
addAutoReleasedObject(new Internal::JavaCompletionAssistProvider);
|
||||||
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
|
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
|
||||||
|
|
||||||
// AndroidManifest.xml editor
|
// AndroidManifest.xml editor
|
||||||
@@ -99,6 +103,9 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
|
|||||||
}
|
}
|
||||||
addAutoReleasedObject(new Internal::AndroidManifestEditorFactory);
|
addAutoReleasedObject(new Internal::AndroidManifestEditorFactory);
|
||||||
|
|
||||||
|
if (!Core::MimeDatabase::addMimeTypes(QLatin1String(":android/Java.mimetypes.xml"), errorMessage))
|
||||||
|
return false;
|
||||||
|
|
||||||
connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()),
|
connect(ProjectExplorer::KitManager::instance(), SIGNAL(kitsLoaded()),
|
||||||
this, SLOT(kitsRestored()));
|
this, SLOT(kitsRestored()));
|
||||||
|
|
||||||
|
44
src/plugins/android/javaautocompleter.cpp
Normal file
44
src/plugins/android/javaautocompleter.cpp
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "javaautocompleter.h"
|
||||||
|
|
||||||
|
using namespace Android;
|
||||||
|
using namespace Android::Internal;
|
||||||
|
|
||||||
|
JavaAutoCompleter::JavaAutoCompleter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JavaAutoCompleter::contextAllowsAutoParentheses(const QTextCursor &cursor, const QString &textToInsert) const
|
||||||
|
{
|
||||||
|
Q_UNUSED(cursor)
|
||||||
|
Q_UNUSED(textToInsert)
|
||||||
|
return true;
|
||||||
|
}
|
51
src/plugins/android/javaautocompleter.h
Normal file
51
src/plugins/android/javaautocompleter.h
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 JAVAAUTOCOMPLETER_H
|
||||||
|
#define JAVAAUTOCOMPLETER_H
|
||||||
|
|
||||||
|
#include <texteditor/autocompleter.h>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class JavaAutoCompleter : public TextEditor::AutoCompleter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
// TODO What does the base class do?
|
||||||
|
// I only need the contextAllowsAutoParenthses change
|
||||||
|
JavaAutoCompleter();
|
||||||
|
bool contextAllowsAutoParentheses(const QTextCursor &cursor,
|
||||||
|
const QString &textToInsert = QString()) const;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // JAVAAUTOCOMPLETER_H
|
120
src/plugins/android/javacompletionassistprovider.cpp
Normal file
120
src/plugins/android/javacompletionassistprovider.cpp
Normal file
@@ -0,0 +1,120 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "javacompletionassistprovider.h"
|
||||||
|
#include "androidconstants.h"
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/keywordscompletionassist.h>
|
||||||
|
|
||||||
|
using namespace Android;
|
||||||
|
using namespace Android::Internal;
|
||||||
|
|
||||||
|
static const char *const keywords[] = {
|
||||||
|
"abstract",
|
||||||
|
"continue",
|
||||||
|
"for",
|
||||||
|
"new",
|
||||||
|
"switch",
|
||||||
|
"assert",
|
||||||
|
"default",
|
||||||
|
"goto",
|
||||||
|
"package",
|
||||||
|
"synchronized",
|
||||||
|
"boolean",
|
||||||
|
"do",
|
||||||
|
"if",
|
||||||
|
"private",
|
||||||
|
"this",
|
||||||
|
"break",
|
||||||
|
"double",
|
||||||
|
"implements",
|
||||||
|
"protected",
|
||||||
|
"throw"
|
||||||
|
"byte",
|
||||||
|
"else",
|
||||||
|
"import",
|
||||||
|
"public",
|
||||||
|
"throws",
|
||||||
|
"case",
|
||||||
|
"enum",
|
||||||
|
"instanceof",
|
||||||
|
"return",
|
||||||
|
"transient",
|
||||||
|
"catch",
|
||||||
|
"extends",
|
||||||
|
"int",
|
||||||
|
"short",
|
||||||
|
"try",
|
||||||
|
"char",
|
||||||
|
"final",
|
||||||
|
"interface",
|
||||||
|
"static",
|
||||||
|
"void",
|
||||||
|
"class",
|
||||||
|
"finally",
|
||||||
|
"long",
|
||||||
|
"strictfp",
|
||||||
|
"volatile",
|
||||||
|
"const",
|
||||||
|
"float",
|
||||||
|
"native",
|
||||||
|
"super",
|
||||||
|
"while",
|
||||||
|
0
|
||||||
|
};
|
||||||
|
|
||||||
|
JavaCompletionAssistProvider::JavaCompletionAssistProvider()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaCompletionAssistProvider::~JavaCompletionAssistProvider()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaCompletionAssistProvider::init() const
|
||||||
|
{
|
||||||
|
for (uint i = 0; i < sizeof keywords / sizeof keywords[0] - 1; i++)
|
||||||
|
m_keywords.append(QLatin1String(keywords[i]));
|
||||||
|
}
|
||||||
|
|
||||||
|
bool JavaCompletionAssistProvider::supportsEditor(const Core::Id &editorId) const
|
||||||
|
{
|
||||||
|
return editorId == Constants::JAVA_EDITOR_ID;
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::IAssistProcessor *JavaCompletionAssistProvider::createProcessor() const
|
||||||
|
{
|
||||||
|
if (m_keywords.isEmpty())
|
||||||
|
init();
|
||||||
|
TextEditor::Keywords keywords = TextEditor::Keywords(m_keywords,
|
||||||
|
QStringList(),
|
||||||
|
QMap<QString, QStringList>());
|
||||||
|
return new TextEditor::KeywordsCompletionAssistProcessor(keywords);
|
||||||
|
}
|
60
src/plugins/android/javacompletionassistprovider.h
Normal file
60
src/plugins/android/javacompletionassistprovider.h
Normal file
@@ -0,0 +1,60 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 JAVACOMPLETIONASSISTPROVIDER_H
|
||||||
|
#define JAVACOMPLETIONASSISTPROVIDER_H
|
||||||
|
|
||||||
|
#include <texteditor/codeassist/completionassistprovider.h>
|
||||||
|
|
||||||
|
#include <QStringList>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class JavaCompletionAssistProvider : public TextEditor::CompletionAssistProvider
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
public:
|
||||||
|
JavaCompletionAssistProvider();
|
||||||
|
~JavaCompletionAssistProvider();
|
||||||
|
|
||||||
|
void init() const;
|
||||||
|
|
||||||
|
bool supportsEditor(const Core::Id &editorId) const;
|
||||||
|
TextEditor::IAssistProcessor *createProcessor() const;
|
||||||
|
|
||||||
|
private:
|
||||||
|
mutable QStringList m_keywords;
|
||||||
|
};
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
#endif // JAVACOMPLETIONASSISTPROVIDER_H
|
134
src/plugins/android/javaeditor.cpp
Normal file
134
src/plugins/android/javaeditor.cpp
Normal file
@@ -0,0 +1,134 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "javaeditor.h"
|
||||||
|
#include "javaindenter.h"
|
||||||
|
#include "javaautocompleter.h"
|
||||||
|
#include "androidconstants.h"
|
||||||
|
#include "javacompletionassistprovider.h"
|
||||||
|
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
#include <texteditor/texteditorconstants.h>
|
||||||
|
#include <texteditor/normalindenter.h>
|
||||||
|
#include <texteditor/highlighterutils.h>
|
||||||
|
#include <coreplugin/mimedatabase.h>
|
||||||
|
#include <extensionsystem/pluginmanager.h>
|
||||||
|
|
||||||
|
#include <QFileInfo>
|
||||||
|
|
||||||
|
using namespace Android;
|
||||||
|
using namespace Android::Internal;
|
||||||
|
|
||||||
|
//
|
||||||
|
// JavaEditor
|
||||||
|
//
|
||||||
|
|
||||||
|
JavaEditor::JavaEditor(JavaEditorWidget *editor)
|
||||||
|
: BaseTextEditor(editor)
|
||||||
|
{
|
||||||
|
setContext(Core::Context(Constants::C_JAVA_EDITOR,
|
||||||
|
TextEditor::Constants::C_TEXTEDITOR));
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IEditor *JavaEditor::duplicate()
|
||||||
|
{
|
||||||
|
JavaEditorWidget *ret = new JavaEditorWidget(
|
||||||
|
qobject_cast<JavaEditorWidget*>(editorWidget()));
|
||||||
|
TextEditor::TextEditorSettings::initializeEditor(ret);
|
||||||
|
return ret->editor();
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::Id JavaEditor::id() const
|
||||||
|
{
|
||||||
|
return Core::Id(Constants::JAVA_EDITOR_ID);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::CompletionAssistProvider *JavaEditor::completionAssistProvider()
|
||||||
|
{
|
||||||
|
return ExtensionSystem::PluginManager::getObject<JavaCompletionAssistProvider>();
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// JavaEditorWidget
|
||||||
|
//
|
||||||
|
|
||||||
|
JavaEditorWidget::JavaEditorWidget(QWidget *parent)
|
||||||
|
: BaseTextEditorWidget(new JavaDocument(), parent)
|
||||||
|
{
|
||||||
|
ctor();
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaEditorWidget::JavaEditorWidget(JavaEditorWidget *other)
|
||||||
|
: BaseTextEditorWidget(other)
|
||||||
|
{
|
||||||
|
ctor();
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaEditorWidget::ctor()
|
||||||
|
{
|
||||||
|
m_commentDefinition.clearCommentStyles();
|
||||||
|
m_commentDefinition.singleLine = QLatin1String("//");
|
||||||
|
m_commentDefinition.multiLineStart = QLatin1String("/*");
|
||||||
|
m_commentDefinition.multiLineEnd = QLatin1String("*/");
|
||||||
|
setAutoCompleter(new JavaAutoCompleter);
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaEditorWidget::unCommentSelection()
|
||||||
|
{
|
||||||
|
Utils::unCommentSelection(this, m_commentDefinition);
|
||||||
|
}
|
||||||
|
|
||||||
|
TextEditor::BaseTextEditor *JavaEditorWidget::createEditor()
|
||||||
|
{
|
||||||
|
return new JavaEditor(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
//
|
||||||
|
// JavaDocument
|
||||||
|
//
|
||||||
|
|
||||||
|
JavaDocument::JavaDocument()
|
||||||
|
: TextEditor::BaseTextDocument()
|
||||||
|
{
|
||||||
|
setMimeType(QLatin1String(Constants::JAVA_MIMETYPE));
|
||||||
|
setSyntaxHighlighter(TextEditor::createGenericSyntaxHighlighter(Core::MimeDatabase::findByType(QLatin1String(Constants::JAVA_MIMETYPE))));
|
||||||
|
setIndenter(new JavaIndenter);
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JavaDocument::defaultPath() const
|
||||||
|
{
|
||||||
|
QFileInfo fi(filePath());
|
||||||
|
return fi.absolutePath();
|
||||||
|
}
|
||||||
|
|
||||||
|
QString JavaDocument::suggestedFileName() const
|
||||||
|
{
|
||||||
|
QFileInfo fi(filePath());
|
||||||
|
return fi.fileName();
|
||||||
|
}
|
88
src/plugins/android/javaeditor.h
Normal file
88
src/plugins/android/javaeditor.h
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 JAVAEDITOR_H
|
||||||
|
#define JAVAEDITOR_H
|
||||||
|
|
||||||
|
#include <texteditor/basetextdocument.h>
|
||||||
|
#include <texteditor/basetexteditor.h>
|
||||||
|
#include <utils/uncommentselection.h>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class JavaEditorFactory;
|
||||||
|
class JavaEditorWidget;
|
||||||
|
|
||||||
|
class JavaEditor : public TextEditor::BaseTextEditor
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaEditor(JavaEditorWidget *);
|
||||||
|
|
||||||
|
bool duplicateSupported() const { return true; }
|
||||||
|
Core::IEditor *duplicate();
|
||||||
|
Core::Id id() const;
|
||||||
|
TextEditor::CompletionAssistProvider *completionAssistProvider();
|
||||||
|
};
|
||||||
|
|
||||||
|
class JavaEditorWidget : public TextEditor::BaseTextEditorWidget
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaEditorWidget(QWidget *parent = 0);
|
||||||
|
JavaEditorWidget(JavaEditorWidget *other);
|
||||||
|
|
||||||
|
void unCommentSelection();
|
||||||
|
|
||||||
|
protected:
|
||||||
|
TextEditor::BaseTextEditor *createEditor();
|
||||||
|
|
||||||
|
private:
|
||||||
|
JavaEditorWidget(BaseTextEditorWidget *); // avoid stupidity
|
||||||
|
void ctor();
|
||||||
|
Utils::CommentDefinition m_commentDefinition;
|
||||||
|
};
|
||||||
|
|
||||||
|
class JavaDocument : public TextEditor::BaseTextDocument
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaDocument();
|
||||||
|
QString defaultPath() const;
|
||||||
|
QString suggestedFileName() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
} // namespace Internal
|
||||||
|
} // namespace QmakeProjectManager
|
||||||
|
|
||||||
|
#endif // JAVAEDITOR_H
|
54
src/plugins/android/javaeditorfactory.cpp
Normal file
54
src/plugins/android/javaeditorfactory.cpp
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "javaeditorfactory.h"
|
||||||
|
#include "javaeditor.h"
|
||||||
|
#include "androidconstants.h"
|
||||||
|
|
||||||
|
#include <texteditor/texteditoractionhandler.h>
|
||||||
|
#include <texteditor/texteditorsettings.h>
|
||||||
|
|
||||||
|
using namespace Android;
|
||||||
|
using namespace Android::Internal;
|
||||||
|
|
||||||
|
JavaEditorFactory::JavaEditorFactory()
|
||||||
|
{
|
||||||
|
setId(Android::Constants::JAVA_EDITOR_ID);
|
||||||
|
setDisplayName(tr("Java Editor"));
|
||||||
|
addMimeType(Android::Constants::JAVA_MIMETYPE);
|
||||||
|
new TextEditor::TextEditorActionHandler(this, Constants::C_JAVA_EDITOR,
|
||||||
|
TextEditor::TextEditorActionHandler::UnCommentSelection);
|
||||||
|
}
|
||||||
|
|
||||||
|
Core::IEditor *JavaEditorFactory::createEditor()
|
||||||
|
{
|
||||||
|
JavaEditorWidget *editor = new JavaEditorWidget;
|
||||||
|
TextEditor::TextEditorSettings::initializeEditor(editor);
|
||||||
|
return editor->editor();
|
||||||
|
}
|
48
src/plugins/android/javaeditorfactory.h
Normal file
48
src/plugins/android/javaeditorfactory.h
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 JAVAEDITORFACTORY_H
|
||||||
|
#define JAVAEDITORFACTORY_H
|
||||||
|
#include <coreplugin/editormanager/ieditorfactory.h>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
|
||||||
|
class JavaEditorFactory : public Core::IEditorFactory
|
||||||
|
{
|
||||||
|
Q_OBJECT
|
||||||
|
|
||||||
|
public:
|
||||||
|
JavaEditorFactory();
|
||||||
|
Core::IEditor *createEditor();
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // JAVAEDITORFACTORY_H
|
91
src/plugins/android/javaindenter.cpp
Normal file
91
src/plugins/android/javaindenter.cpp
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 "javaindenter.h"
|
||||||
|
#include <texteditor/tabsettings.h>
|
||||||
|
|
||||||
|
#include <QTextDocument>
|
||||||
|
|
||||||
|
using namespace Android;
|
||||||
|
using namespace Android::Internal;
|
||||||
|
|
||||||
|
JavaIndenter::JavaIndenter()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
JavaIndenter::~JavaIndenter()
|
||||||
|
{}
|
||||||
|
|
||||||
|
bool JavaIndenter::isElectricCharacter(const QChar &ch) const
|
||||||
|
{
|
||||||
|
if (ch == QLatin1Char('{')
|
||||||
|
|| ch == QLatin1Char('}')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
void JavaIndenter::indentBlock(QTextDocument *doc,
|
||||||
|
const QTextBlock &block,
|
||||||
|
const QChar &typedChar,
|
||||||
|
const TextEditor::TabSettings &tabSettings)
|
||||||
|
{
|
||||||
|
// At beginning: Leave as is.
|
||||||
|
if (block == doc->begin())
|
||||||
|
return;
|
||||||
|
|
||||||
|
const int tabsize = tabSettings.m_indentSize;
|
||||||
|
|
||||||
|
QTextBlock previous = block.previous();
|
||||||
|
QString previousText = previous.text();
|
||||||
|
while (previousText.trimmed().isEmpty()) {
|
||||||
|
previous = previous.previous();
|
||||||
|
if (previous == doc->begin())
|
||||||
|
return;
|
||||||
|
previousText = previous.text();
|
||||||
|
}
|
||||||
|
|
||||||
|
int adjust = 0;
|
||||||
|
if (previousText.contains(QLatin1Char('{')))
|
||||||
|
adjust = tabsize;
|
||||||
|
|
||||||
|
if (block.text().contains(QLatin1Char('}')) || typedChar == QLatin1Char('}'))
|
||||||
|
adjust += -tabsize;
|
||||||
|
|
||||||
|
// Count the indentation of the previous line.
|
||||||
|
int i = 0;
|
||||||
|
while (i < previousText.size()) {
|
||||||
|
if (!previousText.at(i).isSpace()) {
|
||||||
|
tabSettings.indentLine(block, tabSettings.columnAt(previousText, i)
|
||||||
|
+ adjust);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
++i;
|
||||||
|
}
|
||||||
|
}
|
53
src/plugins/android/javaindenter.h
Normal file
53
src/plugins/android/javaindenter.h
Normal file
@@ -0,0 +1,53 @@
|
|||||||
|
/****************************************************************************
|
||||||
|
**
|
||||||
|
** 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 JAVAINDENTER_H
|
||||||
|
#define JAVAINDENTER_H
|
||||||
|
|
||||||
|
#include <texteditor/indenter.h>
|
||||||
|
|
||||||
|
namespace Android {
|
||||||
|
namespace Internal {
|
||||||
|
class JavaIndenter : public TextEditor::Indenter
|
||||||
|
{
|
||||||
|
public:
|
||||||
|
JavaIndenter();
|
||||||
|
virtual ~JavaIndenter();
|
||||||
|
|
||||||
|
bool isElectricCharacter(const QChar &ch) const;
|
||||||
|
|
||||||
|
virtual void indentBlock(QTextDocument *doc,
|
||||||
|
const QTextBlock &block,
|
||||||
|
const QChar &typedChar,
|
||||||
|
const TextEditor::TabSettings &tabSettings);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // JAVAINDENTER_H
|
Reference in New Issue
Block a user