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 --- 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 ++++++ 6 files changed, 51 insertions(+), 13 deletions(-) (limited to 'src') 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