~ubuntu-branches/ubuntu/trusty/blender/trusty-proposed

« back to all changes in this revision

Viewing changes to source/blender/editors/space_text/text_ops.c

  • Committer: Package Import Robot
  • Author(s): Matteo F. Vescovi
  • Date: 2013-08-14 10:43:49 UTC
  • mfrom: (14.2.19 sid)
  • Revision ID: package-import@ubuntu.com-20130814104349-t1d5mtwkphp12dyj
Tags: 2.68a-3
* Upload to unstable
* debian/: python3.3 Depends simplified
  - debian/control: python3.3 Depends dropped
    for blender-data package
  - 0001-blender_thumbnailer.patch refreshed
* debian/control: libavcodec b-dep versioning dropped

Show diffs side-by-side

added added

removed removed

Lines of Context:
69
69
#include "text_intern.h"
70
70
#include "text_format.h"
71
71
 
 
72
static void txt_screen_clamp(SpaceText *st, ARegion *ar);
 
73
 
72
74
/************************ poll ***************************/
73
75
 
74
76
 
75
 
BLI_INLINE int text_pixel_x_to_index(SpaceText *st, const int x)
 
77
BLI_INLINE int text_pixel_x_to_column(SpaceText *st, const int x)
76
78
{
77
79
        /* add half the char width so mouse cursor selection is inbetween letters */
78
80
        return (x + (st->cwidth / 2)) / st->cwidth;
236
238
 
237
239
        RNA_string_get(op->ptr, "filepath", str);
238
240
 
239
 
        text = BKE_text_load(bmain, str, G.main->name);
 
241
        text = BKE_text_load_ex(bmain, str, G.main->name, internal);
240
242
 
241
243
        if (!text) {
242
244
                if (op->customdata) MEM_freeN(op->customdata);
262
264
                st->text = text;
263
265
                st->top = 0;
264
266
        }
265
 
        
266
 
        if (internal) {
267
 
                if (text->name)
268
 
                        MEM_freeN(text->name);
269
 
                
270
 
                text->name = NULL;
271
 
        }
272
267
 
273
268
        text_drawcache_tag_update(st, 1);
274
269
        WM_event_add_notifier(C, NC_TEXT | NA_ADDED, text);
278
273
        return OPERATOR_FINISHED;
279
274
}
280
275
 
281
 
static int text_open_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
276
static int text_open_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
282
277
{
283
278
        Text *text = CTX_data_edit_text(C);
284
279
        char *path = (text && text->name) ? text->name : G.main->name;
319
314
 
320
315
static int text_reload_exec(bContext *C, wmOperator *op)
321
316
{
 
317
        SpaceText *st = CTX_wm_space_text(C);
322
318
        Text *text = CTX_data_edit_text(C);
 
319
        ARegion *ar = CTX_wm_region(C);
 
320
 
 
321
        /* store view & cursor state */
 
322
        const int orig_top = st->top;
 
323
        const int orig_curl = BLI_findindex(&text->lines, text->curl);
 
324
        const int orig_curc = text->curc;
323
325
 
324
326
        if (!BKE_text_reload(text)) {
325
327
                BKE_report(op->reports, RPT_ERROR, "Could not reopen file");
336
338
        text_drawcache_tag_update(CTX_wm_space_text(C), 1);
337
339
        WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
338
340
 
 
341
        /* return to scroll position */
 
342
        st->top = orig_top;
 
343
        txt_screen_clamp(st, ar);
 
344
        /* return cursor */
 
345
        txt_move_to(text, orig_curl, orig_curc, false);
 
346
 
339
347
        return OPERATOR_FINISHED;
340
348
}
341
349
 
478
486
        
479
487
        fclose(fp);
480
488
 
481
 
        if (stat(filepath, &st) == 0) {
 
489
        if (BLI_stat(filepath, &st) == 0) {
482
490
                text->mtime = st.st_mtime;
483
491
        }
484
492
        else {
487
495
                            filepath, errno ? strerror(errno) : TIP_("unknown error stating file"));
488
496
        }
489
497
        
490
 
        if (text->flags & TXT_ISDIRTY)
491
 
                text->flags ^= TXT_ISDIRTY;
 
498
        text->flags &= ~TXT_ISDIRTY;
492
499
}
493
500
 
494
501
static int text_save_exec(bContext *C, wmOperator *op)
539
546
        return OPERATOR_FINISHED;
540
547
}
541
548
 
542
 
static int text_save_as_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
549
static int text_save_as_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
543
550
{
544
551
        Text *text = CTX_data_edit_text(C);
545
552
        char *str;
1011
1018
        text_drawcache_tag_update(st, 0);
1012
1019
 
1013
1020
        // double check tabs/spaces before splitting the line
1014
 
        curts = setcurr_tab_spaces(text, space);
 
1021
        curts = txt_setcurr_tab_spaces(text, space);
1015
1022
        txt_split_curline(text);
1016
1023
 
1017
1024
        for (a = 0; a < curts; a++) {
1407
1414
 
1408
1415
        for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe(linein->line + j)) {
1409
1416
                int chars;
 
1417
                int columns = BLI_str_utf8_char_width_safe(linein->line + j); /* = 1 for tab */
 
1418
 
1410
1419
                /* Mimic replacement of tabs */
1411
1420
                ch = linein->line[j];
1412
1421
                if (ch == '\t') {
1413
1422
                        chars = st->tabnumber - i % st->tabnumber;
1414
1423
                        ch = ' ';
1415
1424
                }
1416
 
                else chars = 1;
 
1425
                else {
 
1426
                        chars = 1;
 
1427
                }
1417
1428
 
1418
1429
                while (chars--) {
1419
 
                        if (rell == 0 && i - start == relc) {
 
1430
                        if (rell == 0 && i - start <= relc && i + columns - start > relc) {
1420
1431
                                /* current position could be wrapped to next line */
1421
1432
                                /* this should be checked when end of current line would be reached */
1422
1433
                                selc = j;
1423
1434
                                found = 1;
1424
1435
                        }
1425
 
                        else if (i - end == relc) {
 
1436
                        else if (i - end <= relc && i + columns - end > relc) {
1426
1437
                                curs = j;
1427
1438
                        }
1428
 
                        if (i - start >= max) {
 
1439
                        if (i + columns - start > max) {
 
1440
                                end = MIN2(end, i);
 
1441
 
1429
1442
                                if (found) {
1430
1443
                                        /* exact cursor position was found, check if it's */
1431
1444
                                        /* still on needed line (hasn't been wrapped) */
1441
1454
                                chop = 1;
1442
1455
                                rell--;
1443
1456
 
1444
 
                                if (rell == 0 && i - start >= relc) {
 
1457
                                if (rell == 0 && i + columns - start > relc) {
1445
1458
                                        selc = curs;
1446
1459
                                        loop = 0;
1447
1460
                                        break;
1458
1471
                                        break;
1459
1472
                                }
1460
1473
 
1461
 
                                if (rell == 0 && i - start >= relc) {
 
1474
                                if (rell == 0 && i + columns - start > relc) {
1462
1475
                                        selc = curs;
1463
1476
                                        loop = 0;
1464
1477
                                        break;
1467
1480
                                endj = j;
1468
1481
                                chop = 0;
1469
1482
                        }
1470
 
                        i++;
 
1483
                        i += columns;
1471
1484
                }
1472
1485
        }
1473
1486
 
1585
1598
 
1586
1599
        for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
1587
1600
                int chars;
 
1601
                int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
 
1602
 
1588
1603
                /* Mimic replacement of tabs */
1589
1604
                ch = (*linep)->line[j];
1590
1605
                if (ch == '\t') {
1591
1606
                        chars = st->tabnumber - i % st->tabnumber;
1592
1607
                        ch = ' ';
1593
1608
                }
1594
 
                else chars = 1;
 
1609
                else {
 
1610
                        chars = 1;
 
1611
                }
1595
1612
 
1596
1613
                while (chars--) {
1597
 
                        if (i - start >= max) {
 
1614
                        if (i + columns - start > max) {
 
1615
                                end = MIN2(end, i);
 
1616
 
1598
1617
                                *charp = endj;
1599
1618
 
1600
1619
                                if (j >= oldc) {
1601
 
                                        if (ch == '\0') *charp = txt_utf8_index_to_offset((*linep)->line, start);
 
1620
                                        if (ch == '\0') *charp = txt_utf8_column_to_offset((*linep)->line, start);
1602
1621
                                        loop = 0;
1603
1622
                                        break;
1604
1623
                                }
1611
1630
                        }
1612
1631
                        else if (ch == ' ' || ch == '-' || ch == '\0') {
1613
1632
                                if (j >= oldc) {
1614
 
                                        *charp = txt_utf8_index_to_offset((*linep)->line, start);
 
1633
                                        *charp = txt_utf8_column_to_offset((*linep)->line, start);
1615
1634
                                        loop = 0;
1616
1635
                                        break;
1617
1636
                                }
1620
1639
                                endj = j + 1;
1621
1640
                                chop = 0;
1622
1641
                        }
1623
 
                        i++;
 
1642
                        i += columns;
1624
1643
                }
1625
1644
        }
1626
1645
 
1651
1670
 
1652
1671
        for (i = 0, j = 0; loop; j += BLI_str_utf8_size_safe((*linep)->line + j)) {
1653
1672
                int chars;
 
1673
                int columns = BLI_str_utf8_char_width_safe((*linep)->line + j); /* = 1 for tab */
 
1674
 
1654
1675
                /* Mimic replacement of tabs */
1655
1676
                ch = (*linep)->line[j];
1656
1677
                if (ch == '\t') {
1657
1678
                        chars = st->tabnumber - i % st->tabnumber;
1658
1679
                        ch = ' ';
1659
1680
                }
1660
 
                else chars = 1;
 
1681
                else {
 
1682
                        chars = 1;
 
1683
                }
1661
1684
 
1662
1685
                while (chars--) {
1663
 
                        if (i - start >= max) {
 
1686
                        if (i + columns - start > max) {
 
1687
                                end = MIN2(end, i);
 
1688
 
1664
1689
                                if (chop) endj = BLI_str_prev_char_utf8((*linep)->line + j) - (*linep)->line;
1665
1690
 
1666
1691
                                if (endj >= oldc) {
1684
1709
                                endj = j;
1685
1710
                                chop = 0;
1686
1711
                        }
1687
 
                        i++;
 
1712
                        i += columns;
1688
1713
                }
1689
1714
        }
1690
1715
 
1716
1741
                        visible_lines = text_get_visible_lines(st, ar, (*linep)->line);
1717
1742
                        *charp = text_get_cursor_rel(st, ar, *linep, visible_lines - 1, col);
1718
1743
                }
1719
 
                else *charp = 0;
 
1744
                else {
 
1745
                        *charp = 0;
 
1746
                }
1720
1747
        }
1721
1748
 
1722
1749
        if (!sel) txt_pop_sel(text);
1745
1772
                        *linep = (*linep)->next;
1746
1773
                        *charp = text_get_cursor_rel(st, ar, *linep, 0, col);
1747
1774
                }
1748
 
                else *charp = (*linep)->len;
 
1775
                else {
 
1776
                        *charp = (*linep)->len;
 
1777
                }
1749
1778
        }
1750
1779
 
1751
1780
        if (!sel) txt_pop_sel(text);
1818
1847
                        break;
1819
1848
 
1820
1849
                case PREV_WORD:
 
1850
                        if (txt_cursor_is_line_start(text)) {
 
1851
                                txt_move_left(text, select);
 
1852
                        }
1821
1853
                        txt_jump_left(text, select, true);
1822
1854
                        break;
1823
1855
 
1824
1856
                case NEXT_WORD:
 
1857
                        if (txt_cursor_is_line_end(text)) {
 
1858
                                txt_move_right(text, select);
 
1859
                        }
1825
1860
                        txt_jump_right(text, select, true);
1826
1861
                        break;
1827
1862
 
1927
1962
        return OPERATOR_FINISHED;
1928
1963
}
1929
1964
 
1930
 
static int text_jump_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
1965
static int text_jump_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
1931
1966
{
1932
1967
        return WM_operator_props_dialog_popup(C, op, 10 * UI_UNIT_X, 5 * UI_UNIT_Y);
1933
1968
 
1963
1998
 
1964
1999
static int text_delete_exec(bContext *C, wmOperator *op)
1965
2000
{
 
2001
        SpaceText *st = CTX_wm_space_text(C);
1966
2002
        Text *text = CTX_data_edit_text(C);
1967
2003
        int type = RNA_enum_get(op->ptr, "type");
1968
2004
 
1969
 
        text_drawcache_tag_update(CTX_wm_space_text(C), 0);
1970
 
 
1971
 
        if (type == DEL_PREV_WORD)
 
2005
        text_drawcache_tag_update(st, 0);
 
2006
 
 
2007
        /* behavior could be changed here,
 
2008
         * but for now just don't jump words when we have a selection */
 
2009
        if (txt_has_sel(text)) {
 
2010
                if      (type == DEL_PREV_WORD) type = DEL_PREV_CHAR;
 
2011
                else if (type == DEL_NEXT_WORD) type = DEL_NEXT_CHAR;
 
2012
        }
 
2013
 
 
2014
        if (type == DEL_PREV_WORD) {
 
2015
                if (txt_cursor_is_line_start(text)) {
 
2016
                        txt_backspace_char(text);
 
2017
                }
1972
2018
                txt_backspace_word(text);
1973
 
        else if (type == DEL_PREV_CHAR)
 
2019
        }
 
2020
        else if (type == DEL_PREV_CHAR) {
1974
2021
                txt_backspace_char(text);
1975
 
        else if (type == DEL_NEXT_WORD)
 
2022
        }
 
2023
        else if (type == DEL_NEXT_WORD) {
 
2024
                if (txt_cursor_is_line_end(text)) {
 
2025
                        txt_delete_char(text);
 
2026
                }
1976
2027
                txt_delete_word(text);
1977
 
        else if (type == DEL_NEXT_CHAR)
 
2028
        }
 
2029
        else if (type == DEL_NEXT_CHAR) {
1978
2030
                txt_delete_char(text);
 
2031
        }
1979
2032
 
1980
2033
        text_update_line_edited(text->curl);
1981
2034
 
1983
2036
        WM_event_add_notifier(C, NC_TEXT | NA_EDITED, text);
1984
2037
 
1985
2038
        /* run the script while editing, evil but useful */
1986
 
        if (CTX_wm_space_text(C)->live_edit)
 
2039
        if (st->live_edit)
1987
2040
                text_run_script(C, NULL);
1988
2041
        
1989
2042
        return OPERATOR_FINISHED;
2031
2084
 
2032
2085
/******************* scroll operator **********************/
2033
2086
 
 
2087
static void txt_screen_clamp(SpaceText *st, ARegion *ar)
 
2088
{
 
2089
        int last;
 
2090
        last = text_get_total_lines(st, ar);
 
2091
        last = last - (st->viewlines / 2);
 
2092
        CLAMP(st->top, 0, last);
 
2093
}
 
2094
 
2034
2095
/* Moves the view vertically by the specified number of lines */
2035
2096
static void txt_screen_skip(SpaceText *st, ARegion *ar, int lines)
2036
2097
{
2037
 
        int last;
2038
 
 
2039
2098
        st->top += lines;
2040
 
 
2041
 
        last = text_get_total_lines(st, ar);
2042
 
        last = last - (st->viewlines / 2);
2043
 
        
2044
 
        if (st->top > last) st->top = last;
2045
 
        if (st->top < 0) st->top = 0;
 
2099
        txt_screen_clamp(st, ar);
2046
2100
}
2047
2101
 
2048
2102
/* quick enum for tsc->zone (scroller handles) */
2085
2139
        return OPERATOR_FINISHED;
2086
2140
}
2087
2141
 
2088
 
static void text_scroll_apply(bContext *C, wmOperator *op, wmEvent *event)
 
2142
static void text_scroll_apply(bContext *C, wmOperator *op, const wmEvent *event)
2089
2143
{
2090
2144
        SpaceText *st = CTX_wm_space_text(C);
2091
2145
        ARegion *ar = CTX_wm_region(C);
2142
2196
        MEM_freeN(op->customdata);
2143
2197
}
2144
2198
 
2145
 
static int text_scroll_modal(bContext *C, wmOperator *op, wmEvent *event)
 
2199
static int text_scroll_modal(bContext *C, wmOperator *op, const wmEvent *event)
2146
2200
{
2147
2201
        TextScroll *tsc = op->customdata;
2148
2202
        SpaceText *st = CTX_wm_space_text(C);
2157
2211
                case RIGHTMOUSE:
2158
2212
                case MIDDLEMOUSE:
2159
2213
                        if (ELEM(tsc->zone, SCROLLHANDLE_MIN_OUTSIDE, SCROLLHANDLE_MAX_OUTSIDE)) {
2160
 
                                int last;
2161
 
 
2162
 
                                st->top += st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1);
2163
 
 
2164
 
                                last = text_get_total_lines(st, ar);
2165
 
                                last = last - (st->viewlines / 2);
2166
 
 
2167
 
                                CLAMP(st->top, 0, last);
 
2214
                                txt_screen_skip(st, ar, st->viewlines * (tsc->zone == SCROLLHANDLE_MIN_OUTSIDE ? 1 : -1));
2168
2215
 
2169
2216
                                ED_area_tag_redraw(CTX_wm_area(C));
2170
2217
                        }
2182
2229
        return OPERATOR_CANCELLED;
2183
2230
}
2184
2231
 
2185
 
static int text_scroll_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2232
static int text_scroll_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2186
2233
{
2187
2234
        SpaceText *st = CTX_wm_space_text(C);
2188
2235
        TextScroll *tsc;
2259
2306
        return 1;
2260
2307
}
2261
2308
 
2262
 
static int text_scroll_bar_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2309
static int text_scroll_bar_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2263
2310
{
2264
2311
        SpaceText *st = CTX_wm_space_text(C);
2265
2312
        ARegion *ar = CTX_wm_region(C);
2342
2389
        short old[2];
2343
2390
} SetSelection;
2344
2391
 
2345
 
static int flatten_len(SpaceText *st, const char *str)
 
2392
static int flatten_width(SpaceText *st, const char *str)
2346
2393
{
2347
2394
        int i, total = 0;
2348
2395
 
2350
2397
                if (str[i] == '\t') {
2351
2398
                        total += st->tabnumber - total % st->tabnumber;
2352
2399
                }
2353
 
                else total++;
 
2400
                else {
 
2401
                        total += BLI_str_utf8_char_width_safe(str + i);
 
2402
                }
2354
2403
        }
2355
2404
        
2356
2405
        return total;
2357
2406
}
2358
2407
 
2359
 
static int flatten_index_to_offset(SpaceText *st, const char *str, int index)
 
2408
static int flatten_column_to_offset(SpaceText *st, const char *str, int index)
2360
2409
{
2361
 
        int i, j;
2362
 
        for (i = 0, j = 0; i < index; j += BLI_str_utf8_size_safe(str + j))
 
2410
        int i = 0, j = 0, col;
 
2411
 
 
2412
        while (*(str + j)) {
2363
2413
                if (str[j] == '\t')
2364
 
                        i += st->tabnumber - i % st->tabnumber;
 
2414
                        col = st->tabnumber - i % st->tabnumber;
2365
2415
                else
2366
 
                        i++;
 
2416
                        col = BLI_str_utf8_char_width_safe(str + j);
 
2417
                
 
2418
                if (i + col > index)
 
2419
                        break;
 
2420
                
 
2421
                i += col;
 
2422
                j += BLI_str_utf8_size_safe(str + j);
 
2423
        }
2367
2424
        
2368
2425
        return j;
2369
2426
}
2390
2447
static void text_cursor_set_to_pos_wrapped(SpaceText *st, ARegion *ar, int x, int y, int sel)
2391
2448
{
2392
2449
        Text *text = st->text;
2393
 
        int max = wrap_width(st, ar); /* view */
 
2450
        int max = wrap_width(st, ar); /* column */
2394
2451
        int charp = -1;               /* mem */
2395
2452
        int loop = 1, found = 0;      /* flags */
2396
2453
        char ch;
2399
2456
        TextLine *linep = get_first_visible_line(st, ar, &y);
2400
2457
        
2401
2458
        while (loop && linep) {
2402
 
                int i = 0, start = 0, end = max; /* view */
 
2459
                int i = 0, start = 0, end = max; /* column */
2403
2460
                int j = 0, curs = 0, endj = 0;   /* mem */
2404
2461
                int chop = 1;                    /* flags */
2405
2462
                
2406
2463
                for (; loop; j += BLI_str_utf8_size_safe(linep->line + j)) {
2407
2464
                        int chars;
 
2465
                        int columns = BLI_str_utf8_char_width_safe(linep->line + j); /* = 1 for tab */
2408
2466
                        
2409
2467
                        /* Mimic replacement of tabs */
2410
2468
                        ch = linep->line[j];
2412
2470
                                chars = st->tabnumber - i % st->tabnumber;
2413
2471
                                ch = ' ';
2414
2472
                        }
2415
 
                        else chars = 1;
 
2473
                        else {
 
2474
                                chars = 1;
 
2475
                        }
2416
2476
                        
2417
2477
                        while (chars--) {
2418
2478
                                /* Gone too far, go back to last wrap point */
2422
2482
                                        break;
2423
2483
                                        /* Exactly at the cursor */
2424
2484
                                }
2425
 
                                else if (y == 0 && i - start == x) {
 
2485
                                else if (y == 0 && i - start <= x && i + columns - start > x) {
2426
2486
                                        /* current position could be wrapped to next line */
2427
2487
                                        /* this should be checked when end of current line would be reached */
2428
2488
                                        charp = curs = j;
2429
2489
                                        found = 1;
2430
2490
                                        /* Prepare curs for next wrap */
2431
2491
                                }
2432
 
                                else if (i - end == x) {
 
2492
                                else if (i - end <= x && i + columns - end > x) {
2433
2493
                                        curs = j;
2434
2494
                                }
2435
 
                                if (i - start >= max) {
 
2495
                                if (i + columns - start > max) {
 
2496
                                        end = MIN2(end, i);
 
2497
                                        
2436
2498
                                        if (found) {
2437
2499
                                                /* exact cursor position was found, check if it's */
2438
2500
                                                /* still on needed line (hasn't been wrapped) */
2449
2511
                                                y--;
2450
2512
                                        
2451
2513
                                        chop = 1;
2452
 
                                        if (y == 0 && i - start >= x) {
 
2514
                                        if (y == 0 && i + columns - start > x) {
2453
2515
                                                charp = curs;
2454
2516
                                                loop = 0;
2455
2517
                                                break;
2461
2523
                                                break;
2462
2524
                                        }
2463
2525
                                        
2464
 
                                        if (y == 0 && i - start >= x) {
 
2526
                                        if (y == 0 && i + columns - start > x) {
2465
2527
                                                charp = curs;
2466
2528
                                                loop = 0;
2467
2529
                                                break;
2470
2532
                                        endj = j;
2471
2533
                                        chop = 0;
2472
2534
                                }
2473
 
                                i++;
 
2535
                                i += columns;
2474
2536
                        }
2475
2537
                        
2476
2538
                        if (ch == '\0') break;
2509
2571
        else x -= TXT_OFFSET;
2510
2572
 
2511
2573
        if (x < 0) x = 0;
2512
 
        x = text_pixel_x_to_index(st, x) + st->left;
 
2574
        x = text_pixel_x_to_column(st, x) + st->left;
2513
2575
        
2514
2576
        if (st->wordwrap) {
2515
2577
                text_cursor_set_to_pos_wrapped(st, ar, x, y, sel);
2532
2594
                }
2533
2595
 
2534
2596
                
2535
 
                w = flatten_len(st, (*linep)->line);
2536
 
                if (x < w) *charp = flatten_index_to_offset(st, (*linep)->line, x);
 
2597
                w = flatten_width(st, (*linep)->line);
 
2598
                if (x < w) *charp = flatten_column_to_offset(st, (*linep)->line, x);
2537
2599
                else *charp = (*linep)->len;
2538
2600
        }
2539
2601
        if (!sel) txt_pop_sel(text);
2540
2602
}
2541
2603
 
2542
 
static void text_cursor_set_apply(bContext *C, wmOperator *op, wmEvent *event)
 
2604
static void text_cursor_set_apply(bContext *C, wmOperator *op, const wmEvent *event)
2543
2605
{
2544
2606
        SpaceText *st = CTX_wm_space_text(C);
2545
2607
        ARegion *ar = CTX_wm_region(C);
2594
2656
        MEM_freeN(ssel);
2595
2657
}
2596
2658
 
2597
 
static int text_set_selection_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2659
static int text_set_selection_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2598
2660
{
2599
2661
        SpaceText *st = CTX_wm_space_text(C);
2600
2662
        SetSelection *ssel;
2619
2681
        return OPERATOR_RUNNING_MODAL;
2620
2682
}
2621
2683
 
2622
 
static int text_set_selection_modal(bContext *C, wmOperator *op, wmEvent *event)
 
2684
static int text_set_selection_modal(bContext *C, wmOperator *op, const wmEvent *event)
2623
2685
{
2624
2686
        switch (event->type) {
2625
2687
                case LEFTMOUSE:
2675
2737
        return OPERATOR_PASS_THROUGH;
2676
2738
}
2677
2739
 
2678
 
static int text_cursor_set_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2740
static int text_cursor_set_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2679
2741
{
2680
2742
        SpaceText *st = CTX_wm_space_text(C);
2681
2743
 
2707
2769
 
2708
2770
/******************* line number operator **********************/
2709
2771
 
2710
 
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), wmEvent *event)
 
2772
static int text_line_number_invoke(bContext *C, wmOperator *UNUSED(op), const wmEvent *event)
2711
2773
{
2712
2774
        SpaceText *st = CTX_wm_space_text(C);
2713
2775
        Text *text = CTX_data_edit_text(C);
2797
2859
        return OPERATOR_FINISHED;
2798
2860
}
2799
2861
 
2800
 
static int text_insert_invoke(bContext *C, wmOperator *op, wmEvent *event)
 
2862
static int text_insert_invoke(bContext *C, wmOperator *op, const wmEvent *event)
2801
2863
{
2802
2864
        int ret;
2803
2865
 
2870
2932
        int found = 0;
2871
2933
        char *tmp;
2872
2934
 
2873
 
        if (!st->findstr[0] || (mode == TEXT_REPLACE && !st->replacestr[0]))
 
2935
        if (!st->findstr[0])
2874
2936
                return OPERATOR_CANCELLED;
2875
2937
 
2876
2938
        flags = st->flags;
2929
2991
void TEXT_OT_find(wmOperatorType *ot)
2930
2992
{
2931
2993
        /* identifiers */
2932
 
        ot->name = "Find";
 
2994
        ot->name = "Find Next";
2933
2995
        ot->idname = "TEXT_OT_find";
2934
2996
        ot->description = "Find specified text";
2935
2997
        
3045
3107
        if (!BLI_exists(file))
3046
3108
                return 2;
3047
3109
 
3048
 
        result = stat(file, &st);
 
3110
        result = BLI_stat(file, &st);
3049
3111
        
3050
3112
        if (result == -1)
3051
3113
                return -1;
3072
3134
 
3073
3135
        if (!BLI_exists(file)) return;
3074
3136
 
3075
 
        result = stat(file, &st);
 
3137
        result = BLI_stat(file, &st);
3076
3138
        
3077
3139
        if (result == -1 || (st.st_mode & S_IFMT) != S_IFREG)
3078
3140
                return;
3100
3162
        return OPERATOR_CANCELLED;
3101
3163
}
3102
3164
 
3103
 
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, wmEvent *UNUSED(event))
 
3165
static int text_resolve_conflict_invoke(bContext *C, wmOperator *op, const wmEvent *UNUSED(event))
3104
3166
{
3105
3167
        Text *text = CTX_data_edit_text(C);
3106
3168
        uiPopupMenu *pup;
3110
3172
                case 1:
3111
3173
                        if (text->flags & TXT_ISDIRTY) {
3112
3174
                                /* modified locally and externally, ahhh. offer more possibilites. */
3113
 
                                pup = uiPupMenuBegin(C, "File Modified Outside and Inside Blender", ICON_NONE);
 
3175
                                pup = uiPupMenuBegin(C, IFACE_("File Modified Outside and Inside Blender"), ICON_NONE);
3114
3176
                                layout = uiPupMenuLayout(pup);
3115
 
                                uiItemEnumO_ptr(layout, op->type, "Reload from disk (ignore local changes)", 0, "resolution", RESOLVE_RELOAD);
3116
 
                                uiItemEnumO_ptr(layout, op->type, "Save to disk (ignore outside changes)", 0, "resolution", RESOLVE_SAVE);
3117
 
                                uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
 
3177
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Reload from disk (ignore local changes)"),
 
3178
                                                0, "resolution", RESOLVE_RELOAD);
 
3179
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Save to disk (ignore outside changes)"),
 
3180
                                                0, "resolution", RESOLVE_SAVE);
 
3181
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal (separate copy)"),
 
3182
                                                0, "resolution", RESOLVE_MAKE_INTERNAL);
3118
3183
                                uiPupMenuEnd(C, pup);
3119
3184
                        }
3120
3185
                        else {
3121
 
                                pup = uiPupMenuBegin(C, "File Modified Outside Blender", ICON_NONE);
 
3186
                                pup = uiPupMenuBegin(C, IFACE_("File Modified Outside Blender"), ICON_NONE);
3122
3187
                                layout = uiPupMenuLayout(pup);
3123
 
                                uiItemEnumO_ptr(layout, op->type, "Reload from disk", 0, "resolution", RESOLVE_RELOAD);
3124
 
                                uiItemEnumO_ptr(layout, op->type, "Make text internal (separate copy)", 0, "resolution", RESOLVE_MAKE_INTERNAL);
3125
 
                                uiItemEnumO_ptr(layout, op->type, "Ignore", 0, "resolution", RESOLVE_IGNORE);
 
3188
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Reload from disk"), 0, "resolution", RESOLVE_RELOAD);
 
3189
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal (separate copy)"),
 
3190
                                                0, "resolution", RESOLVE_MAKE_INTERNAL);
 
3191
                                uiItemEnumO_ptr(layout, op->type, IFACE_("Ignore"), 0, "resolution", RESOLVE_IGNORE);
3126
3192
                                uiPupMenuEnd(C, pup);
3127
3193
                        }
3128
3194
                        break;
3129
3195
                case 2:
3130
 
                        pup = uiPupMenuBegin(C, "File Deleted Outside Blender", ICON_NONE);
 
3196
                        pup = uiPupMenuBegin(C, IFACE_("File Deleted Outside Blender"), ICON_NONE);
3131
3197
                        layout = uiPupMenuLayout(pup);
3132
 
                        uiItemEnumO_ptr(layout, op->type, "Make text internal", 0, "resolution", RESOLVE_MAKE_INTERNAL);
3133
 
                        uiItemEnumO_ptr(layout, op->type, "Recreate file", 0, "resolution", RESOLVE_SAVE);
 
3198
                        uiItemEnumO_ptr(layout, op->type, IFACE_("Make text internal"), 0, "resolution", RESOLVE_MAKE_INTERNAL);
 
3199
                        uiItemEnumO_ptr(layout, op->type, IFACE_("Recreate file"), 0, "resolution", RESOLVE_SAVE);
3134
3200
                        uiPupMenuEnd(C, pup);
3135
3201
                        break;
3136
3202
        }