forked from qt-creator/qt-creator
QmlPreview: Add QML Preview button to QML editor toolbar
This adds the action from "Build->QML Preview" into the QML editor toolbar. Fixes: QTCREATORBUG-30078 Change-Id: I848b33f006b51866dde2565bd7f76c1eac0f3d28 Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
BIN
src/libs/utils/images/eyeoverlay.png
Normal file
BIN
src/libs/utils/images/eyeoverlay.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 141 B |
BIN
src/libs/utils/images/eyeoverlay@2x.png
Normal file
BIN
src/libs/utils/images/eyeoverlay@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 262 B |
@@ -168,6 +168,8 @@
|
|||||||
<file>images/eye_closed@2x.png</file>
|
<file>images/eye_closed@2x.png</file>
|
||||||
<file>images/eye_open.png</file>
|
<file>images/eye_open.png</file>
|
||||||
<file>images/eye_open@2x.png</file>
|
<file>images/eye_open@2x.png</file>
|
||||||
|
<file>images/eyeoverlay.png</file>
|
||||||
|
<file>images/eyeoverlay@2x.png</file>
|
||||||
<file>images/desktopdevicesmall.png</file>
|
<file>images/desktopdevicesmall.png</file>
|
||||||
<file>images/desktopdevicesmall@2x.png</file>
|
<file>images/desktopdevicesmall@2x.png</file>
|
||||||
<file>images/reset@2x.png</file>
|
<file>images/reset@2x.png</file>
|
||||||
|
@@ -40,14 +40,19 @@
|
|||||||
#include <qtsupport/qtversionmanager.h>
|
#include <qtsupport/qtversionmanager.h>
|
||||||
#include <qtsupport/baseqtversion.h>
|
#include <qtsupport/baseqtversion.h>
|
||||||
|
|
||||||
|
#include <texteditor/texteditor.h>
|
||||||
|
|
||||||
#include <android/androidconstants.h>
|
#include <android/androidconstants.h>
|
||||||
|
|
||||||
|
#include <utils/icon.h>
|
||||||
#include <utils/mimeconstants.h>
|
#include <utils/mimeconstants.h>
|
||||||
|
#include <utils/proxyaction.h>
|
||||||
|
|
||||||
#include <QAction>
|
#include <QAction>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
#include <QTimer>
|
#include <QTimer>
|
||||||
|
#include <QToolBar>
|
||||||
|
|
||||||
using namespace ProjectExplorer;
|
using namespace ProjectExplorer;
|
||||||
|
|
||||||
@@ -155,12 +160,12 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
|||||||
|
|
||||||
Core::ActionContainer *menu = Core::ActionManager::actionContainer(
|
Core::ActionContainer *menu = Core::ActionManager::actionContainer(
|
||||||
Constants::M_BUILDPROJECT);
|
Constants::M_BUILDPROJECT);
|
||||||
QAction *action = new QAction(Tr::tr("QML Preview"), this);
|
QAction *runPreviewAction = new QAction(Tr::tr("QML Preview"), this);
|
||||||
action->setToolTip(Tr::tr("Preview changes to QML code live in your application."));
|
runPreviewAction->setToolTip(Tr::tr("Preview changes to QML code live in your application."));
|
||||||
action->setEnabled(ProjectManager::startupProject() != nullptr);
|
runPreviewAction->setEnabled(ProjectManager::startupProject() != nullptr);
|
||||||
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, action,
|
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, runPreviewAction,
|
||||||
&QAction::setEnabled);
|
&QAction::setEnabled);
|
||||||
connect(action, &QAction::triggered, this, [this] {
|
connect(runPreviewAction, &QAction::triggered, this, [this] {
|
||||||
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
||||||
m_localeIsoCode = multiLanguageAspect->currentLocale();
|
m_localeIsoCode = multiLanguageAspect->currentLocale();
|
||||||
bool skipDeploy = false;
|
bool skipDeploy = false;
|
||||||
@@ -171,19 +176,52 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
|||||||
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE, skipDeploy);
|
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE, skipDeploy);
|
||||||
});
|
});
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
Core::ActionManager::registerAction(action, "QmlPreview.RunPreview"),
|
Core::ActionManager::registerAction(runPreviewAction, "QmlPreview.RunPreview"),
|
||||||
Constants::G_BUILD_RUN);
|
Constants::G_BUILD_RUN);
|
||||||
|
|
||||||
menu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT);
|
menu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT);
|
||||||
action = new QAction(Tr::tr("Preview File"), this);
|
QAction *previewFileAction = new QAction(Tr::tr("Preview File"), this);
|
||||||
connect(action, &QAction::triggered, q, &QmlPreviewPlugin::previewCurrentFile);
|
connect(previewFileAction, &QAction::triggered, q, &QmlPreviewPlugin::previewCurrentFile);
|
||||||
menu->addAction(
|
menu->addAction(
|
||||||
Core::ActionManager::registerAction(action, "QmlPreview.PreviewFile", Core::Context(Constants::C_PROJECT_TREE)),
|
Core::ActionManager::registerAction(previewFileAction, "QmlPreview.PreviewFile",
|
||||||
|
Core::Context(Constants::C_PROJECT_TREE)),
|
||||||
Constants::G_FILE_OTHER);
|
Constants::G_FILE_OTHER);
|
||||||
action->setVisible(false);
|
previewFileAction->setVisible(false);
|
||||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action](Node *node) {
|
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, previewFileAction,
|
||||||
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
[previewFileAction] (Node *node) {
|
||||||
action->setVisible(fileNode ? fileNode->fileType() == FileType::QML : false);
|
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
||||||
|
previewFileAction->setVisible(fileNode && fileNode->fileType() == FileType::QML);
|
||||||
|
});
|
||||||
|
connect(Core::EditorManager::instance(), &Core::EditorManager::editorOpened, this,
|
||||||
|
[runPreviewAction] (Core::IEditor *editor) {
|
||||||
|
if (!editor)
|
||||||
|
return;
|
||||||
|
if (!editor->document())
|
||||||
|
return;
|
||||||
|
|
||||||
|
if (const QString mimeType = editor->document()->mimeType();
|
||||||
|
mimeType != Utils::Constants::QML_MIMETYPE
|
||||||
|
&& mimeType != Utils::Constants::QMLUI_MIMETYPE) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
auto *textEditor = qobject_cast<TextEditor::BaseTextEditor *>(editor);
|
||||||
|
if (!textEditor)
|
||||||
|
return;
|
||||||
|
TextEditor::TextEditorWidget *widget = textEditor->editorWidget();
|
||||||
|
if (!widget)
|
||||||
|
return;
|
||||||
|
QToolBar *toolBar = widget->toolBar();
|
||||||
|
if (!toolBar)
|
||||||
|
return;
|
||||||
|
|
||||||
|
const QIcon icon = Utils::Icon({
|
||||||
|
{":/utils/images/run_small.png", Utils::Theme::IconsRunToolBarColor},
|
||||||
|
{":/utils/images/eyeoverlay.png", Utils::Theme::IconsDebugColor}
|
||||||
|
}).icon();
|
||||||
|
Utils::ProxyAction *action =
|
||||||
|
Utils::ProxyAction::proxyActionWithIcon(runPreviewAction, icon);
|
||||||
|
toolBar->insertAction(nullptr, action);
|
||||||
});
|
});
|
||||||
|
|
||||||
m_parseThread.start();
|
m_parseThread.start();
|
||||||
|
@@ -3786,6 +3786,29 @@
|
|||||||
id="path4682"
|
id="path4682"
|
||||||
sodipodi:nodetypes="cczccccc" />
|
sodipodi:nodetypes="cczccccc" />
|
||||||
</g>
|
</g>
|
||||||
|
<g
|
||||||
|
id="src/libs/utils/images/eyeoverlay">
|
||||||
|
<use
|
||||||
|
style="display:inline"
|
||||||
|
transform="translate(2033,132)"
|
||||||
|
height="100%"
|
||||||
|
width="100%"
|
||||||
|
id="use3"
|
||||||
|
xlink:href="#backgroundRect"
|
||||||
|
y="0"
|
||||||
|
x="0" />
|
||||||
|
<path
|
||||||
|
id="path5"
|
||||||
|
style="fill:none;stroke:#000000;stroke-linejoin:miter;stroke-dasharray:none"
|
||||||
|
d="m 2023.5,580 c 2,3.33 6,3.33 8,0 -2.5,-3.35 -5.5,-3.32 -8,0 z"
|
||||||
|
sodipodi:nodetypes="ccc" />
|
||||||
|
<circle
|
||||||
|
style="fill:#000000;fill-opacity:1;stroke:none"
|
||||||
|
id="path6"
|
||||||
|
cy="579.5"
|
||||||
|
cx="2027.5"
|
||||||
|
r="1.5" />
|
||||||
|
</g>
|
||||||
</g>
|
</g>
|
||||||
<g
|
<g
|
||||||
inkscape:groupmode="layer"
|
inkscape:groupmode="layer"
|
||||||
|
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 369 KiB |
Reference in New Issue
Block a user