mirror of
https://github.com/zoriya/noctalia-shell.git
synced 2025-12-06 06:36:15 +00:00
Merge pull request #794 from lonerOrz/feat/custombutton
feat: Tooltip supports rich text parsing
This commit is contained in:
@@ -159,7 +159,7 @@ Item {
|
||||
const parsed = JSON.parse(lineToParse);
|
||||
const text = parsed.text || "";
|
||||
const icon = parsed.icon || "";
|
||||
const tooltip = parsed.tooltip || "";
|
||||
let tooltip = parsed.tooltip || "";
|
||||
|
||||
if (checkCollapse(text)) {
|
||||
_dynamicText = "";
|
||||
@@ -170,7 +170,8 @@ Item {
|
||||
|
||||
_dynamicText = text;
|
||||
_dynamicIcon = icon;
|
||||
_dynamicTooltip = tooltip;
|
||||
|
||||
_dynamicTooltip = toHtml(tooltip);
|
||||
return;
|
||||
} catch (e) {
|
||||
Logger.w("CustomButton", `Failed to parse JSON. Content: "${lineToParse}"`);
|
||||
@@ -186,7 +187,7 @@ Item {
|
||||
|
||||
_dynamicText = contentStr;
|
||||
_dynamicIcon = "";
|
||||
_dynamicTooltip = "";
|
||||
_dynamicTooltip = toHtml(contentStr);
|
||||
}
|
||||
|
||||
function checkCollapse(text) {
|
||||
@@ -245,6 +246,25 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
function toHtml(str) {
|
||||
const htmlRegex = /<\/?[a-zA-Z][\s\S]*>/;
|
||||
|
||||
if (htmlRegex.test(str)) {
|
||||
return str;
|
||||
}
|
||||
|
||||
const escaped = str
|
||||
.replace(/&/g, "&")
|
||||
.replace(/</g, "<")
|
||||
.replace(/>/g, ">")
|
||||
.replace(/"/g, """)
|
||||
.replace(/'/g, "'");
|
||||
|
||||
const withBreaks = escaped.replace(/\r\n|\r|\n/g, "<br/>");
|
||||
|
||||
return withBreaks;
|
||||
}
|
||||
|
||||
function runTextCommand() {
|
||||
if (!textCommand || textCommand.length === 0)
|
||||
return;
|
||||
|
||||
@@ -436,7 +436,8 @@ PopupWindow {
|
||||
horizontalAlignment: Text.AlignHCenter
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
wrapMode: Text.WordWrap
|
||||
width: root.maxWidth - (root.padding * 2)
|
||||
width: Math.min(implicitWidth, root.maxWidth - (root.padding * 2))
|
||||
richTextEnabled: true
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,6 +17,8 @@ Text {
|
||||
return fontScale;
|
||||
}
|
||||
|
||||
property bool richTextEnabled: false
|
||||
|
||||
font.family: root.family
|
||||
font.weight: Style.fontWeightMedium
|
||||
font.pointSize: root.pointSize * fontScale
|
||||
@@ -24,4 +26,6 @@ Text {
|
||||
elide: Text.ElideRight
|
||||
wrapMode: Text.NoWrap
|
||||
verticalAlignment: Text.AlignVCenter
|
||||
|
||||
textFormat: richTextEnabled ? Text.RichText : Text.PlainText
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user