app: get_file_from_dialog restricts to .gps ext

This commit is contained in:
Stéphane Cerveau 2024-10-18 18:29:04 +02:00
parent 2828930823
commit f7efe807a3

View file

@ -11,8 +11,8 @@ use gtk::gdk;
use gtk::prelude::*; use gtk::prelude::*;
use gtk::{gio, gio::SimpleAction, glib, graphene}; use gtk::{gio, gio::SimpleAction, glib, graphene};
use gtk::{ use gtk::{
Application, ApplicationWindow, Builder, Button, FileChooserAction, FileChooserDialog, Paned, Application, ApplicationWindow, Builder, Button, FileChooserAction, FileChooserDialog,
PopoverMenu, ResponseType, Statusbar, Widget, FileFilter, Paned, PopoverMenu, ResponseType, Statusbar, Widget,
}; };
use log::error; use log::error;
use std::cell::{Cell, RefCell}; use std::cell::{Cell, RefCell};
@ -381,6 +381,13 @@ impl GPSApp {
(cancel_button, ResponseType::Cancel), (cancel_button, ResponseType::Cancel),
], ],
); );
if save {
file_chooser.set_current_name("untitled.gps");
}
let filter = FileFilter::new();
filter.add_pattern("*.gps");
filter.set_name(Some("GPS Files (*.gps)"));
file_chooser.add_filter(&filter);
let app_weak = app.downgrade(); let app_weak = app.downgrade();
file_chooser.connect_response(move |d: &FileChooserDialog, response: ResponseType| { file_chooser.connect_response(move |d: &FileChooserDialog, response: ResponseType| {
let app = upgrade_weak!(app_weak); let app = upgrade_weak!(app_weak);