[Option][GUI] Folder options

This commit is contained in:
Eric Kotato 2022-09-05 15:31:25 +03:00
parent 92c5d63157
commit c0a2f78bb7
11 changed files with 169 additions and 31 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.2 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 3 KiB

View file

@ -83,8 +83,13 @@
"other": "Recent stickers: show {count} stickers"
},
"ktg_settings_recent_stickers_limit_none": "Recent stickers: hide all",
"ktg_filters_context_edit_all": "Edit folders",
"ktg_settings_filters": "Folders",
"ktg_settings_filters_only_unmuted_counter": "Do not count muted chats",
"ktg_settings_filters_hide_edit": "Hide Edit button",
"ktg_settings_filters_hide_folder_names": "Compact folders",
"ktg_settings_messages": "Messages",
"ktg_settings_filters_hide_all": "Hide \"All chats\" folder",
"ktg_settings_userpic_rounding": "Profile pictures rounding",
"ktg_settings_userpic_rounding_none": "Square",
"ktg_settings_userpic_rounding_small": "Small",
@ -113,6 +118,10 @@
"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.",
"ktg_channel_id_copied": "Channel ID copied to clipboard.",
"ktg_settings_forward": "Forward",
"ktg_filters_hide_folder": "Hide folder",
"ktg_filters_hide_button": "Hide button",
"ktg_filters_hide_all_chats_toast": "\"All Chats\" folder is hidden.\nYou can enable it back in Kotatogram Settings.",
"ktg_filters_hide_edit_toast": "Edit button is hidden.\nYou can enable it back in Kotatogram Settings.",
"ktg_in_app_update_disabled": "In-app updater is disabled.",
"dummy_last_string": ""
}

View file

@ -407,6 +407,18 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap {
.type = SettingType::IntSetting,
.defaultValue = 0,
.limitHandler = IntLimit(0, 5), }},
{ "folders/count_unmuted_only", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_edit_button", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_names", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
{ "folders/hide_all_chats", {
.type = SettingType::BoolSetting,
.defaultValue = false, }},
};
using OldOptionKey = QString;

View file

@ -159,6 +159,22 @@ QString ChatIdLabel(int option) {
::Kotato::JsonSettings::Write(); \
}, container->lifetime());
#define SettingsMenuJsonFilterSwitch(LangKey, Option) AddButton( \
container, \
rktr(#LangKey), \
st::settingsButton \
)->toggleOn( \
rpl::single(::Kotato::JsonSettings::GetBool(#Option)) \
)->toggledValue( \
) | rpl::filter([](bool enabled) { \
return (enabled != ::Kotato::JsonSettings::GetBool(#Option)); \
}) | rpl::start_with_next([controller](bool enabled) { \
::Kotato::JsonSettings::Set(#Option, enabled); \
::Kotato::JsonSettings::Write(); \
controller->reloadFiltersMenu(); \
App::wnd()->fixOrder(); \
}, container->lifetime());
void SetupKotatoChats(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
@ -424,6 +440,10 @@ void SetupKotatoFolders(
AddSkip(container);
AddSubsectionTitle(container, rktr("ktg_settings_filters"));
SettingsMenuJsonFilterSwitch(ktg_settings_filters_only_unmuted_counter, folders/count_unmuted_only);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_all, folders/hide_all_chats);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_edit, folders/hide_edit_button);
SettingsMenuJsonFilterSwitch(ktg_settings_filters_hide_folder_names, folders/hide_names);
AddSkip(container);
}

View file

@ -86,6 +86,7 @@ menuIconImportTheme: icon {{ "menu/import_theme", menuSubmenuArrowFg }};
menuIconExportTheme: icon {{ "menu/export_theme", menuSubmenuArrowFg }};
menuIconRestore: icon {{ "menu/restore", menuSubmenuArrowFg }};
menuIconSettings: icon {{ "menu/settings", menuSubmenuArrowFg }};
menuIconHide: icon {{ "menu/hide", menuSubmenuArrowFg }};
mediaMenuIconStickers: icon {{ "menu/stickers", mediaviewMenuFg }};
mediaMenuIconCancel: icon {{ "menu/cancel", mediaviewMenuFg }};

View file

@ -268,10 +268,11 @@ createThemeLink: InputField(defaultInputField) {
}
windowFiltersWidth: 72px;
windowFiltersWidthNoText: 50px;
windowFiltersButton: SideBarButton(defaultSideBarButton) {
textTop: 40px;
textSkip: 6px;
minHeight: 62px;
minHeight: 48px;
minTextWidth: 48px;
style: TextStyle(defaultTextStyle) {
font: font(11px semibold);

View file

@ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
*/
#include "window/window_filters_menu.h"
#include "kotato/kotato_settings.h"
#include "kotato/kotato_lang.h"
#include "mainwindow.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
@ -20,6 +22,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/filter_icons.h"
#include "ui/wrap/vertical_layout_reorder.h"
#include "ui/widgets/popup_menu.h"
#include "ui/toast/toast.h"
#include "ui/boxes/confirm_box.h"
#include "boxes/filters/edit_filter_box.h"
#include "settings/settings_common.h"
@ -92,7 +95,9 @@ void FiltersMenu::setup() {
_parent->heightValue(
) | rpl::start_with_next([=](int height) {
const auto width = st::windowFiltersWidth;
const auto width = (::Kotato::JsonSettings::GetBool("folders/hide_names")
? st::windowFiltersWidthNoText
: st::windowFiltersWidth);
_outer.setGeometry({ 0, 0, width, height });
_menu.resizeToWidth(width);
_menu.move(0, 0);
@ -119,7 +124,7 @@ void FiltersMenu::setup() {
const auto i = _filters.find(_activeFilterId);
if (i != end(_filters)) {
i->second->setActive(false);
} else if (!_activeFilterId) {
} else if (!_activeFilterId && _all) {
_all->setActive(false);
}
_activeFilterId = id;
@ -127,7 +132,7 @@ void FiltersMenu::setup() {
if (j != end(_filters)) {
j->second->setActive(true);
scrollToButton(j->second);
} else if (!_activeFilterId) {
} else if (!_activeFilterId && _all) {
_all->setActive(true);
scrollToButton(_all);
}
@ -207,21 +212,29 @@ void FiltersMenu::refresh() {
// so we have to restore it.
_scroll.scrollToY(oldTop);
const auto i = _filters.find(_activeFilterId);
scrollToButton((i != end(_filters)) ? i->second : _all);
if (i != end(_filters)) {
scrollToButton(i->second);
} else if (!::Kotato::JsonSettings::GetBool("folders/hide_all_chats")) {
scrollToButton(_all);
}
}
void FiltersMenu::setupList() {
if (!::Kotato::JsonSettings::GetBool("folders/hide_all_chats")) {
_all = prepareButton(
_container,
0,
tr::lng_filters_all(tr::now),
Ui::FilterIcon::All);
}
_list = _container->add(object_ptr<Ui::VerticalLayout>(_container));
if (!::Kotato::JsonSettings::GetBool("folders/hide_edit_button")) {
_setup = prepareButton(
_container,
-1,
tr::lng_filters_setup(tr::now),
Ui::FilterIcon::Edit);
}
_reorder = std::make_unique<Ui::VerticalLayoutReorder>(_list, &_scroll);
_reorder->updates(
@ -248,7 +261,7 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
auto button = base::unique_qptr<Ui::SideBarButton>(container->add(
object_ptr<Ui::SideBarButton>(
container,
title,
(::Kotato::JsonSettings::GetBool("folders/hide_names") ? QString() : title),
st::windowFiltersButton)));
const auto raw = button.get();
const auto &icons = Ui::LookupFilterIcon(icon);
@ -260,12 +273,22 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
) | rpl::start_with_next([=](const Dialogs::UnreadState &state) {
const auto count = (state.chats + state.marks);
const auto muted = (state.chatsMuted + state.marksMuted);
if (::Kotato::JsonSettings::GetBool("folders/count_unmuted_only")) {
const auto unmuted = count - muted;
const auto string = !unmuted
? QString()
: (unmuted > 99)
? "99+"
: QString::number(unmuted);
raw->setBadge(string, false);
} else {
const auto string = !count
? QString()
: (count > 99)
? "99+"
: QString::number(count);
raw->setBadge(string, count == muted);
}
}, raw->lifetime());
}
raw->setActive(_session->activeChatsFilterCurrent() == id);
@ -288,14 +311,18 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton(
}
}
});
if (id > 0) {
raw->events(
) | rpl::filter([=](not_null<QEvent*> e) {
return e->type() == QEvent::ContextMenu;
}) | rpl::start_with_next([=] {
if (id == -1) {
showEditMenu(QCursor::pos());
} else if (id) {
showMenu(QCursor::pos(), id);
}, raw->lifetime());
} else {
showAllMenu(QCursor::pos());
}
}, raw->lifetime());
return button;
}
@ -323,7 +350,7 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
addAction(
tr::lng_filters_context_edit(tr::now),
[=] { showEditBox(id); },
crl::guard(&_outer, [=] { showEditBox(id); }),
&st::menuIconEdit);
auto filteredChats = [=] {
@ -340,6 +367,68 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) {
_popupMenu->popup(position);
}
void FiltersMenu::showAllMenu(QPoint position) {
if (_popupMenu) {
_popupMenu = nullptr;
return;
}
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
_all,
st::popupMenuWithIcons);
const auto addAction = [&](
const QString &text,
Fn<void()> callback,
const style::icon *icon) {
return _popupMenu->addAction(
text,
crl::guard(&_outer, std::move(callback)),
icon);
};
MenuAddMarkAsReadAllChatsAction(&_session->session().data(), addAction);
_popupMenu->addAction(
ktr("ktg_filters_context_edit_all"),
crl::guard(&_outer, [=] { _session->showSettings(Settings::Type::Folders); }),
&st::menuIconEdit);
_popupMenu->addAction(
ktr("ktg_filters_hide_folder"),
crl::guard(&_outer, [=] {
::Kotato::JsonSettings::Set("folders/hide_all_chats", true);
::Kotato::JsonSettings::Write();
_all = nullptr;
Ui::Toast::Show(Ui::Toast::Config{
.text = { ktr("ktg_filters_hide_all_chats_toast") },
.st = &st::windowArchiveToast,
.multiline = true,
});
}), &st::menuIconHide);
_popupMenu->popup(position);
}
void FiltersMenu::showEditMenu(QPoint position) {
if (_popupMenu) {
_popupMenu = nullptr;
return;
}
_popupMenu = base::make_unique_q<Ui::PopupMenu>(
_setup,
st::popupMenuWithIcons);
_popupMenu->addAction(
ktr("ktg_filters_hide_button"),
crl::guard(&_outer, [=] {
::Kotato::JsonSettings::Set("folders/hide_edit_button", true);
::Kotato::JsonSettings::Write();
_setup = nullptr;
Ui::Toast::Show(Ui::Toast::Config{
.text = { ktr("ktg_filters_hide_edit_toast") },
.st = &st::windowArchiveToast,
.multiline = true,
});
}), &st::menuIconHide);
_popupMenu->popup(position);
}
void FiltersMenu::showEditBox(FilterId id) {
EditExistingFilter(_session, id);
}

View file

@ -48,6 +48,8 @@ private:
Ui::FilterIcon icon);
void setupMainMenuIcon();
void showMenu(QPoint position, FilterId id);
void showAllMenu(QPoint position);
void showEditMenu(QPoint position);
void showEditBox(FilterId id);
void showRemoveBox(FilterId id);
void remove(FilterId id);

View file

@ -1413,7 +1413,11 @@ not_null<MainWidget*> SessionController::content() const {
}
int SessionController::filtersWidth() const {
return _filters ? st::windowFiltersWidth : 0;
return _filters
? (::Kotato::JsonSettings::GetBool("folders/hide_names")
? st::windowFiltersWidthNoText
: st::windowFiltersWidth)
: 0;
}
rpl::producer<FilterId> SessionController::activeChatsFilter() const {