forked from Shinonome/dots-hyprland
ai: code blocks: add save to file button
This commit is contained in:
@@ -9,4 +9,5 @@ Singleton {
|
|||||||
readonly property string state: StandardPaths.standardLocations(StandardPaths.StateLocation)[0]
|
readonly property string state: StandardPaths.standardLocations(StandardPaths.StateLocation)[0]
|
||||||
readonly property string cache: StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]
|
readonly property string cache: StandardPaths.standardLocations(StandardPaths.CacheLocation)[0]
|
||||||
readonly property string pictures: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
|
readonly property string pictures: StandardPaths.standardLocations(StandardPaths.PicturesLocation)[0]
|
||||||
|
readonly property string downloads: StandardPaths.standardLocations(StandardPaths.DownloadLocation)[0]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -198,6 +198,7 @@ Rectangle {
|
|||||||
copyButton.activated = false
|
copyButton.activated = false
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
StyledToolTip {
|
StyledToolTip {
|
||||||
content: qsTr("Copy")
|
content: qsTr("Copy")
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -6,6 +6,7 @@ import "root:/modules/common/"
|
|||||||
import "root:/modules/common/widgets"
|
import "root:/modules/common/widgets"
|
||||||
import "../"
|
import "../"
|
||||||
import "root:/modules/common/functions/string_utils.js" as StringUtils
|
import "root:/modules/common/functions/string_utils.js" as StringUtils
|
||||||
|
import "root:/modules/common/functions/file_utils.js" as FileUtils
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import QtQuick.Controls
|
import QtQuick.Controls
|
||||||
import QtQuick.Layouts
|
import QtQuick.Layouts
|
||||||
@@ -22,7 +23,7 @@ ColumnLayout {
|
|||||||
property bool renderMarkdown: parent?.renderMarkdown ?? true
|
property bool renderMarkdown: parent?.renderMarkdown ?? true
|
||||||
property bool enableMouseSelection: parent?.enableMouseSelection ?? false
|
property bool enableMouseSelection: parent?.enableMouseSelection ?? false
|
||||||
property var segmentContent: parent?.segmentContent ?? ({})
|
property var segmentContent: parent?.segmentContent ?? ({})
|
||||||
property var segmentLang: parent?.segmentLang ?? "plaintext"
|
property var segmentLang: parent?.segmentLang ?? "txt"
|
||||||
property var messageData: parent?.messageData ?? {}
|
property var messageData: parent?.messageData ?? {}
|
||||||
|
|
||||||
property real codeBlockBackgroundRounding: Appearance.rounding.small
|
property real codeBlockBackgroundRounding: Appearance.rounding.small
|
||||||
@@ -66,14 +67,51 @@ ColumnLayout {
|
|||||||
|
|
||||||
Item { Layout.fillWidth: true }
|
Item { Layout.fillWidth: true }
|
||||||
|
|
||||||
AiMessageControlButton {
|
ButtonGroup {
|
||||||
id: copyCodeButton
|
AiMessageControlButton {
|
||||||
buttonIcon: "content_copy"
|
id: copyCodeButton
|
||||||
onClicked: {
|
buttonIcon: activated ? "inventory" : "content_copy"
|
||||||
Hyprland.dispatch(`exec wl-copy '${StringUtils.shellSingleQuoteEscape(segmentContent)}'`)
|
|
||||||
|
onClicked: {
|
||||||
|
Hyprland.dispatch(`exec wl-copy '${StringUtils.shellSingleQuoteEscape(segmentContent)}'`)
|
||||||
|
copyCodeButton.activated = true
|
||||||
|
copyIconTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: copyIconTimer
|
||||||
|
interval: 1500
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
copyCodeButton.activated = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StyledToolTip {
|
||||||
|
content: qsTr("Copy code")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
StyledToolTip {
|
AiMessageControlButton {
|
||||||
content: qsTr("Copy code")
|
id: saveCodeButton
|
||||||
|
buttonIcon: activated ? "check" : "save"
|
||||||
|
|
||||||
|
onClicked: {
|
||||||
|
Hyprland.dispatch(`exec echo '${StringUtils.shellSingleQuoteEscape(segmentContent)}' > '${FileUtils.trimFileProtocol(XdgDirectories.downloads)}/code.${segmentLang || "txt"}'`)
|
||||||
|
Hyprland.dispatch(`exec notify-send 'Code saved to file' '${FileUtils.trimFileProtocol(XdgDirectories.downloads)}/code.${segmentLang || "txt"}'`)
|
||||||
|
saveCodeButton.activated = true
|
||||||
|
saveIconTimer.restart()
|
||||||
|
}
|
||||||
|
|
||||||
|
Timer {
|
||||||
|
id: saveIconTimer
|
||||||
|
interval: 1500
|
||||||
|
repeat: false
|
||||||
|
onTriggered: {
|
||||||
|
saveCodeButton.activated = false
|
||||||
|
}
|
||||||
|
}
|
||||||
|
StyledToolTip {
|
||||||
|
content: qsTr("Save to Downloads")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user