mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-01-27 23:12:49 -05:00
clipboard: fix duplicate clear dialog
This commit is contained in:
@@ -30,7 +30,9 @@ Item {
|
||||
onKeyboardHintsToggled: modal.showKeyboardHints = !modal.showKeyboardHints
|
||||
onTabChanged: tabName => modal.activeTab = tabName
|
||||
onClearAllClicked: {
|
||||
clearConfirmDialog.show(I18n.tr("Clear All History?"), I18n.tr("This will permanently delete all clipboard history."), function () {
|
||||
const hasPinned = modal.pinnedCount > 0;
|
||||
const message = hasPinned ? I18n.tr("This will delete all unpinned entries. %1 pinned entries will be kept.").arg(modal.pinnedCount) : I18n.tr("This will permanently delete all clipboard history.");
|
||||
clearConfirmDialog.show(I18n.tr("Clear History?"), message, function () {
|
||||
modal.clearAll();
|
||||
modal.hide();
|
||||
}, function () {});
|
||||
|
||||
@@ -239,20 +239,16 @@ DankModal {
|
||||
|
||||
function clearAll() {
|
||||
const hasPinned = pinnedCount > 0;
|
||||
const message = hasPinned ? I18n.tr("This will delete all unpinned entries. %1 pinned entries will be kept.").arg(pinnedCount) : I18n.tr("This will permanently delete all clipboard history.");
|
||||
|
||||
clearConfirmDialog.show(I18n.tr("Clear History?"), message, function () {
|
||||
DMSService.sendRequest("clipboard.clearHistory", null, function (response) {
|
||||
if (response.error) {
|
||||
console.warn("ClipboardHistoryModal: Failed to clear history:", response.error);
|
||||
return;
|
||||
}
|
||||
refreshClipboard();
|
||||
if (hasPinned) {
|
||||
ToastService.showInfo(I18n.tr("History cleared. %1 pinned entries kept.").arg(pinnedCount));
|
||||
}
|
||||
});
|
||||
}, function () {});
|
||||
DMSService.sendRequest("clipboard.clearHistory", null, function (response) {
|
||||
if (response.error) {
|
||||
console.warn("ClipboardHistoryModal: Failed to clear history:", response.error);
|
||||
return;
|
||||
}
|
||||
refreshClipboard();
|
||||
if (hasPinned) {
|
||||
ToastService.showInfo(I18n.tr("History cleared. %1 pinned entries kept.").arg(pinnedCount));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
function getEntryPreview(entry) {
|
||||
@@ -295,13 +291,18 @@ DankModal {
|
||||
onVisibleChanged: {
|
||||
if (visible) {
|
||||
clipboardHistoryModal.shouldHaveFocus = false;
|
||||
} else if (clipboardHistoryModal.shouldBeVisible) {
|
||||
return;
|
||||
}
|
||||
Qt.callLater(function () {
|
||||
if (!clipboardHistoryModal.shouldBeVisible) {
|
||||
return;
|
||||
}
|
||||
clipboardHistoryModal.shouldHaveFocus = true;
|
||||
clipboardHistoryModal.modalFocusScope.forceActiveFocus();
|
||||
if (clipboardHistoryModal.contentLoader.item?.searchField) {
|
||||
clipboardHistoryModal.contentLoader.item.searchField.forceActiveFocus();
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -93,31 +93,41 @@ Item {
|
||||
}
|
||||
}
|
||||
|
||||
Timer {
|
||||
id: visibilityTimer
|
||||
interval: 100
|
||||
onTriggered: thumbnailImage.checkVisibility()
|
||||
}
|
||||
|
||||
function checkVisibility() {
|
||||
if (entryType !== "image" || listView.height <= 0 || isVisible) {
|
||||
return;
|
||||
}
|
||||
const itemY = itemIndex * (ClipboardConstants.itemHeight + listView.spacing);
|
||||
const viewTop = listView.contentY - ClipboardConstants.viewportBuffer;
|
||||
const viewBottom = viewTop + listView.height + ClipboardConstants.extendedBuffer;
|
||||
const nowVisible = (itemY + ClipboardConstants.itemHeight >= viewTop && itemY <= viewBottom);
|
||||
if (nowVisible) {
|
||||
isVisible = true;
|
||||
tryLoadImage();
|
||||
}
|
||||
}
|
||||
|
||||
Connections {
|
||||
target: listView
|
||||
|
||||
function checkVisibility() {
|
||||
if (entryType !== "image" || listView.height <= 0) {
|
||||
function onContentYChanged() {
|
||||
if (thumbnailImage.isVisible || entryType !== "image") {
|
||||
return;
|
||||
}
|
||||
|
||||
const itemY = itemIndex * (ClipboardConstants.itemHeight + listView.spacing);
|
||||
const viewTop = listView.contentY - ClipboardConstants.viewportBuffer;
|
||||
const viewBottom = viewTop + listView.height + ClipboardConstants.extendedBuffer;
|
||||
const nowVisible = (itemY + ClipboardConstants.itemHeight >= viewTop && itemY <= viewBottom);
|
||||
|
||||
if (nowVisible && !thumbnailImage.isVisible) {
|
||||
thumbnailImage.isVisible = true;
|
||||
thumbnailImage.tryLoadImage();
|
||||
}
|
||||
}
|
||||
|
||||
function onContentYChanged() {
|
||||
checkVisibility();
|
||||
visibilityTimer.restart();
|
||||
}
|
||||
|
||||
function onHeightChanged() {
|
||||
checkVisibility();
|
||||
if (thumbnailImage.isVisible || entryType !== "image") {
|
||||
return;
|
||||
}
|
||||
visibilityTimer.restart();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user