summaryrefslogtreecommitdiff
path: root/src/ui
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2022-02-20 09:33:20 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2022-02-20 09:33:20 +0200
commited14d3467d6046ddfa66c3143a340428aeef66ae (patch)
tree1c06f4f34c5caf874847d2d6cfba206f89cd4f33 /src/ui
parent44214359c0f95dcce3a1390506e9fd74202d5ae7 (diff)
Adding context items to open in new window
Diffstat (limited to 'src/ui')
-rw-r--r--src/ui/documentwidget.c68
-rw-r--r--src/ui/lookupwidget.c2
-rw-r--r--src/ui/root.c3
-rw-r--r--src/ui/sidebarwidget.c28
-rw-r--r--src/ui/window.c17
-rw-r--r--src/ui/window.h1
6 files changed, 79 insertions, 40 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c
index 76c26e27..99039ff5 100644
--- a/src/ui/documentwidget.c
+++ b/src/ui/documentwidget.c
@@ -5071,10 +5071,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
5071 iArray items; 5071 iArray items;
5072 init_Array(&items, sizeof(iMenuItem)); 5072 init_Array(&items, sizeof(iMenuItem));
5073 if (d->contextLink) { 5073 if (d->contextLink) {
5074 /* Context menu for a link. */ 5074 /* Construct the link context menu, depending on what kind of link was clicked. */
5075 interactingWithLink_DocumentWidget_(d, d->contextLink->linkId); /* perhaps will be triggered */ 5075 interactingWithLink_DocumentWidget_(d, d->contextLink->linkId); /* perhaps will be triggered */
5076 const iString *linkUrl = linkUrl_GmDocument(view->doc, d->contextLink->linkId); 5076 const iString *linkUrl = linkUrl_GmDocument(view->doc, d->contextLink->linkId);
5077// const int linkFlags = linkFlags_GmDocument(d->doc, d->contextLink->linkId);
5078 const iRangecc scheme = urlScheme_String(linkUrl); 5077 const iRangecc scheme = urlScheme_String(linkUrl);
5079 const iBool isGemini = equalCase_Rangecc(scheme, "gemini"); 5078 const iBool isGemini = equalCase_Rangecc(scheme, "gemini");
5080 iBool isNative = iFalse; 5079 iBool isNative = iFalse;
@@ -5086,39 +5085,48 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
5086 format_CStr("```%s", cstr_String(infoText)), 5085 format_CStr("```%s", cstr_String(infoText)),
5087 0, 0, NULL }); 5086 0, 0, NULL });
5088 } 5087 }
5089 if (willUseProxy_App(scheme) || isGemini || 5088 if (isGemini ||
5089 willUseProxy_App(scheme) ||
5090 equalCase_Rangecc(scheme, "data") ||
5090 equalCase_Rangecc(scheme, "file") || 5091 equalCase_Rangecc(scheme, "file") ||
5091 equalCase_Rangecc(scheme, "finger") || 5092 equalCase_Rangecc(scheme, "finger") ||
5092 equalCase_Rangecc(scheme, "gopher")) { 5093 equalCase_Rangecc(scheme, "gopher")) {
5093 isNative = iTrue; 5094 isNative = iTrue;
5094 /* Regular links that we can open. */ 5095 /* Regular links that we can open. */
5095 pushBackN_Array( 5096 pushBackN_Array(&items,
5096 &items, 5097 (iMenuItem[]){
5097 (iMenuItem[]){ { openTab_Icon " ${link.newtab}", 5098 { openTab_Icon " ${link.newtab}",
5098 0, 5099 0,
5099 0, 5100 0,
5100 format_CStr("!open newtab:1 origin:%s url:%s", 5101 format_CStr("!open newtab:1 origin:%s url:%s",
5101 cstr_String(id_Widget(w)), 5102 cstr_String(id_Widget(w)),
5102 cstr_String(linkUrl)) }, 5103 cstr_String(linkUrl)) },
5103 { openTabBg_Icon " ${link.newtab.background}", 5104 { openTabBg_Icon " ${link.newtab.background}",
5104 0, 5105 0,
5105 0, 5106 0,
5106 format_CStr("!open newtab:2 origin:%s url:%s", 5107 format_CStr("!open newtab:2 origin:%s url:%s",
5107 cstr_String(id_Widget(w)), 5108 cstr_String(id_Widget(w)),
5108 cstr_String(linkUrl)) }, 5109 cstr_String(linkUrl)) },
5109 { "${link.side}", 5110 { "${link.side}",
5110 0, 5111 0,
5111 0, 5112 0,
5112 format_CStr("!open newtab:4 origin:%s url:%s", 5113 format_CStr("!open newtab:4 origin:%s url:%s",
5113 cstr_String(id_Widget(w)), 5114 cstr_String(id_Widget(w)),
5114 cstr_String(linkUrl)) }, 5115 cstr_String(linkUrl)) },
5115 { "${link.side.newtab}", 5116 { "${link.side.newtab}",
5116 0, 5117 0,
5117 0, 5118 0,
5118 format_CStr("!open newtab:5 origin:%s url:%s", 5119 format_CStr("!open newtab:5 origin:%s url:%s",
5119 cstr_String(id_Widget(w)), 5120 cstr_String(id_Widget(w)),
5120 cstr_String(linkUrl)) } }, 5121 cstr_String(linkUrl)) },
5121 4); 5122 { openWindow_Icon " ${link.newwindow}",
5123 0,
5124 0,
5125 format_CStr("!open newwindow:1 origin:%s url:%s",
5126 cstr_String(id_Widget(w)),
5127 cstr_String(linkUrl)) },
5128 },
5129 5);
5122 if (deviceType_App() == phone_AppDeviceType) { 5130 if (deviceType_App() == phone_AppDeviceType) {
5123 removeN_Array(&items, size_Array(&items) - 2, iInvalidSize); 5131 removeN_Array(&items, size_Array(&items) - 2, iInvalidSize);
5124 } 5132 }
diff --git a/src/ui/lookupwidget.c b/src/ui/lookupwidget.c
index f14170ad..dc3264a2 100644
--- a/src/ui/lookupwidget.c
+++ b/src/ui/lookupwidget.c
@@ -568,7 +568,7 @@ static void presentResults_LookupWidget_(iLookupWidget *d) {
568 cstr_String(&res->label), 568 cstr_String(&res->label),
569 uiText_ColorEscape, 569 uiText_ColorEscape,
570 cstr_String(&res->meta)); 570 cstr_String(&res->meta));
571 const iString *cmd = feedEntryOpenCommand_String(&res->url, 0); 571 const iString *cmd = feedEntryOpenCommand_String(&res->url, 0, 0);
572 if (cmd) { 572 if (cmd) {
573 set_String(&item->command, cmd); 573 set_String(&item->command, cmd);
574 } 574 }
diff --git a/src/ui/root.c b/src/ui/root.c
index 7e4b4863..9dee50ae 100644
--- a/src/ui/root.c
+++ b/src/ui/root.c
@@ -56,7 +56,8 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */
56#if defined (iPlatformPcDesktop) 56#if defined (iPlatformPcDesktop)
57/* TODO: Submenus wouldn't hurt here. */ 57/* TODO: Submenus wouldn't hurt here. */
58static const iMenuItem navMenuItems_[] = { 58static const iMenuItem navMenuItems_[] = {
59 { add_Icon " ${menu.newtab}", 't', KMOD_PRIMARY, "tabs.new" }, 59 { openWindow_Icon " ${menu.newwindow}", SDLK_n, KMOD_PRIMARY, "window.new" },
60 { add_Icon " ${menu.newtab}", SDLK_t, KMOD_PRIMARY, "tabs.new" },
60 { "${menu.openlocation}", SDLK_l, KMOD_PRIMARY, "navigate.focus" }, 61 { "${menu.openlocation}", SDLK_l, KMOD_PRIMARY, "navigate.focus" },
61 { "---" }, 62 { "---" },
62 { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" }, 63 { download_Icon " " saveToDownloads_Label, SDLK_s, KMOD_PRIMARY, "document.save" },
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c
index 73023a4f..0322b2a9 100644
--- a/src/ui/sidebarwidget.c
+++ b/src/ui/sidebarwidget.c
@@ -414,9 +414,13 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
414 } 414 }
415 d->menu = makeMenu_Widget( 415 d->menu = makeMenu_Widget(
416 as_Widget(d), 416 as_Widget(d),
417 (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" }, 417 (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "feed.entry.open newtab:1" },
418 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "feed.entry.open newtab:2" },
419 { openWindow_Icon " ${menu.openwindow}", 0, 0, "feed.entry.open newwindow:1" },
420 { "---", 0, 0, NULL },
418 { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, 421 { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" },
419 { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, 422 { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" },
423 { "${menu.copyurl}", 0, 0, "feed.entry.copyurl" },
420 { "---", 0, 0, NULL }, 424 { "---", 0, 0, NULL },
421 { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, 425 { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" },
422 { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, 426 { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" },
@@ -424,7 +428,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
424 { "---", 0, 0, NULL }, 428 { "---", 0, 0, NULL },
425 { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" }, 429 { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" },
426 { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } }, 430 { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } },
427 10); 431 13);
428 d->modeMenu = makeMenu_Widget( 432 d->modeMenu = makeMenu_Widget(
429 as_Widget(d), 433 as_Widget(d),
430 (iMenuItem[]){ 434 (iMenuItem[]){
@@ -491,6 +495,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
491 as_Widget(d), 495 as_Widget(d),
492 (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" }, 496 (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" },
493 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" }, 497 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" },
498 { openWindow_Icon " ${menu.openwindow}", 0, 0, "bookmark.open newwindow:1" },
494 { "---", 0, 0, NULL }, 499 { "---", 0, 0, NULL },
495 { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" }, 500 { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" },
496 { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, 501 { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" },
@@ -502,11 +507,11 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
502 { "---", 0, 0, NULL }, 507 { "---", 0, 0, NULL },
503 { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, 508 { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" },
504 { "---", 0, 0, NULL }, 509 { "---", 0, 0, NULL },
505 { add_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, 510 { folder_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" },
506 { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" }, 511 { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" },
507 { "---", 0, 0, NULL }, 512 { "---", 0, 0, NULL },
508 { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } }, 513 { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } },
509 17); 514 18);
510 d->modeMenu = makeMenu_Widget( 515 d->modeMenu = makeMenu_Widget(
511 as_Widget(d), 516 as_Widget(d),
512 (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, 517 (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" },
@@ -571,13 +576,17 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct
571 d->menu = makeMenu_Widget( 576 d->menu = makeMenu_Widget(
572 as_Widget(d), 577 as_Widget(d),
573 (iMenuItem[]){ 578 (iMenuItem[]){
579 { openTab_Icon " ${menu.opentab}", 0, 0, "history.open newtab:1" },
580 { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" },
581 { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" },
582 { "---" },
574 { "${menu.copyurl}", 0, 0, "history.copy" }, 583 { "${menu.copyurl}", 0, 0, "history.copy" },
575 { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, 584 { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" },
576 { "---", 0, 0, NULL }, 585 { "---", 0, 0, NULL },
577 { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, 586 { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" },
578 { "---", 0, 0, NULL }, 587 { "---", 0, 0, NULL },
579 { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" }, 588 { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" },
580 }, 6); 589 }, 10);
581 d->modeMenu = makeMenu_Widget( 590 d->modeMenu = makeMenu_Widget(
582 as_Widget(d), 591 as_Widget(d),
583 (iMenuItem[]){ 592 (iMenuItem[]){
@@ -981,7 +990,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si
981 } 990 }
982 case feeds_SidebarMode: { 991 case feeds_SidebarMode: {
983 postCommandString_Root(get_Root(), 992 postCommandString_Root(get_Root(),
984 feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()))); 993 feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()), 0));
985 break; 994 break;
986 } 995 }
987 case bookmarks_SidebarMode: 996 case bookmarks_SidebarMode:
@@ -1641,8 +1650,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev)
1641 else if (startsWith_CStr(cmd, "feed.entry.") && d->mode == feeds_SidebarMode) { 1650 else if (startsWith_CStr(cmd, "feed.entry.") && d->mode == feeds_SidebarMode) {
1642 const iSidebarItem *item = d->contextItem; 1651 const iSidebarItem *item = d->contextItem;
1643 if (item) { 1652 if (item) {
1644 if (isCommand_Widget(w, ev, "feed.entry.opentab")) { 1653 if (isCommand_Widget(w, ev, "feed.entry.open")) {
1645 postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url, 1)); 1654 const char *cmd = command_UserEvent(ev);
1655 postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url,
1656 argLabel_Command(cmd, "newtab"),
1657 argLabel_Command(cmd, "newwindow")));
1646 return iTrue; 1658 return iTrue;
1647 } 1659 }
1648 if (isCommand_Widget(w, ev, "feed.entry.toggleread")) { 1660 if (isCommand_Widget(w, ev, "feed.entry.toggleread")) {
diff --git a/src/ui/window.c b/src/ui/window.c
index 6f680cd4..b0de0557 100644
--- a/src/ui/window.c
+++ b/src/ui/window.c
@@ -1567,6 +1567,23 @@ void setKeyboardHeight_MainWindow(iMainWindow *d, int height) {
1567 } 1567 }
1568} 1568}
1569 1569
1570iObjectList *listDocuments_MainWindow(iMainWindow *d, const iRoot *rootOrNull) {
1571 iObjectList *docs = new_ObjectList();
1572 iForIndices(i, d->base.roots) {
1573 iRoot *root = d->base.roots[i];
1574 if (!root) continue;
1575 if (!rootOrNull || root == rootOrNull) {
1576 const iWidget *tabs = findChild_Widget(root->widget, "doctabs");
1577 iForEach(ObjectList, i, children_Widget(findChild_Widget(tabs, "tabs.pages"))) {
1578 if (isInstance_Object(i.object, &Class_DocumentWidget)) {
1579 pushBack_ObjectList(docs, i.object);
1580 }
1581 }
1582 }
1583 }
1584 return docs;
1585}
1586
1570void checkPendingSplit_MainWindow(iMainWindow *d) { 1587void checkPendingSplit_MainWindow(iMainWindow *d) {
1571 if (d->splitMode != d->pendingSplitMode) { 1588 if (d->splitMode != d->pendingSplitMode) {
1572 setSplitMode_MainWindow(d, d->pendingSplitMode); 1589 setSplitMode_MainWindow(d, d->pendingSplitMode);
diff --git a/src/ui/window.h b/src/ui/window.h
index c7d59380..c3c34e1b 100644
--- a/src/ui/window.h
+++ b/src/ui/window.h
@@ -187,6 +187,7 @@ void setTitle_MainWindow (iMainWindow *, const iString *title
187void setSnap_MainWindow (iMainWindow *, int snapMode); 187void setSnap_MainWindow (iMainWindow *, int snapMode);
188void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw); 188void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw);
189void setKeyboardHeight_MainWindow (iMainWindow *, int height); 189void setKeyboardHeight_MainWindow (iMainWindow *, int height);
190iObjectList *listDocuments_MainWindow (iMainWindow *, const iRoot *rootOrNull);
190void setSplitMode_MainWindow (iMainWindow *, int splitMode); 191void setSplitMode_MainWindow (iMainWindow *, int splitMode);
191void checkPendingSplit_MainWindow (iMainWindow *); 192void checkPendingSplit_MainWindow (iMainWindow *);
192void swapRoots_MainWindow (iMainWindow *); 193void swapRoots_MainWindow (iMainWindow *);