diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-18 23:51:02 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-18 23:51:02 +0300 |
commit | 477225fc168cf794d7a985faca1a2f45e67c6295 (patch) | |
tree | 272f7085cd7e80522942deda4b68de59f1072c4e /src/ui | |
parent | 01b09cc3cf3cd25396c53e184563fbfdab74f8e7 (diff) |
DocumentWidget: Improved context menu
The contents of the menu depend on what is clicked and whether text has been selected.
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 63 |
1 files changed, 43 insertions, 20 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index f54b1e3a..91b33464 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1484,7 +1484,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1484 | case '`': { | 1484 | case '`': { |
1485 | iBlock *seed = new_Block(64); | 1485 | iBlock *seed = new_Block(64); |
1486 | for (size_t i = 0; i < 64; ++i) { | 1486 | for (size_t i = 0; i < 64; ++i) { |
1487 | setByte_Block(seed, i, iRandom(0, 255)); | 1487 | setByte_Block(seed, i, iRandom(0, 256)); |
1488 | } | 1488 | } |
1489 | setThemeSeed_GmDocument(d->doc, seed); | 1489 | setThemeSeed_GmDocument(d->doc, seed); |
1490 | delete_Block(seed); | 1490 | delete_Block(seed); |
@@ -1549,25 +1549,48 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1549 | } | 1549 | } |
1550 | iArray items; | 1550 | iArray items; |
1551 | init_Array(&items, sizeof(iMenuItem)); | 1551 | init_Array(&items, sizeof(iMenuItem)); |
1552 | pushBackN_Array( | 1552 | if (d->contextLink) { |
1553 | &items, | 1553 | pushBackN_Array( |
1554 | (iMenuItem[]){ | 1554 | &items, |
1555 | { "Go Back", navigateBack_KeyShortcut, "navigate.back" }, | 1555 | (iMenuItem[]){ { "Open Link in New Tab", |
1556 | { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" }, | 1556 | 0, |
1557 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, | 1557 | 0, |
1558 | { "---", 0, 0, NULL }, | 1558 | format_CStr("!open newtab:1 url:%s", |
1559 | { d->contextLink ? "Copy Link URL" : "Copy Page URL", | 1559 | cstr_String(linkUrl_GmDocument( |
1560 | 0, | 1560 | d->doc, d->contextLink->linkId))) }, |
1561 | 0, | 1561 | { "---", 0, 0, NULL }, |
1562 | "document.copylink" }, | 1562 | { "Copy Link", |
1563 | { isEmpty_Range(&d->selectMark) ? "Copy Full Source" : "Copy Selected", | 1563 | 0, |
1564 | 'c', | 1564 | 0, |
1565 | KMOD_PRIMARY, | 1565 | "document.copylink" }}, |
1566 | "copy" }, | 1566 | 3); |
1567 | { "---", 0, 0, NULL }, | 1567 | } |
1568 | { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" }, | 1568 | else { |
1569 | }, | 1569 | if (!isEmpty_Range(&d->selectMark)) { |
1570 | 8); | 1570 | pushBackN_Array( |
1571 | &items, | ||
1572 | (iMenuItem[]){ { "Copy", 0, 0, "copy" }, { "---", 0, 0, NULL } }, | ||
1573 | 2); | ||
1574 | } | ||
1575 | pushBackN_Array( | ||
1576 | &items, | ||
1577 | (iMenuItem[]){ | ||
1578 | { "Go Back", navigateBack_KeyShortcut, "navigate.back" }, | ||
1579 | { "Go Forward", navigateForward_KeyShortcut, "navigate.forward" }, | ||
1580 | { "Reload Page", reload_KeyShortcut, "navigate.reload" }, | ||
1581 | { "---", 0, 0, NULL }, | ||
1582 | { "Copy Page URL", 0, 0, "document.copylink" }, | ||
1583 | { "---", 0, 0, NULL } }, | ||
1584 | 6); | ||
1585 | if (isEmpty_Range(&d->selectMark)) { | ||
1586 | pushBackN_Array( | ||
1587 | &items, | ||
1588 | (iMenuItem[]){ | ||
1589 | { "Copy Page Source", 'c', KMOD_PRIMARY, "copy" }, | ||
1590 | { "Save to Downloads", SDLK_s, KMOD_PRIMARY, "document.save" } }, | ||
1591 | 2); | ||
1592 | } | ||
1593 | } | ||
1571 | d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items)); | 1594 | d->menu = makeMenu_Widget(w, data_Array(&items), size_Array(&items)); |
1572 | deinit_Array(&items); | 1595 | deinit_Array(&items); |
1573 | } | 1596 | } |