Move create theme button to three-dot menu.

This commit is contained in:
John Preston 2019-09-08 15:47:22 +03:00
parent f9b2a8d6ac
commit 95da2dbc34
4 changed files with 64 additions and 48 deletions

View File

@ -408,7 +408,8 @@ void WrapWidget::createTopBar() {
addProfileCallsButton();
// addProfileNotificationsButton();
} else if (section.type() == Section::Type::Settings
&& section.settingsType() == Section::SettingsType::Main) {
&& (section.settingsType() == Section::SettingsType::Main
|| section.settingsType() == Section::SettingsType::Chat)) {
addTopBarMenuButton();
} else if (section.type() == Section::Type::Settings
&& section.settingsType() == Section::SettingsType::Information) {
@ -586,7 +587,11 @@ void WrapWidget::showTopBarMenu() {
_topBarMenu = nullptr;
controller->showSettings(type);
};
::Settings::FillMenu(&self->session(), showOther, addAction);
::Settings::FillMenu(
_controller->parentController(),
_controller->section().settingsType(),
showOther,
addAction);
} else {
_topBarMenu = nullptr;
return;

View File

@ -1161,53 +1161,20 @@ void SetupThemeOptions(
AddSkip(container, st::settingsThemesTopSkip);
SetupDefaultThemes(container);
AddSkip(container, st::settingsThemesBottomSkip);
const auto canEditCurrent = [=] {
const auto userId = controller->session().userId();
return (Background()->themeObject().cloud.createdBy == userId);
};
auto canEdit = rpl::single(BackgroundUpdate(
BackgroundUpdate::Type::ApplyingTheme,
Background()->tile()
)) | rpl::then(base::ObservableViewer(
*Background()
)) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}) | rpl::map([=] {
return canEditCurrent();
});
AddButton(
container,
rpl::conditional(
std::move(canEdit),
tr::lng_settings_bg_theme_edit(),
tr::lng_settings_bg_theme_create()),
st::settingsChatButton,
&st::settingsIconThemes,
st::settingsChatIconLeft
)->addClickHandler([=] {
if (canEditCurrent()) {
StartEditor(
&controller->window(),
Background()->themeObject().cloud);
} else {
controller->window().show(Box(CreateBox, &controller->window()));
}
});
AddSkip(container);
}
void SetupCloudThemes(
not_null<Window::SessionController*> controller,
not_null<Ui::VerticalLayout*> container) {
using namespace Window::Theme;
using namespace rpl::mappers;
const auto wrap = container->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
container,
object_ptr<Ui::VerticalLayout>(container)));
object_ptr<Ui::VerticalLayout>(container))
)->setDuration(0);
const auto inner = wrap->entity();
AddDivider(inner);
@ -1233,7 +1200,7 @@ void SetupCloudThemes(
AddSkip(inner, st::settingsThemesTopSkip);
const auto list = inner->lifetime().make_state<Window::Theme::CloudList>(
const auto list = inner->lifetime().make_state<CloudList>(
inner,
controller);
inner->add(
@ -1253,7 +1220,39 @@ void SetupCloudThemes(
list->showAll();
});
AddSkip(inner, st::settingsThemesTopSkip);
const auto editWrap = inner->add(
object_ptr<Ui::SlideWrap<Ui::VerticalLayout>>(
inner,
object_ptr<Ui::VerticalLayout>(inner))
)->setDuration(0);
const auto edit = editWrap->entity();
AddSkip(edit, st::settingsThemesBottomSkip);
AddButton(
edit,
tr::lng_settings_bg_theme_edit(),
st::settingsChatButton,
&st::settingsIconThemes,
st::settingsChatIconLeft
)->addClickHandler([=] {
StartEditor(
&controller->window(),
Background()->themeObject().cloud);
});
editWrap->toggleOn(rpl::single(BackgroundUpdate(
BackgroundUpdate::Type::ApplyingTheme,
Background()->tile()
)) | rpl::then(base::ObservableViewer(
*Background()
)) | rpl::filter([](const BackgroundUpdate &update) {
return (update.type == BackgroundUpdate::Type::ApplyingTheme);
}) | rpl::map([=] {
const auto userId = controller->session().userId();
return (Background()->themeObject().cloud.createdBy == userId);
}));
AddSkip(inner, 2 * st::settingsSectionSkip);
wrap->setDuration(0)->toggleOn(list->empty() | rpl::map(!_1));
}

View File

@ -19,6 +19,9 @@ https://github.com/telegramdesktop/tdesktop/blob/master/LEGAL
#include "ui/widgets/labels.h"
#include "info/profile/info_profile_button.h"
#include "boxes/abstract_box.h"
#include "window/themes/window_theme_editor_box.h"
#include "window/window_session_controller.h"
#include "window/window_controller.h"
#include "lang/lang_keys.h"
#include "mainwindow.h"
#include "main/main_session.h"
@ -170,17 +173,25 @@ not_null<Ui::FlatLabel*> AddSubsectionTitle(
}
void FillMenu(
not_null<::Main::Session*> session,
not_null<Window::SessionController*> controller,
Type type,
Fn<void(Type)> showOther,
MenuCallback addAction) {
if (!session->supportMode()) {
const auto window = &controller->window();
if (type == Type::Chat) {
addAction(
tr::lng_settings_information(tr::now),
[=] { showOther(Type::Information); });
tr::lng_settings_bg_theme_create(tr::now),
[=] { window->show(Box(Window::Theme::CreateBox, window)); });
} else {
if (!controller->session().supportMode()) {
addAction(
tr::lng_settings_information(tr::now),
[=] { showOther(Type::Information); });
}
addAction(
tr::lng_settings_logout(tr::now),
[=] { window->widget()->onLogout(); });
}
addAction(
tr::lng_settings_logout(tr::now),
[=] { App::wnd()->onLogout(); });
}
} // namespace Settings

View File

@ -100,7 +100,8 @@ using MenuCallback = Fn<QAction*(
Fn<void()> handler)>;
void FillMenu(
not_null<::Main::Session*> session,
not_null<Window::SessionController*> controller,
Type type,
Fn<void(Type)> showOther,
MenuCallback addAction);