From 3eff473554c3a69ebc1ccf7a5fd18d75693af8e3 Mon Sep 17 00:00:00 2001 From: Evangelos Paterakis Date: Fri, 4 Aug 2023 23:47:49 +0300 Subject: [PATCH 1/2] feat: FileDialog remember last folder --- src/Dialogs/Composer/AttachmentsPage.vala | 19 ++++++++++++++++++- src/Dialogs/ProfileEdit.vala | 20 +++++++++++++++++++- 2 files changed, 37 insertions(+), 2 deletions(-) diff --git a/src/Dialogs/Composer/AttachmentsPage.vala b/src/Dialogs/Composer/AttachmentsPage.vala index ab5ecd92d..9c03620d4 100644 --- a/src/Dialogs/Composer/AttachmentsPage.vala +++ b/src/Dialogs/Composer/AttachmentsPage.vala @@ -201,6 +201,7 @@ public class Tuba.AttachmentsPage : ComposerPage { } } + File? last_used_folder; void show_file_selector () { var filter = new FileFilter () { name = _("All Supported Files") @@ -227,9 +228,15 @@ public class Tuba.AttachmentsPage : ComposerPage { modal = true, default_filter = filter }; + + if (!Tuba.is_flatpak && last_used_folder != null) + chooser.initial_folder = last_used_folder; + chooser.open_multiple.begin (dialog, null, (obj, res) => { try { - var files = chooser.open_multiple.end (res); + var files = chooser.open_multiple.end (res); + if (!Tuba.is_flatpak && files.get_n_items () > 0) + last_used_folder = ((File) files.get_item (0)).get_parent (); #else // translators: Open file var chooser = new FileChooserNative (_("Open"), dialog, Gtk.FileChooserAction.OPEN, null, null) { @@ -237,10 +244,20 @@ public class Tuba.AttachmentsPage : ComposerPage { filter = filter }; + if (!Tuba.is_flatpak && last_used_folder != null) { + try { + chooser.set_current_folder (last_used_folder); + } catch { + last_used_folder = null; + } + } + chooser.response.connect (id => { switch (id) { case ResponseType.ACCEPT: var files = chooser.get_files (); + if (!Tuba.is_flatpak) + last_used_folder = chooser.get_current_folder (); #endif var selected_files_amount = files.get_n_items (); diff --git a/src/Dialogs/ProfileEdit.vala b/src/Dialogs/ProfileEdit.vala index fe93ce525..2b0f5ef50 100644 --- a/src/Dialogs/ProfileEdit.vala +++ b/src/Dialogs/ProfileEdit.vala @@ -399,6 +399,7 @@ public class Tuba.Dialogs.ProfileEdit : Adw.Window { File new_avi; File new_header; + File? last_used_folder; void choose_file (bool for_header = false) { #if GTK_4_10 var chooser = new Gtk.FileDialog () { @@ -406,19 +407,36 @@ public class Tuba.Dialogs.ProfileEdit : Adw.Window { modal = true, default_filter = filter }; + + if (!Tuba.is_flatpak && last_used_folder != null) + chooser.initial_folder = last_used_folder; + chooser.open.begin (this, null, (obj, res) => { try { - var file = chooser.open.end (res); + var file = chooser.open.end (res); + if (!Tuba.is_flatpak) + last_used_folder = file.get_parent (); #else var chooser = new Gtk.FileChooserNative (_("Open"), this, Gtk.FileChooserAction.OPEN, null, null) { select_multiple = false, filter = filter }; + if (!Tuba.is_flatpak && last_used_folder != null) { + try { + chooser.set_current_folder (last_used_folder); + } catch { + last_used_folder = null; + } + } + + chooser.response.connect (id => { switch (id) { case Gtk.ResponseType.ACCEPT: var file = chooser.get_file (); + if (!Tuba.is_flatpak) + last_used_folder = chooser.get_current_folder (); #endif try { From 05ab00d04b48d5531c0f2f68e756d0a7e8a23479 Mon Sep 17 00:00:00 2001 From: Evangelos Paterakis Date: Fri, 4 Aug 2023 23:57:39 +0300 Subject: [PATCH 2/2] chore: lint --- src/Dialogs/ProfileEdit.vala | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Dialogs/ProfileEdit.vala b/src/Dialogs/ProfileEdit.vala index 2b0f5ef50..8bc29d43e 100644 --- a/src/Dialogs/ProfileEdit.vala +++ b/src/Dialogs/ProfileEdit.vala @@ -429,7 +429,6 @@ public class Tuba.Dialogs.ProfileEdit : Adw.Window { last_used_folder = null; } } - chooser.response.connect (id => { switch (id) {