1
0
mirror of https://github.com/AvengeMedia/DankMaterialShell.git synced 2026-01-24 21:42:51 -05:00

Fix focus issues with add widget dialog

This commit is contained in:
bbedward
2025-10-05 19:17:11 -04:00
parent 2315d423c4
commit fbbf10078f
3 changed files with 52 additions and 40 deletions

View File

@@ -68,6 +68,7 @@ Item {
asynchronous: true
sourceComponent: DankBarTab {
parentModal: root.parentModal
}
}

View File

@@ -8,6 +8,8 @@ import qs.Widgets
Item {
id: dankBarTab
property var parentModal: null
function getWidgetsForPopup() {
return baseWidgetDefinitions.filter(widget => {
if (widget.warning && widget.warning.includes("Plugin is disabled")) {
@@ -1159,7 +1161,7 @@ Item {
widgetSelectionPopup.allWidgets
= dankBarTab.getWidgetsForPopup()
widgetSelectionPopup.targetSection = sectionId
widgetSelectionPopup.safeOpen()
widgetSelectionPopup.show()
}
onRemoveWidget: (sectionId, widgetIndex) => {
dankBarTab.removeWidgetFromSection(
@@ -1231,7 +1233,7 @@ Item {
widgetSelectionPopup.allWidgets
= dankBarTab.getWidgetsForPopup()
widgetSelectionPopup.targetSection = sectionId
widgetSelectionPopup.safeOpen()
widgetSelectionPopup.show()
}
onRemoveWidget: (sectionId, widgetIndex) => {
dankBarTab.removeWidgetFromSection(
@@ -1303,7 +1305,7 @@ Item {
widgetSelectionPopup.allWidgets
= dankBarTab.getWidgetsForPopup()
widgetSelectionPopup.targetSection = sectionId
widgetSelectionPopup.safeOpen()
widgetSelectionPopup.show()
}
onRemoveWidget: (sectionId, widgetIndex) => {
dankBarTab.removeWidgetFromSection(
@@ -1349,7 +1351,7 @@ Item {
WidgetSelectionPopup {
id: widgetSelectionPopup
anchors.centerIn: parent
parentModal: dankBarTab.parentModal
onWidgetSelected: (widgetId, targetSection) => {
dankBarTab.addWidgetToSection(widgetId,
targetSection)

View File

@@ -1,18 +1,20 @@
import QtQuick
import QtQuick.Controls
import qs.Common
import qs.Modals.Common
import qs.Widgets
Popup {
DankModal {
id: root
property var allWidgets: []
property string targetSection: ""
property bool isOpening: false
property string searchQuery: ""
property var filteredWidgets: []
property int selectedIndex: -1
property bool keyboardNavigationActive: false
property Component widgetSelectionContent
property var parentModal: null
signal widgetSelected(string widgetId, string targetSection)
@@ -70,26 +72,33 @@ Popup {
}
}
function safeOpen() {
if (!isOpening && !visible) {
isOpening = true
open()
function show() {
if (parentModal) {
parentModal.shouldHaveFocus = false
}
open()
Qt.callLater(() => {
if (contentLoader.item && contentLoader.item.searchField) {
contentLoader.item.searchField.forceActiveFocus()
}
})
}
function hide() {
close()
if (parentModal) {
parentModal.shouldHaveFocus = Qt.binding(() => {
return parentModal.shouldBeVisible
})
}
}
width: 500
height: 550
modal: true
focus: true
closePolicy: Popup.CloseOnEscape | Popup.CloseOnPressOutside
onOpened: {
isOpening = false
Qt.callLater(() => {
searchField.forceActiveFocus()
})
}
onClosed: {
isOpening = false
allowStacking: true
backgroundOpacity: 0
closeOnEscapeKey: false
onDialogClosed: () => {
allWidgets = []
targetSection = ""
searchQuery = ""
@@ -97,19 +106,19 @@ Popup {
selectedIndex = -1
keyboardNavigationActive = false
}
background: Rectangle {
color: Qt.rgba(Theme.surfaceContainer.r, Theme.surfaceContainer.g,
Theme.surfaceContainer.b, 1)
border.color: Theme.primarySelected
border.width: 0
radius: Theme.cornerRadius
onBackgroundClicked: () => {
return hide()
}
content: widgetSelectionContent
widgetSelectionContent: Component {
FocusScope {
id: widgetKeyHandler
property alias searchField: searchField
contentItem: Item {
anchors.fill: parent
focus: true
Keys.onPressed: event => {
if (event.key === Qt.Key_Escape) {
root.close()
@@ -141,10 +150,8 @@ Popup {
root.close()
}
event.accepted = true
} else if (event.text && event.text.length > 0 && event.text.match(/[a-zA-Z0-9\\s]/)) {
if (!searchField.activeFocus) {
searchField.forceActiveFocus()
}
} else if (!searchField.activeFocus && event.text && event.text.length > 0 && event.text.match(/[a-zA-Z0-9\s]/)) {
searchField.forceActiveFocus()
searchField.insertText(event.text)
event.accepted = true
}
@@ -204,19 +211,20 @@ Popup {
height: 48
cornerRadius: Theme.cornerRadius
backgroundColor: Theme.surfaceContainerHigh
normalBorderColor: Qt.rgba(Theme.outline.r, Theme.outline.g, Theme.outline.b, 0.2)
normalBorderColor: Theme.outlineMedium
focusedBorderColor: Theme.primary
leftIconName: "search"
leftIconSize: Theme.iconSize - 2
leftIconColor: Theme.outline
leftIconSize: Theme.iconSize
leftIconColor: Theme.surfaceVariantText
leftIconFocusedColor: Theme.primary
showClearButton: true
textColor: Theme.surfaceText
font.pixelSize: Theme.fontSizeMedium
placeholderText: "Search widgets..."
placeholderText: ""
text: root.searchQuery
focus: true
ignoreLeftRightKeys: true
keyForwardTargets: [root.contentItem]
keyForwardTargets: [widgetKeyHandler]
onTextEdited: {
root.searchQuery = text
updateFilteredWidgets()
@@ -225,7 +233,7 @@ Popup {
if (event.key === Qt.Key_Escape) {
root.close()
event.accepted = true
} else if (event.key === Qt.Key_Down || event.key === Qt.Key_Up ||
} else if (event.key === Qt.Key_Down || event.key === Qt.Key_Up ||
((event.key === Qt.Key_Return || event.key === Qt.Key_Enter) && text.length === 0)) {
event.accepted = false
}
@@ -322,5 +330,6 @@ Popup {
}
}
}
}
}
}