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"], "clearRoomMessages": ["Ctrl+L"],
"sendFile": ["Alt+F"], "sendFile": ["Alt+F"],
"sendFileFromPathInClipboard": ["Alt+Shift+F"],
}, },
} }

View File

@ -1,4 +1,5 @@
import QtQuick 2.12 import QtQuick 2.12
import "../utils.js" as Utils
HFileDialogOpener { HFileDialogOpener {
fill: false fill: false
@ -6,7 +7,12 @@ HFileDialogOpener {
onFilePicked: { onFilePicked: {
let path = Qt.resolvedUrl(file).replace(/^file:/, "") 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() if (destroyWhenDone) destroy()
}) })
} }

View File

@ -147,4 +147,14 @@ HShortcutHandler {
picker => { picker.dialog.open() } 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(".") return url.toString().split("/").slice(-1)[0].split("?")[0].split(".")
.slice(-1)[0].toLowerCase() .slice(-1)[0].toLowerCase()
} }
function sendFile(userId, roomId, path, onSuccess, onError) {
py.callClientCoro(userId, "send_file", [roomId, path], onSuccess, onError)
}