diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gmdocument.c | 18 | ||||
-rw-r--r-- | src/gmdocument.h | 12 | ||||
-rw-r--r-- | src/gmutil.c | 13 | ||||
-rw-r--r-- | src/ui/documentwidget.c | 17 | ||||
-rw-r--r-- | src/ui/window.c | 4 |
5 files changed, 46 insertions, 18 deletions
diff --git a/src/gmdocument.c b/src/gmdocument.c index 5da654c4..3dbef514 100644 --- a/src/gmdocument.c +++ b/src/gmdocument.c | |||
@@ -119,9 +119,10 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li | |||
119 | if (matchRange_RegExp(pattern, line, &m)) { | 119 | if (matchRange_RegExp(pattern, line, &m)) { |
120 | iGmLink *link = new_GmLink(); | 120 | iGmLink *link = new_GmLink(); |
121 | setRange_String(&link->url, capturedRange_RegExpMatch(&m, 1)); | 121 | setRange_String(&link->url, capturedRange_RegExpMatch(&m, 1)); |
122 | /* Check the host. */ { | 122 | /* Check the URL. */ { |
123 | iUrl parts; | 123 | iUrl parts; |
124 | init_Url(&parts, &link->url); | 124 | init_Url(&parts, &link->url); |
125 | /* Host name. */ | ||
125 | if (!isEmpty_Range(&parts.host) && | 126 | if (!isEmpty_Range(&parts.host) && |
126 | !equalCase_Rangecc(&parts.host, cstr_String(&d->localHost))) { | 127 | !equalCase_Rangecc(&parts.host, cstr_String(&d->localHost))) { |
127 | link->flags |= remote_GmLinkFlag; | 128 | link->flags |= remote_GmLinkFlag; |
@@ -138,6 +139,21 @@ static iRangecc addLink_GmDocument_(iGmDocument *d, iRangecc line, iGmLinkId *li | |||
138 | else if (equalCase_Rangecc(&parts.protocol, "file")) { | 139 | else if (equalCase_Rangecc(&parts.protocol, "file")) { |
139 | link->flags |= file_GmLinkFlag; | 140 | link->flags |= file_GmLinkFlag; |
140 | } | 141 | } |
142 | /* Check the file name extension, if present. */ | ||
143 | if (!isEmpty_Range(&parts.path)) { | ||
144 | iString *path = newRange_String(parts.path); | ||
145 | if (endsWithCase_String(path, ".gif") || endsWithCase_String(path, ".jpg") || | ||
146 | endsWithCase_String(path, ".jpeg") || endsWithCase_String(path, ".png") || | ||
147 | endsWithCase_String(path, ".tga") || endsWithCase_String(path, ".psd") || | ||
148 | endsWithCase_String(path, ".hdr") || endsWithCase_String(path, ".pic")) { | ||
149 | link->flags |= imageFileExtension_GmLinkFlag; | ||
150 | } | ||
151 | else if (endsWithCase_String(path, ".mp3") || endsWithCase_String(path, ".wav") || | ||
152 | endsWithCase_String(path, ".mid")) { | ||
153 | link->flags |= audioFileExtension_GmLinkFlag; | ||
154 | } | ||
155 | delete_String(path); | ||
156 | } | ||
141 | } | 157 | } |
142 | pushBack_PtrArray(&d->links, link); | 158 | pushBack_PtrArray(&d->links, link); |
143 | *linkId = size_PtrArray(&d->links); /* index + 1 */ | 159 | *linkId = size_PtrArray(&d->links); /* index + 1 */ |
diff --git a/src/gmdocument.h b/src/gmdocument.h index d834f9d6..c671eaaf 100644 --- a/src/gmdocument.h +++ b/src/gmdocument.h | |||
@@ -10,11 +10,13 @@ iDeclareType(GmRun) | |||
10 | typedef uint16_t iGmLinkId; | 10 | typedef uint16_t iGmLinkId; |
11 | 11 | ||
12 | enum iGmLinkFlags { | 12 | enum iGmLinkFlags { |
13 | userFriendly_GmLinkFlag = 0x1, | 13 | userFriendly_GmLinkFlag = 0x1, |
14 | remote_GmLinkFlag = 0x2, | 14 | remote_GmLinkFlag = 0x2, |
15 | http_GmLinkFlag = 0x4, | 15 | http_GmLinkFlag = 0x4, |
16 | gopher_GmLinkFlag = 0x8, | 16 | gopher_GmLinkFlag = 0x8, |
17 | file_GmLinkFlag = 0x10, | 17 | file_GmLinkFlag = 0x10, |
18 | imageFileExtension_GmLinkFlag = 0x20, | ||
19 | audioFileExtension_GmLinkFlag = 0x40, | ||
18 | }; | 20 | }; |
19 | 21 | ||
20 | struct Impl_GmRun { | 22 | struct Impl_GmRun { |
diff --git a/src/gmutil.c b/src/gmutil.c index dbaf8759..1a8d469f 100644 --- a/src/gmutil.c +++ b/src/gmutil.c | |||
@@ -5,10 +5,10 @@ | |||
5 | #include <the_Foundation/object.h> | 5 | #include <the_Foundation/object.h> |
6 | 6 | ||
7 | void init_Url(iUrl *d, const iString *text) { | 7 | void init_Url(iUrl *d, const iString *text) { |
8 | iRegExp *pattern = | 8 | iRegExp *absPat = |
9 | new_RegExp("(.+)://([^/:?]*)(:[0-9]+)?([^?]*)(\\?.*)?", caseInsensitive_RegExpOption); | 9 | new_RegExp("(.+)://([^/:?]*)(:[0-9]+)?([^?]*)(\\?.*)?", caseInsensitive_RegExpOption); |
10 | iRegExpMatch m; | 10 | iRegExpMatch m; |
11 | if (matchString_RegExp(pattern, text, &m)) { | 11 | if (matchString_RegExp(absPat, text, &m)) { |
12 | d->protocol = capturedRange_RegExpMatch(&m, 1); | 12 | d->protocol = capturedRange_RegExpMatch(&m, 1); |
13 | d->host = capturedRange_RegExpMatch(&m, 2); | 13 | d->host = capturedRange_RegExpMatch(&m, 2); |
14 | d->port = capturedRange_RegExpMatch(&m, 3); | 14 | d->port = capturedRange_RegExpMatch(&m, 3); |
@@ -20,9 +20,16 @@ void init_Url(iUrl *d, const iString *text) { | |||
20 | d->query = capturedRange_RegExpMatch(&m, 5); | 20 | d->query = capturedRange_RegExpMatch(&m, 5); |
21 | } | 21 | } |
22 | else { | 22 | else { |
23 | /* Must be a relative path. */ | ||
23 | iZap(*d); | 24 | iZap(*d); |
25 | iRegExp *relPat = new_RegExp("([^?]*)(\\?.*)?", 0); | ||
26 | if (matchString_RegExp(relPat, text, &m)) { | ||
27 | d->path = capturedRange_RegExpMatch(&m, 1); | ||
28 | d->query = capturedRange_RegExpMatch(&m, 2); | ||
29 | } | ||
30 | iRelease(relPat); | ||
24 | } | 31 | } |
25 | iRelease(pattern); | 32 | iRelease(absPat); |
26 | } | 33 | } |
27 | 34 | ||
28 | void urlEncodeSpaces_String(iString *d) { | 35 | void urlEncodeSpaces_String(iString *d) { |
diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index b681c2c8..10af43f3 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c | |||
@@ -730,18 +730,21 @@ static void drawRun_DrawContext_(void *context, const iGmRun *run) { | |||
730 | // desc = cstrFormat_String("\u2192 %s", cstr_String(collect_String(newRange_String(parts.protocol)))); | 730 | // desc = cstrFormat_String("\u2192 %s", cstr_String(collect_String(newRange_String(parts.protocol)))); |
731 | const iString *host = collect_String(newRange_String(parts.host)); | 731 | const iString *host = collect_String(newRange_String(parts.host)); |
732 | fg = linkColor_GmDocument(doc, linkId); | 732 | fg = linkColor_GmDocument(doc, linkId); |
733 | if (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag) { | 733 | const iBool showHost = (!isEmpty_String(host) && flags & userFriendly_GmLinkFlag); |
734 | // int descWidth = measure_Text(default_FontId, cstr_String(host)).x + gap_UI; | 734 | const iBool showImage = (flags & imageFileExtension_GmLinkFlag) != 0; |
735 | const iBool showAudio = (flags & audioFileExtension_GmLinkFlag) != 0; | ||
736 | if (flags & (imageFileExtension_GmLinkFlag | audioFileExtension_GmLinkFlag) || showHost) { | ||
735 | iRect linkRect = moved_Rect(run->visBounds, origin); | 737 | iRect linkRect = moved_Rect(run->visBounds, origin); |
736 | // linkRect.size.x += descWidth; | ||
737 | // fillRect_Paint(&d->paint, linkRect, teal_ColorId); | ||
738 | drawAlign_Text(default_FontId, | 738 | drawAlign_Text(default_FontId, |
739 | // init_I2(right_Rect(d->bounds), top_Rect(linkRect)), | ||
740 | topRight_Rect(linkRect), | 739 | topRight_Rect(linkRect), |
741 | fg - 1, | 740 | fg - 1, |
742 | left_Alignment, | 741 | left_Alignment, |
743 | " \u2014 %s", | 742 | " \u2014%s%s\r%c%s", |
744 | cstr_String(host)); | 743 | showHost ? " " : "", |
744 | showHost ? cstr_String(host) : "", | ||
745 | showImage || showAudio ? '0' + fg : ('0' + fg - 1), | ||
746 | showImage ? " View Image \U0001f5bc" | ||
747 | : showAudio ? " Play Audio \U0001f3b5" : ""); | ||
745 | } | 748 | } |
746 | } | 749 | } |
747 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); | 750 | const iInt2 visPos = add_I2(run->visBounds.pos, origin); |
diff --git a/src/ui/window.c b/src/ui/window.c index ad2aced8..a7291320 100644 --- a/src/ui/window.c +++ b/src/ui/window.c | |||
@@ -204,8 +204,8 @@ static void setupUserInterface_Window(iWindow *d) { | |||
204 | iInputWidget *input = new_InputWidget(0); | 204 | iInputWidget *input = new_InputWidget(0); |
205 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), | 205 | setId_Widget(addChildFlags_Widget(searchBar, iClob(input), expand_WidgetFlag), |
206 | "find.input"); | 206 | "find.input"); |
207 | addChild_Widget(searchBar, iClob(new_LabelWidget("Next", 'g', KMOD_PRIMARY, "find.next"))); | 207 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f86b ", 'g', KMOD_PRIMARY, "find.next"))); |
208 | addChild_Widget(searchBar, iClob(new_LabelWidget("Previous", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); | 208 | addChild_Widget(searchBar, iClob(new_LabelWidget(" \U0001f869 ", 'g', KMOD_PRIMARY | KMOD_SHIFT, "find.prev"))); |
209 | addChild_Widget(searchBar, iClob(new_LabelWidget("\u00d7", SDLK_ESCAPE, 0, "find.close"))); | 209 | addChild_Widget(searchBar, iClob(new_LabelWidget("\u00d7", SDLK_ESCAPE, 0, "find.close"))); |
210 | } | 210 | } |
211 | 211 | ||