2
0
mirror of https://github.com/kotatogram/kotatogram-desktop synced 2025-08-31 14:45:14 +00:00

Update file dialog option value in menu after selection

This commit is contained in:
RadRussianRus
2021-04-01 07:23:53 +03:00
parent 602961e70a
commit f55e38ca9d
6 changed files with 37 additions and 11 deletions

View File

@@ -370,7 +370,7 @@ QByteArray GenerateSettingsJson(bool areDefault = false) {
settings.insert(qsl("userpic_corner_type"), cUserpicCornersType()); settings.insert(qsl("userpic_corner_type"), cUserpicCornersType());
settings.insert(qsl("always_show_top_userpic"), cShowTopBarUserpic()); settings.insert(qsl("always_show_top_userpic"), cShowTopBarUserpic());
settings.insert(qsl("gtk_integration"), cGtkIntegration()); settings.insert(qsl("gtk_integration"), cGtkIntegration());
settings.insert(qsl("file_dialog_type"), int(cFileDialogType())); settings.insert(qsl("file_dialog_type"), int(FileDialogType()));
settings.insert(qsl("disable_tray_counter"), cDisableTrayCounter()); settings.insert(qsl("disable_tray_counter"), cDisableTrayCounter());
settings.insert(qsl("use_telegram_panel_icon"), cUseTelegramPanelIcon()); settings.insert(qsl("use_telegram_panel_icon"), cUseTelegramPanelIcon());
settings.insert(qsl("custom_app_icon"), cCustomAppIcon()); settings.insert(qsl("custom_app_icon"), cCustomAppIcon());
@@ -621,7 +621,7 @@ bool Manager::readCustomFile() {
const auto typedValue = Platform::FileDialog::ImplementationType(v); const auto typedValue = Platform::FileDialog::ImplementationType(v);
if (typedValue >= Platform::FileDialog::ImplementationType::Default if (typedValue >= Platform::FileDialog::ImplementationType::Default
&& typedValue < Platform::FileDialog::ImplementationType::Count) { && typedValue < Platform::FileDialog::ImplementationType::Count) {
cSetFileDialogType(typedValue); SetFileDialogType(typedValue);
} }
}); });

View File

@@ -148,7 +148,21 @@ rpl::producer<int> RecentStickersLimitChanges() {
int gUserpicCornersType = 3; int gUserpicCornersType = 3;
bool gShowTopBarUserpic = false; bool gShowTopBarUserpic = false;
bool gGtkIntegration = false; bool gGtkIntegration = false;
Platform::FileDialog::ImplementationType gFileDialogType = Platform::FileDialog::ImplementationType::Default;
rpl::variable<Platform::FileDialog::ImplementationType> gFileDialogType = Platform::FileDialog::ImplementationType::Default;
void SetFileDialogType(Platform::FileDialog::ImplementationType t) {
if (t == Platform::FileDialog::ImplementationType::Count) {
t = Platform::FileDialog::ImplementationType::Default;
}
gFileDialogType = t;
}
Platform::FileDialog::ImplementationType FileDialogType() {
return gFileDialogType.current();
}
rpl::producer<Platform::FileDialog::ImplementationType> FileDialogTypeChanges() {
return gFileDialogType.changes();
}
bool gDisableTrayCounter = Platform::IsLinux(); bool gDisableTrayCounter = Platform::IsLinux();
bool gUseTelegramPanelIcon = false; bool gUseTelegramPanelIcon = false;
int gCustomAppIcon = 0; int gCustomAppIcon = 0;

View File

@@ -104,7 +104,11 @@ void SetRecentStickersLimit(int limit);
DeclareSetting(int, UserpicCornersType); DeclareSetting(int, UserpicCornersType);
DeclareSetting(bool, ShowTopBarUserpic); DeclareSetting(bool, ShowTopBarUserpic);
DeclareSetting(bool, GtkIntegration); DeclareSetting(bool, GtkIntegration);
DeclareSetting(Platform::FileDialog::ImplementationType, FileDialogType);
void SetFileDialogType(Platform::FileDialog::ImplementationType t);
[[nodiscard]] Platform::FileDialog::ImplementationType FileDialogType();
[[nodiscard]] rpl::producer<Platform::FileDialog::ImplementationType> FileDialogTypeChanges();
DeclareSetting(bool, DisableTrayCounter); DeclareSetting(bool, DisableTrayCounter);
DeclareSetting(bool, UseTelegramPanelIcon); DeclareSetting(bool, UseTelegramPanelIcon);
DeclareSetting(int, CustomAppIcon); DeclareSetting(int, CustomAppIcon);

View File

@@ -472,20 +472,28 @@ void SetupKotatoSystem(
#endif // !DESKTOP_APP_DISABLE_GTK_INTEGRATION #endif // !DESKTOP_APP_DISABLE_GTK_INTEGRATION
if (Platform::IsLinux()) { if (Platform::IsLinux()) {
auto fileDialogTypeText = rpl::single(
rpl::empty_value()
) | rpl::then(
FileDialogTypeChanges()
) | rpl::map([] {
return FileDialogTypeLabel(int(cFileDialogType()));
});
AddButtonWithLabel( AddButtonWithLabel(
container, container,
tr::ktg_settings_file_dialog_type(), tr::ktg_settings_file_dialog_type(),
rpl::single(FileDialogTypeLabel(int(cFileDialogType()))), fileDialogTypeText,
st::settingsButton st::settingsButton
)->addClickHandler([=] { )->addClickHandler([=] {
Ui::show(Box<::Kotato::RadioBox>( Ui::show(Box<::Kotato::RadioBox>(
tr::ktg_settings_file_dialog_type(tr::now), tr::ktg_settings_file_dialog_type(tr::now),
int(cFileDialogType()), int(FileDialogType()),
int(Platform::FileDialog::ImplementationType::Count), int(Platform::FileDialog::ImplementationType::Count),
FileDialogTypeLabel, FileDialogTypeLabel,
FileDialogTypeDescription, FileDialogTypeDescription,
[=](int value) { [=](int value) {
cSetFileDialogType(Platform::FileDialog::ImplementationType(value)); SetFileDialogType(Platform::FileDialog::ImplementationType(value));
::Kotato::JsonSettings::Write(); ::Kotato::JsonSettings::Write();
}, false)); }, false));
}); });

View File

@@ -643,11 +643,11 @@ void GtkFileDialog::setNameFilters(const QStringList &filters) {
bool Use(Type type) { bool Use(Type type) {
if (!Supported() if (!Supported()
|| (cFileDialogType() > ImplementationType::GTK)) { || (FileDialogType() > ImplementationType::GTK)) {
return false; return false;
} }
return (cFileDialogType() == ImplementationType::GTK) return (FileDialogType() == ImplementationType::GTK)
|| DesktopEnvironment::IsGtkBased(); || DesktopEnvironment::IsGtkBased();
} }

View File

@@ -643,8 +643,8 @@ rpl::producer<> XDPFileDialog::rejected() {
bool Use(Type type) { bool Use(Type type) {
const auto shouldUse = [&] { const auto shouldUse = [&] {
const auto setting = cFileDialogType() <= ImplementationType::XDP; const auto setting = FileDialogType() <= ImplementationType::XDP;
const auto forceSetting = cFileDialogType() == ImplementationType::XDP; const auto forceSetting = FileDialogType() == ImplementationType::XDP;
const auto confined = InFlatpak() || InSnap(); const auto confined = InFlatpak() || InSnap();
const auto notGtkBased = !DesktopEnvironment::IsGtkBased(); const auto notGtkBased = !DesktopEnvironment::IsGtkBased();