Allow editing tag name from search tags.

This commit is contained in:
John Preston 2024-02-02 11:25:04 +04:00
parent f072173d7c
commit 8459c29073
9 changed files with 111 additions and 23 deletions

View file

@ -2833,6 +2833,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
"lng_context_animated_emoji_many#one" = "This message contains emoji from **{count} pack**.";
"lng_context_animated_emoji_many#other" = "This message contains emoji from **{count} packs**.";
"lng_context_animated_reaction" = "This reaction is from **{name} pack**.";
"lng_context_animated_tag" = "This tag is from **{name} pack**.";
"lng_context_animated_reactions" = "Reactions contain emoji from **{name} pack**.";
"lng_context_animated_reactions_many#one" = "Reactions contain emoji from **{count} pack**.";
"lng_context_animated_reactions_many#other" = "Reactions contain emoji from **{count} packs**.";

View file

@ -1320,7 +1320,7 @@ editTagAbout: FlatLabel(defaultFlatLabel) {
}
editTagField: InputField(defaultInputField) {
textBg: transparent;
textMargins: margins(24px, 10px, 32px, 0px);
textMargins: margins(24px, 10px, 32px, 2px);
placeholderFg: placeholderFg;
placeholderFgActive: placeholderFgActive;
@ -1328,7 +1328,7 @@ editTagField: InputField(defaultInputField) {
placeholderMargins: margins(2px, 0px, 2px, 0px);
placeholderScale: 0.;
heightMin: 32px;
heightMin: 36px;
}
editTagLimit: FlatLabel(defaultFlatLabel) {
textFg: windowSubTextFg;

View file

@ -16,6 +16,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_widget.h"
#include "dialogs/dialogs_search_from_controllers.h"
#include "dialogs/dialogs_search_tags.h"
#include "history/view/history_view_context_menu.h"
#include "history/history.h"
#include "history/history_item.h"
#include "core/application.h"
@ -3010,6 +3011,16 @@ void InnerWidget::searchInChat(
update(0, searchInChatOffset(), width(), height);
}, _searchTags->lifetime());
_searchTags->menuRequests(
) | rpl::start_with_next([=](Data::ReactionId id) {
HistoryView::ShowTagInListMenu(
&_menu,
_lastMousePosition.value_or(QCursor::pos()),
this,
id,
_controller);
}, _searchTags->lifetime());
_searchTags->heightValue() | rpl::skip(
1
) | rpl::start_with_next([=] {

View file

@ -132,11 +132,14 @@ void SearchTags::fill(
_tags.clear();
_tags.reserve(list.size());
const auto link = [&](Data::ReactionId id) {
return std::make_shared<LambdaClickHandler>(crl::guard(this, [=](
return std::make_shared<GenericClickHandler>(crl::guard(this, [=](
ClickContext context) {
if (!premium) {
MakePromoLink()->onClick(context);
return;
} else if (context.button == Qt::RightButton) {
_menuRequests.fire_copy(id);
return;
}
const auto i = ranges::find(_tags, id, &Tag::id);
if (i != end(_tags)) {
@ -315,6 +318,10 @@ void SearchTags::paintCustomFrame(
_customCache);
}
rpl::producer<Data::ReactionId> SearchTags::menuRequests() const {
return _menuRequests.events();
}
void SearchTags::paint(
Painter &p,
QPoint position,

View file

@ -40,6 +40,8 @@ public:
[[nodiscard]] auto selectedChanges() const
-> rpl::producer<std::vector<Data::ReactionId>>;
[[nodiscard]] rpl::producer<Data::ReactionId> menuRequests() const;
void paint(
Painter &p,
QPoint position,
@ -73,6 +75,7 @@ private:
Ui::Text::String _additionalText;
rpl::event_stream<> _selectedChanges;
rpl::event_stream<> _repaintRequests;
rpl::event_stream<Data::ReactionId> _menuRequests;
mutable QImage _normalBg;
mutable QImage _selectedBg;
mutable QImage _promoBg;

View file

@ -18,6 +18,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "dialogs/dialogs_search_from_controllers.h" // SearchFromBox
#include "dialogs/dialogs_search_tags.h"
#include "dialogs/ui/dialogs_layout.h"
#include "history/view/history_view_context_menu.h"
#include "history/history.h"
#include "history/history_item.h"
#include "lang/lang_keys.h"
@ -26,6 +27,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/buttons.h"
#include "ui/widgets/labels.h"
#include "ui/widgets/multi_select.h"
#include "ui/widgets/popup_menu.h"
#include "ui/widgets/shadow.h"
#include "ui/widgets/scroll_area.h"
#include "ui/painter.h"
@ -297,6 +299,8 @@ private:
std::vector<Data::ReactionId> _searchTagsSelected;
base::unique_qptr<Ui::MultiSelect> _select;
std::unique_ptr<Dialogs::SearchTags> _searchTags;
base::unique_qptr<Ui::PopupMenu> _menu;
std::optional<QPoint> _mouseGlobalPosition;
const not_null<Window::SessionController*> _window;
const not_null<History*> _history;
@ -461,6 +465,16 @@ void TopBar::refreshTags() {
requestSearch(false);
}, _searchTags->lifetime());
_searchTags->menuRequests(
) | rpl::start_with_next([=](Data::ReactionId id) {
ShowTagInListMenu(
&_menu,
_mouseGlobalPosition.value_or(QCursor::pos()),
this,
id,
_window);
}, _searchTags->lifetime());
if (!_searchTagsSelected.empty()) {
crl::on_main(this, [=] {
requestSearch(false);
@ -497,6 +511,7 @@ void TopBar::refreshTags() {
parent->events() | rpl::start_with_next([=](not_null<QEvent*> e) {
if (e->type() == QEvent::MouseMove) {
const auto mouse = static_cast<QMouseEvent*>(e.get());
_mouseGlobalPosition = mouse->globalPos();
const auto point = mouse->pos() - position;
const auto handler = _searchTags->lookupHandler(point);
ClickHandler::setActive(handler);

View file

@ -1074,7 +1074,7 @@ void EditTagBox(
}, warning->lifetime());
warning->setAttribute(Qt::WA_TransparentForMouseEvents);
box->addButton(tr::lng_settings_save(), [=] {
const auto save = [=] {
const auto text = field->getLastText();
if (text.size() > kTagNameLimit) {
field->showError();
@ -1085,7 +1085,12 @@ void EditTagBox(
if (const auto strong = weak.data()) {
strong->closeBox();
}
});
};
field->submits(
) | rpl::start_with_next(save, field->lifetime());
box->addButton(tr::lng_settings_save(), save);
box->addButton(tr::lng_cancel(), [=] {
box->closeBox();
});
@ -1454,6 +1459,37 @@ void AddWhoReactedAction(
}
}
void AddEditTagAction(
not_null<Ui::PopupMenu*> menu,
const Data::ReactionId &id,
not_null<Window::SessionController*> controller) {
const auto owner = &controller->session().data();
const auto editLabel = owner->reactions().myTagTitle(id).isEmpty()
? tr::lng_context_tag_add_name(tr::now)
: tr::lng_context_tag_edit_name(tr::now);
menu->addAction(editLabel, [=] {
controller->show(Box(EditTagBox, controller, id));
}, &st::menuIconTagRename);
}
void AddTagPackAction(
not_null<Ui::PopupMenu*> menu,
const Data::ReactionId &id,
not_null<Window::SessionController*> controller) {
if (const auto custom = id.custom()) {
const auto owner = &controller->session().data();
if (const auto set = owner->document(custom)->sticker()) {
if (set->set.id) {
AddEmojiPacksAction(
menu,
{ set->set },
EmojiPacksSource::Tag,
controller);
}
}
}
}
void ShowTagMenu(
not_null<base::unique_qptr<Ui::PopupMenu>*> menu,
QPoint position,
@ -1476,12 +1512,7 @@ void ShowTagMenu(
});
}, &st::menuIconTagFilter);
const auto editLabel = owner->reactions().myTagTitle(id).isEmpty()
? tr::lng_context_tag_add_name(tr::now)
: tr::lng_context_tag_edit_name(tr::now);
(*menu)->addAction(editLabel, [=] {
controller->show(Box(EditTagBox, controller, id));
}, &st::menuIconTagRename);
AddEditTagAction(menu->get(), id, controller);
const auto removeTag = [=] {
if (const auto item = owner->message(itemId)) {
@ -1503,17 +1534,24 @@ void ShowTagMenu(
&st::menuIconTagRemoveAttention,
&st::menuIconTagRemoveAttention));
if (const auto custom = id.custom()) {
if (const auto set = owner->document(custom)->sticker()) {
if (set->set.id) {
AddEmojiPacksAction(
menu->get(),
{ set->set },
EmojiPacksSource::Reaction,
controller);
}
}
}
AddTagPackAction(menu->get(), id, controller);
(*menu)->popup(position);
}
void ShowTagInListMenu(
not_null<base::unique_qptr<Ui::PopupMenu>*> menu,
QPoint position,
not_null<QWidget*> context,
const Data::ReactionId &id,
not_null<Window::SessionController*> controller) {
*menu = base::make_unique_q<Ui::PopupMenu>(
context,
st::popupMenuExpandedSeparator);
AddEditTagAction(menu->get(), id, controller);
AddTagPackAction(menu->get(), id, controller);
(*menu)->popup(position);
}
@ -1676,6 +1714,12 @@ void AddEmojiPacksAction(
lt_name,
TextWithEntities{ name },
Ui::Text::RichLangValue);
case EmojiPacksSource::Tag:
return tr::lng_context_animated_tag(
tr::now,
lt_name,
TextWithEntities{ name },
Ui::Text::RichLangValue);
case EmojiPacksSource::Reaction:
if (!name.text.isEmpty()) {
return tr::lng_context_animated_reaction(

View file

@ -88,11 +88,18 @@ void ShowWhoReactedMenu(
const Data::ReactionId &id,
not_null<Window::SessionController*> controller,
rpl::lifetime &lifetime);
void ShowTagInListMenu(
not_null<base::unique_qptr<Ui::PopupMenu>*> menu,
QPoint position,
not_null<QWidget*> context,
const Data::ReactionId &id,
not_null<Window::SessionController*> controller);
enum class EmojiPacksSource {
Message,
Reaction,
Reactions,
Tag,
};
[[nodiscard]] std::vector<StickerSetIdentifier> CollectEmojiPacks(
not_null<HistoryItem*> item,

@ -1 +1 @@
Subproject commit a2c2d92cda2cffdafeb671d1f292a2002fb54217
Subproject commit 7328e2786248c673e3599695a56989d9c1062303