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..8bc29d43e 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,35 @@ 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 {