Replaced box for choosing of filter with submenu.

This commit is contained in:
23rd 2022-04-10 13:49:14 +03:00
parent d15ff46eb4
commit 8440c44def
7 changed files with 45 additions and 19 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 608 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1003 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

View File

@ -19,9 +19,11 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/text/text_utilities.h" // Ui::Text::Bold
#include "ui/toast/toast.h"
#include "ui/widgets/buttons.h"
#include "ui/widgets/popup_menu.h"
#include "window/window_session_controller.h"
#include "styles/style_settings.h"
#include "styles/style_payments.h" // paymentsSectionButton
#include "styles/style_media_player.h" // mediaPlayerMenuCheck
namespace {
@ -203,3 +205,31 @@ void ChooseFilterBox(
box->addButton(tr::lng_close(), [=] { box->closeBox(); });
}
void FillChooseFilterMenu(
not_null<Ui::PopupMenu*> menu,
not_null<History*> history) {
const auto validator = ChooseFilterValidator(history);
for (const auto &filter : history->owner().chatsFilters().list()) {
const auto id = filter.id();
const auto contains = filter.contains(history);
const auto action = menu->addAction(filter.title(), [=] {
if (filter.contains(history)) {
if (validator.canRemove(id)) {
validator.remove(id);
}
} else {
if (validator.canAdd()) {
validator.add(id);
}
}
}, contains ? &st::mediaPlayerMenuCheck : nullptr);
action->setEnabled(contains
? validator.canRemove(id)
: validator.canAdd());
}
history->owner().chatsFilters().changed(
) | rpl::start_with_next([=] {
menu->hideMenu();
}, menu->lifetime());
}

View File

@ -9,6 +9,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
namespace Ui {
class GenericBox;
class PopupMenu;
} // namespace Ui
class History;
@ -31,3 +32,7 @@ private:
void ChooseFilterBox(
not_null<Ui::GenericBox*> box,
not_null<History*> history);
void FillChooseFilterMenu(
not_null<Ui::PopupMenu*> menu,
not_null<History*> history);

View File

@ -111,6 +111,7 @@ menuIconSoundSelect: icon {{ "menu/sound_select", menuIconColor }};
menuIconSoundAdd: icon {{ "menu/sound_add", menuIconColor }};
menuIconFile: icon {{ "menu/file", menuIconColor }};
menuIconPhoto: icon {{ "menu/image", menuIconColor }};
menuIconAddToFolder: icon {{ "menu/add_to_folder", menuIconColor }};
menuIconTTLAny: icon {{ "menu/auto_delete_plain", menuIconColor }};
menuIconTTLAnyTextPosition: point(11px, 22px);

View File

@ -420,27 +420,17 @@ void Filler::addInfo() {
void Filler::addToggleFolder() {
const auto history = _request.key.history();
if (!history) {
if (!history || history->owner().chatsFilters().list().empty()) {
return;
}
if (!_request.filterId) {
if (!ChooseFilterValidator(history).canAdd()) {
return;
}
const auto window = _controller;
_addAction(tr::lng_filters_menu_add(tr::now), [=] {
window->show(Box(ChooseFilterBox, history));
}, nullptr);
} else {
const auto id = _request.filterId;
const auto validator = ChooseFilterValidator(history);
if (!validator.canRemove(id)) {
return;
}
_addAction(tr::lng_filters_menu_remove(tr::now), [=] {
validator.remove(id);
}, nullptr);
}
_addAction(PeerMenuCallback::Args{
.text = tr::lng_filters_menu_add(tr::now),
.handler = nullptr,
.icon = &st::menuIconAddToFolder,
.fillSubmenu = [=](not_null<Ui::PopupMenu*> menu) {
FillChooseFilterMenu(menu, history);
},
});
}
void Filler::addToggleUnreadMark() {