mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
settings: added helpers function to open settings and focus a subtab
This commit is contained in:
@@ -464,6 +464,7 @@ Item {
|
||||
Logger.i("CustomButton", `Executing command: ${leftClickExec}`);
|
||||
} else if (!leftClickUpdateText) {
|
||||
BarService.openWidgetSettings(screen, section, sectionWidgetIndex, widgetId, widgetSettings);
|
||||
//SettingsPanelService.openToTab(SettingsPanel.Tab.Bar, 1, screen);
|
||||
}
|
||||
if (!textStream && leftClickUpdateText) {
|
||||
runTextCommand();
|
||||
|
||||
@@ -172,6 +172,35 @@ Item {
|
||||
highlightClearTimer.restart();
|
||||
}
|
||||
|
||||
// Navigate to a tab and optionally a subtab (simpler than navigateToResult, no highlighting)
|
||||
function navigateToTab(tabId, subTabIndex) {
|
||||
// Find the tab index by tab ID
|
||||
let tabIndex = -1;
|
||||
for (let i = 0; i < tabsModel.length; i++) {
|
||||
if (tabsModel[i].id === tabId) {
|
||||
tabIndex = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (tabIndex < 0)
|
||||
return;
|
||||
|
||||
const hasSubTab = subTabIndex !== null && subTabIndex !== undefined && subTabIndex >= 0;
|
||||
_pendingSubTab = hasSubTab ? subTabIndex : -1;
|
||||
|
||||
// Check if we're already on this tab
|
||||
const alreadyOnTab = (currentTabIndex === tabIndex);
|
||||
|
||||
currentTabIndex = tabIndex;
|
||||
|
||||
if (alreadyOnTab && activeTabContent && hasSubTab) {
|
||||
// Tab is already loaded, apply subtab directly
|
||||
setSubTabIndex(subTabIndex);
|
||||
_pendingSubTab = -1;
|
||||
}
|
||||
}
|
||||
|
||||
function searchSelectNext() {
|
||||
if (searchResults.length === 0)
|
||||
return;
|
||||
|
||||
@@ -94,6 +94,7 @@ SmartPanel {
|
||||
}
|
||||
|
||||
property int requestedTab: SettingsPanel.Tab.General
|
||||
property int requestedSubTab: -1
|
||||
property var requestedEntry: null
|
||||
|
||||
// Content state - these are synced with SettingsContent when panel opens
|
||||
@@ -146,6 +147,13 @@ SmartPanel {
|
||||
PanelService.willOpenPanel(root);
|
||||
}
|
||||
|
||||
// Open to a specific tab and optionally a subtab
|
||||
function openToTab(tab, subTab, buttonItem, buttonName) {
|
||||
requestedTab = tab !== undefined ? tab : SettingsPanel.Tab.General;
|
||||
requestedSubTab = subTab !== undefined ? subTab : -1;
|
||||
open(buttonItem, buttonName);
|
||||
}
|
||||
|
||||
// When the panel opens, initialize content
|
||||
onOpened: {
|
||||
if (_settingsContent) {
|
||||
@@ -158,6 +166,11 @@ SmartPanel {
|
||||
} else {
|
||||
_settingsContent.requestedTab = requestedTab;
|
||||
_settingsContent.initialize();
|
||||
if (requestedSubTab >= 0) {
|
||||
const subTab = requestedSubTab;
|
||||
requestedSubTab = -1;
|
||||
Qt.callLater(() => _settingsContent.navigateToTab(requestedTab, subTab));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,6 +28,12 @@ FloatingWindow {
|
||||
if (visible) {
|
||||
settingsContent.requestedTab = SettingsPanelService.requestedTab;
|
||||
settingsContent.initialize();
|
||||
if (SettingsPanelService.requestedSubTab >= 0) {
|
||||
const tab = SettingsPanelService.requestedTab;
|
||||
const subTab = SettingsPanelService.requestedSubTab;
|
||||
SettingsPanelService.requestedSubTab = -1;
|
||||
Qt.callLater(() => settingsContent.navigateToTab(tab, subTab));
|
||||
}
|
||||
SettingsPanelService.isWindowOpen = true;
|
||||
} else {
|
||||
SettingsPanelService.isWindowOpen = false;
|
||||
|
||||
@@ -3,6 +3,7 @@ pragma Singleton
|
||||
import QtQuick
|
||||
import Quickshell
|
||||
import qs.Commons
|
||||
import qs.Services.UI
|
||||
|
||||
Singleton {
|
||||
id: root
|
||||
@@ -16,11 +17,42 @@ Singleton {
|
||||
// Requested tab when opening
|
||||
property int requestedTab: 0
|
||||
|
||||
// Requested subtab when opening (-1 means no specific subtab)
|
||||
property int requestedSubTab: -1
|
||||
|
||||
signal windowOpened
|
||||
signal windowClosed
|
||||
|
||||
// Unified function to open settings to a specific tab and subtab
|
||||
// Respects user's settingsPanelMode setting (window vs panel)
|
||||
// For panel mode, screen parameter is required
|
||||
function openToTab(tab, subTab, screen) {
|
||||
const tabId = tab !== undefined ? tab : 0;
|
||||
const subTabId = subTab !== undefined ? subTab : -1;
|
||||
|
||||
if (Settings.data.ui.settingsPanelMode === "window") {
|
||||
requestedTab = tabId;
|
||||
requestedSubTab = subTabId;
|
||||
if (settingsWindow) {
|
||||
settingsWindow.visible = true;
|
||||
isWindowOpen = true;
|
||||
windowOpened();
|
||||
}
|
||||
} else {
|
||||
if (!screen) {
|
||||
Logger.w("SettingsPanelService", "Screen parameter required for panel mode");
|
||||
return;
|
||||
}
|
||||
var settingsPanel = PanelService.getPanel("settingsPanel", screen);
|
||||
if (settingsPanel) {
|
||||
settingsPanel.openToTab(tabId, subTabId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function openWindow(tab) {
|
||||
requestedTab = tab !== undefined ? tab : 0;
|
||||
requestedSubTab = -1;
|
||||
if (settingsWindow) {
|
||||
settingsWindow.visible = true;
|
||||
isWindowOpen = true;
|
||||
|
||||
Reference in New Issue
Block a user