From fb71407409b2debd8e03c42faecd811d168321bf Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 13 Feb 2022 20:27:11 +0200 Subject: Added UI helper for presenting data URLs Omit the actual data. --- src/ui/sidebarwidget.c | 54 ++++++++++++++++++++++++++++++-------------------- 1 file changed, 32 insertions(+), 22 deletions(-) (limited to 'src/ui/sidebarwidget.c') diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index da377ac2..73023a4f 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -2156,28 +2156,38 @@ static void draw_SidebarItem_(const iSidebarItem *d, iPaint *p, iRect itemRect, : uiTextDim_ColorId; iUrl parts; init_Url(&parts, &d->label); - const iBool isAbout = equalCase_Rangecc(parts.scheme, "about"); - const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini"); - draw_Text(font, - add_I2(topLeft_Rect(itemRect), - init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2)), - fg, - "%s%s%s%s%s%s%s%s", - isGemini ? "" : cstr_Rangecc(parts.scheme), - isGemini ? "" - : isAbout ? ":" - : "://", - escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId - : uiTextFramelessHover_ColorId) - : uiTextStrong_ColorId), - cstr_Rangecc(parts.host), - escape_Color(fg), - cstr_Rangecc(parts.path), - !isEmpty_Range(&parts.query) ? escape_Color(isPressing ? uiTextPressed_ColorId - : isHover ? uiText_ColorId - : uiAnnotation_ColorId) - : "", - !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : ""); + const iBool isAbout = equalCase_Rangecc(parts.scheme, "about"); + const iBool isGemini = equalCase_Rangecc(parts.scheme, "gemini"); + const iBool isData = equalCase_Rangecc(parts.scheme, "data"); + const int queryColor = isPressing ? uiTextPressed_ColorId + : isHover ? uiText_ColorId + : uiAnnotation_ColorId; + const iInt2 textPos = + add_I2(topLeft_Rect(itemRect), + init_I2(3 * gap_UI, (itemHeight - lineHeight_Text(font)) / 2)); + if (isData) { + drawRange_Text( + font, textPos, fg, range_String(prettyDataUrl_String(&d->label, queryColor))); + } + else { + draw_Text( + font, + textPos, + fg, + "%s%s%s%s%s%s%s%s", + isGemini ? "" : cstr_Rangecc(parts.scheme), + isGemini ? "" + : isAbout ? ":" + : "://", + escape_Color(isHover ? (isPressing ? uiTextPressed_ColorId + : uiTextFramelessHover_ColorId) + : uiTextStrong_ColorId), + cstr_Rangecc(parts.host), + escape_Color(fg), + cstr_Rangecc(parts.path), + !isEmpty_Range(&parts.query) ? escape_Color(queryColor) : "", + !isEmpty_Range(&parts.query) ? cstr_Rangecc(parts.query) : ""); + } } iEndCollect(); } -- cgit v1.2.3 From ed14d3467d6046ddfa66c3143a340428aeef66ae Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 20 Feb 2022 09:33:20 +0200 Subject: Adding context items to open in new window --- po/en.po | 12 ++++++--- src/app.c | 45 +++++++++++++++++++------------- src/app.h | 1 + src/defs.h | 5 ++-- src/gmutil.c | 11 +++++--- src/gmutil.h | 2 +- src/ui/documentwidget.c | 68 +++++++++++++++++++++++++++---------------------- src/ui/lookupwidget.c | 2 +- src/ui/root.c | 3 ++- src/ui/sidebarwidget.c | 28 ++++++++++++++------ src/ui/window.c | 17 +++++++++++++ src/ui/window.h | 1 + 12 files changed, 128 insertions(+), 67 deletions(-) (limited to 'src/ui/sidebarwidget.c') diff --git a/po/en.po b/po/en.po index bff4c495..6647324e 100644 --- a/po/en.po +++ b/po/en.po @@ -148,6 +148,9 @@ msgstr "Identity" msgid "menu.title.help" msgstr "Help" +msgid "menu.newwindow" +msgstr "New Window" + msgid "menu.newtab" msgstr "New Tab" @@ -519,9 +522,6 @@ msgstr "%b. %d, %Y" msgid "feeds.today" msgstr "Today" -msgid "feeds.entry.newtab" -msgstr "Open Entry in New Tab" - msgid "feeds.entry.markread" msgstr "Mark as Read" @@ -558,6 +558,9 @@ msgstr "Open in New Tab" msgid "menu.opentab.background" msgstr "Open in Background Tab" +msgid "menu.openwindow" +msgstr "Open in New Window" + msgid "menu.openfile" msgstr "Open File…" @@ -870,6 +873,9 @@ msgstr "Open Link to the Side" msgid "link.side.newtab" msgstr "Open Link in New Tab to the Side" +msgid "link.newwindow" +msgstr "Open Link in New Window" + msgid "link.browser" msgstr "Open Link in Default Browser" diff --git a/src/app.c b/src/app.c index 010c6d74..543467ef 100644 --- a/src/app.c +++ b/src/app.c @@ -1878,7 +1878,7 @@ void postCommand_Root(iRoot *d, const char *command) { ev.user.data2 = d; /* all events are root-specific */ ev.user.windowID = d ? id_Window(d->window) : 0; /* root-specific means window-specific */ SDL_PushEvent(&ev); - iWindow *win = get_Window(); + iWindow *win = d ? d->window : NULL; #if defined (iPlatformAndroid) SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, "%s[command] {%d} %s", app_.isLoadingPrefs ? "[Prefs] " : "", @@ -1979,6 +1979,13 @@ size_t windowIndex_App(const iMainWindow *win) { return indexOf_PtrArray(&app_.mainWindows, win); } +iMainWindow *newMainWindow_App(void) { + iApp *d = &app_; + iMainWindow *win = new_MainWindow(initialWindowRect_App_(d, size_PtrArray(&d->mainWindows))); + addWindow_App(win); + return win; +} + const iPtrArray *mainWindows_App(void) { return &app_.mainWindows; } @@ -3038,7 +3045,18 @@ iBool handleCommand_App(const char *cmd) { return iTrue; /* invalid command */ } if (findWidget_App("prefs")) { - postCommand_App("prefs.dismiss"); + postCommand_App("prefs.dismiss"); + } + if (argLabel_Command(cmd, "newwindow")) { + const iRangecc gotoheading = range_Command(cmd, "gotoheading"); + const iRangecc gotourlheading = range_Command(cmd, "gotourlheading"); + postCommandf_Root(get_Root(), "window.new%s%s%s%s url:%s", + isEmpty_Range(&gotoheading) ? "" : " gotoheading:", + isEmpty_Range(&gotoheading) ? "" : cstr_Rangecc(gotoheading), + isEmpty_Range(&gotourlheading) ? "" : " gotourlheading:", + isEmpty_Range(&gotourlheading) ? "" : cstr_Rangecc(gotourlheading), + urlArg); + return iTrue; } iString *url = collectNewCStr_String(urlArg); const iBool noProxy = argLabel_Command(cmd, "noproxy") != 0; @@ -3187,7 +3205,12 @@ iBool handleCommand_App(const char *cmd) { addWindow_App(newWin); /* takes ownership */ SDL_ShowWindow(newWin->base.win); setCurrent_Window(newWin); - postCommand_Root(newWin->base.roots[0], "~navigate.home"); + if (hasLabel_Command(cmd, "url")) { + postCommandf_Root(newWin->base.roots[0], "~open %s", cmd + 11 /* all arguments passed on */); + } + else { + postCommand_Root(newWin->base.roots[0], "~navigate.home"); + } postCommand_Root(newWin->base.roots[0], "~window.unfreeze"); return iTrue; } @@ -3745,21 +3768,7 @@ void revealPath_App(const iString *path) { } iObjectList *listDocuments_App(const iRoot *rootOrNull) { - iWindow *win = get_Window(); - iObjectList *docs = new_ObjectList(); - iForIndices(i, win->roots) { - iRoot *root = win->roots[i]; - if (!root) continue; - if (!rootOrNull || root == rootOrNull) { - const iWidget *tabs = findChild_Widget(root->widget, "doctabs"); - iForEach(ObjectList, i, children_Widget(findChild_Widget(tabs, "tabs.pages"))) { - if (isInstance_Object(i.object, &Class_DocumentWidget)) { - pushBack_ObjectList(docs, i.object); - } - } - } - } - return docs; + return listDocuments_MainWindow(get_MainWindow(), rootOrNull); } iStringSet *listOpenURLs_App(void) { diff --git a/src/app.h b/src/app.h index 63a477a5..5f7b506f 100644 --- a/src/app.h +++ b/src/app.h @@ -129,6 +129,7 @@ void setActiveWindow_App (iMainWindow *win); void closeWindow_App (iMainWindow *win); size_t numWindows_App (void); size_t windowIndex_App (const iMainWindow *win); +iMainWindow *newMainWindow_App (void); const iPtrArray *mainWindows_App(void); void addPopup_App (iWindow *popup); void removePopup_App (iWindow *popup); diff --git a/src/defs.h b/src/defs.h index be5280fa..c3480bc2 100644 --- a/src/defs.h +++ b/src/defs.h @@ -157,8 +157,9 @@ iLocalDef int acceptKeyMod_ReturnKeyBehavior(int behavior) { #define bookmark_Icon "\U0001f516" #define folder_Icon "\U0001f4c1" #define file_Icon "\U0001f5ce" -#define openTab_Icon "\u2750" -#define openTabBg_Icon "\u2b1a" +#define openWindow_Icon "\u2b1a" //"\U0001F5d4" +#define openTab_Icon add_Icon +#define openTabBg_Icon "\u2750" //"\u2b1a" #define openExt_Icon "\u27a0" #define add_Icon "\u2795" #define page_Icon "\U00010117" diff --git a/src/gmutil.c b/src/gmutil.c index e862b18a..b32722ac 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -780,7 +780,7 @@ iRangecc mediaTypeWithoutParameters_Rangecc(iRangecc mime) { return part; } -const iString *feedEntryOpenCommand_String(const iString *url, int newTab) { +const iString *feedEntryOpenCommand_String(const iString *url, int newTab, int newWindow) { if (!isEmpty_String(url)) { iString *cmd = collectNew_String(); const size_t fragPos = indexOf_String(url, '#'); @@ -788,15 +788,20 @@ const iString *feedEntryOpenCommand_String(const iString *url, int newTab) { iString *head = newRange_String( (iRangecc){ constBegin_String(url) + fragPos + 1, constEnd_String(url) }); format_String(cmd, - "open fromsidebar:1 newtab:%d gotourlheading:%s url:%s", + "open fromsidebar:1 newtab:%d newwindow:%d gotourlheading:%s url:%s", newTab, + newWindow, cstr_String(head), cstr_Rangecc((iRangecc){ constBegin_String(url), constBegin_String(url) + fragPos })); delete_String(head); } else { - format_String(cmd, "open fromsidebar:1 newtab:%d url:%s", newTab, cstr_String(url)); + format_String(cmd, + "open fromsidebar:1 newtab:%d newwindow:%d url:%s", + newTab, + newWindow, + cstr_String(url)); } return cmd; } diff --git a/src/gmutil.h b/src/gmutil.h index 01eb8e52..e4284cfd 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -151,4 +151,4 @@ iRangecc mediaTypeWithoutParameters_Rangecc (iRangecc mime); const iString * findContainerArchive_Path (const iString *path); -const iString * feedEntryOpenCommand_String (const iString *url, int newTab); /* checks fragment */ +const iString * feedEntryOpenCommand_String (const iString *url, int newTab, int newWindow); /* checks fragment */ 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 iArray items; init_Array(&items, sizeof(iMenuItem)); if (d->contextLink) { - /* Context menu for a link. */ + /* Construct the link context menu, depending on what kind of link was clicked. */ interactingWithLink_DocumentWidget_(d, d->contextLink->linkId); /* perhaps will be triggered */ const iString *linkUrl = linkUrl_GmDocument(view->doc, d->contextLink->linkId); -// const int linkFlags = linkFlags_GmDocument(d->doc, d->contextLink->linkId); const iRangecc scheme = urlScheme_String(linkUrl); const iBool isGemini = equalCase_Rangecc(scheme, "gemini"); iBool isNative = iFalse; @@ -5086,39 +5085,48 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e format_CStr("```%s", cstr_String(infoText)), 0, 0, NULL }); } - if (willUseProxy_App(scheme) || isGemini || + if (isGemini || + willUseProxy_App(scheme) || + equalCase_Rangecc(scheme, "data") || equalCase_Rangecc(scheme, "file") || equalCase_Rangecc(scheme, "finger") || equalCase_Rangecc(scheme, "gopher")) { isNative = iTrue; /* Regular links that we can open. */ - pushBackN_Array( - &items, - (iMenuItem[]){ { openTab_Icon " ${link.newtab}", - 0, - 0, - format_CStr("!open newtab:1 origin:%s url:%s", - cstr_String(id_Widget(w)), - cstr_String(linkUrl)) }, - { openTabBg_Icon " ${link.newtab.background}", - 0, - 0, - format_CStr("!open newtab:2 origin:%s url:%s", - cstr_String(id_Widget(w)), - cstr_String(linkUrl)) }, - { "${link.side}", - 0, - 0, - format_CStr("!open newtab:4 origin:%s url:%s", - cstr_String(id_Widget(w)), - cstr_String(linkUrl)) }, - { "${link.side.newtab}", - 0, - 0, - format_CStr("!open newtab:5 origin:%s url:%s", - cstr_String(id_Widget(w)), - cstr_String(linkUrl)) } }, - 4); + pushBackN_Array(&items, + (iMenuItem[]){ + { openTab_Icon " ${link.newtab}", + 0, + 0, + format_CStr("!open newtab:1 origin:%s url:%s", + cstr_String(id_Widget(w)), + cstr_String(linkUrl)) }, + { openTabBg_Icon " ${link.newtab.background}", + 0, + 0, + format_CStr("!open newtab:2 origin:%s url:%s", + cstr_String(id_Widget(w)), + cstr_String(linkUrl)) }, + { "${link.side}", + 0, + 0, + format_CStr("!open newtab:4 origin:%s url:%s", + cstr_String(id_Widget(w)), + cstr_String(linkUrl)) }, + { "${link.side.newtab}", + 0, + 0, + format_CStr("!open newtab:5 origin:%s url:%s", + cstr_String(id_Widget(w)), + cstr_String(linkUrl)) }, + { openWindow_Icon " ${link.newwindow}", + 0, + 0, + format_CStr("!open newwindow:1 origin:%s url:%s", + cstr_String(id_Widget(w)), + cstr_String(linkUrl)) }, + }, + 5); if (deviceType_App() == phone_AppDeviceType) { removeN_Array(&items, size_Array(&items) - 2, iInvalidSize); } 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) { cstr_String(&res->label), uiText_ColorEscape, cstr_String(&res->meta)); - const iString *cmd = feedEntryOpenCommand_String(&res->url, 0); + const iString *cmd = feedEntryOpenCommand_String(&res->url, 0, 0); if (cmd) { set_String(&item->command, cmd); } 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. */ #if defined (iPlatformPcDesktop) /* TODO: Submenus wouldn't hurt here. */ static const iMenuItem navMenuItems_[] = { - { add_Icon " ${menu.newtab}", 't', KMOD_PRIMARY, "tabs.new" }, + { openWindow_Icon " ${menu.newwindow}", SDLK_n, KMOD_PRIMARY, "window.new" }, + { add_Icon " ${menu.newtab}", SDLK_t, KMOD_PRIMARY, "tabs.new" }, { "${menu.openlocation}", SDLK_l, KMOD_PRIMARY, "navigate.focus" }, { "---" }, { 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 } d->menu = makeMenu_Widget( as_Widget(d), - (iMenuItem[]){ { openTab_Icon " ${feeds.entry.newtab}", 0, 0, "feed.entry.opentab" }, + (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "feed.entry.open newtab:1" }, + { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "feed.entry.open newtab:2" }, + { openWindow_Icon " ${menu.openwindow}", 0, 0, "feed.entry.open newwindow:1" }, + { "---", 0, 0, NULL }, { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, + { "${menu.copyurl}", 0, 0, "feed.entry.copyurl" }, { "---", 0, 0, NULL }, { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, @@ -424,7 +428,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct { "---", 0, 0, NULL }, { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" }, { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } }, - 10); + 13); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ @@ -491,6 +495,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct as_Widget(d), (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" }, { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" }, + { openWindow_Icon " ${menu.openwindow}", 0, 0, "bookmark.open newwindow:1" }, { "---", 0, 0, NULL }, { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" }, { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, @@ -502,11 +507,11 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct { "---", 0, 0, NULL }, { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, { "---", 0, 0, NULL }, - { add_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, + { folder_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" }, { "---", 0, 0, NULL }, { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } }, - 17); + 18); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, @@ -571,13 +576,17 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct d->menu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ + { openTab_Icon " ${menu.opentab}", 0, 0, "history.open newtab:1" }, + { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" }, + { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" }, + { "---" }, { "${menu.copyurl}", 0, 0, "history.copy" }, { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, { "---", 0, 0, NULL }, { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, { "---", 0, 0, NULL }, { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" }, - }, 6); + }, 10); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ @@ -981,7 +990,7 @@ static void itemClicked_SidebarWidget_(iSidebarWidget *d, iSidebarItem *item, si } case feeds_SidebarMode: { postCommandString_Root(get_Root(), - feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()))); + feedEntryOpenCommand_String(&item->url, openTabMode_Sym(modState_Keys()), 0)); break; } case bookmarks_SidebarMode: @@ -1641,8 +1650,11 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) else if (startsWith_CStr(cmd, "feed.entry.") && d->mode == feeds_SidebarMode) { const iSidebarItem *item = d->contextItem; if (item) { - if (isCommand_Widget(w, ev, "feed.entry.opentab")) { - postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url, 1)); + if (isCommand_Widget(w, ev, "feed.entry.open")) { + const char *cmd = command_UserEvent(ev); + postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url, + argLabel_Command(cmd, "newtab"), + argLabel_Command(cmd, "newwindow"))); return iTrue; } 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) { } } +iObjectList *listDocuments_MainWindow(iMainWindow *d, const iRoot *rootOrNull) { + iObjectList *docs = new_ObjectList(); + iForIndices(i, d->base.roots) { + iRoot *root = d->base.roots[i]; + if (!root) continue; + if (!rootOrNull || root == rootOrNull) { + const iWidget *tabs = findChild_Widget(root->widget, "doctabs"); + iForEach(ObjectList, i, children_Widget(findChild_Widget(tabs, "tabs.pages"))) { + if (isInstance_Object(i.object, &Class_DocumentWidget)) { + pushBack_ObjectList(docs, i.object); + } + } + } + } + return docs; +} + void checkPendingSplit_MainWindow(iMainWindow *d) { if (d->splitMode != d->pendingSplitMode) { 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 void setSnap_MainWindow (iMainWindow *, int snapMode); void setFreezeDraw_MainWindow (iMainWindow *, iBool freezeDraw); void setKeyboardHeight_MainWindow (iMainWindow *, int height); +iObjectList *listDocuments_MainWindow (iMainWindow *, const iRoot *rootOrNull); void setSplitMode_MainWindow (iMainWindow *, int splitMode); void checkPendingSplit_MainWindow (iMainWindow *); void swapRoots_MainWindow (iMainWindow *); -- cgit v1.2.3 From 09c1f3d7c06b1852ab973e16e2c169a6e541082e Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 20 Feb 2022 11:42:36 +0200 Subject: Context menu items for opening items --- src/ui/documentwidget.c | 12 ++++++------ src/ui/sidebarwidget.c | 32 +++++++++++++++++++++++++------- 2 files changed, 31 insertions(+), 13 deletions(-) (limited to 'src/ui/sidebarwidget.c') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 99039ff5..7492d9bd 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -5107,22 +5107,22 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e format_CStr("!open newtab:2 origin:%s url:%s", cstr_String(id_Widget(w)), cstr_String(linkUrl)) }, - { "${link.side}", + { openWindow_Icon " ${link.newwindow}", 0, 0, - format_CStr("!open newtab:4 origin:%s url:%s", + format_CStr("!open newwindow:1 origin:%s url:%s", cstr_String(id_Widget(w)), cstr_String(linkUrl)) }, - { "${link.side.newtab}", + { "${link.side}", 0, 0, - format_CStr("!open newtab:5 origin:%s url:%s", + format_CStr("!open newtab:4 origin:%s url:%s", cstr_String(id_Widget(w)), cstr_String(linkUrl)) }, - { openWindow_Icon " ${link.newwindow}", + { "${link.side.newtab}", 0, 0, - format_CStr("!open newwindow:1 origin:%s url:%s", + format_CStr("!open newtab:5 origin:%s url:%s", cstr_String(id_Widget(w)), cstr_String(linkUrl)) }, }, diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 0322b2a9..8f9e44c8 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -420,7 +420,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct { "---", 0, 0, NULL }, { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, - { "${menu.copyurl}", 0, 0, "feed.entry.copyurl" }, + { "${menu.copyurl}", 0, 0, "feed.entry.copy" }, { "---", 0, 0, NULL }, { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, @@ -580,8 +580,8 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" }, { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" }, { "---" }, - { "${menu.copyurl}", 0, 0, "history.copy" }, { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, + { "${menu.copyurl}", 0, 0, "history.copy" }, { "---", 0, 0, NULL }, { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, { "---", 0, 0, NULL }, @@ -1652,12 +1652,18 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) if (item) { if (isCommand_Widget(w, ev, "feed.entry.open")) { const char *cmd = command_UserEvent(ev); - postCommandString_Root(get_Root(), feedEntryOpenCommand_String(&item->url, - argLabel_Command(cmd, "newtab"), - argLabel_Command(cmd, "newwindow"))); + postCommandString_Root( + get_Root(), + feedEntryOpenCommand_String(&item->url, + argLabel_Command(cmd, "newtab"), + argLabel_Command(cmd, "newwindow"))); return iTrue; } - if (isCommand_Widget(w, ev, "feed.entry.toggleread")) { + else if (isCommand_Widget(w, ev, "feed.entry.copy")) { + SDL_SetClipboardText(cstr_String(&item->url)); + return iTrue; + } + else if (isCommand_Widget(w, ev, "feed.entry.toggleread")) { iVisited *vis = visited_App(); const iString *url = urlFragmentStripped_String(&item->url); if (containsUrl_Visited(vis, url)) { @@ -1669,7 +1675,7 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) postCommand_App("visited.changed"); return iTrue; } - if (isCommand_Widget(w, ev, "feed.entry.bookmark")) { + else if (isCommand_Widget(w, ev, "feed.entry.bookmark")) { makeBookmarkCreation_Widget(&item->url, &item->label, item->icon); if (deviceType_App() == desktop_AppDeviceType) { postCommand_App("focus.set id:bmed.title"); @@ -1718,6 +1724,18 @@ static iBool processEvent_SidebarWidget_(iSidebarWidget *d, const SDL_Event *ev) } return iTrue; } + else if (isCommand_Widget(w, ev, "history.open")) { + const iSidebarItem *item = d->contextItem; + if (item && !isEmpty_String(&item->url)) { + const char *cmd = command_UserEvent(ev); + postCommand_Widget(d, + "!open newtab:%d newwindow:%d url:%s", + argLabel_Command(cmd, "newtab"), + argLabel_Command(cmd, "newwindow"), + cstr_String(&item->url)); + } + return iTrue; + } else if (isCommand_Widget(w, ev, "history.copy")) { const iSidebarItem *item = d->contextItem; if (item && !isEmpty_String(&item->url)) { -- cgit v1.2.3 From 41f378c4b46cb5dd3599d44c81fa51d3183eefee Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sun, 20 Feb 2022 12:52:36 +0200 Subject: Mobile: Omit menu items for new windows --- src/ui/documentwidget.c | 7 ++- src/ui/sidebarwidget.c | 111 +++++++++++++++++++++++++----------------------- 2 files changed, 64 insertions(+), 54 deletions(-) (limited to 'src/ui/sidebarwidget.c') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 7492d9bd..fdc0dd75 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -5128,7 +5128,12 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e }, 5); if (deviceType_App() == phone_AppDeviceType) { - removeN_Array(&items, size_Array(&items) - 2, iInvalidSize); + /* Phones don't do windows or splits. */ + removeN_Array(&items, size_Array(&items) - 3, iInvalidSize); + } + else if (deviceType_App() == tablet_AppDeviceType) { + /* Tablets only do splits. */ + removeN_Array(&items, size_Array(&items) - 3, 1); } if (equalCase_Rangecc(scheme, "file")) { pushBack_Array(&items, &(iMenuItem){ "---" }); diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index 8f9e44c8..8a96961a 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c @@ -412,23 +412,25 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct setOutline_LabelWidget(child_Widget(d->actions, 1), d->feedsMode != all_FeedsMode); setOutline_LabelWidget(child_Widget(d->actions, 2), d->feedsMode != unread_FeedsMode); } - d->menu = makeMenu_Widget( - as_Widget(d), - (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "feed.entry.open newtab:1" }, - { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "feed.entry.open newtab:2" }, - { openWindow_Icon " ${menu.openwindow}", 0, 0, "feed.entry.open newwindow:1" }, - { "---", 0, 0, NULL }, - { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, - { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, - { "${menu.copyurl}", 0, 0, "feed.entry.copy" }, - { "---", 0, 0, NULL }, - { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, - { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, - { whiteStar_Icon " " uiTextCaution_ColorEscape "${feeds.unsubscribe}", 0, 0, "feed.entry.unsubscribe" }, - { "---", 0, 0, NULL }, - { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" }, - { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } }, - 13); + const iMenuItem menuItems[] = { + { openTab_Icon " ${menu.opentab}", 0, 0, "feed.entry.open newtab:1" }, + { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "feed.entry.open newtab:2" }, +#if defined (iPlatformDesktop) + { openWindow_Icon " ${menu.openwindow}", 0, 0, "feed.entry.open newwindow:1" }, +#endif + { "---", 0, 0, NULL }, + { circle_Icon " ${feeds.entry.markread}", 0, 0, "feed.entry.toggleread" }, + { bookmark_Icon " ${feeds.entry.bookmark}", 0, 0, "feed.entry.bookmark" }, + { "${menu.copyurl}", 0, 0, "feed.entry.copy" }, + { "---", 0, 0, NULL }, + { page_Icon " ${feeds.entry.openfeed}", 0, 0, "feed.entry.openfeed" }, + { edit_Icon " ${feeds.edit}", 0, 0, "feed.entry.edit" }, + { whiteStar_Icon " " uiTextCaution_ColorEscape "${feeds.unsubscribe}", 0, 0, "feed.entry.unsubscribe" }, + { "---", 0, 0, NULL }, + { check_Icon " ${feeds.markallread}", SDLK_a, KMOD_SHIFT, "feeds.markallread" }, + { reload_Icon " ${feeds.refresh}", SDLK_r, KMOD_PRIMARY | KMOD_SHIFT, "feeds.refresh" } + }; + d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems)); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ @@ -491,27 +493,29 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct addItem_ListWidget(d->list, item); iRelease(item); } - d->menu = makeMenu_Widget( - as_Widget(d), - (iMenuItem[]){ { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" }, - { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" }, - { openWindow_Icon " ${menu.openwindow}", 0, 0, "bookmark.open newwindow:1" }, - { "---", 0, 0, NULL }, - { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" }, - { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, - { "${menu.copyurl}", 0, 0, "bookmark.copy" }, - { "---", 0, 0, NULL }, - { "", 0, 0, "bookmark.tag tag:subscribed" }, - { "", 0, 0, "bookmark.tag tag:homepage" }, - { "", 0, 0, "bookmark.tag tag:remotesource" }, - { "---", 0, 0, NULL }, - { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, - { "---", 0, 0, NULL }, - { folder_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, - { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" }, - { "---", 0, 0, NULL }, - { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } }, - 18); + const iMenuItem menuItems[] = { + { openTab_Icon " ${menu.opentab}", 0, 0, "bookmark.open newtab:1" }, + { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "bookmark.open newtab:2" }, +#if defined (iPlatformDesktop) + { openWindow_Icon " ${menu.openwindow}", 0, 0, "bookmark.open newwindow:1" }, +#endif + { "---", 0, 0, NULL }, + { edit_Icon " ${menu.edit}", 0, 0, "bookmark.edit" }, + { copy_Icon " ${menu.dup}", 0, 0, "bookmark.dup" }, + { "${menu.copyurl}", 0, 0, "bookmark.copy" }, + { "---", 0, 0, NULL }, + { "", 0, 0, "bookmark.tag tag:subscribed" }, + { "", 0, 0, "bookmark.tag tag:homepage" }, + { "", 0, 0, "bookmark.tag tag:remotesource" }, + { "---", 0, 0, NULL }, + { delete_Icon " " uiTextCaution_ColorEscape "${bookmark.delete}", 0, 0, "bookmark.delete" }, + { "---", 0, 0, NULL }, + { folder_Icon " ${menu.newfolder}", 0, 0, "bookmark.addfolder" }, + { upDownArrow_Icon " ${menu.sort.alpha}", 0, 0, "bookmark.sortfolder" }, + { "---", 0, 0, NULL }, + { reload_Icon " ${bookmarks.reload}", 0, 0, "bookmarks.reload.remote" } + }; + d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems)); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ { bookmark_Icon " ${menu.page.bookmark}", SDLK_d, KMOD_PRIMARY, "bookmark.add" }, @@ -525,7 +529,7 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct addActionButton_SidebarWidget_(d, "${sidebar.action.bookmarks.newfolder}", "bookmarks.addfolder", !d->isEditing ? hidden_WidgetFlag : 0); addChildFlags_Widget(d->actions, iClob(new_Widget()), expand_WidgetFlag); - iLabelWidget *btn = addActionButton_SidebarWidget_(d, + addActionButton_SidebarWidget_(d, d->isEditing ? "${sidebar.close}" : "${sidebar.action.bookmarks.edit}", "sidebar.bookmarks.edit", 0); } @@ -573,20 +577,21 @@ static void updateItemsWithFlags_SidebarWidget_(iSidebarWidget *d, iBool keepAct addItem_ListWidget(d->list, item); iRelease(item); } - d->menu = makeMenu_Widget( - as_Widget(d), - (iMenuItem[]){ - { openTab_Icon " ${menu.opentab}", 0, 0, "history.open newtab:1" }, - { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" }, - { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" }, - { "---" }, - { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, - { "${menu.copyurl}", 0, 0, "history.copy" }, - { "---", 0, 0, NULL }, - { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, - { "---", 0, 0, NULL }, - { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" }, - }, 10); + const iMenuItem menuItems[] = { + { openTab_Icon " ${menu.opentab}", 0, 0, "history.open newtab:1" }, + { openTabBg_Icon " ${menu.opentab.background}", 0, 0, "history.open newtab:2" }, +#if defined (iPlatformDesktop) + { openWindow_Icon " ${menu.openwindow}", 0, 0, "history.open newwindow:1" }, +#endif + { "---" }, + { bookmark_Icon " ${sidebar.entry.bookmark}", 0, 0, "history.addbookmark" }, + { "${menu.copyurl}", 0, 0, "history.copy" }, + { "---", 0, 0, NULL }, + { close_Icon " ${menu.forgeturl}", 0, 0, "history.delete" }, + { "---", 0, 0, NULL }, + { delete_Icon " " uiTextCaution_ColorEscape "${history.clear}", 0, 0, "history.clear confirm:1" }, + }; + d->menu = makeMenu_Widget(as_Widget(d), menuItems, iElemCount(menuItems)); d->modeMenu = makeMenu_Widget( as_Widget(d), (iMenuItem[]){ -- cgit v1.2.3