fix(storybook): make it possible to inspect popups

add a kbd shortcut (Ctrl+Shift+I) to be able to invoke the "Inspect"
feature for Popup based components; as clicking the "Inspect" button in
the status bar closes the popup itself
This commit is contained in:
Lukáš Tinkl 2023-06-12 16:59:46 +02:00 committed by Lukáš Tinkl
parent ff98144a56
commit 5b94cad94e
2 changed files with 44 additions and 32 deletions

View File

@ -26,6 +26,42 @@ ApplicationWindow {
palette.base: Theme.palette.indirectColor1
font.pixelSize: 13
QtObject {
id: d
function activateInspection(item) {
inspectionWindow.inspect(item)
inspectionWindow.show()
inspectionWindow.requestActivate()
}
function performInspection() {
const getItems = typeName =>
InspectionUtils.findItemsByTypeName(
viewLoader.item, typeName)
const items = [
...getItems(root.currentPage),
...getItems("Custom" + root.currentPage)
]
const lca = InspectionUtils.lowestCommonAncestor(
items, viewLoader.item)
if (!!lca && lca.Overlay.overlay.children.length > 0) {
activateInspection(lca.Overlay.overlay.children[0])
return
}
if (lca) {
activateInspection(lca.parent.contentItem === lca
? lca.parent : lca)
return
}
nothingToInspectDialog.open()
}
}
PagesModel {
id: pagesModel
}
@ -175,37 +211,7 @@ ApplicationWindow {
})
}
function activateInspection(item) {
inspectionWindow.inspect(item)
inspectionWindow.show()
inspectionWindow.requestActivate()
}
onInspectClicked: {
const getItems = typeName =>
InspectionUtils.findItemsByTypeName(
viewLoader.item, typeName)
const items = [
...getItems(root.currentPage),
...getItems("Custom" + root.currentPage)
]
const lca = InspectionUtils.lowestCommonAncestor(
items, viewLoader.item)
if (lca) {
activateInspection(lca.parent.contentItem === lca
? lca.parent : lca)
return
}
if (Overlay.overlay.children.length > 0) {
activateInspection(Overlay.overlay.children[0])
return
}
nothingToInspectDialog.open()
}
onInspectClicked: d.performInspection()
}
}
}
@ -304,4 +310,10 @@ Tips:
property alias hotReloading: hotReloaderControls.enabled
property alias figmaToken: settingsLayout.figmaToken
}
Shortcut {
sequence: "Ctrl+Shift+I"
context: Qt.ApplicationShortcut
onActivated: d.performInspection()
}
}

View File

@ -65,7 +65,7 @@ ToolBar {
ToolSeparator {}
ToolButton {
text: "Inspect"
text: "Inspect (Ctrl+Shift+I)"
Layout.rightMargin: parent.spacing