From b5eef5cbddab73c7bdcd5be00e8228377b0a4ef1 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Sat, 25 Jul 2020 14:27:15 +0300 Subject: DocumentWidget: Context menu --- src/ui/documentwidget.c | 21 +++++++++------------ src/ui/window.c | 4 +--- 2 files changed, 10 insertions(+), 15 deletions(-) (limited to 'src') diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 4197332a..aa24be48 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -37,6 +37,7 @@ struct Impl_DocumentWidget { const iGmRun *hoverLink; iClick click; iScrollWidget *scroll; + iWidget *menu; }; iDefineObjectConstruction(DocumentWidget) @@ -56,6 +57,13 @@ void init_DocumentWidget(iDocumentWidget *d) { init_PtrArray(&d->visibleLinks); init_Click(&d->click, d, SDL_BUTTON_LEFT); addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); + d->menu = + makeMenu_Widget(w, + (iMenuItem[]){ { "Back", SDLK_LEFT, KMOD_PRIMARY, "navigate.back" }, + { "Forward", SDLK_RIGHT, KMOD_PRIMARY, "navigate.forward" }, + { "---", 0, 0, NULL }, + { "Reload", 'r', KMOD_PRIMARY, "navigate.reload" } }, + 4); } void deinit_DocumentWidget(iDocumentWidget *d) { @@ -82,12 +90,6 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { return rect; } -static iRangecc getLine_(iRangecc text) { - iRangecc line = { text.start, text.start }; - for (; *line.end != '\n' && line.end != text.end; line.end++) {} - return line; -} - static void requestUpdated_DocumentWidget_(iAnyObject *obj) { iDocumentWidget *d = obj; const int wasPending = exchange_Atomic(&d->isSourcePending, iTrue); @@ -335,12 +337,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e case ' ': postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1); return iTrue; - case 'r': - if (mods == KMOD_PRIMARY) { - fetch_DocumentWidget_(d); - return iTrue; - } - break; case '0': { extern int enableHalfPixelGlyphs_Text; enableHalfPixelGlyphs_Text = !enableHalfPixelGlyphs_Text; @@ -372,6 +368,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e refresh_Widget(w); } } + processContextMenuEvent_Widget(d->menu, ev); switch (processEvent_Click(&d->click, ev)) { case finished_ClickResult: if (d->hoverLink) { diff --git a/src/ui/window.c b/src/ui/window.c index 65228f2b..e9ed8d61 100644 --- a/src/ui/window.c +++ b/src/ui/window.c @@ -81,9 +81,7 @@ static iBool handleNavBarCommands_(iWidget *navBar, const char *cmd) { if (equal_Command(cmd, "input.ended")) { iInputWidget *url = findChild_Widget(navBar, "url"); if (arg_Command(cmd) && pointer_Command(cmd) == url) { - postCommandf_App( - "open url:%s", - cstr_String(text_InputWidget(url))); + postCommandf_App("open url:%s", cstr_String(text_InputWidget(url))); return iTrue; } } -- cgit v1.2.3