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("always_show_top_userpic"), cShowTopBarUserpic());
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("use_telegram_panel_icon"), cUseTelegramPanelIcon());
settings.insert(qsl("custom_app_icon"), cCustomAppIcon());
@@ -621,7 +621,7 @@ bool Manager::readCustomFile() {
const auto typedValue = Platform::FileDialog::ImplementationType(v);
if (typedValue >= Platform::FileDialog::ImplementationType::Default
&& typedValue < Platform::FileDialog::ImplementationType::Count) {
cSetFileDialogType(typedValue);
SetFileDialogType(typedValue);
}
});

View File

@@ -148,7 +148,21 @@ rpl::producer<int> RecentStickersLimitChanges() {
int gUserpicCornersType = 3;
bool gShowTopBarUserpic = 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 gUseTelegramPanelIcon = false;
int gCustomAppIcon = 0;

View File

@@ -104,7 +104,11 @@ void SetRecentStickersLimit(int limit);
DeclareSetting(int, UserpicCornersType);
DeclareSetting(bool, ShowTopBarUserpic);
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, UseTelegramPanelIcon);
DeclareSetting(int, CustomAppIcon);

View File

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

View File

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

View File

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