summaryrefslogtreecommitdiff
path: root/src/ui/uploadwidget.c
diff options
context:
space:
mode:
authorJaakko Keränen <jaakko.keranen@iki.fi>2021-12-09 15:06:02 +0200
committerJaakko Keränen <jaakko.keranen@iki.fi>2021-12-09 15:06:02 +0200
commita265ab290cc9bce2f0c305a3eaf9d743380b967b (patch)
treeb0842b3fa63ecfb7b135341e40abf70659bf1101 /src/ui/uploadwidget.c
parent38bc51a65be35488857249e5ed5949172f06ee89 (diff)
iOS: Fixes and new edit menu for UploadWidget
The sizing and behavior of the input field on the plain text upload page is much improved.
Diffstat (limited to 'src/ui/uploadwidget.c')
-rw-r--r--src/ui/uploadwidget.c92
1 files changed, 70 insertions, 22 deletions
diff --git a/src/ui/uploadwidget.c b/src/ui/uploadwidget.c
index e11970ec..58106dcb 100644
--- a/src/ui/uploadwidget.c
+++ b/src/ui/uploadwidget.c
@@ -92,17 +92,19 @@ static void updateProgress_UploadWidget_(iGmRequest *request, size_t current, si
92static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) { 92static void updateInputMaxHeight_UploadWidget_(iUploadWidget *d) {
93 iWidget *w = as_Widget(d); 93 iWidget *w = as_Widget(d);
94 /* Calculate how many lines fits vertically in the view. */ 94 /* Calculate how many lines fits vertically in the view. */
95 const iInt2 inputPos = topLeft_Rect(bounds_Widget(as_Widget(d->input))); 95 const iInt2 inputPos = topLeft_Rect(bounds_Widget(as_Widget(d->input)));
96 const int footerHeight = isUsingPanelLayout_Mobile() ? 0 : 96 int footerHeight = 0;
97 (height_Widget(d->token) + 97 if (!isUsingPanelLayout_Mobile()) {
98 height_Widget(findChild_Widget(w, "dialogbuttons")) + 98 footerHeight = (height_Widget(d->token) +
99 12 * gap_UI); 99 height_Widget(findChild_Widget(w, "dialogbuttons")) +
100 const int avail = bottom_Rect(safeRect_Root(w->root)) - footerHeight - 100 12 * gap_UI);
101 get_MainWindow()->keyboardHeight; 101 }
102 setLineLimits_InputWidget(d->input, 102 const int avail = bottom_Rect(visibleRect_Root(w->root)) - footerHeight - inputPos.y;
103 minLines_InputWidget(d->input), 103 /* On desktop, retain the previously set minLines value. */
104 iMaxi(minLines_InputWidget(d->input), 104 int minLines = isUsingPanelLayout_Mobile() ? 1 : minLines_InputWidget(d->input);
105 (avail - inputPos.y) / lineHeight_Text(font_InputWidget(d->input)))); 105 int maxLines = iMaxi(minLines, avail / lineHeight_Text(font_InputWidget(d->input)));
106 /* On mobile, the height is fixed to the available space. */
107 setLineLimits_InputWidget(d->input, isUsingPanelLayout_Mobile() ? maxLines : minLines, maxLines);
106} 108}
107 109
108static const iGmIdentity *titanIdentityForUrl_(const iString *url) { 110static const iGmIdentity *titanIdentityForUrl_(const iString *url) {
@@ -208,11 +210,7 @@ void init_UploadWidget(iUploadWidget *d) {
208 enableUploadButton_UploadWidget_(d, iFalse); 210 enableUploadButton_UploadWidget_(d, iFalse);
209 } 211 }
210 iWidget *title = findChild_Widget(w, "heading.upload.text"); 212 iWidget *title = findChild_Widget(w, "heading.upload.text");
211 iLabelWidget *menu = makeMenuButton_LabelWidget(midEllipsis_Icon, (iMenuItem[]){ 213 iLabelWidget *menu = new_LabelWidget(midEllipsis_Icon, "upload.editmenu.open");
212 { export_Icon " ${upload.text.export}", 0, 0, "upload.text.export" },
213 { "---" },
214 { delete_Icon " " uiTextCaution_ColorEscape "${menu.delete}", 0, 0, "upload.text.delete" }
215 }, 3);
216 setTextColor_LabelWidget(menu, uiTextAction_ColorId); 214 setTextColor_LabelWidget(menu, uiTextAction_ColorId);
217 setFont_LabelWidget(menu, uiLabelBigBold_FontId); 215 setFont_LabelWidget(menu, uiLabelBigBold_FontId);
218 addChildFlags_Widget(title, iClob(menu), frameless_WidgetFlag | moveToParentRightEdge_WidgetFlag); 216 addChildFlags_Widget(title, iClob(menu), frameless_WidgetFlag | moveToParentRightEdge_WidgetFlag);
@@ -428,12 +426,19 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
428 } 426 }
429 else if (equal_Command(cmd, "panel.changed")) { 427 else if (equal_Command(cmd, "panel.changed")) {
430 showOrHideUploadButton_UploadWidget_(d); 428 showOrHideUploadButton_UploadWidget_(d);
431 setFocus_Widget(NULL); 429 if (currentPanelIndex_Mobile(w) == 0) {
430 setFocus_Widget(as_Widget(d->input));
431 }
432 else {
433 setFocus_Widget(NULL);
434 }
435 refresh_Widget(d->input);
432 return iFalse; 436 return iFalse;
433 } 437 }
434#if defined (iPlatformAppleMobile) 438#if defined (iPlatformAppleMobile)
435 else if (deviceType_App() != desktop_AppDeviceType && equal_Command(cmd, "menu.opened")) { 439 else if (deviceType_App() != desktop_AppDeviceType && equal_Command(cmd, "menu.opened")) {
436 setFocus_Widget(NULL); /* overlaid text fields! */ 440 setFocus_Widget(NULL); /* overlaid text fields! */
441 refresh_Widget(d->input);
437 return iFalse; 442 return iFalse;
438 } 443 }
439#endif 444#endif
@@ -474,6 +479,44 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
474 updateIdentityDropdown_UploadWidget_(d); 479 updateIdentityDropdown_UploadWidget_(d);
475 return iTrue; 480 return iTrue;
476 } 481 }
482 if (isCommand_Widget(w, ev, "upload.editmenu.open")) {
483 setFocus_Widget(NULL);
484 refresh_Widget(as_Widget(d->input));
485 iWidget *editMenu = makeMenu_Widget(root_Widget(w), (iMenuItem[]){
486 { select_Icon " ${menu.selectall}", 0, 0, "upload.text.selectall" },
487 { export_Icon " ${menu.upload.export}", 0, 0, "upload.text.export" },
488 { "---" },
489 { delete_Icon " " uiTextCaution_ColorEscape "${menu.upload.delete}", 0, 0, "upload.text.delete" }
490 }, 4);
491 openMenu_Widget(editMenu, topLeft_Rect(bounds_Widget(as_Widget(d->input))));
492 return iTrue;
493 }
494 if (isCommand_UserEvent(ev, "upload.text.export")) {
495#if defined (iPlatformAppleMobile)
496 openTextActivityView_iOS(text_InputWidget(d->input));
497#endif
498 return iTrue;
499 }
500 if (isCommand_UserEvent(ev, "upload.text.delete")) {
501 if (argLabel_Command(command_UserEvent(ev), "confirmed")) {
502 setTextCStr_InputWidget(d->input, "");
503 setFocus_Widget(as_Widget(d->input));
504 }
505 else {
506 iWidget *confirm = makeMenu_Widget(root_Widget(w), (iMenuItem[]){
507 { delete_Icon " " uiTextCaution_ColorEscape "${menu.upload.delete.confirm}", 0, 0,
508 "upload.text.delete confirmed:1" }
509 }, 1);
510 openMenu_Widget(confirm, zero_I2());
511 }
512 return iTrue;
513 }
514 if (isCommand_UserEvent(ev, "upload.text.selectall")) {
515 setFocus_Widget(as_Widget(d->input));
516 refresh_Widget(as_Widget(d->input));
517 postCommand_Widget(d->input, "input.selectall");
518 return iTrue;
519 }
477 if (isCommand_Widget(w, ev, "upload.accept")) { 520 if (isCommand_Widget(w, ev, "upload.accept")) {
478 iBool isText; 521 iBool isText;
479 iWidget *tabs = findChild_Widget(w, "upload.tabs"); 522 iWidget *tabs = findChild_Widget(w, "upload.tabs");
@@ -569,11 +612,16 @@ static iBool processEvent_UploadWidget_(iUploadWidget *d, const SDL_Event *ev) {
569 destroy_Widget(w); 612 destroy_Widget(w);
570 return iTrue; 613 return iTrue;
571 } 614 }
572 else if (!isUsingPanelLayout_Mobile() && isCommand_Widget(w, ev, "input.resized")) { 615 else if (isCommand_Widget(w, ev, "input.resized")) {
573 resizeToLargestPage_Widget(findChild_Widget(w, "upload.tabs")); 616 if (!isUsingPanelLayout_Mobile()) {
574 arrange_Widget(w); 617 resizeToLargestPage_Widget(findChild_Widget(w, "upload.tabs"));
575 refresh_Widget(w); 618 arrange_Widget(w);
576 return iTrue; 619 refresh_Widget(w);
620 return iTrue;
621 }
622 else {
623 refresh_Widget(as_Widget(d->input));
624 }
577 } 625 }
578 else if (isCommand_Widget(w, ev, "upload.pickfile")) { 626 else if (isCommand_Widget(w, ev, "upload.pickfile")) {
579#if defined (iPlatformAppleMobile) 627#if defined (iPlatformAppleMobile)