From c7526ae1cd5f8a7682e1a5bb93da22214b632480 Mon Sep 17 00:00:00 2001 From: 23rd <23rd@vivaldi.net> Date: Thu, 20 Jun 2019 20:31:50 +0300 Subject: [PATCH] Fixed title of recently used emoji in touchbar. - Added "No found" title if sticker list is empty. --- .../chat_helpers/emoji_list_widget.cpp | 18 +--------------- .../SourceFiles/platform/mac/mac_touchbar.mm | 21 +++++++++++++------ Telegram/SourceFiles/ui/emoji_config.cpp | 13 ++++++++++++ Telegram/SourceFiles/ui/emoji_config.h | 3 +++ 4 files changed, 32 insertions(+), 23 deletions(-) diff --git a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp index 879833305..fb2cf425c 100644 --- a/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp +++ b/Telegram/SourceFiles/chat_helpers/emoji_list_widget.cpp @@ -18,22 +18,6 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "styles/style_chat_helpers.h" namespace ChatHelpers { -namespace { - -tr::phrase<> CategoryTitle(int index) { - switch (index) { - case 1: return tr::lng_emoji_category1; - case 2: return tr::lng_emoji_category2; - case 3: return tr::lng_emoji_category3; - case 4: return tr::lng_emoji_category4; - case 5: return tr::lng_emoji_category5; - case 6: return tr::lng_emoji_category6; - case 7: return tr::lng_emoji_category7; - } - Unexpected("Index in CategoryTitle."); -} - -} // namespace class EmojiColorPicker : public Ui::RpWidget { public: @@ -545,7 +529,7 @@ void EmojiListWidget::paintEvent(QPaintEvent *e) { if (info.section > 0 && r.top() < info.rowsTop) { p.setFont(st::emojiPanHeaderFont); p.setPen(st::emojiPanHeaderFg); - p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), CategoryTitle(info.section)(tr::now)); + p.drawTextLeft(st::emojiPanHeaderLeft - st::buttonRadius, info.top + st::emojiPanHeaderTop, width(), Ui::Emoji::CategoryTitle(info.section)(tr::now)); } if (r.top() + r.height() > info.rowsTop) { ensureLoaded(info.section); diff --git a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm index 1179bc145..eef8dd280 100644 --- a/Telegram/SourceFiles/platform/mac/mac_touchbar.mm +++ b/Telegram/SourceFiles/platform/mac/mac_touchbar.mm @@ -172,6 +172,15 @@ inline int UnreadCount(not_null peer) { return 0; } +QString TitleRecentlyUsed() { + const auto &sets = Auth().data().stickerSets(); + const auto it = sets.constFind(Stickers::CloudRecentSetId); + if (it != sets.cend()) { + return it->title; + } + return tr::lng_recent_stickers(tr::now); +} + NSString *FormatTime(int time) { const auto seconds = time % 60; const auto minutes = (time / 60) % 60; @@ -324,16 +333,12 @@ void AppendFavedStickers(std::vector &to) { } void AppendEmojiPacks(std::vector &to) { - // Get 'Recent' string. - const auto recent = Auth().data().stickerSets() - .constFind(Stickers::CloudRecentSetId)->title; - for (auto i = 0; i != ChatHelpers::kEmojiSectionCount; ++i) { const auto section = Ui::Emoji::GetSection( static_cast(i)); const auto title = i - ? lang(LangKey(lng_emoji_category1 + i)) - : recent; + ? Ui::Emoji::CategoryTitle(i)(tr::now) + : TitleRecentlyUsed(); to.emplace_back(title); for (const auto &emoji : section) { to.emplace_back(PickerScrubberItem(emoji)); @@ -712,6 +717,10 @@ void AppendEmojiPacks(std::vector &to) { break; } } + if (!temp.size()) { + temp.emplace_back(PickerScrubberItem( + tr::lng_stickers_nothing_found(tr::now))); + } _stickers = std::move(temp); } diff --git a/Telegram/SourceFiles/ui/emoji_config.cpp b/Telegram/SourceFiles/ui/emoji_config.cpp index 8d2651e31..6e6dd77e4 100644 --- a/Telegram/SourceFiles/ui/emoji_config.cpp +++ b/Telegram/SourceFiles/ui/emoji_config.cpp @@ -576,6 +576,19 @@ void ClearIrrelevantCache() { }); } +tr::phrase<> CategoryTitle(int index) { + switch (index) { + case 1: return tr::lng_emoji_category1; + case 2: return tr::lng_emoji_category2; + case 3: return tr::lng_emoji_category3; + case 4: return tr::lng_emoji_category4; + case 5: return tr::lng_emoji_category5; + case 6: return tr::lng_emoji_category6; + case 7: return tr::lng_emoji_category7; + } + Unexpected("Index in CategoryTitle."); +} + std::vector Sets() { return kSets | ranges::to_vector; } diff --git a/Telegram/SourceFiles/ui/emoji_config.h b/Telegram/SourceFiles/ui/emoji_config.h index d87cb9d98..522f854bc 100644 --- a/Telegram/SourceFiles/ui/emoji_config.h +++ b/Telegram/SourceFiles/ui/emoji_config.h @@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL #include "base/binary_guard.h" #include "emoji.h" +#include "lang/lang_keys.h" namespace Ui { namespace Emoji { @@ -37,6 +38,8 @@ struct Set { // Thread safe, callback is called on main thread. void SwitchToSet(int id, Fn callback); +tr::phrase<> CategoryTitle(int index); + std::vector Sets(); int CurrentSetId(); bool SetIsReady(int id);