diff options
Diffstat (limited to 'src/ui/documentwidget.c')
-rw-r--r-- | src/ui/documentwidget.c | 49 |
1 files changed, 46 insertions, 3 deletions
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 53eb06bd..c8daa2e2 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -297,9 +297,46 @@ static void updateWindowTitle_DocumentWidget_(const iDocumentWidget *d) { | |||
297 | if (isEmpty_StringArray(title)) { | 297 | if (isEmpty_StringArray(title)) { |
298 | pushBackCStr_StringArray(title, "Lagrange"); | 298 | pushBackCStr_StringArray(title, "Lagrange"); |
299 | } | 299 | } |
300 | const iString *text = collect_String(joinCStr_StringArray(title, " \u2014 ")); | 300 | /* Take away parts if it doesn't fit. */ |
301 | setTitle_Window(get_Window(), text); | 301 | iLabelWidget *tabButton = tabPageButton_Widget(findWidget_App("doctabs"), d); |
302 | setTabPageLabel_Widget(findWidget_App("doctabs"), d, text); | 302 | const int avail = bounds_Widget(as_Widget(tabButton)).size.x - 3 * gap_UI; |
303 | iBool setWindow = (document_App() == d); | ||
304 | for (;;) { | ||
305 | iString *text = collect_String(joinCStr_StringArray(title, " \u2014 ")); | ||
306 | if (setWindow) { | ||
307 | /* Longest version for the window title, and omit the icon. */ | ||
308 | setTitle_Window(get_Window(), text); | ||
309 | setWindow = iFalse; | ||
310 | } | ||
311 | const iChar siteIcon = siteIcon_GmDocument(d->doc); | ||
312 | if (siteIcon) { | ||
313 | if (!isEmpty_String(text)) { | ||
314 | prependCStr_String(text, " "); | ||
315 | } | ||
316 | prependChar_String(text, siteIcon); | ||
317 | } | ||
318 | const int width = advanceRange_Text(default_FontId, range_String(text)).x; | ||
319 | if (width <= avail || | ||
320 | isEmpty_StringArray(title)) { | ||
321 | updateText_LabelWidget(tabButton, text); | ||
322 | break; | ||
323 | } | ||
324 | if (size_StringArray(title) == 1) { | ||
325 | /* Just truncate to fit. */ | ||
326 | const char *endPos; | ||
327 | tryAdvanceNoWrap_Text(default_FontId, | ||
328 | range_String(text), | ||
329 | avail - advance_Text(default_FontId, "...").x, | ||
330 | &endPos); | ||
331 | updateText_LabelWidget( | ||
332 | tabButton, | ||
333 | collectNewFormat_String("%s...", | ||
334 | cstrCollect_String(newRange_String( | ||
335 | (iRangecc){ constBegin_String(text), endPos })))); | ||
336 | break; | ||
337 | } | ||
338 | remove_StringArray(title, size_StringArray(title) - 1); | ||
339 | } | ||
303 | } | 340 | } |
304 | 341 | ||
305 | static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { | 342 | static void setSource_DocumentWidget_(iDocumentWidget *d, const iString *source) { |
@@ -446,6 +483,10 @@ iHistory *history_DocumentWidget(iDocumentWidget *d) { | |||
446 | return d->history; | 483 | return d->history; |
447 | } | 484 | } |
448 | 485 | ||
486 | const iString *url_DocumentWidget(const iDocumentWidget *d) { | ||
487 | return d->url; | ||
488 | } | ||
489 | |||
449 | void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) { | 490 | void setUrlFromCache_DocumentWidget(iDocumentWidget *d, const iString *url, iBool isFromCache) { |
450 | if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) { | 491 | if (cmpStringSc_String(d->url, url, &iCaseInsensitive)) { |
451 | set_String(d->url, url); | 492 | set_String(d->url, url); |
@@ -710,12 +751,14 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) | |||
710 | } | 751 | } |
711 | } | 752 | } |
712 | refresh_Widget(w); | 753 | refresh_Widget(w); |
754 | updateWindowTitle_DocumentWidget_(d); | ||
713 | } | 755 | } |
714 | else if (equal_Command(cmd, "tabs.changed")) { | 756 | else if (equal_Command(cmd, "tabs.changed")) { |
715 | if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) { | 757 | if (cmp_String(id_Widget(w), suffixPtr_Command(cmd, "id")) == 0) { |
716 | /* Set palette for our document. */ | 758 | /* Set palette for our document. */ |
717 | updateTheme_DocumentWidget_(d); | 759 | updateTheme_DocumentWidget_(d); |
718 | } | 760 | } |
761 | updateWindowTitle_DocumentWidget_(d); | ||
719 | return iFalse; | 762 | return iFalse; |
720 | } | 763 | } |
721 | else if (equal_Command(cmd, "server.showcert")) { | 764 | else if (equal_Command(cmd, "server.showcert")) { |