mirror of
https://github.com/noctalia-dev/noctalia-shell.git
synced 2026-05-11 17:08:27 +08:00
feat(bar-cb): add custom tooltip option to CustomButton widget
This commit is contained in:
@@ -103,6 +103,8 @@
|
||||
"dynamic-text": "Dynamic text",
|
||||
"enable-colorization-description": "Enable colorization for the custom button icon and text, applying theme colors.",
|
||||
"enable-colorization-label": "Enable colorization",
|
||||
"general-tooltip-text-description": "Custom text to display in the button's tooltip.",
|
||||
"general-tooltip-text-label": "Custom tooltip text",
|
||||
"hide-mode-always-expanded": "Always expanded",
|
||||
"hide-mode-description": "Controls widget visibility when the command has no output.",
|
||||
"hide-mode-expand-with-output": "Expand when has output",
|
||||
|
||||
@@ -60,6 +60,8 @@ Item {
|
||||
readonly property bool showIcon: (widgetSettings.showIcon !== undefined) ? widgetSettings.showIcon : true
|
||||
readonly property bool showExecTooltip: widgetSettings.showExecTooltip !== undefined ? widgetSettings.showExecTooltip : (widgetMetadata.showExecTooltip !== undefined ? widgetMetadata.showExecTooltip : true)
|
||||
readonly property bool showTextTooltip: widgetSettings.showTextTooltip !== undefined ? widgetSettings.showTextTooltip : (widgetMetadata.showTextTooltip !== undefined ? widgetMetadata.showTextTooltip : true)
|
||||
readonly property string generalTooltipText: widgetSettings.generalTooltipText !== undefined ? widgetSettings.generalTooltipText : (widgetMetadata.generalTooltipText || "")
|
||||
readonly property bool _hasCustomTooltip: generalTooltipText.trim() !== ""
|
||||
readonly property string hideMode: widgetSettings.hideMode || "alwaysExpanded"
|
||||
readonly property bool hasOutput: _dynamicText !== ""
|
||||
readonly property bool shouldForceOpen: textStream && (hideMode === "alwaysExpanded" || hideMode === "maxTransparent")
|
||||
@@ -205,46 +207,61 @@ Item {
|
||||
forceOpen: _pillForceOpen
|
||||
customTextIconColor: iconColor
|
||||
|
||||
tooltipText: {
|
||||
var tooltipLines = [];
|
||||
// Helper function to build tooltip content
|
||||
function _buildTooltipContent() {
|
||||
var lines = [];
|
||||
|
||||
// Add custom tooltip if set
|
||||
if (_hasCustomTooltip) {
|
||||
lines.push(generalTooltipText);
|
||||
}
|
||||
|
||||
// Add command details if enabled and available
|
||||
if (showExecTooltip && hasExec) {
|
||||
if (leftClickExec !== "") {
|
||||
tooltipLines.push(`Left click: ${leftClickExec}.`);
|
||||
lines.push(`Left click: ${leftClickExec}.`);
|
||||
}
|
||||
if (rightClickExec !== "") {
|
||||
tooltipLines.push(`Right click: ${rightClickExec}.`);
|
||||
lines.push(`Right click: ${rightClickExec}.`);
|
||||
}
|
||||
if (middleClickExec !== "") {
|
||||
tooltipLines.push(`Middle click: ${middleClickExec}.`);
|
||||
lines.push(`Middle click: ${middleClickExec}.`);
|
||||
}
|
||||
if (wheelMode === "unified" && wheelExec !== "") {
|
||||
tooltipLines.push(`Wheel: ${wheelExec}.`);
|
||||
lines.push(`Wheel: ${wheelExec}.`);
|
||||
} else if (wheelMode === "separate") {
|
||||
if (wheelUpExec !== "") {
|
||||
tooltipLines.push(`Wheel up: ${wheelUpExec}.`);
|
||||
lines.push(`Wheel up: ${wheelUpExec}.`);
|
||||
}
|
||||
if (wheelDownExec !== "") {
|
||||
tooltipLines.push(`Wheel down: ${wheelDownExec}.`);
|
||||
lines.push(`Wheel down: ${wheelDownExec}.`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Add dynamic text tooltip if enabled and available
|
||||
if (showTextTooltip && _dynamicTooltip !== "") {
|
||||
if (tooltipLines.length > 0) {
|
||||
tooltipLines.push("");
|
||||
}
|
||||
tooltipLines.push(_dynamicTooltip);
|
||||
lines.push(_dynamicTooltip);
|
||||
}
|
||||
|
||||
if (tooltipLines.length === 0) {
|
||||
if (!showExecTooltip && !showTextTooltip) {
|
||||
return "";
|
||||
}
|
||||
return lines;
|
||||
}
|
||||
|
||||
tooltipText: {
|
||||
var lines = _buildTooltipContent();
|
||||
|
||||
// If no custom tooltip and both switches are off, show default tooltip
|
||||
if (!_hasCustomTooltip && !showExecTooltip && !showTextTooltip) {
|
||||
return I18n.tr("bar.custom-button.default-tooltip");
|
||||
} else {
|
||||
return tooltipLines.join("\n");
|
||||
}
|
||||
|
||||
// If there's content, join with newlines
|
||||
if (lines.length > 0) {
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
// Fallback (shouldn't reach here normally)
|
||||
return I18n.tr("bar.custom-button.default-tooltip");
|
||||
}
|
||||
|
||||
onClicked: root.clicked()
|
||||
|
||||
@@ -29,6 +29,7 @@ ColumnLayout {
|
||||
property bool valueEnableColorization: widgetData.enableColorization || false
|
||||
property string valueColorizeSystemIcon: widgetData.colorizeSystemIcon !== undefined ? widgetData.colorizeSystemIcon : widgetMetadata.colorizeSystemIcon || "none"
|
||||
property string valueIpcIdentifier: widgetData.ipcIdentifier !== undefined ? widgetData.ipcIdentifier : widgetMetadata.ipcIdentifier || ""
|
||||
property string valueGeneralTooltipText: widgetData.generalTooltipText !== undefined ? widgetData.generalTooltipText : widgetMetadata.generalTooltipText || ""
|
||||
|
||||
function saveSettings() {
|
||||
var settings = Object.assign({}, widgetData || {});
|
||||
@@ -62,6 +63,7 @@ ColumnLayout {
|
||||
settings.enableColorization = valueEnableColorization;
|
||||
settings.colorizeSystemIcon = valueColorizeSystemIcon;
|
||||
settings.ipcIdentifier = valueIpcIdentifier;
|
||||
settings.generalTooltipText = valueGeneralTooltipText;
|
||||
settingsChanged(settings);
|
||||
}
|
||||
|
||||
@@ -128,6 +130,16 @@ ColumnLayout {
|
||||
}
|
||||
}
|
||||
|
||||
NTextInput {
|
||||
Layout.fillWidth: true
|
||||
label: I18n.tr("bar.custom-button.general-tooltip-text-label")
|
||||
description: I18n.tr("bar.custom-button.general-tooltip-text-description")
|
||||
placeholderText: I18n.tr("placeholders.enter-tooltip")
|
||||
text: valueGeneralTooltipText
|
||||
onTextChanged: valueGeneralTooltipText = text
|
||||
onEditingFinished: saveSettings()
|
||||
}
|
||||
|
||||
NToggle {
|
||||
id: showExecTooltipToggle
|
||||
label: I18n.tr("bar.custom-button.show-exec-tooltip-label")
|
||||
|
||||
@@ -129,6 +129,7 @@ Singleton {
|
||||
"showIcon": true,
|
||||
"showExecTooltip": true,
|
||||
"showTextTooltip": true,
|
||||
"generalTooltipText": "",
|
||||
"hideMode": "alwaysExpanded",
|
||||
"leftClickExec": "",
|
||||
"leftClickUpdateText": false,
|
||||
|
||||
Reference in New Issue
Block a user