Skip to content

Commit

Permalink
Replace a modal dialog for entering file's password with a sliding pane.
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Aug 6, 2023
1 parent 3df54e4 commit deedbca
Show file tree
Hide file tree
Showing 8 changed files with 296 additions and 95 deletions.
27 changes: 27 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ readme = "README.md"

[dependencies]
once_cell = "1"
futures = "0.3"
os_str_bytes = "6"

rand = "0.8"
Expand Down
32 changes: 22 additions & 10 deletions src/main_window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,10 @@ use crate::ui::dialogs::ask::{confirm_likely, confirm_unlikely};
use crate::ui::dialogs::ask_save::{ask_save, AskSave};
use crate::ui::dialogs::change_password::change_password;
use crate::ui::dialogs::file_chooser;
use crate::ui::dialogs::read_file::read_file;
use crate::ui::dialogs::say::{say_error, say_info};
use crate::ui::edit_record::edit_record;
use crate::ui::group_selector::select_group;
use crate::ui::open_file::OpenFile;
use crate::ui::record_type_popover::RecordTypePopoverBuilder;
use crate::ui::record_view::view::PSRecordView;
use crate::ui::search::{PSSearchBar, SearchEvent, SearchEventType};
Expand Down Expand Up @@ -62,6 +62,8 @@ mod imp {

pub dashboard: PSDashboard,

pub open_file: OpenFile,

pub toast: Toast,
pub search_bar: PSSearchBar,
pub nav_bar: PSNavBar,
Expand Down Expand Up @@ -196,6 +198,7 @@ mod imp {
.set_transition_type(gtk::StackTransitionType::SlideLeftRight);
self.stack
.add_named(&self.dashboard.get_widget(), Some("dashboard"));
self.stack.add_named(&self.open_file, Some("open_file"));
self.stack.add_named(
&overlayed(&tree_container, &self.toast.as_widget()),
Some("file"),
Expand Down Expand Up @@ -517,8 +520,24 @@ impl PSMainWindow {
}
}

async fn load_data(&self, filename: PathBuf) -> Option<(RecordTree, String)> {
self.imp().stack.set_visible_child_name("open_file");

let result = self
.imp()
.open_file
.run(move |password| format::load_file(&filename, password))
.await;

if result.is_none() {
self.imp().stack.set_visible_child_name("dashboard");
}

result
}

pub async fn do_open_file(&self, filename: &Path) {
if let Some((data, password)) = load_data(filename.to_owned(), self.upcast_ref()).await {
if let Some((data, password)) = self.load_data(filename.to_owned()).await {
self.imp().cache.get().unwrap().add_file(filename);

*self.file_mut() = OpenedFile {
Expand Down Expand Up @@ -651,7 +670,7 @@ impl PSMainWindow {

let window = self.upcast_ref();
let Some(filename) = file_chooser::open_file(window).await else { return };
let Some((extra_records, _password)) = load_data(filename, window).await else { return };
let Some((extra_records, _password)) = self.load_data(filename).await else { return };

// TODO: maybe do merge into current folder?
let merged_tree = crate::model::merge_trees::merge_trees(&self.file().data, &extra_records);
Expand Down Expand Up @@ -891,13 +910,6 @@ impl PSMainWindow {
}
}

async fn load_data(filename: PathBuf, parent_window: &gtk::Window) -> Option<(RecordTree, String)> {
read_file(parent_window, move |password| {
format::load_file(&filename, password)
})
.await
}

async fn new_password(parent_window: &gtk::Window) -> Option<String> {
// TODO: ADD confirmation
let mut form = ui::forms::form::Form::new();
Expand Down
1 change: 0 additions & 1 deletion src/ui/dialogs/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ pub mod ask_save;
pub mod change_password;
pub mod file_chooser;
pub mod preferences;
pub mod read_file;
pub mod say;
84 changes: 0 additions & 84 deletions src/ui/dialogs/read_file.rs

This file was deleted.

1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ pub mod forms;
pub mod group_selector;
pub mod menu;
pub mod nav_bar;
pub mod open_file;
pub mod password_editor;
pub mod password_strength_bar;
pub mod record_type_popover;
Expand Down
Loading

0 comments on commit deedbca

Please sign in to comment.