QmlDesigner: Assign the correct context to QmlDesigner

The context would be updated when switching between different modes.
Some wrong conditions had caused to prevent this update before.

Before this change:

QmlDesignerPlugin ignores hiding the designer when the new editor is
raised by the editor manager because it hides the designer only when
the current designer is QtQuick. So, the previously opened document
is kept by the document manager, since hideDesigner is not called.
Then, when the user decides to go back to the designer mode,
the QtQuick editor is opened, but the previous document is opened,
so the QmlDesignerPlugin will not call showDesigner (Even if a
different file is opened now).

With this change:

QmlDesignerPlugin calls hideDesigner when a non-QtQuick editor is
raised by the editor manager.
It compares the file paths of the editor and the design document. So,
if they are different, it will try to open and show it again.

Task-number: QDS-9686
Change-Id: I6b962f22a1f3863128ac6a40780fdceeecaec040
Reviewed-by: Thomas Hartmann <thomas.hartmann@qt.io>
This commit is contained in:
Ali Kianian
2023-05-02 15:49:52 +03:00
parent 6eadb5d357
commit d823ba2812

View File

@@ -186,8 +186,9 @@ static bool isDesignerMode(Utils::Id mode)
static bool documentIsAlreadyOpen(DesignDocument *designDocument, Core::IEditor *editor, Utils::Id newMode)
{
return designDocument
&& editor == designDocument->editor()
&& isDesignerMode(newMode);
&& editor == designDocument->editor()
&& isDesignerMode(newMode)
&& designDocument->fileName() == editor->document()->filePath();
}
static bool shouldAssertInException()
@@ -440,14 +441,12 @@ void QmlDesignerPlugin::integrateIntoQtCreator(QWidget *modeWidget)
&Core::ModeManager::currentModeChanged,
[this](Utils::Id newMode, Utils::Id oldMode) {
Core::IEditor *currentEditor = Core::EditorManager::currentEditor();
if (d && currentEditor && checkIfEditorIsQtQuick(currentEditor)
if (isDesignerMode(newMode) && checkIfEditorIsQtQuick(currentEditor)
&& !documentIsAlreadyOpen(currentDesignDocument(), currentEditor, newMode)) {
if (isDesignerMode(newMode)) {
showDesigner();
} else if (currentDesignDocument()
|| (!isDesignerMode(newMode) && isDesignerMode(oldMode))) {
hideDesigner();
}
showDesigner();
} else if (currentDesignDocument()
|| (!isDesignerMode(newMode) && isDesignerMode(oldMode))) {
hideDesigner();
}
});
}