mirror of
https://github.com/YGGverse/Yoda.git
synced 2025-01-15 17:20:08 +00:00
add FileDialog filters
This commit is contained in:
parent
6cab09f249
commit
782b7be8ba
@ -1,9 +1,9 @@
|
|||||||
use super::Action;
|
use super::Action;
|
||||||
use gtk::{
|
use gtk::{
|
||||||
gio::{Cancellable, TlsCertificate},
|
gio::{Cancellable, ListStore, TlsCertificate},
|
||||||
glib::{gformat, GString},
|
glib::{gformat, GString},
|
||||||
prelude::{ButtonExt, FileExt, TlsCertificateExt, WidgetExt},
|
prelude::{ButtonExt, FileExt, TlsCertificateExt, WidgetExt},
|
||||||
Button, FileDialog, Window,
|
Button, FileDialog, FileFilter, Window,
|
||||||
};
|
};
|
||||||
|
|
||||||
use std::{cell::RefCell, rc::Rc};
|
use std::{cell::RefCell, rc::Rc};
|
||||||
@ -37,7 +37,25 @@ impl File {
|
|||||||
let pem = pem.clone();
|
let pem = pem.clone();
|
||||||
let update = action.update.clone();
|
let update = action.update.clone();
|
||||||
move |_| {
|
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 gobject = gobject.clone();
|
||||||
let pem = pem.clone();
|
let pem = pem.clone();
|
||||||
let update = update.clone();
|
let update = update.clone();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user