[Qt-creator] Help with plugins
Ziller Eike
Eike.Ziller at digia.com
Tue Oct 29 09:21:20 CET 2013
On Oct 28, 2013, at 7:30 PM, Jochen Becher <jochen_becher at gmx.de> wrote:
> Hi,
>
> I am working on a complex plug-in which introduces a new mode for files
> of a certain mime type. I have some questions about implementing a few
> features and I hope you can give me some links to source code files
> where I can copy the behavior:
>
> 1. When I open document of my mime type the file is usually opened in
> Edit mode. Currently I show a simple "switch to the correct mode" label
> because the file cannot be edited here (it is an xml format that makes
> no sense to edit it manually). In Edit mode I can save the file (when it
> has been changed used the new mode) or select "Save All" and some other
> menu items. As soon as i switch to the new mode "Save" and "Save All"
> are disabled. How do I have to set the right context to enable these
> items in the new mode as well?
I think the .ui designer does it by adding the Core::Constants::C_EDITORMANAGER context to its widget's context, but I think that could have some unwanted side-effects.
IMO the cleaner way (though involving more effort) is to do it similar to the Qt Quick Designer, which registers its own save actions for its own context, like
Core::ActionManager::registerAction(mySaveAction, Core::Constants::SAVE, myModeContext);
connect(mySaveAction, SIGNAL(triggered()), this, SLOT(saveCurrentDocument()));
and handle the mySaveAction enabled state correspondingly.
See e.g. src/plugins/qmldesigner/shortcutmanager.cpp
Known issue is that the xml opens in the editor manager at all…. but solving that needs some heavy refactoring, basically allowing multiple completely different view implementations that can directly hold the IEditor(widget)s.
> 2. What is the preferred way to switch to a new mode after opening the
> document? Directly switch to the mode from the document's open() method
> using the ModeManager does not work. I tried to make it asynchronous
> using a signal from the document's open() method with
> Qt::QuededConnection. This works better but it behaves in an unexpected
> way. Isn't there a signal like "FileWasOpened" where I can connect to?
Core::EditorManager::editorOpened
> 3. How can I save the layout of the mode's main window or other dialogs?
> Is there an official way to save such settings (properties of
> MiniSplitter etc)?
Connect to Core::ICore::saveSettingsRequested() and then use either
1) Core::ICore::settings() for settings you want saved globally independent of session
2) ProjectExplorer::SessionManager::setValue(…) for settings that you want saved for the session
gl hf
Eike
--
Eike Ziller, Senior Software Engineer - Digia, Qt
Digia Germany GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Anja Wasenius
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B
More information about the Qt-creator
mailing list