From c33624f3d1a1698d041d8a00aef3f45e865955f0 Mon Sep 17 00:00:00 2001
From: Kai Koehne <kai.koehne@nokia.com>
Date: Fri, 13 Aug 2010 12:31:15 +0200
Subject: [PATCH] Disable "Qt Quick->Preview" action if no qmlviewer in the
 PATH

An error dialog would be more explicit, but too late because of string
freeze.
(cherry picked from commit ceca9d9d7abba7a48b4388654a68b22073a050e2)
---
 src/plugins/qmljseditor/qmljseditorplugin.cpp  | 2 ++
 src/plugins/qmljseditor/qmljspreviewrunner.cpp | 4 ++++
 src/plugins/qmljseditor/qmljspreviewrunner.h   | 2 ++
 3 files changed, 8 insertions(+)

diff --git a/src/plugins/qmljseditor/qmljseditorplugin.cpp b/src/plugins/qmljseditor/qmljseditorplugin.cpp
index f998309ac17..e9d79261829 100644
--- a/src/plugins/qmljseditor/qmljseditorplugin.cpp
+++ b/src/plugins/qmljseditor/qmljseditorplugin.cpp
@@ -133,7 +133,9 @@ bool QmlJSEditorPlugin::initialize(const QStringList & /*arguments*/, QString *e
     Core::Command *cmd = addToolAction(m_actionPreview,  am, toolsMenuContext,
                    QLatin1String("QtQuick.Preview"), menuQtQuick, tr("Ctrl+Alt+R"));
     connect(cmd->action(), SIGNAL(triggered()), SLOT(openPreview()));
+
     m_previewRunner = new QmlJSPreviewRunner(this);
+    m_actionPreview->setEnabled(m_previewRunner->isReady());
 
     QAction *followSymbolUnderCursorAction = new QAction(tr("Follow Symbol Under Cursor"), this);
     cmd = am->registerAction(followSymbolUnderCursorAction, Constants::FOLLOW_SYMBOL_UNDER_CURSOR, context);
diff --git a/src/plugins/qmljseditor/qmljspreviewrunner.cpp b/src/plugins/qmljseditor/qmljspreviewrunner.cpp
index 61003606143..7611cecc2b0 100644
--- a/src/plugins/qmljseditor/qmljspreviewrunner.cpp
+++ b/src/plugins/qmljseditor/qmljspreviewrunner.cpp
@@ -24,6 +24,10 @@ QmlJSPreviewRunner::QmlJSPreviewRunner(QObject *parent) :
     m_applicationLauncher.setEnvironment(environment.toStringList());
 }
 
+bool QmlJSPreviewRunner::isReady() const
+{
+    return !m_qmlViewerDefaultPath.isEmpty();
+}
 
 void QmlJSPreviewRunner::run(const QString &filename)
 {
diff --git a/src/plugins/qmljseditor/qmljspreviewrunner.h b/src/plugins/qmljseditor/qmljspreviewrunner.h
index 869327b10cc..1a3c26370fa 100644
--- a/src/plugins/qmljseditor/qmljspreviewrunner.h
+++ b/src/plugins/qmljseditor/qmljspreviewrunner.h
@@ -13,6 +13,8 @@ class QmlJSPreviewRunner : public QObject
     Q_OBJECT
 public:
     explicit QmlJSPreviewRunner(QObject *parent = 0);
+
+    bool isReady() const;
     void run(const QString &filename);
 
 signals:
-- 
GitLab