summaryrefslogtreecommitdiff
path: root/src/ui/documentwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2020-09-02 13:29:53 +0300
committerJaakko Keränen <jaakko.keranen@iki.fi>2020-09-02 18:00:19 +0300
commit6f7408cbe91523a3dae80952790a4a8ec0d87cf4 (patch)
tree2bb3245660b5b0d06a3aa7e2207875331910da39 /src/ui/documentwidget.c
parent77ca5271345e02fc6c4b0ede4621893b5dd523b9 (diff)
DocumentWidget: Dynamic context menu
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r--src/ui/documentwidget.c46
1 files changed, 33 insertions, 13 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 6ca6e4c2..fb3c9ad5 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -241,18 +241,12 @@ void init_DocumentWidget(iDocumentWidget *d) {
241 init_PtrArray(&d->visibleLinks); 241 init_PtrArray(&d->visibleLinks);
242 init_Click(&d->click, d, SDL_BUTTON_LEFT); 242 init_Click(&d->click, d, SDL_BUTTON_LEFT);
243 addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); 243 addChild_Widget(w, iClob(d->scroll = new_ScrollWidget()));
244 d->menu = 244 d->menu = NULL; /* created when clicking */
245 makeMenu_Widget(w,
246 (iMenuItem[]){ { "Go Back", SDLK_LEFT, KMOD_PRIMARY, "navigate.back" },
247 { "Go Forward", SDLK_RIGHT, KMOD_PRIMARY, "navigate.forward" },
248 { "Reload Page", 0, 0, "navigate.reload" },
249 { "---", 0, 0, NULL },
250 { "Copy", 'c', KMOD_PRIMARY, "copy" },
251 { "Copy Link", 0, 0, "document.copylink" } },
252 6);
253#if !defined (iPlatformApple) /* in system menu */ 245#if !defined (iPlatformApple) /* in system menu */
254 addAction_Widget(w, SDLK_w, KMOD_PRIMARY, "tabs.close"); 246 addAction_Widget(w, SDLK_w, KMOD_PRIMARY, "tabs.close");
255#endif 247#endif
248 addAction_Widget(w, SDLK_LEFT, KMOD_PRIMARY, "navigate.back");
249 addAction_Widget(w, SDLK_RIGHT, KMOD_PRIMARY, "navigate.forward");
256} 250}
257 251
258void deinit_DocumentWidget(iDocumentWidget *d) { 252void deinit_DocumentWidget(iDocumentWidget *d) {
@@ -1429,11 +1423,37 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
1429 postCommand_App("navigate.forward"); 1423 postCommand_App("navigate.forward");
1430 return iTrue; 1424 return iTrue;
1431 } 1425 }
1426 if (ev->button.button == SDL_BUTTON_RIGHT) {
1427 if (!d->menu || !isVisible_Widget(d->menu)) {
1428 d->contextLink = d->hoverLink;
1429 if (d->menu) {
1430 destroy_Widget(d->menu);
1431 }
1432 iArray items;
1433 init_Array(&items, sizeof(iMenuItem));
1434 pushBackN_Array(
1435 &items,
1436 (iMenuItem[]){
1437 { "Go Back", SDLK_LEFT, KMOD_PRIMARY, "navigate.back" },
1438 { "Go Forward", SDLK_RIGHT, KMOD_PRIMARY, "navigate.forward" },
1439 { "Reload Page", 0, 0, "navigate.reload" },
1440 { "---", 0, 0, NULL },
1441 { d->contextLink ? "Copy Link URL" : "Copy Page URL",
1442 0,
1443 0,
1444 "document.copylink" },
1445 { isEmpty_Range(&d->selectMark) ? "Copy Full Source" : "Copy Selected",
1446 'c',
1447 KMOD_PRIMARY,
1448 "copy" },
1449 },
1450 6);
1451 d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items));
1452 deinit_Array(&items);
1453 }
1454 processContextMenuEvent_Widget(d->menu, ev, d->hoverLink = NULL);
1455 }
1432 } 1456 }
1433 if (!isVisible_Widget(d->menu)) {
1434 d->contextLink = d->hoverLink;
1435 }
1436 processContextMenuEvent_Widget(d->menu, ev, d->hoverLink = NULL);
1437 switch (processEvent_Click(&d->click, ev)) { 1457 switch (processEvent_Click(&d->click, ev)) {
1438 case started_ClickResult: 1458 case started_ClickResult:
1439 d->selecting = iFalse; 1459 d->selecting = iFalse;