mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2026-08-15 18:43:59 +00:00
BarWidgetSettingsDialog: refactored to support direct opening.
This commit is contained in:
@@ -2,6 +2,7 @@ import QtQuick
|
||||
import QtQuick.Layouts
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Modules.Settings
|
||||
import qs.Services
|
||||
import qs.Widgets
|
||||
|
||||
@@ -345,4 +346,20 @@ Rectangle {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
MouseArea {
|
||||
anchors.fill: parent
|
||||
acceptedButtons: Qt.RightButton
|
||||
onClicked: {
|
||||
var settingsPanel = PanelService.getPanel("settingsPanel")
|
||||
settingsPanel.requestedTab = SettingsPanel.Tab.Bar
|
||||
settingsPanel.requestedWidgetSettings = {
|
||||
"widgetIndex": root.sectionWidgetIndex,
|
||||
"widgetData": root.widgetSettings,
|
||||
"widgetId": root.widgetId,
|
||||
"sectionId": root.section
|
||||
}
|
||||
settingsPanel.open()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,12 +8,14 @@ import qs.Services
|
||||
|
||||
// Widget Settings Dialog Component
|
||||
Popup {
|
||||
// Don't replace by root!
|
||||
id: widgetSettings
|
||||
id: root
|
||||
|
||||
property int widgetIndex: -1
|
||||
property var widgetData: null
|
||||
property string widgetId: ""
|
||||
property string sectionId: ""
|
||||
|
||||
signal updateWidgetSettings(string section, int index, var settings)
|
||||
|
||||
// Center popup in parent
|
||||
x: (parent.width - width) * 0.5
|
||||
@@ -26,7 +28,7 @@ Popup {
|
||||
|
||||
onOpened: {
|
||||
// Mark this popup has opened in the PanelService
|
||||
PanelService.willOpenPopup(widgetSettings)
|
||||
PanelService.willOpenPopup(root)
|
||||
|
||||
// Load settings when popup opens with data
|
||||
if (widgetData && widgetId) {
|
||||
@@ -35,7 +37,7 @@ Popup {
|
||||
}
|
||||
|
||||
onClosed: {
|
||||
PanelService.willClosePopup(widgetSettings)
|
||||
PanelService.willClosePopup(root)
|
||||
}
|
||||
|
||||
background: Rectangle {
|
||||
@@ -59,7 +61,7 @@ Popup {
|
||||
|
||||
NText {
|
||||
text: I18n.tr("system.widget-settings-title", {
|
||||
"widget": widgetSettings.widgetId
|
||||
"widget": root.widgetId
|
||||
})
|
||||
pointSize: Style.fontSizeL
|
||||
font.weight: Style.fontWeightBold
|
||||
@@ -70,7 +72,7 @@ Popup {
|
||||
NIconButton {
|
||||
icon: "close"
|
||||
tooltipText: I18n.tr("tooltips.close")
|
||||
onClicked: widgetSettings.close()
|
||||
onClicked: root.close()
|
||||
}
|
||||
}
|
||||
|
||||
@@ -101,7 +103,7 @@ Popup {
|
||||
NButton {
|
||||
text: I18n.tr("bar.widget-settings.dialog.cancel")
|
||||
outlined: true
|
||||
onClicked: widgetSettings.close()
|
||||
onClicked: root.close()
|
||||
}
|
||||
|
||||
NButton {
|
||||
@@ -110,8 +112,8 @@ Popup {
|
||||
onClicked: {
|
||||
if (settingsLoader.item && settingsLoader.item.saveSettings) {
|
||||
var newSettings = settingsLoader.item.saveSettings()
|
||||
root.updateWidgetSettings(sectionId, widgetSettings.widgetIndex, newSettings)
|
||||
widgetSettings.close()
|
||||
root.updateWidgetSettings(root.sectionId, root.widgetIndex, newSettings)
|
||||
root.close()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -44,6 +44,7 @@ NPanel {
|
||||
|
||||
property int requestedTab: SettingsPanel.Tab.General
|
||||
property int currentTabIndex: 0
|
||||
property var requestedWidgetSettings: []
|
||||
property var tabsModel: []
|
||||
property var activeScrollView: null
|
||||
|
||||
@@ -220,6 +221,7 @@ NPanel {
|
||||
|
||||
root.tabsModel = newTabs // Assign the generated list to the model
|
||||
}
|
||||
|
||||
// When the panel opens, choose the appropriate tab
|
||||
onOpened: {
|
||||
updateTabsModel()
|
||||
@@ -233,6 +235,7 @@ NPanel {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Now that the UI is settled, set the current tab index.
|
||||
root.currentTabIndex = initialIndex
|
||||
}
|
||||
|
||||
@@ -412,6 +412,36 @@ ColumnLayout {
|
||||
|
||||
Component.onCompleted: {
|
||||
updateAvailableWidgetsModel()
|
||||
|
||||
// This code is only used when we open settings directly from the widget
|
||||
// Check if there's a widget settings request
|
||||
if (settingsPanel.requestedWidgetSettings && Object.keys(settingsPanel.requestedWidgetSettings).length > 0) {
|
||||
Qt.callLater(() => {
|
||||
var component = Qt.createComponent(Qt.resolvedUrl(Quickshell.shellDir + "/Modules/Settings/Bar/BarWidgetSettingsDialog.qml"))
|
||||
|
||||
function instantiateAndOpen() {
|
||||
var dialog = component.createObject(Overlay.overlay, {
|
||||
"widgetIndex": settingsPanel.requestedWidgetSettings.widgetIndex,
|
||||
"widgetData": settingsPanel.requestedWidgetSettings.widgetData,
|
||||
"widgetId": settingsPanel.requestedWidgetSettings.widgetId,
|
||||
"sectionId": settingsPanel.requestedWidgetSettings.sectionId
|
||||
})
|
||||
if (dialog) {
|
||||
dialog.updateWidgetSettings.connect(_updateWidgetSettingsInSection)
|
||||
dialog.open()
|
||||
}
|
||||
}
|
||||
|
||||
if (component.status === Component.Ready) {
|
||||
instantiateAndOpen()
|
||||
} else {
|
||||
component.statusChanged.connect(instantiateAndOpen)
|
||||
}
|
||||
|
||||
// Clear the request after handling
|
||||
settingsPanel.requestedWidgetSettings = []
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
|
||||
Reference in New Issue
Block a user