Add shortcut to send file from path in clipboard

This commit is contained in:
miruka 2019-11-06 17:03:34 -04:00
parent 25a86bc484
commit 6953239bc3
4 changed files with 25 additions and 3 deletions

View File

@ -143,6 +143,7 @@ class UISettings(JSONConfigFile):
"clearRoomMessages": ["Ctrl+L"],
"sendFile": ["Alt+F"],
"sendFileFromPathInClipboard": ["Alt+Shift+F"],
},
}

View File

@ -1,4 +1,5 @@
import QtQuick 2.12
import "../utils.js" as Utils
HFileDialogOpener {
fill: false
@ -6,7 +7,12 @@ HFileDialogOpener {
onFilePicked: {
let path = Qt.resolvedUrl(file).replace(/^file:/, "")
py.callClientCoro(userId, "send_file", [roomId, path], () => {
Utils.sendFile(userId, roomId, path, () => {
if (destroyWhenDone) destroy()
},
(type, args, error, traceback) => {
console.error("python:\n" + traceback)
if (destroyWhenDone) destroy()
})
}

View File

@ -140,11 +140,21 @@ HShortcutHandler {
"Dialogs/SendFilePicker.qml",
mainUI,
{
userId: window.uiState.pageProperties.userId,
roomId: window.uiState.pageProperties.roomId,
userId: window.uiState.pageProperties.userId,
roomId: window.uiState.pageProperties.roomId,
destroyWhenDone: true,
},
picker => { picker.dialog.open() }
)
}
HShortcut {
enabled: window.uiState.page == "Chat/Chat.qml"
sequences: settings.keys.sendFileFromPathInClipboard
onPressed: Utils.sendFile(
window.uiState.pageProperties.userId,
window.uiState.pageProperties.roomId,
Clipboard.text.trim(),
)
}
}

View File

@ -267,3 +267,8 @@ function urlExtension(url) {
return url.toString().split("/").slice(-1)[0].split("?")[0].split(".")
.slice(-1)[0].toLowerCase()
}
function sendFile(userId, roomId, path, onSuccess, onError) {
py.callClientCoro(userId, "send_file", [roomId, path], onSuccess, onError)
}