From 61ac9375b4a35878576ac2727c5210cd9fc51a92 Mon Sep 17 00:00:00 2001 From: Nathan Reiner Date: Wed, 26 Jul 2023 21:19:59 +0200 Subject: add gtk3 gui --- src/gui/load.rs | 63 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 63 insertions(+) create mode 100644 src/gui/load.rs (limited to 'src/gui/load.rs') diff --git a/src/gui/load.rs b/src/gui/load.rs new file mode 100644 index 0000000..e075d0f --- /dev/null +++ b/src/gui/load.rs @@ -0,0 +1,63 @@ +use gtk::glib; +use gtk::prelude::*; +use super::state::{View, ViewManager}; +use std::rc::Rc; + +use crate::index::Index; + +pub struct Load { + vm : Rc +} + +impl View for Load { + fn name(&self) -> &str { + "load" + } + + fn set_vm(&mut self, vm : Rc) { + self.vm = vm + } + + fn make_current(&self) -> Option { + let vm = Rc::clone(&self.vm); + glib::MainContext::default().spawn_local(async move { + let dialog = gtk::FileChooserDialog::builder() + .action(gtk::FileChooserAction::Open) + .transient_for(vm.get_window()) + .title("Open Index File") + .build(); + + dialog.add_button("Choose", gtk::ResponseType::Accept); + + let _ = dialog.run_future().await; + dialog.close(); + dialog.hide(); + + if let Some(uri) = dialog.uri() { + let splash = gtk::Window::new(gtk::WindowType::Popup); + splash.set_type_hint(gtk::gdk::WindowTypeHint::Splashscreen); + splash.set_decorated(false); + splash.set_position(gtk::WindowPosition::Center); + splash.set_resizable(false); + splash.set_size_request(300, 200); + splash.add(>k::Label::new(Some("Loading"))); + splash.show_all(); + let path = uri.trim_start_matches("file://").to_string(); + let index = Index::from_file(&path); + vm.set_index(index); + vm.set_current_view("search"); + splash.close(); + } else { + vm.set_current_view("welcome"); + } + }); + + None + } +} + +impl Load { + pub fn new() -> Self { + Self { vm : Rc::new(ViewManager::empty()) } + } +} -- cgit v1.2.3-70-g09d2