[Qt-creator] Which plugins are you working on?

Ziller Eike Eike.Ziller at theqtcompany.com
Mon Jun 1 10:58:42 CEST 2015


> On May 30, 2015, at 3:07 PM, Hermann Fieger <hermann.fieger at t-online.de> wrote:
> 
> 
> Hi Tobias, hi everybody,
> 
> at the moment i'm working on about six plugins for QtCreator.
> 
> 1. a HTML Editor with a previewer ( with Syntax  highlighting, also for php and javascript)
> 2. a Python3 Editor with a runtime environment for Qt5 and a ".ui" converter from XML to python code
> 3. a runtime only plugin for previous point, mainly planned at the moment for measurement purposes
> 4. a 3F5-Spice Derivate with GUI
> 5. a connection plugin which very simplifies making connections through TCP, UDP, RS232, VNC, GPIB, LXI, USBTMC ...
> 6. a NC-Code editor with syntax highlighting
> 
> and i also plan to implement a few other things (2D-constructing and painting, OPENGL, ...).
> 
> The plugins are all in a beta state and are growing with daily demands for my work.
> 
> At the moment i run into a small problem. All most all plugin's possess an own "mode" button on the left side of
> QtCreator. 
> 
> For now, i work with "imported projects". Working this way QtCreator creates a "xxx.creator" project-file.
> In this project-file I’m able to add files of all mime types. On the left side I’ve opened two project manager
> windows, an open project tree and an open document windows. 
> 
> For all mime types i use, I've registered an own mime-type like "text/x-myblabla".
> If i doubleclick a file for the first time in the project-tree the right editor will be opened and also the right
> mode will be activated. If i click back to an already opened file ( wether in the project tree or in the open 
> documents ) the right document(placeholder) is displayed, but in the false mode. So you maybe run a python file
> within the Spice environment. This is "not nice", because i always have to press the right mode button manually.
> 
> As already said earlier times, i use QtCreator as a great host system for my own applications, which i implement
> as plugins. 
> 
> After debugging for a while, i found following code segment in "editormanager.cpp", which i think is
> responsible for this behaviour ( It's out of QtCreator 3.0! ):
> 
> Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags)
> {
>     Q_ASSERT(view);
>     if (!editor) {
>         if (!d->m_currentEditor)
>             setCurrentEditor(0, (flags & IgnoreNavigationHistory));
>         return 0;
>     }
>     editor = placeEditor(view, editor);
>     if (!(flags & DoNotChangeCurrentEditor)) {
>         setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
>         if (!(flags & DoNotMakeVisible)) {
>             // switch to design mode?
>             if (editor->isDesignModePreferred()) {
>                 ModeManager::activateMode(Core::Constants::MODE_DESIGN);
>                 ModeManager::setFocusToCurrentMode();
>             } else {
>                 int rootIndex;
>                 findRoot(view, &rootIndex);
>                 if (rootIndex == 0) // main window --> we might need to switch mode
>                     if (!editor->widget()->isVisible())
>                         ModeManager::activateMode(Core::Constants::MODE_EDIT);
>                 editor->widget()->setFocus();
>                 ICore::raiseWindow(editor->widget());
>             }
>         }
>     } else if (!(flags & DoNotMakeVisible)) {
>         view->setCurrentEditor(editor);
>     }
>     return editor;
> }
> 
> 
> I 've changed it to following code:
> 
> Core::IEditor *EditorManager::activateEditor(Core::Internal::EditorView *view, Core::IEditor *editor, OpenEditorFlags flags)
> {
>     Q_ASSERT(view);
> 
>     if (!editor) {
>         if (!d->m_currentEditor)
>             setCurrentEditor(0, (flags & IgnoreNavigationHistory));
>         return 0;
>     }
> 
>     editor = placeEditor(view, editor);
> 
>     if (!(flags & DoNotChangeCurrentEditor)) {
>         setCurrentEditor(editor, (flags & IgnoreNavigationHistory));
>         if (!(flags & DoNotMakeVisible)) {
>             // switch to design mode?
>             if (editor->isDesignModePreferred()) {
>                 ModeManager::activateMode(Core::Constants::MODE_DESIGN);
>                 ModeManager::setFocusToCurrentMode();
>             } else {
>                 int rootIndex;
>                 findRoot(view, &rootIndex);
>                 if (rootIndex == 0) // main window --> we might need to switch mode
>                     if (!editor->widget()->isVisible())
>                         ModeManager::activateMode(Core::Constants::MODE_EDIT);
>                 editor->widget()->setFocus();
>                 ICore::raiseWindow(editor->widget());
> 
> // *** test
> printf("MIME TYPE -->> %s\n", editor->document()->mimeType().toAscii().data() ); fflush(stdout);
> 
> if(      ( editor->document()->mimeType() == QLatin1String("text/x-lpython") )
>        ||( editor->document()->mimeType() == QLatin1String("text/x-python" ) ) ) {
> 
>   ModeManager::activateMode( "Mode.LPy" );
> } else if( editor->document()->mimeType() == QLatin1String("text/x-mpython")     ) {
> 
>   ModeManager::activateMode( "Mode.lmcv" );
> } else if( editor->document()->mimeType() == QLatin1String("text/x-spice")     ) {
> 
>   ModeManager::activateMode( "Mode.LSpice" );
> } else if( editor->document()->mimeType() == QLatin1String("text/x-html")      ) {
> 
>   ModeManager::activateMode( "Mode.lweb" );
> } else if( editor->document()->mimeType() == QLatin1String("text/x-gcode")     ) {
> 
>   ModeManager::activateMode( "Mode.lcnc" );
> }
> // *** test
> 
>             }
>         }
>     } else if (!(flags & DoNotMakeVisible)) {
>         view->setCurrentEditor(editor);
>     }
>     return editor;
> }
> 
> Now it works as expected, but has the big disadvantage, always to patch this file with every new release of the creator.
> I think this does not only belong to me. QtCreator has only two "main modes"( with opened project manager windows ), 
> the designer and the editor mode. These are the two modes, you handle in this code segment.
> 
> Now my question.  Would it have any disadvantage to you, if you would implement something like this pseudocode?:
> 
> 1. Determine mime-type of triggered document ( editor->document()->mimeType() ).
> 2. Was there a mode registered to this mime type?
> 3. Yes, switch to already registered mode.
> 4. No, stay in editor mode.
> 
> With this behaviour many many editors, also binary ones could be applied additional without any patching.
> 
> I also have the problem backwards. If i push the mode buttons, i should remember the "last" used document for each
> mode(which can be more than one).
> 

Actually I want to get rid of Design mode in the not too far future, and instead allow editors to specify that they want as much space as possible, overriding any split layout etc while that editor is open. Design mode was just invented for that, and has many problems (like the necessity to show a corresponding editor in edit mode for it, even though that is totally uninteresting).

It is not quite clear to me how a trigger of a mode change on opening a file with a certain mime type would even help in your case. When working with html+php+JavaScript, for example JavaScript files could also belong to a QML/C++ project. Similarly many other file types are not specific to a "application kind”.
An HTML editor could probably also just be a “full window” editor, so what are the things that couldn’t be done like that, and what do they consist of? Some things could probably also be done with just an IDocumentFactory instead of an editor (which is also used to open projects).
You could probably also just listen to EditorManager::currentEditorChanged and do whatever you want there.

Wrt the “backwards” problem: I want that modes can add their own editor area instead of moving around the editor area from edit mode. E.g. it can be useful to have different split layouts in edit and debug mode - if you work with a split window in edit mode, one often does not want a split view while debugging because of the additional debug windows. This functionality is almost there, since we needed the separate editor areas for the extra editor windows that you can open, but there are still issues when multiple editor areas are present in the same window, which must be fixed first.

Br, Eike

-- 
Eike Ziller, Senior Software Engineer - The Qt Company GmbH
 
The Qt Company GmbH, Rudower Chaussee 13, D-12489 Berlin
Geschäftsführer: Mika Pälsi, Juha Varelius, Tuula Haataja
Sitz der Gesellschaft: Berlin, Registergericht: Amtsgericht Charlottenburg, HRB 144331 B




More information about the Qt-creator mailing list