From c5f9a431f3b42c3a34578f5406b5e39a9eec9cd0 Mon Sep 17 00:00:00 2001 From: Jaakko Keränen Date: Wed, 29 Dec 2021 19:43:48 +0200 Subject: iOS: Sharing file content and selected text --- po/en.po | 3 +++ res/lang/cs.bin | Bin 31582 -> 31599 bytes res/lang/de.bin | Bin 30589 -> 30606 bytes res/lang/en.bin | Bin 26675 -> 26692 bytes res/lang/eo.bin | Bin 25639 -> 25656 bytes res/lang/es.bin | Bin 30413 -> 30430 bytes res/lang/es_MX.bin | Bin 27745 -> 27762 bytes res/lang/fi.bin | Bin 30246 -> 30263 bytes res/lang/fr.bin | Bin 31393 -> 31410 bytes res/lang/gl.bin | Bin 29598 -> 29615 bytes res/lang/hu.bin | Bin 31418 -> 31435 bytes res/lang/ia.bin | Bin 28745 -> 28762 bytes res/lang/ie.bin | Bin 29333 -> 29350 bytes res/lang/isv.bin | Bin 25396 -> 25413 bytes res/lang/pl.bin | Bin 30021 -> 30038 bytes res/lang/ru.bin | Bin 44781 -> 44798 bytes res/lang/sk.bin | Bin 25732 -> 25749 bytes res/lang/sr.bin | Bin 44207 -> 44224 bytes res/lang/tok.bin | Bin 27455 -> 27472 bytes res/lang/tr.bin | Bin 29639 -> 29656 bytes res/lang/uk.bin | Bin 44126 -> 44143 bytes res/lang/zh_Hans.bin | Bin 25640 -> 25657 bytes res/lang/zh_Hant.bin | Bin 25838 -> 25855 bytes src/app.c | 28 +++++++++++++++++++--------- src/gmrequest.c | 2 ++ src/ios.h | 1 + src/ios.m | 15 ++++++++++++--- src/ui/documentwidget.c | 12 +++++++++++- src/ui/mediaui.c | 6 ++++++ 29 files changed, 54 insertions(+), 13 deletions(-) diff --git a/po/en.po b/po/en.po index 49f78eb8..425243cc 100644 --- a/po/en.po +++ b/po/en.po @@ -858,6 +858,9 @@ msgstr "Download Linked File" msgid "menu.reveal.macos" msgstr "Show in Finder" +msgid "menu.share" +msgstr "Share" + msgid "link.file.delete" msgstr "Delete File" diff --git a/res/lang/cs.bin b/res/lang/cs.bin index 1c30a0a9..47a5496f 100644 Binary files a/res/lang/cs.bin and b/res/lang/cs.bin differ diff --git a/res/lang/de.bin b/res/lang/de.bin index bf05a72e..b0967918 100644 Binary files a/res/lang/de.bin and b/res/lang/de.bin differ diff --git a/res/lang/en.bin b/res/lang/en.bin index bd858ade..a918af83 100644 Binary files a/res/lang/en.bin and b/res/lang/en.bin differ diff --git a/res/lang/eo.bin b/res/lang/eo.bin index cc829562..5f5a056a 100644 Binary files a/res/lang/eo.bin and b/res/lang/eo.bin differ diff --git a/res/lang/es.bin b/res/lang/es.bin index f62291f1..91c1a9e6 100644 Binary files a/res/lang/es.bin and b/res/lang/es.bin differ diff --git a/res/lang/es_MX.bin b/res/lang/es_MX.bin index f6f88d6c..baf7e294 100644 Binary files a/res/lang/es_MX.bin and b/res/lang/es_MX.bin differ diff --git a/res/lang/fi.bin b/res/lang/fi.bin index e69245be..67ed5398 100644 Binary files a/res/lang/fi.bin and b/res/lang/fi.bin differ diff --git a/res/lang/fr.bin b/res/lang/fr.bin index 7be665e5..b4ecf798 100644 Binary files a/res/lang/fr.bin and b/res/lang/fr.bin differ diff --git a/res/lang/gl.bin b/res/lang/gl.bin index 8c1fdf24..005feca3 100644 Binary files a/res/lang/gl.bin and b/res/lang/gl.bin differ diff --git a/res/lang/hu.bin b/res/lang/hu.bin index b06c8676..4f9b6d8b 100644 Binary files a/res/lang/hu.bin and b/res/lang/hu.bin differ diff --git a/res/lang/ia.bin b/res/lang/ia.bin index 4c3b403d..d29bcee8 100644 Binary files a/res/lang/ia.bin and b/res/lang/ia.bin differ diff --git a/res/lang/ie.bin b/res/lang/ie.bin index 5e431c29..b648a56c 100644 Binary files a/res/lang/ie.bin and b/res/lang/ie.bin differ diff --git a/res/lang/isv.bin b/res/lang/isv.bin index 54cc6774..32b2cb39 100644 Binary files a/res/lang/isv.bin and b/res/lang/isv.bin differ diff --git a/res/lang/pl.bin b/res/lang/pl.bin index cf6a6b23..20fa1621 100644 Binary files a/res/lang/pl.bin and b/res/lang/pl.bin differ diff --git a/res/lang/ru.bin b/res/lang/ru.bin index 87c82a7d..6c2be568 100644 Binary files a/res/lang/ru.bin and b/res/lang/ru.bin differ diff --git a/res/lang/sk.bin b/res/lang/sk.bin index 3ac6e18c..0604ebab 100644 Binary files a/res/lang/sk.bin and b/res/lang/sk.bin differ diff --git a/res/lang/sr.bin b/res/lang/sr.bin index 5c66460d..38b56ffa 100644 Binary files a/res/lang/sr.bin and b/res/lang/sr.bin differ diff --git a/res/lang/tok.bin b/res/lang/tok.bin index 19b6d9df..c8097f29 100644 Binary files a/res/lang/tok.bin and b/res/lang/tok.bin differ diff --git a/res/lang/tr.bin b/res/lang/tr.bin index 9a8babc9..587774cc 100644 Binary files a/res/lang/tr.bin and b/res/lang/tr.bin differ diff --git a/res/lang/uk.bin b/res/lang/uk.bin index ebcb11be..18707608 100644 Binary files a/res/lang/uk.bin and b/res/lang/uk.bin differ diff --git a/res/lang/zh_Hans.bin b/res/lang/zh_Hans.bin index ab4b338a..39024cdc 100644 Binary files a/res/lang/zh_Hans.bin and b/res/lang/zh_Hans.bin differ diff --git a/res/lang/zh_Hant.bin b/res/lang/zh_Hant.bin index f166156f..59c4dcea 100644 Binary files a/res/lang/zh_Hant.bin and b/res/lang/zh_Hant.bin differ diff --git a/src/app.c b/src/app.c index e5f9a41c..bdc3a733 100644 --- a/src/app.c +++ b/src/app.c @@ -3364,25 +3364,32 @@ void openInDefaultBrowser_App(const iString *url) { return; } #endif -#if !defined (iPlatformAppleMobile) +#if defined (iPlatformAppleMobile) + if (equalCase_Rangecc(urlScheme_String(url), "file")) { + revealPath_App(collect_String(localFilePathFromUrl_String(url))); + } + return; +#endif iProcess *proc = new_Process(); - setArguments_Process(proc, + setArguments_Process(proc, iClob(newStringsCStr_StringList( #if defined (iPlatformAppleDesktop) - iClob(newStringsCStr_StringList("/usr/bin/env", "open", cstr_String(url), NULL)) + "/usr/bin/env", + "open", + cstr_String(url), #elif defined (iPlatformLinux) || defined (iPlatformOther) || defined (iPlatformHaiku) - iClob(newStringsCStr_StringList("/usr/bin/env", "xdg-open", cstr_String(url), NULL)) + "/usr/bin/env", + "xdg-open", + cstr_String(url), #elif defined (iPlatformMsys) - iClob(newStringsCStr_StringList( - concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"), - cstr_String(url), - NULL)) + concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"), + cstr_String(url), /* TODO: The prompt window is shown momentarily... */ #endif + NULL)) ); start_Process(proc); waitForFinished_Process(proc); /* TODO: test on Windows */ iRelease(proc); -#endif } void revealPath_App(const iString *path) { @@ -3392,6 +3399,9 @@ void revealPath_App(const iString *path) { proc, iClob(newStringsCStr_StringList("/usr/bin/open", "-R", cstr_String(path), NULL))); start_Process(proc); iRelease(proc); +#elif defined (iPlatformAppleMobile) + /* Use a share sheet. */ + openFileActivityView_iOS(path); #elif defined (iPlatformLinux) || defined (iPlatformHaiku) iFileInfo *inf = iClob(new_FileInfo(path)); iRangecc target; diff --git a/src/gmrequest.c b/src/gmrequest.c index c23e8499..3d5a4aef 100644 --- a/src/gmrequest.c +++ b/src/gmrequest.c @@ -694,9 +694,11 @@ void submit_GmRequest(iGmRequest *d) { setCStr_String(&resp->meta, "text/gemini"); iString *page = collectNew_String(); iString *parentDir = collectNewRange_String(dirName_Path(path)); +#if !defined (iPlatformMobile) appendFormat_String(page, "=> %s " upArrow_Icon " %s" iPathSeparator "\n\n", cstrCollect_String(makeFileUrl_String(parentDir)), cstr_String(parentDir)); +#endif appendFormat_String(page, "# %s\n", cstr_Rangecc(baseName_Path(path))); /* Make a directory index page. */ iPtrArray *sortedInfo = collectNew_PtrArray(); diff --git a/src/ios.h b/src/ios.h index bf742f1f..9860f7a2 100644 --- a/src/ios.h +++ b/src/ios.h @@ -39,6 +39,7 @@ void exportDownloadedFile_iOS(const iString *path); void pickFileForOpening_iOS (void); void pickFile_iOS (const char *command); /* ` path:%s` will be appended */ void openTextActivityView_iOS(const iString *text); +void openFileActivityView_iOS(const iString *path); iBool isPhone_iOS (void); void safeAreaInsets_iOS (float *left, float *top, float *right, float *bottom); diff --git a/src/ios.m b/src/ios.m index c9e843e4..69e09419 100644 --- a/src/ios.m +++ b/src/ios.m @@ -536,15 +536,24 @@ void pickFile_iOS(const char *command) { [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; } -void openTextActivityView_iOS(const iString *text) { +static void openActivityView_(NSArray *activityItems) { UIActivityViewController *actView = [[UIActivityViewController alloc] - initWithActivityItems:@[ - [NSString stringWithUTF8String:cstr_String(text)]] + initWithActivityItems:activityItems applicationActivities:nil]; [viewController_(get_Window()) presentViewController:actView animated:YES completion:nil]; } +void openTextActivityView_iOS(const iString *text) { + openActivityView_(@[[NSString stringWithUTF8String:cstr_String(text)]]); +} + +void openFileActivityView_iOS(const iString *path) { + NSURL *url = [NSURL fileURLWithPath:[[NSString alloc] initWithCString:cstr_String(path) + encoding:NSUTF8StringEncoding]]; + openActivityView_(@[url]); +} + /*----------------------------------------------------------------------------------------------*/ enum iAVFAudioPlayerState { diff --git a/src/ui/documentwidget.c b/src/ui/documentwidget.c index 9e5e6ea3..65de157b 100644 --- a/src/ui/documentwidget.c +++ b/src/ui/documentwidget.c @@ -3945,7 +3945,14 @@ static iBool handleCommand_DocumentWidget_(iDocumentWidget *d, const char *cmd) /* Full document. */ copied = copy_String(source_GmDocument(d->view.doc)); } - SDL_SetClipboardText(cstr_String(copied)); + if (argLabel_Command(cmd, "share")) { +#if defined (iPlatformAppleMobile) + openTextActivityView_iOS(copied); +#endif + } + else { + SDL_SetClipboardText(cstr_String(copied)); + } delete_String(copied); if (flags_Widget(w) & touchDrag_WidgetFlag) { postCommand_Widget(w, "document.select arg:0"); @@ -5227,6 +5234,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e } d->copyMenu = makeMenu_Widget(w, (iMenuItem[]){ { clipCopy_Icon " ${menu.copy}", 0, 0, "copy" }, +#if defined (iPlatformAppleMobile) + { export_Icon " ${menu.share}", 0, 0, "copy share:1" }, +#endif { "---" }, { close_Icon " ${menu.select.clear}", 0, 0, "document.select arg:0" }, }, 3); diff --git a/src/ui/mediaui.c b/src/ui/mediaui.c index 2aec568f..ab88c94a 100644 --- a/src/ui/mediaui.c +++ b/src/ui/mediaui.c @@ -262,6 +262,12 @@ iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) { 0, 0, format_CStr("!reveal path:%s", cstr_String(path)) }, +#endif +#if defined (iPlatformAppleMobile) + { export_Icon " ${menu.share}", + 0, + 0, + format_CStr("!reveal path:%s", cstr_String(path)) }, #endif { "---" }, /* Generic items */ -- cgit v1.2.3