From 66f73a5a64efa0ddd4d5377345334f452deb7c65 Mon Sep 17 00:00:00 2001 From: John Preston Date: Fri, 20 Oct 2023 18:00:28 +0400 Subject: [PATCH] Copy code blocks on header click. --- Telegram/Resources/icons/chat/mini_copy.png | Bin 0 -> 324 bytes Telegram/Resources/icons/chat/mini_copy@2x.png | Bin 0 -> 484 bytes Telegram/Resources/icons/chat/mini_copy@3x.png | Bin 0 -> 623 bytes Telegram/Resources/langs/lang.strings | 1 + Telegram/SourceFiles/core/ui_integration.cpp | 10 ++++++++++ Telegram/SourceFiles/core/ui_integration.h | 1 + Telegram/SourceFiles/ui/chat/chat.style | 2 ++ Telegram/SourceFiles/ui/chat/chat_style.cpp | 2 ++ Telegram/ThirdParty/libprisma | 2 +- Telegram/lib_spellcheck | 2 +- Telegram/lib_ui | 2 +- 11 files changed, 19 insertions(+), 3 deletions(-) create mode 100644 Telegram/Resources/icons/chat/mini_copy.png create mode 100644 Telegram/Resources/icons/chat/mini_copy@2x.png create mode 100644 Telegram/Resources/icons/chat/mini_copy@3x.png diff --git a/Telegram/Resources/icons/chat/mini_copy.png b/Telegram/Resources/icons/chat/mini_copy.png new file mode 100644 index 0000000000000000000000000000000000000000..05af01e49ab50834e564d8796b47da01317c1dd8 GIT binary patch literal 324 zcmeAS@N?(olHy`uVBq!ia0vp^0wB!61SBU+%rFB|jKx9jP7LeL$-D$|Tv8)E(|mmy zw18|52FCVG1{RPKAeI7R1_tH@j10^`nh_+nfC(-uuz(rC1}QWNE&K$e)_J-(hG>W; zCoC{caM|n-5D?()-92@xsK&ovUtg~dU%yDx;h~y}O3nX&f9-kpRDJE5D0tVUg>Au2 zhpWPBJ_4emPZ^mzY&k?Tbh5Lv7hH6>8ofQQ^(Nz@`hS0J-n!MbOyWpsK>>pobFW(% zZzA*81EvNCBP%3wa&ihH7nvLgWtJ4lV6YOusd6aC&TikOOF;{)eEfwCxFyswsyJGL p{Qb|bkKg~mk7-k*Qi0xENrr$&jVD_k44ofy`glX(f`xTHpSruq6Z zXaU(A42G$TlC0TWzSVF5FO4N|zKE$K5*nV+YNV~7Xu z+t7`Dt_~u#B8!$x(fGqWHDgNMq2(P;53R36P4%CU5x;VRz|=6MJ$sF2pG=7n-h4CH zOho^=-1m9L#cJpG#GU{AUO3>0^_9}QpKY#}`d&`4-k!U9)vDa+X;Y3RN|eQZ-&ygj z@|uZn)D*skU;EyRKVpx)Zkj8`V58*m>~EcQ-{y7M(^69-4^>5qeweqcGxbS<087eS z&q*hI=k2;GTr5zqs-=A^bH}0;@2eeS4jVkF)GJiUoF!y=deZ@iHGaJZn{~SX9xXpm z#;`4ScJc+IzQ@M(rytm~8KvyLv--ZtgC(9nB^GSl@I+W}He1)njtA#GcWFAb*Zck2 zw_nHmvdNXUI{qULhb|fLg#NuZKVnL4wb_C9%zVg%4O0`+UYn_r;W4EzL#cdn z!Ayb3vc#L+(@zJT-S@Le6#2PNe_QRoTj_FDj$+-cI&!<#9X8^MU!))R(EXc~OHO2QnX9$Mm!$q4 zj~Cw^{G9raH_sNfoj&=()1rrJF6W=BJh9+2UudLKe(ny6?jwzUj)jrCUIe?dj_0vd$@?2>=N+_`3iA literal 0 HcmV?d00001 diff --git a/Telegram/Resources/langs/lang.strings b/Telegram/Resources/langs/lang.strings index 98e41d30e..503f0a020 100644 --- a/Telegram/Resources/langs/lang.strings +++ b/Telegram/Resources/langs/lang.strings @@ -2686,6 +2686,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL "lng_formatting_link_create" = "Create"; "lng_text_copied" = "Text copied to clipboard."; +"lng_code_copied" = "Code copied to clipboard."; "lng_spellchecker_submenu" = "Spelling"; "lng_spellchecker_add" = "Add to Dictionary"; diff --git a/Telegram/SourceFiles/core/ui_integration.cpp b/Telegram/SourceFiles/core/ui_integration.cpp index 8f1be8324..1fe33e654 100644 --- a/Telegram/SourceFiles/core/ui_integration.cpp +++ b/Telegram/SourceFiles/core/ui_integration.cpp @@ -243,6 +243,16 @@ bool UiIntegration::handleUrlClick( return true; } +bool UiIntegration::copyPreOnClick(const QVariant &context) { + const auto my = context.value(); + if (const auto window = my.sessionWindow.get()) { + window->showToast(tr::lng_code_copied(tr::now)); + } else if (my.show) { + my.show->showToast(tr::lng_code_copied(tr::now)); + } + return true; +} + std::unique_ptr UiIntegration::createCustomEmoji( const QString &data, const std::any &context) { diff --git a/Telegram/SourceFiles/core/ui_integration.h b/Telegram/SourceFiles/core/ui_integration.h index cd3e4ff58..0515c732f 100644 --- a/Telegram/SourceFiles/core/ui_integration.h +++ b/Telegram/SourceFiles/core/ui_integration.h @@ -53,6 +53,7 @@ public: bool handleUrlClick( const QString &url, const QVariant &context) override; + bool copyPreOnClick(const QVariant &context) override; rpl::producer<> forcePopupMenuHideRequests() override; const Ui::Emoji::One *defaultEmojiVariant( const Ui::Emoji::One *emoji) override; diff --git a/Telegram/SourceFiles/ui/chat/chat.style b/Telegram/SourceFiles/ui/chat/chat.style index 5c126895d..f13781bfe 100644 --- a/Telegram/SourceFiles/ui/chat/chat.style +++ b/Telegram/SourceFiles/ui/chat/chat.style @@ -56,6 +56,8 @@ messageTextStyle: TextStyle(defaultTextStyle) { header: 20px; headerPosition: point(10px, 2px); scrollable: true; + icon: icon{{ "chat/mini_copy", windowFg }}; + iconPosition: point(4px, 2px); } } msgDateTextStyle: defaultTextStyle; diff --git a/Telegram/SourceFiles/ui/chat/chat_style.cpp b/Telegram/SourceFiles/ui/chat/chat_style.cpp index a2604b247..b1e22f808 100644 --- a/Telegram/SourceFiles/ui/chat/chat_style.cpp +++ b/Telegram/SourceFiles/ui/chat/chat_style.cpp @@ -60,6 +60,8 @@ void EnsurePreCache( cache->outline.setAlphaF(0.9); cache->header = color->c; cache->header.setAlphaF(0.25); + cache->icon = cache->outline; + cache->icon.setAlphaF(0.6); } } // namespace diff --git a/Telegram/ThirdParty/libprisma b/Telegram/ThirdParty/libprisma index 7f62494bb..629dc69fb 160000 --- a/Telegram/ThirdParty/libprisma +++ b/Telegram/ThirdParty/libprisma @@ -1 +1 @@ -Subproject commit 7f62494bb8cb6478a7cb6053ad7b5668fa013366 +Subproject commit 629dc69fbffa5d63954c8e8909a26efdd98573b0 diff --git a/Telegram/lib_spellcheck b/Telegram/lib_spellcheck index 5227bec65..c97b3fe73 160000 --- a/Telegram/lib_spellcheck +++ b/Telegram/lib_spellcheck @@ -1 +1 @@ -Subproject commit 5227bec65b6cb8c2b3172747ecb5f3468580de10 +Subproject commit c97b3fe73ddfbc80c9ecacfbf2cda824e5b05ff5 diff --git a/Telegram/lib_ui b/Telegram/lib_ui index 9eb9fcf04..17d73a5c0 160000 --- a/Telegram/lib_ui +++ b/Telegram/lib_ui @@ -1 +1 @@ -Subproject commit 9eb9fcf043276bb3a73f1fc25531e4f4862d6fc9 +Subproject commit 17d73a5c0cb7350a2330b85347a919ad639ad1cf