[Qt-creator] Which plugins are you working on?
Hermann Fieger
hermann.fieger at t-online.de
Sat May 30 15:07:01 CEST 2015
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).
regards, Hermann
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20150530/53634c29/attachment.html>
More information about the Qt-creator
mailing list