[Option][GUI] Folder options
This commit is contained in:
		
							parent
							
								
									bba57d7d16
								
							
						
					
					
						commit
						a5bd126eb8
					
				
					 11 changed files with 112 additions and 18 deletions
				
			
		
							
								
								
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.2 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide@2x.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide@2x.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 2.8 KiB | 
							
								
								
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide@3x.png
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										
											BIN
										
									
								
								Telegram/Resources/icons/menu/hide@3x.png
									
										
									
									
									
										Normal file
									
								
							
										
											Binary file not shown.
										
									
								
							| After Width: | Height: | Size: 3 KiB | 
|  | @ -62,8 +62,13 @@ | ||||||
| 		"other": "Recent stickers: show {count} stickers" | 		"other": "Recent stickers: show {count} stickers" | ||||||
| 	}, | 	}, | ||||||
| 	"ktg_settings_recent_stickers_limit_none": "Recent stickers: hide all", | 	"ktg_settings_recent_stickers_limit_none": "Recent stickers: hide all", | ||||||
|  | 	"ktg_filters_context_edit_all": "Edit folders", | ||||||
| 	"ktg_settings_filters": "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_messages": "Messages", | ||||||
|  | 	"ktg_settings_filters_hide_all": "Hide \"All chats\" folder", | ||||||
| 	"ktg_settings_tray_icon": "Tray icon", | 	"ktg_settings_tray_icon": "Tray icon", | ||||||
| 	"ktg_settings_tray_icon_default": "Default", | 	"ktg_settings_tray_icon_default": "Default", | ||||||
| 	"ktg_settings_tray_icon_blue": "Blue", | 	"ktg_settings_tray_icon_blue": "Blue", | ||||||
|  | @ -86,6 +91,10 @@ | ||||||
| 	"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.", | 	"ktg_supergroup_id_copied": "Supergroup ID copied to clipboard.", | ||||||
| 	"ktg_channel_id_copied": "Channel ID copied to clipboard.", | 	"ktg_channel_id_copied": "Channel ID copied to clipboard.", | ||||||
| 	"ktg_settings_forward": "Forward", | 	"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.", | 	"ktg_in_app_update_disabled": "In-app updater is disabled.", | ||||||
| 	"dummy_last_string": "" | 	"dummy_last_string": "" | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -306,6 +306,18 @@ const std::map<QString, Definition, std::greater<QString>> DefinitionMap { | ||||||
| 		.type = SettingType::IntSetting, | 		.type = SettingType::IntSetting, | ||||||
| 		.defaultValue = 0, | 		.defaultValue = 0, | ||||||
| 		.limitHandler = IntLimit(0, 5), }}, | 		.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; | using OldOptionKey = QString; | ||||||
|  |  | ||||||
|  | @ -107,6 +107,21 @@ QString ChatIdLabel(int option) { | ||||||
| 	::Kotato::JsonSettings::Write(); \ | 	::Kotato::JsonSettings::Write(); \ | ||||||
| }, container->lifetime()); | }, container->lifetime()); | ||||||
| 
 | 
 | ||||||
|  | #define SettingsMenuJsonFilterSwitch(LangKey, Option) container->add(object_ptr<Button>( \ | ||||||
|  | 	container, \ | ||||||
|  | 	rktr(#LangKey), \ | ||||||
|  | 	st::settingsButtonNoIcon \ | ||||||
|  | ))->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(); \ | ||||||
|  | }, container->lifetime()); | ||||||
|  | 
 | ||||||
| void SetupKotatoChats( | void SetupKotatoChats( | ||||||
| 	not_null<Window::SessionController*> controller, | 	not_null<Window::SessionController*> controller, | ||||||
| 	not_null<Ui::VerticalLayout*> container) { | 	not_null<Ui::VerticalLayout*> container) { | ||||||
|  | @ -281,6 +296,10 @@ void SetupKotatoFolders( | ||||||
| 	Ui::AddSkip(container); | 	Ui::AddSkip(container); | ||||||
| 	Ui::AddSubsectionTitle(container, rktr("ktg_settings_filters")); | 	Ui::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); | ||||||
| 
 | 
 | ||||||
| 	Ui::AddSkip(container); | 	Ui::AddSkip(container); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -79,6 +79,7 @@ menuIconFake: icon {{ "menu/fake", menuIconColor }}; | ||||||
| menuIconPersonal: icon {{ "menu/personal", menuIconColor }}; | menuIconPersonal: icon {{ "menu/personal", menuIconColor }}; | ||||||
| menuIconPorn: icon {{ "menu/porn", menuIconColor }}; | menuIconPorn: icon {{ "menu/porn", menuIconColor }}; | ||||||
| menuIconViolence: icon {{ "menu/violence", menuIconColor }}; | menuIconViolence: icon {{ "menu/violence", menuIconColor }}; | ||||||
|  | menuIconHide: icon {{ "menu/hide", menuIconColor }}; | ||||||
| menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }}; | menuIconMuteFor: icon {{ "menu/mute_for", menuIconColor }}; | ||||||
| menuIconSilent: icon {{ "menu/silent", menuIconColor }}; | menuIconSilent: icon {{ "menu/silent", menuIconColor }}; | ||||||
| menuIconCustomize: icon {{ "menu/customize", menuIconColor }}; | menuIconCustomize: icon {{ "menu/customize", menuIconColor }}; | ||||||
|  |  | ||||||
|  | @ -240,10 +240,11 @@ createThemeLink: InputField(defaultInputField) { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| windowFiltersWidth: 72px; | windowFiltersWidth: 72px; | ||||||
|  | windowFiltersWidthNoText: 50px; | ||||||
| windowFiltersButton: SideBarButton(defaultSideBarButton) { | windowFiltersButton: SideBarButton(defaultSideBarButton) { | ||||||
| 	textTop: 40px; | 	textTop: 40px; | ||||||
| 	textSkip: 6px; | 	textSkip: 6px; | ||||||
| 	minHeight: 62px; | 	minHeight: 48px; | ||||||
| 	minTextWidth: 48px; | 	minTextWidth: 48px; | ||||||
| 	style: TextStyle(defaultTextStyle) { | 	style: TextStyle(defaultTextStyle) { | ||||||
| 		font: font(11px semibold); | 		font: font(11px semibold); | ||||||
|  |  | ||||||
|  | @ -7,6 +7,8 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| */ | */ | ||||||
| #include "window/window_filters_menu.h" | #include "window/window_filters_menu.h" | ||||||
| 
 | 
 | ||||||
|  | #include "kotato/kotato_settings.h" | ||||||
|  | #include "kotato/kotato_lang.h" | ||||||
| #include "mainwindow.h" | #include "mainwindow.h" | ||||||
| #include "window/window_session_controller.h" | #include "window/window_session_controller.h" | ||||||
| #include "window/window_controller.h" | #include "window/window_controller.h" | ||||||
|  | @ -24,6 +26,7 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL | ||||||
| #include "ui/wrap/vertical_layout.h" | #include "ui/wrap/vertical_layout.h" | ||||||
| #include "ui/wrap/vertical_layout_reorder.h" | #include "ui/wrap/vertical_layout_reorder.h" | ||||||
| #include "ui/widgets/popup_menu.h" | #include "ui/widgets/popup_menu.h" | ||||||
|  | #include "ui/toast/toast.h" | ||||||
| #include "ui/boxes/confirm_box.h" | #include "ui/boxes/confirm_box.h" | ||||||
| #include "boxes/filters/edit_filter_box.h" | #include "boxes/filters/edit_filter_box.h" | ||||||
| #include "boxes/premium_limits_box.h" | #include "boxes/premium_limits_box.h" | ||||||
|  | @ -110,7 +113,9 @@ void FiltersMenu::setup() { | ||||||
| 
 | 
 | ||||||
| 	_parent->heightValue( | 	_parent->heightValue( | ||||||
| 	) | rpl::start_with_next([=](int height) { | 	) | 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 }); | 		_outer.setGeometry({ 0, 0, width, height }); | ||||||
| 		_menu.resizeToWidth(width); | 		_menu.resizeToWidth(width); | ||||||
| 		_menu.move(0, 0); | 		_menu.move(0, 0); | ||||||
|  | @ -245,11 +250,13 @@ void FiltersMenu::refresh() { | ||||||
| 
 | 
 | ||||||
| void FiltersMenu::setupList() { | void FiltersMenu::setupList() { | ||||||
| 	_list = _container->add(object_ptr<Ui::VerticalLayout>(_container)); | 	_list = _container->add(object_ptr<Ui::VerticalLayout>(_container)); | ||||||
|  | 	if (!::Kotato::JsonSettings::GetBool("folders/hide_edit_button")) { | ||||||
| 		_setup = prepareButton( | 		_setup = prepareButton( | ||||||
| 			_container, | 			_container, | ||||||
| 			-1, | 			-1, | ||||||
| 			tr::lng_filters_setup(tr::now), | 			tr::lng_filters_setup(tr::now), | ||||||
| 			Ui::FilterIcon::Edit); | 			Ui::FilterIcon::Edit); | ||||||
|  | 	} | ||||||
| 	_reorder = std::make_unique<Ui::VerticalLayoutReorder>(_list, &_scroll); | 	_reorder = std::make_unique<Ui::VerticalLayoutReorder>(_list, &_scroll); | ||||||
| 
 | 
 | ||||||
| 	_reorder->updates( | 	_reorder->updates( | ||||||
|  | @ -284,7 +291,9 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton( | ||||||
| 		bool toBeginning) { | 		bool toBeginning) { | ||||||
| 	auto prepared = object_ptr<Ui::SideBarButton>( | 	auto prepared = object_ptr<Ui::SideBarButton>( | ||||||
| 		container, | 		container, | ||||||
| 		id ? title : tr::lng_filters_all(tr::now), | 		(::Kotato::JsonSettings::GetBool("folders/hide_names") | ||||||
|  | 			? QString() | ||||||
|  | 			: id ? title : tr::lng_filters_all(tr::now)), | ||||||
| 		st::windowFiltersButton); | 		st::windowFiltersButton); | ||||||
| 	auto added = toBeginning | 	auto added = toBeginning | ||||||
| 		? container->insert(0, std::move(prepared)) | 		? container->insert(0, std::move(prepared)) | ||||||
|  | @ -302,12 +311,22 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton( | ||||||
| 		) | rpl::start_with_next([=](const Dialogs::UnreadState &state) { | 		) | rpl::start_with_next([=](const Dialogs::UnreadState &state) { | ||||||
| 			const auto count = (state.chats + state.marks); | 			const auto count = (state.chats + state.marks); | ||||||
| 			const auto muted = (state.chatsMuted + state.marksMuted); | 			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 | 				const auto string = !count | ||||||
| 					? QString() | 					? QString() | ||||||
| 					: (count > 99) | 					: (count > 99) | ||||||
| 					? "99+" | 					? "99+" | ||||||
| 					: QString::number(count); | 					: QString::number(count); | ||||||
| 				raw->setBadge(string, count == muted); | 				raw->setBadge(string, count == muted); | ||||||
|  | 			} | ||||||
| 		}, raw->lifetime()); | 		}, raw->lifetime()); | ||||||
| 	} | 	} | ||||||
| 	raw->setActive(_session->activeChatsFilterCurrent() == id); | 	raw->setActive(_session->activeChatsFilterCurrent() == id); | ||||||
|  | @ -325,11 +344,11 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton( | ||||||
| 			openFiltersSettings(); | 			openFiltersSettings(); | ||||||
| 		} | 		} | ||||||
| 	}); | 	}); | ||||||
| 	if (id >= 0) { | 	if (id >= -1) { | ||||||
| 		raw->setAcceptDrops(true); | 		raw->setAcceptDrops(true); | ||||||
| 		raw->events( | 		raw->events( | ||||||
| 		) | rpl::filter([=](not_null<QEvent*> e) { | 		) | rpl::filter([=](not_null<QEvent*> e) { | ||||||
| 			return ((e->type() == QEvent::ContextMenu) && (id >= 0)) | 			return ((e->type() == QEvent::ContextMenu) && (id >= -1)) | ||||||
| 				|| e->type() == QEvent::DragEnter | 				|| e->type() == QEvent::DragEnter | ||||||
| 				|| e->type() == QEvent::DragMove | 				|| e->type() == QEvent::DragMove | ||||||
| 				|| e->type() == QEvent::DragLeave; | 				|| e->type() == QEvent::DragLeave; | ||||||
|  | @ -338,7 +357,11 @@ base::unique_qptr<Ui::SideBarButton> FiltersMenu::prepareButton( | ||||||
| 				return; | 				return; | ||||||
| 			} | 			} | ||||||
| 			if (e->type() == QEvent::ContextMenu) { | 			if (e->type() == QEvent::ContextMenu) { | ||||||
|  | 				if (id == -1) { | ||||||
|  | 					showEditMenu(QCursor::pos()); | ||||||
|  | 				} else if (id > 0) { | ||||||
| 					showMenu(QCursor::pos(), id); | 					showMenu(QCursor::pos(), id); | ||||||
|  | 				} | ||||||
| 			} else if (e->type() == QEvent::DragEnter) { | 			} else if (e->type() == QEvent::DragEnter) { | ||||||
| 				using namespace Storage; | 				using namespace Storage; | ||||||
| 				const auto d = static_cast<QDragEnterEvent*>(e.get()); | 				const auto d = static_cast<QDragEnterEvent*>(e.get()); | ||||||
|  | @ -437,6 +460,30 @@ void FiltersMenu::showMenu(QPoint position, FilterId id) { | ||||||
| 	_popupMenu->popup(position); | 	_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) { | void FiltersMenu::showEditBox(FilterId id) { | ||||||
| 	EditExistingFilter(_session, id); | 	EditExistingFilter(_session, id); | ||||||
| } | } | ||||||
|  |  | ||||||
|  | @ -48,6 +48,7 @@ private: | ||||||
| 		bool toBeginning = false); | 		bool toBeginning = false); | ||||||
| 	void setupMainMenuIcon(); | 	void setupMainMenuIcon(); | ||||||
| 	void showMenu(QPoint position, FilterId id); | 	void showMenu(QPoint position, FilterId id); | ||||||
|  | 	void showEditMenu(QPoint position); | ||||||
| 	void showEditBox(FilterId id); | 	void showEditBox(FilterId id); | ||||||
| 	void showRemoveBox(FilterId id); | 	void showRemoveBox(FilterId id); | ||||||
| 	void remove(FilterId id, std::vector<not_null<PeerData*>> leave = {}); | 	void remove(FilterId id, std::vector<not_null<PeerData*>> leave = {}); | ||||||
|  |  | ||||||
|  | @ -2469,7 +2469,11 @@ not_null<MainWidget*> SessionController::content() const { | ||||||
| } | } | ||||||
| 
 | 
 | ||||||
| int SessionController::filtersWidth() 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 { | rpl::producer<FilterId> SessionController::activeChatsFilter() const { | ||||||
|  |  | ||||||
		Loading…
	
	Add table
		
		Reference in a new issue
	
	 Ilya Fedin
							Ilya Fedin