From 6953239bc35d475a760412280fb73efe09aeccc7 Mon Sep 17 00:00:00 2001 From: miruka Date: Wed, 6 Nov 2019 17:03:34 -0400 Subject: [PATCH] Add shortcut to send file from path in clipboard --- src/python/config_files.py | 1 + src/qml/Dialogs/SendFilePicker.qml | 8 +++++++- src/qml/Shortcuts.qml | 14 ++++++++++++-- src/qml/utils.js | 5 +++++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/src/python/config_files.py b/src/python/config_files.py index ec63a396..23b0dc06 100644 --- a/src/python/config_files.py +++ b/src/python/config_files.py @@ -143,6 +143,7 @@ class UISettings(JSONConfigFile): "clearRoomMessages": ["Ctrl+L"], "sendFile": ["Alt+F"], + "sendFileFromPathInClipboard": ["Alt+Shift+F"], }, } diff --git a/src/qml/Dialogs/SendFilePicker.qml b/src/qml/Dialogs/SendFilePicker.qml index bc1fb4f0..1eef936b 100644 --- a/src/qml/Dialogs/SendFilePicker.qml +++ b/src/qml/Dialogs/SendFilePicker.qml @@ -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() }) } diff --git a/src/qml/Shortcuts.qml b/src/qml/Shortcuts.qml index 9a43b28f..da153594 100644 --- a/src/qml/Shortcuts.qml +++ b/src/qml/Shortcuts.qml @@ -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(), + ) + } } diff --git a/src/qml/utils.js b/src/qml/utils.js index 5ddbbe40..ee232e32 100644 --- a/src/qml/utils.js +++ b/src/qml/utils.js @@ -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) +}