forked from qt-creator/qt-creator
Android: Add Java file wizard
Task-number: QTCREATORBUG-11220 Change-Id: I01967ce9bd205ccbeb93696b98e9b8d9228617f3 Reviewed-by: BogDan Vatra <bogdan@kde.org>
This commit is contained in:
@@ -54,7 +54,8 @@ HEADERS += \
|
||||
javaeditorfactory.h \
|
||||
javaindenter.h \
|
||||
javaautocompleter.h \
|
||||
javacompletionassistprovider.h
|
||||
javacompletionassistprovider.h \
|
||||
javafilewizard.h
|
||||
|
||||
SOURCES += \
|
||||
androidconfigurations.cpp \
|
||||
@@ -103,7 +104,8 @@ SOURCES += \
|
||||
javaeditorfactory.cpp \
|
||||
javaindenter.cpp \
|
||||
javaautocompleter.cpp \
|
||||
javacompletionassistprovider.cpp
|
||||
javacompletionassistprovider.cpp \
|
||||
javafilewizard.cpp
|
||||
|
||||
FORMS += \
|
||||
androidsettingswidget.ui \
|
||||
|
||||
@@ -120,6 +120,8 @@ QtcPlugin {
|
||||
"javaeditor.h",
|
||||
"javaeditorfactory.cpp",
|
||||
"javaeditorfactory.h",
|
||||
"javafilewizard.cpp",
|
||||
"javafilewizard.h",
|
||||
"javaindenter.cpp",
|
||||
"javaindenter.h",
|
||||
"javaparser.cpp",
|
||||
|
||||
@@ -70,6 +70,9 @@ 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";
|
||||
const char WIZARD_JAVA[] = "Wizard.Java";
|
||||
const char JAVA_WIZARD_CATEGORY[] = "U.Java";
|
||||
const char JAVA_DISPLAY_CATEGORY[] = "Java";
|
||||
} // namespace Constants;
|
||||
} // namespace Android
|
||||
|
||||
|
||||
@@ -48,6 +48,7 @@
|
||||
#include "androidpotentialkit.h"
|
||||
#include "javaeditorfactory.h"
|
||||
#include "javacompletionassistprovider.h"
|
||||
#include "javafilewizard.h"
|
||||
#ifdef HAVE_QBS
|
||||
# include "androidqbspropertyprovider.h"
|
||||
#endif
|
||||
@@ -87,6 +88,7 @@ bool AndroidPlugin::initialize(const QStringList &arguments, QString *errorMessa
|
||||
addAutoReleasedObject(new Internal::AndroidPotentialKit);
|
||||
addAutoReleasedObject(new Internal::JavaEditorFactory);
|
||||
addAutoReleasedObject(new Internal::JavaCompletionAssistProvider);
|
||||
addAutoReleasedObject(new Internal::JavaFileWizard);
|
||||
ProjectExplorer::KitManager::registerKitInformation(new Internal::AndroidGdbServerKitInformation);
|
||||
|
||||
// AndroidManifest.xml editor
|
||||
|
||||
79
src/plugins/android/javafilewizard.cpp
Normal file
79
src/plugins/android/javafilewizard.cpp
Normal file
@@ -0,0 +1,79 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 "javafilewizard.h"
|
||||
#include "androidconstants.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
#include <QTextStream>
|
||||
#include <QCoreApplication>
|
||||
|
||||
using namespace Android;
|
||||
using namespace Android::Internal;
|
||||
|
||||
JavaFileWizard::JavaFileWizard()
|
||||
{
|
||||
setWizardKind(Core::IWizard::FileWizard);
|
||||
setCategory(QLatin1String(Constants::JAVA_WIZARD_CATEGORY));
|
||||
setDisplayCategory(QCoreApplication::translate("Android", Constants::JAVA_DISPLAY_CATEGORY));
|
||||
setDescription(tr("Creates a Java file with boilerplate code."));
|
||||
setDisplayName(tr("Java File"));
|
||||
setId(QLatin1String(Constants::WIZARD_JAVA));
|
||||
}
|
||||
|
||||
Core::GeneratedFiles JavaFileWizard::generateFilesFromPath(const QString &path,
|
||||
const QString &name,
|
||||
QString * /*errorMessage*/) const
|
||||
|
||||
{
|
||||
const QString mimeType = QLatin1String(Android::Constants::JAVA_MIMETYPE);
|
||||
QString capitalizedName = name;
|
||||
if (!capitalizedName.isEmpty())
|
||||
capitalizedName[0] = capitalizedName[0].toUpper();
|
||||
const QString fileName = Core::BaseFileWizard::buildFileName(path, capitalizedName, preferredSuffix(mimeType));
|
||||
|
||||
Core::GeneratedFile file(fileName);
|
||||
file.setContents(fileContents(fileName));
|
||||
file.setAttributes(Core::GeneratedFile::OpenEditorAttribute);
|
||||
return Core::GeneratedFiles() << file;
|
||||
}
|
||||
|
||||
QString JavaFileWizard::fileContents(const QString &path) const
|
||||
{
|
||||
QString contents;
|
||||
QTextStream str(&contents);
|
||||
|
||||
QString className = QFileInfo(path).baseName();
|
||||
|
||||
str << QString::fromLatin1("public class %1 {\n").arg(className)
|
||||
<< QLatin1String("\n")
|
||||
<< QLatin1String("}\n")
|
||||
<< QLatin1String("\n");
|
||||
return contents;
|
||||
}
|
||||
55
src/plugins/android/javafilewizard.h
Normal file
55
src/plugins/android/javafilewizard.h
Normal file
@@ -0,0 +1,55 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** 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 JAVAFILEWIZARD_H
|
||||
#define JAVAFILEWIZARD_H
|
||||
|
||||
#include <coreplugin/basefilewizard.h>
|
||||
|
||||
namespace Android {
|
||||
namespace Internal {
|
||||
|
||||
class JavaFileWizard : public Core::StandardFileWizard
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
JavaFileWizard();
|
||||
private:
|
||||
QString fileContents(const QString &path) const;
|
||||
|
||||
Core::GeneratedFiles generateFilesFromPath(const QString &path,
|
||||
const QString &fileName,
|
||||
QString *errorMessage) const;
|
||||
};
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
#endif // JAVAFILEWIZARD_H
|
||||
Reference in New Issue
Block a user