diff options
author | Thomas Adam <thomas.adam@smoothwall.net> | 2021-02-07 20:58:48 +0000 |
---|---|---|
committer | Thomas Adam <thomas.adam@smoothwall.net> | 2021-02-07 20:58:48 +0000 |
commit | f7a7e6a6c318d232d95833fd04e0a9c0093c29a8 (patch) | |
tree | 808ffc13ff8c7683802f819515511b12f5587d01 /src | |
parent | b2f78fca337476513e4be2c9d9af8eee5f8080b4 (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')
-rw-r--r-- | src/ui/inputwidget.c | 49 |
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 | ||
543 | static 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 | |||
543 | static iBool processEvent_InputWidget_(iInputWidget *d, const SDL_Event *ev) { | 566 | static 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; |