summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-29 19:43:48 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-29 19:43:48 +0200
commitc5f9a431f3b42c3a34578f5406b5e39a9eec9cd0 (patch)
treefc84f1605ca9502d86ba3a33be7c4015875ef433 /src
parente8f06bd0985ce2c9ac5ef02525672a426d559d18 (diff)
iOS: Sharing file content and selected text
Diffstat (limited to 'src')
-rw-r--r--src/app.c28
-rw-r--r--src/gmrequest.c2
-rw-r--r--src/ios.h1
-rw-r--r--src/ios.m15
-rw-r--r--src/ui/documentwidget.c12
-rw-r--r--src/ui/mediaui.c6
6 files changed, 51 insertions, 13 deletions
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) {
3364 return; 3364 return;
3365 } 3365 }
3366#endif 3366#endif
3367#if !defined (iPlatformAppleMobile) 3367#if defined (iPlatformAppleMobile)
3368 if (equalCase_Rangecc(urlScheme_String(url), "file")) {
3369 revealPath_App(collect_String(localFilePathFromUrl_String(url)));
3370 }
3371 return;
3372#endif
3368 iProcess *proc = new_Process(); 3373 iProcess *proc = new_Process();
3369 setArguments_Process(proc, 3374 setArguments_Process(proc, iClob(newStringsCStr_StringList(
3370#if defined (iPlatformAppleDesktop) 3375#if defined (iPlatformAppleDesktop)
3371 iClob(newStringsCStr_StringList("/usr/bin/env", "open", cstr_String(url), NULL)) 3376 "/usr/bin/env",
3377 "open",
3378 cstr_String(url),
3372#elif defined (iPlatformLinux) || defined (iPlatformOther) || defined (iPlatformHaiku) 3379#elif defined (iPlatformLinux) || defined (iPlatformOther) || defined (iPlatformHaiku)
3373 iClob(newStringsCStr_StringList("/usr/bin/env", "xdg-open", cstr_String(url), NULL)) 3380 "/usr/bin/env",
3381 "xdg-open",
3382 cstr_String(url),
3374#elif defined (iPlatformMsys) 3383#elif defined (iPlatformMsys)
3375 iClob(newStringsCStr_StringList( 3384 concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"),
3376 concatPath_CStr(cstr_String(execPath_App()), "../urlopen.bat"), 3385 cstr_String(url),
3377 cstr_String(url),
3378 NULL))
3379 /* TODO: The prompt window is shown momentarily... */ 3386 /* TODO: The prompt window is shown momentarily... */
3380#endif 3387#endif
3388 NULL))
3381 ); 3389 );
3382 start_Process(proc); 3390 start_Process(proc);
3383 waitForFinished_Process(proc); /* TODO: test on Windows */ 3391 waitForFinished_Process(proc); /* TODO: test on Windows */
3384 iRelease(proc); 3392 iRelease(proc);
3385#endif
3386} 3393}
3387 3394
3388void revealPath_App(const iString *path) { 3395void revealPath_App(const iString *path) {
@@ -3392,6 +3399,9 @@ void revealPath_App(const iString *path) {
3392 proc, iClob(newStringsCStr_StringList("/usr/bin/open", "-R", cstr_String(path), NULL))); 3399 proc, iClob(newStringsCStr_StringList("/usr/bin/open", "-R", cstr_String(path), NULL)));
3393 start_Process(proc); 3400 start_Process(proc);
3394 iRelease(proc); 3401 iRelease(proc);
3402#elif defined (iPlatformAppleMobile)
3403 /* Use a share sheet. */
3404 openFileActivityView_iOS(path);
3395#elif defined (iPlatformLinux) || defined (iPlatformHaiku) 3405#elif defined (iPlatformLinux) || defined (iPlatformHaiku)
3396 iFileInfo *inf = iClob(new_FileInfo(path)); 3406 iFileInfo *inf = iClob(new_FileInfo(path));
3397 iRangecc target; 3407 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) {
694 setCStr_String(&resp->meta, "text/gemini"); 694 setCStr_String(&resp->meta, "text/gemini");
695 iString *page = collectNew_String(); 695 iString *page = collectNew_String();
696 iString *parentDir = collectNewRange_String(dirName_Path(path)); 696 iString *parentDir = collectNewRange_String(dirName_Path(path));
697#if !defined (iPlatformMobile)
697 appendFormat_String(page, "=> %s " upArrow_Icon " %s" iPathSeparator "\n\n", 698 appendFormat_String(page, "=> %s " upArrow_Icon " %s" iPathSeparator "\n\n",
698 cstrCollect_String(makeFileUrl_String(parentDir)), 699 cstrCollect_String(makeFileUrl_String(parentDir)),
699 cstr_String(parentDir)); 700 cstr_String(parentDir));
701#endif
700 appendFormat_String(page, "# %s\n", cstr_Rangecc(baseName_Path(path))); 702 appendFormat_String(page, "# %s\n", cstr_Rangecc(baseName_Path(path)));
701 /* Make a directory index page. */ 703 /* Make a directory index page. */
702 iPtrArray *sortedInfo = collectNew_PtrArray(); 704 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);
39void pickFileForOpening_iOS (void); 39void pickFileForOpening_iOS (void);
40void pickFile_iOS (const char *command); /* ` path:%s` will be appended */ 40void pickFile_iOS (const char *command); /* ` path:%s` will be appended */
41void openTextActivityView_iOS(const iString *text); 41void openTextActivityView_iOS(const iString *text);
42void openFileActivityView_iOS(const iString *path);
42 43
43iBool isPhone_iOS (void); 44iBool isPhone_iOS (void);
44void safeAreaInsets_iOS (float *left, float *top, float *right, float *bottom); 45void 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) {
536 [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil]; 536 [viewController_(get_Window()) presentViewController:picker animated:YES completion:nil];
537} 537}
538 538
539void openTextActivityView_iOS(const iString *text) { 539static void openActivityView_(NSArray *activityItems) {
540 UIActivityViewController *actView = 540 UIActivityViewController *actView =
541 [[UIActivityViewController alloc] 541 [[UIActivityViewController alloc]
542 initWithActivityItems:@[ 542 initWithActivityItems:activityItems
543 [NSString stringWithUTF8String:cstr_String(text)]]
544 applicationActivities:nil]; 543 applicationActivities:nil];
545 [viewController_(get_Window()) presentViewController:actView animated:YES completion:nil]; 544 [viewController_(get_Window()) presentViewController:actView animated:YES completion:nil];
546} 545}
547 546
547void openTextActivityView_iOS(const iString *text) {
548 openActivityView_(@[[NSString stringWithUTF8String:cstr_String(text)]]);
549}
550
551void openFileActivityView_iOS(const iString *path) {
552 NSURL *url = [NSURL fileURLWithPath:[[NSString alloc] initWithCString:cstr_String(path)
553 encoding:NSUTF8StringEncoding]];
554 openActivityView_(@[url]);
555}
556
548/*----------------------------------------------------------------------------------------------*/ 557/*----------------------------------------------------------------------------------------------*/
549 558
550enum iAVFAudioPlayerState { 559enum 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)
3945 /* Full document. */ 3945 /* Full document. */
3946 copied = copy_String(source_GmDocument(d->view.doc)); 3946 copied = copy_String(source_GmDocument(d->view.doc));
3947 } 3947 }
3948 SDL_SetClipboardText(cstr_String(copied)); 3948 if (argLabel_Command(cmd, "share")) {
3949#if defined (iPlatformAppleMobile)
3950 openTextActivityView_iOS(copied);
3951#endif
3952 }
3953 else {
3954 SDL_SetClipboardText(cstr_String(copied));
3955 }
3949 delete_String(copied); 3956 delete_String(copied);
3950 if (flags_Widget(w) & touchDrag_WidgetFlag) { 3957 if (flags_Widget(w) & touchDrag_WidgetFlag) {
3951 postCommand_Widget(w, "document.select arg:0"); 3958 postCommand_Widget(w, "document.select arg:0");
@@ -5227,6 +5234,9 @@ static iBool processEvent_DocumentWidget_(iDocumentWidget *d, const SDL_Event *e
5227 } 5234 }
5228 d->copyMenu = makeMenu_Widget(w, (iMenuItem[]){ 5235 d->copyMenu = makeMenu_Widget(w, (iMenuItem[]){
5229 { clipCopy_Icon " ${menu.copy}", 0, 0, "copy" }, 5236 { clipCopy_Icon " ${menu.copy}", 0, 0, "copy" },
5237#if defined (iPlatformAppleMobile)
5238 { export_Icon " ${menu.share}", 0, 0, "copy share:1" },
5239#endif
5230 { "---" }, 5240 { "---" },
5231 { close_Icon " ${menu.select.clear}", 0, 0, "document.select arg:0" }, 5241 { close_Icon " ${menu.select.clear}", 0, 0, "document.select arg:0" },
5232 }, 3); 5242 }, 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
@@ -263,6 +263,12 @@ iBool processEvent_DownloadUI(iDownloadUI *d, const SDL_Event *ev) {
263 0, 263 0,
264 format_CStr("!reveal path:%s", cstr_String(path)) }, 264 format_CStr("!reveal path:%s", cstr_String(path)) },
265#endif 265#endif
266#if defined (iPlatformAppleMobile)
267 { export_Icon " ${menu.share}",
268 0,
269 0,
270 format_CStr("!reveal path:%s", cstr_String(path)) },
271#endif
266 { "---" }, 272 { "---" },
267 /* Generic items */ 273 /* Generic items */
268 { "${menu.downloads}", 0, 0, "downloads.open newtab:1" }, 274 { "${menu.downloads}", 0, 0, "downloads.open newtab:1" },