diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:27:15 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-07-25 14:27:15 +0300 |
commit | b5eef5cbddab73c7bdcd5be00e8228377b0a4ef1 (patch) | |
tree | 89e1b746b41b657ba95e940e37d2b044ee80f162 /src/ui | |
parent | 570818dfd9f979a04375bbe0657139c62df34387 (diff) |
DocumentWidget: Context menu
Diffstat (limited to 'src/ui')
-rw-r--r-- | src/ui/documentwidget.c | 21 | ||||
-rw-r--r-- | src/ui/window.c | 4 |
2 files changed, 10 insertions, 15 deletions
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 { | |||
37 | const iGmRun *hoverLink; | 37 | const iGmRun *hoverLink; |
38 | iClick click; | 38 | iClick click; |
39 | iScrollWidget *scroll; | 39 | iScrollWidget *scroll; |
40 | iWidget *menu; | ||
40 | }; | 41 | }; |
41 | 42 | ||
42 | iDefineObjectConstruction(DocumentWidget) | 43 | iDefineObjectConstruction(DocumentWidget) |
@@ -56,6 +57,13 @@ void init_DocumentWidget(iDocumentWidget *d) { | |||
56 | init_PtrArray(&d->visibleLinks); | 57 | init_PtrArray(&d->visibleLinks); |
57 | init_Click(&d->click, d, SDL_BUTTON_LEFT); | 58 | init_Click(&d->click, d, SDL_BUTTON_LEFT); |
58 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); | 59 | addChild_Widget(w, iClob(d->scroll = new_ScrollWidget())); |
60 | d->menu = | ||
61 | makeMenu_Widget(w, | ||
62 | (iMenuItem[]){ { "Back", SDLK_LEFT, KMOD_PRIMARY, "navigate.back" }, | ||
63 | { "Forward", SDLK_RIGHT, KMOD_PRIMARY, "navigate.forward" }, | ||
64 | { "---", 0, 0, NULL }, | ||
65 | { "Reload", 'r', KMOD_PRIMARY, "navigate.reload" } }, | ||
66 | 4); | ||
59 | } | 67 | } |
60 | 68 | ||
61 | void deinit_DocumentWidget(iDocumentWidget *d) { | 69 | void deinit_DocumentWidget(iDocumentWidget *d) { |
@@ -82,12 +90,6 @@ static iRect documentBounds_DocumentWidget_(const iDocumentWidget *d) { | |||
82 | return rect; | 90 | return rect; |
83 | } | 91 | } |
84 | 92 | ||
85 | static iRangecc getLine_(iRangecc text) { | ||
86 | iRangecc line = { text.start, text.start }; | ||
87 | for (; *line.end != '\n' && line.end != text.end; line.end++) {} | ||
88 | return line; | ||
89 | } | ||
90 | |||
91 | static void requestUpdated_DocumentWidget_(iAnyObject *obj) { | 93 | static void requestUpdated_DocumentWidget_(iAnyObject *obj) { |
92 | iDocumentWidget *d = obj; | 94 | iDocumentWidget *d = obj; |
93 | const int wasPending = exchange_Atomic(&d->isSourcePending, iTrue); | 95 | const int wasPending = exchange_Atomic(&d->isSourcePending, iTrue); |
@@ -335,12 +337,6 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
335 | case ' ': | 337 | case ' ': |
336 | postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1); | 338 | postCommand_Widget(w, "scroll.page arg:%d", key == SDLK_PAGEUP ? -1 : +1); |
337 | return iTrue; | 339 | return iTrue; |
338 | case 'r': | ||
339 | if (mods == KMOD_PRIMARY) { | ||
340 | fetch_DocumentWidget_(d); | ||
341 | return iTrue; | ||
342 | } | ||
343 | break; | ||
344 | case '0': { | 340 | case '0': { |
345 | extern int enableHalfPixelGlyphs_Text; | 341 | extern int enableHalfPixelGlyphs_Text; |
346 | enableHalfPixelGlyphs_Text = !enableHalfPixelGlyphs_Text; | 342 | enableHalfPixelGlyphs_Text = !enableHalfPixelGlyphs_Text; |
@@ -372,6 +368,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
372 | refresh_Widget(w); | 368 | refresh_Widget(w); |
373 | } | 369 | } |
374 | } | 370 | } |
371 | processContextMenuEvent_Widget(d->menu, ev); | ||
375 | switch (processEvent_Click(&d->click, ev)) { | 372 | switch (processEvent_Click(&d->click, ev)) { |
376 | case finished_ClickResult: | 373 | case finished_ClickResult: |
377 | if (d->hoverLink) { | 374 | 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) { | |||
81 | if (equal_Command(cmd, "input.ended")) { | 81 | if (equal_Command(cmd, "input.ended")) { |
82 | iInputWidget *url = findChild_Widget(navBar, "url"); | 82 | iInputWidget *url = findChild_Widget(navBar, "url"); |
83 | if (arg_Command(cmd) && pointer_Command(cmd) == url) { | 83 | if (arg_Command(cmd) && pointer_Command(cmd) == url) { |
84 | postCommandf_App( | 84 | postCommandf_App("open url:%s", cstr_String(text_InputWidget(url))); |
85 | "open url:%s", | ||
86 | cstr_String(text_InputWidget(url))); | ||
87 | return iTrue; | 85 | return iTrue; |
88 | } | 86 | } |
89 | } | 87 | } |