diff options
author | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-29 07:18:29 +0200 |
---|---|---|
committer | Jaakko Keränen <jaakko.keranen@iki.fi> | 2021-12-29 07:18:29 +0200 |
commit | e8f06bd0985ce2c9ac5ef02525672a426d559d18 (patch) | |
tree | 5617f7e65d81ae0b5bcf3c0c6a49711662e658f2 /src/ui/mediaui.c | |
parent | 336b9d7272ed8b1a9dccee27dec20e3377ee0c74 (diff) |
Inline download context menu; macOS: Show in Finder
The inline downloads UI finally has some interactivity: left-clicking on a finished download opens it in the default viewer app, and right-clicking shows a context menu with relevant actions.
Diffstat (limited to 'src/ui/mediaui.c')
-rw-r--r-- | src/ui/mediaui.c | 38 |
1 files changed, 38 insertions, 0 deletions
diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c index 1c828194..2aec568f 100644 --- a/src/ui/mediaui.c +++ b/src/ui/mediaui.c | |||
@@ -238,6 +238,44 @@ void init_DownloadUI(iDownloadUI *d, const iMedia *media, uint16_t mediaId, iRec | |||
238 | /*----------------------------------------------------------------------------------------------*/ | 238 | /*----------------------------------------------------------------------------------------------*/ |
239 | 239 | ||
240 | iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { | 240 | iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { |
241 | if (ev->type == SDL_MOUSEBUTTONDOWN || ev->type == SDL_MOUSEBUTTONUP) { | ||
242 | const iInt2 mouse = init_I2(ev->button.x, ev->button.y); | ||
243 | if (!contains_Rect(d->bounds, mouse)) { | ||
244 | return iFalse; | ||
245 | } | ||
246 | float bytesPerSecond; | ||
247 | const iString *path; | ||
248 | iBool isFinished; | ||
249 | downloadStats_Media(d->media, (iMediaId){ download_MediaType, d->mediaId }, | ||
250 | &path, &bytesPerSecond, &isFinished); | ||
251 | if (isFinished) { | ||
252 | if (ev->button.button == SDL_BUTTON_RIGHT && ev->type == SDL_MOUSEBUTTONDOWN) { | ||
253 | const iMenuItem items[] = { | ||
254 | /* Items related to the file */ | ||
255 | { openTab_Icon " ${menu.opentab}", | ||
256 | 0, | ||
257 | 0, | ||
258 | format_CStr("!open newtab:1 url:%s", | ||
259 | cstrCollect_String(makeFileUrl_String(path))) }, | ||
260 | #if defined (iPlatformAppleDesktop) | ||
261 | { "${menu.reveal.macos}", | ||
262 | 0, | ||
263 | 0, | ||
264 | format_CStr("!reveal path:%s", cstr_String(path)) }, | ||
265 | #endif | ||
266 | { "---" }, | ||
267 | /* Generic items */ | ||
268 | { "${menu.downloads}", 0, 0, "downloads.open newtab:1" }, | ||
269 | }; | ||
270 | openMenu_Widget(makeMenu_Widget(get_Root()->widget, items, iElemCount(items)), | ||
271 | mouse); | ||
272 | return iTrue; | ||
273 | } | ||
274 | else if (ev->button.button == SDL_BUTTON_LEFT && ev->type == SDL_MOUSEBUTTONUP) { | ||
275 | postCommandf_App("open default:1 url:%s", cstrCollect_String(makeFileUrl_String(path))); | ||
276 | } | ||
277 | } | ||
278 | } | ||
241 | return iFalse; | 279 | return iFalse; |
242 | } | 280 | } |
243 | 281 | ||