Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: FileDialog remember last folder #429

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion src/Dialogs/Composer/AttachmentsPage.vala
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -227,20 +228,36 @@ 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) {
select_multiple = true,
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 ();

Expand Down
19 changes: 18 additions & 1 deletion src/Dialogs/ProfileEdit.vala
Original file line number Diff line number Diff line change
Expand Up @@ -399,26 +399,43 @@ 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 () {
title = _("Open"),
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 {
Expand Down