main_view.rs (5271B)
1 use crate::folder_view::{FolderInit, MailboxInit, MailboxesInit, MailboxesView}; 2 use gtk::prelude::*; 3 use relm4::actions::{RelmAction, RelmActionGroup}; 4 use relm4::prelude::*; 5 use std::convert::identity; 6 7 use self::about_dialog::AboutWindow; 8 9 mod about_dialog; 10 11 pub struct MainView { 12 mailboxes: Controller<MailboxesView>, 13 about_view: Controller<AboutWindow>, 14 } 15 16 #[derive(Debug)] 17 pub enum Msg {} 18 19 #[relm4::component(pub)] 20 impl Component for MainView { 21 type Init = (); 22 type Input = (); 23 type Output = (); 24 type CommandOutput = Msg; 25 26 view! { 27 #[root] 28 main_window = gtk::Box { 29 set_orientation: gtk::Orientation::Vertical, 30 set_halign: gtk::Align::Fill, 31 set_valign: gtk::Align::Fill, 32 33 gtk::Box { 34 set_halign: gtk::Align::Fill, 35 set_valign: gtk::Align::Baseline, 36 37 gtk::Button { 38 set_margin_all: 8, 39 set_label: "Sync" 40 }, 41 42 gtk::Button { 43 set_margin_all: 8, 44 set_label: "Write" 45 }, 46 47 gtk::MenuButton { 48 set_margin_all: 8, 49 set_halign: gtk::Align::End, 50 set_hexpand: true, 51 set_icon_name: "settings-symbolic", 52 #[wrap(Some)] 53 set_popover = >k::PopoverMenu::from_model(Some(&settings_menu)) {}, 54 } 55 }, 56 57 gtk::Separator {}, 58 59 gtk::Box { 60 set_orientation: gtk::Orientation::Horizontal, 61 set_halign: gtk::Align::Fill, 62 set_valign: gtk::Align::Fill, 63 set_vexpand: true, 64 set_hexpand: true, 65 66 gtk::Paned { 67 set_position: 200, 68 set_shrink_start_child: false, 69 set_shrink_end_child: false, 70 set_hexpand: true, 71 #[wrap(Some)] 72 set_start_child = model.mailboxes.widget(), 73 74 #[wrap(Some)] 75 set_end_child = >k::Paned { 76 set_orientation: gtk::Orientation::Vertical, 77 set_halign: gtk::Align::Fill, 78 set_valign: gtk::Align::Fill, 79 set_shrink_start_child: false, 80 set_shrink_end_child: false, 81 set_position: 300, 82 83 #[wrap(Some)] 84 set_start_child = >k::ScrolledWindow { 85 set_hscrollbar_policy: gtk::PolicyType::Never, 86 87 }, 88 #[wrap(Some)] 89 set_end_child = >k::Box { 90 add_css_class: "main", 91 set_margin_all: 8, 92 set_halign: gtk::Align::Start, 93 set_valign: gtk::Align::Start, 94 set_spacing: 8, 95 96 gtk::Label { 97 set_label: "test2" 98 } 99 } 100 } 101 }, 102 } 103 } 104 } 105 106 // Settingsmenu 107 menu! { 108 settings_menu: { 109 "About" => AboutAction, 110 } 111 } 112 113 fn init( 114 _: Self::Init, 115 root: &Self::Root, 116 sender: ComponentSender<Self>, 117 ) -> ComponentParts<Self> { 118 let mailboxes = MailboxesView::builder() 119 .launch(MailboxesInit { 120 mailboxes: vec![MailboxInit { 121 icon_name: String::from("mail-symbolic"), 122 mailbox_name: String::from("dont@dox.myself"), 123 folders: vec![FolderInit { 124 icon_name: String::from("inbox-symbolic"), 125 folder_name: String::from("Inbox"), 126 depth: 1, 127 }], 128 }], 129 }) 130 .forward(sender.input_sender(), identity); 131 132 let about_view = AboutWindow::builder() 133 .transient_for(root) 134 .launch(()) 135 .detach(); 136 137 let model = MainView { 138 mailboxes, 139 about_view, 140 }; 141 let widgets = view_output!(); 142 143 let group = RelmActionGroup::<WindowActionGroup>::new(); 144 let action: RelmAction<AboutAction> = { 145 let sender = model.about_view.sender().clone(); 146 RelmAction::new_stateless(move |_| { 147 sender.send(()).unwrap(); 148 }) 149 }; 150 group.add_action(&action); 151 152 let actions = group.into_action_group(); 153 widgets 154 .main_window 155 .insert_action_group("win", Some(&actions)); 156 157 ComponentParts { model, widgets } 158 } 159 } 160 161 relm4::new_action_group!(WindowActionGroup, "win"); 162 relm4::new_stateless_action!(AboutAction, WindowActionGroup, "about");