diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-10 15:12:05 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-08-10 15:12:05 +0300 |
commit | fec92538eebb9c06684c71ca1e0abba995a76cf5 (patch) | |
tree | 1cbf8175abf56f2440be54a02661735dedb4218a | |
parent | 9505054c58afccdadc6dcffcb17cd1dd92f8c16e (diff) |
Opening links in a new tab; improved context menu vs. links
-rw-r--r-- | src/app.c | 47 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 10 | ||||
-rw-r--r-- | src/ui/documentwidget.h | 2 | ||||
-rw-r--r-- | src/ui/util.h | 4 |
4 files changed, 39 insertions, 24 deletions
@@ -57,6 +57,7 @@ struct Impl_App { | |||
57 | iBool pendingRefresh; | 57 | iBool pendingRefresh; |
58 | iGmCerts * certs; | 58 | iGmCerts * certs; |
59 | iVisited * visited; | 59 | iVisited * visited; |
60 | int tabEnum; | ||
60 | /* Preferences: */ | 61 | /* Preferences: */ |
61 | iBool retainWindowSize; | 62 | iBool retainWindowSize; |
62 | float uiScale; | 63 | float uiScale; |
@@ -151,6 +152,7 @@ static void init_App_(iApp *d, int argc, char **argv) { | |||
151 | d->pendingRefresh = iFalse; | 152 | d->pendingRefresh = iFalse; |
152 | d->certs = new_GmCerts(dataDir_App_); | 153 | d->certs = new_GmCerts(dataDir_App_); |
153 | d->visited = new_Visited(); | 154 | d->visited = new_Visited(); |
155 | d->tabEnum = 0; | ||
154 | loadPrefs_App_(d); | 156 | loadPrefs_App_(d); |
155 | load_Visited(d->visited, dataDir_App_); | 157 | load_Visited(d->visited, dataDir_App_); |
156 | #if defined (iHaveLoadEmbed) | 158 | #if defined (iHaveLoadEmbed) |
@@ -351,6 +353,28 @@ iDocumentWidget *document_Command(const char *cmd) { | |||
351 | return document_App(); | 353 | return document_App(); |
352 | } | 354 | } |
353 | 355 | ||
356 | iDocumentWidget *newTab_App(const iDocumentWidget *duplicateOf) { | ||
357 | iApp *d = &app_; | ||
358 | iWidget *tabs = findWidget_App("doctabs"); | ||
359 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); | ||
360 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | ||
361 | removeChild_Widget(newTabButton->parent, newTabButton); | ||
362 | iDocumentWidget *doc; | ||
363 | if (duplicateOf) { | ||
364 | doc = duplicate_DocumentWidget(duplicateOf); | ||
365 | } | ||
366 | else { | ||
367 | doc = new_DocumentWidget(); | ||
368 | } | ||
369 | setId_Widget(as_Widget(doc), format_CStr("document%03d", ++d->tabEnum)); | ||
370 | appendTabPage_Widget(tabs, iClob(doc), "", 0, 0); | ||
371 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); | ||
372 | postCommandf_App("tabs.switch page:%p", doc); | ||
373 | arrange_Widget(tabs); | ||
374 | refresh_Widget(tabs); | ||
375 | return doc; | ||
376 | } | ||
377 | |||
354 | iBool handleCommand_App(const char *cmd) { | 378 | iBool handleCommand_App(const char *cmd) { |
355 | iApp *d = &app_; | 379 | iApp *d = &app_; |
356 | if (equal_Command(cmd, "open")) { | 380 | if (equal_Command(cmd, "open")) { |
@@ -363,6 +387,9 @@ iBool handleCommand_App(const char *cmd) { | |||
363 | return iTrue; | 387 | return iTrue; |
364 | } | 388 | } |
365 | iDocumentWidget *doc = document_Command(cmd); | 389 | iDocumentWidget *doc = document_Command(cmd); |
390 | if (argLabel_Command(cmd, "newtab")) { | ||
391 | doc = newTab_App(NULL); | ||
392 | } | ||
366 | iHistory *history = history_DocumentWidget(doc); | 393 | iHistory *history = history_DocumentWidget(doc); |
367 | const iBool isHistory = argLabel_Command(cmd, "history") != 0; | 394 | const iBool isHistory = argLabel_Command(cmd, "history") != 0; |
368 | if (!isHistory) { | 395 | if (!isHistory) { |
@@ -393,27 +420,11 @@ iBool handleCommand_App(const char *cmd) { | |||
393 | return iFalse; | 420 | return iFalse; |
394 | } | 421 | } |
395 | else if (equal_Command(cmd, "tabs.new")) { | 422 | else if (equal_Command(cmd, "tabs.new")) { |
396 | iWidget *tabs = findWidget_App("doctabs"); | 423 | const iBool isDuplicate = argLabel_Command(cmd, "duplicate") != 0; |
397 | setFlags_Widget(tabs, hidden_WidgetFlag, iFalse); | 424 | iDocumentWidget *newDoc = newTab_App(isDuplicate ? document_App() : NULL); |
398 | iWidget *newTabButton = findChild_Widget(tabs, "newtab"); | ||
399 | removeChild_Widget(newTabButton->parent, newTabButton); | ||
400 | iDocumentWidget *newDoc; | ||
401 | const iBool isDuplicate = (argLabel_Command(cmd, "duplicate") != 0); | ||
402 | if (isDuplicate) { | ||
403 | newDoc = duplicate_DocumentWidget(document_App()); | ||
404 | } | ||
405 | else { | ||
406 | newDoc = new_DocumentWidget(); | ||
407 | } | ||
408 | setId_Widget(as_Widget(newDoc), format_CStr("document%03d", tabCount_Widget(tabs))); | ||
409 | appendTabPage_Widget(tabs, iClob(newDoc), "", 0, 0); | ||
410 | addChild_Widget(findChild_Widget(tabs, "tabs.buttons"), iClob(newTabButton)); | ||
411 | postCommandf_App("tabs.switch page:%p", newDoc); | ||
412 | if (!isDuplicate) { | 425 | if (!isDuplicate) { |
413 | postCommand_App("navigate.home"); | 426 | postCommand_App("navigate.home"); |
414 | } | 427 | } |
415 | arrange_Widget(tabs); | ||
416 | refresh_Widget(tabs); | ||
417 | return iTrue; | 428 | return iTrue; |
418 | } | 429 | } |
419 | else if (equal_Command(cmd, "tabs.close")) { | 430 | else if (equal_Command(cmd, "tabs.close")) { |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 2e51f253..90c270fc 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -545,7 +545,7 @@ void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBoo | |||
545 | } | 545 | } |
546 | } | 546 | } |
547 | 547 | ||
548 | iDocumentWidget *duplicate_DocumentWidget(iDocumentWidget *orig) { | 548 | iDocumentWidget *duplicate_DocumentWidget(const iDocumentWidget *orig) { |
549 | iDocumentWidget *d = new_DocumentWidget(); | 549 | iDocumentWidget *d = new_DocumentWidget(); |
550 | delete_History(d->history); | 550 | delete_History(d->history); |
551 | d->textSizePercent = orig->textSizePercent; | 551 | d->textSizePercent = orig->textSizePercent; |
@@ -1060,7 +1060,7 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1060 | return iTrue; | 1060 | return iTrue; |
1061 | } | 1061 | } |
1062 | } | 1062 | } |
1063 | processContextMenuEvent_Widget(d->menu, ev); | 1063 | processContextMenuEvent_Widget(d->menu, ev, d->hoverLink = NULL); |
1064 | switch (processEvent_Click(&d->click, ev)) { | 1064 | switch (processEvent_Click(&d->click, ev)) { |
1065 | case started_ClickResult: | 1065 | case started_ClickResult: |
1066 | d->selecting = iFalse; | 1066 | d->selecting = iFalse; |
@@ -1084,6 +1084,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1084 | return iTrue; | 1084 | return iTrue; |
1085 | } | 1085 | } |
1086 | case finished_ClickResult: | 1086 | case finished_ClickResult: |
1087 | if (isVisible_Widget(d->menu)) { | ||
1088 | closeMenu_Widget(d->menu); | ||
1089 | } | ||
1087 | if (!isMoved_Click(&d->click)) { | 1090 | if (!isMoved_Click(&d->click)) { |
1088 | if (d->hoverLink) { | 1091 | if (d->hoverLink) { |
1089 | const iGmLinkId linkId = d->hoverLink->linkId; | 1092 | const iGmLinkId linkId = d->hoverLink->linkId; |
@@ -1115,7 +1118,8 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e | |||
1115 | refresh_Widget(w); | 1118 | refresh_Widget(w); |
1116 | } | 1119 | } |
1117 | else { | 1120 | else { |
1118 | postCommandf_App("open url:%s", | 1121 | postCommandf_App("open newtab:%d url:%s", |
1122 | (SDL_GetModState() & KMOD_PRIMARY) != 0, | ||
1119 | cstr_String(absoluteUrl_String( | 1123 | cstr_String(absoluteUrl_String( |
1120 | d->url, linkUrl_GmDocument(d->doc, linkId)))); | 1124 | d->url, linkUrl_GmDocument(d->doc, linkId)))); |
1121 | } | 1125 | } |
diff --git a/src/ui/documentwidget.h b/src/ui/documentwidget.h index 5e7c3f2c..85b9a710 100644 --- a/src/ui/documentwidget.h +++ b/src/ui/documentwidget.h | |||
@@ -7,7 +7,7 @@ iDeclareType(History) | |||
7 | iDeclareWidgetClass(DocumentWidget) | 7 | iDeclareWidgetClass(DocumentWidget) |
8 | iDeclareObjectConstruction(DocumentWidget) | 8 | iDeclareObjectConstruction(DocumentWidget) |
9 | 9 | ||
10 | iDocumentWidget *duplicate_DocumentWidget (iDocumentWidget *); | 10 | iDocumentWidget *duplicate_DocumentWidget (const iDocumentWidget *); |
11 | iHistory * history_DocumentWidget (iDocumentWidget *); | 11 | iHistory * history_DocumentWidget (iDocumentWidget *); |
12 | 12 | ||
13 | const iString * url_DocumentWidget (const iDocumentWidget *); | 13 | const iString * url_DocumentWidget (const iDocumentWidget *); |
diff --git a/src/ui/util.h b/src/ui/util.h index 26066e53..b67f0a87 100644 --- a/src/ui/util.h +++ b/src/ui/util.h | |||
@@ -84,9 +84,9 @@ void closeMenu_Widget (iWidget *); | |||
84 | 84 | ||
85 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ | 85 | int checkContextMenu_Widget (iWidget *, const SDL_Event *ev); /* see macro below */ |
86 | 86 | ||
87 | #define processContextMenuEvent_Widget(menu, sdlEvent) \ | 87 | #define processContextMenuEvent_Widget(menu, sdlEvent, stmtEaten) \ |
88 | for (const int result = checkContextMenu_Widget((menu), (sdlEvent));;) { \ | 88 | for (const int result = checkContextMenu_Widget((menu), (sdlEvent));;) { \ |
89 | if (result) return result >> 1; \ | 89 | if (result) { {stmtEaten;} return result >> 1; } \ |
90 | break; \ | 90 | break; \ |
91 | } | 91 | } |
92 | 92 | ||