void QmlDesignerPlugin::selectModelNodeUnderTextCursor()
{
    const int cursorPos = currentDesignDocument()->plainTextEdit()->textCursor().position();
    ModelNode node = currentDesignDocument()->rewriterView()->nodeAtTextCursorPosition(cursorPos);
    if (currentDesignDocument()->rewriterView() && node.isValid())
        currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>() << node);
}
Beispiel #2
0
void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
{
    CrumbleBarInfo clickedCrumbleBarInfo = data.value<CrumbleBarInfo>();

    if (clickedCrumbleBarInfo ==  crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
        return;

    while (clickedCrumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
        crumblePath()->popElement();

    if (!crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().componentId.isEmpty())
        crumblePath()->popElement();

    m_isInternalCalled = true;
    if (clickedCrumbleBarInfo.componentId.isEmpty()
            && clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
        nextFileIsCalledInternally();
        currentDesignDocument()->changeToDocumentModel();
    } else {
        crumblePath()->popElement();
        nextFileIsCalledInternally();
        Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName, Core::Id(),
                                        Core::EditorManager::DoNotMakeVisible);
        if (!clickedCrumbleBarInfo.componentId.isEmpty()) {
            currentDesignDocument()->changeToSubComponent(
                        currentDesignDocument()->rewriterView()->modelNodeForId(clickedCrumbleBarInfo.componentId));
            //pushInFileComponent(clickedCrumbleBarInfo.componentId);
        }
    }
    updateVisibility();
}
void ViewManager::detachRewriterView()
{
    if (currentDesignDocument()->rewriterView()) {
        currentDesignDocument()->rewriterView()->deactivateTextMofifierChangeSignals();
        currentModel()->setRewriterView(0);
    }
}
void CrumbleBar::onCrumblePathElementClicked(const QVariant &data)
{
    CrumbleBarInfo clickedCrumbleBarInfo = data.value<CrumbleBarInfo>();

    if (clickedCrumbleBarInfo ==  crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
        return;

    while (clickedCrumbleBarInfo != crumblePath()->dataForLastIndex().value<CrumbleBarInfo>())
        crumblePath()->popElement();

    if (crumblePath()->dataForLastIndex().value<CrumbleBarInfo>().modelNode.isValid())
        crumblePath()->popElement();

    m_isInternalCalled = true;
    if (!clickedCrumbleBarInfo.modelNode.isValid()
            && clickedCrumbleBarInfo.fileName == currentDesignDocument()->fileName()) {
        nextFileIsCalledInternally();
        currentDesignDocument()->changeToDocumentModel();
        QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster();
    } else {
        showSaveDialog();
        crumblePath()->popElement();
        nextFileIsCalledInternally();
        Core::EditorManager::openEditor(clickedCrumbleBarInfo.fileName, Core::Id(),
                                        Core::EditorManager::DoNotMakeVisible);
        if (clickedCrumbleBarInfo.modelNode.isValid()) {
            currentDesignDocument()->changeToSubComponent(clickedCrumbleBarInfo.modelNode);
            QmlDesignerPlugin::instance()->viewManager().setComponentNode(clickedCrumbleBarInfo.modelNode);
        } else {
            QmlDesignerPlugin::instance()->viewManager().setComponentViewToMaster();
        }
    }
    updateVisibility();
}
void ViewManager::attachRewriterView(TextModifier *textModifier)
{
    if (currentDesignDocument()->rewriterView()) {
        currentDesignDocument()->rewriterView()->setTextModifier(textModifier);
        currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals();
        currentModel()->setRewriterView(currentDesignDocument()->rewriterView());
    }
}
void QmlDesignerPlugin::activateAutoSynchronization()
{
    // text editor -> visual editor
    if (!currentDesignDocument()->isDocumentLoaded())
        currentDesignDocument()->loadDocument(currentDesignDocument()->plainTextEdit());

    currentDesignDocument()->updateActiveQtVersion();
    currentDesignDocument()->attachRewriterToModel();

    resetModelSelection();

    viewManager().attachComponentView();
    viewManager().attachViewsExceptRewriterAndComponetView();

    QList<RewriterView::Error> errors = currentDesignDocument()->qmlSyntaxErrors();
    if (errors.isEmpty()) {
        selectModelNodeUnderTextCursor();
        m_mainWidget->enableWidgets();
        m_mainWidget->setupNavigatorHistory(currentDesignDocument()->textEditor());
    } else {
        m_mainWidget->disableWidgets();
        m_mainWidget->showErrorMessage(errors);
    }

    currentDesignDocument()->updateSubcomponentManager();

    connect(currentDesignDocument()->rewriterView(),
            SIGNAL(errorsChanged(QList<RewriterView::Error>)),
            m_mainWidget,
            SLOT(updateErrorStatus(QList<RewriterView::Error>)));
}
Beispiel #7
0
void ViewManager::attachRewriterView()
{
    if (currentDesignDocument()->rewriterView()) {
        currentDesignDocument()->rewriterView()->setWidgetStatusCallback([this](bool enable) {
            if (enable)
                enableWidgets();
            else
                disableWidgets();
        });

        currentModel()->setRewriterView(currentDesignDocument()->rewriterView());
        currentDesignDocument()->rewriterView()->reactivateTextMofifierChangeSignals();
    }
}
void QmlDesignerPlugin::createDesignModeWidget()
{
    d->mainWidget = new Internal::DesignModeWidget;

    d->context = new Internal::DesignModeContext(d->mainWidget);
    Core::ICore::addContextObject(d->context);
    Core::Context qmlDesignerMainContext(Constants::C_QMLDESIGNER);
    Core::Context qmlDesignerFormEditorContext(Constants::C_QMLFORMEDITOR);
    Core::Context qmlDesignerNavigatorContext(Constants::C_QMLNAVIGATOR);

    d->context->context().add(qmlDesignerMainContext);
    d->context->context().add(qmlDesignerFormEditorContext);
    d->context->context().add(qmlDesignerNavigatorContext);
    d->context->context().add(ProjectExplorer::Constants::LANG_QMLJS);

    d->shortCutManager.registerActions(qmlDesignerMainContext, qmlDesignerFormEditorContext, qmlDesignerNavigatorContext);

    connect(Core::EditorManager::instance(), &Core::EditorManager::currentEditorChanged, [=] (Core::IEditor *editor) {
        if (d && checkIfEditorIsQtQuick(editor) && isInDesignerMode()) {
            d->shortCutManager.updateActions(editor);
            changeEditor();
        }
    });

    connect(Core::EditorManager::instance(), &Core::EditorManager::editorsClosed, [=] (QList<Core::IEditor*> editors) {
        if (d) {
            if (d->documentManager.hasCurrentDesignDocument()
                    && editors.contains(d->documentManager.currentDesignDocument()->textEditor()))
                hideDesigner();

            d->documentManager.removeEditors(editors);
        }
    });

    connect(Core::ModeManager::instance(), &Core::ModeManager::currentModeChanged,
        [=] (Core::Id newMode, Core::Id oldMode) {
        if (d && Core::EditorManager::currentEditor() && checkIfEditorIsQtQuick
                (Core::EditorManager::currentEditor()) && !documentIsAlreadyOpen(
                currentDesignDocument(), Core::EditorManager::currentEditor(), newMode)) {

            if (!isDesignerMode(newMode) && isDesignerMode(oldMode))
                hideDesigner();
            else if (Core::EditorManager::currentEditor() && isDesignerMode(newMode))
                showDesigner();
            else if (currentDesignDocument())
                hideDesigner();
        }
    });
}
Beispiel #9
0
static void handleDelegate(const ModelNode &modelNode)
{
    if (modelNode.metaInfo().isView()
            && modelNode.hasNodeProperty("delegate")
            && modelNode.nodeProperty("delegate").modelNode().nodeSourceType() == ModelNode::NodeWithComponentSource)
        currentDesignDocument()->changeToSubComponent(modelNode.nodeProperty("delegate").modelNode());
}
Beispiel #10
0
static void openComponentSourcePropertyOfLoader(const ModelNode &modelNode)
{
    QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally();

    QHash<PropertyName, QVariant> propertyHash;

    getProperties(modelNode, propertyHash);

    ModelNode componentModelNode;

    if (modelNode.hasNodeProperty("sourceComponent")) {
        componentModelNode = modelNode.nodeProperty("sourceComponent").modelNode();
    } else if (modelNode.hasNodeListProperty("component")) {

     /*
     * The component property should be a NodeProperty, but currently is a NodeListProperty, because
     * the default property is always implcitly a NodeListProperty. This is something that has to be fixed.
     */

        componentModelNode = modelNode.nodeListProperty("component").toModelNodeList().first();
    }

    Core::EditorManager::openEditor(componentModelNode.metaInfo().componentFileName(), Core::Id(), Core::EditorManager::DoNotMakeVisible);

    ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode();
    applyProperties(rootModelNode, propertyHash);
}
void QmlDesignerPlugin::onCurrentModeChanged(Core::IMode *newMode, Core::IMode *oldMode)
{
    if (Core::EditorManager::currentEditor()
            && checkIfEditorIsQtQuick(Core::EditorManager::currentEditor())
            && !documentIsAlreadyOpen(currentDesignDocument(), Core::EditorManager::currentEditor(), newMode)) {

        if (!isDesignerMode(newMode) && isDesignerMode(oldMode))
            hideDesigner();
        else  if (Core::EditorManager::currentEditor()
                  && isDesignerMode(newMode)
                  && isQmlFile(Core::EditorManager::currentEditor()))
            showDesigner();
        else if (currentDesignDocument())
            hideDesigner();
    }
}
Beispiel #12
0
static void handleTabComponent(const ModelNode &modelNode)
{
    if (modelNode.hasNodeProperty("component")
            && modelNode.nodeProperty("component").modelNode().nodeSourceType() == ModelNode::NodeWithComponentSource) {
        currentDesignDocument()->changeToSubComponent(modelNode.nodeProperty("component").modelNode());
    }
}
static CrumbleBarInfo createCrumbleBarInfoFromModelNode(const ModelNode &modelNode)
{
    CrumbleBarInfo crumbleBarInfo;
    crumbleBarInfo.displayName = componentIdForModelNode(modelNode);
    crumbleBarInfo.fileName = currentDesignDocument()->textEditor()->document()->filePath().toString();
    crumbleBarInfo.modelNode = modelNode;

    return crumbleBarInfo;
}
void QmlDesignerPlugin::hideDesigner()
{
    if (currentDesignDocument()
            && currentDesignDocument()->currentModel()
            && !currentDesignDocument()->hasQmlSyntaxErrors())
        jumpTextCursorToSelectedModelNode();


    if (m_documentManager.hasCurrentDesignDocument()) {
        deactivateAutoSynchronization();
        m_mainWidget->saveSettings();
    }

    m_shortCutManager.disconnectUndoActions(currentDesignDocument());

    m_documentManager.setCurrentDesignDocument(0);

    m_shortCutManager.updateUndoActions(0);
}
Beispiel #15
0
static inline void openInlineComponent(const ModelNode &modelNode)
{

    if (!modelNode.isValid() || !modelNode.metaInfo().isValid())
        return;

    if (!currentDesignDocument())
        return;

    QHash<PropertyName, QVariant> propertyHash;

    getProperties(modelNode, propertyHash);

    handleComponent(modelNode);
    handleDelegate(modelNode);
    handleTabComponent(modelNode);

    ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode();
    applyProperties(rootModelNode, propertyHash);
}
void CrumbleBar::showSaveDialog()
{
    DesignerSettings settings = QmlDesignerPlugin::instance()->settings();

    if (settings.alwaysSaveInCrumbleBar) {
        Core::DocumentManager::saveModifiedDocumentSilently(currentDesignDocument()->editor()->document());
    } else {
        bool alwaysSave;
        bool canceled;

        Core::DocumentManager::saveModifiedDocument(currentDesignDocument()->editor()->document(),
                                                    tr("Save the changes to preview them correctly."),
                                                    &canceled,
                                                    tr("Always save when leaving subcomponent"),
                                                    &alwaysSave);

        settings.alwaysSaveInCrumbleBar = alwaysSave;
        QmlDesignerPlugin::instance()->setSettings(settings);
    }
}
void QmlDesignerPlugin::showDesigner()
{
    Q_ASSERT(!m_documentManager.hasCurrentDesignDocument());

    m_shortCutManager.disconnectUndoActions(currentDesignDocument());

    m_documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());

    m_shortCutManager.connectUndoActions(currentDesignDocument());

    m_mainWidget->initialize();

    if (m_documentManager.hasCurrentDesignDocument()) {
        activateAutoSynchronization();
        m_shortCutManager.updateActions(currentDesignDocument()->textEditor());
        m_viewManager.pushFileOnCrumbleBar(m_documentManager.currentDesignDocument()->fileName());
    }

    m_shortCutManager.updateUndoActions(currentDesignDocument());
}
Beispiel #18
0
static void openFileComponent(const ModelNode &modelNode)
{
    QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally();

    QHash<PropertyName, QVariant> propertyHash;

    getProperties(modelNode, propertyHash);
    Core::EditorManager::openEditor(modelNode.metaInfo().componentFileName(), Core::Id(), Core::EditorManager::DoNotMakeVisible);

    ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode();
    applyProperties(rootModelNode, propertyHash);
}
void QmlDesignerPlugin::deactivateAutoSynchronization()
{
    viewManager().detachViewsExceptRewriterAndComponetView();
    viewManager().detachComponentView();
    viewManager().detachRewriterView();
    documentManager().currentDesignDocument()->resetToDocumentModel();

    disconnect(currentDesignDocument()->rewriterView(),
               SIGNAL(errorsChanged(QList<RewriterView::Error>)),
               m_mainWidget,
               SLOT(updateErrorStatus(QList<RewriterView::Error>)));

}
void QmlDesignerPlugin::changeEditor()
{
    if (m_documentManager.hasCurrentDesignDocument()) {
        deactivateAutoSynchronization();
        m_mainWidget->saveSettings();
    }

    m_shortCutManager.disconnectUndoActions(currentDesignDocument());

    m_documentManager.setCurrentDesignDocument(Core::EditorManager::currentEditor());

    m_mainWidget->initialize();

    m_shortCutManager.connectUndoActions(currentDesignDocument());

    if (m_documentManager.hasCurrentDesignDocument()) {
        activateAutoSynchronization();
        m_viewManager.pushFileOnCrumbleBar(m_documentManager.currentDesignDocument()->fileName());
        m_viewManager.setComponentViewToMaster();
    }

    m_shortCutManager.updateUndoActions(currentDesignDocument());
}
Beispiel #21
0
static void openSourcePropertyOfLoader(const ModelNode &modelNode)
{
    QmlDesignerPlugin::instance()->viewManager().nextFileIsCalledInternally();

    QHash<PropertyName, QVariant> propertyHash;

    QString componentFileName = modelNode.variantProperty("source").value().toString();
    QString componentFilePath = modelNode.model()->fileUrl().resolved(QUrl::fromLocalFile(componentFileName)).toLocalFile();

    getProperties(modelNode, propertyHash);
    Core::EditorManager::openEditor(componentFilePath, Core::Id(), Core::EditorManager::DoNotMakeVisible);

    ModelNode rootModelNode = currentDesignDocument()->rewriterView()->rootModelNode();
    applyProperties(rootModelNode, propertyHash);
}
void QmlDesignerPlugin::onCurrentModeChanged(Core::IMode *newMode, Core::IMode *oldMode)
{
    if (!Core::EditorManager::currentEditor())
        return;

    if (Core::EditorManager::currentEditor()
            && Core::EditorManager::currentEditor()->id() != QmlJSEditor::Constants::C_QMLJSEDITOR_ID)
        return;

    if ((currentDesignDocument()
         && Core::EditorManager::currentEditor() == currentDesignDocument()->editor())
            && isDesignerMode(newMode))
        return;

    if (!isDesignerMode(newMode) && isDesignerMode(oldMode))
        hideDesigner();
    else  if (Core::EditorManager::currentEditor()
              && isDesignerMode(newMode)
              && isQmlFile(Core::EditorManager::currentEditor()))
        showDesigner();
    else if (currentDesignDocument())
        hideDesigner();

}
void QmlDesignerPlugin::jumpTextCursorToSelectedModelNode()
{
    // visual editor -> text editor
    ModelNode selectedNode;
    if (!currentDesignDocument()->rewriterView()->selectedModelNodes().isEmpty())
        selectedNode = currentDesignDocument()->rewriterView()->selectedModelNodes().first();

    if (selectedNode.isValid()) {
        const int nodeOffset = currentDesignDocument()->rewriterView()->nodeOffset(selectedNode);
        if (nodeOffset > 0) {
            const ModelNode currentSelectedNode
                    = currentDesignDocument()->rewriterView()->nodeAtTextCursorPosition(currentDesignDocument()->plainTextEdit()->textCursor().position());
            if (currentSelectedNode != selectedNode) {
                int line, column;
                currentDesignDocument()->textEditor()->convertPosition(nodeOffset, &line, &column);
                currentDesignDocument()->textEditor()->gotoLine(line, column);
            }
        }
    }
}
void ViewManager::attachItemLibraryView()
{
    setItemLibraryViewResourcePath(QFileInfo(currentDesignDocument()->fileName()).absolutePath());
    currentModel()->attachView(&d->itemLibraryView);
}
void QmlDesignerPlugin::resetModelSelection()
{
    if (currentDesignDocument()->rewriterView() && currentDesignDocument()->currentModel())
        currentDesignDocument()->rewriterView()->setSelectedModelNodes(QList<ModelNode>());
}
QString ViewManager::pathToQt() const
{
    QtSupport::BaseQtVersion *activeQtVersion = QtSupport::QtVersionManager::instance()->version(currentDesignDocument()->qtVersionId());
    if (activeQtVersion && (activeQtVersion->qtVersion() >= QtSupport::QtVersionNumber(4, 7, 1))
            && (activeQtVersion->type() == QLatin1String(QtSupport::Constants::DESKTOPQT)
                || activeQtVersion->type() == QLatin1String(QtSupport::Constants::SIMULATORQT)))
        return activeQtVersion->qmakeProperty("QT_INSTALL_DATA");

    return QString();
}
Model *ViewManager::documentModel() const
{
    return currentDesignDocument()->documentModel();
}
void ViewManager::detachComponentView()
{
    QObject::disconnect(m_componentView.action(), SIGNAL(currentComponentChanged(ModelNode)), currentDesignDocument(), SLOT(changeToSubComponent(ModelNode)));
    documentModel()->detachView(&m_componentView);
}
Beispiel #29
0
static void handleComponent(const ModelNode &modelNode)
{
    if (modelNode.nodeSourceType() == ModelNode::NodeWithComponentSource)
        currentDesignDocument()->changeToSubComponent(modelNode);
}