1 /**************************************************************************
3 ** This file is part of Qt Creator
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
18 ** Alternatively, this file may be used under the terms of the GNU Lesser
19 ** General Public License version 2.1 as published by the Free Software
20 ** Foundation and appearing in the file LICENSE.LGPL included in the
21 ** packaging of this file. Please review the following information to
22 ** ensure the GNU Lesser General Public License version 2.1 requirements
23 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
25 ** In addition, as a special exception, Nokia gives you certain additional
26 ** rights. These rights are described in the Nokia Qt LGPL Exception
27 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
32 **************************************************************************/
34 #include "resourceeditorplugin.h"
36 #include "resourceeditorw.h"
37 #include "resourceeditorconstants.h"
38 #include "resourcewizard.h"
39 #include "resourceeditorfactory.h"
41 #include <coreplugin/icore.h>
42 #include <coreplugin/mimedatabase.h>
43 #include <coreplugin/coreconstants.h>
44 #include <coreplugin/uniqueidmanager.h>
45 #include <coreplugin/actionmanager/actionmanager.h>
46 #include <coreplugin/editormanager/editormanager.h>
47 #include <extensionsystem/pluginmanager.h>
49 #include <utils/qtcassert.h>
51 #include <QtCore/QtPlugin>
52 #include <QtCore/QCoreApplication>
53 #include <QtGui/QAction>
55 using namespace ResourceEditor::Internal;
57 ResourceEditorPlugin::ResourceEditorPlugin() :
65 ResourceEditorPlugin::~ResourceEditorPlugin()
67 removeObject(m_editor);
68 removeObject(m_wizard);
71 bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
74 Core::ICore *core = Core::ICore::instance();
75 if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/resourceeditor/ResourceEditor.mimetypes.xml"), errorMessage))
78 m_editor = new ResourceEditorFactory(this);
81 Core::BaseFileWizardParameters wizardParameters(Core::IWizard::FileWizard);
82 wizardParameters.setDescription(tr("Creates a Qt Resource file (.qrc) that you can add to a Qt Widget Project."));
83 wizardParameters.setDisplayName(tr("Qt Resource file"));
84 wizardParameters.setId(QLatin1String("F.Resource"));
85 wizardParameters.setCategory(QLatin1String(Core::Constants::WIZARD_CATEGORY_QT));
86 wizardParameters.setDisplayCategory(QCoreApplication::translate("Core", Core::Constants::WIZARD_TR_CATEGORY_QT));
88 m_wizard = new ResourceWizard(wizardParameters, this);
91 errorMessage->clear();
93 // Register undo and redo
94 const Core::Context context(Constants::C_RESOURCEEDITOR);
95 m_undoAction = new QAction(tr("&Undo"), this);
96 m_redoAction = new QAction(tr("&Redo"), this);
97 Core::ActionManager * const actionManager = core->actionManager();
98 actionManager->registerAction(m_undoAction, Core::Constants::UNDO, context);
99 actionManager->registerAction(m_redoAction, Core::Constants::REDO, context);
100 connect(m_undoAction, SIGNAL(triggered()), this, SLOT(onUndo()));
101 connect(m_redoAction, SIGNAL(triggered()), this, SLOT(onRedo()));
106 void ResourceEditorPlugin::extensionsInitialized()
110 void ResourceEditorPlugin::onUndo()
112 currentEditor()->onUndo();
115 void ResourceEditorPlugin::onRedo()
117 currentEditor()->onRedo();
120 void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
121 bool canUndo, bool canRedo)
123 if (editor == currentEditor()) {
124 m_undoAction->setEnabled(canUndo);
125 m_redoAction->setEnabled(canRedo);
129 ResourceEditorW * ResourceEditorPlugin::currentEditor() const
131 ResourceEditorW * const focusEditor = qobject_cast<ResourceEditorW *>(
132 Core::EditorManager::instance()->currentEditor());
133 QTC_ASSERT(focusEditor, return 0);
137 Q_EXPORT_PLUGIN(ResourceEditorPlugin)