16
16
#include < karm-ui/scroll.h>
17
17
#include < mdi/alert-decagram.h>
18
18
#include < mdi/arrow-left.h>
19
+ #include < mdi/arrow-right.h>
19
20
#include < mdi/bookmark-outline.h>
20
21
#include < mdi/bookmark.h>
21
22
#include < mdi/button-cursor.h>
@@ -45,18 +46,31 @@ enum struct SidePanel {
45
46
DEVELOPER_TOOLS,
46
47
};
47
48
48
- struct State {
49
+ struct Navigate {
49
50
Mime::Url url;
51
+ Mime::Uti action = Mime::Uti::PUBLIC_OPEN;
52
+ };
53
+
54
+ struct State {
55
+ usize currentIndex = 0 ;
56
+ Vec<Navigate> history;
50
57
Res<Strong<Markup::Document>> dom;
51
58
SidePanel sidePanel = SidePanel::CLOSE;
52
59
InspectState inspect = {};
53
60
61
+ State (Navigate nav, Res<Strong<Markup::Document>> dom)
62
+ : history{nav}, dom{dom} {}
63
+
54
64
bool canGoBack () const {
55
- return false ;
65
+ return currentIndex > 0 ;
56
66
}
57
67
58
68
bool canGoForward () const {
59
- return false ;
69
+ return currentIndex < history.len () - 1 ;
70
+ }
71
+
72
+ Navigate const ¤tUrl () const {
73
+ return history[currentIndex];
60
74
}
61
75
};
62
76
@@ -66,23 +80,43 @@ struct GoBack {};
66
80
67
81
struct GoForward {};
68
82
69
- using Action = Union<Reload, GoBack, GoForward, SidePanel, InspectorAction>;
83
+ using Action = Union<
84
+ Reload,
85
+ GoBack,
86
+ GoForward,
87
+ SidePanel,
88
+ InspectorAction,
89
+ Navigate>;
70
90
71
91
void reduce (State &s, Action a) {
72
92
a.visit (Visitor{
73
93
[&](Reload) {
74
- s.dom = Vaev::Driver::fetchDocument (s.url );
94
+ auto const &object = s.currentUrl ();
95
+ if (object.action == Mime::Uti::PUBLIC_MODIFY) {
96
+ s.dom = Vaev::Driver::viewSource (object.url );
97
+ } else {
98
+ s.dom = Vaev::Driver::fetchDocument (object.url );
99
+ }
75
100
},
76
101
[&](GoBack) {
102
+ s.currentIndex --;
103
+ reduce (s, Reload{});
77
104
},
78
105
[&](GoForward) {
106
+ s.currentIndex ++;
107
+ reduce (s, Reload{});
79
108
},
80
109
[&](SidePanel p) {
81
110
s.sidePanel = p;
82
111
},
83
112
[&](InspectorAction a) {
84
113
s.inspect .apply (a);
85
- }
114
+ },
115
+ [&](Navigate n) {
116
+ s.history .pushBack (n);
117
+ s.currentIndex ++;
118
+ reduce (s, Reload{});
119
+ },
86
120
});
87
121
}
88
122
@@ -109,7 +143,11 @@ Ui::Child mainMenu([[maybe_unused]] State const &s) {
109
143
),
110
144
#ifdef __ck_host__
111
145
Kr::contextMenuItem ([&](auto &n) {
112
- auto res = Sys::launch (Mime::Uti::PUBLIC_OPEN, s.url );
146
+ auto res = Sys::launch ({
147
+ .action = Mime::Uti::PUBLIC_OPEN,
148
+ .objects = {s.currentUrl ().url },
149
+ });
150
+
113
151
if (not res)
114
152
Ui::showDialog (
115
153
n,
@@ -163,17 +201,22 @@ Ui::Child addressBar(Mime::Url const &url) {
163
201
Ui::Child contextMenu (State const &s) {
164
202
return Kr::contextMenuContent ({
165
203
Kr::contextMenuDock ({
166
- Kr::contextMenuIcon (Ui::NOP, Mdi::ARROW_LEFT),
167
- Kr::contextMenuIcon (Ui::NOP, Mdi::REFRESH),
204
+ Kr::contextMenuIcon (Model::bindIf<GoBack>(s.canGoBack ()), Mdi::ARROW_LEFT),
205
+ Kr::contextMenuIcon (Model::bindIf<GoForward>(s.canGoForward ()), Mdi::ARROW_RIGHT),
206
+ Kr::contextMenuIcon (Model::bind<Reload>(), Mdi::REFRESH),
168
207
}),
169
208
Ui::separator (),
170
209
Kr::contextMenuItem (
171
- [s](auto &) {
172
- (void )Sys::launch (Mime::Uti::PUBLIC_MODIFY, s.url );
173
- },
210
+ Model::bind<Navigate>(
211
+ s.currentUrl ().url ,
212
+ Mime::Uti::PUBLIC_MODIFY
213
+ ),
174
214
Mdi::CODE_TAGS, " View Source..."
175
215
),
176
- Kr::contextMenuItem (Model::bind (SidePanel::DEVELOPER_TOOLS), Mdi::BUTTON_CURSOR, " Inspect" ),
216
+ Kr::contextMenuItem (
217
+ Model::bind (SidePanel::DEVELOPER_TOOLS),
218
+ Mdi::BUTTON_CURSOR, " Inspect"
219
+ ),
177
220
});
178
221
}
179
222
@@ -250,7 +293,7 @@ Ui::Child appContent(State const &s) {
250
293
Ui::Child app (Mime::Url url, Res<Strong<Vaev::Markup::Document>> dom) {
251
294
return Ui::reducer<Model>(
252
295
{
253
- url,
296
+ Navigate{ url} ,
254
297
dom,
255
298
},
256
299
[](State const &s) {
@@ -259,8 +302,9 @@ Ui::Child app(Mime::Url url, Res<Strong<Vaev::Markup::Document>> dom) {
259
302
.title = " Vaev" s,
260
303
.startTools = slots$(
261
304
Ui::button (Model::bindIf<GoBack>(s.canGoBack ()), Ui::ButtonStyle::subtle (), Mdi::ARROW_LEFT),
305
+ Ui::button (Model::bindIf<GoForward>(s.canGoForward ()), Ui::ButtonStyle::subtle (), Mdi::ARROW_RIGHT),
262
306
),
263
- .midleTools = slots$(addressBar (s.url ) | Ui::grow ()),
307
+ .midleTools = slots$(addressBar (s.currentUrl (). url ) | Ui::grow ()),
264
308
.endTools = slots$(
265
309
Ui::button (
266
310
[&](Ui::Node &n) {
0 commit comments