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/gmutil.h | 1 + 1 file changed, 1 insertion(+) (limited to 'src/gmutil.h') diff --git a/src/gmutil.h b/src/gmutil.h index 1594afc4..9217b0e3 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -141,6 +141,7 @@ void urlEncodeSpaces_String (iString *); const iString * withSpacesEncoded_String(const iString *); const iString * withScheme_String (const iString *, const char *scheme); /* replace URI scheme */ const iString * canonicalUrl_String (const iString *); +const iString * prettyDataUrl_String (const iString *, int contentColor); const char * mediaType_Path (const iString *path); const char * mediaTypeFromFileExtension_String (const iString *); -- cgit v1.2.3 From d19691de189227ef1976cb8104cdc55830fdb347 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Mon, 14 Feb 2022 15:04:16 +0200 Subject: Moved a function to the_Foundation --- src/gmutil.c | 37 ------------------------------------- src/gmutil.h | 5 ----- 2 files changed, 42 deletions(-) (limited to 'src/gmutil.h') diff --git a/src/gmutil.c b/src/gmutil.c index 6c2271d7..0573aac1 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -930,40 +930,3 @@ const iGmError *get_GmError(enum iGmStatusCode code) { return &errors_[0].err; /* unknown */ } -int replaceRegExp_String(iString *d, const iRegExp *regexp, const char *replacement, - void (*matchHandler)(void *, const iRegExpMatch *), - void *context) { - iRegExpMatch m; - iString result; - int numMatches = 0; - const char *pos = constBegin_String(d); - init_RegExpMatch(&m); - init_String(&result); - while (matchString_RegExp(regexp, d, &m)) { - appendRange_String(&result, (iRangecc){ pos, begin_RegExpMatch(&m) }); - /* Replace any capture group back-references. */ - for (const char *ch = replacement; *ch; ch++) { - if (*ch == '\\') { - ch++; - if (*ch == '\\') { - appendCStr_String(&result, "\\"); - } - else if (*ch >= '0' && *ch <= '9') { - appendRange_String(&result, capturedRange_RegExpMatch(&m, *ch - '0')); - } - } - else { - appendData_Block(&result.chars, ch, 1); - } - } - if (matchHandler) { - matchHandler(context, &m); - } - pos = end_RegExpMatch(&m); - numMatches++; - } - appendRange_String(&result, (iRangecc){ pos, constEnd_String(d) }); - set_String(d, &result); - deinit_String(&result); - return numMatches; -} diff --git a/src/gmutil.h b/src/gmutil.h index 9217b0e3..c9d7baae 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -151,8 +151,3 @@ const iString * findContainerArchive_Path (const iString *path); const iString * feedEntryOpenCommand_String (const iString *url, int newTab); /* checks fragment */ - -/* TODO: Consider adding this to the_Foundation. */ -int replaceRegExp_String (iString *, const iRegExp *regexp, const char *replacement, - void (*matchHandler)(void *, const iRegExpMatch *), - void *context); -- cgit v1.2.3 From 64eaaaac57fc909a9c9d47302f17f0801b7f2965 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Tue, 15 Feb 2022 17:49:17 +0200 Subject: Working on site-specific settings dialog --- src/gmdocument.c | 27 ++++++++++++++++++--------- src/gmdocument.h | 4 +++- src/gmutil.c | 14 ++++++++++++++ src/gmutil.h | 1 + src/sitespec.c | 13 ++++++++++++- src/sitespec.h | 1 + src/ui/documentwidget.c | 12 ++++++++---- src/ui/util.c | 43 ++++++++++++++++++++++++++++++++++--------- src/ui/util.h | 15 ++++++++------- 9 files changed, 99 insertions(+), 31 deletions(-) (limited to 'src/gmutil.h') diff --git a/src/gmdocument.c b/src/gmdocument.c index a3e233f3..bc0cc073 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c @@ -1292,7 +1292,7 @@ static void updateIconBasedOnUrl_GmDocument_(iGmDocument *d) { } } -void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { +void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *paletteSeed, const iBlock *iconSeed) { const iPrefs * prefs = prefs_App(); enum iGmDocumentTheme theme = currentTheme_(); static const iChar siteIcons[] = { @@ -1303,6 +1303,16 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { 0x1f306, 0x1f308, 0x1f30a, 0x1f319, 0x1f31f, 0x1f320, 0x1f340, 0x1f4cd, 0x1f4e1, 0x1f531, 0x1f533, 0x1f657, 0x1f659, 0x1f665, 0x1f668, 0x1f66b, 0x1f78b, 0x1f796, 0x1f79c, }; + if (!iconSeed) { + iconSeed = paletteSeed; + } + if (iconSeed && !isEmpty_Block(iconSeed)) { + const uint32_t seedHash = themeHash_(iconSeed); + d->siteIcon = siteIcons[(seedHash >> 7) % iElemCount(siteIcons)]; + } + else { + d->siteIcon = 0; + } /* Default colors. These are used on "about:" pages and local files, for example. */ { /* Link colors are generally the same in all themes. */ set_Color(tmBadLink_ColorId, get_Color(red_ColorId)); @@ -1504,13 +1514,11 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { } } } - if (seed && !isEmpty_Block(seed)) { - d->themeSeed = themeHash_(seed); - d->siteIcon = siteIcons[(d->themeSeed >> 7) % iElemCount(siteIcons)]; + if (paletteSeed && !isEmpty_Block(paletteSeed)) { + d->themeSeed = themeHash_(paletteSeed); } else { d->themeSeed = 0; - d->siteIcon = 0; } /* Set up colors. */ if (d->themeSeed) { @@ -1739,8 +1747,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { /* Derived colors. */ setDerivedThemeColors_(theme); /* Special exceptions. */ - if (seed) { - if (equal_CStr(cstr_Block(seed), "gemini.circumlunar.space")) { + if (iconSeed) { + if (equal_CStr(cstr_Block(iconSeed), "gemini.circumlunar.space")) { d->siteIcon = 0x264a; /* gemini symbol */ } updateIconBasedOnUrl_GmDocument_(d); @@ -1761,7 +1769,8 @@ void setThemeSeed_GmDocument(iGmDocument *d, const iBlock *seed) { void makePaletteGlobal_GmDocument(const iGmDocument *d) { if (!d->isPaletteValid) { /* Recompute the palette since it's needed now. */ - setThemeSeed_GmDocument((iGmDocument *) d, urlThemeSeed_String(&d->url)); + setThemeSeed_GmDocument( + (iGmDocument *) d, urlPaletteSeed_String(&d->url), urlThemeSeed_String(&d->url)); } iAssert(d->isPaletteValid); memcpy(get_Root()->tmPalette, d->palette, sizeof(d->palette)); @@ -1938,7 +1947,7 @@ static void normalize_GmDocument(iGmDocument *d) { void setUrl_GmDocument(iGmDocument *d, const iString *url) { url = canonicalUrl_String(url); set_String(&d->url, url); - setThemeSeed_GmDocument(d, urlThemeSeed_String(url)); + setThemeSeed_GmDocument(d, urlPaletteSeed_String(url), urlThemeSeed_String(url)); iUrl parts; init_Url(&parts, url); setRange_String(&d->localHost, parts.host); diff --git a/src/gmdocument.h b/src/gmdocument.h index 0969794c..6c25dd6f 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h @@ -181,7 +181,9 @@ enum iGmDocumentUpdate { final_GmDocumentUpdate, /* process all lines, including the last one if not terminated */ }; -void setThemeSeed_GmDocument (iGmDocument *, const iBlock *seed); +void setThemeSeed_GmDocument (iGmDocument *, + const iBlock *paletteSeed, + const iBlock *iconSeed); /* seeds may be NULL; NULL iconSeed will use paletteSeed instead */ void setFormat_GmDocument (iGmDocument *, enum iSourceFormat format); void setWidth_GmDocument (iGmDocument *, int width, int canvasWidth); iBool updateWidth_GmDocument (iGmDocument *, int width, int canvasWidth); diff --git a/src/gmutil.c b/src/gmutil.c index 0573aac1..9188091d 100644 --- a/src/gmutil.c +++ b/src/gmutil.c @@ -23,6 +23,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ #include "gmutil.h" #include "fontpack.h" #include "lang.h" +#include "sitespec.h" #include "ui/color.h" #include @@ -279,6 +280,19 @@ const iBlock *urlThemeSeed_String(const iString *url) { return collect_Block(newRange_Block(user)); } +const iBlock *urlPaletteSeed_String(const iString *url) { + if (equalCase_Rangecc(urlScheme_String(url), "file")) { + return urlThemeSeed_String(url); + } + /* Check for a site-specific setting. */ + const iString *seed = + valueString_SiteSpec(collectNewRange_String(urlRoot_String(url)), paletteSeed_SiteSpecKey); + if (!isEmpty_String(seed)) { + return utf8_String(seed); + } + return urlThemeSeed_String(url); +} + static iBool isAbsolutePath_(iRangecc path) { return isAbsolute_Path(collect_String(urlDecode_String(collect_String(newRange_String(path))))); } diff --git a/src/gmutil.h b/src/gmutil.h index c9d7baae..01eb8e52 100644 --- a/src/gmutil.h +++ b/src/gmutil.h @@ -120,6 +120,7 @@ uint16_t urlPort_String (const iString *); iRangecc urlUser_String (const iString *); iRangecc urlRoot_String (const iString *); const iBlock * urlThemeSeed_String (const iString *); +const iBlock * urlPaletteSeed_String (const iString *); const iString * absoluteUrl_String (const iString *, const iString *urlMaybeRelative); iBool isLikelyUrl_String (const iString *); diff --git a/src/sitespec.c b/src/sitespec.c index fe80ad13..31094981 100644 --- a/src/sitespec.c +++ b/src/sitespec.c @@ -37,7 +37,8 @@ struct Impl_SiteParams { iString titanIdentity; /* fingerprint */ int dismissWarnings; iStringArray usedIdentities; /* fingerprints; latest ones at the end */ - /* TODO: theme seed, style settings */ + iString paletteSeed; + /* TODO: style settings */ }; void init_SiteParams(iSiteParams *d) { @@ -45,9 +46,11 @@ void init_SiteParams(iSiteParams *d) { init_String(&d->titanIdentity); d->dismissWarnings = 0; init_StringArray(&d->usedIdentities); + init_String(&d->paletteSeed); } void deinit_SiteParams(iSiteParams *d) { + deinit_String(&d->paletteSeed); deinit_StringArray(&d->usedIdentities); deinit_String(&d->titanIdentity); } @@ -149,6 +152,9 @@ static void handleIniKeyValue_SiteSpec_(void *context, const iString *table, con pushBack_StringArray(&d->loadParams->usedIdentities, collectNewRange_String(seg)); } } + else if (!cmp_String(key, "paletteSeed") && value->type == string_TomlType) { + set_String(&d->loadParams->paletteSeed, value->value.string); + } } static iBool load_SiteSpec_(iSiteSpec *d) { @@ -190,6 +196,11 @@ static void save_SiteSpec_(iSiteSpec *d) { "usedIdentities = \"%s\"\n", cstrCollect_String(joinCStr_StringArray(¶ms->usedIdentities, " "))); } + if (!isEmpty_String(¶ms->paletteSeed)) { + appendCStr_String(buf, "paletteSeed = \""); + append_String(buf, collect_String(quote_String(¶ms->paletteSeed, iFalse))); + appendCStr_String(buf, "\"\n"); + } appendCStr_String(buf, "\n"); write_File(f, utf8_String(buf)); iEndCollect(); diff --git a/src/sitespec.h b/src/sitespec.h index 11c40e3c..372e021e 100644 --- a/src/sitespec.h +++ b/src/sitespec.h @@ -31,6 +31,7 @@ enum iSiteSpecKey { titanIdentity_SiteSpecKey, /* String */ dismissWarnings_SiteSpecKey, /* int */ usedIdentities_SiteSpecKey, /* StringArray */ + paletteSeed_SiteSpecKey, /* String */ }; void init_SiteSpec (const char *saveDir); diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 293e4507..7d9ac154 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -3936,12 +3936,12 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) const char *unchecked = red_ColorEscape "\u2610"; const char *checked = green_ColorEscape "\u2611"; const iBool haveFingerprint = (d->certFlags & haveFingerprint_GmCertFlag) != 0; - const int requiredForTrust = (available_GmCertFlag | haveFingerprint_GmCertFlag | - timeVerified_GmCertFlag); + const int requiredForTrust = + (available_GmCertFlag | haveFingerprint_GmCertFlag | timeVerified_GmCertFlag); const iBool canTrust = ~d->certFlags & trusted_GmCertFlag && ((d->certFlags & requiredForTrust) == requiredForTrust); const iRecentUrl *recent = constMostRecentUrl_History(d->mod.history); - const iString *meta = &d->sourceMime; + const iString *meta = &d->sourceMime; if (recent && recent->cachedResponse) { meta = &recent->cachedResponse->meta; } @@ -4006,6 +4006,10 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) if (haveFingerprint) { pushBack_Array(items, &(iMenuItem){ "${dlg.cert.fingerprint}", 0, 0, "server.copycert" }); } + const iRangecc root = urlRoot_String(d->mod.url); + if (!isEmpty_Range(&root)) { + pushBack_Array(items, &(iMenuItem){ "${pageinfo.settings}", 0, 0, "document.sitespec" }); + } if (!isEmpty_Array(items)) { pushBack_Array(items, &(iMenuItem){ "---", 0, 0, 0 }); } @@ -4937,7 +4941,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e for (size_t i = 0; i < 64; ++i) { setByte_Block(seed, i, iRandom(0, 256)); } - setThemeSeed_GmDocument(view->doc, seed); + setThemeSeed_GmDocument(view->doc, seed, NULL); delete_Block(seed); invalidate_DocumentWidget_(d); refresh_Widget(w); diff --git a/src/ui/util.c b/src/ui/util.c index befc2fd5..54715121 100644 --- a/src/ui/util.c +++ b/src/ui/util.c @@ -3169,15 +3169,14 @@ static iBool handleFeedSettingCommands_(iWidget *dlg, const char *cmd) { } iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { - const char *headingText = bookmarkId ? uiHeading_ColorEscape "${heading.feedcfg}" - : uiHeading_ColorEscape "${heading.subscribe}"; - const iMenuItem actions[] = { { "${cancel}" }, - { bookmarkId ? uiTextCaution_ColorEscape "${dlg.feed.save}" - : uiTextCaution_ColorEscape "${dlg.feed.sub}", - SDLK_RETURN, - KMOD_PRIMARY, - format_CStr("feedcfg.accept bmid:%d", bookmarkId) } }; - iWidget *dlg; + iWidget *dlg; + const char *headingText = bookmarkId ? "${heading.feedcfg}" : "${heading.subscribe}"; + const iMenuItem actions[] = { { "${cancel}" }, + { bookmarkId ? uiTextCaution_ColorEscape "${dlg.feed.save}" + : uiTextCaution_ColorEscape "${dlg.feed.sub}", + SDLK_RETURN, + KMOD_PRIMARY, + format_CStr("feedcfg.accept bmid:%d", bookmarkId) } }; if (isUsingPanelLayout_Mobile()) { const iMenuItem typeItems[] = { { "button id:feedcfg.type.gemini label:dlg.feed.type.gemini", 0, 0, "feedcfg.type arg:0" }, @@ -3234,6 +3233,32 @@ iWidget *makeFeedSettings_Widget(uint32_t bookmarkId) { return dlg; } +iWidget *makeSiteSpecificSettings_Widget(const iString *url) { + iWidget *dlg; + const iMenuItem actions[] = { + { "${cancel}" }, { "${sitespec.accept}", SDLK_RETURN, KMOD_PRIMARY, "sitespec.accept" } + }; + if (isUsingPanelLayout_Mobile()) { + iAssert(iFalse); + } + else { + iWidget *headings, *values; + dlg = makeSheet_Widget("sitespec"); + addDialogTitle_(dlg, "${heading.sitespec}", "heading.sitespec"); + addChild_Widget(dlg, iClob(makeTwoColumns_Widget(&headings, &values))); + addDialogToggle_(headings, values, "${sitespec.ansi}", "sitespec.ansi"); + iInputWidget *palInput = new_InputWidget(0); + addPrefsInputWithHeading_(headings, values, "sitespec.palette", iClob(palInput)); + as_Widget(palInput)->rect.size.x = 80 * gap_UI; + addChild_Widget(dlg, iClob(makeDialogButtons_Widget(actions, iElemCount(actions)))); + } + /* Initialize. */ { + const iRangecc root = urlRoot_String(url); + + } + return dlg; +} + iWidget *makeIdentityCreation_Widget(void) { const iMenuItem actions[] = { { "${dlg.newident.more}", 0, 0, "ident.showmore" }, { "---" }, diff --git a/src/ui/util.h b/src/ui/util.h index 0289d579..31c8cedc 100644 --- a/src/ui/util.h +++ b/src/ui/util.h @@ -336,13 +336,14 @@ iWidget * makeQuestion_Widget (const char *title, const char *msg, iWidget * makePreferences_Widget (void); void updatePreferencesLayout_Widget (iWidget *prefs); -iWidget * makeBookmarkEditor_Widget (void); -void setBookmarkEditorFolder_Widget(iWidget *editor, uint32_t folderId); -iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon); -iWidget * makeIdentityCreation_Widget (void); -iWidget * makeFeedSettings_Widget (uint32_t bookmarkId); -iWidget * makeTranslation_Widget (iWidget *parent); -iWidget * makeGlyphFinder_Widget (void); +iWidget * makeBookmarkEditor_Widget (void); +void setBookmarkEditorFolder_Widget (iWidget *editor, uint32_t folderId); +iWidget * makeBookmarkCreation_Widget (const iString *url, const iString *title, iChar icon); +iWidget * makeIdentityCreation_Widget (void); +iWidget * makeFeedSettings_Widget (uint32_t bookmarkId); +iWidget * makeSiteSpecificSettings_Widget (const iString *url); +iWidget * makeTranslation_Widget (iWidget *parent); +iWidget * makeGlyphFinder_Widget (void); const char * languageId_String (const iString *menuItemLabel); int languageIndex_CStr (const char *langId); -- 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/gmutil.h') 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