Skip to content

Commit

Permalink
Extract record context menu into an own module
Browse files Browse the repository at this point in the history
  • Loading branch information
andy128k committed Nov 20, 2023
1 parent 20adb96 commit 8f66e1a
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 40 deletions.
43 changes: 3 additions & 40 deletions src/ui/file_pane.rs
Original file line number Diff line number Diff line change
@@ -1,13 +1,11 @@
use crate::model::record::Record;
use crate::model::tree::{RecordNode, RecordTree};
use crate::primary_accel;
use crate::ui::dialogs::say::say;
use crate::ui::group_selector::select_group;
use crate::ui::nav_bar::PSNavBar;
use crate::ui::record_view::view::PSRecordView;
use crate::utils::menu_builder::*;
use awesome_gtk::prelude::BitSetIterExt;
use gtk::{gio, glib, prelude::*, subclass::prelude::*};
use gtk::{glib, prelude::*, subclass::prelude::*};
use std::cell::Ref;

const ACTION_COPY_NAME: &str = "copy-name";
Expand All @@ -25,6 +23,7 @@ mod imp {
use super::*;
use crate::model::record::RECORD_TYPES;
use crate::primary_accel;
use crate::ui::record_context_menu::record_context_menu;
use crate::ui::record_type_popover::RecordTypePopoverBuilder;
use crate::ui::record_view::item::DropOption;
use crate::utils::typed_list_store::TypedListStore;
Expand Down Expand Up @@ -77,7 +76,7 @@ mod imp {
obj.set_layout_manager(Some(gtk::BinLayout::new()));

self.view.set_vexpand(true);
self.view.set_popup(&create_popup());
self.view.set_popup(&record_context_menu());

let action_bar = gtk::ActionBar::builder().hexpand(true).build();
action_bar.pack_start(&action_popover_button(
Expand Down Expand Up @@ -586,39 +585,3 @@ impl FilePane {
)
}
}

fn create_popup() -> gio::MenuModel {
gio::Menu::new()
.section(
gio::Menu::new()
.item(
gio::MenuItem::create()
.action(ACTION_COPY_NAME)
.label("Copy _name")
.accel(primary_accel!("c")),
)
.item(
gio::MenuItem::create()
.action(ACTION_COPY_PASSWORD)
.label("Copy pass_word")
.accel(primary_accel!("<Shift>c")),
),
)
.section(
gio::Menu::new().item(
gio::MenuItem::create()
.action(ACTION_MOVE)
.label("_Move to..."),
),
)
.section(
gio::Menu::new()
.item(gio::MenuItem::create().action(ACTION_EDIT).label("_Edit"))
.item(
gio::MenuItem::create()
.action(ACTION_DELETE)
.label("_Delete"),
),
)
.upcast()
}
1 change: 1 addition & 0 deletions src/ui/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ pub mod nav_bar;
pub mod open_file;
pub mod password_editor;
pub mod password_strength_bar;
pub mod record_context_menu;
pub mod record_type_popover;
pub mod record_view;
pub mod search;
Expand Down
45 changes: 45 additions & 0 deletions src/ui/record_context_menu.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
use crate::primary_accel;
use crate::utils::menu_builder::*;
use gtk::{gio, prelude::*};

const ACTION_COPY_NAME: &str = "copy-name";
const ACTION_COPY_PASSWORD: &str = "copy-password";
const ACTION_MOVE: &str = "move";
const ACTION_EDIT: &str = "edit";
const ACTION_DELETE: &str = "delete";

pub fn record_context_menu() -> gio::MenuModel {
gio::Menu::new()
.section(
gio::Menu::new()
.item(
gio::MenuItem::create()
.action(ACTION_COPY_NAME)
.label("Copy _name")
.accel(primary_accel!("c")),
)
.item(
gio::MenuItem::create()
.action(ACTION_COPY_PASSWORD)
.label("Copy pass_word")
.accel(primary_accel!("<Shift>c")),
),
)
.section(
gio::Menu::new().item(
gio::MenuItem::create()
.action(ACTION_MOVE)
.label("_Move to..."),
),
)
.section(
gio::Menu::new()
.item(gio::MenuItem::create().action(ACTION_EDIT).label("_Edit"))
.item(
gio::MenuItem::create()
.action(ACTION_DELETE)
.label("_Delete"),
),
)
.upcast()
}

0 comments on commit 8f66e1a

Please sign in to comment.