diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-29 14:11:46 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2020-10-29 14:11:46 +0200 |
commit | 68444017d86c8912ecc26542046b005b2bad12eb (patch) | |
tree | 82809f02fe28dd18db1db23211bcc173e4ccd5e8 | |
parent | a3d56f967643ac77847dcc1669eca5144d736056 (diff) |
SidebarWidget: Improving blank Identities tab
If there are no identities, the Identities tab now shows a button for creating one, and a link to the Help documentation.
-rw-r--r-- | src/app.c | 6 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 13 | ||||
-rw-r--r-- | src/ui/listwidget.h | 2 | ||||
-rw-r--r-- | src/ui/sidebarwidget.c | 31 |
4 files changed, 51 insertions, 1 deletions
@@ -1018,6 +1018,12 @@ iBool handleCommand_App(const char *cmd) { | |||
1018 | setInitialScroll_DocumentWidget(doc, argfLabel_Command(cmd, "scroll")); | 1018 | setInitialScroll_DocumentWidget(doc, argfLabel_Command(cmd, "scroll")); |
1019 | setRedirectCount_DocumentWidget(doc, redirectCount); | 1019 | setRedirectCount_DocumentWidget(doc, redirectCount); |
1020 | setUrlFromCache_DocumentWidget(doc, url, isHistory); | 1020 | setUrlFromCache_DocumentWidget(doc, url, isHistory); |
1021 | /* Optionally, jump to a text in the document. This will only work if the document | ||
1022 | is already available, e.g., it's from "about:" or restored from cache. */ | ||
1023 | const iRangecc gotoHeading = range_Command(cmd, "gotoheading"); | ||
1024 | if (gotoHeading.start) { | ||
1025 | postCommandf_App("document.goto heading:%s", cstr_Rangecc(gotoHeading)); | ||
1026 | } | ||
1021 | } | 1027 | } |
1022 | else if (equal_Command(cmd, "document.request.cancelled")) { | 1028 | else if (equal_Command(cmd, "document.request.cancelled")) { |
1023 | /* TODO: How should cancelled requests be treated in the history? */ | 1029 | /* TODO: How should cancelled requests be treated in the history? */ |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 07b0cc63..fa375969 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -1548,6 +1548,19 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
1548 | return iTrue; | 1548 | return iTrue; |
1549 | } | 1549 | } |
1550 | else if (equal_Command(cmd, "document.goto") && document_App() == d) { | 1550 | else if (equal_Command(cmd, "document.goto") && document_App() == d) { |
1551 | const iRangecc heading = range_Command(cmd, "heading"); | ||
1552 | if (heading.start) { | ||
1553 | const char *target = cstr_Rangecc(heading); | ||
1554 | iConstForEach(Array, h, headings_GmDocument(d->doc)) { | ||
1555 | const iGmHeading *head = h.value; | ||
1556 | if (startsWithCase_Rangecc(head->text, target)) { | ||
1557 | /* TODO: A bit lazy here, the code is right down below. */ | ||
1558 | postCommandf_App("document.goto loc:%p", head->text.start); | ||
1559 | break; | ||
1560 | } | ||
1561 | } | ||
1562 | return iTrue; | ||
1563 | } | ||
1551 | const char *loc = pointerLabel_Command(cmd, "loc"); | 1564 | const char *loc = pointerLabel_Command(cmd, "loc"); |
1552 | const iGmRun *run = findRunAtLoc_GmDocument(d->doc, loc); | 1565 | const iGmRun *run = findRunAtLoc_GmDocument(d->doc, loc); |
1553 | if (run) { | 1566 | if (run) { |
diff --git a/src/ui/listwidget.h b/src/ui/listwidget.h index a6030f9d..3e1c6777 100644 --- a/src/ui/listwidget.h +++ b/src/ui/listwidget.h | |||
@@ -73,4 +73,6 @@ size_t itemIndex_ListWidget (const iListWidget *, iInt2 pos) | |||
73 | const iAnyObject * constItem_ListWidget (const iListWidget *, size_t index); | 73 | const iAnyObject * constItem_ListWidget (const iListWidget *, size_t index); |
74 | const iAnyObject * constHoverItem_ListWidget (const iListWidget *); | 74 | const iAnyObject * constHoverItem_ListWidget (const iListWidget *); |
75 | 75 | ||
76 | iLocalDef isEmpty_ListWidget(const iListWidget *d) { return numItems_ListWidget(d) == 0; } | ||
77 | |||
76 | iBool isMouseDown_ListWidget (const iListWidget *); | 78 | iBool isMouseDown_ListWidget (const iListWidget *); |
diff --git a/src/ui/sidebarwidget.c b/src/ui/sidebarwidget.c index d311ca92..e0ec9083 100644 --- a/src/ui/sidebarwidget.c +++ b/src/ui/sidebarwidget.c | |||
@@ -83,6 +83,7 @@ iDefineObjectConstruction(SidebarItem) | |||
83 | struct Impl_SidebarWidget { | 83 | struct Impl_SidebarWidget { |
84 | iWidget widget; | 84 | iWidget widget; |
85 | enum iSidebarMode mode; | 85 | enum iSidebarMode mode; |
86 | iWidget *blank; | ||
86 | iListWidget *list; | 87 | iListWidget *list; |
87 | int modeScroll[max_SidebarMode]; | 88 | int modeScroll[max_SidebarMode]; |
88 | int width; | 89 | int width; |
@@ -106,6 +107,7 @@ static int cmpTitle_Bookmark_(const iBookmark **a, const iBookmark **b) { | |||
106 | 107 | ||
107 | static void updateItems_SidebarWidget_(iSidebarWidget *d) { | 108 | static void updateItems_SidebarWidget_(iSidebarWidget *d) { |
108 | clear_ListWidget(d->list); | 109 | clear_ListWidget(d->list); |
110 | releaseChildren_Widget(d->blank); | ||
109 | destroy_Widget(d->menu); | 111 | destroy_Widget(d->menu); |
110 | d->menu = NULL; | 112 | d->menu = NULL; |
111 | switch (d->mode) { | 113 | switch (d->mode) { |
@@ -224,6 +226,28 @@ static void updateItems_SidebarWidget_(iSidebarWidget *d) { | |||
224 | addItem_ListWidget(d->list, item); | 226 | addItem_ListWidget(d->list, item); |
225 | iRelease(item); | 227 | iRelease(item); |
226 | } | 228 | } |
229 | if (isEmpty_ListWidget(d->list)) { | ||
230 | iWidget *div = makeVDiv_Widget(); | ||
231 | setPadding_Widget(div, 3 * gap_UI, 0, 3 * gap_UI, 0); | ||
232 | addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag); /* pad */ | ||
233 | iLabelWidget *msg = new_LabelWidget("No Identities", 0, 0, NULL); | ||
234 | setFont_LabelWidget(msg, uiLabelLarge_FontId); | ||
235 | addChildFlags_Widget(div, iClob(msg), frameless_WidgetFlag); | ||
236 | addChild_Widget(div, iClob(makePadding_Widget(3 * gap_UI))); | ||
237 | addChild_Widget(div, iClob(new_LabelWidget("New Identity...", 0, 0, "ident.new"))); | ||
238 | addChild_Widget(div, iClob(makePadding_Widget(3 * gap_UI))); | ||
239 | addChildFlags_Widget( | ||
240 | div, | ||
241 | iClob(new_LabelWidget("See " uiTextStrong_ColorEscape "Help" uiText_ColorEscape | ||
242 | " for more information about TLS client certificates.", | ||
243 | 0, | ||
244 | 0, | ||
245 | "!open newtab:1 gotoheading:Identities url:about:help")), | ||
246 | frameless_WidgetFlag | fixedHeight_WidgetFlag | wrapText_WidgetFlag); | ||
247 | addChildFlags_Widget(div, iClob(new_Widget()), expand_WidgetFlag); /* pad */ | ||
248 | addChild_Widget(d->blank, iClob(div)); | ||
249 | arrange_Widget(d->blank); | ||
250 | } | ||
227 | const iMenuItem menuItems[] = { | 251 | const iMenuItem menuItems[] = { |
228 | { "Use on This Page", 0, 0, "ident.use arg:1" }, | 252 | { "Use on This Page", 0, 0, "ident.use arg:1" }, |
229 | { "Stop Using This Page", 0, 0, "ident.use arg:0" }, | 253 | { "Stop Using This Page", 0, 0, "ident.use arg:0" }, |
@@ -320,9 +344,14 @@ void init_SidebarWidget(iSidebarWidget *d) { | |||
320 | iClob(buttons), | 344 | iClob(buttons), |
321 | arrangeHorizontal_WidgetFlag | resizeWidthOfChildren_WidgetFlag | | 345 | arrangeHorizontal_WidgetFlag | resizeWidthOfChildren_WidgetFlag | |
322 | arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); | 346 | arrangeHeight_WidgetFlag | resizeToParentWidth_WidgetFlag); |
347 | iWidget *content = new_Widget(); | ||
348 | setFlags_Widget(content, resizeChildren_WidgetFlag, iTrue); | ||
323 | d->list = new_ListWidget(); | 349 | d->list = new_ListWidget(); |
324 | setPadding_Widget(as_Widget(d->list), 0, gap_UI, 0, gap_UI); | 350 | setPadding_Widget(as_Widget(d->list), 0, gap_UI, 0, gap_UI); |
325 | addChildFlags_Widget(vdiv, iClob(d->list), expand_WidgetFlag); | 351 | addChild_Widget(content, iClob(d->list)); |
352 | d->blank = new_Widget(); | ||
353 | addChildFlags_Widget(content, iClob(d->blank), resizeChildren_WidgetFlag); | ||
354 | addChildFlags_Widget(vdiv, iClob(content), expand_WidgetFlag); | ||
326 | setMode_SidebarWidget(d, bookmarks_SidebarMode); | 355 | setMode_SidebarWidget(d, bookmarks_SidebarMode); |
327 | d->resizer = addChildFlags_Widget( | 356 | d->resizer = addChildFlags_Widget( |
328 | w, | 357 | w, |