add FileDialog filters

This commit is contained in:
yggverse 2024-11-21 14:54:41 +02:00
parent 6cab09f249
commit 782b7be8ba

View File

@ -1,9 +1,9 @@
use super::Action;
use gtk::{
gio::{Cancellable, TlsCertificate},
gio::{Cancellable, ListStore, TlsCertificate},
glib::{gformat, GString},
prelude::{ButtonExt, FileExt, TlsCertificateExt, WidgetExt},
Button, FileDialog, Window,
Button, FileDialog, FileFilter, Window,
};
use std::{cell::RefCell, rc::Rc};
@ -37,7 +37,25 @@ impl File {
let pem = pem.clone();
let update = action.update.clone();
move |_| {
FileDialog::new().open(None::<&Window>, None::<&Cancellable>, {
// Init file filters related with PEM extension
let filters = ListStore::new::<FileFilter>();
let filter_all = FileFilter::new();
filter_all.add_pattern("*.*");
filter_all.set_name(Some("All files"));
filters.append(&filter_all);
let filter_pem = FileFilter::new();
filter_pem.add_mime_type("application/x-x509-ca-cert");
filter_pem.set_name(Some("Certificates (*.pem)"));
filters.append(&filter_pem);
// Init file dialog
FileDialog::builder()
.filters(&filters)
.default_filter(&filter_pem)
.build()
.open(None::<&Window>, None::<&Cancellable>, {
let gobject = gobject.clone();
let pem = pem.clone();
let update = update.clone();