blob: b04ee5f7c7896b878775a24d6075f1a94ecffdd0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
|
// Copyright (C) 2016 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0
#include "entertabdesigneraction.h"
#include <abstractaction.h>
#include <documentmanager.h>
#include <modelnode.h>
#include <nodeabstractproperty.h>
#include <nodemetainfo.h>
#include <qmlitemnode.h>
#include <QCoreApplication>
namespace QmlDesigner {
class EnterTabAction : public DefaultAction
{
public:
EnterTabAction(const QString &description)
: DefaultAction(description)
{ }
public:
void actionTriggered(bool) override
{
DocumentManager::goIntoComponent(m_selectionContext.targetNode());
}
};
EnterTabDesignerAction::EnterTabDesignerAction()
: AbstractActionGroup(QCoreApplication::translate("TabViewToolAction", "Step into Tab"))
{
}
QByteArray EnterTabDesignerAction::category() const
{
return QByteArray();
}
QByteArray EnterTabDesignerAction::menuId() const
{
return "TabViewAction";
}
int EnterTabDesignerAction::priority() const
{
//Editing tabs is above adding tabs
return CustomActionsPriority + 10;
}
void EnterTabDesignerAction::updateContext()
{
menu()->clear();
if (selectionContext().isValid()) {
action()->setEnabled(isEnabled(selectionContext()));
action()->setVisible(isVisible(selectionContext()));
if (action()->isEnabled()) {
const ModelNode selectedModelNode = selectionContext().currentSingleSelectedNode();
if (selectedModelNode.metaInfo().isValid()
&& selectedModelNode.metaInfo().isQtQuickControlsTabView()) {
const NodeAbstractProperty defaultProperty = selectedModelNode
.defaultNodeAbstractProperty();
const QList<QmlDesigner::ModelNode> childModelNodes = defaultProperty.directSubNodes();
for (const QmlDesigner::ModelNode &childModelNode : childModelNodes) {
createActionForTab(childModelNode);
}
}
}
}
}
bool EnterTabDesignerAction::isVisible(const SelectionContext &selectionContext) const
{
if (selectionContext.singleNodeIsSelected()) {
ModelNode selectedModelNode = selectionContext.currentSingleSelectedNode();
return selectedModelNode.metaInfo().isQtQuickControlsTabView();
}
return false;
}
static bool tabViewIsNotEmpty(const SelectionContext &selectionContext)
{
return selectionContext.currentSingleSelectedNode().defaultNodeAbstractProperty().isNodeListProperty();
}
bool EnterTabDesignerAction::isEnabled(const SelectionContext &selectionContext) const
{
return isVisible(selectionContext) && tabViewIsNotEmpty(selectionContext);
}
void EnterTabDesignerAction::createActionForTab(const ModelNode &modelNode)
{
if (modelNode.metaInfo().isQtQuickControlsTab()) {
QmlDesigner::QmlItemNode itemNode(modelNode);
if (itemNode.isValid()) {
QString what = tr("Step into: %1").
arg(itemNode.instanceValue("title").toString());
auto selectionAction = new EnterTabAction(what);
SelectionContext nodeSelectionContext = selectionContext();
nodeSelectionContext.setTargetNode(modelNode);
selectionAction->setSelectionContext(nodeSelectionContext);
menu()->addAction(selectionAction);
}
}
}
} // namespace QmlDesigner
|