diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 04dab8e1e..601366ee4 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2752,6 +2752,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_context_copy_email" = "Copy Email Address"; "lng_context_copy_hashtag" = "Copy Hashtag"; "lng_context_copy_mention" = "Copy Username"; +"lng_context_copy_filename" = "Copy Filename"; "lng_context_save_image" = "Save Image As..."; "lng_context_copy_image" = "Copy Image"; "lng_context_cancel_download" = "Cancel Download"; diff --git a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp index d652d0f4c..b7bb4b9e0 100644 --- a/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp +++ b/Telegram/SourceFiles/history/admin_log/history_admin_log_inner.cpp @@ -15,6 +15,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "history/history_item_text.h" #include "history/admin_log/history_admin_log_section.h" #include "history/admin_log/history_admin_log_filter.h" +#include "history/view/history_view_context_menu.h" #include "history/view/history_view_message.h" #include "history/view/history_view_service_message.h" #include "history/view/history_view_cursor_state.h" @@ -1251,6 +1252,12 @@ void InnerWidget::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), base::fn_delayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [this, lnkDocument] { saveDocumentToFile(lnkDocument); }), &st::menuIconDownload); + + HistoryView::AddCopyFilename( + _menu, + lnkDocument, + [] { return false; }); + if (lnkDocument->hasAttachedStickers()) { const auto controller = _controller; auto callback = [=] { diff --git a/Telegram/SourceFiles/history/history_inner_widget.cpp b/Telegram/SourceFiles/history/history_inner_widget.cpp index 8d008113b..b7955f4ba 100644 --- a/Telegram/SourceFiles/history/history_inner_widget.cpp +++ b/Telegram/SourceFiles/history/history_inner_widget.cpp @@ -2223,6 +2223,11 @@ void HistoryInner::showContextMenu(QContextMenuEvent *e, bool showFromTouch) { _menu->addAction(lnkIsVideo ? tr::lng_context_save_video(tr::now) : (lnkIsVoice ? tr::lng_context_save_audio(tr::now) : (lnkIsAudio ? tr::lng_context_save_audio_file(tr::now) : tr::lng_context_save_file(tr::now))), base::fn_delayed(st::defaultDropdownMenu.menu.ripple.hideDuration, this, [=] { saveDocumentToFile(itemId, document); }), &st::menuIconDownload); + + HistoryView::AddCopyFilename( + _menu, + document, + [=] { return showCopyRestrictionForSelected(); }); } if (document->hasAttachedStickers()) { _menu->addAction(tr::lng_context_attached_stickers(tr::now), [=] { diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp index 9183ab81b..9267aeb5c 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.cpp +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.cpp @@ -34,6 +34,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "ui/widgets/menu/menu_multiline_action.h" #include "ui/image/image.h" #include "ui/toast/toast.h" +#include "ui/text/format_song_document_name.h" #include "ui/text/text_utilities.h" #include "ui/controls/delete_message_context_action.h" #include "ui/controls/who_reacted_context_action.h" @@ -326,6 +327,10 @@ void AddDocumentActions( AddSaveSoundForNotifications(menu, item, document, controller); } AddSaveDocumentAction(menu, item, document, list); + AddCopyFilename( + menu, + document, + [=] { return list->showCopyRestrictionForSelected(); }); } void AddPostLinkAction( @@ -1555,6 +1560,33 @@ void ShowTagInListMenu( (*menu)->popup(position); } +void AddCopyFilename( + not_null menu, + not_null document, + Fn showCopyRestrictionForSelected) { + const auto filenameToCopy = [&] { + if (document->isAudioFile()) { + return TextForMimeData().append( + Ui::Text::FormatSongNameFor(document).string()); + } else if (document->sticker() + || document->isAnimation() + || document->isVideoMessage() + || document->isVideoFile() + || document->isVoiceMessage()) { + return TextForMimeData(); + } else { + return TextForMimeData().append(document->filename()); + } + }(); + if (!filenameToCopy.empty()) { + menu->addAction(tr::lng_context_copy_filename(tr::now), [=] { + if (!showCopyRestrictionForSelected()) { + TextUtilities::SetClipboardText(filenameToCopy); + } + }, &st::menuIconCopy); + } +} + void ShowWhoReactedMenu( not_null*> menu, QPoint position, diff --git a/Telegram/SourceFiles/history/view/history_view_context_menu.h b/Telegram/SourceFiles/history/view/history_view_context_menu.h index 65afd007b..8f00f4da8 100644 --- a/Telegram/SourceFiles/history/view/history_view_context_menu.h +++ b/Telegram/SourceFiles/history/view/history_view_context_menu.h @@ -94,6 +94,10 @@ void ShowTagInListMenu( not_null context, const Data::ReactionId &id, not_null controller); +void AddCopyFilename( + not_null menu, + not_null document, + Fn showCopyRestrictionForSelected); enum class EmojiPacksSource { Message,