summaryrefslogtreecommitdiff
path: root/src/ui/inputwidget.c
diff options
context:
space:
mode:
authorThomas Adam <thomas.adam@smoothwall.net>2021-02-07 20:58:48 +0000
committerThomas Adam <thomas.adam@smoothwall.net>2021-02-07 20:58:48 +0000
commitf7a7e6a6c318d232d95833fd04e0a9c0093c29a8 (patch)
tree808ffc13ff8c7683802f819515511b12f5587d01 /src/ui/inputwidget.c
parentb2f78fca337476513e4be2c9d9af8eee5f8080b4 (diff)
paste: refactor to allow for Shift+Ins
Under Linux/Unix, the key combination of "Shift+Ins" allows for pasting from the clipboard into most applications. Refactor pasting to its own function and define the key combination of Shift+Ins to allow for this.
Diffstat (limited to 'src/ui/inputwidget.c')
-rw-r--r--src/ui/inputwidget.c49
1 files changed, 29 insertions, 20 deletions
diff --git a/src/ui/inputwidget.c b/src/ui/inputwidget.c
index 2d767152..45214d60 100644
--- a/src/ui/inputwidget.c
+++ b/src/ui/inputwidget.c
@@ -540,6 +540,29 @@ static iBool copy_InputWidget_(iInputWidget *d, iBool doCut) {
540 return iFalse; 540 return iFalse;
541} 541}
542 542
543static void process_Paste_(iInputWidget *d) {
544 if (SDL_HasClipboardText()) {
545 pushUndo_InputWidget_(d);
546 deleteMarked_InputWidget_(d);
547 char *text = SDL_GetClipboardText();
548 iString *paste = collect_String(newCStr_String(text));
549 /* Url decoding. */
550 if (d->inFlags & isUrl_InputWidgetFlag) {
551 if (prefs_App()->decodeUserVisibleURLs) {
552 paste = collect_String(urlDecode_String(paste));
553 }
554 else {
555 urlEncodePath_String(paste);
556 }
557 }
558 SDL_free(text);
559 iConstForEach(String, i, paste) {
560 insertChar_InputWidget_(d, i.value);
561 }
562 contentsWereChanged_InputWidget_(d);
563 }
564}
565
543static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { 566static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
544 iWidget *w = as_Widget(d); 567 iWidget *w = as_Widget(d);
545 if (isCommand_Widget(w, ev, "focus.gained")) { 568 if (isCommand_Widget(w, ev, "focus.gained")) {
@@ -606,26 +629,7 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
606 copy_InputWidget_(d, key == 'x'); 629 copy_InputWidget_(d, key == 'x');
607 return iTrue; 630 return iTrue;
608 case 'v': 631 case 'v':
609 if (SDL_HasClipboardText()) { 632 process_Paste_(d);
610 pushUndo_InputWidget_(d);
611 deleteMarked_InputWidget_(d);
612 char *text = SDL_GetClipboardText();
613 iString *paste = collect_String(newCStr_String(text));
614 /* Url decoding. */
615 if (d->inFlags & isUrl_InputWidgetFlag) {
616 if (prefs_App()->decodeUserVisibleURLs) {
617 paste = collect_String(urlDecode_String(paste));
618 }
619 else {
620 urlEncodePath_String(paste);
621 }
622 }
623 SDL_free(text);
624 iConstForEach(String, i, paste) {
625 insertChar_InputWidget_(d, i.value);
626 }
627 contentsWereChanged_InputWidget_(d);
628 }
629 return iTrue; 633 return iTrue;
630 case 'z': 634 case 'z':
631 if (popUndo_InputWidget_(d)) { 635 if (popUndo_InputWidget_(d)) {
@@ -637,6 +641,11 @@ static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) {
637 } 641 }
638 d->lastCursor = d->cursor; 642 d->lastCursor = d->cursor;
639 switch (key) { 643 switch (key) {
644 case SDLK_INSERT:
645 if (mods == KMOD_SHIFT) {
646 process_Paste_(d);
647 }
648 return iTrue;
640 case SDLK_RETURN: 649 case SDLK_RETURN:
641 case SDLK_KP_ENTER: 650 case SDLK_KP_ENTER:
642 d->inFlags |= enterPressed_InputWidgetFlag; 651 d->inFlags |= enterPressed_InputWidgetFlag;