Confirm clearing clipboard history
This commit is contained in:
@@ -3,6 +3,7 @@ import Quickshell.Io
|
|||||||
import Quickshell.Wayland
|
import Quickshell.Wayland
|
||||||
import QtQuick
|
import QtQuick
|
||||||
import qs.Commons
|
import qs.Commons
|
||||||
|
import qs.Ui
|
||||||
import "ClipboardHistory.js" as ClipboardHistory
|
import "ClipboardHistory.js" as ClipboardHistory
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
@@ -13,6 +14,7 @@ Item {
|
|||||||
property string filterText: ""
|
property string filterText: ""
|
||||||
property int selectedIndex: 0
|
property int selectedIndex: 0
|
||||||
property bool cursorActive: false
|
property bool cursorActive: false
|
||||||
|
property bool clearConfirmOpen: false
|
||||||
property var history: []
|
property var history: []
|
||||||
|
|
||||||
property string historyPath: Quickshell.env("HOME") + "/.local/state/omarchy/clipboard-history.json"
|
property string historyPath: Quickshell.env("HOME") + "/.local/state/omarchy/clipboard-history.json"
|
||||||
@@ -46,6 +48,7 @@ Item {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function close() {
|
function close() {
|
||||||
|
root.cancelClearHistory()
|
||||||
root.opened = false
|
root.opened = false
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,6 +87,27 @@ Item {
|
|||||||
root.addClipboardEntry(ClipboardHistory.parseEntryJson(line))
|
root.addClipboardEntry(ClipboardHistory.parseEntryJson(line))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function requestClearHistory() {
|
||||||
|
if (root.history.length === 0) return
|
||||||
|
clearConfirm.selectedIndex = 1
|
||||||
|
root.clearConfirmOpen = true
|
||||||
|
}
|
||||||
|
|
||||||
|
function cancelClearHistory() {
|
||||||
|
root.clearConfirmOpen = false
|
||||||
|
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
|
||||||
|
}
|
||||||
|
|
||||||
|
function confirmClearHistory() {
|
||||||
|
root.history = ClipboardHistory.clearHistory()
|
||||||
|
root.saveHistory()
|
||||||
|
root.selectedIndex = 0
|
||||||
|
root.cursorActive = false
|
||||||
|
root.clearConfirmOpen = false
|
||||||
|
root.rebuildDisplay()
|
||||||
|
Qt.callLater(function() { keyCatcher.forceActiveFocus() })
|
||||||
|
}
|
||||||
|
|
||||||
function removeDisplayIndex(index) {
|
function removeDisplayIndex(index) {
|
||||||
if (index < 0 || index >= displayModel.count) return
|
if (index < 0 || index >= displayModel.count) return
|
||||||
|
|
||||||
@@ -237,10 +261,16 @@ Item {
|
|||||||
Item {
|
Item {
|
||||||
id: keyCatcher
|
id: keyCatcher
|
||||||
anchors.fill: parent
|
anchors.fill: parent
|
||||||
|
z: root.clearConfirmOpen ? 20 : 0
|
||||||
focus: true
|
focus: true
|
||||||
|
|
||||||
Keys.priority: Keys.BeforeItem
|
Keys.priority: Keys.BeforeItem
|
||||||
Keys.onPressed: function(event) {
|
Keys.onPressed: function(event) {
|
||||||
|
if (root.clearConfirmOpen) {
|
||||||
|
if (clearConfirm.handleKey(event)) event.accepted = true
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if (event.key === Qt.Key_Escape) {
|
if (event.key === Qt.Key_Escape) {
|
||||||
if (root.filterText) root.setFilter("")
|
if (root.filterText) root.setFilter("")
|
||||||
else root.close()
|
else root.close()
|
||||||
@@ -249,7 +279,8 @@ Item {
|
|||||||
if (root.filterText.length > 0) root.setFilter(root.filterText.slice(0, -1))
|
if (root.filterText.length > 0) root.setFilter(root.filterText.slice(0, -1))
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_Delete) {
|
} else if (event.key === Qt.Key_Delete) {
|
||||||
root.removeDisplayIndex(root.selectedIndex)
|
if (event.modifiers & Qt.ShiftModifier) root.requestClearHistory()
|
||||||
|
else root.removeDisplayIndex(root.selectedIndex)
|
||||||
event.accepted = true
|
event.accepted = true
|
||||||
} else if (event.key === Qt.Key_Up) {
|
} else if (event.key === Qt.Key_Up) {
|
||||||
root.select(-1)
|
root.select(-1)
|
||||||
@@ -272,6 +303,25 @@ Item {
|
|||||||
event.accepted = true
|
event.accepted = true
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
ConfirmDialog {
|
||||||
|
id: clearConfirm
|
||||||
|
|
||||||
|
anchors.fill: parent
|
||||||
|
opened: root.clearConfirmOpen
|
||||||
|
z: 10
|
||||||
|
message: "Delete entire clipboard history?"
|
||||||
|
confirmText: "Delete"
|
||||||
|
background: root.background
|
||||||
|
foreground: root.foreground
|
||||||
|
scrim: root.scrim
|
||||||
|
selectedBackground: root.selectedBackground
|
||||||
|
selectedText: root.selectedText
|
||||||
|
fontFamily: root.fontFamily
|
||||||
|
cornerRadius: root.cornerRadius
|
||||||
|
onCanceled: root.cancelClearHistory()
|
||||||
|
onConfirmed: root.confirmClearHistory()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
Column {
|
Column {
|
||||||
|
|||||||
@@ -76,6 +76,10 @@ function removeEntryAt(history, index) {
|
|||||||
return next
|
return next
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function clearHistory() {
|
||||||
|
return []
|
||||||
|
}
|
||||||
|
|
||||||
function parseEntryJson(line) {
|
function parseEntryJson(line) {
|
||||||
var raw = String(line || "").trim()
|
var raw = String(line || "").trim()
|
||||||
if (!raw) return null
|
if (!raw) return null
|
||||||
@@ -132,6 +136,7 @@ if (typeof module !== "undefined") {
|
|||||||
parseHistory: parseHistory,
|
parseHistory: parseHistory,
|
||||||
addEntry: addEntry,
|
addEntry: addEntry,
|
||||||
removeEntryAt: removeEntryAt,
|
removeEntryAt: removeEntryAt,
|
||||||
|
clearHistory: clearHistory,
|
||||||
parseEntryJson: parseEntryJson,
|
parseEntryJson: parseEntryJson,
|
||||||
searchableText: searchableText,
|
searchableText: searchableText,
|
||||||
previewText: previewText,
|
previewText: previewText,
|
||||||
|
|||||||
@@ -57,6 +57,7 @@ assertDeepEqual(
|
|||||||
)
|
)
|
||||||
|
|
||||||
assertDeepEqual(clipboard.removeEntryAt(history, 10), history, 'clipboard removeEntryAt ignores invalid indexes')
|
assertDeepEqual(clipboard.removeEntryAt(history, 10), history, 'clipboard removeEntryAt ignores invalid indexes')
|
||||||
|
assertDeepEqual(clipboard.clearHistory(), [], 'clipboard clearHistory returns an empty history')
|
||||||
|
|
||||||
assertDeepEqual(
|
assertDeepEqual(
|
||||||
clipboard.displayRows(history, 'image', 50).map(row => ({ type: row.entryType, preview: row.previewText, mime: row.mime })),
|
clipboard.displayRows(history, 'image', 50).map(row => ({ type: row.entryType, preview: row.previewText, mime: row.mime })),
|
||||||
|
|||||||
Reference in New Issue
Block a user