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 "formeditorfactory.h"
35 #include "formeditorw.h"
36 #include "formwindoweditor.h"
37 #include "editordata.h"
38 #include "designerconstants.h"
39 #include "designerxmleditor.h"
41 #include <coreplugin/coreconstants.h>
42 #include <coreplugin/icore.h>
43 #include <coreplugin/fileiconprovider.h>
44 #include <coreplugin/editormanager/editormanager.h>
45 #include <coreplugin/modemanager.h>
47 #include <QtCore/QFileInfo>
48 #include <QtCore/QDebug>
50 using namespace Designer::Constants;
55 FormEditorFactory::FormEditorFactory()
56 : Core::IEditorFactory(Core::ICore::instance()),
57 m_mimeTypes(QLatin1String(FORM_MIMETYPE))
59 Core::FileIconProvider *iconProvider = Core::FileIconProvider::instance();
60 iconProvider->registerIconOverlayForSuffix(QIcon(QLatin1String(":/formeditor/images/qt_ui.png")),
62 connect(Core::EditorManager::instance(), SIGNAL(currentEditorChanged(Core::IEditor*)),
63 SLOT(updateEditorInfoBar(Core::IEditor*)));
66 QString FormEditorFactory::id() const
68 return QLatin1String(DESIGNER_XML_EDITOR_ID);
71 QString FormEditorFactory::displayName() const
73 return tr(C_DESIGNER_XML_DISPLAY_NAME);
76 Core::IFile *FormEditorFactory::open(const QString &fileName)
78 Core::IEditor *iface = Core::EditorManager::instance()->openEditor(fileName, id());
79 return iface ? iface->file() : 0;
82 Core::IEditor *FormEditorFactory::createEditor(QWidget *parent)
84 const EditorData data = FormEditorW::instance()->createEditor(parent);
85 return data.formWindowEditor;
88 QStringList FormEditorFactory::mimeTypes() const
93 void FormEditorFactory::updateEditorInfoBar(Core::IEditor *editor)
95 if (qobject_cast<FormWindowEditor *>(editor)) {
96 Core::EditorManager::instance()->showEditorInfoBar(Constants::INFO_READ_ONLY,
97 tr("This file can only be edited in <b>Design</b> mode."),
98 tr("Switch mode"), this, SLOT(designerModeClicked()));
100 Core::EditorManager::instance()->hideEditorInfoBar(Constants::INFO_READ_ONLY);
104 void FormEditorFactory::designerModeClicked()
106 Core::ICore::instance()->modeManager()->activateMode(QLatin1String(Core::Constants::MODE_DESIGN));
109 } // namespace Internal
110 } // namespace Designer