Skip to content

Commit

Permalink
Edit record pane (no modal)
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Aug 20, 2023
1 parent 67ba42a commit c0809e3
Show file tree
Hide file tree
Showing 8 changed files with 572 additions and 271 deletions.
34 changes: 19 additions & 15 deletions src/main_window.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::cache::Cache;
use crate::config::ConfigService;
use crate::format;
use crate::model::record::{RecordType, RECORD_TYPE_GENERIC};
use crate::model::record::{Record, RecordType, RECORD_TYPE_GENERIC};
use crate::model::tree::RecordNode;
use crate::model::tree::RecordTree;
use crate::ui;
Expand All @@ -10,7 +10,6 @@ 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::say::say_error;
use crate::ui::edit_record::edit_record;
use crate::ui::forms::entry::form_password_entry;
use crate::ui::open_file::OpenFile;
use crate::ui::search::SearchEvent;
Expand All @@ -37,6 +36,7 @@ pub struct OpenedFile {

mod imp {
use super::*;
use crate::ui::edit_record::edit_record_pane::EditRecordPane;
use crate::ui::file_pane::FilePane;
use crate::ui::search::PSSearchBar;
use crate::ui::toast::Toast;
Expand All @@ -60,6 +60,7 @@ mod imp {
pub open_file: OpenFile,
pub search_bar: PSSearchBar,
pub file_pane: FilePane,
pub edit_record_pane: EditRecordPane,

pub delete_handler: RefCell<Option<glib::signal::SignalHandlerId>>,

Expand Down Expand Up @@ -138,6 +139,7 @@ mod imp {
.add_named(&self.dashboard.get_widget(), Some("dashboard"));
self.stack.add_named(&self.open_file, Some("open_file"));
self.stack.add_named(&main_pane, Some("file"));
self.stack.add_named(&self.edit_record_pane, Some("edit"));

let overlay = overlayed(&self.stack, &self.toast.as_widget());
win.set_child(Some(&overlay));
Expand Down Expand Up @@ -516,12 +518,7 @@ impl PSMainWindow {
let record_type = RecordType::find(&record_type_name).unwrap_or(&*RECORD_TYPE_GENERIC);

let empty_record = record_type.new_record();
let Some(new_record) = edit_record(
&empty_record,
self.upcast_ref(),
"Add record",
self.get_usernames(),
).await else { return };
let Some(new_record) = self.edit_record(&empty_record).await else { return };

let record_node = if new_record.record_type.is_group {
RecordNode::group(new_record, &Default::default())
Expand All @@ -534,14 +531,21 @@ impl PSMainWindow {
}

impl PSMainWindow {
async fn edit_record(&self, record: &Record) -> Option<Record> {
self.imp().stack.set_visible_child_name("edit");
let result = self
.imp()
.edit_record_pane
.run(record, self.get_usernames())
.await;
self.imp().stack.set_visible_child_name("file");
pending().await;
self.imp().file_pane.grab_focus_to_view();
result
}

async fn action_edit(&self, position: u32, record_node: RecordNode) {
let Some(new_record) = edit_record(
record_node.record(),
self.upcast_ref(),
"Edit record",
self.get_usernames(),
)
.await else { return };
let Some(new_record) = self.edit_record(record_node.record()).await else { return };

self.imp()
.file_pane
Expand Down
255 changes: 0 additions & 255 deletions src/ui/edit_record.rs

This file was deleted.

Loading

0 comments on commit c0809e3

Please sign in to comment.