Changeset 0902edfe in mainline
- Timestamp:
- 2009-12-04T20:53:50Z (15 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 0b772f5
- Parents:
- 0f24c57
- Location:
- uspace
- Files:
-
- 2 added
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
uspace/app/edit/edit.c
r0f24c57 r0902edfe 45 45 #include <align.h> 46 46 #include <macros.h> 47 #include <clipboard.h> 47 48 #include <bool.h> 48 49 … … 119 120 spt_t const *epos); 120 121 static char *filename_prompt(char const *prompt, char const *init_value); 122 static char *range_get_str(spt_t const *spos, spt_t const *epos); 121 123 122 124 static void pane_text_display(void); … … 133 135 134 136 static bool selection_active(void); 137 static void selection_get_points(spt_t *pa, spt_t *pb); 135 138 static void selection_delete(void); 139 static void selection_copy(void); 140 static void insert_clipboard_data(void); 136 141 137 142 static void pt_get_sof(spt_t *pt); … … 321 326 case KC_E: 322 327 file_save_as(); 328 break; 329 case KC_C: 330 selection_copy(); 331 break; 332 case KC_V: 333 selection_delete(); 334 insert_clipboard_data(); 335 pane.rflags |= REDRAW_TEXT; 336 caret_update(); 323 337 break; 324 338 default: … … 579 593 } 580 594 595 /** Return contents of range as a new string. */ 596 static char *range_get_str(spt_t const *spos, spt_t const *epos) 597 { 598 char *buf; 599 spt_t sp, bep; 600 size_t bytes; 601 size_t buf_size, bpos; 602 603 buf_size = 1; 604 605 buf = malloc(buf_size); 606 if (buf == NULL) 607 return NULL; 608 609 bpos = 0; 610 sp = *spos; 611 612 while (true) { 613 sheet_copy_out(&doc.sh, &sp, epos, &buf[bpos], buf_size - bpos, 614 &bep); 615 bytes = str_size(&buf[bpos]); 616 bpos += bytes; 617 sp = bep; 618 619 if (spt_equal(&bep, epos)) 620 break; 621 622 buf_size *= 2; 623 buf = realloc(buf, buf_size); 624 if (buf == NULL) 625 return NULL; 626 } 627 628 return buf; 629 } 630 581 631 static void pane_text_display(void) 582 632 { … … 913 963 } 914 964 965 static void selection_get_points(spt_t *pa, spt_t *pb) 966 { 967 spt_t pt; 968 969 tag_get_pt(&pane.sel_start, pa); 970 tag_get_pt(&pane.caret_pos, pb); 971 972 if (spt_cmp(pa, pb) > 0) { 973 pt = *pa; 974 *pa = *pb; 975 *pb = pt; 976 } 977 } 978 915 979 /** Delete selected text. */ 916 980 static void selection_delete(void) … … 940 1004 } 941 1005 1006 static void selection_copy(void) 1007 { 1008 spt_t pa, pb; 1009 char *str; 1010 1011 selection_get_points(&pa, &pb); 1012 str = range_get_str(&pa, &pb); 1013 if (str == NULL || clipboard_put_str(str) != EOK) { 1014 status_display("Copying to clipboard failed!"); 1015 } 1016 free(str); 1017 } 1018 1019 static void insert_clipboard_data(void) 1020 { 1021 char *str; 1022 size_t off; 1023 wchar_t c; 1024 int rc; 1025 1026 rc = clipboard_get_str(&str); 1027 if (rc != EOK || str == NULL) 1028 return; 1029 1030 off = 0; 1031 1032 while (true) { 1033 c = str_decode(str, &off, STR_NO_LIMIT); 1034 if (c == '\0') 1035 break; 1036 1037 insert_char(c); 1038 } 1039 1040 free(str); 1041 } 1042 942 1043 /** Get start-of-file s-point. */ 943 1044 static void pt_get_sof(spt_t *pt) -
uspace/lib/libc/Makefile.build
r0f24c57 r0902edfe 50 50 generic/as.c \ 51 51 generic/cap.c \ 52 generic/clipboard.c \ 52 53 generic/devmap.c \ 53 54 generic/event.c \
Note:
See TracChangeset
for help on using the changeset viewer.