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_open.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@2x.png</file>
|
||||
<file>images/reset@2x.png</file>
|
||||
|
@@ -40,14 +40,19 @@
|
||||
#include <qtsupport/qtversionmanager.h>
|
||||
#include <qtsupport/baseqtversion.h>
|
||||
|
||||
#include <texteditor/texteditor.h>
|
||||
|
||||
#include <android/androidconstants.h>
|
||||
|
||||
#include <utils/icon.h>
|
||||
#include <utils/mimeconstants.h>
|
||||
#include <utils/proxyaction.h>
|
||||
|
||||
#include <QAction>
|
||||
#include <QMessageBox>
|
||||
#include <QPointer>
|
||||
#include <QTimer>
|
||||
#include <QToolBar>
|
||||
|
||||
using namespace ProjectExplorer;
|
||||
|
||||
@@ -155,12 +160,12 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
||||
|
||||
Core::ActionContainer *menu = Core::ActionManager::actionContainer(
|
||||
Constants::M_BUILDPROJECT);
|
||||
QAction *action = new QAction(Tr::tr("QML Preview"), this);
|
||||
action->setToolTip(Tr::tr("Preview changes to QML code live in your application."));
|
||||
action->setEnabled(ProjectManager::startupProject() != nullptr);
|
||||
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, action,
|
||||
QAction *runPreviewAction = new QAction(Tr::tr("QML Preview"), this);
|
||||
runPreviewAction->setToolTip(Tr::tr("Preview changes to QML code live in your application."));
|
||||
runPreviewAction->setEnabled(ProjectManager::startupProject() != nullptr);
|
||||
connect(ProjectManager::instance(), &ProjectManager::startupProjectChanged, runPreviewAction,
|
||||
&QAction::setEnabled);
|
||||
connect(action, &QAction::triggered, this, [this] {
|
||||
connect(runPreviewAction, &QAction::triggered, this, [this] {
|
||||
if (auto multiLanguageAspect = QmlProjectManager::QmlMultiLanguageAspect::current())
|
||||
m_localeIsoCode = multiLanguageAspect->currentLocale();
|
||||
bool skipDeploy = false;
|
||||
@@ -171,19 +176,52 @@ QmlPreviewPluginPrivate::QmlPreviewPluginPrivate(QmlPreviewPlugin *parent)
|
||||
ProjectExplorerPlugin::runStartupProject(Constants::QML_PREVIEW_RUN_MODE, skipDeploy);
|
||||
});
|
||||
menu->addAction(
|
||||
Core::ActionManager::registerAction(action, "QmlPreview.RunPreview"),
|
||||
Core::ActionManager::registerAction(runPreviewAction, "QmlPreview.RunPreview"),
|
||||
Constants::G_BUILD_RUN);
|
||||
|
||||
menu = Core::ActionManager::actionContainer(Constants::M_FILECONTEXT);
|
||||
action = new QAction(Tr::tr("Preview File"), this);
|
||||
connect(action, &QAction::triggered, q, &QmlPreviewPlugin::previewCurrentFile);
|
||||
QAction *previewFileAction = new QAction(Tr::tr("Preview File"), this);
|
||||
connect(previewFileAction, &QAction::triggered, q, &QmlPreviewPlugin::previewCurrentFile);
|
||||
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);
|
||||
action->setVisible(false);
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, action, [action](Node *node) {
|
||||
previewFileAction->setVisible(false);
|
||||
connect(ProjectTree::instance(), &ProjectTree::currentNodeChanged, previewFileAction,
|
||||
[previewFileAction] (Node *node) {
|
||||
const FileNode *fileNode = node ? node->asFileNode() : nullptr;
|
||||
action->setVisible(fileNode ? fileNode->fileType() == FileType::QML : false);
|
||||
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();
|
||||
|
@@ -3786,6 +3786,29 @@
|
||||
id="path4682"
|
||||
sodipodi:nodetypes="cczccccc" />
|
||||
</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
|
||||
inkscape:groupmode="layer"
|
||||
|
Before Width: | Height: | Size: 368 KiB After Width: | Height: | Size: 369 KiB |
Reference in New Issue
Block a user