mirror of
https://github.com/AvengeMedia/DankMaterialShell.git
synced 2026-06-15 15:45:20 -04:00
0f2f4b96c4
* fix(clipboard): improve confirmation dialog keyboard focus * fix(clipboard): require confirmation for clear-all shortcut
119 lines
3.6 KiB
QML
119 lines
3.6 KiB
QML
pragma ComponentBehavior: Bound
|
|
|
|
import QtQuick
|
|
import qs.Common
|
|
import qs.Modals.Clipboard
|
|
import qs.Modals.Common
|
|
import qs.Services
|
|
|
|
DankModal {
|
|
id: clipboardHistoryModal
|
|
|
|
layerNamespace: "dms:clipboard"
|
|
|
|
function toggle() {
|
|
if (shouldBeVisible) {
|
|
hide();
|
|
return;
|
|
}
|
|
show();
|
|
}
|
|
|
|
function show() {
|
|
open();
|
|
shouldHaveFocus = true;
|
|
|
|
Qt.callLater(function () {
|
|
if (contentLoader.item) {
|
|
contentLoader.item.resetState();
|
|
}
|
|
if (clipboardHistoryModal.clipboardAvailable) {
|
|
if (Theme.isConnectedEffect) {
|
|
Qt.callLater(() => {
|
|
if (clipboardHistoryModal.shouldBeVisible) {
|
|
ClipboardService.refresh();
|
|
}
|
|
});
|
|
} else {
|
|
ClipboardService.refresh();
|
|
}
|
|
}
|
|
if (contentLoader.item?.searchField) {
|
|
contentLoader.item.searchField.text = "";
|
|
contentLoader.item.searchField.forceActiveFocus();
|
|
}
|
|
});
|
|
}
|
|
|
|
function hide() {
|
|
close();
|
|
}
|
|
|
|
onDialogClosed: {
|
|
if (contentLoader.item) {
|
|
contentLoader.item.resetState();
|
|
}
|
|
}
|
|
|
|
readonly property bool clipboardAvailable: ClipboardService.clipboardAvailable
|
|
|
|
visible: false
|
|
keepContentLoaded: true
|
|
modalWidth: ClipboardConstants.modalWidth
|
|
modalHeight: ClipboardConstants.modalHeight
|
|
backgroundColor: Theme.withAlpha(Theme.surfaceContainer, Theme.popupTransparency)
|
|
cornerRadius: Theme.cornerRadius
|
|
borderColor: Theme.outlineMedium
|
|
borderWidth: 1
|
|
enableShadow: true
|
|
closeOnEscapeKey: (contentLoader.item?.mode ?? "history") !== "editor"
|
|
onBackgroundClicked: hide()
|
|
|
|
Ref {
|
|
service: ClipboardService
|
|
}
|
|
|
|
ConfirmModal {
|
|
id: clearConfirmDialog
|
|
confirmButtonText: I18n.tr("Clear All")
|
|
confirmButtonColor: Theme.primary
|
|
onShouldBeVisibleChanged: {
|
|
if (shouldBeVisible) {
|
|
clipboardHistoryModal.shouldHaveFocus = false;
|
|
selectedButton = 0;
|
|
keyboardNavigation = true;
|
|
return;
|
|
}
|
|
Qt.callLater(function () {
|
|
if (!clipboardHistoryModal.shouldBeVisible) {
|
|
return;
|
|
}
|
|
clipboardHistoryModal.shouldHaveFocus = Qt.binding(() => clipboardHistoryModal.shouldBeVisible);
|
|
clipboardHistoryModal.modalFocusScope.forceActiveFocus();
|
|
if (clipboardHistoryModal.contentLoader.item?.searchField) {
|
|
clipboardHistoryModal.contentLoader.item.searchField.forceActiveFocus();
|
|
}
|
|
});
|
|
}
|
|
Connections {
|
|
target: clearConfirmDialog.modalFocusScope.Keys
|
|
function onPressed(event) {
|
|
if (!clearConfirmDialog.shouldBeVisible || event.key !== Qt.Key_Backtab) {
|
|
return;
|
|
}
|
|
clearConfirmDialog.selectedButton = clearConfirmDialog.selectedButton === -1 ? 1 : (clearConfirmDialog.selectedButton - 1 + 2) % 2;
|
|
clearConfirmDialog.keyboardNavigation = true;
|
|
event.accepted = true;
|
|
}
|
|
}
|
|
}
|
|
|
|
content: Component {
|
|
ClipboardHistoryContent {
|
|
clearConfirmDialog: clearConfirmDialog
|
|
onCloseRequested: clipboardHistoryModal.hide()
|
|
onInstantCloseRequested: clipboardHistoryModal.instantClose()
|
|
}
|
|
}
|
|
}
|