mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 17:15:28 +00:00
cleanup unused constructions, fix tab state for bookmark action
This commit is contained in:
parent
c511b97d2d
commit
fb8f9904d0
8 changed files with 13 additions and 190 deletions
|
|
@ -1,63 +0,0 @@
|
|||
// @TODO prototype
|
||||
// do not use it as currently profile get auto-generating on application startup!
|
||||
|
||||
mod widget;
|
||||
use gtk::glib::DateTime;
|
||||
use widget::Widget;
|
||||
|
||||
use crate::profile::Profile;
|
||||
use adw::ApplicationWindow;
|
||||
use std::rc::Rc;
|
||||
|
||||
pub struct Welcome {
|
||||
profile: Rc<Profile>,
|
||||
widget: Rc<Widget>,
|
||||
}
|
||||
|
||||
impl Welcome {
|
||||
// Construct
|
||||
|
||||
/// Create new `Self` for given Profile
|
||||
pub fn new(profile: Rc<Profile>, parent: ApplicationWindow) -> Self {
|
||||
// Init widget
|
||||
let widget = Rc::new(Widget::new(parent));
|
||||
|
||||
// Init events
|
||||
widget.connect_response({
|
||||
let profile = profile.clone();
|
||||
move |value| {
|
||||
match value {
|
||||
Some(id) => {
|
||||
// Activate selected profile by record ID
|
||||
let _ = profile.database.activate(id);
|
||||
}
|
||||
None => {
|
||||
// Create and select new profile
|
||||
let _ = profile
|
||||
.database
|
||||
.add(true, DateTime::now_local().unwrap(), None);
|
||||
}
|
||||
} // @TODO handle result
|
||||
}
|
||||
});
|
||||
|
||||
// Return activated `Self`
|
||||
Self { profile, widget }
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Show dialog for parent [Window](https://docs.gtk.org/gtk4/class.Window.html)
|
||||
pub fn present(&self) {
|
||||
// Collect Profile list
|
||||
let mut responses = Vec::new();
|
||||
for record in self.profile.database.records() {
|
||||
responses.push((
|
||||
record.id.to_string(),
|
||||
record.time.format_iso8601().unwrap().to_string(),
|
||||
))
|
||||
}
|
||||
// Show dialog
|
||||
self.widget.present(responses);
|
||||
}
|
||||
}
|
||||
|
|
@ -1,88 +0,0 @@
|
|||
use adw::{
|
||||
prelude::{AdwDialogExt, AlertDialogExt, AlertDialogExtManual},
|
||||
AlertDialog, ApplicationWindow, ResponseAppearance,
|
||||
};
|
||||
use gtk::prelude::GtkWindowExt;
|
||||
use std::cell::RefCell;
|
||||
|
||||
const HEADING: &str = "Welcome!";
|
||||
const BODY: &str = "Select profile for personal data";
|
||||
const RESPONSE_QUIT: (&str, &str) = ("quit", "Quit");
|
||||
const RESPONSE_CREATE: (&str, &str) = ("create", "Create new profile");
|
||||
const RESPONSE_IMPORT: (&str, &str) = ("import", "Import..");
|
||||
|
||||
pub struct Widget {
|
||||
gobject: AlertDialog,
|
||||
parent: ApplicationWindow,
|
||||
responses: RefCell<Vec<String>>, // wanted to cleanup previous preset by key
|
||||
}
|
||||
|
||||
impl Widget {
|
||||
// Constructors
|
||||
|
||||
/// Create new `Self` for [Window](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/1.3/class.ApplicationWindow.html)
|
||||
pub fn new(parent: ApplicationWindow) -> Self {
|
||||
// Init gobject
|
||||
let gobject = AlertDialog::builder()
|
||||
.heading(HEADING)
|
||||
.body(BODY)
|
||||
.close_response(RESPONSE_QUIT.0)
|
||||
.default_response(RESPONSE_CREATE.0)
|
||||
.build();
|
||||
|
||||
// Set response variants
|
||||
gobject.add_responses(&[RESPONSE_QUIT, RESPONSE_CREATE, RESPONSE_IMPORT]);
|
||||
|
||||
// Deactivate not implemented feature @TODO
|
||||
gobject.set_response_enabled(RESPONSE_IMPORT.0, false);
|
||||
|
||||
// Decorate default response preset
|
||||
gobject.set_response_appearance(RESPONSE_CREATE.0, ResponseAppearance::Suggested);
|
||||
gobject.set_response_appearance(RESPONSE_QUIT.0, ResponseAppearance::Destructive);
|
||||
|
||||
// Return new `Self`
|
||||
Self {
|
||||
gobject,
|
||||
parent,
|
||||
responses: RefCell::new(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
// Actions
|
||||
|
||||
/// Wrapper for default [response](https://gnome.pages.gitlab.gnome.org/libadwaita/doc/main/signal.AlertDialog.response.html) signal
|
||||
/// * return profile ID, new record request on `None` or immediately close `self.parent` given on construction
|
||||
pub fn connect_response(&self, callback: impl Fn(Option<i64>) + 'static) {
|
||||
self.gobject.connect_response(None, {
|
||||
let parent = self.parent.clone();
|
||||
move |_, response| match response {
|
||||
id if id == RESPONSE_CREATE.0 => callback(None),
|
||||
id if id == RESPONSE_QUIT.0 => parent.close(),
|
||||
_ => callback(Some(response.parse::<i64>().unwrap())),
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// Show dialog with new profile responses preset
|
||||
pub fn present(&self, profiles: Vec<(String, String)>) {
|
||||
// Borrow current index to update
|
||||
let mut index = self.responses.borrow_mut();
|
||||
|
||||
// Remove previous responses from widget
|
||||
for response in index.iter() {
|
||||
self.gobject.remove_response(response)
|
||||
}
|
||||
|
||||
// Reset index
|
||||
index.clear();
|
||||
|
||||
// Build new preset
|
||||
for (id, label) in profiles {
|
||||
self.gobject.add_response(&id, &label);
|
||||
index.push(id)
|
||||
}
|
||||
|
||||
// Show dialog
|
||||
self.gobject.present(Some(&self.parent))
|
||||
}
|
||||
}
|
||||
|
|
@ -50,6 +50,7 @@ impl Tab {
|
|||
let state = tab_page.map(|this| tab_view.page_position(this));
|
||||
|
||||
// Update actions with new state value
|
||||
action.bookmark().change_state(state);
|
||||
action.close_all().change_state(state);
|
||||
action.close().change_state(state);
|
||||
action.history_back().change_state(state);
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue