[Qt-creator] Plugins: two different editorplugins for the same mimetype

Liebe Markus (RtP2/TEF72) Markus.Liebe at de.bosch.com
Thu Jan 14 15:48:31 CET 2010


Hi there,

I am really stuck here.
I have two plugins (editors). I want to use them to edit .xml files.
To figure out which editor has to be loaded for a .xml file to be opened I wrote two magic matchers.

As far as I understand the magicmatchers are supposed to read the raw data of the file to be opened, and depending on what they read, decide if they are responsible for that particular file or not.

Well that's the theory. I cannot get it to work.
At the moment the only way for me to differentiate the two file formats is to introduce two new file suffixes (.xmodglobal / .xmoduledoc).
That is certainly not the way I want to go.

Do you have any recommondations on how to approach this problem?

As I sent the last eMail concerning this topic just before christmas holidy I attach it again below. So you can get the whole picture.

Hope you don't mind the tofu =)

> Hi there,
>
> I have written two new editor plugins to handle two types of
> xml files from our department.
> There are two different xml file formats and for each format
> I have a seperate editor:
> ModEditor and CcsDocEditor.
>
> I register the mimetype for the editors like that:
>
> --------snip--------
>  Core::MimeDatabase* mdb = m_core->mimeDatabase();
>  if(!mdb->findByType(CcsDocEditorConstants::getMimeType()).isNull()){
>      return;
>  }
>  QSharedPointer<Core::IMagicMatcher> matcher(new
> CcsDocXmlMagicMatcher);
>  Core::MimeType xmlMimeType = mdb->findByType("application/xml");
>  Core::MimeType guixmlMimeType(xmlMimeType);
>
> guixmlMimeType.setType(CcsDocEditorConstants::getMimeType());
> // "application/ccsdocxml"
>  guixmlMimeType.addMagicMatcher(matcher);
>  guixmlMimeType.setSubClassesOf(QStringList() << "text/plain"
> << "application/xml");
>  mdb->addMimeType(guixmlMimeType);
> --------snap--------
> The same goes for ModEditor.
>
> Now I was hoping that I can use
> CcsDocXmlMagicMatcher::match(...) and
> ModXmlMagicMatcher::match(...) to let the plugin find out
> whether it is responsible for the file that is beeing opened.
> But the function is never called. In addition to that
> QtCreator always uses the same editor for both formats
> (depending on the order in which they got loaded by the pluginloader).
>
> Btw.: If I use the "Open with" dialog, there is only one
> editor of the two in the list - which is the one of the two
> new plugins that gets loaded last.
>
> My questions are now:
> 1.) Where should the MagicMatcher::match() function normally
> be called?
> 2.) Is it correct to introduce two editors for the same
> filetype and differentiate them by using the
> MagicMatcher::match() function?
--
Markus




More information about the Qt-creator-old mailing list