diff options
Diffstat (limited to 'src/plugins/resourceeditor')
-rw-r--r-- | src/plugins/resourceeditor/ResourceEditor.mimetypes.xml | 8 | ||||
-rw-r--r-- | src/plugins/resourceeditor/ResourceEditor.pluginspec | 10 | ||||
-rw-r--r-- | src/plugins/resourceeditor/images/qt_qrc.png | bin | 0 -> 622 bytes | |||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditor.pro | 24 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditor.qrc | 6 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorconstants.h | 44 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorfactory.cpp | 86 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorfactory.h | 80 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorplugin.cpp | 131 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorplugin.h | 84 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorw.cpp | 271 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourceeditorw.h | 143 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcewizard.cpp | 59 | ||||
-rw-r--r-- | src/plugins/resourceeditor/resourcewizard.h | 59 |
14 files changed, 1005 insertions, 0 deletions
diff --git a/src/plugins/resourceeditor/ResourceEditor.mimetypes.xml b/src/plugins/resourceeditor/ResourceEditor.mimetypes.xml new file mode 100644 index 0000000000..82a1797028 --- /dev/null +++ b/src/plugins/resourceeditor/ResourceEditor.mimetypes.xml @@ -0,0 +1,8 @@ +<?xml version="1.0"?> +<mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'> + <mime-type type="application/vnd.nokia.xml.qt.resource"> + <sub-class-of type="text/xml"/> + <comment>Qt Resource file</comment> + <glob pattern="*.qrc"/> + </mime-type> +</mime-info> diff --git a/src/plugins/resourceeditor/ResourceEditor.pluginspec b/src/plugins/resourceeditor/ResourceEditor.pluginspec new file mode 100644 index 0000000000..cddde0b0d9 --- /dev/null +++ b/src/plugins/resourceeditor/ResourceEditor.pluginspec @@ -0,0 +1,10 @@ +<plugin name="ResourceEditor" version="0.9.1" compatVersion="0.9.1"> + <vendor>Nokia Corporation</vendor> + <copyright>(C) 2008 Nokia Corporation</copyright> + <license>Nokia Technology Preview License Agreement</license> + <description>Editor for qrc files.</description> + <url>http://www.trolltech.com/</url> + <dependencyList> + <dependency name="Core" version="0.9.1"/> + </dependencyList> +</plugin> diff --git a/src/plugins/resourceeditor/images/qt_qrc.png b/src/plugins/resourceeditor/images/qt_qrc.png Binary files differnew file mode 100644 index 0000000000..d22ca67610 --- /dev/null +++ b/src/plugins/resourceeditor/images/qt_qrc.png diff --git a/src/plugins/resourceeditor/resourceeditor.pro b/src/plugins/resourceeditor/resourceeditor.pro new file mode 100644 index 0000000000..e91099d963 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditor.pro @@ -0,0 +1,24 @@ +TEMPLATE = lib +TARGET = ResourceEditor + +qtAddLibrary(QtDesigner) + +include(../../qworkbenchplugin.pri) +include(../../libs/utils/utils.pri) +include(../../plugins/coreplugin/coreplugin.pri) +include(../../../shared/qrceditor/qrceditor.pri) + +INCLUDEPATH += $$PWD/../../tools/utils + +HEADERS += resourceeditorfactory.h \ +resourceeditorplugin.h \ +resourcewizard.h \ +resourceeditorw.h \ +resourceeditorconstants.h + +SOURCES +=resourceeditorfactory.cpp \ +resourceeditorplugin.cpp \ +resourcewizard.cpp \ +resourceeditorw.cpp + +RESOURCES += resourceeditor.qrc diff --git a/src/plugins/resourceeditor/resourceeditor.qrc b/src/plugins/resourceeditor/resourceeditor.qrc new file mode 100644 index 0000000000..2265055f97 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditor.qrc @@ -0,0 +1,6 @@ +<RCC> + <qresource prefix="/resourceeditor" > + <file>images/qt_qrc.png</file> + <file>ResourceEditor.mimetypes.xml</file> + </qresource> +</RCC> diff --git a/src/plugins/resourceeditor/resourceeditorconstants.h b/src/plugins/resourceeditor/resourceeditorconstants.h new file mode 100644 index 0000000000..9786a681e4 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorconstants.h @@ -0,0 +1,44 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RESOURCEEDITOR_CONSTANTS_H +#define RESOURCEEDITOR_CONSTANTS_H + +namespace ResourceEditor { +namespace Constants { +const char * const C_RESOURCEEDITOR = "Resource Editor"; +const char * const C_RESOURCEWINDOW = "Resourcewindow"; +const char * const C_RESOURCE_MIMETYPE = "application/vnd.nokia.xml.qt.resource"; +} +} + +#endif // RESOURCEEDITOR_CONSTANTS_H diff --git a/src/plugins/resourceeditor/resourceeditorfactory.cpp b/src/plugins/resourceeditor/resourceeditorfactory.cpp new file mode 100644 index 0000000000..8897b11524 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorfactory.cpp @@ -0,0 +1,86 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "resourceeditorfactory.h" +#include "resourceeditorw.h" +#include "resourceeditorplugin.h" +#include "resourceeditorconstants.h" + +#include <coreplugin/icore.h> +#include <coreplugin/uniqueidmanager.h> +#include <coreplugin/fileiconprovider.h> +#include <coreplugin/editormanager/editormanager.h> + +#include <QtCore/QFileInfo> +#include <QtCore/qdebug.h> + +using namespace ResourceEditor::Internal; +using namespace ResourceEditor::Constants; + +ResourceEditorFactory::ResourceEditorFactory(Core::ICore *core, ResourceEditorPlugin *plugin) : + Core::IEditorFactory(plugin), + m_mimeTypes(QStringList(QLatin1String("application/vnd.nokia.xml.qt.resource"))), + m_kind(QLatin1String(C_RESOURCEEDITOR)), + m_core(core), + m_plugin(plugin) +{ + m_context += m_core->uniqueIDManager() + ->uniqueIdentifier(QLatin1String(ResourceEditor::Constants::C_RESOURCEEDITOR)); + Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance(); + iconProvider->registerIconForSuffix(QIcon(":/resourceeditor/images/qt_qrc.png"), + QLatin1String("qrc")); +} + +QString ResourceEditorFactory::kind() const +{ + return m_kind; +} + +Core::IFile *ResourceEditorFactory::open(const QString &fileName) +{ + Core::IEditor *iface = m_core->editorManager()->openEditor(fileName, kind()); + if (!iface) { + qWarning() << "ResourceEditorFactory::open: openEditor failed for " << fileName; + return 0; + } + return iface->file(); +} + +Core::IEditor *ResourceEditorFactory::createEditor(QWidget *parent) +{ + return new ResourceEditorW(m_context, m_core, m_plugin, parent); +} + +QStringList ResourceEditorFactory::mimeTypes() const +{ + return m_mimeTypes; +} diff --git a/src/plugins/resourceeditor/resourceeditorfactory.h b/src/plugins/resourceeditor/resourceeditorfactory.h new file mode 100644 index 0000000000..9f22743a35 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorfactory.h @@ -0,0 +1,80 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RRESOURCEEDITORFACTORY_H +#define RRESOURCEEDITORFACTORY_H + +#include <extensionsystem/ExtensionSystemInterfaces> +#include <coreplugin/editormanager/ieditorfactory.h> + +#include <QtCore/QStringList> + +namespace Core { +class ICore; +class IEditor; +class IFile; +} + +namespace ResourceEditor { +namespace Internal { + +class ResourceEditorPlugin; + +class ResourceEditorFactory : public Core::IEditorFactory +{ + Q_OBJECT + +public: + typedef QList<int> Context; + + ResourceEditorFactory(Core::ICore *core, ResourceEditorPlugin *plugin); + + virtual QStringList mimeTypes() const; + + //EditorFactory + QString kind() const; + Core::IFile *open(const QString &fileName); + Core::IEditor *createEditor(QWidget *parent); + +private: + const QStringList m_mimeTypes; + const QString m_kind; + Context m_context; + + Core::ICore *m_core; + ResourceEditorPlugin *m_plugin; +}; + +} // namespace Internal +} // namespace ResourceEditor + +#endif // RRESOURCEEDITORFACTORY_H diff --git a/src/plugins/resourceeditor/resourceeditorplugin.cpp b/src/plugins/resourceeditor/resourceeditorplugin.cpp new file mode 100644 index 0000000000..d0335db5a8 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorplugin.cpp @@ -0,0 +1,131 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "resourceeditorplugin.h" +#include "resourceeditorw.h" +#include "resourceeditorconstants.h" +#include "resourcewizard.h" +#include "resourceeditorfactory.h" + +#include <coreplugin/icore.h> +#include <coreplugin/mimedatabase.h> +#include <coreplugin/coreconstants.h> +#include <coreplugin/uniqueidmanager.h> +#include <coreplugin/actionmanager/actionmanagerinterface.h> +#include <coreplugin/editormanager/editormanager.h> + +#include <QtCore/qplugin.h> +#include <QtGui/QAction> + +using namespace ResourceEditor::Internal; + +ResourceEditorPlugin::ResourceEditorPlugin() : + m_wizard(0), + m_editor(0), + m_core(NULL), + m_redoAction(NULL), + m_undoAction(NULL) +{ +} + +ResourceEditorPlugin::~ResourceEditorPlugin() +{ + removeObject(m_editor); + removeObject(m_wizard); +} + +bool ResourceEditorPlugin::initialize(const QStringList & /*arguments*/, QString *error_message) +{ + m_core = ExtensionSystem::PluginManager::instance()->getObject<Core::ICore>(); + if (!m_core->mimeDatabase()->addMimeTypes(QLatin1String(":/resourceeditor/ResourceEditor.mimetypes.xml"), error_message)) + return false; + + m_editor = new ResourceEditorFactory(m_core, this); + addObject(m_editor); + + Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard); + wizardParameters.setDescription(tr("Resource file")); + wizardParameters.setName(tr("Resource file")); + wizardParameters.setCategory(QLatin1String("Qt")); + wizardParameters.setTrCategory(tr("Qt")); + + m_wizard = new ResourceWizard(wizardParameters, m_core, this); + addObject(m_wizard); + + error_message->clear(); + + // Register undo and redo + Core::ActionManagerInterface * const actionManager = m_core->actionManager(); + int const pluginId = m_core->uniqueIDManager()->uniqueIdentifier( + Constants::C_RESOURCEEDITOR); + QList<int> const idList = QList<int>() << pluginId; + m_undoAction = new QAction(tr("&Undo"), this); + m_redoAction = new QAction(tr("&Redo"), this); + actionManager->registerAction(m_undoAction, Core::Constants::UNDO, idList); + actionManager->registerAction(m_redoAction, Core::Constants::REDO, idList); + connect(m_undoAction, SIGNAL(triggered()), this, SLOT(onUndo())); + connect(m_redoAction, SIGNAL(triggered()), this, SLOT(onRedo())); + + return true; +} + +void ResourceEditorPlugin::extensionsInitialized() +{ +} + +void ResourceEditorPlugin::onUndo() +{ + currentEditor()->onUndo(); +} + +void ResourceEditorPlugin::onRedo() +{ + currentEditor()->onRedo(); +} + +void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor, + bool canUndo, bool canRedo) +{ + if (editor == currentEditor()) { + m_undoAction->setEnabled(canUndo); + m_redoAction->setEnabled(canRedo); + } +} + +ResourceEditorW * ResourceEditorPlugin::currentEditor() const { + ResourceEditorW * const focusEditor = qobject_cast<ResourceEditorW *>( + m_core->editorManager()->currentEditor()); + Q_ASSERT(focusEditor); + return focusEditor; +} + +Q_EXPORT_PLUGIN(ResourceEditorPlugin) diff --git a/src/plugins/resourceeditor/resourceeditorplugin.h b/src/plugins/resourceeditor/resourceeditorplugin.h new file mode 100644 index 0000000000..6f75275da0 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorplugin.h @@ -0,0 +1,84 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RESOURCEEDITORPLUGIN_H +#define RESOURCEEDITORPLUGIN_H + +#include <extensionsystem/iplugin.h> + +QT_FORWARD_DECLARE_CLASS(QAction); + +namespace Core { + class ICore; +} + +namespace ResourceEditor { +namespace Internal { + +class ResourceEditorW; +class ResourceWizard; +class ResourceEditorFactory; + +class ResourceEditorPlugin : public ExtensionSystem::IPlugin +{ + Q_OBJECT + +public: + ResourceEditorPlugin(); + virtual ~ResourceEditorPlugin(); + + //Plugin + bool initialize(const QStringList &arguments, QString *error_message = 0); + void extensionsInitialized(); + +private slots: + void onUndo(); + void onRedo(); + +public: + void onUndoStackChanged(ResourceEditorW const *editor, bool canUndo, bool canRedo); + +private: + ResourceEditorW * currentEditor() const; + +private: + ResourceWizard *m_wizard; + ResourceEditorFactory *m_editor; + Core::ICore *m_core; + QAction *m_redoAction; + QAction *m_undoAction; +}; + +} // namespace Internal +} // namespace ResourceEditor + +#endif // RESOURCEEDITORPLUGIN_H diff --git a/src/plugins/resourceeditor/resourceeditorw.cpp b/src/plugins/resourceeditor/resourceeditorw.cpp new file mode 100644 index 0000000000..9eea18bce1 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorw.cpp @@ -0,0 +1,271 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "resourceeditorw.h" +#include "resourceeditorplugin.h" +#include "resourceeditorconstants.h" + +#include <qrceditor.h> + +#include <QtCore/QTemporaryFile> +#include <QtCore/QFileInfo> +#include <QtCore/QDir> +#include <QtCore/qdebug.h> +#include <QtGui/QMainWindow> +#include <QtGui/QHBoxLayout> + +#include <coreplugin/icore.h> +#include <utils/reloadpromptutils.h> + +namespace ResourceEditor { +namespace Internal { + +enum { debugResourceEditorW = 0 }; + + + +ResourceEditorFile::ResourceEditorFile(ResourceEditorW *parent) : + IFile(parent), + m_mimeType(QLatin1String(ResourceEditor::Constants::C_RESOURCE_MIMETYPE)), + m_parent(parent) +{ + if (debugResourceEditorW) + qDebug() << "ResourceEditorFile::ResourceEditorFile()"; +} + +QString ResourceEditorFile::mimeType() const +{ + return m_mimeType; +} + + +ResourceEditorW::ResourceEditorW(const QList<int> &context, + Core::ICore *core, + ResourceEditorPlugin *plugin, + QWidget *parent) + : m_context(context), + m_core(core), + m_resourceEditor(new SharedTools::QrcEditor(parent)), + m_resourceFile(new ResourceEditorFile(this)), + m_plugin(plugin) +{ + m_resourceEditor->setResourceDragEnabled(true); + m_resourceEditor->layout()->setMargin(9); + + connect(m_resourceEditor, SIGNAL(dirtyChanged(bool)), this, SLOT(dirtyChanged(bool))); + connect(m_resourceEditor, SIGNAL(undoStackChanged(bool, bool)), + this, SLOT(onUndoStackChanged(bool, bool))); + connect(m_resourceFile, SIGNAL(changed()), this, SIGNAL(changed())); + if (debugResourceEditorW) + qDebug() << "ResourceEditorW::ResourceEditorW()"; +} + +ResourceEditorW::~ResourceEditorW() +{ + if (m_resourceEditor) + m_resourceEditor->deleteLater(); +} + +bool ResourceEditorW::createNew(const QString &contents) +{ + QTemporaryFile tempFile(0); + tempFile.setAutoRemove(true); + if (!tempFile.open()) + return false; + const QString tempFileName = tempFile.fileName(); + tempFile.write(contents.toUtf8()); + tempFile.close(); + + const bool rc = m_resourceEditor->load(tempFileName); + m_resourceEditor->setFileName(QString()); + if (debugResourceEditorW) + qDebug() << "ResourceEditorW::createNew: " << contents << " (" << tempFileName << ") returns " << rc; + return rc; +} + +bool ResourceEditorW::open(const QString &fileName /*= QString()*/) +{ + if (debugResourceEditorW) + qDebug() << "ResourceEditorW::open: " << fileName; + + if (fileName.isEmpty()) { + setDisplayName(tr("untitled")); + return true; + } + + const QFileInfo fi(fileName); + + const QString absFileName = fi.absoluteFilePath(); + + if (!fi.isReadable()) + return false; + + if (!m_resourceEditor->load(absFileName)) + return false; + + setDisplayName(fi.fileName()); + + emit changed(); + return true; +} + +bool ResourceEditorFile::save(const QString &name /*= QString()*/) +{ + if (debugResourceEditorW) + qDebug() << ">ResourceEditorW::save: " << name; + + const QString oldFileName = fileName(); + const QString actualName = name.isEmpty() ? oldFileName : name; + if (actualName.isEmpty()) + return false; + + m_parent->m_resourceEditor->setFileName(actualName); + if (!m_parent->m_resourceEditor->save()) { + m_parent->m_resourceEditor->setFileName(oldFileName); + return false; + } + + m_parent->m_resourceEditor->setDirty(false); + m_parent->setDisplayName(QFileInfo(actualName).fileName()); + + emit changed(); + return true; +} + +const char *ResourceEditorW::kind() const { + return ResourceEditor::Constants::C_RESOURCEWINDOW; +} + +QString ResourceEditorFile::fileName() const +{ + return m_parent->m_resourceEditor->fileName(); +} + +bool ResourceEditorFile::isModified() const +{ + return m_parent->m_resourceEditor->isDirty(); +} + +bool ResourceEditorFile::isReadOnly() const +{ + const QString fileName = m_parent->m_resourceEditor->fileName(); + if (fileName.isEmpty()) + return false; + const QFileInfo fi(fileName); + return !fi.isWritable(); +} + +bool ResourceEditorFile::isSaveAsAllowed() const +{ + return true; +} + +void ResourceEditorFile::modified(Core::IFile::ReloadBehavior *behavior) +{ + const QString fileName = m_parent->m_resourceEditor->fileName(); + + switch (*behavior) { + case Core::IFile::ReloadNone: + return; + case Core::IFile::ReloadAll: + m_parent->open(fileName); + return; + case Core::IFile::ReloadPermissions: + emit changed(); + return; + case Core::IFile::AskForReload: + break; + } + + switch (Core::Utils::reloadPrompt(fileName, m_parent->m_core->mainWindow())) { + case Core::Utils::ReloadCurrent: + m_parent->open(fileName); + break; + case Core::Utils::ReloadAll: + m_parent->open(fileName); + *behavior = Core::IFile::ReloadAll; + break; + case Core::Utils::ReloadSkipCurrent: + break; + case Core::Utils::ReloadNone: + *behavior = Core::IFile::ReloadNone; + break; + } +} + +QString ResourceEditorFile::defaultPath() const +{ + return QString(); +} + +void ResourceEditorW::setSuggestedFileName(const QString &fileName) +{ + m_suggestedName = fileName; +} + +QString ResourceEditorFile::suggestedFileName() const +{ + return m_parent->m_suggestedName; +} + +void ResourceEditorW::dirtyChanged(bool dirty) +{ + if (debugResourceEditorW) + qDebug() << " ResourceEditorW::dirtyChanged" << dirty; + if (dirty) + emit changed(); +} + +QWidget *ResourceEditorW::widget() +{ + return m_resourceEditor; /* we know it's a subclass of QWidget...*/ +} + +void ResourceEditorW::onUndoStackChanged(bool canUndo, bool canRedo) +{ + m_plugin->onUndoStackChanged(this, canUndo, canRedo); +} + +void ResourceEditorW::onUndo() +{ + if (!m_resourceEditor.isNull()) + m_resourceEditor.data()->onUndo(); +} + +void ResourceEditorW::onRedo() +{ + if (!m_resourceEditor.isNull()) + m_resourceEditor.data()->onRedo(); +} + +} +} diff --git a/src/plugins/resourceeditor/resourceeditorw.h b/src/plugins/resourceeditor/resourceeditorw.h new file mode 100644 index 0000000000..b580f37d90 --- /dev/null +++ b/src/plugins/resourceeditor/resourceeditorw.h @@ -0,0 +1,143 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RESOURCEDITORW_H +#define RESOURCEDITORW_H + +#include <coreplugin/ifile.h> +#include <coreplugin/editormanager/ieditor.h> + +#include <QtGui/QWidget> +#include <QtCore/QPointer> + + +namespace Core { + class ICore; +} + +namespace SharedTools { + class QrcEditor; +} + +namespace ResourceEditor { +namespace Internal { + +class ResourceEditorPlugin; +class ResourceEditorW; + +class ResourceEditorFile + : public virtual Core::IFile +{ + Q_OBJECT + +public: + typedef QList<int> Context; + + ResourceEditorFile(ResourceEditorW *parent = 0); + + //IFile + bool save(const QString &fileName = QString()); + QString fileName() const; + bool isModified() const; + bool isReadOnly() const; + bool isSaveAsAllowed() const; + void modified(Core::IFile::ReloadBehavior *behavior); + QString defaultPath() const; + QString suggestedFileName() const; + virtual QString mimeType() const; + +signals: + void changed(); + +private: + const QString m_mimeType; + ResourceEditorW *m_parent; +}; + +class ResourceEditorW : public Core::IEditor +{ + Q_OBJECT + +public: + typedef QList<int> Context; + + ResourceEditorW(const Context &context, + Core::ICore *core, + ResourceEditorPlugin *plugin, + QWidget *parent = 0); + ~ResourceEditorW(); + + // IEditor + bool createNew(const QString &contents); + bool open(const QString &fileName = QString()); + bool duplicateSupported() const { return false; } + Core::IEditor *duplicate(QWidget *) { return 0; } + Core::IFile *file() { return m_resourceFile; } + const char *kind() const; + QString displayName() const { return m_displayName; } + void setDisplayName(const QString &title) { m_displayName = title; } + QToolBar *toolBar() { return 0; } + QByteArray saveState() const { return QByteArray(); } + bool restoreState(const QByteArray &/*state*/) { return true; } + + // ContextInterface + Context context() const { return m_context; } + QWidget *widget(); + + void setSuggestedFileName(const QString &fileName); + +private slots: + void dirtyChanged(bool); + void onUndoStackChanged(bool canUndo, bool canRedo); + +private: + const QString m_extension; + const QString m_fileFilter; + QString m_displayName; + QString m_suggestedName; + const Context m_context; + Core::ICore *m_core; + QPointer<SharedTools::QrcEditor> m_resourceEditor; + ResourceEditorFile *m_resourceFile; + ResourceEditorPlugin *m_plugin; + +public: + void onUndo(); + void onRedo(); + + friend class ResourceEditorFile; +}; + +} // namespace Internal +} // namespace ResourceEditor + +#endif //RESOURCEDITORW_H diff --git a/src/plugins/resourceeditor/resourcewizard.cpp b/src/plugins/resourceeditor/resourcewizard.cpp new file mode 100644 index 0000000000..ce1b8eb8f1 --- /dev/null +++ b/src/plugins/resourceeditor/resourcewizard.cpp @@ -0,0 +1,59 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#include "resourcewizard.h" +#include "resourceeditorw.h" +#include "resourceeditorconstants.h" + +namespace ResourceEditor { +namespace Internal { + +ResourceWizard::ResourceWizard(const BaseFileWizardParameters ¶meters, Core::ICore *core, QObject *parent) : + Core::StandardFileWizard(parameters, core, parent) +{ +} + +Core::GeneratedFiles + ResourceWizard::generateFilesFromPath(const QString &path, + const QString &name, + QString * /*errorMessage*/) const +{ + const QString suffix = preferredSuffix(QLatin1String(Constants::C_RESOURCE_MIMETYPE)); + const QString fileName = Core::BaseFileWizard::buildFileName(path, name, suffix); + Core::GeneratedFile file(fileName); + file.setContents(QLatin1String("<RCC/>")); + file.setEditorKind(QLatin1String(Constants::C_RESOURCEEDITOR)); + return Core::GeneratedFiles() << file; +} + +} +} diff --git a/src/plugins/resourceeditor/resourcewizard.h b/src/plugins/resourceeditor/resourcewizard.h new file mode 100644 index 0000000000..40abe4612c --- /dev/null +++ b/src/plugins/resourceeditor/resourcewizard.h @@ -0,0 +1,59 @@ +/*************************************************************************** +** +** This file is part of Qt Creator +** +** Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies). +** +** Contact: Qt Software Information (qt-info@nokia.com) +** +** +** Non-Open Source Usage +** +** Licensees may use this file in accordance with the Qt Beta Version +** License Agreement, Agreement version 2.2 provided with the Software or, +** alternatively, in accordance with the terms contained in a written +** agreement between you and Nokia. +** +** GNU General Public License Usage +** +** Alternatively, this file may be used under the terms of the GNU General +** Public License versions 2.0 or 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the packaging +** of this file. Please review the following information to ensure GNU +** General Public Licensing requirements will be met: +** +** http://www.fsf.org/licensing/licenses/info/GPLv2.html and +** http://www.gnu.org/copyleft/gpl.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt GPL Exception version +** 1.2, included in the file GPL_EXCEPTION.txt in this package. +** +***************************************************************************/ +#ifndef RESOURCEWIZARD_H +#define RESOURCEWIZARD_H + +#include <coreplugin/basefilewizard.h> + +namespace ResourceEditor { +namespace Internal { + +class ResourceWizard : public Core::StandardFileWizard +{ + Q_OBJECT + +public: + + typedef Core::BaseFileWizardParameters BaseFileWizardParameters; + explicit ResourceWizard(const BaseFileWizardParameters ¶meters, Core::ICore *core, QObject *parent); + +protected: + virtual Core::GeneratedFiles + generateFilesFromPath(const QString &path, const QString &name, + QString *errorMessage) const; +}; + +} // namespace Internal +} // namespace ResourceEditor + +#endif //RESOURCEWIZARD_H |