Work at SourceForge, help us to make it a better place! We have an immediate need for a Support Technician in our San Francisco or Denver office.

Close

[bb518b]: src / SciTEBase.cxx Maximize Restore History

Download this file

SciTEBase.cxx    4782 lines (4353 with data), 142.8 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
3425
3426
3427
3428
3429
3430
3431
3432
3433
3434
3435
3436
3437
3438
3439
3440
3441
3442
3443
3444
3445
3446
3447
3448
3449
3450
3451
3452
3453
3454
3455
3456
3457
3458
3459
3460
3461
3462
3463
3464
3465
3466
3467
3468
3469
3470
3471
3472
3473
3474
3475
3476
3477
3478
3479
3480
3481
3482
3483
3484
3485
3486
3487
3488
3489
3490
3491
3492
3493
3494
3495
3496
3497
3498
3499
3500
3501
3502
3503
3504
3505
3506
3507
3508
3509
3510
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
3523
3524
3525
3526
3527
3528
3529
3530
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
3555
3556
3557
3558
3559
3560
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
3575
3576
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
3587
3588
3589
3590
3591
3592
3593
3594
3595
3596
3597
3598
3599
3600
3601
3602
3603
3604
3605
3606
3607
3608
3609
3610
3611
3612
3613
3614
3615
3616
3617
3618
3619
3620
3621
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
3637
3638
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
3656
3657
3658
3659
3660
3661
3662
3663
3664
3665
3666
3667
3668
3669
3670
3671
3672
3673
3674
3675
3676
3677
3678
3679
3680
3681
3682
3683
3684
3685
3686
3687
3688
3689
3690
3691
3692
3693
3694
3695
3696
3697
3698
3699
3700
3701
3702
3703
3704
3705
3706
3707
3708
3709
3710
3711
3712
3713
3714
3715
3716
3717
3718
3719
3720
3721
3722
3723
3724
3725
3726
3727
3728
3729
3730
3731
3732
3733
3734
3735
3736
3737
3738
3739
3740
3741
3742
3743
3744
3745
3746
3747
3748
3749
3750
3751
3752
3753
3754
3755
3756
3757
3758
3759
3760
3761
3762
3763
3764
3765
3766
3767
3768
3769
3770
3771
3772
3773
3774
3775
3776
3777
3778
3779
3780
3781
3782
3783
3784
3785
3786
3787
3788
3789
3790
3791
3792
3793
3794
3795
3796
3797
3798
3799
3800
3801
3802
3803
3804
3805
3806
3807
3808
3809
3810
3811
3812
3813
3814
3815
3816
3817
3818
3819
3820
3821
3822
3823
3824
3825
3826
3827
3828
3829
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
3863
3864
3865
3866
3867
3868
3869
3870
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
3909
3910
3911
3912
3913
3914
3915
3916
3917
3918
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
3930
3931
3932
3933
3934
3935
3936
3937
3938
3939
3940
3941
3942
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
3953
3954
3955
3956
3957
3958
3959
3960
3961
3962
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
3973
3974
3975
3976
3977
3978
3979
3980
3981
3982
3983
3984
3985
3986
3987
3988
3989
3990
3991
3992
3993
3994
3995
3996
3997
3998
3999
4000
4001
4002
4003
4004
4005
4006
4007
4008
4009
4010
4011
4012
4013
4014
4015
4016
4017
4018
4019
4020
4021
4022
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
4034
4035
4036
4037
4038
4039
4040
4041
4042
4043
4044
4045
4046
4047
4048
4049
4050
4051
4052
4053
4054
4055
4056
4057
4058
4059
4060
4061
4062
4063
4064
4065
4066
4067
4068
4069
4070
4071
4072
4073
4074
4075
4076
4077
4078
4079
4080
4081
4082
4083
4084
4085
4086
4087
4088
4089
4090
4091
4092
4093
4094
4095
4096
4097
4098
4099
4100
4101
4102
4103
4104
4105
4106
4107
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
4127
4128
4129
4130
4131
4132
4133
4134
4135
4136
4137
4138
4139
4140
4141
4142
4143
4144
4145
4146
4147
4148
4149
4150
4151
4152
4153
4154
4155
4156
4157
4158
4159
4160
4161
4162
4163
4164
4165
4166
4167
4168
4169
4170
4171
4172
4173
4174
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
4186
4187
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
4199
4200
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
4217
4218
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
4229
4230
4231
4232
4233
4234
4235
4236
4237
4238
4239
4240
4241
4242
4243
4244
4245
4246
4247
4248
4249
4250
4251
4252
4253
4254
4255
4256
4257
4258
4259
4260
4261
4262
4263
4264
4265
4266
4267
4268
4269
4270
4271
4272
4273
4274
4275
4276
4277
4278
4279
4280
4281
4282
4283
4284
4285
4286
4287
4288
4289
4290
4291
4292
4293
4294
4295
4296
4297
4298
4299
4300
4301
4302
4303
4304
4305
4306
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
4335
4336
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
4347
4348
4349
4350
4351
4352
4353
4354
4355
4356
4357
4358
4359
4360
4361
4362
4363
4364
4365
4366
4367
4368
4369
4370
4371
4372
4373
4374
4375
4376
4377
4378
4379
4380
4381
4382
4383
4384
4385
4386
4387
4388
4389
4390
4391
4392
4393
4394
4395
4396
4397
4398
4399
4400
4401
4402
4403
4404
4405
4406
4407
4408
4409
4410
4411
4412
4413
4414
4415
4416
4417
4418
4419
4420
4421
4422
4423
4424
4425
4426
4427
4428
4429
4430
4431
4432
4433
4434
4435
4436
4437
4438
4439
4440
4441
4442
4443
4444
4445
4446
4447
4448
4449
4450
4451
4452
4453
4454
4455
4456
4457
4458
4459
4460
4461
4462
4463
4464
4465
4466
4467
4468
4469
4470
4471
4472
4473
4474
4475
4476
4477
4478
4479
4480
4481
4482
4483
4484
4485
4486
4487
4488
4489
4490
4491
4492
4493
4494
4495
4496
4497
4498
4499
4500
4501
4502
4503
4504
4505
4506
4507
4508
4509
4510
4511
4512
4513
4514
4515
4516
4517
4518
4519
4520
4521
4522
4523
4524
4525
4526
4527
4528
4529
4530
4531
4532
4533
4534
4535
4536
4537
4538
4539
4540
4541
4542
4543
4544
4545
4546
4547
4548
4549
4550
4551
4552
4553
4554
4555
4556
4557
4558
4559
4560
4561
4562
4563
4564
4565
4566
4567
4568
4569
4570
4571
4572
4573
4574
4575
4576
4577
4578
4579
4580
4581
4582
4583
4584
4585
4586
4587
4588
4589
4590
4591
4592
4593
4594
4595
4596
4597
4598
4599
4600
4601
4602
4603
4604
4605
4606
4607
4608
4609
4610
4611
4612
4613
4614
4615
4616
4617
4618
4619
4620
4621
4622
4623
4624
4625
4626
4627
4628
4629
4630
4631
4632
4633
4634
4635
4636
4637
4638
4639
4640
4641
4642
4643
4644
4645
4646
4647
4648
4649
4650
4651
4652
4653
4654
4655
4656
4657
4658
4659
4660
4661
4662
4663
4664
4665
4666
4667
4668
4669
4670
4671
4672
4673
4674
4675
4676
4677
4678
4679
4680
4681
4682
4683
4684
4685
4686
4687
4688
4689
4690
4691
4692
4693
4694
4695
4696
4697
4698
4699
4700
4701
4702
4703
4704
4705
4706
4707
4708
4709
4710
4711
4712
4713
4714
4715
4716
4717
4718
4719
4720
4721
4722
4723
4724
4725
4726
4727
4728
4729
4730
4731
4732
4733
4734
4735
4736
4737
4738
4739
4740
4741
4742
4743
4744
4745
4746
4747
4748
4749
4750
4751
4752
4753
4754
4755
4756
4757
4758
4759
4760
4761
4762
4763
4764
4765
4766
4767
4768
4769
4770
4771
4772
4773
4774
4775
4776
4777
4778
4779
4780
// SciTE - Scintilla based Text Editor
/** @file SciTEBase.cxx
** Platform independent base class of editor.
**/
// Copyright 1998-2011 by Neil Hodgson <neilh@scintilla.org>
// The License.txt file describes the conditions under which this software may be distributed.
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdarg.h>
#include <sys/stat.h>
#include <time.h>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <algorithm>
#if defined(__unix__)
#include <unistd.h>
#if defined(GTK)
#include <gtk/gtk.h>
#endif
#else
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0500
#ifdef _MSC_VER
// windows.h, et al, use a lot of nameless struct/unions - can't fix it, so allow it
#pragma warning(disable: 4201)
#endif
#include <windows.h>
#ifdef _MSC_VER
// okay, that's done, don't allow it in our code
#pragma warning(default: 4201)
#endif
#include <commctrl.h>
#ifdef _MSC_VER
#include <direct.h>
#endif
#ifdef __DMC__
#include <dir.h>
#endif
#endif
#include "Scintilla.h"
#include "SciLexer.h"
#include "ILexer.h"
#include "GUI.h"
#include "SString.h"
#include "StringList.h"
#include "StringHelpers.h"
#include "FilePath.h"
#include "PropSetFile.h"
#include "StyleWriter.h"
#include "Extender.h"
#include "SciTE.h"
#include "Mutex.h"
#include "JobQueue.h"
#include "Cookie.h"
#include "Worker.h"
#include "FileWorker.h"
#include "SciTEBase.h"
Searcher::Searcher() {
wholeWord = false;
matchCase = false;
regExp = false;
unSlash = false;
wrapFind = true;
reverseFind = false;
replacing = false;
havefound = false;
findInStyle = false;
findStyle = 0;
closeFind = true;
focusOnReplace = false;
}
// The find and replace dialogs and strips often manipulate boolean
// flags based on dialog control IDs and menu IDs.
bool &Searcher::FlagFromCmd(int cmd) {
static bool notFound;
switch (cmd) {
case IDWHOLEWORD:
case IDM_WHOLEWORD:
return wholeWord;
case IDMATCHCASE:
case IDM_MATCHCASE:
return matchCase;
case IDREGEXP:
case IDM_REGEXP:
return regExp;
case IDUNSLASH:
case IDM_UNSLASH:
return unSlash;
case IDWRAP:
case IDM_WRAPAROUND:
return wrapFind;
case IDDIRECTIONUP:
case IDM_DIRECTIONUP:
return reverseFind;
}
return notFound;
}
SciTEBase::SciTEBase(Extension *ext) : apis(true), extender(ext) {
codePage = 0;
characterSet = 0;
language = "java";
lexLanguage = SCLEX_CPP;
lexLPeg = -1;
functionDefinition = 0;
diagnosticStyleStart = 0;
indentOpening = true;
indentClosing = true;
indentMaintain = false;
statementLookback = 10;
preprocessorSymbol = '\0';
tbVisible = false;
sbVisible = false;
tabVisible = false;
tabHideOne = false;
tabMultiLine = false;
sbNum = 1;
visHeightTools = 0;
visHeightTab = 0;
visHeightStatus = 0;
visHeightEditor = 1;
heightBar = 7;
dialogsOnScreen = 0;
topMost = false;
wrap = false;
wrapOutput = false;
wrapStyle = SC_WRAP_WORD;
isReadOnly = false;
openFilesHere = false;
fullScreen = false;
heightOutput = 0;
heightOutputStartDrag = 0;
previousHeightOutput = 0;
allowMenuActions = true;
scrollOutput = 1;
returnOutputToCommand = true;
ptStartDrag.x = 0;
ptStartDrag.y = 0;
capturedMouse = false;
firstPropertiesRead = true;
localiser.read = false;
splitVertical = false;
bufferedDraw = true;
twoPhaseDraw = true;
bracesCheck = true;
bracesSloppy = false;
bracesStyle = 0;
braceCount = 0;
indentationWSVisible = true;
indentExamine = SC_IV_LOOKBOTH;
autoCompleteIgnoreCase = false;
callTipUseEscapes = false;
callTipIgnoreCase = false;
autoCCausedByOnlyOne = false;
startCalltipWord = 0;
currentCallTip = 0;
maxCallTips = 1;
currentCallTipWord = "";
lastPosCallTip = 0;
margin = false;
marginWidth = marginWidthDefault;
foldMargin = true;
foldMarginWidth = foldMarginWidthDefault;
lineNumbers = false;
lineNumbersWidth = lineNumbersWidthDefault;
lineNumbersExpand = false;
languageMenu = 0;
languageItems = 0;
macrosEnabled = false;
recording = false;
propsBase.superPS = &propsEmbed;
propsUser.superPS = &propsBase;
propsDirectory.superPS = &propsUser;
propsLocal.superPS = &propsDirectory;
propsDiscovered.superPS = &propsLocal;
props.superPS = &propsDiscovered;
propsStatus.superPS = &props;
needReadProperties = false;
quitting = false;
timerMask = 0;
delayBeforeAutoSave = 0;
}
SciTEBase::~SciTEBase() {
TimerEnd(timerAutoSave);
if (extender)
extender->Finalise();
delete []languageMenu;
popup.Destroy();
}
void SciTEBase::WorkerCommand(int cmd, Worker *pWorker) {
switch (cmd) {
case WORK_FILEREAD:
TextRead(static_cast<FileLoader *>(pWorker));
UpdateProgress(pWorker);
break;
case WORK_FILEWRITTEN:
TextWritten(static_cast<FileStorer *>(pWorker));
UpdateProgress(pWorker);
break;
case WORK_FILEPROGRESS:
UpdateProgress(pWorker);
break;
}
}
int SciTEBase::CallFocused(unsigned int msg, uptr_t wParam, sptr_t lParam) {
if (wOutput.HasFocus())
return wOutput.Call(msg, wParam, lParam);
else
return wEditor.Call(msg, wParam, lParam);
}
int SciTEBase::CallFocusedElseDefault(int defaultValue, unsigned int msg, uptr_t wParam, sptr_t lParam) {
if (wOutput.HasFocus())
return wOutput.Call(msg, wParam, lParam);
else if (wEditor.HasFocus())
return wEditor.Call(msg, wParam, lParam);
else
return defaultValue;
}
sptr_t SciTEBase::CallPane(int destination, unsigned int msg, uptr_t wParam, sptr_t lParam) {
if (destination == IDM_SRCWIN)
return wEditor.Call(msg, wParam, lParam);
else if (destination == IDM_RUNWIN)
return wOutput.Call(msg, wParam, lParam);
else
return CallFocused(msg, wParam, lParam);
}
void SciTEBase::CallChildren(unsigned int msg, uptr_t wParam, sptr_t lParam) {
wEditor.Call(msg, wParam, lParam);
wOutput.Call(msg, wParam, lParam);
}
SString SciTEBase::GetTranslationToAbout(const char * const propname, bool retainIfNotFound) {
#if !defined(GTK)
return SString(GUI::UTF8FromString(localiser.Text(propname, retainIfNotFound)).c_str());
#else
// On GTK+, localiser.Text always converts to UTF-8.
return SString(localiser.Text(propname, retainIfNotFound).c_str());
#endif
}
void SciTEBase::ViewWhitespace(bool view) {
if (view && indentationWSVisible)
wEditor.Call(SCI_SETVIEWWS, SCWS_VISIBLEALWAYS);
else if (view)
wEditor.Call(SCI_SETVIEWWS, SCWS_VISIBLEAFTERINDENT);
else
wEditor.Call(SCI_SETVIEWWS, SCWS_INVISIBLE);
}
StyleAndWords SciTEBase::GetStyleAndWords(const char *base) {
StyleAndWords sw;
SString fileNameForExtension = ExtensionFileName();
SString sAndW = props.GetNewExpand(base, fileNameForExtension.c_str());
sw.styleNumber = sAndW.value();
const char *space = strchr(sAndW.c_str(), ' ');
if (space)
sw.words = space + 1;
return sw;
}
void SciTEBase::AssignKey(int key, int mods, int cmd) {
wEditor.Call(SCI_ASSIGNCMDKEY,
LongFromTwoShorts(static_cast<short>(key),
static_cast<short>(mods)), cmd);
}
/**
* Override the language of the current file with the one indicated by @a cmdID.
* Mostly used to set a language on a file of unknown extension.
*/
void SciTEBase::SetOverrideLanguage(int cmdID) {
RecentFile rf = GetFilePosition();
EnsureRangeVisible(wEditor, 0, wEditor.Call(SCI_GETLENGTH), false);
// Zero all the style bytes
wEditor.Call(SCI_CLEARDOCUMENTSTYLE);
CurrentBuffer()->overrideExtension = "x.";
CurrentBuffer()->overrideExtension += languageMenu[cmdID].extension;
ReadProperties();
SetIndentSettings();
wEditor.Call(SCI_COLOURISE, 0, -1);
Redraw();
DisplayAround(rf);
}
int SciTEBase::LengthDocument() {
return wEditor.Call(SCI_GETLENGTH);
}
int SciTEBase::GetCaretInLine() {
int caret = wEditor.Call(SCI_GETCURRENTPOS);
int line = wEditor.Call(SCI_LINEFROMPOSITION, caret);
int lineStart = wEditor.Call(SCI_POSITIONFROMLINE, line);
return caret - lineStart;
}
void SciTEBase::GetLine(char *text, int sizeText, int line) {
if (line < 0)
line = GetCurrentLineNumber();
int lineStart = wEditor.Call(SCI_POSITIONFROMLINE, line);
int lineEnd = wEditor.Call(SCI_GETLINEENDPOSITION, line);
int lineMax = lineStart + sizeText - 1;
if (lineEnd > lineMax)
lineEnd = lineMax;
GetRange(wEditor, lineStart, lineEnd, text);
text[lineEnd - lineStart] = '\0';
}
SString SciTEBase::GetLine(int line) {
int len;
// Get needed buffer size
if (line < 0) {
len = wEditor.Call(SCI_GETCURLINE, 0, 0);
} else {
len = wEditor.Call(SCI_GETLINE, line, 0);
}
// Allocate buffer
SBuffer text(len);
// And get the line
if (line < 0) {
wEditor.CallString(SCI_GETCURLINE, len, text.ptr());
} else {
wEditor.CallString(SCI_GETLINE, line, text.ptr());
}
return SString(text);
}
void SciTEBase::GetRange(GUI::ScintillaWindow &win, int start, int end, char *text) {
Sci_TextRange tr;
tr.chrg.cpMin = start;
tr.chrg.cpMax = end;
tr.lpstrText = text;
win.SendPointer(SCI_GETTEXTRANGE, 0, &tr);
}
/**
* Check if the given line is a preprocessor condition line.
* @return The kind of preprocessor condition (enum values).
*/
int SciTEBase::IsLinePreprocessorCondition(char *line) {
char *currChar = line;
if (!currChar) {
return false;
}
while (isspacechar(*currChar) && *currChar) {
currChar++;
}
if (preprocessorSymbol && (*currChar == preprocessorSymbol)) {
currChar++;
while (isspacechar(*currChar) && *currChar) {
currChar++;
}
char word[32];
size_t i = 0;
while (!isspacechar(*currChar) && *currChar && (i < (sizeof(word) - 1))) {
word[i++] = *currChar++;
}
word[i] = '\0';
if (preprocCondStart.InList(word)) {
return ppcStart;
}
if (preprocCondMiddle.InList(word)) {
return ppcMiddle;
}
if (preprocCondEnd.InList(word)) {
return ppcEnd;
}
}
return noPPC;
}
/**
* Search a matching preprocessor condition line.
* @return @c true if the end condition are meet.
* Also set curLine to the line where one of these conditions is mmet.
*/
bool SciTEBase::FindMatchingPreprocessorCondition(
int &curLine, ///< Number of the line where to start the search
int direction, ///< Direction of search: 1 = forward, -1 = backward
int condEnd1, ///< First status of line for which the search is OK
int condEnd2) { ///< Second one
bool isInside = false;
char line[800]; // No need for full line
int level = 0;
int maxLines = wEditor.Call(SCI_GETLINECOUNT) - 1;
while (curLine < maxLines && curLine > 0 && !isInside) {
curLine += direction; // Increment or decrement
GetLine(line, sizeof(line), curLine);
int status = IsLinePreprocessorCondition(line);
if ((direction == 1 && status == ppcStart) || (direction == -1 && status == ppcEnd)) {
level++;
} else if (level > 0 && ((direction == 1 && status == ppcEnd) || (direction == -1 && status == ppcStart))) {
level--;
} else if (level == 0 && (status == condEnd1 || status == condEnd2)) {
isInside = true;
}
}
return isInside;
}
/**
* Find if there is a preprocessor condition after or before the caret position,
* @return @c true if inside a preprocessor condition.
*/
bool SciTEBase::FindMatchingPreprocCondPosition(
bool isForward, ///< @c true if search forward
int &mppcAtCaret, ///< Matching preproc. cond.: current position of caret
int &mppcMatch) { ///< Matching preproc. cond.: matching position
bool isInside = false;
int curLine;
char line[800]; // Probably no need to get more characters, even if the line is longer, unless very strange layout...
int status;
// Get current line
curLine = wEditor.Call(SCI_LINEFROMPOSITION, mppcAtCaret);
GetLine(line, sizeof(line), curLine);
status = IsLinePreprocessorCondition(line);
switch (status) {
case ppcStart:
if (isForward) {
isInside = FindMatchingPreprocessorCondition(curLine, 1, ppcMiddle, ppcEnd);
} else {
mppcMatch = mppcAtCaret;
return true;
}
break;
case ppcMiddle:
if (isForward) {
isInside = FindMatchingPreprocessorCondition(curLine, 1, ppcMiddle, ppcEnd);
} else {
isInside = FindMatchingPreprocessorCondition(curLine, -1, ppcStart, ppcMiddle);
}
break;
case ppcEnd:
if (isForward) {
mppcMatch = mppcAtCaret;
return true;
} else {
isInside = FindMatchingPreprocessorCondition(curLine, -1, ppcStart, ppcMiddle);
}
break;
default: // Should be noPPC
if (isForward) {
isInside = FindMatchingPreprocessorCondition(curLine, 1, ppcMiddle, ppcEnd);
} else {
isInside = FindMatchingPreprocessorCondition(curLine, -1, ppcStart, ppcMiddle);
}
break;
}
if (isInside) {
mppcMatch = wEditor.Call(SCI_POSITIONFROMLINE, curLine);
}
return isInside;
}
static bool IsBrace(char ch) {
return ch == '[' || ch == ']' || ch == '(' || ch == ')' || ch == '{' || ch == '}';
}
/**
* Find if there is a brace next to the caret, checking before caret first, then
* after caret. If brace found also find its matching brace.
* @return @c true if inside a bracket pair.
*/
bool SciTEBase::FindMatchingBracePosition(bool editor, int &braceAtCaret, int &braceOpposite, bool sloppy) {
int maskStyle = (1 << wEditor.Call(SCI_GETSTYLEBITSNEEDED)) - 1;
bool isInside = false;
GUI::ScintillaWindow &win = editor ? wEditor : wOutput;
int mainSel = win.Call(SCI_GETMAINSELECTION, 0, 0);
if (win.Send(SCI_GETSELECTIONNCARETVIRTUALSPACE, mainSel, 0) > 0)
return false;
int bracesStyleCheck = editor ? bracesStyle : 0;
int caretPos = win.Call(SCI_GETCURRENTPOS, 0, 0);
braceAtCaret = -1;
braceOpposite = -1;
char charBefore = '\0';
char styleBefore = '\0';
int lengthDoc = win.Call(SCI_GETLENGTH, 0, 0);
TextReader acc(win);
if ((lengthDoc > 0) && (caretPos > 0)) {
// Check to ensure not matching brace that is part of a multibyte character
if (win.Send(SCI_POSITIONBEFORE, caretPos) == (caretPos - 1)) {
charBefore = acc[caretPos - 1];
styleBefore = static_cast<char>(acc.StyleAt(caretPos - 1) & maskStyle);
}
}
// Priority goes to character before caret
if (charBefore && IsBrace(charBefore) &&
((styleBefore == bracesStyleCheck) || (!bracesStyle))) {
braceAtCaret = caretPos - 1;
}
bool colonMode = false;
if ((lexLanguage == SCLEX_PYTHON) &&
(':' == charBefore) && (SCE_P_OPERATOR == styleBefore)) {
braceAtCaret = caretPos - 1;
colonMode = true;
}
bool isAfter = true;
if (lengthDoc > 0 && sloppy && (braceAtCaret < 0) && (caretPos < lengthDoc)) {
// No brace found so check other side
// Check to ensure not matching brace that is part of a multibyte character
if (win.Send(SCI_POSITIONAFTER, caretPos) == (caretPos + 1)) {
char charAfter = acc[caretPos];
char styleAfter = static_cast<char>(acc.StyleAt(caretPos) & maskStyle);
if (charAfter && IsBrace(charAfter) && ((styleAfter == bracesStyleCheck) || (!bracesStyle))) {
braceAtCaret = caretPos;
isAfter = false;
}
if ((lexLanguage == SCLEX_PYTHON) &&
(':' == charAfter) && (SCE_P_OPERATOR == styleAfter)) {
braceAtCaret = caretPos;
colonMode = true;
}
}
}
if (braceAtCaret >= 0) {
if (colonMode) {
int lineStart = win.Call(SCI_LINEFROMPOSITION, braceAtCaret);
int lineMaxSubord = win.Call(SCI_GETLASTCHILD, lineStart, -1);
braceOpposite = win.Call(SCI_GETLINEENDPOSITION, lineMaxSubord);
} else {
braceOpposite = win.Call(SCI_BRACEMATCH, braceAtCaret, 0);
}
if (braceOpposite > braceAtCaret) {
isInside = isAfter;
} else {
isInside = !isAfter;
}
}
return isInside;
}
void SciTEBase::BraceMatch(bool editor) {
if (!bracesCheck)
return;
int braceAtCaret = -1;
int braceOpposite = -1;
FindMatchingBracePosition(editor, braceAtCaret, braceOpposite, bracesSloppy);
GUI::ScintillaWindow &win = editor ? wEditor : wOutput;
if ((braceAtCaret != -1) && (braceOpposite == -1)) {
win.Send(SCI_BRACEBADLIGHT, braceAtCaret, 0);
wEditor.Call(SCI_SETHIGHLIGHTGUIDE, 0);
} else {
char chBrace = 0;
if (braceAtCaret >= 0)
chBrace = static_cast<char>(win.Send(
SCI_GETCHARAT, braceAtCaret, 0));
win.Send(SCI_BRACEHIGHLIGHT, braceAtCaret, braceOpposite);
int columnAtCaret = win.Call(SCI_GETCOLUMN, braceAtCaret, 0);
int columnOpposite = win.Call(SCI_GETCOLUMN, braceOpposite, 0);
if (chBrace == ':') {
int lineStart = win.Call(SCI_LINEFROMPOSITION, braceAtCaret);
int indentPos = win.Call(SCI_GETLINEINDENTPOSITION, lineStart, 0);
int indentPosNext = win.Call(SCI_GETLINEINDENTPOSITION, lineStart + 1, 0);
columnAtCaret = win.Call(SCI_GETCOLUMN, indentPos, 0);
int columnAtCaretNext = win.Call(SCI_GETCOLUMN, indentPosNext, 0);
int indentSize = win.Call(SCI_GETINDENT);
if (columnAtCaretNext - indentSize > 1)
columnAtCaret = columnAtCaretNext - indentSize;
if (columnOpposite == 0) // If the final line of the structure is empty
columnOpposite = columnAtCaret;
} else {
if (win.Send(SCI_LINEFROMPOSITION, braceAtCaret) == win.Send(SCI_LINEFROMPOSITION, braceOpposite)) {
// Avoid attempting to draw a highlight guide
columnAtCaret = 0;
columnOpposite = 0;
}
}
if (props.GetInt("highlight.indentation.guides"))
win.Send(SCI_SETHIGHLIGHTGUIDE, Minimum(columnAtCaret, columnOpposite), 0);
}
}
void SciTEBase::SetWindowName() {
if (filePath.IsUntitled()) {
windowName = localiser.Text("Untitled");
windowName.insert(0, GUI_TEXT("("));
windowName += GUI_TEXT(")");
} else if (props.GetInt("title.full.path") == 2) {
windowName = FileNameExt().AsInternal();
windowName += GUI_TEXT(" ");
windowName += localiser.Text("in");
windowName += GUI_TEXT(" ");
windowName += filePath.Directory().AsInternal();
} else if (props.GetInt("title.full.path") == 1) {
windowName = filePath.AsInternal();
} else {
windowName = FileNameExt().AsInternal();
}
if (CurrentBuffer()->isDirty)
windowName += GUI_TEXT(" * ");
else
windowName += GUI_TEXT(" - ");
windowName += appName;
if (buffers.length > 1 && props.GetInt("title.show.buffers")) {
windowName += GUI_TEXT(" [");
windowName += GUI::StringFromInteger(buffers.Current() + 1);
windowName += GUI_TEXT(" ");
windowName += localiser.Text("of");
windowName += GUI_TEXT(" ");
windowName += GUI::StringFromInteger(buffers.length);
windowName += GUI_TEXT("]");
}
wSciTE.SetTitle(windowName.c_str());
}
Sci_CharacterRange SciTEBase::GetSelection() {
Sci_CharacterRange crange;
crange.cpMin = wEditor.Call(SCI_GETSELECTIONSTART);
crange.cpMax = wEditor.Call(SCI_GETSELECTIONEND);
return crange;
}
SelectedRange SciTEBase::GetSelectedRange() {
return SelectedRange(wEditor.Call(SCI_GETCURRENTPOS), wEditor.Call(SCI_GETANCHOR));
}
void SciTEBase::SetSelection(int anchor, int currentPos) {
wEditor.Call(SCI_SETSEL, anchor, currentPos);
}
SString SciTEBase::GetCTag() {
int lengthDoc, selStart, selEnd;
int mustStop = 0;
char c;
GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
lengthDoc = wCurrent.Call(SCI_GETLENGTH);
selStart = selEnd = wCurrent.Call(SCI_GETSELECTIONEND);
TextReader acc(wCurrent);
while (!mustStop) {
if (selStart < lengthDoc - 1) {
selStart++;
c = acc[selStart];
if (c == '\r' || c == '\n') {
mustStop = -1;
} else if (c == '\t' && ((acc[selStart + 1] == '/' && acc[selStart + 2] == '^') || isdigit(acc[selStart + 1]))) {
mustStop = 1;
}
} else {
mustStop = -1;
}
}
if (mustStop == 1 && (acc[selStart + 1] == '/' && acc[selStart + 2] == '^')) { // Found
selEnd = selStart += 3;
mustStop = 0;
while (!mustStop) {
if (selEnd < lengthDoc - 1) {
selEnd++;
c = acc[selEnd];
if (c == '\r' || c == '\n') {
mustStop = -1;
} else if (c == '$' && acc[selEnd + 1] == '/') {
mustStop = 1; // Found!
}
} else {
mustStop = -1;
}
}
} else if (mustStop == 1 && isdigit(acc[selStart + 1])) {
// a Tag can be referenced by line Number also
selEnd = selStart += 1;
while (isdigit(acc[selEnd]) && (selEnd < lengthDoc)) {
selEnd++;
}
}
if (selStart < selEnd) {
return GetRange(wCurrent, selStart, selEnd);
} else {
return SString();
}
}
// Default characters that can appear in a word
bool SciTEBase::iswordcharforsel(char ch) {
return !strchr("\t\n\r !\"#$%&'()*+,-./:;<=>?@[\\]^`{|}~", ch);
}
// Accept slightly more characters than for a word
// Doesn't accept all valid characters, as they are rarely used in source filenames...
// Accept path separators '/' and '\', extension separator '.', and ':', MS drive unit
// separator, and also used for separating the line number for grep. Same for '(' and ')' for cl.
// Accept '?' and '%' which are used in URL.
bool SciTEBase::isfilenamecharforsel(char ch) {
return !strchr("\t\n\r \"$'*,;<>[]^`{|}", ch);
}
bool SciTEBase::islexerwordcharforsel(char ch) {
// If there are no word.characters defined for the current file, fall back on the original function
if (wordCharacters.length())
return wordCharacters.contains(ch);
else
return iswordcharforsel(ch);
}
void SciTEBase::HighlightCurrentWord(bool highlight) {
if (!currentWordHighlight.isEnabled)
return;
GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
// Remove old indicators if any exist.
wCurrent.Call(SCI_SETINDICATORCURRENT, indicatorHightlightCurrentWord);
int lenDoc = wCurrent.Call(SCI_GETLENGTH);
wCurrent.Call(SCI_INDICATORCLEARRANGE, 0, lenDoc);
if (!highlight)
return;
// Get start & end selection.
int selStart = wCurrent.Call(SCI_GETSELECTIONSTART);
int selEnd = wCurrent.Call(SCI_GETSELECTIONEND);
bool noUserSelection = selStart == selEnd;
SString wordToFind = RangeExtendAndGrab(wCurrent, selStart, selEnd,
&SciTEBase::islexerwordcharforsel);
if (wordToFind.length() == 0 || wordToFind.contains('\n') || wordToFind.contains('\r'))
return; // No highlight when no selection or multi-lines selection.
if (noUserSelection && currentWordHighlight.statesOfDelay == currentWordHighlight.noDelay) {
// Manage delay before highlight when no user selection but there is word at the caret.
currentWordHighlight.statesOfDelay = currentWordHighlight.delay;
// Reset timer
currentWordHighlight.elapsedTimes.Duration(true);
return;
}
// Get style of the current word to highlight only word with same style.
int selectedStyle = wCurrent.Call(SCI_GETSTYLEAT, selStart);
// Manage word with DBCS.
wordToFind = EncodeString(wordToFind);
// Case sensitive & whole word only.
wCurrent.Call(SCI_SETSEARCHFLAGS, SCFIND_MATCHCASE | SCFIND_WHOLEWORD);
wCurrent.Call(SCI_SETTARGETSTART, 0);
wCurrent.Call(SCI_SETTARGETEND, lenDoc);
//Monitor the amount of time took by the search.
GUI::ElapsedTime searchElapsedTime;
// Find the first occurrence of word.
int indexOf = wCurrent.CallString(SCI_SEARCHINTARGET,
wordToFind.length(), wordToFind.c_str());
while (indexOf != -1 && indexOf < lenDoc) {
// Limit the search duration to 250 ms. Avoid to freeze editor for large files.
if (searchElapsedTime.Duration() > 0.25) {
// Clear all indicators because timer has expired.
wCurrent.Call(SCI_INDICATORCLEARRANGE, 0, lenDoc);
break;
}
if (!currentWordHighlight.isOnlyWithSameStyle || selectedStyle ==
wCurrent.Call(SCI_GETSTYLEAT, indexOf)) {
wCurrent.Call(SCI_INDICATORFILLRANGE, indexOf, wordToFind.length());
}
// Try to find next occurrence of word.
wCurrent.Call(SCI_SETTARGETSTART, indexOf + wordToFind.length() + 1);
wCurrent.Call(SCI_SETTARGETEND, lenDoc);
indexOf = wCurrent.CallString(SCI_SEARCHINTARGET, wordToFind.length(),
wordToFind.c_str());
}
}
SString SciTEBase::GetRange(GUI::ScintillaWindow &win, int selStart, int selEnd) {
SBuffer sel(selEnd - selStart);
Sci_TextRange tr;
tr.chrg.cpMin = selStart;
tr.chrg.cpMax = selEnd;
tr.lpstrText = sel.ptr();
win.SendPointer(SCI_GETTEXTRANGE, 0, &tr);
return SString(sel);
}
SString SciTEBase::GetRangeInUIEncoding(GUI::ScintillaWindow &win, int selStart, int selEnd) {
return GetRange(win, selStart, selEnd);
}
SString SciTEBase::GetLine(GUI::ScintillaWindow &win, int line) {
int lineStart = win.Call(SCI_POSITIONFROMLINE, line);
int lineEnd = win.Call(SCI_GETLINEENDPOSITION, line);
if ((lineStart < 0) || (lineEnd < 0))
return SString();
return GetRange(win, lineStart, lineEnd);
}
SString SciTEBase::RangeExtendAndGrab(
GUI::ScintillaWindow &wCurrent,
int &selStart,
int &selEnd,
bool (SciTEBase::*ischarforsel)(char ch), ///< Function returning @c true if the given char. is part of the selection.
bool stripEol /*=true*/) {
if (selStart == selEnd && ischarforsel) {
// Empty range and have a function to extend it
int lengthDoc = wCurrent.Call(SCI_GETLENGTH);
TextReader acc(wCurrent);
// Try and find a word at the caret
// On the left...
while ((selStart > 0) && ((this->*ischarforsel)(acc[selStart - 1]))) {
selStart--;
}
// and on the right
while ((selEnd < lengthDoc) && ((this->*ischarforsel)(acc[selEnd]))) {
selEnd++;
}
}
SString selected;
if (selStart != selEnd) {
selected = GetRangeInUIEncoding(wCurrent, selStart, selEnd);
}
if (stripEol) {
// Change whole line selected but normally end of line characters not wanted.
// Remove possible terminating \r, \n, or \r\n.
size_t sellen = selected.length();
if (sellen >= 2 && (selected[sellen - 2] == '\r' && selected[sellen - 1] == '\n')) {
selected.remove(sellen - 2, 0);
} else if (sellen >= 1 && (selected[sellen - 1] == '\r' || selected[sellen - 1] == '\n')) {
selected.remove(sellen - 1, 0);
}
}
return selected;
}
/**
* If there is selected text, either in the editor or the output pane,
* put the selection in the @a sel buffer, up to @a len characters.
* Otherwise, try and select characters around the caret, as long as they are OK
* for the @a ischarforsel function.
* Remove the last two character controls from the result, as they are likely
* to be CR and/or LF.
*/
SString SciTEBase::SelectionExtend(
bool (SciTEBase::*ischarforsel)(char ch), ///< Function returning @c true if the given char. is part of the selection.
bool stripEol /*=true*/) {
GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
int selStart = wCurrent.Call(SCI_GETSELECTIONSTART);
int selEnd = wCurrent.Call(SCI_GETSELECTIONEND);
return RangeExtendAndGrab(wCurrent, selStart, selEnd, ischarforsel, stripEol);
}
SString SciTEBase::SelectionWord(bool stripEol /*=true*/) {
return SelectionExtend(&SciTEBase::islexerwordcharforsel, stripEol);
}
SString SciTEBase::SelectionFilename() {
return SelectionExtend(&SciTEBase::isfilenamecharforsel);
}
void SciTEBase::SelectionIntoProperties() {
SString currentSelection = SelectionExtend(0, false);
props.Set("CurrentSelection", currentSelection.c_str());
SString word = SelectionWord();
props.Set("CurrentWord", word.c_str());
int selStart = CallFocused(SCI_GETSELECTIONSTART);
int selEnd = CallFocused(SCI_GETSELECTIONEND);
props.SetInteger("SelectionStartLine", CallFocused(SCI_LINEFROMPOSITION, selStart) + 1);
props.SetInteger("SelectionStartColumn", CallFocused(SCI_GETCOLUMN, selStart) + 1);
props.SetInteger("SelectionEndLine", CallFocused(SCI_LINEFROMPOSITION, selEnd) + 1);
props.SetInteger("SelectionEndColumn", CallFocused(SCI_GETCOLUMN, selEnd) + 1);
}
void SciTEBase::SelectionIntoFind(bool stripEol /*=true*/) {
SString sel = SelectionWord(stripEol);
if (sel.length() && !sel.contains('\r') && !sel.contains('\n')) {
// The selection does not include a new line, so is likely to be
// the expression to search...
findWhat = sel;
if (unSlash) {
char *slashedFind = Slash(findWhat.c_str(), false);
if (slashedFind) {
findWhat = slashedFind;
delete []slashedFind;
}
}
}
// else findWhat remains the same as last time.
}
SString SciTEBase::EncodeString(const SString &s) {
return SString(s);
}
static int UnSlashAsNeeded(SString &s, bool escapes, bool regularExpression) {
if (escapes) {
char *sUnslashed = StringDup(s.c_str(), s.length());
size_t len;
if (regularExpression) {
// For regular expressions, the only escape sequences allowed start with \0
// Other sequences, like \t, are handled by the RE engine.
len = UnSlashLowOctal(sUnslashed);
} else {
// C style escapes allowed
len = UnSlash(sUnslashed);
}
s = sUnslashed;
delete []sUnslashed;
return static_cast<int>(len);
} else {
return static_cast<int>(s.length());
}
}
void SciTEBase::RemoveFindMarks() {
if (CurrentBuffer()->findMarks != Buffer::fmNone) {
wEditor.Call(SCI_SETINDICATORCURRENT, indicatorMatch);
wEditor.Call(SCI_INDICATORCLEARRANGE, 0, LengthDocument());
CurrentBuffer()->findMarks = Buffer::fmNone;
}
wEditor.Call(SCI_ANNOTATIONCLEARALL);
}
int SciTEBase::MarkAll() {
int posCurrent = wEditor.Call(SCI_GETCURRENTPOS);
int marked = 0;
int posFirstFound = FindNext(false, false);
SString findMark = props.Get("find.mark");
if (findMark.length()) {
wEditor.Call(SCI_SETINDICATORCURRENT, indicatorMatch);
RemoveFindMarks();
CurrentBuffer()->findMarks = Buffer::fmMarked;
}
if (posFirstFound != -1) {
int posEndFound;
int posFound = posFirstFound;
do {
marked++;
int line = wEditor.Call(SCI_LINEFROMPOSITION, posFound);
BookmarkAdd(line);
if (findMark.length()) {
wEditor.Call(SCI_INDICATORFILLRANGE, posFound, wEditor.Call(SCI_GETTARGETEND) - posFound);
}
posFound = FindNext(false, false);
posEndFound = wEditor.Call(SCI_GETTARGETEND);
// Since start position may be within a match, terminate when match includes initial position
} while ((posFound != -1) && !((posFound <= posFirstFound) && (posFirstFound <= posEndFound)));
}
wEditor.Call(SCI_SETCURRENTPOS, posCurrent);
return marked;
}
int SciTEBase::IncrementSearchMode() {
FindIncrement();
return 0;
}
int SciTEBase::FindInTarget(const char *findWhatText, int lenFind, int startPosition, int endPosition) {
wEditor.Call(SCI_SETTARGETSTART, startPosition);
wEditor.Call(SCI_SETTARGETEND, endPosition);
int posFind = wEditor.CallString(SCI_SEARCHINTARGET, lenFind, findWhatText);
while (findInStyle && posFind != -1 && findStyle != wEditor.Call(SCI_GETSTYLEAT, posFind)) {
if (startPosition < endPosition) {
wEditor.Call(SCI_SETTARGETSTART, posFind + 1);
wEditor.Call(SCI_SETTARGETEND, endPosition);
} else {
wEditor.Call(SCI_SETTARGETSTART, startPosition);
wEditor.Call(SCI_SETTARGETEND, posFind + 1);
}
posFind = wEditor.CallString(SCI_SEARCHINTARGET, lenFind, findWhatText);
}
return posFind;
}
void SciTEBase::SetFind(const char *sFind) {
findWhat = sFind;
memFinds.Insert(findWhat.c_str());
props.Set("find.what", findWhat.c_str());
}
bool SciTEBase::FindHasText() const {
return findWhat[0];
}
void SciTEBase::SetReplace(const char *sReplace) {
replaceWhat = sReplace;
memReplaces.Insert(replaceWhat.c_str());
}
void SciTEBase::MoveBack(int distance) {
Sci_CharacterRange cr = GetSelection();
int caret = static_cast<int>(cr.cpMin) - distance;
SetSelection(caret, caret);
}
void SciTEBase::ScrollEditorIfNeeded() {
GUI::Point ptCaret;
int caret = wEditor.Call(SCI_GETCURRENTPOS);
ptCaret.x = wEditor.Call(SCI_POINTXFROMPOSITION, 0, caret);
ptCaret.y = wEditor.Call(SCI_POINTYFROMPOSITION, 0, caret);
ptCaret.y += wEditor.Call(SCI_TEXTHEIGHT, 0, 0) - 1;
GUI::Rectangle rcEditor = wEditor.GetClientPosition();
if (!rcEditor.Contains(ptCaret))
wEditor.Call(SCI_SCROLLCARET);
}
int SciTEBase::FindNext(bool reverseDirection, bool showWarnings, bool allowRegExp) {
if (findWhat.length() == 0) {
Find();
return -1;
}
SString findTarget = EncodeString(findWhat);
int lenFind = UnSlashAsNeeded(findTarget, unSlash, regExp);
if (lenFind == 0)
return -1;
Sci_CharacterRange cr = GetSelection();
int startPosition = static_cast<int>(cr.cpMax);
int endPosition = LengthDocument();
if (reverseDirection) {
startPosition = static_cast<int>(cr.cpMin);
endPosition = 0;
}
int flags = (wholeWord ? SCFIND_WHOLEWORD : 0) |
(matchCase ? SCFIND_MATCHCASE : 0) |
((allowRegExp && regExp) ? SCFIND_REGEXP : 0) |
(props.GetInt("find.replace.regexp.posix") ? SCFIND_POSIX : 0);
wEditor.Call(SCI_SETSEARCHFLAGS, flags);
int posFind = FindInTarget(findTarget.c_str(), lenFind, startPosition, endPosition);
if (posFind == -1 && wrapFind) {
// Failed to find in indicated direction
// so search from the beginning (forward) or from the end (reverse)
// unless wrapFind is false
if (reverseDirection) {
startPosition = LengthDocument();
endPosition = 0;
} else {
startPosition = 0;
endPosition = LengthDocument();
}
posFind = FindInTarget(findTarget.c_str(), lenFind, startPosition, endPosition);
WarnUser(warnFindWrapped);
}
if (posFind == -1) {
havefound = false;
if (showWarnings) {
WarnUser(warnNotFound);
FindMessageBox("Can not find the string '^0'.",
&findWhat);
}
} else {
havefound = true;
int start = wEditor.Call(SCI_GETTARGETSTART);
int end = wEditor.Call(SCI_GETTARGETEND);
// Ensure found text is styled so that caret will be made visible.
int endStyled = wEditor.Call(SCI_GETENDSTYLED);
if (endStyled < end)
wEditor.Call(SCI_COLOURISE, endStyled, end);
EnsureRangeVisible(wEditor, start, end);
wEditor.Call(SCI_SCROLLRANGE, start, end);
SetSelection(start, end);
if (!replacing && closeFind) {
DestroyFindReplace();
}
}
return posFind;
}
void SciTEBase::HideMatch() {
}
void SciTEBase::ReplaceOnce() {
if (!FindHasText())
return;
if (!havefound) {
Sci_CharacterRange crange = GetSelection();
SetSelection(static_cast<int>(crange.cpMin), static_cast<int>(crange.cpMin));
FindNext(false);
}
if (havefound) {
SString replaceTarget = EncodeString(replaceWhat);
int replaceLen = UnSlashAsNeeded(replaceTarget, unSlash, regExp);
Sci_CharacterRange cr = GetSelection();
wEditor.Call(SCI_SETTARGETSTART, cr.cpMin);
wEditor.Call(SCI_SETTARGETEND, cr.cpMax);
int lenReplaced = replaceLen;
if (regExp)
lenReplaced = wEditor.CallString(SCI_REPLACETARGETRE, replaceLen, replaceTarget.c_str());
else // Allow \0 in replacement
wEditor.CallString(SCI_REPLACETARGET, replaceLen, replaceTarget.c_str());
SetSelection(static_cast<int>(cr.cpMin) + lenReplaced, static_cast<int>(cr.cpMin));
havefound = false;
}
FindNext(false);
}
int SciTEBase::DoReplaceAll(bool inSelection) {
SString findTarget = EncodeString(findWhat);
int findLen = UnSlashAsNeeded(findTarget, unSlash, regExp);
if (findLen == 0) {
return -1;
}
Sci_CharacterRange cr = GetSelection();
int startPosition = static_cast<int>(cr.cpMin);
int endPosition = static_cast<int>(cr.cpMax);
int countSelections = wEditor.Call(SCI_GETSELECTIONS);
if (inSelection) {
int selType = wEditor.Call(SCI_GETSELECTIONMODE);
if (selType == SC_SEL_LINES) {
// Take care to replace in whole lines
int startLine = wEditor.Call(SCI_LINEFROMPOSITION, startPosition);
startPosition = wEditor.Call(SCI_POSITIONFROMLINE, startLine);
int endLine = wEditor.Call(SCI_LINEFROMPOSITION, endPosition);
endPosition = wEditor.Call(SCI_POSITIONFROMLINE, endLine + 1);
} else {
for (int i=0; i<countSelections; i++) {
startPosition = Minimum(startPosition, wEditor.Call(SCI_GETSELECTIONNSTART, i));
endPosition = Maximum(endPosition, wEditor.Call(SCI_GETSELECTIONNEND, i));
}
}
if (startPosition == endPosition) {
return -2;
}
} else {
endPosition = LengthDocument();
if (wrapFind) {
// Whole document
startPosition = 0;
}
// If not wrapFind, replace all only from caret to end of document
}
SString replaceTarget = EncodeString(replaceWhat);
int replaceLen = UnSlashAsNeeded(replaceTarget, unSlash, regExp);
int flags = (wholeWord ? SCFIND_WHOLEWORD : 0) |
(matchCase ? SCFIND_MATCHCASE : 0) |
(regExp ? SCFIND_REGEXP : 0) |
(props.GetInt("find.replace.regexp.posix") ? SCFIND_POSIX : 0);
wEditor.Call(SCI_SETSEARCHFLAGS, flags);
int posFind = FindInTarget(findTarget.c_str(), findLen, startPosition, endPosition);
if ((findLen == 1) && regExp && (findTarget[0] == '^')) {
// Special case for replace all start of line so it hits the first line
posFind = startPosition;
wEditor.Call(SCI_SETTARGETSTART, startPosition);
wEditor.Call(SCI_SETTARGETEND, startPosition);
}
if ((posFind != -1) && (posFind <= endPosition)) {
int lastMatch = posFind;
int replacements = 0;
wEditor.Call(SCI_BEGINUNDOACTION);
// Replacement loop
while (posFind != -1) {
int lenTarget = wEditor.Call(SCI_GETTARGETEND) - wEditor.Call(SCI_GETTARGETSTART);
if (inSelection && countSelections > 1) {
// We must check that the found target is entirely inside a selection
bool insideASelection = false;
for (int i=0; i<countSelections && !insideASelection; i++) {
int startPos= wEditor.Call(SCI_GETSELECTIONNSTART, i);
int endPos = wEditor.Call(SCI_GETSELECTIONNEND, i);
if (posFind >= startPos && posFind + lenTarget <= endPos)
insideASelection = true;
}
if (!insideASelection) {
// Found target is totally or partly outside the selections
lastMatch = posFind + 1;
if (lastMatch >= endPosition) {
// Run off the end of the document/selection with an empty match
posFind = -1;
} else {
posFind = FindInTarget(findTarget.c_str(), findLen, lastMatch, endPosition);
}
continue; // No replacement
}
}
int movepastEOL = 0;
if (lenTarget <= 0) {
char chNext = static_cast<char>(wEditor.Call(SCI_GETCHARAT, wEditor.Call(SCI_GETTARGETEND)));
if (chNext == '\r' || chNext == '\n') {
movepastEOL = 1;
}
}
int lenReplaced = replaceLen;
if (regExp) {
lenReplaced = wEditor.CallString(SCI_REPLACETARGETRE, replaceLen, replaceTarget.c_str());
} else {
wEditor.CallString(SCI_REPLACETARGET, replaceLen, replaceTarget.c_str());
}
// Modify for change caused by replacement
endPosition += lenReplaced - lenTarget;
// For the special cases of start of line and end of line
// something better could be done but there are too many special cases
lastMatch = posFind + lenReplaced + movepastEOL;
if (lenTarget == 0) {
lastMatch = wEditor.Call(SCI_POSITIONAFTER, lastMatch);
}
if (lastMatch >= endPosition) {
// Run off the end of the document/selection with an empty match
posFind = -1;
} else {
posFind = FindInTarget(findTarget.c_str(), findLen, lastMatch, endPosition);
}
replacements++;
}
if (inSelection) {
if (countSelections == 1)
SetSelection(startPosition, endPosition);
} else {
SetSelection(lastMatch, lastMatch);
}
wEditor.Call(SCI_ENDUNDOACTION);
return replacements;
}
return 0;
}
int SciTEBase::ReplaceAll(bool inSelection) {
int replacements = DoReplaceAll(inSelection);
props.SetInteger("Replacements", (replacements > 0 ? replacements : 0));
UpdateStatusBar(false);
if (replacements == -1) {
FindMessageBox(
inSelection ?
"Find string must not be empty for 'Replace in Selection' command." :
"Find string must not be empty for 'Replace All' command.");
} else if (replacements == -2) {
FindMessageBox(
"Selection must not be empty for 'Replace in Selection' command.");
} else if (replacements == 0) {
FindMessageBox(
"No replacements because string '^0' was not present.", &findWhat);
}
return replacements;
}
int SciTEBase::ReplaceInBuffers() {
int currentBuffer = buffers.Current();
int replacements = 0;
for (int i = 0; i < buffers.length; i++) {
SetDocumentAt(i);
replacements += DoReplaceAll(false);
if (i == 0 && replacements < 0) {
FindMessageBox(
"Find string must not be empty for 'Replace in Buffers' command.");
break;
}
}
SetDocumentAt(currentBuffer);
props.SetInteger("Replacements", replacements);
UpdateStatusBar(false);
if (replacements == 0) {
FindMessageBox(
"No replacements because string '^0' was not present.", &findWhat);
}
return replacements;
}
void SciTEBase::UIClosed() {
}
void SciTEBase::UIHasFocus() {
}
void SciTEBase::OutputAppendString(const char *s, int len) {
if (len == -1)
len = static_cast<int>(strlen(s));
wOutput.Call(SCI_APPENDTEXT, len, reinterpret_cast<sptr_t>(s));
if (scrollOutput) {
int line = wOutput.Call(SCI_GETLINECOUNT, 0, 0);
int lineStart = wOutput.Call(SCI_POSITIONFROMLINE, line);
wOutput.Call(SCI_GOTOPOS, lineStart);
}
}
void SciTEBase::OutputAppendStringSynchronised(const char *s, int len) {
if (len == -1)
len = static_cast<int>(strlen(s));
wOutput.Send(SCI_APPENDTEXT, len, reinterpret_cast<sptr_t>(s));
if (scrollOutput) {
sptr_t line = wOutput.Send(SCI_GETLINECOUNT);
sptr_t lineStart = wOutput.Send(SCI_POSITIONFROMLINE, line);
wOutput.Send(SCI_GOTOPOS, lineStart);
}
}
void SciTEBase::MakeOutputVisible() {
if (heightOutput <= 0) {
ToggleOutputVisible();
}
}
void SciTEBase::Execute() {
props.Set("CurrentMessage", "");
dirNameForExecute = FilePath();
bool displayParameterDialog = false;
int ic;
parameterisedCommand = "";
for (ic = 0; ic < jobQueue.commandMax; ic++) {
if (jobQueue.jobQueue[ic].command[0] == '*') {
displayParameterDialog = true;
jobQueue.jobQueue[ic].command.remove(0, 1);
parameterisedCommand = jobQueue.jobQueue[ic].command;
}
if (jobQueue.jobQueue[ic].directory.IsSet()) {
dirNameForExecute = jobQueue.jobQueue[ic].directory;
}
}
if (displayParameterDialog) {
if (!ParametersDialog(true)) {
jobQueue.ClearJobs();
return;
}
} else {
ParamGrab();
}
for (ic = 0; ic < jobQueue.commandMax; ic++) {
jobQueue.jobQueue[ic].command = props.Expand(jobQueue.jobQueue[ic].command.c_str());
}
if (jobQueue.ClearBeforeExecute()) {
wOutput.Send(SCI_CLEARALL);
}
wOutput.Call(SCI_MARKERDELETEALL, static_cast<uptr_t>(-1));
wEditor.Call(SCI_MARKERDELETEALL, 0);
// Ensure the output pane is visible
if (jobQueue.ShowOutputPane()) {
MakeOutputVisible();
}
jobQueue.cancelFlag = 0L;
if (jobQueue.HasCommandToRun()) {
jobQueue.SetExecuting(true);
}
CheckMenus();
dirNameAtExecute = filePath.Directory();
}
void SciTEBase::ToggleOutputVisible() {
if (heightOutput > 0) {
heightOutput = NormaliseSplit(0);
WindowSetFocus(wEditor);
} else {
if (previousHeightOutput < 20) {
if (splitVertical)
heightOutput = NormaliseSplit(300);
else
heightOutput = NormaliseSplit(100);
previousHeightOutput = heightOutput;
} else {
heightOutput = NormaliseSplit(previousHeightOutput);
}
}
SizeSubWindows();
Redraw();
}
void SciTEBase::BookmarkAdd(int lineno) {
if (lineno == -1)
lineno = GetCurrentLineNumber();
if (!BookmarkPresent(lineno))
wEditor.Call(SCI_MARKERADD, lineno, markerBookmark);
}
void SciTEBase::BookmarkDelete(int lineno) {
if (lineno == -1)
lineno = GetCurrentLineNumber();
if (BookmarkPresent(lineno))
wEditor.Call(SCI_MARKERDELETE, lineno, markerBookmark);
}
bool SciTEBase::BookmarkPresent(int lineno) {
if (lineno == -1)
lineno = GetCurrentLineNumber();
int state = wEditor.Call(SCI_MARKERGET, lineno);
return state & (1 << markerBookmark);
}
void SciTEBase::BookmarkToggle(int lineno) {
if (lineno == -1)
lineno = GetCurrentLineNumber();
if (BookmarkPresent(lineno)) {
BookmarkDelete(lineno);
} else {
BookmarkAdd(lineno);
}
}
void SciTEBase::BookmarkNext(bool forwardScan, bool select) {
int lineno = GetCurrentLineNumber();
int sci_marker = SCI_MARKERNEXT;
int lineStart = lineno + 1; //Scan starting from next line
int lineRetry = 0; //If not found, try from the beginning
int anchor = wEditor.Call(SCI_GETANCHOR);
if (!forwardScan) {
lineStart = lineno - 1; //Scan starting from previous line
lineRetry = wEditor.Call(SCI_GETLINECOUNT, 0, 0L); //If not found, try from the end
sci_marker = SCI_MARKERPREVIOUS;
}
int nextLine = wEditor.Call(sci_marker, lineStart, 1 << markerBookmark);
if (nextLine < 0)
nextLine = wEditor.Call(sci_marker, lineRetry, 1 << markerBookmark);
if (nextLine < 0 || nextLine == lineno) // No bookmark (of the given type) or only one, and already on it
WarnUser(warnNoOtherBookmark);
else {
GotoLineEnsureVisible(nextLine);
if (select) {
wEditor.Call(SCI_SETANCHOR, anchor);
}
}
}
GUI::Rectangle SciTEBase::GetClientRectangle() {
return wContent.GetClientPosition();
}
void SciTEBase::Redraw() {
wSciTE.InvalidateAll();
wEditor.InvalidateAll();
wOutput.InvalidateAll();
}
char *SciTEBase::GetNearestWords(const char *wordStart, size_t searchLen,
const char *separators, bool ignoreCase /*=false*/, bool exactLen /*=false*/) {
char *words = 0;
while (!words && *separators) {
words = apis.GetNearestWords(wordStart, searchLen, ignoreCase, *separators, exactLen);
separators++;
}
return words;
}
void SciTEBase::FillFunctionDefinition(int pos /*= -1*/) {
if (pos > 0) {
lastPosCallTip = pos;
}
if (apis) {
char *words = GetNearestWords(currentCallTipWord.c_str(), currentCallTipWord.length(),
calltipParametersStart.c_str(), callTipIgnoreCase, true);
if (!words)
return;
// Counts how many call tips
const char *spacePos = strchr(words, ' ');
maxCallTips = 1;
while (spacePos) {
maxCallTips++;
spacePos = strchr(spacePos + 1, ' ');
}
delete []words;
// Should get current api definition
const char *word = apis.GetNearestWord(currentCallTipWord.c_str(), currentCallTipWord.length(),
callTipIgnoreCase, calltipWordCharacters, currentCallTip);
if (word) {
functionDefinition = word;
if (maxCallTips > 1) {
functionDefinition.insert(0, "\001");
}
if (calltipEndDefinition != "") {
int posEndDef = functionDefinition.search(calltipEndDefinition.c_str());
if (maxCallTips > 1) {
if ((posEndDef > 1) &&
((posEndDef + calltipEndDefinition.length()) < functionDefinition.length())) {
functionDefinition.insert(posEndDef + calltipEndDefinition.length(), "\n\002");
} else {
functionDefinition.append("\n\002");
}
} else {
if ((posEndDef > 1) &&
((posEndDef + calltipEndDefinition.length()) < functionDefinition.length())) {
functionDefinition.insert(posEndDef + calltipEndDefinition.length(), "\n");
}
}
} else if (maxCallTips > 1) {
functionDefinition.insert(1, "\002");
}
SString definitionForDisplay;
if (callTipUseEscapes) {
char *sUnslashed = StringDup(functionDefinition.c_str());
UnSlash(sUnslashed);
definitionForDisplay = sUnslashed;
delete []sUnslashed;
} else {
definitionForDisplay = functionDefinition;
}
wEditor.CallString(SCI_CALLTIPSHOW, lastPosCallTip - currentCallTipWord.length(), definitionForDisplay.c_str());
ContinueCallTip();
}
}
}
bool SciTEBase::StartCallTip() {
currentCallTip = 0;
currentCallTipWord = "";
SString line = GetLine();
int current = GetCaretInLine();
int pos = wEditor.Call(SCI_GETCURRENTPOS);
do {
int braces = 0;
while (current > 0 && (braces || !calltipParametersStart.contains(line[current - 1]))) {
if (calltipParametersStart.contains(line[current - 1]))
braces--;
else if (calltipParametersEnd.contains(line[current - 1]))
braces++;
current--;
pos--;
}
if (current > 0) {
current--;
pos--;
} else
break;
while (current > 0 && isspacechar(line[current - 1])) {
current--;
pos--;
}
} while (current > 0 && !calltipWordCharacters.contains(line[current - 1]));
if (current <= 0)
return true;
startCalltipWord = current - 1;
while (startCalltipWord > 0 &&
calltipWordCharacters.contains(line[startCalltipWord - 1])) {
startCalltipWord--;
}
line.change(current, '\0');
currentCallTipWord = line.c_str() + startCalltipWord;
functionDefinition = "";
FillFunctionDefinition(pos);
return true;
}
void SciTEBase::ContinueCallTip() {
SString line = GetLine();
int current = GetCaretInLine();
int braces = 0;
int commas = 0;
for (int i = startCalltipWord; i < current; i++) {
if (calltipParametersStart.contains(line[i]))
braces++;
else if (calltipParametersEnd.contains(line[i]) && braces > 0)
braces--;
else if (braces == 1 && calltipParametersSeparators.contains(line[i]))
commas++;
}
int startHighlight = 0;
while (functionDefinition[startHighlight] && !calltipParametersStart.contains(functionDefinition[startHighlight]))
startHighlight++;
if (functionDefinition[startHighlight] && calltipParametersStart.contains(functionDefinition[startHighlight]))
startHighlight++;
while (functionDefinition[startHighlight] && commas > 0) {
if (calltipParametersSeparators.contains(functionDefinition[startHighlight]))
commas--;
// If it reached the end of the argument list it means that the user typed in more
// arguments than the ones listed in the calltip
if (calltipParametersEnd.contains(functionDefinition[startHighlight]))
commas = 0;
else
startHighlight++;
}
if (functionDefinition[startHighlight] && calltipParametersSeparators.contains(functionDefinition[startHighlight]))
startHighlight++;
int endHighlight = startHighlight;
while (functionDefinition[endHighlight] && !calltipParametersSeparators.contains(functionDefinition[endHighlight]) && !calltipParametersEnd.contains(functionDefinition[endHighlight]))
endHighlight++;
if (callTipUseEscapes) {
char *sUnslashed = StringDup(functionDefinition.substr(0, startHighlight + 1).c_str());
int unslashedStartHighlight = UnSlash(sUnslashed) - 1;
delete []sUnslashed;
int unslashedEndHighlight = unslashedStartHighlight;
if (startHighlight < endHighlight) {
sUnslashed = StringDup(functionDefinition.substr(startHighlight, endHighlight - startHighlight + 1).c_str());
unslashedEndHighlight = unslashedStartHighlight + UnSlash(sUnslashed) - 1;
delete []sUnslashed;
}
startHighlight = unslashedStartHighlight;
endHighlight = unslashedEndHighlight;
}
wEditor.Call(SCI_CALLTIPSETHLT, startHighlight, endHighlight);
}
void SciTEBase::EliminateDuplicateWords(char *words) {
std::set<std::string> wordSet;
std::vector<char> wordsOut(strlen(words) + 1);
char *wordsWrite = &wordsOut[0];
char *wordCurrent = words;
while (*wordCurrent) {
char *afterWord = strchr(wordCurrent, ' ');
if (!afterWord)
afterWord = wordCurrent + strlen(wordCurrent);
std::string word(wordCurrent, afterWord);
if (wordSet.count(word) == 0) {
wordSet.insert(word);
if (wordsWrite != &wordsOut[0])
*wordsWrite++ = ' ';
strcpy(wordsWrite, word.c_str());
wordsWrite += word.length();
}
wordCurrent = afterWord;
if (*wordCurrent)
wordCurrent++;
}
*wordsWrite = '\0';
strcpy(words, &wordsOut[0]);
}
bool SciTEBase::StartAutoComplete() {
SString line = GetLine();
int current = GetCaretInLine();
int startword = current;
while ((startword > 0) &&
(calltipWordCharacters.contains(line[startword - 1]) ||
autoCompleteStartCharacters.contains(line[startword - 1]))) {
startword--;
}
SString root = line.substr(startword, current - startword);
if (apis) {
char *words = GetNearestWords(root.c_str(), root.length(),
calltipParametersStart.c_str(), autoCompleteIgnoreCase);
if (words) {
EliminateDuplicateWords(words);
wEditor.Call(SCI_AUTOCSETSEPARATOR, ' ');
wEditor.CallString(SCI_AUTOCSHOW, root.length(), words);
delete []words;
}
}
return true;
}
bool SciTEBase::StartAutoCompleteWord(bool onlyOneWord) {
SString line = GetLine();
int current = GetCaretInLine();
int startword = current;
// Autocompletion of pure numbers is mostly an annoyance
bool allNumber = true;
while (startword > 0 && wordCharacters.contains(line[startword - 1])) {
startword--;
if (line[startword] < '0' || line[startword] > '9') {
allNumber = false;
}
}
if (startword == current || allNumber)
return true;
SString root = line.substr(startword, current - startword);
int doclen = LengthDocument();
Sci_TextToFind ft = {{0, 0}, 0, {0, 0}};
ft.lpstrText = const_cast<char *>(root.c_str());
ft.chrg.cpMin = 0;
ft.chrg.cpMax = doclen;
ft.chrgText.cpMin = 0;
ft.chrgText.cpMax = 0;
const int flags = SCFIND_WORDSTART | (autoCompleteIgnoreCase ? 0 : SCFIND_MATCHCASE);
int posCurrentWord = wEditor.Call(SCI_GETCURRENTPOS) - static_cast<int>(root.length());
unsigned int minWordLength = 0;
unsigned int nwords = 0;
// wordsNear contains a list of words separated by single spaces and with a space
// at the start and end. This makes it easy to search for words.
SString wordsNear;
wordsNear.setsizegrowth(1000);
wordsNear.append("\n");
int posFind = wEditor.CallString(SCI_FINDTEXT, flags, reinterpret_cast<char *>(&ft));
TextReader acc(wEditor);
while (posFind >= 0 && posFind < doclen) { // search all the document
int wordEnd = posFind + static_cast<int>(root.length());
if (posFind != posCurrentWord) {
while (wordCharacters.contains(acc.SafeGetCharAt(wordEnd)))
wordEnd++;
unsigned int wordLength = wordEnd - posFind;
if (wordLength > root.length()) {
SString word = GetRange(wEditor, posFind, wordEnd);
word.insert(0, "\n");
word.append("\n");
if (!wordsNear.contains(word.c_str())) { // add a new entry
wordsNear += word.c_str() + 1;
if (minWordLength < wordLength)
minWordLength = wordLength;
nwords++;
if (onlyOneWord && nwords > 1) {
return true;
}
}
}
}
ft.chrg.cpMin = wordEnd;
posFind = wEditor.CallString(SCI_FINDTEXT, flags, reinterpret_cast<char *>(&ft));
}
size_t length = wordsNear.length();
if ((length > 2) && (!onlyOneWord || (minWordLength > root.length()))) {
// Protect spaces by temporrily transforming to \001
wordsNear.substitute(' ', '\001');
StringList wl(true);
wl.Set(wordsNear.c_str());
char *words = wl.GetNearestWords("", 0, autoCompleteIgnoreCase);
SString acText(words);
// Use \n as word separator
acText.substitute(' ', '\n');
// Return spaces from \001
acText.substitute('\001', ' ');
wEditor.Call(SCI_AUTOCSETSEPARATOR, '\n');
wEditor.CallString(SCI_AUTOCSHOW, root.length(), acText.c_str());
delete []words;
} else {
wEditor.Call(SCI_AUTOCCANCEL);
}
return true;
}
bool SciTEBase::PerformInsertAbbreviation() {
SString data = propsAbbrev.Get(abbrevInsert.c_str());
size_t dataLength = data.length();
if (dataLength == 0) {
return true; // returning if expanded abbreviation is empty
}
char *expbuf = new char[dataLength + 1];
strcpy(expbuf, data.c_str());
UnSlash(expbuf);
size_t expbuflen = strlen(expbuf);
int caret_pos = wEditor.Call(SCI_GETSELECTIONSTART);
int sel_start = caret_pos;
int sel_length = wEditor.Call(SCI_GETSELECTIONEND) - sel_start;
bool at_start = true;
bool double_pipe = false;
size_t last_pipe = expbuflen;
int currentLineNumber = wEditor.Call(SCI_LINEFROMPOSITION, caret_pos);
int indent = 0;
int indentSize = wEditor.Call(SCI_GETINDENT);
int indentChars = (wEditor.Call(SCI_GETUSETABS) && wEditor.Call(SCI_GETTABWIDTH) ? wEditor.Call(SCI_GETTABWIDTH) : 1);
int indentExtra = 0;
bool isIndent = true;
int eolMode = wEditor.Call(SCI_GETEOLMODE);
if (props.GetInt("indent.automatic")) {
indent = GetLineIndentation(currentLineNumber);
}
size_t i;
// find last |, can't be strrchr(exbuf, '|') because of ||
for (i = expbuflen; i--; ) {
if (expbuf[i] == '|' && (i == 0 || expbuf[i-1] != '|')) {
last_pipe = i;
break;
}
}
wEditor.Call(SCI_BEGINUNDOACTION);
// add the abbreviation one character at a time
for (i = 0; i < expbuflen; i++) {
char c = expbuf[i];
SString abbrevText("");
if (isIndent && c == '\t') {
if (props.GetInt("indent.automatic")) {
indentExtra++;
SetLineIndentation(currentLineNumber, indent + indentSize * indentExtra);
caret_pos += indentSize / indentChars;
}
} else {
switch (c) {
case '|':
// user may want to insert '|' instead of caret
if (i < (dataLength - 1) && expbuf[i + 1] == '|') {
// put '|' into the line
abbrevText += c;
i++;
} else if (i != last_pipe) {
double_pipe = true;
} else {
// indent on multiple lines
int j = currentLineNumber + 1; // first line indented as others
currentLineNumber = wEditor.Call(SCI_LINEFROMPOSITION, caret_pos + sel_length);
for (; j <= currentLineNumber; j++) {
SetLineIndentation(j, GetLineIndentation(j) + indentSize * indentExtra);
caret_pos += indentExtra * indentSize / indentChars;
}
at_start = false;
caret_pos += sel_length;
}
break;
case '\r':
// backward compatibility
break;
case '\n':
if (eolMode == SC_EOL_CRLF || eolMode == SC_EOL_CR) {
abbrevText += '\r';
}
if (eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) {
abbrevText += '\n';
}
break;
default:
abbrevText += c;
break;
}
if (caret_pos > wEditor.Call(SCI_GETLENGTH)) {
caret_pos = wEditor.Call(SCI_GETLENGTH);
}
wEditor.CallString(SCI_INSERTTEXT, caret_pos, abbrevText.c_str());
if (!double_pipe && at_start) {
sel_start += static_cast<int>(abbrevText.length());
}
caret_pos += static_cast<int>(abbrevText.length());
if (c == '\n') {
isIndent = true;
indentExtra = 0;
currentLineNumber++;
SetLineIndentation(currentLineNumber, indent);
caret_pos += indent / indentChars;
if (!double_pipe && at_start) {
sel_start += indent / indentChars;
}
} else {
isIndent = false;
}
}
}
// set the caret to the desired position
if (double_pipe) {
sel_length = 0;
}
wEditor.Call(SCI_SETSEL, sel_start, sel_start + sel_length);
wEditor.Call(SCI_ENDUNDOACTION);
delete []expbuf;
return true;
}
bool SciTEBase::StartInsertAbbreviation() {
if (!AbbrevDialog()) {
return true;
}
return PerformInsertAbbreviation();
}
bool SciTEBase::StartExpandAbbreviation() {
int currentPos = GetCaretInLine();
int position = wEditor.Call(SCI_GETCURRENTPOS); // from the beginning
char *linebuf = new char[currentPos + 2];
GetLine(linebuf, currentPos + 2); // Just get text to the left of the caret
linebuf[currentPos] = '\0';
int abbrevPos = (currentPos > 32 ? currentPos - 32 : 0);
const char *abbrev = linebuf + abbrevPos;
SString data;
size_t dataLength = 0;
int abbrevLength = currentPos - abbrevPos;
// Try each potential abbreviation from the first letter on a line
// and expanding to the right.
// We arbitrarily limit the length of an abbreviation (seems a reasonable value..),
// and of course stop on the caret.
while (abbrevLength > 0) {
data = propsAbbrev.Get(abbrev);
dataLength = data.length();
if (dataLength > 0) {
break; /* Found */
}
abbrev++; // One more letter to the right
abbrevLength--;
}
if (dataLength == 0) {
delete []linebuf;
WarnUser(warnNotFound); // No need for a special warning
return true; // returning if expanded abbreviation is empty
}
char *expbuf = new char[dataLength + 1];
strcpy(expbuf, data.c_str());
UnSlash(expbuf);
size_t expbuflen = strlen(expbuf);
int caret_pos = -1; // caret position
int currentLineNumber = GetCurrentLineNumber();
int indent = 0;
int indentExtra = 0;
bool isIndent = true;
int eolMode = wEditor.Call(SCI_GETEOLMODE);
if (props.GetInt("indent.automatic")) {
indent = GetLineIndentation(currentLineNumber);
}
wEditor.Call(SCI_BEGINUNDOACTION);
wEditor.Call(SCI_SETSEL, position - abbrevLength, position);
// add the abbreviation one character at a time
for (size_t i = 0; i < expbuflen; i++) {
char c = expbuf[i];
SString abbrevText("");
if (isIndent && c == '\t') {
indentExtra++;
SetLineIndentation(currentLineNumber, indent + wEditor.Call(SCI_GETINDENT) * indentExtra);
} else {
switch (c) {
case '|':
// user may want to insert '|' instead of caret
if (i < (dataLength - 1) && expbuf[i + 1] == '|') {
// put '|' into the line
abbrevText += c;
i++;
} else if (caret_pos == -1) {
if (i == 0) {
// when caret is set at the first place in abbreviation
caret_pos = wEditor.Call(SCI_GETCURRENTPOS) - abbrevLength;
} else {
caret_pos = wEditor.Call(SCI_GETCURRENTPOS);
}
}
break;
case '\n':
if (eolMode == SC_EOL_CRLF || eolMode == SC_EOL_CR) {
abbrevText += '\r';
}
if (eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) {
abbrevText += '\n';
}
break;
default:
abbrevText += c;
break;
}
wEditor.CallString(SCI_REPLACESEL, 0, abbrevText.c_str());
if (c == '\n') {
isIndent = true;
indentExtra = 0;
currentLineNumber++;
SetLineIndentation(currentLineNumber, indent);
} else {
isIndent = false;
}
}
}
// set the caret to the desired position
if (caret_pos != -1) {
wEditor.Call(SCI_GOTOPOS, caret_pos);
}
wEditor.Call(SCI_ENDUNDOACTION);
delete []expbuf;
delete []linebuf;
return true;
}
bool SciTEBase::StartBlockComment() {
SString fileNameForExtension = ExtensionFileName();
SString lexerName = props.GetNewExpand("lexer.", fileNameForExtension.c_str());
SString base("comment.block.");
SString comment_at_line_start("comment.block.at.line.start.");
base += lexerName;
comment_at_line_start += lexerName;
bool placeCommentsAtLineStart = props.GetInt(comment_at_line_start.c_str()) != 0;
SString comment = props.Get(base.c_str());
if (comment == "") { // user friendly error message box
GUI::gui_string sBase = GUI::StringFromUTF8(base.c_str());
GUI::gui_string error = LocaliseMessage(
"Block comment variable '^0' is not defined in SciTE *.properties!", sBase.c_str());
WindowMessageBox(wSciTE, error, MB_OK | MB_ICONWARNING);
return true;
}
SString long_comment = comment;
long_comment.append(" ");
int selectionStart = wEditor.Call(SCI_GETSELECTIONSTART);
int selectionEnd = wEditor.Call(SCI_GETSELECTIONEND);
int caretPosition = wEditor.Call(SCI_GETCURRENTPOS);
// checking if caret is located in _beginning_ of selected block
bool move_caret = caretPosition < selectionEnd;
int selStartLine = wEditor.Call(SCI_LINEFROMPOSITION, selectionStart);
int selEndLine = wEditor.Call(SCI_LINEFROMPOSITION, selectionEnd);
int lines = selEndLine - selStartLine;
int firstSelLineStart = wEditor.Call(SCI_POSITIONFROMLINE, selStartLine);
// "caret return" is part of the last selected line
if ((lines > 0) &&
(selectionEnd == wEditor.Call(SCI_POSITIONFROMLINE, selEndLine)))
selEndLine--;
wEditor.Call(SCI_BEGINUNDOACTION);
for (int i = selStartLine; i <= selEndLine; i++) {
int lineStart = wEditor.Call(SCI_POSITIONFROMLINE, i);
int lineIndent = lineStart;
int lineEnd = wEditor.Call(SCI_GETLINEENDPOSITION, i);
if (!placeCommentsAtLineStart) {
lineIndent = GetLineIndentPosition(i);
}
SString linebuf = GetRange(wEditor, lineIndent, lineEnd);
// empty lines are not commented
if (linebuf.length() < 1)
continue;
if (linebuf.startswith(comment.c_str())) {
int commentLength = static_cast<int>(comment.length());
if (linebuf.startswith(long_comment.c_str())) {
// Removing comment with space after it.
commentLength = static_cast<int>(long_comment.length());
}
wEditor.Call(SCI_SETSEL, lineIndent, lineIndent + commentLength);
wEditor.CallString(SCI_REPLACESEL, 0, "");
if (i == selStartLine) // is this the first selected line?
selectionStart -= commentLength;
selectionEnd -= commentLength; // every iteration
continue;
}
if (i == selStartLine) // is this the first selected line?
selectionStart += static_cast<int>(long_comment.length());
selectionEnd += static_cast<int>(long_comment.length()); // every iteration
wEditor.CallString(SCI_INSERTTEXT, lineIndent, long_comment.c_str());
}
// after uncommenting selection may promote itself to the lines
// before the first initially selected line;
// another problem - if only comment symbol was selected;
if (selectionStart < firstSelLineStart) {
if (selectionStart >= selectionEnd - (static_cast<int>(long_comment.length()) - 1))
selectionEnd = firstSelLineStart;
selectionStart = firstSelLineStart;
}
if (move_caret) {
// moving caret to the beginning of selected block
wEditor.Call(SCI_GOTOPOS, selectionEnd);
wEditor.Call(SCI_SETCURRENTPOS, selectionStart);
} else {
wEditor.Call(SCI_SETSEL, selectionStart, selectionEnd);
}
wEditor.Call(SCI_ENDUNDOACTION);
return true;
}
static const char *LineEndString(int eolMode) {
switch (eolMode) {
case SC_EOL_CRLF:
return "\r\n";
case SC_EOL_CR:
return "\r";
case SC_EOL_LF:
default:
return "\n";
}
}
bool SciTEBase::StartBoxComment() {
// Get start/middle/end comment strings from options file(s)
SString fileNameForExtension = ExtensionFileName();
SString lexerName = props.GetNewExpand("lexer.", fileNameForExtension.c_str());
SString start_base("comment.box.start.");
SString middle_base("comment.box.middle.");
SString end_base("comment.box.end.");
SString white_space(" ");
SString eol(LineEndString(wEditor.Call(SCI_GETEOLMODE)));
start_base += lexerName;
middle_base += lexerName;
end_base += lexerName;
SString start_comment = props.Get(start_base.c_str());
SString middle_comment = props.Get(middle_base.c_str());
SString end_comment = props.Get(end_base.c_str());
if (start_comment == "" || middle_comment == "" || end_comment == "") {
GUI::gui_string sStart = GUI::StringFromUTF8(start_base.c_str());
GUI::gui_string sMiddle = GUI::StringFromUTF8(middle_base.c_str());
GUI::gui_string sEnd = GUI::StringFromUTF8(end_base.c_str());
GUI::gui_string error = LocaliseMessage(
"Box comment variables '^0', '^1' and '^2' are not defined in SciTE *.properties!",
sStart.c_str(), sMiddle.c_str(), sEnd.c_str());
WindowMessageBox(wSciTE, error, MB_OK | MB_ICONWARNING);
return true;
}
// Note selection and cursor location so that we can reselect text and reposition cursor after we insert comment strings
size_t selectionStart = wEditor.Call(SCI_GETSELECTIONSTART);
size_t selectionEnd = wEditor.Call(SCI_GETSELECTIONEND);
size_t caretPosition = wEditor.Call(SCI_GETCURRENTPOS);
bool move_caret = caretPosition < selectionEnd;
size_t selStartLine = wEditor.Call(SCI_LINEFROMPOSITION, selectionStart);
size_t selEndLine = wEditor.Call(SCI_LINEFROMPOSITION, selectionEnd);
size_t lines = selEndLine - selStartLine + 1;
// If selection ends at start of last selected line, fake it so that selection goes to end of second-last selected line
if (lines > 1 && selectionEnd == static_cast<size_t>(wEditor.Call(SCI_POSITIONFROMLINE, selEndLine))) {
selEndLine--;
lines--;
selectionEnd = wEditor.Call(SCI_GETLINEENDPOSITION, selEndLine);
}
// Pad comment strings with appropriate whitespace, then figure out their lengths (end_comment is a bit special-- see below)
start_comment += white_space;
middle_comment += white_space;
int start_comment_length = static_cast<int>(start_comment.length());
int middle_comment_length = static_cast<int>(middle_comment.length());
int end_comment_length = static_cast<int>(end_comment.length());
int whitespace_length = static_cast<int>(white_space.length());
// Calculate the length of the longest comment string to be inserted, and allocate a null-terminated char buffer of equal size
int maxCommentLength = start_comment_length;
if (middle_comment_length > maxCommentLength)
maxCommentLength = middle_comment_length;
if (end_comment_length + whitespace_length > maxCommentLength)
maxCommentLength = end_comment_length + whitespace_length;
char *tempString = new char[maxCommentLength + 1];
wEditor.Call(SCI_BEGINUNDOACTION);
// Insert start_comment if needed
int lineStart = wEditor.Call(SCI_POSITIONFROMLINE, selStartLine);
GetRange(wEditor, lineStart, lineStart + start_comment_length, tempString);
tempString[start_comment_length] = '\0';
if (start_comment != tempString) {
wEditor.CallString(SCI_INSERTTEXT, lineStart, start_comment.c_str());
selectionStart += start_comment_length;
selectionEnd += start_comment_length;
}
if (lines <= 1) {
// Only a single line was selected, so just append whitespace + end-comment at end of line if needed
int lineEnd = wEditor.Call(SCI_GETLINEENDPOSITION, selEndLine);
GetRange(wEditor, lineEnd - end_comment_length, lineEnd, tempString);
tempString[end_comment_length] = '\0';
if (end_comment != tempString) {
end_comment.insert(0, white_space.c_str());
wEditor.CallString(SCI_INSERTTEXT, lineEnd, end_comment.c_str());
}
} else {
// More than one line selected, so insert middle_comments where needed
for (size_t i = selStartLine + 1; i < selEndLine; i++) {
lineStart = wEditor.Call(SCI_POSITIONFROMLINE, i);
GetRange(wEditor, lineStart, lineStart + middle_comment_length, tempString);
tempString[middle_comment_length] = '\0';
if (middle_comment != tempString) {
wEditor.CallString(SCI_INSERTTEXT, lineStart, middle_comment.c_str());
selectionEnd += middle_comment_length;
}
}
// If last selected line is not middle-comment or end-comment, we need to insert
// a middle-comment at the start of last selected line and possibly still insert
// and end-comment tag after the last line (extra logic is necessary to
// deal with the case that user selected the end-comment tag)
lineStart = wEditor.Call(SCI_POSITIONFROMLINE, selEndLine);
GetRange(wEditor, lineStart, lineStart + end_comment_length, tempString);
tempString[end_comment_length] = '\0';
if (end_comment != tempString) {
GetRange(wEditor, lineStart, lineStart + middle_comment_length, tempString);
tempString[middle_comment_length] = '\0';
if (middle_comment != tempString) {
wEditor.CallString(SCI_INSERTTEXT, lineStart, middle_comment.c_str());
selectionEnd += middle_comment_length;
}
// And since we didn't find the end-comment string yet, we need to check the *next* line
// to see if it's necessary to insert an end-comment string and a linefeed there....
lineStart = wEditor.Call(SCI_POSITIONFROMLINE, selEndLine + 1);
GetRange(wEditor, lineStart, lineStart + (int) end_comment_length, tempString);
tempString[end_comment_length] = '\0';
if (end_comment != tempString) {
end_comment += eol;
wEditor.CallString(SCI_INSERTTEXT, lineStart, end_comment.c_str());
}
}
}
if (move_caret) {
// moving caret to the beginning of selected block
wEditor.Call(SCI_GOTOPOS, selectionEnd);
wEditor.Call(SCI_SETCURRENTPOS, selectionStart);
} else {
wEditor.Call(SCI_SETSEL, selectionStart, selectionEnd);
}
wEditor.Call(SCI_ENDUNDOACTION);
delete[] tempString;
return true;
}
bool SciTEBase::StartStreamComment() {
SString fileNameForExtension = ExtensionFileName();
SString lexerName = props.GetNewExpand("lexer.", fileNameForExtension.c_str());
SString start_base("comment.stream.start.");
SString end_base("comment.stream.end.");
SString white_space(" ");
start_base += lexerName;
end_base += lexerName;
SString start_comment = props.Get(start_base.c_str());
SString end_comment = props.Get(end_base.c_str());
if (start_comment == "" || end_comment == "") {
GUI::gui_string sStart = GUI::StringFromUTF8(start_base.c_str());
GUI::gui_string sEnd = GUI::StringFromUTF8(end_base.c_str());
GUI::gui_string error = LocaliseMessage(
"Stream comment variables '^0' and '^1' are not defined in SciTE *.properties!",
sStart.c_str(), sEnd.c_str());
WindowMessageBox(wSciTE, error, MB_OK | MB_ICONWARNING);
return true;
}
start_comment += white_space;
white_space += end_comment;
end_comment = white_space;
size_t start_comment_length = start_comment.length();
size_t selectionStart = wEditor.Call(SCI_GETSELECTIONSTART);
size_t selectionEnd = wEditor.Call(SCI_GETSELECTIONEND);
size_t caretPosition = wEditor.Call(SCI_GETCURRENTPOS);
// checking if caret is located in _beginning_ of selected block
bool move_caret = caretPosition < selectionEnd;
// if there is no selection?
if (selectionEnd - selectionStart <= 0) {
int selLine = wEditor.Call(SCI_LINEFROMPOSITION, selectionStart);
int lineIndent = GetLineIndentPosition(selLine);
int lineEnd = wEditor.Call(SCI_GETLINEENDPOSITION, selLine);
if (RangeIsAllWhitespace(lineIndent, lineEnd))
return true; // we are not dealing with empty lines
char linebuf[1000];
GetLine(linebuf, sizeof(linebuf));
int current = GetCaretInLine();
// checking if we are not inside a word
if (!wordCharacters.contains(linebuf[current]))
return true; // caret is located _between_ words
int startword = current;
int endword = current;
int start_counter = 0;
int end_counter = 0;
while (startword > 0 && wordCharacters.contains(linebuf[startword - 1])) {
start_counter++;
startword--;
}
// checking _beginning_ of the word
if (startword == current)
return true; // caret is located _before_ a word
while (linebuf[endword + 1] != '\0' && wordCharacters.contains(linebuf[endword + 1])) {
end_counter++;
endword++;
}
selectionStart -= start_counter;
selectionEnd += (end_counter + 1);
}
wEditor.Call(SCI_BEGINUNDOACTION);
wEditor.CallString(SCI_INSERTTEXT, selectionStart, start_comment.c_str());
selectionEnd += start_comment_length;
selectionStart += start_comment_length;
wEditor.CallString(SCI_INSERTTEXT, selectionEnd, end_comment.c_str());
if (move_caret) {
// moving caret to the beginning of selected block
wEditor.Call(SCI_GOTOPOS, selectionEnd);
wEditor.Call(SCI_SETCURRENTPOS, selectionStart);
} else {
wEditor.Call(SCI_SETSEL, selectionStart, selectionEnd);
}
wEditor.Call(SCI_ENDUNDOACTION);
return true;
}
/**
* Return the length of the given line, not counting the EOL.
*/
int SciTEBase::GetLineLength(int line) {
return wEditor.Call(SCI_GETLINEENDPOSITION, line) - wEditor.Call(SCI_POSITIONFROMLINE, line);
}
int SciTEBase::GetCurrentLineNumber() {
return wEditor.Call(SCI_LINEFROMPOSITION,
wEditor.Call(SCI_GETCURRENTPOS));
}
int SciTEBase::GetCurrentScrollPosition() {
int lineDisplayTop = wEditor.Call(SCI_GETFIRSTVISIBLELINE);
return wEditor.Call(SCI_DOCLINEFROMVISIBLE, lineDisplayTop);
}
/**
* Set up properties for ReadOnly, EOLMode, BufferLength, NbOfLines, SelLength, SelHeight.
*/
void SciTEBase::SetTextProperties(
PropSetFile &ps) { ///< Property set to update.
const int TEMP_LEN = 100;
char temp[TEMP_LEN];
std::string ro = GUI::UTF8FromString(localiser.Text("READ"));
ps.Set("ReadOnly", isReadOnly ? ro.c_str() : "");
int eolMode = wEditor.Call(SCI_GETEOLMODE);
ps.Set("EOLMode", eolMode == SC_EOL_CRLF ? "CR+LF" : (eolMode == SC_EOL_LF ? "LF" : "CR"));
sprintf(temp, "%d", LengthDocument());
ps.Set("BufferLength", temp);
ps.SetInteger("NbOfLines", wEditor.Call(SCI_GETLINECOUNT));
Sci_CharacterRange crange = GetSelection();
int selFirstLine = wEditor.Call(SCI_LINEFROMPOSITION, crange.cpMin);
int selLastLine = wEditor.Call(SCI_LINEFROMPOSITION, crange.cpMax);
long charCount = 0;
if (wEditor.Call(SCI_GETSELECTIONMODE) == SC_SEL_RECTANGLE) {
for (int line = selFirstLine; line <= selLastLine; line++) {
int startPos = wEditor.Call(SCI_GETLINESELSTARTPOSITION, line);
int endPos = wEditor.Call(SCI_GETLINESELENDPOSITION, line);
charCount += wEditor.Call(SCI_COUNTCHARACTERS, startPos, endPos);
}
} else {
charCount = wEditor.Call(SCI_COUNTCHARACTERS, crange.cpMin, crange.cpMax);
}
sprintf(temp, "%ld", charCount);
ps.Set("SelLength", temp);
int caretPos = wEditor.Call(SCI_GETCURRENTPOS);
int selAnchor = wEditor.Call(SCI_GETANCHOR);
if (0 == (crange.cpMax - crange.cpMin)) {
sprintf(temp, "%d", 0);
} else if (selLastLine == selFirstLine) {
sprintf(temp, "%d", 1);
} else if ((wEditor.Call(SCI_GETCOLUMN, caretPos) == 0 && (selAnchor <= caretPos)) ||
((wEditor.Call(SCI_GETCOLUMN, selAnchor) == 0) && (selAnchor > caretPos ))) {
sprintf(temp, "%d", selLastLine - selFirstLine);
} else {
sprintf(temp, "%d", selLastLine - selFirstLine + 1);
}
ps.Set("SelHeight", temp);
}
void SciTEBase::UpdateStatusBar(bool bUpdateSlowData) {
if (sbVisible) {
if (bUpdateSlowData) {
SetFileProperties(propsStatus);
}
SetTextProperties(propsStatus);
int caretPos = wEditor.Call(SCI_GETCURRENTPOS);
propsStatus.SetInteger("LineNumber",
wEditor.Call(SCI_LINEFROMPOSITION, caretPos) + 1);
propsStatus.SetInteger("ColumnNumber",
wEditor.Call(SCI_GETCOLUMN, caretPos) + 1);
propsStatus.Set("OverType", wEditor.Call(SCI_GETOVERTYPE) ? "OVR" : "INS");
char sbKey[32];
sprintf(sbKey, "statusbar.text.%d", sbNum);
SString msg = propsStatus.GetExpanded(sbKey);
if (msg.size() && sbValue != msg) { // To avoid flickering, update only if needed
SetStatusBarText(msg.c_str());
sbValue = msg;
}
} else {
sbValue = "";
}
}
void SciTEBase::SetLineIndentation(int line, int indent) {
if (indent < 0)
return;
Sci_CharacterRange crange = GetSelection();
int posBefore = GetLineIndentPosition(line);
wEditor.Call(SCI_SETLINEINDENTATION, line, indent);
int posAfter = GetLineIndentPosition(line);
int posDifference = posAfter - posBefore;
if (posAfter > posBefore) {
// Move selection on
if (crange.cpMin >= posBefore) {
crange.cpMin += posDifference;
}
if (crange.cpMax >= posBefore) {
crange.cpMax += posDifference;
}
} else if (posAfter < posBefore) {
// Move selection back
if (crange.cpMin >= posAfter) {
if (crange.cpMin >= posBefore)
crange.cpMin += posDifference;
else
crange.cpMin = posAfter;
}
if (crange.cpMax >= posAfter) {
if (crange.cpMax >= posBefore)
crange.cpMax += posDifference;
else
crange.cpMax = posAfter;
}
}
SetSelection(static_cast<int>(crange.cpMin), static_cast<int>(crange.cpMax));
}
int SciTEBase::GetLineIndentation(int line) {
return wEditor.Call(SCI_GETLINEINDENTATION, line);
}
int SciTEBase::GetLineIndentPosition(int line) {
return wEditor.Call(SCI_GETLINEINDENTPOSITION, line);
}
static SString CreateIndentation(int indent, int tabSize, bool insertSpaces) {
SString indentation;
if (!insertSpaces) {
while (indent >= tabSize) {
indentation.append("\t", 1);
indent -= tabSize;
}
}
while (indent > 0) {
indentation.append(" ", 1);
indent--;
}
return indentation;
}
void SciTEBase::ConvertIndentation(int tabSize, int useTabs) {
wEditor.Call(SCI_BEGINUNDOACTION);
int maxLine = wEditor.Call(SCI_GETLINECOUNT);
for (int line = 0; line < maxLine; line++) {
int lineStart = wEditor.Call(SCI_POSITIONFROMLINE, line);
int indent = GetLineIndentation(line);
int indentPos = GetLineIndentPosition(line);
const int maxIndentation = 1000;
if (indent < maxIndentation) {
SString indentationNow = GetRange(wEditor, lineStart, indentPos);
SString indentationWanted = CreateIndentation(indent, tabSize, !useTabs);
if (indentationNow != indentationWanted) {
wEditor.Call(SCI_SETTARGETSTART, lineStart);
wEditor.Call(SCI_SETTARGETEND, indentPos);
wEditor.CallString(SCI_REPLACETARGET, indentationWanted.length(),
indentationWanted.c_str());
}
}
}
wEditor.Call(SCI_ENDUNDOACTION);
}
bool SciTEBase::RangeIsAllWhitespace(int start, int end) {
TextReader acc(wEditor);
for (int i = start; i < end; i++) {
if ((acc[i] != ' ') && (acc[i] != '\t'))
return false;
}
return true;
}
unsigned int SciTEBase::GetLinePartsInStyle(int line, int style1, int style2, SString sv[], int len) {
for (int i = 0; i < len; i++)
sv[i] = "";
TextReader acc(wEditor);
SString s;
int part = 0;
int thisLineStart = wEditor.Call(SCI_POSITIONFROMLINE, line);
int nextLineStart = wEditor.Call(SCI_POSITIONFROMLINE, line + 1);
for (int pos = thisLineStart; pos < nextLineStart; pos++) {
if ((acc.StyleAt(pos) == style1) || (acc.StyleAt(pos) == style2)) {
char c[2];
c[0] = acc[pos];
c[1] = '\0';
s += c;
} else if (s.length() > 0) {
if (part < len) {
sv[part++] = s;
}
s = "";
}
}
if ((s.length() > 0) && (part < len)) {
sv[part++] = s;
}
return part;
}
inline bool IsAlphabetic(unsigned int ch) {
return ((ch >= 'A') && (ch <= 'Z')) || ((ch >= 'a') && (ch <= 'z'));
}
static bool includes(const StyleAndWords &symbols, const SString &value) {
if (symbols.words.length() == 0) {
return false;
} else if (IsAlphabetic(symbols.words[0])) {
// Set of symbols separated by spaces
size_t lenVal = value.length();
const char *symbol = symbols.words.c_str();
while (symbol) {
const char *symbolEnd = strchr(symbol, ' ');
size_t lenSymbol = strlen(symbol);
if (symbolEnd)
lenSymbol = symbolEnd - symbol;
if (lenSymbol == lenVal) {
if (strncmp(symbol, value.c_str(), lenSymbol) == 0) {
return true;
}
}
symbol = symbolEnd;
if (symbol)
symbol++;
}
} else {
// Set of individual characters. Only one character allowed for now
char ch = symbols.words[0];
return strchr(value.c_str(), ch) != 0;
}
return false;
}
IndentationStatus SciTEBase::GetIndentState(int line) {
// C like language indentation defined by braces and keywords
IndentationStatus indentState = isNone;
SString controlWords[20];
unsigned int parts = GetLinePartsInStyle(line, statementIndent.styleNumber,
-1, controlWords, ELEMENTS(controlWords));
unsigned int i;
for (i = 0; i < parts; i++) {
if (includes(statementIndent, controlWords[i]))
indentState = isKeyWordStart;
}
parts = GetLinePartsInStyle(line, statementEnd.styleNumber,
-1, controlWords, ELEMENTS(controlWords));
for (i = 0; i < parts; i++) {
if (includes(statementEnd, controlWords[i]))
indentState = isNone;
}
// Braces override keywords
SString controlStrings[20];
parts = GetLinePartsInStyle(line, blockEnd.styleNumber,
-1, controlStrings, ELEMENTS(controlStrings));
for (unsigned int j = 0; j < parts; j++) {
if (includes(blockEnd, controlStrings[j]))
indentState = isBlockEnd;
if (includes(blockStart, controlStrings[j]))
indentState = isBlockStart;
}
return indentState;
}
int SciTEBase::IndentOfBlock(int line) {
if (line < 0)
return 0;
int indentSize = wEditor.Call(SCI_GETINDENT);
int indentBlock = GetLineIndentation(line);
int backLine = line;
IndentationStatus indentState = isNone;
if (statementIndent.IsEmpty() && blockStart.IsEmpty() && blockEnd.IsEmpty())
indentState = isBlockStart; // Don't bother searching backwards
int lineLimit = line - statementLookback;
if (lineLimit < 0)
lineLimit = 0;
while ((backLine >= lineLimit) && (indentState == 0)) {
indentState = GetIndentState(backLine);
if (indentState != 0) {
indentBlock = GetLineIndentation(backLine);
if (indentState == isBlockStart) {
if (!indentOpening)
indentBlock += indentSize;
}
if (indentState == isBlockEnd) {
if (indentClosing)
indentBlock -= indentSize;
if (indentBlock < 0)
indentBlock = 0;
}
if ((indentState == isKeyWordStart) && (backLine == line))
indentBlock += indentSize;
}
backLine--;
}
return indentBlock;
}
void SciTEBase::MaintainIndentation(char ch) {
int eolMode = wEditor.Call(SCI_GETEOLMODE);
int curLine = GetCurrentLineNumber();
int lastLine = curLine - 1;
if (((eolMode == SC_EOL_CRLF || eolMode == SC_EOL_LF) && ch == '\n') ||
(eolMode == SC_EOL_CR && ch == '\r')) {
if (props.GetInt("indent.automatic")) {
while (lastLine >= 0 && GetLineLength(lastLine) == 0)
lastLine--;
}
int indentAmount = 0;
if (lastLine >= 0) {
indentAmount = GetLineIndentation(lastLine);
}
if (indentAmount > 0) {
SetLineIndentation(curLine, indentAmount);
}
}
}
void SciTEBase::AutomaticIndentation(char ch) {
Sci_CharacterRange crange = GetSelection();
int selStart = static_cast<int>(crange.cpMin);
int curLine = GetCurrentLineNumber();
int thisLineStart = wEditor.Call(SCI_POSITIONFROMLINE, curLine);
int indentSize = wEditor.Call(SCI_GETINDENT);
int indentBlock = IndentOfBlock(curLine - 1);
if ((wEditor.Call(SCI_GETLEXER) == SCLEX_PYTHON) &&
(props.GetInt("indent.python.colon") == 1)) {
int eolMode = wEditor.Call(SCI_GETEOLMODE);
int eolChar = (eolMode == SC_EOL_CR ? '\r' : '\n');
int eolChars = (eolMode == SC_EOL_CRLF ? 2 : 1);
int prevLineStart = wEditor.Call(SCI_POSITIONFROMLINE, curLine - 1);
int prevIndentPos = GetLineIndentPosition(curLine - 1);
int indentExisting = GetLineIndentation(curLine);
if (ch == eolChar) {
// Find last noncomment, nonwhitespace character on previous line
int character = 0;
int style = 0;
for (int p = selStart - eolChars - 1; p > prevLineStart; p--) {
style = wEditor.Call(SCI_GETSTYLEAT, p);
if (style != SCE_P_DEFAULT && style != SCE_P_COMMENTLINE &&
style != SCE_P_COMMENTBLOCK) {
character = wEditor.Call(SCI_GETCHARAT, p);
break;
}
}
indentBlock = GetLineIndentation(curLine - 1);
if (style == SCE_P_OPERATOR && character == ':') {
SetLineIndentation(curLine, indentBlock + indentSize);
} else if (selStart == prevIndentPos + eolChars) {
// Preserve the indentation of preexisting text beyond the caret
SetLineIndentation(curLine, indentBlock + indentExisting);
} else {
SetLineIndentation(curLine, indentBlock);
}
}
return;
}
if (blockEnd.IsSingleChar() && ch == blockEnd.words[0]) { // Dedent maybe
if (!indentClosing) {
if (RangeIsAllWhitespace(thisLineStart, selStart - 1)) {
SetLineIndentation(curLine, indentBlock - indentSize);
}
}
} else if (!blockEnd.IsSingleChar() && (ch == ' ')) { // Dedent maybe
if (!indentClosing && (GetIndentState(curLine) == isBlockEnd)) {}
} else if (blockStart.IsSingleChar() && (ch == blockStart.words[0])) {
// Dedent maybe if first on line and previous line was starting keyword
if (!indentOpening && (GetIndentState(curLine - 1) == isKeyWordStart)) {
if (RangeIsAllWhitespace(thisLineStart, selStart - 1)) {
SetLineIndentation(curLine, indentBlock - indentSize);
}
}
} else if ((ch == '\r' || ch == '\n') && (selStart == thisLineStart)) {
if (!indentClosing && !blockEnd.IsSingleChar()) { // Dedent previous line maybe
SString controlWords[1];
if (GetLinePartsInStyle(curLine - 1, blockEnd.styleNumber,
-1, controlWords, ELEMENTS(controlWords))) {
if (includes(blockEnd, controlWords[0])) {
// Check if first keyword on line is an ender
SetLineIndentation(curLine - 1, IndentOfBlock(curLine - 2) - indentSize);
// Recalculate as may have changed previous line
indentBlock = IndentOfBlock(curLine - 1);
}
}
}
SetLineIndentation(curLine, indentBlock);
}
}
/**
* Upon a character being added, SciTE may decide to perform some action
* such as displaying a completion list or auto-indentation.
*/
void SciTEBase::CharAdded(char ch) {
if (recording)
return;
Sci_CharacterRange crange = GetSelection();
int selStart = static_cast<int>(crange.cpMin);
int selEnd = static_cast<int>(crange.cpMax);
if ((selEnd == selStart) && (selStart > 0)) {
if (wEditor.Call(SCI_CALLTIPACTIVE)) {
if (calltipParametersEnd.contains(ch)) {
braceCount--;
if (braceCount < 1)
wEditor.Call(SCI_CALLTIPCANCEL);
else
StartCallTip();
} else if (calltipParametersStart.contains(ch)) {
braceCount++;
StartCallTip();
} else {
ContinueCallTip();
}
} else if (wEditor.Call(SCI_AUTOCACTIVE)) {
if (calltipParametersStart.contains(ch)) {
braceCount++;
StartCallTip();
} else if (calltipParametersEnd.contains(ch)) {
braceCount--;
} else if (!wordCharacters.contains(ch)) {
wEditor.Call(SCI_AUTOCCANCEL);
if (autoCompleteStartCharacters.contains(ch)) {
StartAutoComplete();
}
} else if (autoCCausedByOnlyOne) {
StartAutoCompleteWord(true);
}
} else if (HandleXml(ch)) {
// Handled in the routine
} else {
if (calltipParametersStart.contains(ch)) {
braceCount = 1;
StartCallTip();
} else {
autoCCausedByOnlyOne = false;
if (indentMaintain)
MaintainIndentation(ch);
else if (props.GetInt("indent.automatic"))
AutomaticIndentation(ch);
if (autoCompleteStartCharacters.contains(ch)) {
StartAutoComplete();
} else if (props.GetInt("autocompleteword.automatic") && wordCharacters.contains(ch)) {
StartAutoCompleteWord(true);
autoCCausedByOnlyOne = wEditor.Call(SCI_AUTOCACTIVE);
}
}
}
}
}
/**
* Upon a character being added to the output, SciTE may decide to perform some action
* such as displaying a completion list or running a shell command.
*/
void SciTEBase::CharAddedOutput(int ch) {
if (ch == '\n') {
NewLineInOutput();
} else if (ch == '(') {
// Potential autocompletion of symbols when $( typed
int selStart = wOutput.Call(SCI_GETSELECTIONSTART);
if ((selStart > 1) && (wOutput.Call(SCI_GETCHARAT, selStart - 2, 0) == '$')) {
SString symbols;
const char *key = NULL;
const char *val = NULL;
bool b = props.GetFirst(key, val);
while (b) {
symbols.append(key);
symbols.append(") ");
b = props.GetNext(key, val);
}
StringList symList;
symList.Set(symbols.c_str());
char *words = symList.GetNearestWords("", 0, true);
if (words) {
wEditor.Call(SCI_AUTOCSETSEPARATOR, ' ');
wOutput.CallString(SCI_AUTOCSHOW, 0, words);
delete []words;
}
}
}
}
/**
* This routine will auto complete XML or HTML tags that are still open by closing them
* @parm ch The characer we are dealing with, currently only works with the '>' character
* @return True if handled, false otherwise
*/
bool SciTEBase::HandleXml(char ch) {
// We're looking for this char
// Quit quickly if not found
if (ch != '>') {
return false;
}
// This may make sense only in certain languages
if (lexLanguage != SCLEX_HTML && lexLanguage != SCLEX_XML) {
return false;
}
// If the user has turned us off, quit now.
// Default is off
SString value = props.GetExpanded("xml.auto.close.tags");
if ((value.length() == 0) || (value == "0")) {
return false;
}
// Grab the last 512 characters or so
int nCaret = wEditor.Call(SCI_GETCURRENTPOS);
char sel[512];
int nMin = nCaret - (sizeof(sel) - 1);
if (nMin < 0) {
nMin = 0;
}
if (nCaret - nMin < 3) {
return false; // Smallest tag is 3 characters ex. <p>
}
GetRange(wEditor, nMin, nCaret, sel);
sel[sizeof(sel) - 1] = '\0';
if (sel[nCaret - nMin - 2] == '/') {
// User typed something like "<br/>"
return false;
}
if (sel[nCaret - nMin - 2] == '-') {
// User typed something like "<a $this->"
return false;
}
SString strFound = FindOpenXmlTag(sel, nCaret - nMin);
if (strFound.length() > 0) {
wEditor.Call(SCI_BEGINUNDOACTION);
SString toInsert = "</";
toInsert += strFound;
toInsert += ">";
wEditor.CallString(SCI_REPLACESEL, 0, toInsert.c_str());
SetSelection(nCaret, nCaret);
wEditor.Call(SCI_ENDUNDOACTION);
return true;
}
return false;
}
/** Search backward through nSize bytes looking for a '<', then return the tag if any
* @return The tag name
*/
SString SciTEBase::FindOpenXmlTag(const char sel[], int nSize) {
SString strRet = "";
if (nSize < 3) {
// Smallest tag is "<p>" which is 3 characters
return strRet;
}
const char *pBegin = &sel[0];
const char *pCur = &sel[nSize - 1];
pCur--; // Skip past the >
while (pCur > pBegin) {
if (*pCur == '<') {
break;
} else if (*pCur == '>') {
if (*(pCur - 1) != '-') {
break;
}
}
--pCur;
}
if (*pCur == '<') {
pCur++;
while (strchr(":_-.", *pCur) || isalnum(*pCur)) {
strRet += *pCur;
pCur++;
}
}
// Return the tag name or ""
return strRet;
}
void SciTEBase::GoMatchingBrace(bool select) {
int braceAtCaret = -1;
int braceOpposite = -1;
GUI::ScintillaWindow &wCurrent = wOutput.HasFocus() ? wOutput : wEditor;
bool isInside = FindMatchingBracePosition(!wOutput.HasFocus(), braceAtCaret, braceOpposite, true);
// Convert the character positions into caret positions based on whether
// the caret position was inside or outside the braces.
if (isInside) {
if (braceOpposite > braceAtCaret) {
braceAtCaret++;
} else {
braceOpposite++;
}
} else { // Outside
if (braceOpposite > braceAtCaret) {
braceOpposite++;
} else {
braceAtCaret++;
}
}
if (braceOpposite >= 0) {
EnsureRangeVisible(wCurrent, braceOpposite, braceOpposite);
if (select) {
wCurrent.Call(SCI_SETSEL, braceAtCaret, braceOpposite);
} else {
wCurrent.Call(SCI_SETSEL, braceOpposite, braceOpposite);
}
}
}
// Text ConditionalUp Ctrl+J Finds the previous matching preprocessor condition
// Text ConditionalDown Ctrl+K Finds the next matching preprocessor condition
void SciTEBase::GoMatchingPreprocCond(int direction, bool select) {
int mppcAtCaret = wEditor.Call(SCI_GETCURRENTPOS);
int mppcMatch = -1;
int forward = (direction == IDM_NEXTMATCHPPC);
bool isInside = FindMatchingPreprocCondPosition(forward, mppcAtCaret, mppcMatch);
if (isInside && mppcMatch >= 0) {
EnsureRangeVisible(wEditor, mppcMatch, mppcMatch);
if (select) {
// Selection changes the rules a bit...
int selStart = wEditor.Call(SCI_GETSELECTIONSTART);
int selEnd = wEditor.Call(SCI_GETSELECTIONEND);
// pivot isn't the caret position but the opposite (if there is a selection)
int pivot = (mppcAtCaret == selStart ? selEnd : selStart);
if (forward) {
// Caret goes one line beyond the target, to allow selecting the whole line
int lineNb = wEditor.Call(SCI_LINEFROMPOSITION, mppcMatch);
mppcMatch = wEditor.Call(SCI_POSITIONFROMLINE, lineNb + 1);
}
SetSelection(pivot, mppcMatch);
} else {
SetSelection(mppcMatch, mppcMatch);
}
} else {
WarnUser(warnNotFound);
}
}
void SciTEBase::AddCommand(const SString &cmd, const SString &dir, JobSubsystem jobType, const SString &input, int flags) {
// If no explicit directory, use the directory of the current file
FilePath directoryRun;
if (dir.length()) {
FilePath directoryExplicit(GUI::StringFromUTF8(dir.c_str()));
if (directoryExplicit.IsAbsolute()) {
directoryRun = directoryExplicit;
} else {
// Relative paths are relative to the current file
directoryRun = FilePath(filePath.Directory(), directoryExplicit).NormalizePath();
}
} else {
directoryRun = filePath.Directory();
}
jobQueue.AddCommand(cmd, directoryRun, jobType, input, flags);
}
int ControlIDOfCommand(unsigned long wParam) {
return wParam & 0xffff;
}
void WindowSetFocus(GUI::ScintillaWindow &w) {
w.Send(SCI_GRABFOCUS, 0, 0);
}
void SciTEBase::SetLineNumberWidth() {
if (lineNumbers) {
int lineNumWidth = lineNumbersWidth;
if (lineNumbersExpand) {
// The margin size will be expanded if the current buffer's maximum
// line number would overflow the margin.
int lineCount = wEditor.Call(SCI_GETLINECOUNT);
lineNumWidth = 1;
while (lineCount >= 10) {
lineCount /= 10;
++lineNumWidth;
}
if (lineNumWidth < lineNumbersWidth) {
lineNumWidth = lineNumbersWidth;
}
}
if (lineNumWidth < 0)
lineNumWidth = 0;
// The 4 here allows for spacing: 1 pixel on left and 3 on right.
std::string nNines(lineNumWidth, '9');
int pixelWidth = 4 + wEditor.CallString(SCI_TEXTWIDTH, STYLE_LINENUMBER, nNines.c_str());
wEditor.Call(SCI_SETMARGINWIDTHN, 0, pixelWidth);
} else {
wEditor.Call(SCI_SETMARGINWIDTHN, 0, 0);
}
}
void SciTEBase::MenuCommand(int cmdID, int source) {
switch (cmdID) {
case IDM_NEW:
// For the New command, the "are you sure" question is always asked as this gives
// an opportunity to abandon the edits made to a file when are.you.sure is turned off.
if (CanMakeRoom()) {
New();
ReadProperties();
SetIndentSettings();
SetEol();
UpdateStatusBar(true);
WindowSetFocus(wEditor);
}
break;
case IDM_OPEN:
// No need to see if can make room as that will occur
// when doing the opening. Must be done there as user
// may decide to open multiple files so do not know yet
// how much room needed.
OpenDialog(filePath.Directory(), GUI::StringFromUTF8(props.GetExpanded("open.filter").c_str()).c_str());
WindowSetFocus(wEditor);
break;
case IDM_OPENSELECTED:
if (OpenSelected())
WindowSetFocus(wEditor);
break;
case IDM_REVERT:
Revert();
WindowSetFocus(wEditor);
break;
case IDM_CLOSE:
if (SaveIfUnsure() != IDCANCEL) {
Close();
WindowSetFocus(wEditor);
}
break;
case IDM_CLOSEALL:
CloseAllBuffers();
break;
case IDM_SAVE:
Save();
WindowSetFocus(wEditor);
break;
case IDM_SAVEALL:
SaveAllBuffers(false, true);
break;
case IDM_SAVEAS:
SaveAsDialog();
WindowSetFocus(wEditor);
break;
case IDM_SAVEACOPY:
SaveACopy();
WindowSetFocus(wEditor);
break;
case IDM_COPYPATH:
CopyPath();
break;
case IDM_SAVEASHTML:
SaveAsHTML();
WindowSetFocus(wEditor);
break;
case IDM_SAVEASRTF:
SaveAsRTF();
WindowSetFocus(wEditor);
break;
case IDM_SAVEASPDF:
SaveAsPDF();
WindowSetFocus(wEditor);
break;
case IDM_SAVEASTEX:
SaveAsTEX();
WindowSetFocus(wEditor);
break;
case IDM_SAVEASXML:
SaveAsXML();
WindowSetFocus(wEditor);
break;
case IDM_PRINT:
Print(true);
break;
case IDM_PRINTSETUP:
PrintSetup();
break;
case IDM_LOADSESSION:
LoadSessionDialog();
WindowSetFocus(wEditor);
break;
case IDM_SAVESESSION:
SaveSessionDialog();
WindowSetFocus(wEditor);
break;
case IDM_ABOUT:
AboutDialog();
break;
case IDM_QUIT:
QuitProgram();
break;
case IDM_ENCODING_DEFAULT:
case IDM_ENCODING_UCS2BE:
case IDM_ENCODING_UCS2LE:
case IDM_ENCODING_UTF8:
case IDM_ENCODING_UCOOKIE:
CurrentBuffer()->unicodeMode = static_cast<UniMode>(cmdID - IDM_ENCODING_DEFAULT);
if (CurrentBuffer()->unicodeMode != uni8Bit) {
// Override the code page if Unicode
codePage = SC_CP_UTF8;
} else {
codePage = props.GetInt("code.page");
}
wEditor.Call(SCI_SETCODEPAGE, codePage);
break;
case IDM_NEXTFILESTACK:
if (buffers.size > 1 && props.GetInt("buffers.zorder.switching")) {
NextInStack(); // next most recently selected buffer
WindowSetFocus(wEditor);
break;
}
// else fall through and do NEXTFILE behaviour...
case IDM_NEXTFILE:
if (buffers.size > 1) {
Next(); // Use Next to tabs move left-to-right
WindowSetFocus(wEditor);
} else {
// Not using buffers - switch to next file on MRU
StackMenuNext();
}
break;
case IDM_PREVFILESTACK:
if (buffers.size > 1 && props.GetInt("buffers.zorder.switching")) {
PrevInStack(); // next least recently selected buffer
WindowSetFocus(wEditor);
break;
}
// else fall through and do PREVFILE behaviour...
case IDM_PREVFILE:
if (buffers.size > 1) {
Prev(); // Use Prev to tabs move right-to-left
WindowSetFocus(wEditor);
} else {
// Not using buffers - switch to previous file on MRU
StackMenuPrev();
}
break;
case IDM_MOVETABRIGHT:
MoveTabRight();
WindowSetFocus(wEditor);
break;
case IDM_MOVETABLEFT:
MoveTabLeft();
WindowSetFocus(wEditor);
break;
case IDM_UNDO:
CallPane(source, SCI_UNDO);
CheckMenus();
break;
case IDM_REDO:
CallPane(source, SCI_REDO);
CheckMenus();
break;
case IDM_CUT:
if (!CallPane(source, SCI_GETSELECTIONEMPTY)) {
CallPane(source, SCI_CUT);
}
break;
case IDM_COPY:
if (!CallPane(source, SCI_GETSELECTIONEMPTY)) {
//fprintf(stderr, "Copy from %d\n", source);
CallPane(source, SCI_COPY);
}
// does not trigger SCN_UPDATEUI, so do CheckMenusClipboard() here
CheckMenusClipboard();
break;
case IDM_PASTE:
CallPane(source, SCI_PASTE);
break;
case IDM_DUPLICATE:
CallPane(source, SCI_SELECTIONDUPLICATE);
break;
case IDM_PASTEANDDOWN: {
int pos = CallFocused(SCI_GETCURRENTPOS);
CallFocused(SCI_PASTE);
CallFocused(SCI_SETCURRENTPOS, pos);
CallFocused(SCI_CHARLEFT);
CallFocused(SCI_LINEDOWN);
}
break;
case IDM_CLEAR:
CallPane(source, SCI_CLEAR);
break;
case IDM_SELECTALL:
CallPane(source, SCI_SELECTALL);
break;
case IDM_COPYASRTF:
CopyAsRTF();
break;
case IDM_FIND:
Find();
break;
case IDM_INCSEARCH:
IncrementSearchMode();
break;
case IDM_FINDNEXT:
FindNext(reverseFind);
break;
case IDM_FINDNEXTBACK:
FindNext(!reverseFind);
break;
case IDM_FINDNEXTSEL:
SelectionIntoFind();
FindNext(reverseFind, true, false);
break;
case IDM_ENTERSELECTION:
SelectionIntoFind();
break;
case IDM_FINDNEXTBACKSEL:
SelectionIntoFind();
FindNext(!reverseFind, true, false);
break;
case IDM_FINDINFILES:
FindInFiles();
break;
case IDM_REPLACE:
Replace();
break;
case IDM_GOTO:
GoLineDialog();
break;
case IDM_MATCHBRACE:
GoMatchingBrace(false);
break;
case IDM_SELECTTOBRACE:
GoMatchingBrace(true);
break;
case IDM_PREVMATCHPPC:
GoMatchingPreprocCond(IDM_PREVMATCHPPC, false);
break;
case IDM_SELECTTOPREVMATCHPPC:
GoMatchingPreprocCond(IDM_PREVMATCHPPC, true);
break;
case IDM_NEXTMATCHPPC:
GoMatchingPreprocCond(IDM_NEXTMATCHPPC, false);
break;
case IDM_SELECTTONEXTMATCHPPC:
GoMatchingPreprocCond(IDM_NEXTMATCHPPC, true);
break;
case IDM_SHOWCALLTIP:
if (wEditor.Call(SCI_CALLTIPACTIVE)) {
currentCallTip = (currentCallTip + 1 == maxCallTips) ? 0 : currentCallTip + 1;
FillFunctionDefinition();
} else {
StartCallTip();
}
break;
case IDM_COMPLETE:
autoCCausedByOnlyOne = false;
StartAutoComplete();
break;
case IDM_COMPLETEWORD:
autoCCausedByOnlyOne = false;
StartAutoCompleteWord(false);
break;
case IDM_ABBREV:
wEditor.Call(SCI_CANCEL);
StartExpandAbbreviation();
break;
case IDM_INS_ABBREV:
wEditor.Call(SCI_CANCEL);
StartInsertAbbreviation();
break;
case IDM_BLOCK_COMMENT:
StartBlockComment();
break;
case IDM_BOX_COMMENT:
StartBoxComment();
break;
case IDM_STREAM_COMMENT:
StartStreamComment();
break;
case IDM_TOGGLE_FOLDALL:
FoldAll();
break;
case IDM_UPRCASE:
CallFocused(SCI_UPPERCASE);
break;
case IDM_LWRCASE:
CallFocused(SCI_LOWERCASE);
break;
case IDM_JOIN:
CallFocused(SCI_TARGETFROMSELECTION);
CallFocused(SCI_LINESJOIN);
break;
case IDM_SPLIT:
CallFocused(SCI_TARGETFROMSELECTION);
CallFocused(SCI_LINESSPLIT);
break;
case IDM_EXPAND:
wEditor.Call(SCI_TOGGLEFOLD, GetCurrentLineNumber());
break;
case IDM_TOGGLE_FOLDRECURSIVE: {
int line = GetCurrentLineNumber();
int level = wEditor.Call(SCI_GETFOLDLEVEL, line);
ToggleFoldRecursive(line, level);
}
break;
case IDM_EXPAND_ENSURECHILDRENVISIBLE: {
int line = GetCurrentLineNumber();
int level = wEditor.Call(SCI_GETFOLDLEVEL, line);
EnsureAllChildrenVisible(line, level);
}
break;
case IDM_SPLITVERTICAL:
{
GUI::Rectangle rcClient = GetClientRectangle();
heightOutput = splitVertical ?
int((double)heightOutput * rcClient.Height() / rcClient.Width() + 0.5) :
int((double)heightOutput * rcClient.Width() / rcClient.Height() + 0.5);
previousHeightOutput = splitVertical ?
int((double)previousHeightOutput * rcClient.Height() / rcClient.Width() + 0.5) :
int((double)previousHeightOutput * rcClient.Width() / rcClient.Height() + 0.5);
}
splitVertical = !splitVertical;
heightOutput = NormaliseSplit(heightOutput);
SizeSubWindows();
CheckMenus();
Redraw();
break;
case IDM_LINENUMBERMARGIN:
lineNumbers = !lineNumbers;
SetLineNumberWidth();
CheckMenus();
break;
case IDM_SELMARGIN:
margin = !margin;
wEditor.Call(SCI_SETMARGINWIDTHN, 1, margin ? marginWidth : 0);
CheckMenus();
break;
case IDM_FOLDMARGIN:
foldMargin = !foldMargin;
wEditor.Call(SCI_SETMARGINWIDTHN, 2, foldMargin ? foldMarginWidth : 0);
CheckMenus();
break;
case IDM_VIEWEOL:
wEditor.Call(SCI_SETVIEWEOL, !wEditor.Call(SCI_GETVIEWEOL));
CheckMenus();
break;
case IDM_VIEWTOOLBAR:
tbVisible = !tbVisible;
ShowToolBar();
CheckMenus();
break;
case IDM_TOGGLEOUTPUT:
ToggleOutputVisible();
CheckMenus();
break;
case IDM_TOGGLEPARAMETERS:
ParametersDialog(false);
CheckMenus();
break;
case IDM_WRAP:
wrap = !wrap;
wEditor.Call(SCI_SETWRAPMODE, wrap ? wrapStyle : SC_WRAP_NONE);
CheckMenus();
break;
case IDM_WRAPOUTPUT:
wrapOutput = !wrapOutput;
wOutput.Call(SCI_SETWRAPMODE, wrapOutput ? wrapStyle : SC_WRAP_NONE);
CheckMenus();
break;
case IDM_READONLY:
isReadOnly = !isReadOnly;
CurrentBuffer()->isReadOnly = isReadOnly;
wEditor.Call(SCI_SETREADONLY, isReadOnly);
UpdateStatusBar(true);
CheckMenus();
break;
case IDM_VIEWTABBAR:
tabVisible = !tabVisible;
ShowTabBar();
CheckMenus();
break;
case IDM_VIEWSTATUSBAR:
sbVisible = !sbVisible;
ShowStatusBar();
UpdateStatusBar(true);
CheckMenus();
break;
case IDM_CLEAROUTPUT:
wOutput.Send(SCI_CLEARALL);
break;
case IDM_SWITCHPANE:
if (wEditor.HasFocus())
WindowSetFocus(wOutput);
else
WindowSetFocus(wEditor);
break;
case IDM_EOL_CRLF:
wEditor.Call(SCI_SETEOLMODE, SC_EOL_CRLF);
CheckMenus();
UpdateStatusBar(false);
break;
case IDM_EOL_CR:
wEditor.Call(SCI_SETEOLMODE, SC_EOL_CR);
CheckMenus();
UpdateStatusBar(false);
break;
case IDM_EOL_LF:
wEditor.Call(SCI_SETEOLMODE, SC_EOL_LF);
CheckMenus();
UpdateStatusBar(false);
break;
case IDM_EOL_CONVERT:
wEditor.Call(SCI_CONVERTEOLS, wEditor.Call(SCI_GETEOLMODE));
break;
case IDM_VIEWSPACE:
ViewWhitespace(!wEditor.Call(SCI_GETVIEWWS));
CheckMenus();
Redraw();
break;
case IDM_VIEWGUIDES: {
bool viewIG = wEditor.Call(SCI_GETINDENTATIONGUIDES, 0, 0) == 0;
wEditor.Call(SCI_SETINDENTATIONGUIDES, viewIG ? indentExamine : SC_IV_NONE);
CheckMenus();
Redraw();
}
break;
case IDM_COMPILE: {
if (SaveIfUnsureForBuilt() != IDCANCEL) {
SelectionIntoProperties();
AddCommand(props.GetWild("command.compile.", FileNameExt().AsUTF8().c_str()), "",
SubsystemType("command.compile.subsystem."));
if (jobQueue.HasCommandToRun())
Execute();
}
}
break;
case IDM_BUILD: {
if (SaveIfUnsureForBuilt() != IDCANCEL) {
SelectionIntoProperties();
AddCommand(
props.GetWild("command.build.", FileNameExt().AsUTF8().c_str()),
props.GetNewExpand("command.build.directory.", FileNameExt().AsUTF8().c_str()),
SubsystemType("command.build.subsystem."));
if (jobQueue.HasCommandToRun()) {
jobQueue.isBuilding = true;
Execute();
}
}
}
break;
case IDM_GO: {
if (SaveIfUnsureForBuilt() != IDCANCEL) {
SelectionIntoProperties();
int flags = 0;
if (!jobQueue.isBuilt) {
SString buildcmd = props.GetNewExpand("command.go.needs.", FileNameExt().AsUTF8().c_str());
AddCommand(buildcmd, "",
SubsystemType("command.go.needs.subsystem."));
if (buildcmd.length() > 0) {
jobQueue.isBuilding = true;
flags |= jobForceQueue;
}
}
AddCommand(props.GetWild("command.go.", FileNameExt().AsUTF8().c_str()), "",
SubsystemType("command.go.subsystem."), "", flags);
if (jobQueue.HasCommandToRun())
Execute();
}
}
break;
case IDM_STOPEXECUTE:
StopExecute();
break;
case IDM_NEXTMSG:
GoMessage(1);
break;
case IDM_PREVMSG:
GoMessage(-1);
break;
case IDM_OPENLOCALPROPERTIES:
OpenProperties(IDM_OPENLOCALPROPERTIES);
WindowSetFocus(wEditor);
break;
case IDM_OPENUSERPROPERTIES:
OpenProperties(IDM_OPENUSERPROPERTIES);
WindowSetFocus(wEditor);
break;
case IDM_OPENGLOBALPROPERTIES:
OpenProperties(IDM_OPENGLOBALPROPERTIES);
WindowSetFocus(wEditor);
break;
case IDM_OPENABBREVPROPERTIES:
OpenProperties(IDM_OPENABBREVPROPERTIES);
WindowSetFocus(wEditor);
break;
case IDM_OPENLUAEXTERNALFILE:
OpenProperties(IDM_OPENLUAEXTERNALFILE);
WindowSetFocus(wEditor);
break;
case IDM_OPENDIRECTORYPROPERTIES:
OpenProperties(IDM_OPENDIRECTORYPROPERTIES);
WindowSetFocus(wEditor);
break;
case IDM_SRCWIN:
break;
case IDM_BOOKMARK_TOGGLE:
BookmarkToggle();
break;
case IDM_BOOKMARK_NEXT:
BookmarkNext(true);
break;
case IDM_BOOKMARK_PREV:
BookmarkNext(false);
break;
case IDM_BOOKMARK_NEXT_SELECT:
BookmarkNext(true, true);
break;
case IDM_BOOKMARK_PREV_SELECT:
BookmarkNext(false, true);
break;
case IDM_BOOKMARK_CLEARALL:
wEditor.Call(SCI_MARKERDELETEALL, markerBookmark);
RemoveFindMarks();
break;
case IDM_TABSIZE:
TabSizeDialog();
break;
case IDM_MONOFONT:
CurrentBuffer()->useMonoFont = !CurrentBuffer()->useMonoFont;
ReadFontProperties();
Redraw();
break;
case IDM_MACROLIST:
AskMacroList();
break;
case IDM_MACROPLAY:
StartPlayMacro();
break;
case IDM_MACRORECORD:
StartRecordMacro();
break;
case IDM_MACROSTOPRECORD:
StopRecordMacro();
break;
case IDM_HELP: {
SelectionIntoProperties();
AddCommand(props.GetWild("command.help.", FileNameExt().AsUTF8().c_str()), "",
SubsystemType("command.help.subsystem."));
if (jobQueue.HasCommandToRun()) {
jobQueue.isBuilding = true;
Execute();
}
}
break;
case IDM_HELP_SCITE: {
SelectionIntoProperties();
AddCommand(props.Get("command.scite.help"), "",
SubsystemFromChar(props.Get("command.scite.help.subsystem")[0]));
if (jobQueue.HasCommandToRun()) {
jobQueue.isBuilding = true;
Execute();
}
}
break;
default:
if ((cmdID >= bufferCmdID) &&
(cmdID < bufferCmdID + buffers.size)) {
SetDocumentAt(cmdID - bufferCmdID);
CheckReload();
} else if ((cmdID >= fileStackCmdID) &&
(cmdID < fileStackCmdID + fileStackMax)) {
StackMenu(cmdID - fileStackCmdID);
} else if (cmdID >= importCmdID &&
(cmdID < importCmdID + importMax)) {
ImportMenu(cmdID - importCmdID);
} else if (cmdID >= IDM_TOOLS && cmdID < IDM_TOOLS + toolMax) {
ToolsMenu(cmdID - IDM_TOOLS);
} else if (cmdID >= IDM_LANGUAGE && cmdID < IDM_LANGUAGE + 100) {
SetOverrideLanguage(cmdID - IDM_LANGUAGE);
}
break;
}
}
void SciTEBase::FoldChanged(int line, int levelNow, int levelPrev) {
if (levelNow & SC_FOLDLEVELHEADERFLAG) {
if (!(levelPrev & SC_FOLDLEVELHEADERFLAG)) {
// Adding a fold point.
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
if (!wEditor.Call(SCI_GETALLLINESVISIBLE))
Expand(line, true, false, 0, levelPrev);
}
} else if (levelPrev & SC_FOLDLEVELHEADERFLAG) {
if (!wEditor.Call(SCI_GETFOLDEXPANDED, line)) {
// Removing the fold from one that has been contracted so should expand
// otherwise lines are left invisible with no way to make them visible
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
if (!wEditor.Call(SCI_GETALLLINESVISIBLE))
Expand(line, true, false, 0, levelPrev);
}
}
if (!(levelNow & SC_FOLDLEVELWHITEFLAG) &&
((levelPrev & SC_FOLDLEVELNUMBERMASK) > (levelNow & SC_FOLDLEVELNUMBERMASK))) {
if (!wEditor.Call(SCI_GETALLLINESVISIBLE)) {
// See if should still be hidden
int parentLine = wEditor.Call(SCI_GETFOLDPARENT, line);
if (parentLine < 0) {
wEditor.Call(SCI_SHOWLINES, line, line);
} else if (wEditor.Call(SCI_GETFOLDEXPANDED, parentLine) && wEditor.Call(SCI_GETLINEVISIBLE, parentLine)) {
wEditor.Call(SCI_SHOWLINES, line, line);
}
}
}
}
void SciTEBase::Expand(int &line, bool doExpand, bool force, int visLevels, int level) {
int lineMaxSubord = wEditor.Call(SCI_GETLASTCHILD, line, level & SC_FOLDLEVELNUMBERMASK);
line++;
while (line <= lineMaxSubord) {
if (force) {
if (visLevels > 0)
wEditor.Call(SCI_SHOWLINES, line, line);
else
wEditor.Call(SCI_HIDELINES, line, line);
} else {
if (doExpand)
wEditor.Call(SCI_SHOWLINES, line, line);
}
int levelLine = level;
if (levelLine == -1)
levelLine = wEditor.Call(SCI_GETFOLDLEVEL, line);
if (levelLine & SC_FOLDLEVELHEADERFLAG) {
if (force) {
if (visLevels > 1)
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
else
wEditor.Call(SCI_SETFOLDEXPANDED, line, 0);
Expand(line, doExpand, force, visLevels - 1);
} else {
if (doExpand) {
if (!wEditor.Call(SCI_GETFOLDEXPANDED, line))
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
Expand(line, true, force, visLevels - 1);
} else {
Expand(line, false, force, visLevels - 1);
}
}
} else {
line++;
}
}
}
void SciTEBase::FoldAll() {
wEditor.Call(SCI_COLOURISE, 0, -1);
int maxLine = wEditor.Call(SCI_GETLINECOUNT);
bool expanding = true;
for (int lineSeek = 0; lineSeek < maxLine; lineSeek++) {
if (wEditor.Call(SCI_GETFOLDLEVEL, lineSeek) & SC_FOLDLEVELHEADERFLAG) {
expanding = !wEditor.Call(SCI_GETFOLDEXPANDED, lineSeek);
break;
}
}
for (int line = 0; line < maxLine; line++) {
int level = wEditor.Call(SCI_GETFOLDLEVEL, line);
if ((level & SC_FOLDLEVELHEADERFLAG) &&
(SC_FOLDLEVELBASE == (level & SC_FOLDLEVELNUMBERMASK))) {
if (expanding) {
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
Expand(line, true, false, 0, level);
line--;
} else {
int lineMaxSubord = wEditor.Call(SCI_GETLASTCHILD, line, -1);
wEditor.Call(SCI_SETFOLDEXPANDED, line, 0);
if (lineMaxSubord > line)
wEditor.Call(SCI_HIDELINES, line + 1, lineMaxSubord);
}
}
}
}
void SciTEBase::GotoLineEnsureVisible(int line) {
wEditor.Call(SCI_ENSUREVISIBLEENFORCEPOLICY, line);
wEditor.Call(SCI_GOTOLINE, line);
}
void SciTEBase::EnsureRangeVisible(GUI::ScintillaWindow &win, int posStart, int posEnd, bool enforcePolicy) {
int lineStart = win.Call(SCI_LINEFROMPOSITION, Minimum(posStart, posEnd));
int lineEnd = win.Call(SCI_LINEFROMPOSITION, Maximum(posStart, posEnd));
for (int line = lineStart; line <= lineEnd; line++) {
win.Call(enforcePolicy ? SCI_ENSUREVISIBLEENFORCEPOLICY : SCI_ENSUREVISIBLE, line);
}
}
bool SciTEBase::MarginClick(int position, int modifiers) {
int lineClick = wEditor.Call(SCI_LINEFROMPOSITION, position);
if ((modifiers & SCMOD_SHIFT) && (modifiers & SCMOD_CTRL)) {
FoldAll();
} else {
int levelClick = wEditor.Call(SCI_GETFOLDLEVEL, lineClick);
if (levelClick & SC_FOLDLEVELHEADERFLAG) {
if (modifiers & SCMOD_SHIFT) {
EnsureAllChildrenVisible(lineClick, levelClick);
} else if (modifiers & SCMOD_CTRL) {
ToggleFoldRecursive(lineClick, levelClick);
} else {
// Toggle this line
wEditor.Call(SCI_TOGGLEFOLD, lineClick);
}
}
}
return true;
}
void SciTEBase::ToggleFoldRecursive(int line, int level) {
if (wEditor.Call(SCI_GETFOLDEXPANDED, line)) {
// Contract this line and all children
wEditor.Call(SCI_SETFOLDEXPANDED, line, 0);
Expand(line, false, true, 0, level);
} else {
// Expand this line and all children
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
Expand(line, true, true, 100, level);
}
}
void SciTEBase::EnsureAllChildrenVisible(int line, int level) {
// Ensure all children visible
wEditor.Call(SCI_SETFOLDEXPANDED, line, 1);
Expand(line, true, true, 100, level);
}
void SciTEBase::NewLineInOutput() {
if (jobQueue.IsExecuting())
return;
int line = wOutput.Call(SCI_LINEFROMPOSITION,
wOutput.Call(SCI_GETCURRENTPOS)) - 1;
SString cmd = GetLine(wOutput, line);
if (cmd == ">") {
// Search output buffer for previous command
line--;
while (line >= 0) {
cmd = GetLine(wOutput, line);
if (cmd.startswith(">") && !cmd.startswith(">Exit")) {
cmd = cmd.substr(1);
break;
}
line--;
}
} else if (cmd.startswith(">")) {
cmd = cmd.substr(1);
}
returnOutputToCommand = false;
AddCommand(cmd, "", jobCLI);
Execute();
}
void SciTEBase::Notify(SCNotification *notification) {
bool handled = false;
switch (notification->nmhdr.code) {
case SCN_PAINTED:
if ((notification->nmhdr.idFrom == IDM_SRCWIN) == (wEditor.HasFocus())) {
// Obly highlight focussed pane.
// Manage delay before highlight when no user selection but there is word at the caret.
// So the Delay is based on the blinking of caret, scroll...
// If currentWordHighlight.statesOfDelay == currentWordHighlight.delay,
// then there is word at the caret without selection, and need some delay.
if (currentWordHighlight.statesOfDelay == currentWordHighlight.delay) {
if (currentWordHighlight.elapsedTimes.Duration() >= 0.5) {
currentWordHighlight.statesOfDelay = currentWordHighlight.delayJustEnded;
HighlightCurrentWord(true);
(wOutput.HasFocus() ? wOutput : wEditor).InvalidateAll();
}
}
}
break;
case SCEN_SETFOCUS:
case SCEN_KILLFOCUS:
CheckMenus();
break;
case SCN_STYLENEEDED: {
if (extender) {
// Colourisation may be performed by script
if ((notification->nmhdr.idFrom == IDM_SRCWIN) && (lexLanguage == SCLEX_CONTAINER)) {
int endStyled = wEditor.Call(SCI_GETENDSTYLED);
int lineEndStyled = wEditor.Call(SCI_LINEFROMPOSITION, endStyled);
endStyled = wEditor.Call(SCI_POSITIONFROMLINE, lineEndStyled);
StyleWriter styler(wEditor);
int styleStart = 0;
if (endStyled > 0)
styleStart = styler.StyleAt(endStyled - 1);
styler.SetCodePage(codePage);
extender->OnStyle(endStyled, notification->position - endStyled,
styleStart, &styler);
styler.Flush();
}
}
}
break;
case SCN_CHARADDED:
if (extender)
handled = extender->OnChar(static_cast<char>(notification->ch));
if (!handled) {
if (notification->nmhdr.idFrom == IDM_SRCWIN) {
CharAdded(static_cast<char>(notification->ch));
} else {
CharAddedOutput(notification->ch);
}
}
break;
case SCN_SAVEPOINTREACHED:
if (notification->nmhdr.idFrom == IDM_SRCWIN) {
if (extender)
handled = extender->OnSavePointReached();
if (!handled) {
CurrentBuffer()->isDirty = false;
}
}
CheckMenus();
SetWindowName();
SetBuffersMenu();
break;
case SCN_SAVEPOINTLEFT:
if (notification->nmhdr.idFrom == IDM_SRCWIN) {
if (extender)
handled = extender->OnSavePointLeft();
if (!handled) {
CurrentBuffer()->isDirty = true;
jobQueue.isBuilt = false;
}
}
CheckMenus();
SetWindowName();
SetBuffersMenu();
break;
case SCN_DOUBLECLICK:
if (extender)
handled = extender->OnDoubleClick();
if (!handled && notification->nmhdr.idFrom == IDM_RUNWIN) {
GoMessage(0);
}
break;
case SCN_UPDATEUI:
if (extender)
handled = extender->OnUpdateUI();
if (!handled) {
BraceMatch(notification->nmhdr.idFrom == IDM_SRCWIN);
if (notification->nmhdr.idFrom == IDM_SRCWIN) {
UpdateStatusBar(false);
}
CheckMenusClipboard();
}
if (CurrentBuffer()->findMarks == Buffer::fmModified) {
RemoveFindMarks();
}
if (notification->updated & (SC_UPDATE_SELECTION | SC_UPDATE_CONTENT)) {
if ((notification->nmhdr.idFrom == IDM_SRCWIN) == (wEditor.HasFocus())) {
// Obly highlight focussed pane.
if (notification->updated & SC_UPDATE_SELECTION)
currentWordHighlight.statesOfDelay = currentWordHighlight.noDelay; // Selection has just been updated, so delay is disabled.
if (currentWordHighlight.statesOfDelay != currentWordHighlight.delayJustEnded)
HighlightCurrentWord(notification->updated != SC_UPDATE_CONTENT);
else
currentWordHighlight.statesOfDelay = currentWordHighlight.delayAlreadyElapsed;
}
}
break;
case SCN_MODIFIED:
if (notification->nmhdr.idFrom == IDM_SRCWIN)
CurrentBuffer()->DocumentModified();
if (notification->modificationType & SC_LASTSTEPINUNDOREDO) {
//when the user hits undo or redo, several normal insert/delete
//notifications may fire, but we will end up here in the end
EnableAMenuItem(IDM_UNDO, CallFocusedElseDefault(true, SCI_CANUNDO));
EnableAMenuItem(IDM_REDO, CallFocusedElseDefault(true, SCI_CANREDO));
} else if (notification->modificationType & (SC_MOD_INSERTTEXT | SC_MOD_DELETETEXT)) {
//this will be called a lot, and usually means "typing".
EnableAMenuItem(IDM_UNDO, true);
EnableAMenuItem(IDM_REDO, false);
if (CurrentBuffer()->findMarks == Buffer::fmMarked) {
CurrentBuffer()->findMarks = Buffer::fmModified;
}
}
if (notification->linesAdded && lineNumbers && lineNumbersExpand)
SetLineNumberWidth();
if (0 != (notification->modificationType & SC_MOD_CHANGEFOLD)) {
FoldChanged(notification->line,
notification->foldLevelNow, notification->foldLevelPrev);
}
break;
case SCN_MARGINCLICK: {
if (extender)
handled = extender->OnMarginClick();
if (!handled) {
if (notification->margin == 2) {
MarginClick(notification->position, notification->modifiers);
}
}
}
break;
case SCN_NEEDSHOWN: {
EnsureRangeVisible(wEditor, notification->position, notification->position + notification->length, false);
}
break;
case SCN_USERLISTSELECTION: {
if (notification->wParam == 2)
ContinueMacroList(notification->text);
else if (extender && notification->wParam > 2)
extender->OnUserListSelection(static_cast<int>(notification->wParam), notification->text);
}
break;
case SCN_CALLTIPCLICK: {
if (notification->position == 1 && currentCallTip > 0) {
currentCallTip--;
FillFunctionDefinition();
} else if (notification->position == 2 && currentCallTip + 1 < maxCallTips) {
currentCallTip++;
FillFunctionDefinition();
}
}
break;
case SCN_MACRORECORD:
RecordMacroCommand(notification);
break;
case SCN_URIDROPPED:
OpenUriList(notification->text);
break;
case SCN_DWELLSTART:
if (extender && (INVALID_POSITION != notification->position)) {
int endWord = notification->position;
SString message =
RangeExtendAndGrab(wEditor,
notification->position, endWord, &SciTEBase::iswordcharforsel);
if (message.length()) {
extender->OnDwellStart(notification->position,message.c_str());
}
}
break;
case SCN_DWELLEND:
if (extender) {
extender->OnDwellStart(0,""); // flags end of calltip
}
break;
case SCN_ZOOM:
SetLineNumberWidth();
break;
case SCN_MODIFYATTEMPTRO:
AbandonAutomaticSave();
break;
}
}
void SciTEBase::CheckMenusClipboard() {
bool hasSelection = !CallFocusedElseDefault(false, SCI_GETSELECTIONEMPTY);
EnableAMenuItem(IDM_CUT, hasSelection);
EnableAMenuItem(IDM_COPY, hasSelection);
EnableAMenuItem(IDM_CLEAR, hasSelection);
EnableAMenuItem(IDM_PASTE, CallFocusedElseDefault(true, SCI_CANPASTE));
}
void SciTEBase::CheckMenus() {
CheckMenusClipboard();
EnableAMenuItem(IDM_UNDO, CallFocusedElseDefault(true, SCI_CANUNDO));
EnableAMenuItem(IDM_REDO, CallFocusedElseDefault(true, SCI_CANREDO));
EnableAMenuItem(IDM_DUPLICATE, !isReadOnly);
EnableAMenuItem(IDM_SHOWCALLTIP, apis != 0);
EnableAMenuItem(IDM_COMPLETE, apis != 0);
CheckAMenuItem(IDM_SPLITVERTICAL, splitVertical);
EnableAMenuItem(IDM_OPENFILESHERE, props.GetInt("check.if.already.open") != 0);
CheckAMenuItem(IDM_OPENFILESHERE, openFilesHere);
CheckAMenuItem(IDM_WRAP, wrap);
CheckAMenuItem(IDM_WRAPOUTPUT, wrapOutput);
CheckAMenuItem(IDM_READONLY, isReadOnly);
CheckAMenuItem(IDM_FULLSCREEN, fullScreen);
CheckAMenuItem(IDM_VIEWTOOLBAR, tbVisible);
CheckAMenuItem(IDM_VIEWTABBAR, tabVisible);
CheckAMenuItem(IDM_VIEWSTATUSBAR, sbVisible);
CheckAMenuItem(IDM_VIEWEOL, wEditor.Call(SCI_GETVIEWEOL));
CheckAMenuItem(IDM_VIEWSPACE, wEditor.Call(SCI_GETVIEWWS));
CheckAMenuItem(IDM_VIEWGUIDES, wEditor.Call(SCI_GETINDENTATIONGUIDES));
CheckAMenuItem(IDM_LINENUMBERMARGIN, lineNumbers);
CheckAMenuItem(IDM_SELMARGIN, margin);
CheckAMenuItem(IDM_FOLDMARGIN, foldMargin);
CheckAMenuItem(IDM_TOGGLEOUTPUT, heightOutput > 0);
CheckAMenuItem(IDM_TOGGLEPARAMETERS, ParametersOpen());
CheckAMenuItem(IDM_MONOFONT, CurrentBuffer()->useMonoFont);
EnableAMenuItem(IDM_COMPILE, !jobQueue.IsExecuting() &&
props.GetWild("command.compile.", FileNameExt().AsUTF8().c_str()).size() != 0);
EnableAMenuItem(IDM_BUILD, !jobQueue.IsExecuting() &&
props.GetWild("command.build.", FileNameExt().AsUTF8().c_str()).size() != 0);
EnableAMenuItem(IDM_GO, !jobQueue.IsExecuting() &&
props.GetWild("command.go.", FileNameExt().AsUTF8().c_str()).size() != 0);
EnableAMenuItem(IDM_OPENDIRECTORYPROPERTIES, props.GetInt("properties.directory.enable") != 0);
for (int toolItem = 0; toolItem < toolMax; toolItem++)
EnableAMenuItem(IDM_TOOLS + toolItem, ToolIsImmediate(toolItem) || !jobQueue.IsExecuting());
EnableAMenuItem(IDM_STOPEXECUTE, jobQueue.IsExecuting());
if (buffers.size > 0) {
TabSelect(buffers.Current());
for (int bufferItem = 0; bufferItem < buffers.lengthVisible; bufferItem++) {
CheckAMenuItem(IDM_BUFFER + bufferItem, bufferItem == buffers.Current());
}
}
EnableAMenuItem(IDM_MACROPLAY, !recording);
EnableAMenuItem(IDM_MACRORECORD, !recording);
EnableAMenuItem(IDM_MACROSTOPRECORD, recording);
}
void SciTEBase::ContextMenu(GUI::ScintillaWindow &wSource, GUI::Point pt, GUI::Window wCmd) {
int currentPos = wSource.Call(SCI_GETCURRENTPOS);
int anchor = wSource.Call(SCI_GETANCHOR);
popup.CreatePopUp();
bool writable = !wSource.Call(SCI_GETREADONLY);
AddToPopUp("Undo", IDM_UNDO, writable && wSource.Call(SCI_CANUNDO));
AddToPopUp("Redo", IDM_REDO, writable && wSource.Call(SCI_CANREDO));
AddToPopUp("");
AddToPopUp("Cut", IDM_CUT, writable && currentPos != anchor);
AddToPopUp("Copy", IDM_COPY, currentPos != anchor);
AddToPopUp("Paste", IDM_PASTE, writable && wSource.Call(SCI_CANPASTE));
AddToPopUp("Delete", IDM_CLEAR, writable && currentPos != anchor);
AddToPopUp("");
AddToPopUp("Select All", IDM_SELECTALL);
AddToPopUp("");
if (wSource.GetID() == wOutput.GetID()) {
AddToPopUp("Hide", IDM_TOGGLEOUTPUT, true);
} else {
AddToPopUp("Close", IDM_CLOSE, true);
}
SString userContextMenu = props.GetNewExpand("user.context.menu");
userContextMenu.substitute('|', '\0');
const char *userContextItem = userContextMenu.c_str();
const char *endDefinition = userContextItem + userContextMenu.length();
while (userContextItem < endDefinition) {
const char *caption = userContextItem;
userContextItem += strlen(userContextItem) + 1;
if (userContextItem < endDefinition) {
int cmd = GetMenuCommandAsInt(userContextItem);
userContextItem += strlen(userContextItem) + 1;
AddToPopUp(caption, cmd);
}
}
popup.Show(pt, wCmd);
}
/**
* Ensure that a splitter bar position is inside the main window.
*/
int SciTEBase::NormaliseSplit(int splitPos) {
GUI::Rectangle rcClient = GetClientRectangle();
int w = rcClient.Width();
int h = rcClient.Height();
if (splitPos < 20)
splitPos = 0;
if (splitVertical) {
if (splitPos > w - heightBar - 20)
splitPos = w - heightBar;
} else {
if (splitPos > h - heightBar - 20)
splitPos = h - heightBar;
}
return splitPos;
}
void SciTEBase::MoveSplit(GUI::Point ptNewDrag) {
int newHeightOutput = heightOutputStartDrag + (ptStartDrag.y - ptNewDrag.y);
if (splitVertical)
newHeightOutput = heightOutputStartDrag + (ptStartDrag.x - ptNewDrag.x);
newHeightOutput = NormaliseSplit(newHeightOutput);
if (heightOutput != newHeightOutput) {
heightOutput = newHeightOutput;
SizeContentWindows();
//Redraw();
}
previousHeightOutput = newHeightOutput;
}
void SciTEBase::TimerStart(int /* mask */) {
}
void SciTEBase::TimerEnd(int /* mask */) {
}
void SciTEBase::OnTimer() {
if (delayBeforeAutoSave) {
// First save the visible buffer to avoid any switching if not needed
if (CurrentBuffer()->NeedsSave(delayBeforeAutoSave)) {
Save(sfNone);
}
// Then look through the other buffers to save any that need to be saved
int currentBuffer = buffers.Current();
for (int i = 0; i < buffers.length; i++) {
if (buffers.buffers[i].NeedsSave(delayBeforeAutoSave)) {
SetDocumentAt(i);
Save(sfNone);
}
}
SetDocumentAt(currentBuffer);
}
}
void SciTEBase::SetHomeProperties() {
FilePath homepath = GetSciteDefaultHome();
props.Set("SciteDefaultHome", homepath.AsUTF8().c_str());
homepath = GetSciteUserHome();
props.Set("SciteUserHome", homepath.AsUTF8().c_str());
}
void SciTEBase::UIAvailable() {
SetImportMenu();
if (extender) {
SetHomeProperties();
extender->Initialise(this);
}
}
/**
* Find the character following a name which is made up of characters from
* the set [a-zA-Z.]
*/
static GUI::gui_char AfterName(const GUI::gui_char *s) {
while (*s && ((*s == '.') ||
(*s >= 'a' && *s <= 'z') ||
(*s >= 'A' && *s <= 'Z')))
s++;
return *s;
}
void SciTEBase::PerformOne(char *action) {
unsigned int len = UnSlash(action);
char *arg = strchr(action, ':');
if (arg) {
arg++;
if (isprefix(action, "askfilename:")) {
extender->OnMacro("filename", filePath.AsUTF8().c_str());
} else if (isprefix(action, "askproperty:")) {
PropertyToDirector(arg);
} else if (isprefix(action, "close:")) {
Close();
WindowSetFocus(wEditor);
} else if (isprefix(action, "currentmacro:")) {
currentMacro = arg;
} else if (isprefix(action, "cwd:")) {
FilePath dirTarget(GUI::StringFromUTF8(arg));
if (!dirTarget.SetWorkingDirectory()) {
GUI::gui_string msg = LocaliseMessage("Invalid directory '^0'.", dirTarget.AsInternal());
WindowMessageBox(wSciTE, msg, MB_OK | MB_ICONWARNING);
}
} else if (isprefix(action, "enumproperties:")) {
EnumProperties(arg);
} else if (isprefix(action, "exportashtml:")) {
SaveToHTML(GUI::StringFromUTF8(arg));
} else if (isprefix(action, "exportasrtf:")) {
SaveToRTF(GUI::StringFromUTF8(arg));
} else if (isprefix(action, "exportaspdf:")) {
SaveToPDF(GUI::StringFromUTF8(arg));
} else if (isprefix(action, "exportaslatex:")) {
SaveToTEX(GUI::StringFromUTF8(arg));
} else if (isprefix(action, "exportasxml:")) {
SaveToXML(GUI::StringFromUTF8(arg));
} else if (isprefix(action, "find:") && wEditor.Created()) {
findWhat = arg;
FindNext(false, false);
} else if (isprefix(action, "goto:") && wEditor.Created()) {
int line = atoi(arg) - 1;
GotoLineEnsureVisible(line);
// jump to column if given and greater than 0
char *colstr = strchr(arg, ',');
if (colstr != NULL) {
int col = atoi(colstr + 1);
if (col > 0) {
int pos = wEditor.Call(SCI_GETCURRENTPOS) + col;
// select the word you have found there
int wordStart = wEditor.Call(SCI_WORDSTARTPOSITION, pos, true);
int wordEnd = wEditor.Call(SCI_WORDENDPOSITION, pos, true);
wEditor.Call(SCI_SETSEL, wordStart, wordEnd);
}
}
} else if (isprefix(action, "insert:") && wEditor.Created()) {
wEditor.CallString(SCI_REPLACESEL, 0, arg);
} else if (isprefix(action, "loadsession:")) {
if (*arg) {
LoadSessionFile(GUI::StringFromUTF8(arg).c_str());
RestoreSession();
}
} else if (isprefix(action, "macrocommand:")) {
ExecuteMacroCommand(arg);
} else if (isprefix(action, "macroenable:")) {
macrosEnabled = atoi(arg);
SetToolsMenu();
} else if (isprefix(action, "macrolist:")) {
StartMacroList(arg);
} else if (isprefix(action, "menucommand:")) {
MenuCommand(atoi(arg));
} else if (isprefix(action, "open:")) {
Open(GUI::StringFromUTF8(arg), ofSynchronous);
} else if (isprefix(action, "output:") && wOutput.Created()) {
wOutput.Call(SCI_REPLACESEL, 0, reinterpret_cast<sptr_t>(arg));
} else if (isprefix(action, "property:")) {
PropertyFromDirector(arg);
} else if (isprefix(action, "reloadproperties:")) {
ReloadProperties();
} else if (isprefix(action, "quit:")) {
QuitProgram();
} else if (isprefix(action, "replaceall:") && wEditor.Created()) {
if (len > strlen(action)) {
char *arg2 = arg + strlen(arg) + 1;
findWhat = arg;
replaceWhat = arg2;
ReplaceAll(false);
}
} else if (isprefix(action, "saveas:")) {
if (*arg) {
SaveAs(GUI::StringFromUTF8(arg).c_str(), true);
} else {
SaveAsDialog();
}
} else if (isprefix(action, "savesession:")) {
if (*arg) {
SaveSessionFile(GUI::StringFromUTF8(arg).c_str());
}
} else if (isprefix(action, "extender:")) {
extender->OnExecute(arg);
} else if (isprefix(action, "focus:")) {
ActivateWindow(arg);
}
}
}
static bool IsSwitchCharacter(GUI::gui_char ch) {
#ifdef __unix__
return ch == '-';
#else
return (ch == '-') || (ch == '/');
#endif
}
// Called by SciTEBase::PerformOne when action="enumproperties:"
void SciTEBase::EnumProperties(const char *propkind) {
PropSetFile *pf = NULL;
if (!extender)
return;
if (!strcmp(propkind, "dyn")) {
SelectionIntoProperties(); // Refresh properties ...
pf = &props;
} else if (!strcmp(propkind, "local"))
pf = &propsLocal;
else if (!strcmp(propkind, "directory"))
pf = &propsDirectory;
else if (!strcmp(propkind, "user"))
pf = &propsUser;
else if (!strcmp(propkind, "base"))
pf = &propsBase;
else if (!strcmp(propkind, "embed"))
pf = &propsEmbed;
else if (!strcmp(propkind, "abbrev"))
pf = &propsAbbrev;
if (pf != NULL) {
const char *key = NULL;
const char *val = NULL;
bool b = pf->GetFirst(key, val);
while (b) {
SendOneProperty(propkind, key, val);
b = pf->GetNext(key, val);
}
}
}
void SciTEBase::SendOneProperty(const char *kind, const char *key, const char *val) {
size_t keysize = strlen(kind) + 1 + strlen(key) + 1 + strlen(val) + 1;
char *m = new char[keysize];
strcpy(m, kind);
strcat(m, ":");
strcat(m, key);
strcat(m, "=");
strcat(m, val);
extender->SendProperty(m);
delete []m;
}
void SciTEBase::PropertyFromDirector(const char *arg) {
props.Set(arg);
}
void SciTEBase::PropertyToDirector(const char *arg) {
if (!extender)
return;
SelectionIntoProperties();
SString gotprop = props.Get(arg);
extender->OnMacro("macro:stringinfo", gotprop.c_str());
}
/**
* Menu/Toolbar command "Record".
*/
void SciTEBase::StartRecordMacro() {
recording = true;
CheckMenus();
wEditor.Call(SCI_STARTRECORD);
}
/**
* Received a SCN_MACRORECORD from Scintilla: send it to director.
*/
bool SciTEBase::RecordMacroCommand(SCNotification *notification) {
if (extender) {
char *szMessage;
char *t;
bool handled;
t = (char *)(notification->lParam);
SString sWParam(static_cast<size_t>(notification->wParam));
if (t != NULL) {
//format : "<message>;<wParam>;1;<text>"
szMessage = new char[50 + strlen(t) + 4];
sprintf(szMessage, "%d;%s;1;%s", notification->message, sWParam.c_str(), t);
} else {
//format : "<message>;<wParam>;0;"
szMessage = new char[50];
sprintf(szMessage, "%d;%s;0;", notification->message, sWParam.c_str());
}
handled = extender->OnMacro("macro:record", szMessage);
delete []szMessage;
return handled;
}
return true;
}
/**
* Menu/Toolbar command "Stop recording".
*/
void SciTEBase::StopRecordMacro() {
wEditor.Call(SCI_STOPRECORD);
if (extender)
extender->OnMacro("macro:stoprecord", "");
recording = false;
CheckMenus();
}
/**
* Menu/Toolbar command "Play macro...": tell director to build list of Macro names
* Through this call, user has access to all macros in Filerx.
*/
void SciTEBase::AskMacroList() {
if (extender)
extender->OnMacro("macro:getlist", "");
}
/**
* List of Macro names has been created. Ask Scintilla to show it.
*/
bool SciTEBase::StartMacroList(const char *words) {
if (words) {
wEditor.CallString(SCI_USERLISTSHOW, 2, words); //listtype=2
}
return true;
}
/**
* User has chosen a macro in the list. Ask director to execute it.
*/
void SciTEBase::ContinueMacroList(const char *stext) {
if ((extender) && (*stext != '\0')) {
currentMacro = stext;
StartPlayMacro();
}
}
/**
* Menu/Toolbar command "Play current macro" (or called from ContinueMacroList).
*/
void SciTEBase::StartPlayMacro() {
if (extender)
extender->OnMacro("macro:run", currentMacro.c_str());
}
/*
SciTE received a macro command from director : execute it.
If command needs answer (SCI_GETTEXTLENGTH ...) : give answer to director
*/
static unsigned int ReadNum(const char *&t) {
const char *argend = strchr(t, ';'); // find ';'
unsigned int v = 0;
if (*t)
v = atoi(t); // read value
t = argend + 1; // update pointer
return v; // return value
}
void SciTEBase::ExecuteMacroCommand(const char *command) {
const char *nextarg = command;
uptr_t wParam;
sptr_t lParam = 0;
int rep = 0; //Scintilla's answer
const char *answercmd;
int l;
char *string1 = NULL;
char params[4];
//params describe types of return values and of arguments
//0 : void or no param
//I : integer
//S : string
//R : return string (for lParam only)
//extract message,wParam ,lParam
unsigned int message = ReadNum(nextarg);
strncpy(params, nextarg, 3);
params[3] = '\0';
nextarg += 4;
if (*(params + 1) == 'R') {
// in one function wParam is a string : void SetProperty(string key,string name)
const char *s1 = nextarg;
while (*nextarg != ';')
nextarg++;
size_t lstring1 = nextarg - s1;
string1 = new char[lstring1 + 1];
if (lstring1 > 0)
strncpy(string1, s1, lstring1);
*(string1 + lstring1) = '\0';
wParam = reinterpret_cast<uptr_t>(string1);
nextarg++;
} else {
wParam = ReadNum(nextarg);
}
if (*(params + 2) == 'S')
lParam = reinterpret_cast<sptr_t>(nextarg);
else if (*(params + 2) == 'I')
lParam = atoi(nextarg);
if (*params == '0') {
// no answer ...
wEditor.Call(message, wParam, lParam);
delete []string1;
return;
}
if (*params == 'S') {
// string answer
if (message == SCI_GETSELTEXT) {
l = wEditor.Call(SCI_GETSELTEXT, 0, 0);
wParam = 0;
} else if (message == SCI_GETCURLINE) {
int line = wEditor.Call(SCI_LINEFROMPOSITION, wEditor.Call(SCI_GETCURRENTPOS));
l = wEditor.Call(SCI_LINELENGTH, line);
wParam = l;
} else if (message == SCI_GETTEXT) {
l = wEditor.Call(SCI_GETLENGTH);
wParam = l;
} else if (message == SCI_GETLINE) {
l = wEditor.Call(SCI_LINELENGTH, wParam);
} else {
l = 0; //unsupported calls EM
}
answercmd = "stringinfo:";
} else {
//int answer
answercmd = "intinfo:";
l = 30;
}
size_t alen = strlen(answercmd);
char *tbuff = new char[l + alen + 1];
strcpy(tbuff, answercmd);
if (*params == 'S')
lParam = reinterpret_cast<sptr_t>(tbuff + alen);
if (l > 0)
rep = wEditor.Call(message, wParam, lParam);
if (*params == 'I')
sprintf(tbuff + alen, "%0d", rep);
extender->OnMacro("macro", tbuff);
delete []tbuff;
}
/**
* Process all the command line arguments.
* Arguments that start with '-' (also '/' on Windows) are switches or commands with
* other arguments being file names which are opened. Commands are distinguished
* from switches by containing a ':' after the command name.
* The print switch /p is special cased.
* Processing occurs in two phases to allow switches that occur before any file opens
* to be evaluated before creating the UI.
* Call twice, first with phase=0, then with phase=1 after creating UI.
*/
bool SciTEBase::ProcessCommandLine(GUI::gui_string &args, int phase) {
bool performPrint = false;
bool evaluate = phase == 0;
std::vector<GUI::gui_string> wlArgs = ListFromString(args);
// Convert args to vector
for (size_t i = 0; i < wlArgs.size(); i++) {
const GUI::gui_char *arg = wlArgs[i].c_str();
if (IsSwitchCharacter(arg[0])) {
arg++;
if (arg[0] == '\0' || (arg[0] == '-' && arg[1] == '\0')) {
if (phase == 1) {
OpenFromStdin(arg[0] == '-');
}
} else if (arg[0] == '@') {
if (phase == 1) {
OpenFilesFromStdin();
}
} else if ((tolower(arg[0]) == 'p') && (arg[1] == 0)) {
performPrint = true;
} else if (GUI::gui_string(arg) == GUI_TEXT("grep") && (wlArgs.size() - i >= 4)) {
// in form -grep [w~][c~][d~][b~] "<file-patterns>" "<search-string>"
GrepFlags gf = grepStdOut;
if (wlArgs[i+1][0] == 'w')
gf = static_cast<GrepFlags>(gf | grepWholeWord);
if (wlArgs[i+1][1] == 'c')
gf = static_cast<GrepFlags>(gf | grepMatchCase);
if (wlArgs[i+1][2] == 'd')
gf = static_cast<GrepFlags>(gf | grepDot);
if (wlArgs[i+1][3] == 'b')
gf = static_cast<GrepFlags>(gf | grepBinary);
char unquoted[1000];
strcpy(unquoted, GUI::UTF8FromString(wlArgs[i+3].c_str()).c_str());
UnSlash(unquoted);
sptr_t originalEnd = 0;
InternalGrep(gf, FilePath::GetWorkingDirectory().AsInternal(), wlArgs[i+2].c_str(), unquoted, originalEnd);
exit(0);
} else {
if (AfterName(arg) == ':') {
if (StartsWith(arg, GUI_TEXT("open:")) || StartsWith(arg, GUI_TEXT("loadsession:"))) {
if (phase == 0)
return performPrint;
else
evaluate = true;
}
if (evaluate) {
const std::string sArg = GUI::UTF8FromString(arg);
std::vector<char> vcArg(sArg.size() + 1);
std::copy(sArg.begin(), sArg.end(), vcArg.begin());
PerformOne(&vcArg[0]);
}
} else {
if (evaluate) {
props.ReadLine(GUI::UTF8FromString(arg).c_str(), true, FilePath::GetWorkingDirectory(), filter);
}
}
}
} else { // Not a switch: it is a file name
if (phase == 0)
return performPrint;
else
evaluate = true;
if (!buffers.initialised) {
InitialiseBuffers();
if (props.GetInt("save.recent"))
RestoreRecentMenu();
}
if (!PreOpenCheck(arg))
Open(arg, static_cast<OpenFlags>(ofQuiet|ofSynchronous));
}
}
if (phase == 1) {
// If we have finished with all args and no buffer is open
// try to load session.
if (!buffers.initialised) {
InitialiseBuffers();
if (props.GetInt("save.recent"))
RestoreRecentMenu();
if (props.GetInt("buffers") && props.GetInt("save.session"))
RestoreSession();
}
// No open file after session load so create empty document.
if (filePath.IsUntitled() && buffers.length == 1 && !buffers.buffers[0].isDirty) {
Open(GUI_TEXT(""));
}
}
return performPrint;
}
// Implement ExtensionAPI methods
sptr_t SciTEBase::Send(Pane p, unsigned int msg, uptr_t wParam, sptr_t lParam) {
if (p == paneEditor)
return wEditor.Call(msg, wParam, lParam);
else
return wOutput.Call(msg, wParam, lParam);
}
char *SciTEBase::Range(Pane p, int start, int end) {
int len = end - start;
char *s = new char[len + 1];
if (p == paneEditor)
GetRange(wEditor, start, end, s);
else
GetRange(wOutput, start, end, s);
return s;
}
void SciTEBase::Remove(Pane p, int start, int end) {
if (p == paneEditor) {
wEditor.Call(SCI_DELETERANGE, start, end-start);
} else {
wOutput.Call(SCI_DELETERANGE, start, end-start);
}
}
void SciTEBase::Insert(Pane p, int pos, const char *s) {
if (p == paneEditor)
wEditor.CallString(SCI_INSERTTEXT, pos, s);
else
wOutput.CallString(SCI_INSERTTEXT, pos, s);
}
void SciTEBase::Trace(const char *s) {
MakeOutputVisible();
OutputAppendStringSynchronised(s);
}
char *SciTEBase::Property(const char *key) {
SString value = props.GetExpanded(key);
char *retval = new char[value.length() + 1];
strcpy(retval, value.c_str());
return retval;
}
void SciTEBase::SetProperty(const char *key, const char *val) {
SString value = props.GetExpanded(key);
if (value != val) {
props.Set(key, val);
needReadProperties = true;
}
}
void SciTEBase::UnsetProperty(const char *key) {
props.Unset(key);
needReadProperties = true;
}
uptr_t SciTEBase::GetInstance() {
return 0;
}
void SciTEBase::ShutDown() {
QuitProgram();
}
void SciTEBase::Perform(const char *actionList) {
char *actionsDup = StringDup(actionList);
char *actions = actionsDup;
char *nextAct;
while ((nextAct = strchr(actions, '\n')) != NULL) {
*nextAct = '\0';
PerformOne(actions);
actions = nextAct + 1;
}
PerformOne(actions);
delete []actionsDup;
}
void SciTEBase::DoMenuCommand(int cmdID) {
MenuCommand(cmdID, 0);
}