OSDN Git Service

b753defcdf1c95c930552cd4b9a7f29954f3510e
[qt-creator-jp/qt-creator-jp.git] / src / plugins / resourceeditor / resourceeditorplugin.cpp
1 /**************************************************************************
2 **
3 ** This file is part of Qt Creator
4 **
5 ** Copyright (c) 2011 Nokia Corporation and/or its subsidiary(-ies).
6 **
7 ** Contact: Nokia Corporation (qt-info@nokia.com)
8 **
9 ** No Commercial Usage
10 **
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
14 ** this package.
15 **
16 ** GNU Lesser General Public License Usage
17 **
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.
24 **
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.
28 **
29 ** If you have questions regarding the use of this file, please contact
30 ** Nokia at qt-info@nokia.com.
31 **
32 **************************************************************************/
33
34 #include "resourceeditorplugin.h"
35
36 #include "resourceeditorw.h"
37 #include "resourceeditorconstants.h"
38 #include "resourcewizard.h"
39 #include "resourceeditorfactory.h"
40
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>
48
49 #include <utils/qtcassert.h>
50
51 #include <QtCore/QtPlugin>
52 #include <QtCore/QCoreApplication>
53 #include <QtGui/QAction>
54
55 using namespace ResourceEditor::Internal;
56
57 ResourceEditorPlugin::ResourceEditorPlugin() :
58     m_wizard(0),
59     m_editor(0),
60     m_redoAction(0),
61     m_undoAction(0)
62 {
63 }
64
65 ResourceEditorPlugin::~ResourceEditorPlugin()
66 {
67     removeObject(m_editor);
68     removeObject(m_wizard);
69 }
70
71 bool ResourceEditorPlugin::initialize(const QStringList &arguments, QString *errorMessage)
72 {
73     Q_UNUSED(arguments)
74     Core::ICore *core = Core::ICore::instance();
75     if (!core->mimeDatabase()->addMimeTypes(QLatin1String(":/resourceeditor/ResourceEditor.mimetypes.xml"), errorMessage))
76         return false;
77
78     m_editor = new ResourceEditorFactory(this);
79     addObject(m_editor);
80
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));
87
88     m_wizard = new ResourceWizard(wizardParameters, this);
89     addObject(m_wizard);
90
91     errorMessage->clear();
92
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()));
102
103     return true;
104 }
105
106 void ResourceEditorPlugin::extensionsInitialized()
107 {
108 }
109
110 void ResourceEditorPlugin::onUndo()
111 {
112     currentEditor()->onUndo();
113 }
114
115 void ResourceEditorPlugin::onRedo()
116 {
117     currentEditor()->onRedo();
118 }
119
120 void ResourceEditorPlugin::onUndoStackChanged(ResourceEditorW const *editor,
121         bool canUndo, bool canRedo)
122 {
123     if (editor == currentEditor()) {
124         m_undoAction->setEnabled(canUndo);
125         m_redoAction->setEnabled(canRedo);
126     }
127 }
128
129 ResourceEditorW * ResourceEditorPlugin::currentEditor() const
130 {
131     ResourceEditorW * const focusEditor = qobject_cast<ResourceEditorW *>(
132             Core::EditorManager::instance()->currentEditor());
133     QTC_ASSERT(focusEditor, return 0);
134     return focusEditor;
135 }
136
137 Q_EXPORT_PLUGIN(ResourceEditorPlugin)