1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
mod db;
mod header;
mod main;
use header::Header;
use main::Main;
use gtk::{
gio::ActionEntry,
prelude::{ActionMapExtManual, GtkWindowExt},
Application, ApplicationWindow,
};
use std::sync::Arc;
pub struct Browser {
// Extras
// db: db::Browser,
widget: ApplicationWindow,
// Components
header: Arc<Header>,
main: Arc<Main>,
}
impl Browser {
// Construct
pub fn new(
app: &Application,
// connection: Arc<sqlite::Connection>,
default_width: i32,
default_height: i32,
) -> Browser {
// Init components
// let db = db::Browser::new(connection);
let header = Arc::new(header::Header::new());
let main = Arc::new(main::Main::new());
let widget = ApplicationWindow::builder()
.application(app)
.default_width(default_width)
.default_height(default_height)
.titlebar(header.widget())
.child(main.widget())
.build();
// Init actions
widget.add_action_entries([
ActionEntry::builder("update")
.activate({
let header = header.clone();
let main = main.clone();
move |_, _, _| {
main.update();
header.update(main.tab_page_title(), main.tab_page_description());
}
})
.build(),
ActionEntry::builder("debug")
.activate(|this: &ApplicationWindow, _, _| {
this.emit_enable_debugging(true);
})
.build(),
ActionEntry::builder("quit")
.activate(|this: &ApplicationWindow, _, _| {
this.close();
})
.build(),
ActionEntry::builder("tab_append")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_append(None);
}
})
.build(),
ActionEntry::builder("tab_page_reload")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_page_reload();
}
})
.build(),
ActionEntry::builder("tab_close")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close();
}
})
.build(),
ActionEntry::builder("tab_close_all")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_close_all();
}
})
.build(),
ActionEntry::builder("tab_pin")
.activate({
let main = main.clone();
move |_, _, _| {
main.tab_pin();
}
})
.build(),
]);
// Return
Self {
// db,
widget,
header,
main,
}
}
// Getters
pub fn widget(&self) -> &ApplicationWindow {
&self.widget
}
}