[Qt-creator] own editor plugin and mimetypes
Prashanth Udupa
prashanth.udupa at gmail.com
Tue Nov 17 10:20:22 CET 2009
Hi Markus,
Qt Creator already has a editor for xml files. The mime-type associated with
that is 'application/xml'.
You can register your editor for handling a subset of XML files. The
following code will help you with that..
-------------
const char* ModeXML::MimeTypeStr = "application/modexml";
const char* ModeXML::EditorTypeStr = "ModeXML Editor";
const QString ModeXML::MimeType = QString(ModeXML::MimeTypeStr);
const QString ModeXML::EditorType = QString(ModeXML::EditorTypeStr);
void ModeXML::registerModeXMLMimeType()
{
Core::ICore* core = Core::ICore::instance();
Core::MimeDatabase* mdb = core->mimeDatabase();
if(!mdb->findByType(ModeXML::MimeType).isNull())
return;
QSharedPointer<Core::IMagicMatcher> matcher(new ModeXMLMagicMatcher);
Core::MimeType xmlMimeType = mdb->findByType("application/xml");
Core::MimeType guixmlMimeType(xmlMimeType);
guixmlMimeType.setType(ModeXML::MimeType);
guixmlMimeType.addMagicMatcher(matcher);
guixmlMimeType.setSubClassesOf( QStringList() << "text/plain" <<
"application/xml" );
mdb->addMimeType(guixmlMimeType);
}
-------------
And then return ModeXML::MimeTypeStr from your implementation of
IFile::mimeType(), IEditor::kind() and IEditorFactory::mimeTypes().
This trick worked for us. Hope this helps.
Thanks and Regards,
Prashanth
On Tue, Nov 17, 2009 at 2:23 PM, Liebe Markus (RtP2/TEF72) <
Markus.Liebe at de.bosch.com> wrote:
> Hello there,
>
> I am developing an own editor plugin for QtCreator (modeditor). It is
supposed to provide an editor for *.xml files.
>
> I created a new mimetype description:
> -----------application-xml-mimetype.xml------------------
> <?xml version="1.0" encoding="UTF-8"?>
> <mime-info xmlns='http://www.freedesktop.org/standards/shared-mime-info'>
> <mime-type type="application/xml">
> <sub-class-of type="text/plain"/>
> <comment>XML File</comment>
> <glob pattern="*.xml"/>
> </mime-type>
> </mime-info>
> ---------------------------------------------------------
>
> In my plugins ::initialize() function I add that mimetype:
> ---------------------------------------------------------
> [...]
> Core::MimeDatabase* mdb = new m_core->mimeDatabase();
> If(!mdb->addMimeTypes(":/modeditor/application-xml-mimetype.xml",error))
> return false;
> addAutoReleasedObject(new XmlEditorFactory(this));
> [...]
> ---------------------------------------------------------
>
> The modeditor plugin gets loaeded properly. Help->About->plugins does not
show any errors.
> Problem is now that xml files are still opened only in the
plain-text-editor.
> I had a look into the existing editor plugins and found out that there is
indeed already a mimetype for xml files that is used by the texteditor
plugin.
>
> I think that now that there are two mimetypes for xml and two possible
editorplugins qtcreator chooses the texteditor over the modeditor.
>
> To check that I bound the modeditor plugin to the mimetype text/x-java and
the glob *.java instead. As a result of this my modeditor worked as expected
and qtcreator used it to display *.java files.
>
> But I am still not able to make modeditor display the xml files using the
mimetype description from above. Or more precisely to make qtcreator know
that it should use the new modeditor plugin to display xml files instead of
the texteditor plugin.
>
> Do you have any hints on what the problem could be?
>
> Thanks!
>
> Markus
>
> _______________________________________________
> Qt-creator mailing list
> Qt-creator at trolltech.com
> http://lists.trolltech.com/mailman/listinfo/qt-creator
>
--
Thanks and Warm Regards,
Prashanth N Udupa
prashanth.udupa at gmail.com
http://www.prashanthudupa.com
http://prashanthudupa.livejournal.com/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-creator-old/attachments/20091117/7a02114d/attachment.html
More information about the Qt-creator-old
mailing list