diff options
author | Daniel Teske <daniel.teske@digia.com> | 2014-01-20 15:38:50 +0100 |
---|---|---|
committer | Daniel Teske <daniel.teske@digia.com> | 2014-02-18 13:50:29 +0100 |
commit | fac46592c3417519d9da9d81e366339dde4bb6c0 (patch) | |
tree | c27dfe50ec4e29be14dbbfbcae4c967130db6d83 /src | |
parent | 73cf43f32370d8986b4c06511b95771582cc421d (diff) | |
download | qt-creator-fac46592c3417519d9da9d81e366339dde4bb6c0.tar.gz |
Android: Add Java file wizard
Task-number: QTCREATORBUG-11220
Change-Id: I01967ce9bd205ccbeb93696b98e9b8d9228617f3
Reviewed-by: BogDan Vatra <bogdan@kde.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/android/android.pro | 6 | ||||
-rw-r--r-- | src/plugins/android/android.qbs | 2 | ||||
-rw-r--r-- | src/plugins/android/androidconstants.h | 3 | ||||
-rw-r--r-- | src/plugins/android/androidplugin.cpp | 2 | ||||
-rw-r--r-- | src/plugins/android/javafilewizard.cpp | 79 | ||||
-rw-r--r-- | src/plugins/android/javafilewizard.h | 55 |
6 files changed, 145 insertions, 2 deletions
diff --git a/src/plugins/android/android.pro b/src/plugins/android/android.pro index 455e312bf0..18e26ce087 100644 --- a/src/plugins/android/android.pro +++ b/src/plugins/android/android.pro @@ -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 \ diff --git a/src/plugins/android/android.qbs b/src/plugins/android/android.qbs index 593f0c5b6f..c79434734e 100644 --- a/src/plugins/android/android.qbs +++ b/src/plugins/android/android.qbs @@ -120,6 +120,8 @@ QtcPlugin { "javaeditor.h", "javaeditorfactory.cpp", "javaeditorfactory.h", + "javafilewizard.cpp", + "javafilewizard.h", "javaindenter.cpp", "javaindenter.h", "javaparser.cpp", diff --git a/src/plugins/android/androidconstants.h b/src/plugins/android/androidconstants.h index d685625e15..f84e18f9b8 100644 --- a/src/plugins/android/androidconstants.h +++ b/src/plugins/android/androidconstants.h @@ -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 diff --git a/src/plugins/android/androidplugin.cpp b/src/plugins/android/androidplugin.cpp index 77640d02a9..d4a7861125 100644 --- a/src/plugins/android/androidplugin.cpp +++ b/src/plugins/android/androidplugin.cpp @@ -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 diff --git a/src/plugins/android/javafilewizard.cpp b/src/plugins/android/javafilewizard.cpp new file mode 100644 index 0000000000..1689d6d219 --- /dev/null +++ b/src/plugins/android/javafilewizard.cpp @@ -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; +} diff --git a/src/plugins/android/javafilewizard.h b/src/plugins/android/javafilewizard.h new file mode 100644 index 0000000000..04b8a23854 --- /dev/null +++ b/src/plugins/android/javafilewizard.h @@ -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 |