diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-08 07:49:08 +0300 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-09-08 07:49:08 +0300 |
commit | 5ae35b010cfb44d3930cfc900bc71ff2449d39f7 (patch) | |
tree | d126e1cb97194ebcc1ea4e136c3a39ddb90798c8 /src/ui/lookupwidget.c | |
parent | 92efe35c6b1ef4bea6aa1e43faf42610c1597340 (diff) |
LookupWidget: Identities lookup and commands
Diffstat (limited to 'src/ui/lookupwidget.c')
-rw-r--r-- | src/ui/lookupwidget.c | 56 |
1 files changed, 47 insertions, 9 deletions
diff --git a/src/ui/lookupwidget.c b/src/ui/lookupwidget.c index dbe734bf..676f8678 100644 --- a/src/ui/lookupwidget.c +++ b/src/ui/lookupwidget.c | |||
@@ -422,6 +422,8 @@ static void presentResults_LookupWidget_(iLookupWidget *d) { | |||
422 | clear_ListWidget(d->list); | 422 | clear_ListWidget(d->list); |
423 | sort_Array(&job->results, cmpPtr_LookupResult_); | 423 | sort_Array(&job->results, cmpPtr_LookupResult_); |
424 | enum iLookupResultType lastType = none_LookupResultType; | 424 | enum iLookupResultType lastType = none_LookupResultType; |
425 | const size_t maxPerType = 10; /* TODO: Setting? */ | ||
426 | size_t perType = 0; | ||
425 | iConstForEach(PtrArray, i, &job->results) { | 427 | iConstForEach(PtrArray, i, &job->results) { |
426 | const iLookupResult *res = i.ptr; | 428 | const iLookupResult *res = i.ptr; |
427 | if (lastType != res->type) { | 429 | if (lastType != res->type) { |
@@ -434,6 +436,42 @@ static void presentResults_LookupWidget_(iLookupWidget *d) { | |||
434 | addItem_ListWidget(d->list, item); | 436 | addItem_ListWidget(d->list, item); |
435 | iRelease(item); | 437 | iRelease(item); |
436 | lastType = res->type; | 438 | lastType = res->type; |
439 | perType = 0; | ||
440 | } | ||
441 | if (perType > maxPerType) { | ||
442 | continue; | ||
443 | } | ||
444 | if (res->type == identity_LookupResultType) { | ||
445 | const iString *docUrl = url_DocumentWidget(document_App()); | ||
446 | iBlock *finger = hexDecode_Rangecc(range_String(&res->meta)); | ||
447 | const iGmIdentity *ident = findIdentity_GmCerts(certs_App(), finger); | ||
448 | /* Sign in/out. */ { | ||
449 | const iBool isUsed = isUsedOn_GmIdentity(ident, docUrl); | ||
450 | iLookupItem *item = new_LookupItem(res); | ||
451 | item->fg = uiText_ColorId; | ||
452 | item->font = uiContent_FontId; | ||
453 | format_String(&item->text, | ||
454 | "%s \u2014 " uiTextStrong_ColorEscape "%s on this page", | ||
455 | cstr_String(&res->label), | ||
456 | isUsed ? "Stop using" : "Use"); | ||
457 | format_String(&item->command, "ident.sign%s ident:%s url:%s", | ||
458 | isUsed ? "out arg:0" : "in", cstr_String(&res->meta), cstr_String(docUrl)); | ||
459 | addItem_ListWidget(d->list, item); | ||
460 | iRelease(item); | ||
461 | } | ||
462 | if (isUsed_GmIdentity(ident)) { | ||
463 | iLookupItem *item = new_LookupItem(res); | ||
464 | item->fg = uiText_ColorId; | ||
465 | item->font = uiContent_FontId; | ||
466 | format_String(&item->text, | ||
467 | "%s \u2014 " uiTextStrong_ColorEscape "Stop using everywhere", | ||
468 | cstr_String(&res->label)); | ||
469 | format_String(&item->command, "ident.signout arg:1 ident:%s", cstr_String(&res->meta)); | ||
470 | addItem_ListWidget(d->list, item); | ||
471 | iRelease(item); | ||
472 | } | ||
473 | delete_Block(finger); | ||
474 | continue; | ||
437 | } | 475 | } |
438 | iLookupItem *item = new_LookupItem(res); | 476 | iLookupItem *item = new_LookupItem(res); |
439 | const char *url = cstr_String(&res->url); | 477 | const char *url = cstr_String(&res->url); |
@@ -463,19 +501,16 @@ static void presentResults_LookupWidget_(iLookupWidget *d) { | |||
463 | case content_LookupResultType: { | 501 | case content_LookupResultType: { |
464 | item->fg = uiText_ColorId; | 502 | item->fg = uiText_ColorId; |
465 | item->font = uiContent_FontId; | 503 | item->font = uiContent_FontId; |
466 | format_String(&item->text, "%s \u2014 %s", cstr_String(&res->label), url); | 504 | format_String(&item->text, "%s \u2014 pe%s", url, cstr_String(&res->label)); |
467 | format_String(&item->command, "open url:%s", cstr_String(&res->url)); | 505 | format_String(&item->command, "open url:%s", cstr_String(&res->url)); |
468 | break; | 506 | break; |
469 | } | 507 | } |
470 | case identity_LookupResultType: { | 508 | default: |
471 | item->fg = uiText_ColorId; | ||
472 | item->font = uiContent_FontId; | ||
473 | format_String(&item->text, "%s", cstr_String(&res->label)); | ||
474 | break; | 509 | break; |
475 | } | ||
476 | } | 510 | } |
477 | addItem_ListWidget(d->list, item); | 511 | addItem_ListWidget(d->list, item); |
478 | iRelease(item); | 512 | iRelease(item); |
513 | perType++; | ||
479 | } | 514 | } |
480 | delete_LookupJob(job); | 515 | delete_LookupJob(job); |
481 | /* Re-select the item at the cursor. */ | 516 | /* Re-select the item at the cursor. */ |
@@ -483,6 +518,7 @@ static void presentResults_LookupWidget_(iLookupWidget *d) { | |||
483 | d->cursor = iMin(d->cursor, numItems_ListWidget(d->list) - 1); | 518 | d->cursor = iMin(d->cursor, numItems_ListWidget(d->list) - 1); |
484 | ((iListItem *) item_ListWidget(d->list, d->cursor))->isSelected = iTrue; | 519 | ((iListItem *) item_ListWidget(d->list, d->cursor))->isSelected = iTrue; |
485 | } | 520 | } |
521 | scrollOffset_ListWidget(d->list, 0); | ||
486 | updateVisible_ListWidget(d->list); | 522 | updateVisible_ListWidget(d->list); |
487 | invalidate_ListWidget(d->list); | 523 | invalidate_ListWidget(d->list); |
488 | setFlags_Widget(as_Widget(d), hidden_WidgetFlag, numItems_ListWidget(d->list) == 0); | 524 | setFlags_Widget(as_Widget(d), hidden_WidgetFlag, numItems_ListWidget(d->list) == 0); |
@@ -557,13 +593,15 @@ static iBool processEvent_LookupWidget_(iLookupWidget *d, const SDL_Event *ev) { | |||
557 | } | 593 | } |
558 | } | 594 | } |
559 | if (isCommand_Widget(w, ev, "list.clicked")) { | 595 | if (isCommand_Widget(w, ev, "list.clicked")) { |
560 | setTextCStr_InputWidget(findWidget_App("url"), ""); | 596 | iInputWidget *url = findWidget_App("url"); |
597 | // setTextCStr_InputWidget(findWidget_App("url"), ""); | ||
561 | const iLookupItem *item = constItem_ListWidget(d->list, arg_Command(cmd)); | 598 | const iLookupItem *item = constItem_ListWidget(d->list, arg_Command(cmd)); |
562 | if (item && !isEmpty_String(&item->command)) { | 599 | if (item && !isEmpty_String(&item->command)) { |
563 | postCommandString_App(&item->command); | 600 | setText_InputWidget(url, url_DocumentWidget(document_App())); |
601 | setFocus_Widget(NULL); | ||
564 | setFlags_Widget(w, hidden_WidgetFlag, iTrue); | 602 | setFlags_Widget(w, hidden_WidgetFlag, iTrue); |
565 | setCursor_LookupWidget_(d, iInvalidPos); | 603 | setCursor_LookupWidget_(d, iInvalidPos); |
566 | setFocus_Widget(NULL); | 604 | postCommandString_App(&item->command); |
567 | } | 605 | } |
568 | return iTrue; | 606 | return iTrue; |
569 | } | 607 | } |