[fractal] file dialog: add a common filepicker dialog
- From: Jordan Petridis <jpetridis src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [fractal] file dialog: add a common filepicker dialog
- Date: Wed, 9 Jan 2019 18:37:19 +0000 (UTC)
commit 985782b3b313a49a4074f4dbcf06b9e18ddf69a5
Author: Julian Sparber <julian sparber net>
Date: Fri Dec 28 15:24:30 2018 +0100
file dialog: add a common filepicker dialog
fractal-gtk/po/POTFILES.in | 1 +
fractal-gtk/src/widgets/file_dialog.rs | 39 ++++++++++++++++++++++++++++++++++
fractal-gtk/src/widgets/mod.rs | 2 ++
3 files changed, 42 insertions(+)
---
diff --git a/fractal-gtk/po/POTFILES.in b/fractal-gtk/po/POTFILES.in
index 90100879..aa37da14 100644
--- a/fractal-gtk/po/POTFILES.in
+++ b/fractal-gtk/po/POTFILES.in
@@ -84,6 +84,7 @@ fractal-gtk/src/widgets/autocomplete.rs
fractal-gtk/src/widgets/avatar.rs
fractal-gtk/src/widgets/divider.rs
fractal-gtk/src/widgets/error_dialog.rs
+fractal-gtk/src/widgets/file_dialog.rs
fractal-gtk/src/widgets/image.rs
fractal-gtk/src/widgets/inline_player.rs
fractal-gtk/src/widgets/media_viewer.rs
diff --git a/fractal-gtk/src/widgets/file_dialog.rs b/fractal-gtk/src/widgets/file_dialog.rs
new file mode 100644
index 00000000..bf14209b
--- /dev/null
+++ b/fractal-gtk/src/widgets/file_dialog.rs
@@ -0,0 +1,39 @@
+use gtk;
+use gtk::prelude::*;
+use gtk::ResponseType;
+use i18n::i18n;
+use std::path::PathBuf;
+
+pub fn save(parent: >k::Window, title: &str) -> Option<PathBuf> {
+ let file_chooser = gtk::FileChooserNative::new(
+ Some(i18n("Save media as").as_str()),
+ Some(parent),
+ gtk::FileChooserAction::Save,
+ Some(i18n("_Save").as_str()),
+ Some(i18n("_Cancel").as_str()),
+ );
+
+ file_chooser.set_current_folder(dirs::download_dir().unwrap_or_default());
+ file_chooser.set_current_name(title);
+ let response = file_chooser.run();
+ if ResponseType::from(response) == ResponseType::Accept {
+ return file_chooser.get_filename();
+ }
+ None
+}
+
+pub fn open(parent: >k::Window, title: &str) -> Option<PathBuf> {
+ let file_chooser = gtk::FileChooserNative::new(
+ Some(title),
+ Some(parent),
+ gtk::FileChooserAction::Open,
+ Some(i18n("_Select").as_str()),
+ Some(i18n("_Cancel").as_str()),
+ );
+
+ let response = file_chooser.run();
+ if gtk::ResponseType::from(response) == gtk::ResponseType::Accept {
+ return file_chooser.get_filename();
+ }
+ None
+}
diff --git a/fractal-gtk/src/widgets/mod.rs b/fractal-gtk/src/widgets/mod.rs
index a81256ea..04c6bbf8 100644
--- a/fractal-gtk/src/widgets/mod.rs
+++ b/fractal-gtk/src/widgets/mod.rs
@@ -3,6 +3,7 @@ mod autocomplete;
pub mod avatar;
mod divider;
pub mod error_dialog;
+pub mod file_dialog;
pub mod image;
mod inline_player;
pub mod media_viewer;
@@ -29,6 +30,7 @@ pub use self::avatar::AvatarData;
pub use self::avatar::AvatarExt;
pub use self::divider::NewMessageDivider;
pub use self::error_dialog as ErrorDialog;
+pub use self::file_dialog as FileDialog;
pub use self::inline_player::AudioPlayerWidget;
pub use self::media_viewer::MediaViewer;
pub use self::member::MemberBox;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]