From b1226db758ddef092db6eb036abc6513cc06c26f Mon Sep 17 00:00:00 2001 From: George Hazan Date: Mon, 1 Jun 2020 17:01:42 +0300 Subject: fixes #2412 (Add ability to paste file URL instead of file sending initiation) --- src/mir_app/src/srmm_base.cpp | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) (limited to 'src') diff --git a/src/mir_app/src/srmm_base.cpp b/src/mir_app/src/srmm_base.cpp index 78e14711eb..2faeba337a 100644 --- a/src/mir_app/src/srmm_base.cpp +++ b/src/mir_app/src/srmm_base.cpp @@ -737,11 +737,49 @@ int CSrmmBaseDialog::NotifyEvent(int code) bool CSrmmBaseDialog::ProcessFileDrop(HDROP hDrop, MCONTACT hContact) { + if (PasteFilesAsURL(hDrop)) + return true; + return ::ProcessFileDrop(hDrop, hContact); } ///////////////////////////////////////////////////////////////////////////////////////// +/** +If enabled pastes droped files as list of URL of file:/// type + Can be enabled/disabled by Chat/ShiftDropFilePasteURL database parameter +@param hDrop Drop handle +@param hContact Contact handle +@return Returns true if processed here, returns false if should be processed elsewhere +*/ +bool CSrmmBaseDialog::PasteFilesAsURL(HDROP hDrop) +{ + bool isShift = (GetKeyState(VK_SHIFT) & 0x8000) != 0; + if (db_get_b(0, CHAT_MODULE, "ShiftDropFilePasteURL", 1) == 0 || !isShift) + return false; + + int fileCount = DragQueryFileW(hDrop, -1, nullptr, 0); + CMStringW pasteString; + for (int i = 0; i < fileCount; i++) { + wchar_t szFilename[MAX_PATH]; + if (DragQueryFileW(hDrop, i, szFilename, _countof(szFilename))) { + CMStringW fileString(L"file:///"); + fileString.Append(_A2T(mir_urlEncode(T2Utf(szFilename)))); + if (i == 0) + fileString.Insert(0, L" "); + fileString.Append((i != fileCount - 1) ? L"\r\n" : L" "); + pasteString += fileString; + } + } + + if (pasteString.GetLength()) + m_message.SendMsg(EM_REPLACESEL, TRUE, (LPARAM)pasteString.c_str()); + + return true; +} + +///////////////////////////////////////////////////////////////////////////////////////// + bool CSrmmBaseDialog::ProcessHotkeys(int key, bool isShift, bool isCtrl, bool isAlt) { // Esc (close tab) -- cgit v1.2.3