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 4781 4782 4783 4784 4785 4786 4787 4788 4789 4790 4791 4792 4793 4794 4795 4796 4797 4798 4799 4800 4801 4802 4803 4804 4805 4806 4807 4808 4809 4810 4811 4812 4813 4814 4815 4816 4817 4818 4819 4820 4821 4822 4823 4824 4825 4826 4827 4828 4829 4830 4831 4832 4833 4834 4835 4836 4837 4838 4839 4840 4841 4842 4843 4844 4845 4846 4847 4848 4849 4850 4851 4852 4853 4854 4855 4856 4857 4858 4859 4860 4861 4862 4863 4864 4865 4866 4867 4868 4869 4870 4871 4872 4873 4874 4875 4876 4877 4878 4879 4880 4881 4882 4883 4884 4885 4886 4887 4888 4889 4890 4891 4892 4893 4894 4895 4896 4897 4898 4899 4900 4901 4902 4903 4904 4905 4906 4907 4908 4909 4910 4911 4912 4913 4914 4915 4916 4917 4918 4919 4920 4921 4922 4923 4924 4925 4926 4927 4928 4929 4930 4931 4932 4933 4934 4935 4936 4937 4938 4939 4940 4941 4942 4943 4944 4945 4946 4947 4948 4949 4950 4951 4952 4953 4954 4955 4956 4957 4958 4959 4960 4961 4962 4963 4964 4965 4966 4967 4968 4969 4970 4971 4972 4973 4974 4975 4976 4977 4978 4979 4980 4981 4982 4983 4984 4985 4986 4987 4988 4989 4990 4991 4992 4993 4994 4995 4996 4997 4998 4999 5000 5001 5002 5003 5004 5005 5006 5007 5008 5009 5010 5011 5012 5013 5014 5015 5016 5017 5018 5019 5020 5021 5022 5023 5024 5025 5026 5027 5028 5029 5030 5031 5032 5033 5034 5035 5036 5037 5038 5039 5040 5041 5042 5043 5044 5045 5046 5047 5048 5049 5050 5051 5052 5053 5054 5055 5056 5057 5058 5059 5060 5061 5062 5063 5064 5065 5066 5067 5068 5069 5070 5071 5072 5073 5074 5075 5076 5077 5078 5079 5080 5081 5082 5083 5084 5085 5086 5087 5088 5089 5090 5091 5092 5093 5094 5095 5096 5097 5098 5099 5100 5101 5102 5103 5104 5105 5106 5107 5108 5109 5110 5111 5112 5113 5114 5115 5116 5117 5118 5119 5120 5121 5122 5123 5124 5125 5126 5127 5128 5129 5130 5131 5132 5133 5134 5135 5136 5137 5138 5139 5140 5141 5142 5143 5144 5145 5146 5147 5148 5149 5150 5151 5152 5153 5154 5155 5156 5157 5158 5159 5160 5161 5162 5163 5164 5165 5166 5167 5168 5169 5170 5171 5172 5173 5174 5175 5176 5177 5178 5179 5180 5181 5182 5183 5184 5185 5186 5187 5188 5189 5190 5191 5192 5193 5194 5195 5196 5197 5198 5199 5200 5201 5202 5203 5204 5205 5206 5207 5208 5209 5210 5211 5212 5213 5214 5215 5216 5217 5218 5219 5220 5221 5222 5223 5224 5225 5226 5227 5228 5229 5230 5231 5232 5233 5234 5235 5236 5237 5238 5239 5240 5241 5242 5243 5244 5245 5246 5247 5248 5249 5250 5251 5252 5253 5254 5255 5256 5257 5258 5259 5260 5261 5262 5263 5264 5265 5266 5267 5268 5269 5270 5271 5272 5273 5274 5275 5276 5277 5278 5279 5280 5281 5282 5283 5284 5285 5286 5287 5288 5289 5290 5291 5292 5293 5294 5295 5296 5297 5298 5299 5300 5301 5302 5303 5304 5305 5306 5307 5308 5309 5310 5311 5312 5313 5314 5315 5316 5317 5318 5319 5320 5321 5322 5323 5324 5325 5326 5327 5328 5329 5330 5331 5332 5333 5334 5335 5336 5337 5338 5339 5340 5341 5342 5343 5344 5345 5346 5347 5348 5349 5350 5351 5352 5353 5354 5355 5356 5357 5358 5359 5360 5361 5362 5363 5364 5365 5366 5367 5368 5369 5370 5371 5372 5373 5374 5375 5376 5377 5378 5379 5380 5381 5382 5383 5384 5385 5386 5387 5388 5389 5390 5391 5392 5393 5394 5395 5396 5397 5398 5399 5400 5401 5402 5403 5404 5405 5406 5407 5408 5409 5410 5411 5412 5413 5414 5415 5416 5417 5418 5419 5420 5421 5422 5423 5424 5425 5426 5427 5428 5429 5430 5431 5432 5433 5434 5435 5436 5437 5438 5439 5440 5441 5442 5443 5444 5445 5446 5447 5448 5449 5450 5451 5452 5453 5454 5455 5456 5457 5458 5459 5460 5461 5462 5463 5464 5465 5466 5467 5468 5469 5470 5471 5472 5473 5474 5475 5476 5477 5478 5479 5480 5481 5482 5483 5484 5485 5486 5487 5488 5489 5490 5491 5492 5493 5494 5495 5496 5497 5498 5499 5500 5501 5502 5503 5504 5505 5506 5507 5508 5509 5510 5511 5512 5513 5514 5515 5516 5517 5518 5519 5520 5521 5522 5523 5524 5525 5526 5527 5528 5529 5530 5531 5532 5533 5534 5535 5536 5537 5538 5539 5540 5541 5542 5543 5544 5545 5546 5547 5548 5549 5550 5551 5552 5553 5554 5555 5556 5557 5558 5559 5560 5561 5562 5563 5564 5565 5566 5567 5568 5569 5570 5571 5572 5573 5574 5575 5576 5577 5578 5579 5580 5581 5582 5583 5584 5585 5586 5587 5588 5589 5590 5591 5592 5593 5594 5595 5596 5597 5598 5599 5600 5601 5602 5603 5604 5605 5606 5607 5608 5609 5610 5611 5612 5613 5614 5615 5616 5617 5618 5619 5620 5621 5622 5623 5624 5625 5626 5627 5628 5629 5630 5631 5632 5633 5634 5635 5636 5637 5638 5639 5640 5641 5642 5643 5644 5645 5646 5647 5648 5649 5650 5651 5652 5653 5654 5655 5656 5657 5658 5659 5660 5661 5662 5663 5664 5665 5666 5667 5668 5669 5670 5671 5672 5673 5674 5675 5676 5677 5678 5679 5680 5681 5682 5683 5684 5685 5686 5687 5688 5689 5690 5691 5692 5693 5694 5695 5696 5697 5698 5699 5700 5701 5702 5703 5704 5705 5706 5707 5708 5709 5710 5711 5712 5713 5714 5715 5716 5717 5718 5719 5720 5721 5722 5723 5724 5725 5726 5727 5728 5729 5730 5731 5732 5733 5734 5735 5736 5737 5738 5739 5740 5741 5742 5743 5744 5745 5746 5747 5748 5749 5750 5751 5752 5753 5754 5755 5756 5757 5758 5759 5760 5761 5762 5763 5764 5765 5766 5767 5768 5769 5770 5771 5772 5773 5774 5775 5776 5777 5778 5779 5780 5781 5782 5783 5784 5785 5786 5787 5788 5789 5790 5791 5792 5793 5794 5795 5796 5797 5798 5799 5800 5801 5802 5803 5804 5805 5806 5807 5808 5809 5810 5811 5812 5813 5814 5815 5816 5817 5818 5819 5820 5821 5822 5823 5824 5825 5826 5827 5828 5829 5830 5831 5832 5833 5834 5835 5836 5837 5838 5839 5840 5841 5842 5843 5844 5845 5846 5847 5848 5849 5850 5851 5852 5853 5854 5855 5856 5857 5858 5859 5860 5861 5862 5863 5864 5865 5866 5867 5868 5869 5870 5871 5872 5873 5874 5875 5876 5877 5878 5879 5880 5881 5882 5883 5884 5885 5886 5887 5888 5889 5890 5891 5892 5893 5894 5895 5896 5897 5898 5899 5900 5901 5902 5903 5904 5905 5906 5907 5908 5909 5910 5911 5912 5913 5914 5915 5916 5917 5918 5919 5920 5921 5922 5923 5924 5925 5926 5927 5928 5929 5930 5931 5932 5933 5934 5935 5936 5937 5938 5939 5940 5941 5942 5943 5944 5945 5946 5947 5948 5949 5950 5951 5952 5953 5954 5955 5956 5957 5958 5959 5960 5961 5962 5963 5964 5965 5966 5967 5968 5969 5970 5971 5972 5973 5974 5975 5976 5977 5978 5979 5980 5981 5982 5983 5984 5985 5986 5987 5988 5989 5990 5991 5992 5993 5994 5995 5996 5997 5998 5999 6000 6001 6002 6003 6004 6005 6006 6007 6008 6009 6010 6011 6012 6013 6014 6015 6016 6017 6018 6019 6020 6021 6022 6023 6024 6025 6026 6027 6028 6029 6030 6031 6032 6033 6034 6035 6036 6037 6038 6039 6040 6041 6042 6043 6044 6045 6046 6047 6048 6049 6050 6051 6052 6053 6054 6055 6056 6057 6058 6059 6060 6061 6062 6063 6064 6065 6066 6067 6068 6069 6070 6071 6072 6073 6074 6075 6076 6077 6078 6079 6080 6081 6082 6083 6084 6085 6086 6087 6088 6089 6090 6091 6092 6093 6094 6095 6096 6097 6098 6099 6100 6101 6102 6103 6104 6105 6106 6107 6108 6109 6110 6111 6112 6113 6114 6115 6116 6117 6118 6119 6120 6121 6122 6123 6124 6125 6126 6127 6128 6129 6130 6131 6132 6133 6134 6135 6136 6137 6138 6139 6140 6141 6142 6143 6144 6145 6146 6147 6148 6149 6150 6151 6152 6153 6154 6155 6156 6157 6158 6159 6160 6161 6162 6163 6164 6165 6166 6167 6168 6169 6170 6171 6172 6173 6174 6175 6176 6177 6178 6179 6180 6181 6182 6183 6184 6185 6186 6187 6188 6189 6190 6191 6192 6193 6194 6195 6196 6197 6198 6199 6200 6201 6202 6203 6204 6205 6206 6207 6208 6209 6210 6211 6212 6213 6214 6215 6216 6217 6218 6219 6220 6221 6222 6223 6224 6225 6226 6227 6228 6229 6230 6231 6232 6233 6234 6235 6236 6237 6238 6239 6240 6241 6242 6243 6244 6245 6246 6247 6248 6249 6250 6251 6252 6253 6254 6255 6256 6257 6258 6259 6260 6261 6262 6263 6264 6265 6266 6267 6268 6269 6270 6271 6272 6273 6274 6275 6276 6277 6278 6279 6280 6281 6282 6283 6284 6285 6286 6287 6288 6289 6290 6291 6292 6293 6294 6295 6296 6297 6298 6299 6300 6301 6302 6303 6304 6305 6306 6307 6308 6309 6310 6311 6312 6313 6314 6315 6316 6317 6318 6319 6320 6321 6322 6323 6324 6325 6326 6327 6328 6329 6330 6331 6332 6333 6334 6335 6336 6337 6338 6339 6340 6341 6342 6343 6344 6345 6346 6347 6348 6349 6350 6351 6352 6353 6354 6355 6356 6357 6358 6359 6360 6361 6362 6363 6364 6365 6366 6367 6368 6369 6370 6371 6372 6373 6374 6375 6376 6377 6378 6379 6380 6381 6382 6383 6384 6385 6386 6387 6388 6389 6390 6391 6392 6393 6394 6395 6396 6397 6398 6399 6400 6401 6402 6403 6404 6405 6406 6407 6408 6409 6410 6411 6412 6413 6414 6415 6416 6417 6418 6419 6420 6421 6422 6423 6424 6425 6426 6427 6428 6429 6430 6431 6432 6433 6434 6435 6436 6437 6438 6439 6440 6441 6442 6443 6444 6445 6446 6447 6448 6449 6450 6451 6452 6453 6454 6455 6456 6457 6458 6459 6460 6461 6462 6463 6464 6465 6466 6467 6468 6469 6470 6471 6472 6473 6474 6475 6476 6477 6478 6479 6480 6481 6482 6483 6484 6485 6486 6487 6488 6489 6490 6491 6492 6493 6494 6495 6496 6497 6498 6499 6500 6501 6502 6503 6504 6505 6506 6507 6508 6509 6510 6511 6512 6513 6514 6515 6516 6517 6518 6519 6520 6521 6522 6523 6524 6525 6526 6527 6528 6529 6530 6531 6532 6533 6534 6535 6536 6537 6538 6539 6540 6541 6542 6543 6544 6545 6546 6547 6548 6549 6550 6551 6552 6553 6554 6555 6556 6557 6558 6559 6560 6561 6562 6563 6564 6565 6566 6567 6568 6569 6570 6571 6572 6573 6574 6575 6576 6577 6578 6579 6580 6581 6582 6583 6584 6585 6586 6587 6588 6589 6590 6591 6592 6593 6594 6595 6596 6597 6598 6599 6600 6601 6602 6603 6604 6605 6606 6607 6608 6609 6610 6611 6612 6613 6614 6615 6616 6617 6618 6619 6620 6621 6622 6623 6624 6625 6626 6627 6628 6629 6630 6631 6632 6633 6634 6635 6636 6637 6638 6639 6640 6641 6642 6643 6644 6645 6646 6647 6648 6649 6650 6651 6652 6653 6654 6655 6656 6657 6658 6659 6660 6661 6662 6663 6664 6665 6666 6667 6668 6669 6670 6671 6672 6673 6674 6675 6676 6677 6678 6679 6680 6681 6682 6683 6684 6685 6686 6687 6688 6689 6690 6691 6692 6693 6694 6695 6696 6697 6698 6699 6700 6701 6702 6703 6704 6705 6706 6707 6708 6709 6710 6711 6712 6713 6714 6715 6716 6717 6718 6719 6720 6721 6722 6723 6724 6725 6726 6727 6728 6729 6730 6731 6732 6733 6734 6735 6736 6737 6738 6739 6740 6741 6742 6743 6744 6745 6746 6747 6748 6749 6750 6751 6752 6753 6754 6755 6756 6757 6758 6759 6760 6761 6762 6763 6764 6765 6766 6767 6768 6769 6770 6771 6772 6773 6774 6775 6776 6777 6778 6779 6780 6781 6782 6783 6784 6785 6786 6787 6788 6789 6790 6791 6792 6793 6794 6795 6796 6797 6798 6799 6800 6801 6802 6803 6804 6805 6806 6807 6808 6809 6810 6811 6812 6813 6814 6815 6816 6817 6818 6819 6820 6821 6822 6823 6824 6825 6826 6827 6828 6829 6830 6831 6832 6833 6834 6835 6836 6837 6838 6839 6840 6841 6842 6843 6844 6845 6846 6847 6848 6849 6850 6851 6852 6853 6854 6855 6856 6857 6858 6859 6860 6861 6862 6863 6864 6865 6866 6867 6868 6869 6870 6871 6872 6873 6874 6875 6876 6877 6878 6879 6880 6881 6882 6883 6884 6885 6886 6887 6888 6889 6890 6891 6892 6893 6894 6895 6896 6897 6898 6899 6900 6901 6902 6903 6904 6905 6906 6907 6908 6909 6910 6911 6912 6913 6914 6915 6916 6917 6918 6919 6920 6921 6922 6923 6924 6925 6926 6927 6928 6929 6930 6931 6932 6933 6934 6935 6936 6937 6938 6939 6940 6941 6942 6943 6944 6945 6946 6947 6948 6949 6950 6951 6952 6953 6954 6955 6956 6957 6958 6959 6960 6961 6962 6963 6964 6965 6966 6967 6968 6969 6970 6971 6972 6973 6974 6975 6976 6977 6978 6979 6980 6981 6982 6983 6984 6985 6986 6987 6988 6989 6990 6991 6992 6993 6994 6995 6996 6997 6998 6999 7000 7001 7002 7003 7004 7005 7006 7007 7008 7009 7010 7011 7012 7013 7014 7015 7016 7017 7018 7019 7020 7021 7022 7023 7024 7025 7026 7027 7028 7029 7030 7031 7032 7033 7034 7035 7036 7037 7038 7039 7040 7041 7042 7043 7044 7045 7046 7047 7048 7049 7050 7051 7052 7053 7054 7055 7056 7057 7058 7059 7060 7061 7062 7063 7064 7065 7066 7067 7068 7069 7070 7071 7072 7073 7074 7075 7076 7077 7078 7079 7080 7081 7082 7083 7084 7085 7086 7087 7088 7089 7090 7091 7092 7093 7094 7095 7096 7097 7098 7099 7100 7101 7102 7103 7104 7105 7106 7107 7108 7109 7110 7111 7112 7113 7114 7115 7116 7117 7118 7119 7120 7121 7122 7123 7124 7125 7126 7127 7128 7129 7130 7131 7132 7133 7134 7135 7136 7137 7138 7139 7140 7141 7142 7143 7144 7145 7146 7147 7148 7149 7150 7151 7152 7153 7154 7155 7156 7157 7158 7159 7160 7161 7162 7163 7164 7165 7166 7167 7168 7169 7170 7171 7172 7173 7174 7175 7176 7177 7178 7179 7180 7181 7182 7183 7184 7185 7186 7187 7188 7189 7190 7191 7192 7193 7194 7195 7196 7197 7198 7199 7200 7201 7202 7203 7204 7205 7206 7207 7208 7209 7210 7211 7212 7213 7214 7215 7216 7217 7218 7219 7220 7221 7222 7223 7224 7225 7226 7227 7228 7229 7230 7231 7232 7233 7234 7235 7236 7237 7238 7239 7240 7241 7242 7243 7244 7245 7246 7247 7248 7249 7250 7251 7252 7253 7254 7255 7256 7257 7258 7259 7260 7261 7262 7263 7264 7265 7266 7267 7268 7269 7270 7271 7272 7273 7274 7275 7276 7277 7278 7279 7280 7281 7282 7283 7284 7285 7286 7287 7288 7289 7290 7291 7292 7293 7294 7295 7296 7297 7298 7299 7300 7301 7302 7303 7304 7305 7306 7307 7308 7309 7310 7311 7312 7313 7314 7315 7316 7317 7318 7319 7320 7321 7322 7323 7324 7325 7326 7327 7328 7329 7330 7331 7332 7333 7334 7335 7336 7337 7338 7339 7340 7341 7342 7343 7344 7345 7346 7347 7348 7349 7350 7351 7352 7353 7354 7355 7356 7357 7358 7359 7360 7361 7362 7363 7364 7365 7366 7367 7368 7369 7370 7371 7372 7373 7374 7375 7376 7377 7378 7379 7380 7381 7382 7383 7384 7385 7386 7387 7388 7389 7390 7391 7392 7393 7394 7395 7396 7397 7398 7399 7400 7401 7402 7403 7404 7405 7406 7407 7408 7409 7410 7411 7412 7413 7414 7415 7416 7417 7418 7419 7420 7421 7422 7423 7424 7425 7426 7427 7428 7429 7430 7431 7432 7433 7434 7435 7436 7437 7438 7439 7440 7441 7442 7443 7444 7445 7446 7447 7448 7449 7450 7451 7452 7453 7454 7455 7456 7457 7458 7459 7460 7461 7462 7463 7464 7465 7466 7467 7468 7469 7470 7471 7472 7473 7474 7475 7476 7477 7478 7479 7480 7481 7482 7483 7484 7485 7486 7487 7488 7489 7490 7491 7492 7493 7494 7495 7496 7497 7498 7499 7500 7501 7502 7503 7504 7505 7506 7507 7508 7509 7510 7511 7512 7513 7514 7515 7516 7517 7518 7519 7520 7521 7522 7523 7524 7525 7526 7527 7528 7529 7530 7531 7532 7533 7534 7535 7536 7537 7538 7539 7540 7541 7542 7543 7544 7545 7546 7547 7548 7549 7550 7551 7552 7553 7554 7555 7556 7557 7558 7559 7560 7561 7562 7563 7564 7565 7566 7567 7568 7569 7570 7571 7572 7573 7574 7575 7576 7577 7578 7579 7580 7581 7582 7583 7584 7585 7586 7587 7588 7589 7590 7591 7592 7593 7594 7595 7596 7597 7598 7599 7600 7601 7602 7603 7604 7605 7606 7607 7608 7609 7610 7611 7612 7613 7614 7615 7616 7617 7618 7619 7620 7621 7622 7623 7624 7625 7626 7627 7628 7629 7630 7631 7632 7633 7634 7635 7636 7637 7638 7639 7640 7641 7642 7643 7644 7645 7646 7647 7648 7649 7650 7651 7652 7653 7654 7655 7656 7657 7658 7659 7660 7661 7662 7663 7664 7665 7666 7667 7668 7669 7670 7671 7672 7673 7674 7675 7676 7677 7678 7679 7680 7681 7682 7683 7684 7685 7686 7687 7688 7689 7690 7691 7692 7693 7694 7695 7696 7697 7698 7699 7700 7701 7702 7703 7704 7705 7706 7707 7708 7709 7710 7711 7712 7713 7714 7715 7716 7717 7718 7719 7720 7721 7722 7723 7724 7725 7726 7727 7728 7729 7730 7731 7732 7733 7734 7735 7736 7737 7738 7739 7740 7741 7742 7743 7744 7745 7746 7747 7748 7749 7750 7751 7752 7753 7754 7755 7756 7757 7758 7759 7760 7761 7762 7763 7764 7765 7766 7767 7768 7769 7770 7771 7772 7773 7774 7775 7776 7777 7778 7779 7780 7781 7782 7783 7784 7785 7786 7787 7788 7789 7790 7791 7792 7793 7794 7795 7796 7797 7798 7799 7800 7801 7802 7803 7804 7805 7806 7807 7808 7809 7810 7811 7812 7813 7814 7815 7816 7817 7818 7819 7820 7821 7822 7823 7824 7825 7826 7827 7828 7829 7830 7831 7832 7833 7834 7835 7836 7837 7838 7839 7840 7841 7842 7843 7844 7845 7846 7847 7848 7849 7850 7851 7852 7853 7854 7855 7856 7857 7858 7859 7860 7861 7862 7863 7864 7865 7866 7867 7868 7869 7870 7871 7872 7873 7874 7875 7876 7877 7878 7879 7880 7881 7882 7883 7884 7885 7886 7887 7888 7889 7890 7891 7892 7893 7894 7895 7896 7897 7898 7899 7900 7901 7902 7903 7904 7905 7906 7907 7908 7909 7910 7911 7912 7913 7914 7915 7916 7917 7918 7919 7920 7921 7922 7923 7924 7925 7926 7927 7928 7929 7930 7931 7932 7933 7934 7935 7936 7937 7938 7939 7940 7941 7942 7943 7944 7945 7946 7947 7948 7949 7950 7951 7952 7953 7954 7955 7956 7957 7958 7959 7960 7961 7962 7963 7964 7965 7966 7967 7968 7969 7970 7971 7972 7973 7974 7975 7976 7977 7978 7979 7980 7981 7982 7983 7984 7985 7986 7987 7988 7989 7990 7991 7992 7993 7994 7995 7996 7997 7998 7999 8000 8001 8002 8003 8004 8005 8006 8007 8008 8009 8010 8011 8012 8013 8014 8015 8016 8017 8018 8019 8020 8021 8022 8023 8024 8025 8026 8027 8028 8029 8030 8031 8032 8033 8034 8035 8036 8037 8038 8039 8040 8041 8042 8043 8044 8045 8046 8047 8048 8049 8050 8051 8052 8053 8054 8055 8056 8057 8058 8059 8060 8061 8062 8063 8064 8065 8066 8067 8068 8069 8070 8071 8072 8073 8074 8075 8076 8077 8078 8079 8080 8081 8082 8083 8084 8085 8086 8087 8088 8089 8090 8091 8092 8093 8094 8095 8096 8097 8098 8099 8100 8101 8102 8103 8104 8105 8106 8107 8108 8109 8110 8111 8112 8113 8114 8115 8116 8117 8118 8119 8120 8121 8122 8123 8124 8125 8126 8127 8128 8129 8130 8131 8132 8133 8134 8135 8136 8137 8138 8139 8140 8141 8142 8143 8144 8145 8146 8147 8148 8149 8150 8151 8152 8153 8154 8155 8156 8157 8158 8159 8160 8161 8162 8163 8164 8165 8166 8167 8168 8169 8170 8171 8172 8173 8174 8175 8176 8177 8178 8179 8180 8181 8182 8183 8184 8185 8186 8187 8188 8189 8190 8191 8192 8193 8194 8195 8196 8197 8198 8199 8200 8201 8202 8203 8204 8205 8206 8207 8208 8209 8210 8211 8212 8213 8214 8215 8216 8217 8218 8219 8220 8221 8222 8223 8224 8225 8226 8227 8228 8229 8230 8231 8232 8233 8234 8235 8236 8237 8238 8239 8240 8241 8242 8243 8244 8245 8246 8247 8248 8249 8250 8251 8252 8253 8254 8255 8256 8257 8258 8259 8260 8261 8262 8263 8264 8265 8266 8267 8268 8269 8270 8271 8272 8273 8274 8275 8276 8277 8278 8279 8280 8281 8282 8283 8284 8285 8286 8287 8288 8289 8290 8291 8292 8293 8294 8295 8296 8297 8298 8299 8300 8301 8302 8303 8304 8305 8306 8307 8308 8309 8310 8311 8312 8313 8314 8315 8316 8317 8318 8319 8320 8321 8322 8323 8324 8325 8326 8327 8328 8329 8330 8331 8332 8333 8334 8335 8336 8337 8338 8339 8340 8341 8342 8343 8344 8345 8346 8347 8348 8349 8350 8351 8352 8353 8354 8355 8356 8357 8358 8359 8360 8361 8362 8363 8364 8365 8366 8367 8368 8369 8370 8371 8372 8373 8374 8375 8376 8377 8378 8379 8380 8381 8382 8383 8384 8385 8386 8387 8388 8389 8390 8391 8392 8393 8394 8395 8396 8397 8398 8399 8400 8401 8402 8403 8404 8405 8406 8407 8408 8409 8410 8411 8412 8413 8414 8415 8416 8417 8418 8419 8420 8421 8422 8423 8424 8425 8426 8427 8428 8429 8430 8431 8432 8433 8434 8435 8436 8437 8438 8439 8440 8441 8442 8443 8444 8445 8446 8447 8448 8449 8450 8451 8452 8453 8454 8455 8456 8457 8458 8459 8460 8461 8462 8463 8464 8465 8466 8467 8468 8469 8470 8471 8472 8473 8474 8475 8476 8477 8478 8479 8480 8481 8482 8483 8484 8485 8486 8487 8488 8489 8490 8491 8492 8493 8494 8495 8496 8497 8498 8499 8500 8501 8502 8503 8504 8505 8506 8507 8508 8509 8510 8511 8512 8513 8514 8515 8516 8517 8518 8519 8520 8521 8522 8523 8524 8525 8526 8527 8528 8529 8530 8531 8532 8533 8534 8535 8536 8537 8538 8539 8540 8541 8542 8543 8544 8545 8546 8547 8548 8549 8550 8551 8552 8553 8554 8555 8556 8557 8558 8559 8560 8561 8562 8563 8564 8565 8566 8567 8568 8569 8570 8571 8572 8573 8574 8575 8576 8577 8578 8579 8580 8581 8582 8583 8584 8585 8586 8587 8588 8589 8590 8591 8592 8593 8594 8595 8596 8597 8598 8599 8600 8601 8602 8603 8604 8605 8606 8607 8608 8609 8610 8611 8612 8613 8614 8615 8616 8617 8618 8619 8620 8621 8622 8623 8624 8625 8626 8627 8628 8629 8630 8631 8632 8633 8634 8635 8636 8637 8638 8639 8640 8641 8642 8643 8644 8645 8646 8647 8648 8649 8650 8651 8652 8653 8654 8655 8656 8657 8658 8659 8660 8661 8662 8663 8664 8665 8666 8667 8668 8669 8670 8671 8672 8673 8674 8675 8676 8677 8678 8679 8680 8681 8682 8683 8684 8685 8686 8687 8688 8689 8690 8691 8692 8693 8694 8695 8696 8697 8698 8699 8700 8701 8702 8703 8704 8705 8706 8707 8708 8709 8710 8711 8712 8713 8714 8715 8716 8717 8718 8719 8720 8721 8722 8723 8724 8725 8726 8727 8728 8729 8730 8731 8732 8733 8734 8735 8736 8737 8738 8739 8740 8741 8742 8743 8744 8745 8746 8747 8748 8749 8750 8751 8752 8753 8754 8755 8756 8757 8758 8759 8760 8761 8762 8763 8764 8765 8766 8767 8768 8769 8770 8771 8772 8773 8774 8775 8776 8777 8778 8779 8780 8781 8782 8783 8784 8785 8786 8787 8788 8789 8790 8791 8792 8793 8794 8795 8796 8797 8798 8799 8800 8801 8802 8803 8804 8805 8806 8807 8808 8809 8810 8811 8812 8813 8814 8815 8816 8817 8818 8819 8820 8821 8822 8823 8824 8825 8826 8827 8828 8829 8830 8831 8832 8833 8834 8835 8836 8837 8838 8839 8840 8841 8842 8843 8844 8845 8846 8847 8848 8849 8850 8851 8852 8853 8854 8855 8856 8857 8858 8859 8860 8861 8862 8863 8864 8865 8866 8867 8868 8869 8870 8871 8872 8873 8874 8875 8876 8877 8878 8879 8880 8881 8882 8883 8884 8885 8886 8887 8888 8889 8890 8891 8892 8893 8894 8895 8896 8897 8898 8899 8900 8901 8902 8903 8904 8905 8906 8907 8908 8909 8910 8911 8912 8913 8914 8915 8916 8917 8918 8919 8920 8921 8922 8923 8924 8925 8926 8927 8928 8929 8930 8931 8932 8933 8934 8935 8936 8937 8938 8939 8940 8941 8942 8943 8944 8945 8946 8947 8948 8949 8950 8951 8952 8953 8954 8955 8956 8957 8958 8959 8960 8961 8962 8963 8964 8965 8966 8967 8968 8969 8970 8971 8972 8973 8974 8975 8976 8977 8978 8979 8980 8981 8982 8983 8984 8985 8986 8987 8988 8989 8990 8991 8992 8993 8994 8995 8996 8997 8998 8999 9000 9001 9002 9003 9004 9005 9006 9007 9008 9009 9010 9011 9012 9013 9014 9015 9016 9017 9018 9019 9020 9021 9022 9023 9024 9025 9026 9027 9028 9029 9030 9031 9032 9033 9034 9035 9036 9037 9038 9039 9040 9041 9042 9043 9044 9045 9046 9047 9048 9049 9050 9051 9052 9053 9054 9055 9056 9057 9058 9059 9060 9061 9062 9063 9064 9065 9066 9067 9068 9069 9070 9071 9072 9073 9074 9075 9076 9077 9078 9079 9080 9081 9082 9083 9084 9085 9086 9087 9088 9089 9090 9091 9092 9093 9094 9095 9096 9097 9098 9099 9100 9101 9102 9103 9104 9105 9106 9107 9108 9109 9110 9111 9112 9113 9114 9115 9116 9117 9118 9119 9120 9121 9122 9123 9124 9125 9126 9127 9128 9129 9130 9131 9132 9133 9134 9135 9136 9137 9138 9139 9140 9141 9142 9143 9144 9145 9146 9147 9148 9149 9150 9151 9152 9153 9154 9155 9156 9157 9158 9159 9160 9161 9162 9163 9164 9165 9166 9167 9168 9169 9170 9171 9172 9173 9174 9175 9176 9177 9178 9179 9180 9181 9182 9183 9184 9185 9186 9187 9188 9189 9190 9191 9192 9193 9194 9195 9196 9197 9198 9199 9200 9201 9202 9203 9204 9205 9206 9207 9208 9209 9210 9211 9212 9213 9214 9215 9216 9217 9218 9219 9220 9221 9222 9223 9224 9225 9226 9227 9228 9229 9230 9231 9232 9233 9234 9235 9236 9237 9238 9239 9240 9241 9242 9243 9244 9245 9246 9247 9248 9249 9250 9251 9252 9253 9254
|
/***************************************************************************
* copyright : (C) 2003-2008 by Pascal Brachet *
* addons by Luis Silvestre *
* http://www.xm1math.net/texmaker/ *
* *
* This program is free software; you can redistribute it and/or modify *
* it under the terms of the GNU General Public License as published by *
* the Free Software Foundation either version 2 of the License, or *
* (at your option) any later version. *
* *
***************************************************************************/
//#include <stdlib.h>
//#include "/usr/include/valgrind/callgrind.h"
#include "texmaker.h"
#include "latexeditorview.h"
#include "smallUsefulFunctions.h"
#include "cleandialog.h"
#include "debughelper.h"
#include "dblclickmenubar.h"
#include "structdialog.h"
#include "filechooser.h"
#include "tabdialog.h"
#include "arraydialog.h"
#include "bibtexdialog.h"
#include "tabbingdialog.h"
#include "letterdialog.h"
#include "quickdocumentdialog.h"
#include "quickbeamerdialog.h"
#include "mathassistant.h"
#include "maketemplatedialog.h"
#include "templateselector.h"
#include "templatemanager.h"
#include "usermenudialog.h"
#include "usertooldialog.h"
#include "aboutdialog.h"
#include "encodingdialog.h"
#include "randomtextgenerator.h"
#include "webpublishdialog.h"
#include "thesaurusdialog.h"
#include "qsearchreplacepanel.h"
#include "latexcompleter_config.h"
#include "universalinputdialog.h"
#include "insertgraphics.h"
#include "latexeditorview_config.h"
#include "scriptengine.h"
#include "grammarcheck.h"
#include "qmetautils.h"
#include "updatechecker.h"
#include "session.h"
#include "help.h"
#include "fileselector.h"
#ifndef QT_NO_DEBUG
#include "tests/testmanager.h"
#endif
#include "qdocument.h"
#include "qdocumentcursor.h"
#include "qdocumentline.h"
#include "qdocumentline_p.h"
#include "qnfadefinition.h"
bool programStopped = false;
Texmaker* txsInstance = 0;
QCache<QString,QIcon>IconCache;
Texmaker::Texmaker(QWidget *parent, Qt::WindowFlags flags, QSplashScreen *splash)
: QMainWindow(parent, flags), textAnalysisDlg(0), spellDlg(0), mDontScrollToItem(false), runBibliographyIfNecessaryEntered(false) {
programStopped = false;
spellLanguageActions=0;
MapForSymbols=0;
currentLine=-1;
svndlg=0;
userMacroDialog = 0;
mCompleterNeedsUpdate=false;
latexStyleParser=0;
packageListReader=0;
bibtexEntryActions = 0;
biblatexEntryActions = 0;
bibTypeActions = 0;
highlightLanguageActions = 0;
runningPDFCommands = runningPDFAsyncCommands = 0;
completerPreview=false;
recheckLabels=true;
findDlg=0;
recentSessionList = 0;
EditorTabs = 0;
ReadSettings();
#if (QT_VERSION > 0x050000) && (defined(Q_OS_MAC))
QCoreApplication::instance()->installEventFilter(this);
#endif
latexReference = new LatexReference();
latexReference->setFile(findResourceFile("latex2e.html"));
qRegisterMetaType<QSet<QString> >();
readinAllPackageNames(); // asynchrnous read in of all available sty/cls
txsInstance = this;
static int crashHandlerType = 1;
configManager.registerOption("Crash Handler Type", &crashHandlerType, 1);
initCrashHandler(crashHandlerType);
QTimer * t = new QTimer(this);
connect(t, SIGNAL(timeout()), SLOT(iamalive()));
t->start(9500);
setCorner(Qt::TopLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::TopRightCorner, Qt::RightDockWidgetArea);
setCorner(Qt::BottomLeftCorner, Qt::LeftDockWidgetArea);
setCorner(Qt::BottomRightCorner, Qt::RightDockWidgetArea);
setWindowIcon(QIcon(":/images/logo128.png"));
int iconSize = qMax(16, configManager.guiToolbarIconSize);
setIconSize(QSize(iconSize, iconSize));
leftPanel=0;
structureTreeView=0;
outputView=0;
qRegisterMetaType<LatexParser>();
latexParser.importCwlAliases();
m_formatsOldDefault = QDocument::defaultFormatScheme();
QDocument::setDefaultFormatScheme(m_formats);
SpellerUtility::spellcheckErrorFormat = m_formats->id("spellingMistake");
qRegisterMetaType<QList<LineInfo> >();
qRegisterMetaType<QList<GrammarError> >();
qRegisterMetaType<LatexParser>();
qRegisterMetaType<GrammarCheckerConfig>();
grammarCheck = new GrammarCheck();
grammarCheck->moveToThread(&grammarCheckThread);
GrammarCheck::staticMetaObject.invokeMethod(grammarCheck, "init", Qt::QueuedConnection, Q_ARG(LatexParser, latexParser), Q_ARG(GrammarCheckerConfig, *configManager.grammarCheckerConfig));
connect(grammarCheck, SIGNAL(checked(const void*,const void*,int,QList<GrammarError>)), &documents, SLOT(lineGrammarChecked(const void*,const void*,int,QList<GrammarError>)));
if(configManager.autoLoadChildren)
connect(&documents, SIGNAL(docToLoad(QString)),this,SLOT(addDocToLoad(QString)));
grammarCheckThread.start();
if (configManager.autoDetectEncodingFromLatex || configManager.autoDetectEncodingFromChars) QDocument::setDefaultCodec(0);
else QDocument::setDefaultCodec(configManager.newFileEncoding);
if (configManager.autoDetectEncodingFromLatex)
QDocument::addGuessEncodingCallback(&LatexParser::guessEncoding); // encodingcallbacks before restoer session !!!
if (configManager.autoDetectEncodingFromChars)
QDocument::addGuessEncodingCallback(&ConfigManager::getDefaultEncoding);
QString qxsPath=QFileInfo(findResourceFile("qxs/tex.qnfa")).path();
m_languages = new QLanguageFactory(m_formats, this);
m_languages->addDefinitionPath(qxsPath);
m_languages->addDefinitionPath(configManager.configBaseDir + "languages"); // definitions here overwrite previous ones
// custom evironments & structure commands
updateTexQNFA();
QLineMarksInfoCenter::instance()->loadMarkTypes(qxsPath+"/marks.qxm");
QList<QLineMarkType> &marks = QLineMarksInfoCenter::instance()->markTypes();
for (int i=0;i<marks.size();i++)
if (m_formats->format("line:"+marks[i].id).background.isValid())
marks[i].color = m_formats->format("line:"+marks[i].id).background;
else
marks[i].color = Qt::transparent;
LatexEditorView::updateFormatSettings();
// TAB WIDGET EDITEUR
documents.indentationInStructure=configManager.indentationInStructure;
documents.indentIncludesInStructure=configManager.indentIncludesInStructure;
documents.showLineNumbersInStructure=configManager.showLineNumbersInStructure;
connect(&documents,SIGNAL(masterDocumentChanged(LatexDocument *)), SLOT(masterDocumentChanged(LatexDocument *)));
connect(&documents,SIGNAL(aboutToDeleteDocument(LatexDocument*)), SLOT(aboutToDeleteDocument(LatexDocument*)));
centralFrame=new QFrame(this);
centralFrame->setLineWidth(0);
centralFrame->setFrameShape(QFrame::NoFrame);
centralFrame->setFrameShadow(QFrame::Plain);
//edit
centralToolBar=new QToolBar(tr("Central"),this);
centralToolBar->setFloatable(false);
centralToolBar->setOrientation(Qt::Vertical);
centralToolBar->setMovable(false);
iconSize = qMax(16, configManager.guiSecondaryToolbarIconSize);
centralToolBar->setIconSize(QSize(iconSize, iconSize));
EditorTabs=new TxsTabWidget(centralFrame);
EditorTabs->setFocus();
connect(&documents, SIGNAL(docToHide(LatexEditorView *)), EditorTabs, SLOT(removeEditor(LatexEditorView *)));
connect(EditorTabs, SIGNAL(tabBarContextMenuRequested(QPoint)), SLOT(editorTabContextMenu(QPoint)));
connect(EditorTabs, SIGNAL(currentEditorChanged()), SLOT(currentEditorChanged()));
connect(EditorTabs, SIGNAL(closeCurrentEditorRequest()), this, SLOT(fileClose()));
if (hasAtLeastQt(4,5)){
connect(EditorTabs, SIGNAL(tabMoved(int,int)), this, SLOT(EditorTabMoved(int,int)));
}
connect(EditorTabs, SIGNAL(editorAboutToChangeByTabClick(LatexEditorView*,LatexEditorView*)), this, SLOT(editorAboutToChangeByTabClick(LatexEditorView*,LatexEditorView*)));
cursorHistory = new CursorHistory(&documents);
bookmarks = new Bookmarks(&documents, this);
QLayout* centralLayout= new QHBoxLayout(centralFrame);
centralLayout->setSpacing(0);
centralLayout->setMargin(0);
centralLayout->addWidget(centralToolBar);
centralLayout->addWidget(EditorTabs);
centralVSplitter = new QSplitter(Qt::Vertical, this);
centralVSplitter->setChildrenCollapsible(false);
centralVSplitter->addWidget(centralFrame);
centralVSplitter->setStretchFactor(0,1);
mainHSplitter = new QSplitter(Qt::Horizontal, this);
mainHSplitter->addWidget(centralVSplitter);
mainHSplitter->setChildrenCollapsible(false);
setCentralWidget(mainHSplitter);
setContextMenuPolicy(Qt::ActionsContextMenu);
symbolMostused.clear();
setupDockWidgets();
connect(outputView,SIGNAL(updateTheSearch(int)),this,SLOT(updateFindGlobal(int)));
setMenuBar(new DblClickMenuBar());
setupMenus();
TitledPanelPage *logPage = outputView->pageFromId(outputView->LOG_PAGE);
if (logPage) {
logPage->addToolbarAction(getManagedAction("main/tools/logmarkers"));
logPage->addToolbarAction(getManagedAction("main/edit2/goto/errorprev"));
logPage->addToolbarAction(getManagedAction("main/edit2/goto/errornext"));
}
setupToolBars();
connect(&configManager, SIGNAL(watchedMenuChanged(QString)), SLOT(updateToolBarMenu(QString)));
restoreState(windowstate, 0);
//workaround as toolbar central seems not be be handled by windowstate
centralToolBar->setVisible(configManager.centralVisible);
if(tobemaximized) showMaximized();
if(tobefullscreen) {
showFullScreen();
restoreState(stateFullScreen,1);
fullscreenModeAction->setChecked(true);
}
createStatusBar();
completer=0;
UpdateCaption();
show();
if (splash)
splash->raise();
statusLabelMode->setText(QString(" %1 ").arg(tr("Normal Mode")));
statusLabelProcess->setText(QString(" %1 ").arg(tr("Ready")));
setAcceptDrops(true);
//installEventFilter(this);
UpdateChecker::instance()->autoCheck();
completer=new LatexCompleter(latexParser, this);
completer->setConfig(configManager.completerConfig);
completer->setPackageList(&latexPackageList);
connect(completer,SIGNAL(showImagePreview(QString)),this,SLOT(showImgPreview(QString)));
connect(this,SIGNAL(ImgPreview(QString)),completer,SLOT(bibtexSectionFound(QString)));
//updateCompleter();
LatexEditorView::setCompleter(completer);
completer->setLatexReference(latexReference);
completer->updateAbbreviations();
TemplateManager::setConfigBaseDir(configManager.configBaseDir);
TemplateManager::ensureUserTemplateDirExists();
TemplateManager::checkForOldUserTemplates();
if (configManager.sessionRestore) {
fileRestoreSession(false, false);
ToggleRememberAct->setChecked(true);
}
/* The encoding detection works as follow:
If QDocument detects the file is UTF16LE/BE, use that encoding
Else If QDocument detects UTF-8 {
If LatexParser::guessEncoding finds an encoding, use that
Else use UTF-8
} Else {
If LatexParser::guessEncoding finds an encoding use that
Else if QDocument detects ascii (only 7bit characters) {
if default encoding == utf16: use utf-8 as fallback (because utf16 can be reliable detected and the user seems to like unicode)
else use default encoding
}
Else {
if default encoding == utf16/8: use latin1 (because the file contains invalid unicode characters )
else use default encoding
}
}
*/
QStringList filters;
filters << tr("TeX files")+" (*.tex *.bib *.sty *.cls *.mp *.dtx *.cfg *.ins *.ltx)";
filters << tr("LilyPond files")+" (*.lytex)";
filters << tr("Plaintext files")+" (*.txt)";
filters << tr("Pweave files")+" (*.Pnw)";
filters << tr("Sweave files")+" (*.Snw *.Rnw)";
filters << tr("PDF files")+" (*.pdf)";
filters << tr("All files")+" (*)";
fileFilters = filters.join(";;");
if (!configManager.rememberFileFilter)
selectedFileFilter=filters.first();
//setup autosave timer
connect(&autosaveTimer,SIGNAL(timeout()),this,SLOT(fileSaveAll()));
if(configManager.autosaveEveryMinutes>0){
autosaveTimer.start(configManager.autosaveEveryMinutes*1000*60);
}
//script things
setProperty("applicationName",TEXSTUDIO);
QTimer::singleShot(500, this, SLOT(autoRunScripts()));
connectWithAdditionalArguments(this, SIGNAL(infoNewFile()), this, "runScripts", QList<QVariant>() << Macro::ST_NEW_FILE);
connectWithAdditionalArguments(this, SIGNAL(infoNewFromTemplate()), this, "runScripts", QList<QVariant>() << Macro::ST_NEW_FROM_TEMPLATE);
connectWithAdditionalArguments(this, SIGNAL(infoLoadFile(QString)), this, "runScripts", QList<QVariant>() << Macro::ST_LOAD_FILE);
connectWithAdditionalArguments(this, SIGNAL(infoFileSaved(QString)), this, "runScripts", QList<QVariant>() << Macro::ST_FILE_SAVED);
connectWithAdditionalArguments(this, SIGNAL(infoFileClosed()), this, "runScripts", QList<QVariant>() << Macro::ST_FILE_CLOSED);
connectWithAdditionalArguments(&documents, SIGNAL(masterDocumentChanged(LatexDocument*)), this, "runScripts", QList<QVariant>() << Macro::ST_MASTER_CHANGED);
connectWithAdditionalArguments(this, SIGNAL(infoAfterTypeset()), this, "runScripts", QList<QVariant>() << Macro::ST_AFTER_TYPESET);
connectWithAdditionalArguments(&buildManager, SIGNAL(endRunningCommands(QString,bool,bool,bool)), this, "runScripts", QList<QVariant>() << Macro::ST_AFTER_COMMAND_RUN);
}
Texmaker::~Texmaker(){
IconCache.clear();
QDocument::setDefaultFormatScheme(m_formatsOldDefault); //prevents crash when deleted latexeditorview accesses the default format scheme, as m_format is going to be deleted
programStopped = true;
Guardian::shutdown();
delete MapForSymbols;
delete findDlg;
if(latexStyleParser){
latexStyleParser->stop();
latexStyleParser->wait();
}
if(packageListReader){
packageListReader->stop();
packageListReader->wait();
}
GrammarCheck::staticMetaObject.invokeMethod(grammarCheck, "deleteLater", Qt::BlockingQueuedConnection);
grammarCheckThread.quit();
grammarCheckThread.wait(5000); //TODO: timeout causes sigsegv, is there any better solution?
}
QAction* Texmaker::newManagedAction(QWidget* menu, const QString &id,const QString &text, const char* slotName, const QKeySequence &shortCut, const QString & iconFile, const QList<QVariant>& args) {
QAction* tmp = configManager.newManagedAction(menu,id,text,args.isEmpty()?slotName:SLOT(relayToOwnSlot()),QList<QKeySequence>() << shortCut, iconFile);
if (!args.isEmpty()) {
QString slot = QString(slotName).left(QString(slotName).indexOf("("));
Q_ASSERT(staticMetaObject.indexOfSlot(createMethodSignature(qPrintable(slot), args)) != -1);
tmp->setProperty("slot", qPrintable(slot));
tmp->setProperty("args", QVariant::fromValue<QList<QVariant> >(args));
}
return tmp;
}
QAction* Texmaker::newManagedAction(QWidget* menu, const QString &id,const QString &text, const char* slotName, const QList<QKeySequence> &shortCuts, const QString & iconFile, const QList<QVariant>& args) {
QAction* tmp = configManager.newManagedAction(menu,id,text, args.isEmpty()?slotName:SLOT(relayToOwnSlot()),shortCuts, iconFile);
if (!args.isEmpty()) {
QString slot = QString(slotName).left(QString(slotName).indexOf("("));
Q_ASSERT(staticMetaObject.indexOfSlot(createMethodSignature(qPrintable(slot), args)) != -1);
tmp->setProperty("slot", qPrintable(slot));
tmp->setProperty("args", QVariant::fromValue<QList<QVariant> >(args));
}
return tmp;
}
QAction* Texmaker::newManagedEditorAction(QWidget* menu, const QString &id,const QString &text, const char* slotName, const QKeySequence &shortCut, const QString & iconFile, const QList<QVariant>& args) {
QAction* tmp = configManager.newManagedAction(menu,id,text,0,QList<QKeySequence>() << shortCut, iconFile);
linkToEditorSlot(tmp, slotName, args);
return tmp;
}
QAction* Texmaker::newManagedEditorAction(QWidget* menu, const QString &id,const QString &text, const char* slotName, const QList<QKeySequence> &shortCuts, const QString & iconFile, const QList<QVariant>& args) {
QAction* tmp = configManager.newManagedAction(menu,id,text,0,shortCuts, iconFile);
linkToEditorSlot(tmp, slotName, args);
return tmp;
}
QAction* Texmaker::insertManagedAction(QAction* before, const QString &id,const QString &text, const char* slotName, const QKeySequence &shortCut, const QString & iconFile){
QMenu* menu = before->menu();
REQUIRE_RET(menu, 0);
QAction* inserted = newManagedAction(menu, id, text, slotName, shortCut, iconFile);
menu->removeAction(inserted);
menu->insertAction(before, inserted);
return inserted;
}
SymbolGridWidget* Texmaker::addSymbolGrid(const QString& SymbolList, const QString& iconName, const QString& text){
SymbolGridWidget* list = qobject_cast<SymbolGridWidget*>(leftPanel->widget(SymbolList));
if (!list) {
list=new SymbolGridWidget(this,SymbolList,MapForSymbols);
list->setProperty("isSymbolGrid",true);
connect(list, SIGNAL(itemClicked(QTableWidgetItem*)), this, SLOT(InsertSymbol(QTableWidgetItem*)));
connect(list, SIGNAL(itemPressed(QTableWidgetItem*)), this, SLOT(InsertSymbolPressed(QTableWidgetItem*)));
leftPanel->addWidget(list, SymbolList, text, getRealIconFile(iconName));
} else {
leftPanel->setWidgetText(list,text);
leftPanel->setWidgetIcon(list,getRealIconFile(iconName));
}
return list;
}
void Texmaker::addTagList(const QString& id, const QString& iconName, const QString& text, const QString& tagFile){
XmlTagsListWidget* list=qobject_cast<XmlTagsListWidget*>(leftPanel->widget(id));
if (!list) {
list=new XmlTagsListWidget(this,":/tags/"+tagFile);
list->setObjectName("tags/"+tagFile.left(tagFile.indexOf("_tags.xml")));
connect(list, SIGNAL(itemClicked(QListWidgetItem*)), this, SLOT(InsertXmlTag(QListWidgetItem*)));
leftPanel->addWidget(list, id, text, iconName);
//(*list)->setProperty("mType",2);
} else leftPanel->setWidgetText(list,text);
}
void Texmaker::setupDockWidgets(){
//to allow retranslate this function must be able to be called multiple times
//Structure panel
if (!leftPanel) {
leftPanel = new CustomWidgetList(this);
leftPanel->setWindowTitle(tr("Structure"));
leftPanel->setObjectName("leftPanel");
leftPanel->setAllowedAreas(Qt::AllDockWidgetAreas);
leftPanel->setFeatures(QDockWidget::DockWidgetClosable);
addDockWidget(Qt::LeftDockWidgetArea, leftPanel);
connect(&configManager,SIGNAL(newLeftPanelLayoutChanged(bool)), leftPanel, SLOT(showWidgets(bool)));
if (hiddenLeftPanelWidgets!="") {
leftPanel->setHiddenWidgets(hiddenLeftPanelWidgets);
hiddenLeftPanelWidgets=""; //not needed anymore after the first call
}
connect(leftPanel,SIGNAL(widgetContextMenuRequested(QWidget*, QPoint)),this,SLOT(SymbolGridContextMenu(QWidget*, QPoint)));
addAction(leftPanel->toggleViewAction());
}
if (!structureTreeView) {
structureTreeView=new QTreeView(this);
structureTreeView->header()->hide();
if(configManager.indentationInStructure>0)
structureTreeView->setIndentation(configManager.indentationInStructure);
structureTreeView->setModel(documents.model);
//disabled because it also reacts to expand, connect(structureTreeView, SIGNAL(activated(const QModelIndex &)), SLOT(clickedOnStructureEntry(const QModelIndex &))); //enter or double click (+single click on some platforms)
connect(structureTreeView, SIGNAL(pressed(const QModelIndex &)), SLOT(clickedOnStructureEntry(const QModelIndex &))); //single click
// connect(structureTreeView, SIGNAL(expanded(const QModelIndex &)), SLOT(treeWidgetChanged()));
// connect(structureTreeView, SIGNAL(collapsed(const QModelIndex &)), SLOT(treeWidgetChanged()));
//-- connect( StructureTreeWidget, SIGNAL(itemDoubleClicked(QTreeWidgetItem *,int )), SLOT(DoubleClickedOnStructure(QTreeWidgetItem *,int))); // qt4 bugs - don't use it ?? also true for view??
leftPanel->addWidget(structureTreeView, "structureTreeView", tr("Structure"), getRealIconFile("structure"));
} else leftPanel->setWidgetText(structureTreeView,tr("Structure"));
if(!leftPanel->widget("bookmarks")) {
QListWidget *bookmarksWidget = bookmarks->widget();
connect(bookmarks, SIGNAL(loadFileRequest(QString)), this, SLOT(load(QString)));
connect(bookmarks, SIGNAL(gotoLineRequest(int,int,LatexEditorView*)), this, SLOT(gotoLine(int,int,LatexEditorView*)));
leftPanel->addWidget(bookmarksWidget, "bookmarks", tr("Bookmarks"), getRealIconFile("bookmarks"));
} else leftPanel->setWidgetText("bookmarks", tr("Bookmarks"));
int cnt=modernStyle ? 11 : 1;
addSymbolGrid("operators", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Operator symbols"));
addSymbolGrid("relation", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Relation symbols"));
addSymbolGrid("arrows", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Arrow symbols"));
addSymbolGrid("delimiters",QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Delimiters"));
addSymbolGrid("greek", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Greek letters"));
addSymbolGrid("cyrillic", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Cyrillic letters"));
addSymbolGrid("misc-math", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Miscellaneous math symbols"));
addSymbolGrid("misc-text", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Miscellaneous text symbols"));
addSymbolGrid("wasysym", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Miscellaneous text symbols (wasysym)"));
addSymbolGrid("special", QString(":/symbols-ng/icons/img0%1icons.png").arg(cnt++,2,10,QLatin1Char('0')),tr("Accented letters"));
MostUsedSymbolWidget=addSymbolGrid("!mostused",getRealIconFile("math6"),tr("Most used symbols"));
MostUsedSymbolWidget->loadSymbols(MapForSymbols->keys(),MapForSymbols);
FavoriteSymbolWidget=addSymbolGrid("!favorite",getRealIconFile("math7"),tr("Favorites"));
FavoriteSymbolWidget->loadSymbols(symbolFavorites);
addTagList("brackets", getRealIconFile("leftright"), tr("Left/Right Brackets"),"brackets_tags.xml");
addTagList("pstricks", getRealIconFile("pstricks"), tr("Pstricks Commands"),"pstricks_tags.xml");
addTagList("metapost", getRealIconFile("metapost"), tr("MetaPost Commands"),"metapost_tags.xml");
addTagList("tikz", getRealIconFile("tikz"), tr("Tikz Commands"),"tikz_tags.xml");
addTagList("asymptote", getRealIconFile("asymptote"), tr("Asymptote Commands"),"asymptote_tags.xml");
leftPanel->showWidgets(configManager.newLeftPanelLayout);
// update MostOftenUsed
MostUsedSymbolsTriggered(true);
// OUTPUT WIDGETS
if (!outputView) {
outputView = new OutputViewWidget(this);
outputView->setObjectName("OutputView");
centralVSplitter->addWidget(outputView);
outputView->toggleViewAction()->setChecked(configManager.getOption("GUI/outputView/visible", true).toBool());
centralVSplitter->setStretchFactor(1,0);
centralVSplitter->restoreState(configManager.getOption("centralVSplitterState").toByteArray());
connect(outputView->getLogWidget(),SIGNAL(logEntryActivated(int)),this,SLOT(gotoLogEntryEditorOnly(int)));
connect(outputView->getLogWidget(),SIGNAL(logLoaded()),this,SLOT(updateLogEntriesInEditors()));
connect(outputView->getLogWidget(),SIGNAL(logResetted()),this,SLOT(clearLogEntriesInEditors()));
connect(outputView,SIGNAL(pageChanged(QString)),this,SLOT(outputPageChanged(QString)));
connect(outputView,SIGNAL(jumpToSearch(QDocument*,int)),this,SLOT(jumpToSearch(QDocument*,int)));
connect(&buildManager,SIGNAL(previewAvailable(const QString&, const PreviewSource&)),this,SLOT(previewAvailable (const QString&,const PreviewSource&)));
connect(&buildManager, SIGNAL(processNotification(QString)), SLOT(processNotification(QString)));
connect(&buildManager, SIGNAL(beginRunningCommands(QString,bool,bool,bool)), SLOT(beginRunningCommand(QString,bool,bool,bool)));
connect(&buildManager, SIGNAL(beginRunningSubCommand(ProcessX*,QString,QString,RunCommandFlags)), SLOT(beginRunningSubCommand(ProcessX*,QString,QString,RunCommandFlags)));
connect(&buildManager, SIGNAL(endRunningSubCommand(ProcessX*,QString,QString,RunCommandFlags)), SLOT(endRunningSubCommand(ProcessX*,QString,QString,RunCommandFlags)));
connect(&buildManager, SIGNAL(endRunningCommands(QString,bool,bool,bool)), SLOT(endRunningCommand(QString,bool,bool,bool)));
connect(&buildManager, SIGNAL(latexCompiled(LatexCompileResult*)), SLOT(ViewLogOrReRun(LatexCompileResult*)));
connect(&buildManager, SIGNAL(runInternalCommand(QString,QFileInfo,QString)), SLOT(runInternalCommand(QString,QFileInfo,QString)));
connect(&buildManager, SIGNAL(commandLineRequested(QString,QString*,bool*)), SLOT(commandLineRequested(QString,QString*,bool*)));
addAction(outputView->toggleViewAction());
QAction* temp = new QAction(this); temp->setSeparator(true);
addAction(temp);
}
}
void Texmaker::updateToolBarMenu(const QString& menuName){
QMenu* menu = configManager.getManagedMenu(menuName);
if (!menu) return;
foreach (const ManagedToolBar& tb, configManager.managedToolBars)
if (tb.toolbar && tb.actualActions.contains(menuName))
foreach (QObject* w, tb.toolbar->children())
if (w->property("menuID").toString() == menuName) {
QToolButton* combo = qobject_cast<QToolButton*>(w);
REQUIRE(combo);
QFontMetrics fontMetrics(tb.toolbar->font());
QStringList actionTexts;
QList<QIcon> actionIcons;
foreach (const QAction* act, menu->actions())
if (!act->isSeparator()) {
actionTexts.append(act->text());
actionIcons.append(act->icon());
}
createComboToolButton(tb.toolbar, actionTexts, actionIcons, -1, this, SLOT(callToolButtonAction()), "", combo);
if (menuName == "main/view/documents") {
//workaround to select the current document
int index = EditorTabs->currentIndex();
if (index >= 0 && index < combo->menu()->actions().size())
combo->setDefaultAction(combo->menu()->actions()[index]);
}
}
}
// we different native shortcuts on OSX and Win/Linux
// note: in particular many key combination with arrows are reserved for text navigation in OSX
// and we already set them in QEditor. Don't overwrite them here.
#ifdef Q_OS_MAC
#define MAC_OTHER(shortcutMac, shortcutOther) shortcutMac
#else
#define MAC_OTHER(shortcutMac, shortcutOther) shortcutOther
#endif
void Texmaker::setupMenus() {
//This function is called whenever the menu changes (= start and retranslation)
//This means if you call it repeatedly with the same language setting it should not change anything
//Currently this is not true, because it adds additional separator, which are invisible
//creates new action groups and new context menu, although all invisible, they are a memory leak
//But not a bad one, because no one is expected to change the language multiple times
//TODO: correct somewhen
configManager.menuParent=this;
configManager.menuParentsBar=menuBar();
//file
QMenu *menu=newManagedMenu("main/file",tr("&File"));
getManagedMenu("main/file");
newManagedAction(menu, "new",tr("&New"), SLOT(fileNew()), Qt::CTRL+Qt::Key_N, "filenew");
newManagedAction(menu, "newfromtemplate",tr("New From &Template..."), SLOT(fileNewFromTemplate()));
newManagedAction(menu, "open",tr("&Open..."), SLOT(fileOpen()), Qt::CTRL+Qt::Key_O, "fileopen");
QMenu *submenu=newManagedMenu(menu, "openrecent",tr("Open &Recent")); //only create the menu here, actions are created by config manager
submenu = newManagedMenu(menu, "session", tr("Session"));
newManagedAction(submenu, "loadsession", tr("Load Session..."), SLOT(fileLoadSession()));
newManagedAction(submenu, "savesession", tr("Save Session..."), SLOT(fileSaveSession()));
newManagedAction(submenu, "restoresession",tr("Restore Previous Session"), SLOT(fileRestoreSession()));
submenu->addSeparator();
if (!recentSessionList) {
recentSessionList = new SessionList(submenu, this);
connect(recentSessionList, SIGNAL(loadSessionRequest(QString)), this, SLOT(loadSession(QString)));
}
recentSessionList->updateMostRecentMenu();
menu->addSeparator();
actSave = newManagedAction(menu,"save",tr("&Save"), SLOT(fileSave()), Qt::CTRL+Qt::Key_S, "filesave");
newManagedAction(menu,"saveas",tr("Save &As..."), SLOT(fileSaveAs()), Qt::CTRL+Qt::ALT+Qt::Key_S);
newManagedAction(menu,"saveall",tr("Save A&ll"), SLOT(fileSaveAll()), Qt::CTRL+Qt::SHIFT+Qt::ALT+Qt::Key_S);
newManagedAction(menu, "maketemplate",tr("&Make Template..."), SLOT(fileMakeTemplate()));
submenu=newManagedMenu(menu, "utilities",tr("Fifi&x"));
newManagedAction(submenu, "rename", tr("Save renamed/&moved file..."), "fileUtilCopyMove",0,QString(),QList<QVariant>() << true);
newManagedAction(submenu, "copy", tr("Save copied file..."), "fileUtilCopyMove",0,QString(),QList<QVariant>() << false);
newManagedAction(submenu, "delete", tr("&Delete file"), SLOT(fileUtilDelete()));
newManagedAction(submenu, "chmod", tr("Set &permissions..."), SLOT(fileUtilPermissions()));
submenu->addSeparator();
newManagedAction(submenu, "revert", tr("&Revert to saved..."), SLOT(fileUtilRevert()));
submenu->addSeparator();
newManagedAction(submenu, "copyfilename", tr("Copy filename to &clipboard"), SLOT(fileUtilCopyFileName()));
newManagedAction(submenu, "copymasterfilename", tr("Copy master filename to clipboard"), SLOT(fileUtilCopyMasterFileName()));
QMenu *svnSubmenu=newManagedMenu(menu, "svn",tr("S&VN..."));
newManagedAction(svnSubmenu, "checkin",tr("Check &in..."), SLOT(fileCheckin()));
newManagedAction(svnSubmenu, "svnupdate",tr("SVN &update..."), SLOT(fileUpdate()));
newManagedAction(svnSubmenu, "svnupdatecwd",tr("SVN update &work directory"), SLOT(fileUpdateCWD()));
newManagedAction(svnSubmenu, "showrevisions",tr("Sh&ow old Revisions"), SLOT(showOldRevisions()));
newManagedAction(svnSubmenu, "lockpdf",tr("Lock &PDF"), SLOT(fileLockPdf()));
newManagedAction(svnSubmenu, "checkinpdf",tr("Check in P&DF"), SLOT(fileCheckinPdf()));
newManagedAction(svnSubmenu, "difffiles",tr("Show difference between two files"), SLOT(fileDiff()));
newManagedAction(svnSubmenu, "diff3files",tr("Show difference between two files in relation to base file"), SLOT(fileDiff3()));
newManagedAction(svnSubmenu, "checksvnconflict",tr("Check SVN Conflict"), SLOT(checkSVNConflicted()));
newManagedAction(svnSubmenu, "mergediff",tr("Try to merge differences"), SLOT(fileDiffMerge()));
newManagedAction(svnSubmenu, "removediffmakers",tr("Remove Difference-Markers"), SLOT(removeDiffMarkers()));
newManagedAction(svnSubmenu, "declareresolved",tr("Declare Conflict Resolved"), SLOT(declareConflictResolved()));
newManagedAction(svnSubmenu, "nextdiff",tr("Jump to next difference"), SLOT(jumpNextDiff()),0,"go-next-diff");
newManagedAction(svnSubmenu, "prevdiff",tr("Jump to previous difference"), SLOT(jumpPrevDiff()),0,"go-previous-diff");
menu->addSeparator();
newManagedAction(menu,"close",tr("&Close"), SLOT(fileClose()), Qt::CTRL+Qt::Key_W, "fileclose");
newManagedAction(menu,"closeall",tr("Clos&e All"), SLOT(fileCloseAll()));
menu->addSeparator();
newManagedEditorAction(menu, "print",tr("Print..."), "print", Qt::CTRL+Qt::Key_P);
menu->addSeparator();
newManagedAction(menu,"exit",tr("Exit"), SLOT(fileExit()), Qt::CTRL+Qt::Key_Q)->setMenuRole(QAction::QuitRole);
//edit
menu=newManagedMenu("main/edit",tr("&Edit"));
actUndo = newManagedAction(menu, "undo",tr("&Undo"), SLOT(editUndo()), Qt::CTRL+Qt::Key_Z, "undo");
actRedo = newManagedAction(menu, "redo",tr("&Redo"), SLOT(editRedo()), Qt::CTRL+Qt::Key_Y, "redo");
#ifndef QT_NO_DEBUG
newManagedAction(menu, "debughistory",tr("Debug undo stack"), SLOT(editDebugUndoStack()));
#endif
menu->addSeparator();
newManagedAction(menu,"copy",tr("&Copy"), SLOT(editCopy()), (QList<QKeySequence>()<< Qt::CTRL+Qt::Key_C)<<Qt::CTRL+Qt::Key_Insert, "editcopy");
newManagedEditorAction(menu,"cut",tr("C&ut"), "cut", (QList<QKeySequence>()<< Qt::CTRL+Qt::Key_X)<<Qt::SHIFT+Qt::Key_Delete, "editcut");
newManagedAction(menu,"paste",tr("&Paste"), SLOT(editPaste()), (QList<QKeySequence>()<< Qt::CTRL+Qt::Key_V)<<Qt::AltModifier+Qt::Key_Insert, "editpaste");
//newManagedEditorAction(menu,"paste",tr("&Paste"), "paste", (QList<QKeySequence>()<< Qt::CTRL+Qt::Key_V)<<Qt::AltModifier+Qt::Key_Insert, "editpaste");
newManagedEditorAction(menu,"selectall",tr("Select &All"), "selectAll", Qt::CTRL+Qt::Key_A);
submenu = newManagedMenu(menu, "lineoperations", tr("&Line Operations"));
newManagedAction(submenu,"eraseLine",tr("Erase &Line"), SLOT(editEraseLine()), (QList<QKeySequence>()<< Qt::CTRL+Qt::Key_K));
newManagedAction(submenu,"eraseEndLine",tr("Erase until E&nd of Line"), SLOT(editEraseEndLine()), (QList<QKeySequence>()<< Qt::AltModifier+Qt::Key_K));
newManagedAction(submenu,"moveLineUp",tr("Move Line &Up"), SLOT(editMoveLineUp()));
newManagedAction(submenu,"moveLineDown",tr("Move Line &Down"), SLOT(editMoveLineDown()));
newManagedAction(submenu,"duplicateLine",tr("Duplicate Line"), SLOT(editDuplicateLine()));
submenu = newManagedMenu(menu, "textoperations", tr("&Text Operations"));
newManagedAction(submenu,"textToLowercase", tr("To Lowercase"), SLOT(editTextToLowercase()));
newManagedAction(submenu,"textToUppercase", tr("To Uppercase"), SLOT(editTextToUppercase()));
newManagedAction(submenu,"textToTitlecaseStrict", tr("To Titlecase (strict)"), SLOT(editTextToTitlecase()));
newManagedAction(submenu,"textToTitlecaseSmart", tr("To Titlecase (smart)"), SLOT(editTextToTitlecaseSmart()));
menu->addSeparator();
submenu = newManagedMenu(menu, "searching", tr("&Searching"));
newManagedAction(submenu,"find", tr("&Find"), SLOT(editFind()), Qt::CTRL+Qt::Key_F);
newManagedEditorAction(submenu,"findinsamedir",tr("Continue F&ind"), "findInSameDir", (QList<QKeySequence>()<< Qt::Key_F3)<<Qt::CTRL+Qt::Key_M);
newManagedEditorAction(submenu,"findnext",tr("Find &Next"), "findNext", MAC_OTHER(Qt::CTRL+Qt::Key_G, 0));
newManagedEditorAction(submenu,"findprev",tr("Find &Prev"), "findPrev", MAC_OTHER(Qt::CTRL+Qt::SHIFT+Qt::Key_G, 0));
newManagedEditorAction(submenu,"findcount",tr("&Count"), "findCount");
newManagedEditorAction(submenu,"select",tr("&Select all matches..."), "selectAllMatches");
//newManagedAction(submenu,"findglobal",tr("Find &Dialog..."), SLOT(editFindGlobal()));
submenu->addSeparator();
newManagedEditorAction(submenu,"replace",tr("&Replace"), "replacePanel", Qt::CTRL+Qt::Key_R);
newManagedEditorAction(submenu,"replacenext",tr("Replace Next"), "replaceNext");
newManagedEditorAction(submenu,"replaceprev",tr("Replace Prev"), "replacePrev");
newManagedEditorAction(submenu,"replaceall",tr("Replace &All"), "replaceAll");
menu->addSeparator();
submenu=newManagedMenu(menu, "goto",tr("Go to"));
newManagedEditorAction(submenu,"line", tr("Line"), "gotoLine", MAC_OTHER(Qt::CTRL+Qt::Key_L, Qt::CTRL+Qt::Key_G), "goto");
newManagedEditorAction(submenu,"lastchange",tr("Previous Change"), "jumpChangePositionBackward", Qt::CTRL+Qt::Key_H);
newManagedEditorAction(submenu,"nextchange",tr("Next Change"), "jumpChangePositionForward", Qt::CTRL+Qt::SHIFT+Qt::Key_H);
submenu->addSeparator();
newManagedAction(submenu,"markprev",tr("Previous mark"),"gotoMark", MAC_OTHER(0, Qt::CTRL+Qt::Key_Up),"",QList<QVariant>() << true << -1);//, ":/images/errorprev.png");
newManagedAction(submenu,"marknext",tr("Next mark"),"gotoMark", MAC_OTHER(0, Qt::CTRL+Qt::Key_Down),"",QList<QVariant>() << false << -1);//, ":/images/errornext.png");
submenu->addSeparator();
cursorHistory->setBackAction(newManagedAction(submenu,"goback",tr("Go Back"), SLOT(goBack()), MAC_OTHER(0, Qt::ALT+Qt::Key_Left), "back"));
cursorHistory->setForwardAction(newManagedAction(submenu,"goforward",tr("Go Forward"), SLOT(goForward()), MAC_OTHER(0, Qt::ALT+Qt::Key_Right), "forward"));
submenu=newManagedMenu(menu, "gotoBookmark",tr("Goto Bookmark"));
for (int i=0; i<=9; i++)
newManagedEditorAction(submenu,QString("bookmark%1").arg(i),tr("Bookmark %1").arg(i),"jumpToBookmark",Qt::CTRL+Qt::Key_0+i,"",QList<QVariant>() << i);
submenu=newManagedMenu(menu, "toggleBookmark",tr("Toggle Bookmark"));
newManagedEditorAction(submenu,QString("bookmark"),tr("Unnamed Bookmark"),"toggleBookmark",Qt::CTRL+Qt::SHIFT+Qt::Key_B,"",QList<QVariant>() <<-1);
for (int i=0; i<=9; i++)
newManagedEditorAction(submenu,QString("bookmark%1").arg(i),tr("Bookmark %1").arg(i),"toggleBookmark",Qt::CTRL+Qt::SHIFT+Qt::Key_0+i,"",QList<QVariant>() << i);
menu->addSeparator();
submenu=newManagedMenu(menu,"lineend",tr("Line Ending"));
QActionGroup *lineEndingGroup=new QActionGroup(this);
QAction* act=newManagedAction(submenu, "crlf", tr("DOS/Windows (CR LF)"), SLOT(editChangeLineEnding()));
act->setData(QDocument::Windows);
act->setCheckable(true);
lineEndingGroup->addAction(act);
act=newManagedAction(submenu, "lf", tr("Unix (LF)"), SLOT(editChangeLineEnding()));
act->setData(QDocument::Unix);
act->setCheckable(true);
lineEndingGroup->addAction(act);
act=newManagedAction(submenu, "cr", tr("Old Mac (CR)"), SLOT(editChangeLineEnding()));
act->setData(QDocument::Mac);
act->setCheckable(true);
lineEndingGroup->addAction(act);
newManagedAction(menu,"encoding",tr("Setup Encoding..."),SLOT(editSetupEncoding()))->setMenuRole(QAction::NoRole); // with the default "QAction::TextHeuristicRole" this was interperted as Preferences on OSX
newManagedAction(menu,"unicodeChar",tr("Insert Unicode Character..."),SLOT(editInsertUnicode()), Qt::ALT + Qt::CTRL + Qt::Key_U);
//Edit 2 (for LaTeX related things)
menu=newManagedMenu("main/edit2",tr("&Idefix"));
newManagedAction(menu,"eraseWord",tr("Erase &Word/Cmd/Env"), SLOT(editEraseWordCmdEnv()), MAC_OTHER(0, Qt::ALT+Qt::Key_Delete));
menu->addSeparator();
newManagedAction(menu,"pasteAsLatex",tr("Pas&te as LaTeX"), SLOT(editPasteLatex()), Qt::CTRL+Qt::SHIFT+Qt::Key_V, "editpaste");
newManagedAction(menu,"convertTo",tr("Co&nvert to LaTeX"), SLOT(convertToLatex()));
newManagedAction(menu,"previewLatex",tr("Pre&view Selection/Parentheses"), SLOT(previewLatex()),Qt::ALT+Qt::Key_P);
newManagedAction(menu,"removePreviewLatex",tr("C&lear Inline Preview"), SLOT(clearPreview()));
menu->addSeparator();
newManagedEditorAction(menu,"comment", tr("&Comment"), "commentSelection", Qt::CTRL+Qt::Key_T);
newManagedEditorAction(menu,"uncomment",tr("&Uncomment"), "uncommentSelection", Qt::CTRL+Qt::Key_U);
newManagedEditorAction(menu,"indent",tr("&Indent"), "indentSelection");
newManagedEditorAction(menu,"unindent",tr("Unin&dent"), "unindentSelection");
newManagedAction(menu,"hardbreak",tr("Hard Line &Break..."), SLOT(editHardLineBreak()));
newManagedAction(menu,"hardbreakrepeat",tr("R&epeat Hard Line Break"), SLOT(editHardLineBreakRepeat()));
menu->addSeparator();
submenu=newManagedMenu(menu, "goto",tr("&Go to"));
newManagedAction(submenu,"errorprev",tr("Previous Error"),"gotoNearLogEntry",MAC_OTHER(0, Qt::CTRL+Qt::SHIFT+Qt::Key_Up), "errorprev", QList<QVariant>() << LT_ERROR << true << tr("No LaTeX errors detected !"));
newManagedAction(submenu,"errornext",tr("Next Error"),"gotoNearLogEntry",MAC_OTHER(0, Qt::CTRL+Qt::SHIFT+Qt::Key_Down), "errornext", QList<QVariant>() << LT_ERROR << false << tr("No LaTeX errors detected !"));
newManagedAction(submenu,"warningprev",tr("Previous Warning"),"gotoNearLogEntry",QKeySequence(),"", QList<QVariant>() << LT_WARNING << true << tr("No LaTeX warnings detected !"));//, ":/images/errorprev.png");
newManagedAction(submenu,"warningnext",tr("Next Warning"),"gotoNearLogEntry",QKeySequence(),"", QList<QVariant>() << LT_WARNING << false << tr("No LaTeX warnings detected !"));//, ":/images/errornext.png");
newManagedAction(submenu,"badboxprev",tr("Previous Bad Box"),"gotoNearLogEntry", MAC_OTHER(0, Qt::SHIFT+Qt::ALT+Qt::Key_Up), "", QList<QVariant>() << LT_BADBOX << true << tr("No bad boxes detected !"));//, ":/images/errorprev.png");
newManagedAction(submenu,"badboxnext",tr("Next Bad Box"),"gotoNearLogEntry", MAC_OTHER(0, Qt::SHIFT+Qt::ALT+Qt::Key_Down), "", QList<QVariant>() << LT_BADBOX << true << tr("No bad boxes detected !"));//, ":/images/errornext.png");
submenu->addSeparator();
QKeySequence sc(Qt::CTRL+Qt::ALT+Qt::Key_F);
#ifdef Q_OS_WIN32
QLocale::Language lang;
#if QT_VERSION < 0x050000
lang = QApplication::keyboardInputLocale().language();
#else
lang = QGuiApplication::inputMethod()->locale().language();
#endif
// on win ctrl+alt = altGr, hungarian: altGr+F = [
// so we should not use this as shortcut in this special case
if (lang == QLocale::Hungarian)
sc = QKeySequence(Qt::CTRL+Qt::ALT+Qt::SHIFT+Qt::Key_F);
#endif
newManagedAction(submenu,"definition",tr("Definition"),SLOT(editGotoDefinition()),sc);
menu->addSeparator();
newManagedAction(menu,"generateMirror",tr("Re&name Environment"), SLOT(generateMirror()));
submenu = newManagedMenu(menu, "parens", tr("Parenthesis"));
newManagedAction(submenu, "jump", tr("Jump to Match"), SLOT(jumpToBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_J));
newManagedAction(submenu, "selectBracketInner", tr("Select Inner"), SLOT(selectBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_I))->setProperty("minimal", true);
newManagedAction(submenu, "selectBracketOuter", tr("Select Outer"), SLOT(selectBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_O))->setProperty("minimal", false);
newManagedAction(submenu, "selectBracketCommand", tr("Select Command"), SLOT(selectBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_C))->setProperty("backslash", true);
newManagedAction(submenu, "selectBracketLine", tr("Select Line"), SLOT(selectBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_L))->setProperty("line", true);
newManagedAction(submenu, "generateInvertedBracketMirror", tr("Select Inverting"), SLOT(generateBracketInverterMirror()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_S));
submenu->addSeparator();
newManagedAction(submenu, "findMissingBracket", tr("Find Mismatch"), SLOT(findMissingBracket()), QKeySequence(Qt::SHIFT+Qt::CTRL+Qt::Key_P, Qt::Key_M));
submenu=newManagedMenu(menu, "complete",tr("Complete"));
newManagedAction(submenu, "normal", tr("Normal"), SLOT(NormalCompletion()),Qt::CTRL+Qt::Key_Space);
newManagedAction(submenu, "environment", tr("\\begin{ Completion"), SLOT(InsertEnvironmentCompletion()),Qt::CTRL+Qt::ALT+Qt::Key_Space);
newManagedAction(submenu, "text", tr("Normal Text"), SLOT(InsertTextCompletion()),Qt::SHIFT+Qt::ALT+Qt::Key_Space);
newManagedAction(submenu, "closeEnvironment", tr("Close latest open environment"), SLOT(CloseEnv()),Qt::ALT+Qt::Key_Return);
menu->addSeparator();
newManagedAction(menu,"reparse",tr("Refresh Structure"),SLOT(updateStructure()));
newManagedAction(menu,"removePlaceHolders",tr("Remove Placeholders"),SLOT(editRemovePlaceHolders()),Qt::CTRL+Qt::SHIFT+Qt::Key_K);
newManagedAction(menu,"removeCurrentPlaceHolder",tr("Remove Current Placeholder"),SLOT(editRemoveCurrentPlaceHolder()));
//tools
menu=newManagedMenu("main/tools",tr("&Tools"));
menu->setProperty("defaultSlot", QByteArray(SLOT(commandFromAction())));
newManagedAction(menu, "quickbuild",tr("&Build && View"), SLOT(commandFromAction()), Qt::Key_F1, "build")->setData(BuildManager::CMD_QUICK);
newManagedAction(menu, "compile",tr("&Compile"), SLOT(commandFromAction()), Qt::Key_F6,"compile")->setData(BuildManager::CMD_COMPILE);
newManagedAction(menu, "stopcompile", buildManager.stopBuildAction())->setText(buildManager.tr("Stop Compile")); // resetting text necessary for language updates
buildManager.stopBuildAction()->setParent(menu); // actions need to be a child of the menu in order to be configurable in toolbars
newManagedAction(menu, "view",tr("&View"), SLOT(commandFromAction()), Qt::Key_F7,"viewer")->setData(BuildManager::CMD_VIEW);
newManagedAction(menu, "glossary",tr("&Glossary"), SLOT(commandFromAction()), Qt::Key_F10)->setData(BuildManager::CMD_GLOSSARY);
newManagedAction(menu, "bibtex",tr("&Bibliography"), SLOT(commandFromAction()), Qt::Key_F11)->setData(BuildManager::CMD_BIBLIOGRAPHY);
newManagedAction(menu, "index",tr("&Index"), SLOT(commandFromAction()), Qt::Key_F12)->setData(BuildManager::CMD_INDEX);
menu->addSeparator();
submenu=newManagedMenu(menu, "commands",tr("&Commands", "menu"));
newManagedAction(submenu, "latexmk",tr("&Latexmk"), SLOT(commandFromAction()))->setData(BuildManager::CMD_LATEXMK);
submenu->addSeparator();
newManagedAction(submenu, "latex",tr("&LaTeX"), SLOT(commandFromAction()), QKeySequence(), "compile-latex")->setData(BuildManager::CMD_LATEX);
newManagedAction(submenu, "pdflatex",tr("&PDFLaTeX"), SLOT(commandFromAction()), QKeySequence(), "compile-pdf")->setData(BuildManager::CMD_PDFLATEX);
newManagedAction(submenu, "xelatex","&XeLaTeX", SLOT(commandFromAction()), QKeySequence(), "compile-xelatex")->setData(BuildManager::CMD_XELATEX);
newManagedAction(submenu, "lualatex","L&uaLaTeX", SLOT(commandFromAction()), QKeySequence(), "compile-lua")->setData(BuildManager::CMD_LUALATEX);
submenu->addSeparator();
newManagedAction(submenu, "dvi2ps",tr("DVI->PS"), SLOT(commandFromAction()), QKeySequence(), "convert-dvips")->setData(BuildManager::CMD_DVIPS);
newManagedAction(submenu, "ps2pdf",tr("P&S->PDF"), SLOT(commandFromAction()), QKeySequence(), "convert-pspdf")->setData(BuildManager::CMD_PS2PDF);
newManagedAction(submenu, "dvipdf",tr("DV&I->PDF"), SLOT(commandFromAction()), QKeySequence(), "convert-dvipdf")->setData(BuildManager::CMD_DVIPDF);
submenu->addSeparator();
newManagedAction(submenu, "viewdvi",tr("View &DVI"), SLOT(commandFromAction()), QKeySequence(), "view-doc-dvi")->setData(BuildManager::CMD_VIEW_DVI);
newManagedAction(submenu, "viewps",tr("Vie&w PS"), SLOT(commandFromAction()), QKeySequence(), "view-doc-ps")->setData(BuildManager::CMD_VIEW_PS);
newManagedAction(submenu, "viewpdf",tr("View PD&F"), SLOT(commandFromAction()), QKeySequence(), "view-doc-pdf")->setData(BuildManager::CMD_VIEW_PDF);
submenu->addSeparator();
newManagedAction(submenu, "bibtex",tr("&Bibtex"), SLOT(commandFromAction()))->setData(BuildManager::CMD_BIBTEX);
newManagedAction(submenu, "bibtex8",tr("&Bibtex 8-Bit"), SLOT(commandFromAction()))->setData(BuildManager::CMD_BIBTEX8);
newManagedAction(submenu, "biber",tr("Bibe&r"), SLOT(commandFromAction()))->setData(BuildManager::CMD_BIBER);
submenu->addSeparator();
newManagedAction(submenu, "makeindex",tr("&MakeIndex"), SLOT(commandFromAction()))->setData(BuildManager::CMD_MAKEINDEX);
newManagedAction(submenu, "texindy",tr("&TexIndy"), SLOT(commandFromAction()), QKeySequence())->setData(BuildManager::CMD_TEXINDY);
newManagedAction(submenu, "makeglossaries",tr("&Makeglossaries"), SLOT(commandFromAction()), QKeySequence())->setData(BuildManager::CMD_MAKEGLOSSARIES);
submenu->addSeparator();
newManagedAction(submenu, "metapost",tr("&MetaPost"), SLOT(commandFromAction()))->setData(BuildManager::CMD_METAPOST);
newManagedAction(submenu, "asymptote",tr("&Asymptote"), SLOT(commandFromAction()))->setData(BuildManager::CMD_ASY);
submenu=newManagedMenu(menu, "user",tr("&User", "menu"));
updateUserToolMenu();
menu->addSeparator();
newManagedAction(menu, "clean",tr("Cle&an Auxiliary Files..."), SLOT(CleanAll()));
menu->addSeparator();
newManagedAction(menu, "viewlog",tr("View &Log"), SLOT(commandFromAction()), QKeySequence(), "viewlog")->setData(BuildManager::CMD_VIEW_LOG);
act = newManagedAction(menu, "logmarkers", tr("Show Log Markers"), 0, 0, "logmarkers");
act->setCheckable(true);
connect(act, SIGNAL(triggered(bool)), SLOT(setLogMarksVisible(bool)));
menu->addSeparator();
newManagedAction(menu, "htmlexport",tr("C&onvert to Html..."), SLOT(WebPublish()));
newManagedAction(menu, "htmlsourceexport",tr("C&onvert Source to Html..."), SLOT(WebPublishSource()));
menu->addSeparator();
newManagedAction(menu, "analysetext",tr("A&nalyse Text..."), SLOT(AnalyseText()));
newManagedAction(menu, "generaterandomtext",tr("Generate &Random Text..."), SLOT(GenerateRandomText()));
menu->addSeparator();
act = newManagedAction(menu,"spelling",tr("Check Spelling..."),SLOT(editSpell()),Qt::CTRL+Qt::SHIFT+Qt::Key_F7);
#ifndef QT_OS_MAC
act->setShortcut(Qt::CTRL+Qt::Key_Colon);
#endif
newManagedAction(menu,"thesaurus",tr("Thesaurus..."),SLOT(editThesaurus()),Qt::CTRL+Qt::SHIFT+Qt::Key_F8);
newManagedAction(menu,"wordrepetions",tr("Find Word Repetitions..."),SLOT(findWordRepetions()));
// Latex/Math external
configManager.loadManagedMenus(":/uiconfig.xml");
// add some additional items
menu=newManagedMenu("main/latex",tr("&LaTeX"));
menu->setProperty("defaultSlot", QByteArray(SLOT(InsertFromAction())));
newManagedAction(menu, "insertrefnextlabel",tr("Insert \\ref to Next Label"), SLOT(editInsertRefToNextLabel()), Qt::ALT+Qt::CTRL+Qt::Key_R);
newManagedAction(menu, "insertrefprevlabel",tr("Insert \\ref to Previous Label"), SLOT(editInsertRefToPrevLabel()));
submenu=newManagedMenu(menu, "tabularmanipulation",tr("Manipulate Tables","table"));
newManagedAction(submenu, "addRow",tr("Add Row","table"), SLOT(addRowCB()),QKeySequence(),"addRow");
newManagedAction(submenu, "addColumn",tr("Add Column","table"), SLOT(addColumnCB()),QKeySequence(),"addCol");
newManagedAction(submenu, "removeRow",tr("Remove Row","table"), SLOT(removeRowCB()),QKeySequence(),"remRow");
newManagedAction(submenu, "removeColumn",tr("Remove Column","table"), SLOT(removeColumnCB()),QKeySequence(),"remCol");
newManagedAction(submenu, "cutColumn",tr("Cut Column","table"), SLOT(cutColumnCB()),QKeySequence(),"cutCol");
newManagedAction(submenu, "pasteColumn",tr("Paste Column","table"), SLOT(pasteColumnCB()),QKeySequence(),"pasteCol");
newManagedAction(submenu, "addHLine",tr("Add \\hline","table"), SLOT(addHLineCB()));
newManagedAction(submenu, "remHLine",tr("Remove \\hline","table"), SLOT(remHLineCB()));
newManagedAction(submenu, "insertTableTemplate",tr("Remodel Table Using Template","table"), SLOT(insertTableTemplate()));
newManagedAction(submenu, "alignColumns", tr("Align Columns"), SLOT(alignTableCols()),QKeySequence(),"alignCols");
submenu=newManagedMenu(menu, "magicComments",tr("Add magic comments ..."));
newManagedAction(submenu, "addMagicRoot", tr("Insert root document name as TeX comment"), SLOT(addMagicRoot()));
newManagedAction(submenu, "addMagicLang", tr("Insert language as TeX comment"), SLOT(InsertSpellcheckMagicComment()));
newManagedAction(submenu, "addMagicCoding", tr("Insert document coding as TeX comment"), SLOT(addMagicCoding()));
menu=newManagedMenu("main/math",tr("&Math"));
menu->setProperty("defaultSlot", QByteArray(SLOT(InsertFromAction())));
//wizards
menu=newManagedMenu("main/wizards",tr("&Wizards"));
newManagedAction(menu, "start",tr("Quick &Start..."), SLOT(QuickDocument()));
newManagedAction(menu, "beamer",tr("Quick &Beamer Presentation..."), SLOT(QuickBeamer()));
newManagedAction(menu, "letter",tr("Quick &Letter..."), SLOT(QuickLetter()));
menu->addSeparator();
newManagedAction(menu, "tabular",tr("Quick &Tabular..."), SLOT(QuickTabular()));
newManagedAction(menu, "tabbing",tr("Quick T&abbing..."), SLOT(QuickTabbing()));
newManagedAction(menu, "array",tr("Quick &Array..."), SLOT(QuickArray()));
newManagedAction(menu, "graphic",tr("Insert &Graphic..."), SLOT(QuickGraphics()), QKeySequence(), "image");
#ifdef Q_OS_WIN
if (QSysInfo::windowsVersion() >= QSysInfo::WV_WINDOWS7) {
newManagedAction(menu, "math",tr("Math Assistant..."), SLOT(QuickMath()), QKeySequence(), "TexTablet");
}
#endif
menu=newManagedMenu("main/bibliography",tr("&Bibliography"));
if (!bibtexEntryActions) {
bibtexEntryActions = new QActionGroup(this);
foreach (const BibTeXType& bt, BibTeXDialog::getPossibleEntryTypes(BibTeXDialog::BIBTEX)) {
QAction *act = newManagedAction(menu,"bibtex/"+bt.name.mid(1), bt.description, SLOT(InsertBibEntryFromAction()));
act->setData(bt.name);
act->setActionGroup(bibtexEntryActions);
}
} else {
foreach (const BibTeXType& bt, BibTeXDialog::getPossibleEntryTypes(BibTeXDialog::BIBTEX))
newManagedAction(menu,"bibtex/"+bt.name.mid(1), bt.description, SLOT(InsertBibEntryFromAction()))->setData(bt.name);
}
if (!biblatexEntryActions) {
biblatexEntryActions = new QActionGroup(this);
foreach (const BibTeXType& bt, BibTeXDialog::getPossibleEntryTypes(BibTeXDialog::BIBLATEX)) {
QAction *act = newManagedAction(menu,"biblatex/"+bt.name.mid(1), bt.description, SLOT(InsertBibEntryFromAction()));
act->setData(bt.name);
act->setActionGroup(biblatexEntryActions);
}
} else {
foreach (const BibTeXType& bt, BibTeXDialog::getPossibleEntryTypes(BibTeXDialog::BIBLATEX))
newManagedAction(menu,"biblatex/"+bt.name.mid(1), bt.description, SLOT(InsertBibEntryFromAction()))->setData(bt.name);
}
menu->addSeparator();
newManagedEditorAction(menu, "clean", tr("&Clean"), "cleanBib");
menu->addSeparator();
newManagedAction(menu, "dialog", tr("&Insert Bibliography Entry..."), SLOT(InsertBibEntry()));
menu->addSeparator();
QMenu *bibTypeMenu = newManagedMenu(menu, "type", tr("Type"));
if (!bibTypeActions) {
bibTypeActions = new QActionGroup(this);
bibTypeActions->setExclusive(true);
act = newManagedAction(bibTypeMenu, "bibtex", tr("BibTeX"), SLOT(SetBibTypeFromAction()));
act->setData("bibtex");
act->setCheckable("true");
act->setChecked(true);
bibTypeActions->addAction(act);
act = newManagedAction(bibTypeMenu, "biblatex", tr("BibLaTeX"), SLOT(SetBibTypeFromAction()));
act->setData("biblatex");
act->setCheckable("true");
bibTypeActions->addAction(act);
}
act = newManagedAction(bibTypeMenu, "bibtex", tr("BibTeX"), SLOT(SetBibTypeFromAction()));
act = newManagedAction(bibTypeMenu, "biblatex", tr("BibLaTeX"), SLOT(SetBibTypeFromAction()));
act->trigger(); // initialize menu for specified type
// User
menu=newManagedMenu("main/macros",tr("Ma&cros"));
updateUserMacros();
scriptengine::macros = &configManager.completerConfig->userMacros;
//---view---
menu=newManagedMenu("main/view",tr("&View"));
newManagedAction(menu, "prevdocument",tr("Previous Document"), SLOT(gotoPrevDocument()), QList<QKeySequence>() << Qt::CTRL+Qt::Key_PageUp << Qt::CTRL+Qt::SHIFT+Qt::Key_Tab);
newManagedAction(menu, "nextdocument",tr("Next Document"), SLOT(gotoNextDocument()), QList<QKeySequence>() << Qt::CTRL+Qt::Key_PageDown << Qt::CTRL+Qt::Key_Tab);
newManagedMenu(menu, "documents",tr("Open Documents"));
newManagedAction(menu, "documentlist",tr("List Of Open Documents"), SLOT(viewDocumentList()));
newManagedAction(menu, "focuseditor", tr("Focus Editor"), SLOT(focusEditor()), QList<QKeySequence>() << Qt::ALT+Qt::CTRL+Qt::Key_Left);
newManagedAction(menu, "focusviewer", tr("Focus Viewer"), SLOT(focusViewer()), QList<QKeySequence>() << Qt::ALT+Qt::CTRL+Qt::Key_Right);
menu->addSeparator();
newManagedAction(menu, "structureview",leftPanel->toggleViewAction());
newManagedAction(menu, "outputview",outputView->toggleViewAction());
newManagedAction(menu, "enlargePDF",tr("Show embedded PDF large"),SLOT(enlargeEmbeddedPDFViewer()));
newManagedAction(menu, "shrinkPDF",tr("Show embedded PDF small"),SLOT(shrinkEmbeddedPDFViewer()));
newManagedAction(menu, "closesomething",tr("Close Something"), SLOT(viewCloseSomething()), Qt::Key_Escape);
menu->addSeparator();
submenu=newManagedMenu(menu, "collapse", tr("Collapse"));
newManagedEditorAction(submenu, "all", tr("Everything"), "foldEverything", 0, "", QList<QVariant>() << false);
newManagedAction(submenu, "block", tr("Nearest Block"), SLOT(viewCollapseBlock()));
for (int i=1; i<=4; i++)
newManagedEditorAction(submenu, QString::number(i), tr("Level %1").arg(i), "foldLevel", 0, "", QList<QVariant>() << false << i);
submenu=newManagedMenu(menu, "expand", tr("Expand"));
newManagedEditorAction(submenu, "all", tr("Everything"), "foldEverything", 0, "", QList<QVariant>() << true);
newManagedAction(submenu, "block", tr("Nearest Block"), SLOT(viewExpandBlock()));
for (int i=1; i<=4; i++)
newManagedEditorAction(submenu, QString::number(i), tr("Level %1").arg(i), "foldLevel", 0, "", QList<QVariant>() << true << i);
submenu=newManagedMenu(menu, "grammar", tr("Grammar errors"));
static bool showGrammarType[8] = {false};
for (int i=0;i<8;i++) configManager.registerOption(QString("Grammar/Display Error %1").arg(i), &showGrammarType[i], true);
newManagedAction(submenu, "0", tr("Word Repetition"), "toggleGrammar", 0, "", QList<QVariant>() << 0);
newManagedAction(submenu, "1", tr("Long-range Word Repetition"), "toggleGrammar", 0, "", QList<QVariant>() << 1);
newManagedAction(submenu, "2", tr("Bad words"), "toggleGrammar", 0, "", QList<QVariant>() << 2);
newManagedAction(submenu, "3", tr("Grammar Mistake"), "toggleGrammar", 0, "", QList<QVariant>() << 3);
for (int i=4;i<8;i++)
newManagedAction(submenu, QString("%1").arg(i), tr("Grammar Mistake Special %1").arg(i-3), "toggleGrammar", 0, "", QList<QVariant>() << i);
for (int i=0;i<submenu->actions().size();i++)
if (!submenu->actions()[i]->isCheckable()){
submenu->actions()[i]->setCheckable(true);
configManager.linkOptionToObject(&showGrammarType[i], submenu->actions()[i], 0);
LatexEditorView::setGrammarOverlayDisabled(i,!submenu->actions()[i]->isChecked());
}
menu->addSeparator();
newManagedAction(menu, "alignwindows", tr("Align Windows"), SLOT(viewAlignWindows()));
fullscreenModeAction=newManagedAction(menu, "fullscreenmode",tr("Fullscreen Mode"));
fullscreenModeAction->setCheckable(true);
connectUnique(fullscreenModeAction, SIGNAL(toggled(bool)), this, SLOT(setFullScreenMode()));
connectUnique(menuBar(), SIGNAL(doubleClicked()), fullscreenModeAction, SLOT(toggle()));
menu->addSeparator();
QMenu *hlMenu = newManagedMenu(menu, "highlighting", tr("Highlighting"));
if (!highlightLanguageActions) {
highlightLanguageActions = new QActionGroup(this);
highlightLanguageActions->setExclusive(true);
connect(highlightLanguageActions, SIGNAL(triggered(QAction*)), this, SLOT(viewSetHighlighting(QAction*)));
connect(hlMenu, SIGNAL(aboutToShow()), this, SLOT(showHighlightingMenu()));
int id = 0;
foreach (const QString &s, m_languages->languages()) {
#ifdef QT_NO_DEBUG
if (s == "TXS Test Results") continue;
#endif
QAction *act = newManagedAction(hlMenu, QString::number(id++), tr(qPrintable(s)));
act->setData(s);
act->setCheckable(true);
hlMenu->addAction(act);
highlightLanguageActions->addAction(act);
}
} else {
int id = 0;
foreach (const QString &s, m_languages->languages())
newManagedAction(hlMenu, QString::number(id++), tr(qPrintable(s)));
}
//---options---
menu=newManagedMenu("main/options",tr("&Options"));
newManagedAction(menu, "config",tr("&Configure TeXstudio..."), SLOT(GeneralOptions()), 0,"configure")->setMenuRole(QAction::PreferencesRole);
menu->addSeparator();
newManagedAction(menu, "loadProfile",tr("Load &Profile..."), SLOT(loadProfile()));
newManagedAction(menu, "saveProfile",tr("S&ave Profile..."), SLOT(saveProfile()));
newManagedAction(menu, "saveSettings",tr("Save Current Settings","menu"), SLOT(SaveSettings()));
menu->addSeparator();
ToggleAct=newManagedAction(menu, "masterdocument",tr("Define Current Document as '&Master Document'"), SLOT(ToggleMode()));
ToggleRememberAct=newManagedAction(menu, "remembersession",tr("Automatically Restore &Session at Next Start"));
ToggleRememberAct->setCheckable(true);
//---help---
menu=newManagedMenu("main/help",tr("&Help"));
newManagedAction(menu, "latexreference",tr("LaTeX Reference..."), SLOT(LatexHelp()), 0,"help");
newManagedAction(menu, "usermanual",tr("User Manual..."), SLOT(UserManualHelp()), 0,"help");
newManagedAction(menu, "texdocdialog", tr("Packages Help..."), SLOT(TexdocHelp()));
menu->addSeparator();
newManagedAction(menu, "checkinstall",tr("Check LaTeX Installation"), SLOT(checkLatexInstall()));
newManagedAction(menu, "appinfo",tr("About TeXstudio..."), SLOT(HelpAbout()), 0,"appicon")->setMenuRole(QAction::AboutRole);
//additional elements for development
//-----context menus-----
if (LatexEditorView::getBaseActions().empty()) { //only called at first menu created
QList<QAction*> baseContextActions;
QAction *sep = new QAction(menu);
sep->setSeparator(true);
baseContextActions << getManagedActions(QStringList() << "copy" << "cut" << "paste", "main/edit/");
baseContextActions << getManagedActions(QStringList() << "main/edit2/pasteAsLatex" << "main/edit2/convertTo" << "main/edit/selectall");
baseContextActions << sep;
baseContextActions << getManagedActions(QStringList() << "previewLatex" << "removePreviewLatex", "main/edit2/");
LatexEditorView::setBaseActions(baseContextActions);
}
structureTreeView->setObjectName("StructureTree");
structureTreeView->setContextMenuPolicy(Qt::CustomContextMenu);
newManagedAction(structureTreeView,"CopySection",tr("Copy"), SLOT(editSectionCopy()));
newManagedAction(structureTreeView,"CutSection",tr("Cut"), SLOT(editSectionCut()));
newManagedAction(structureTreeView,"PasteBefore",tr("Paste Before"), SLOT(editSectionPasteBefore()));
newManagedAction(structureTreeView,"PasteAfter",tr("Paste After"), SLOT(editSectionPasteAfter()));
QAction* sep = new QAction(structureTreeView);
sep->setSeparator(true);
structureTreeView->addAction(sep);
newManagedAction(structureTreeView,"IndentSection",tr("Indent Section"), SLOT(editIndentSection()));
newManagedAction(structureTreeView,"UnIndentSection",tr("Unindent Section"), SLOT(editUnIndentSection()));
connect(structureTreeView,SIGNAL(customContextMenuRequested(QPoint)),this,SLOT(StructureContextMenu(QPoint)));
configManager.updateRecentFiles(true);
configManager.modifyMenuContents();
configManager.modifyManagedShortcuts();
}
void Texmaker::setupToolBars() {
//This method will be called multiple times and must not create something if this something already exists
configManager.watchedMenus.clear();
//customizable toolbars
//first apply custom icons
QMap<QString, QVariant>::const_iterator i = configManager.replacedIconsOnMenus.constBegin();
while (i != configManager.replacedIconsOnMenus.constEnd()) {
QString id=i.key();
QVariant zw=i.value();
QObject *obj=configManager.menuParent->findChild<QObject*>(id);
QAction *act=qobject_cast<QAction*>(obj);
if (act && zw.canConvert<QString>()) act->setIcon(QIcon(zw.toString()));
//qDebug() << "Icon:" << id << zw.toString();
++i;
}
//setup customizable toolbars
for (int i=0;i<configManager.managedToolBars.size();i++){
ManagedToolBar &mtb = configManager.managedToolBars[i];
if (!mtb.toolbar) { //create actual toolbar on first call
if (mtb.name == "Central") mtb.toolbar = centralToolBar;
else mtb.toolbar = addToolBar(tr(qPrintable(mtb.name)));
mtb.toolbar->setObjectName(mtb.name);
addAction(mtb.toolbar->toggleViewAction());
if(mtb.name=="Spelling") addToolBarBreak();
} else mtb.toolbar->clear();
foreach (const QString& actionName, mtb.actualActions){
if (actionName == "separator") mtb.toolbar->addSeparator(); //Case 1: Separator
else if (actionName.startsWith("tags/")) {
//Case 2: One of the xml tag widgets mapped on a toolbutton
int tagCategorySep=actionName.indexOf("/",5);
XmlTagsListWidget* tagsWidget = findChild<XmlTagsListWidget*>(actionName.left(tagCategorySep));
if (!tagsWidget) continue;
if(!tagsWidget->isPopulated())
tagsWidget->populate();
QStringList list=tagsWidget->tagsTxtFromCategory(actionName.mid(tagCategorySep+1));
if (list.isEmpty()) continue;
QToolButton* combo=createComboToolButton(mtb.toolbar,list,QList<QIcon>(),0,this,SLOT(insertXmlTagFromToolButtonAction()));
combo->setProperty("tagsID", actionName);
mtb.toolbar->addWidget(combo);
} else {
QObject *obj=configManager.menuParent->findChild<QObject*>(actionName);
QAction *act=qobject_cast<QAction*>(obj);
if (act) {
//Case 3: A normal QAction
if(act->icon().isNull())
act->setIcon(QIcon("appicon"));
mtb.toolbar->addAction(act);
} else {
QMenu* menu=qobject_cast<QMenu*>(obj);
if (!menu) {
qWarning("Unknown toolbar command %s", qPrintable(actionName));
continue;
}
//Case 4: A submenu mapped on a toolbutton
configManager.watchedMenus << actionName;
QStringList list;
QList<QIcon> icons;
foreach (const QAction* act, menu->actions())
if (!act->isSeparator()) {
list.append(act->text());
icons.append(act->icon());
}
//TODO: Is the callToolButtonAction()-slot really needed? Can't we just add the menu itself as the menu of the qtoolbutton, without creating a copy? (should be much faster)
QToolButton* combo=createComboToolButton(mtb.toolbar,list,icons,0,this,SLOT(callToolButtonAction()));
combo->setProperty("menuID", actionName);
mtb.toolbar->addWidget(combo);
}
}
}
if(mtb.actualActions.empty()) mtb.toolbar->setVisible(false);
}
}
void Texmaker::UpdateAvailableLanguages() {
if (spellLanguageActions) delete spellLanguageActions;
spellLanguageActions = new QActionGroup(statusTbLanguage);
spellLanguageActions->setExclusive(true);
foreach (const QString& s, spellerManager.availableDicts()) {
QAction *act = new QAction(spellLanguageActions);
act->setText(spellerManager.prettyName(s));
act->setData(QVariant(s));
act->setCheckable(true);
connect(act, SIGNAL(triggered()), this, SLOT(ChangeEditorSpeller()));
}
QAction *act = new QAction(spellLanguageActions);
act->setSeparator(true);
act = new QAction(spellLanguageActions);
act->setText(tr("Default")+QString(": %1").arg(spellerManager.prettyName(spellerManager.defaultSpellerName())));
act->setData(QVariant("<default>"));
connect(act, SIGNAL(triggered()), this, SLOT(ChangeEditorSpeller()));
act->setCheckable(true);
act->setChecked(true);
act = new QAction(spellLanguageActions);
act->setSeparator(true);
act = new QAction(spellLanguageActions);
act->setText(tr("Insert language as TeX comment"));
connect(act, SIGNAL(triggered()), this, SLOT(InsertSpellcheckMagicComment()));
statusTbLanguage->addActions(spellLanguageActions->actions());
if (currentEditorView()) {
EditorSpellerChanged(currentEditorView()->getSpeller());
} else {
EditorSpellerChanged("<default>");
}
}
void Texmaker::createStatusBar() {
QStatusBar * status=statusBar();
status->setContextMenuPolicy(Qt::PreventContextMenu);
QAction *act;
QToolButton *tb;
act = getManagedAction("main/view/structureview");
if (act) {
tb = new QToolButton(status);
tb->setCheckable(true);
tb->setChecked(act->isChecked());
tb->setAutoRaise(true);
tb->setIcon(act->icon());
tb->setToolTip(act->toolTip());
connect(tb, SIGNAL(clicked()), act, SLOT(trigger()));
connect(act, SIGNAL(toggled(bool)), tb, SLOT(setChecked(bool)));
status->addPermanentWidget(tb, 0);
}
act = getManagedAction("main/view/outputview");
if (act) {
tb = new QToolButton(status);
tb->setCheckable(true);
tb->setChecked(act->isChecked());
tb->setAutoRaise(true);
tb->setIcon(act->icon());
tb->setToolTip(act->toolTip());
connect(tb, SIGNAL(clicked()), act, SLOT(trigger()));
connect(act, SIGNAL(toggled(bool)), tb, SLOT(setChecked(bool)));
status->addPermanentWidget(tb, 0);
}
// spacer eating up all the space between "left" and "right" permanent widgets.
QLabel* messageArea = new QLabel(status);
connect(status, SIGNAL(messageChanged(QString)), messageArea, SLOT(setText(QString)));
status->addPermanentWidget(messageArea, 1);
// language
statusTbLanguage = new QToolButton(status);
statusTbLanguage->setToolTip(tr("Language"));
statusTbLanguage->setPopupMode(QToolButton::InstantPopup);
statusTbLanguage->setAutoRaise(true);
statusTbLanguage->setMinimumWidth(status->fontMetrics().width("OOOOOOO"));
connect(&spellerManager, SIGNAL(dictPathChanged()), this, SLOT(UpdateAvailableLanguages()));
connect(&spellerManager, SIGNAL(defaultSpellerChanged()), this, SLOT(UpdateAvailableLanguages()));
UpdateAvailableLanguages();
statusTbLanguage->setText(spellerManager.defaultSpellerName());
status->addPermanentWidget(statusTbLanguage,0);
// encoding
statusTbEncoding = new QToolButton(status);
statusTbEncoding->setToolTip(tr("Encoding"));
statusTbEncoding->setText(tr("Encoding")+ " ");
statusTbEncoding->setPopupMode(QToolButton::InstantPopup);
statusTbEncoding->setAutoRaise(true);
statusTbEncoding->setMinimumWidth(status->fontMetrics().width("OOOOO"));
QSet<int> encodingMibs;
foreach (const QString& s, configManager.commonEncodings) {
QTextCodec *codec = QTextCodec::codecForName(s.toLocal8Bit());
if (!codec) continue;
encodingMibs.insert(codec->mibEnum());
}
foreach (int mib, encodingMibs) {
QAction *act = new QAction(statusTbEncoding);
act->setText(QTextCodec::codecForMib(mib)->name());
act->setData(mib);
statusTbEncoding->addAction(act);
connect(act, SIGNAL(triggered()), this, SLOT(changeTextCodec()));
}
act = new QAction(statusTbEncoding);
act->setSeparator(true);
statusTbEncoding->addAction(act);
act = new QAction(statusTbEncoding);
act->setText(tr("More Encodings..."));
statusTbEncoding->addAction(act);
connect(act, SIGNAL(triggered()), this, SLOT(editSetupEncoding()));
act = new QAction(statusTbEncoding);
act->setSeparator(true);
statusTbEncoding->addAction(act);
act = new QAction(statusTbEncoding);
act->setText(tr("Insert encoding as TeX comment"));
statusTbEncoding->addAction(act);
connect(act, SIGNAL(triggered()), this, SLOT(addMagicCoding()));
status->addPermanentWidget(statusTbEncoding,0);
statusLabelMode=new QLabel(status);
statusLabelProcess=new QLabel(status);
status->addPermanentWidget(statusLabelProcess, 0);
status->addPermanentWidget(statusLabelMode, 0);
for (int i=1; i<=3; i++) {
QPushButton* pb = new QPushButton(getRealIcon(QString("bookmark%1").arg(i)), "", status);
pb->setToolTip(tr("Click to jump to the bookmark"));
connect(pb, SIGNAL(clicked()), getManagedAction(QString("main/edit/gotoBookmark/bookmark%1").arg(i)), SIGNAL(triggered()));
pb->setMaximumSize(20,20);
pb->setFlat(true);
status->addPermanentWidget(pb, 0);
}
}
void Texmaker::UpdateCaption() {
if (!currentEditorView()) documents.currentDocument=0;
else {
documents.currentDocument=currentEditorView()->document;
documents.updateStructure();
structureTreeView->setExpanded(documents.model->index(documents.currentDocument->baseStructure),true);
}
if(completer && completer->isVisible()) completer->close();
QString title;
if (!currentEditorView()) {
title=TEXSTUDIO;
} else {
QString file = QDir::toNativeSeparators(getCurrentFileName());
if (file.isEmpty() && EditorTabs->currentIndex()>=0)
file = EditorTabs->tabText(EditorTabs->currentIndex());
title = file + " - " + TEXSTUDIO;
if (currentEditorView()->editor) {
NewDocumentStatus();
NewDocumentLineEnding();
//currentEditorView()->editor->setFocus();
}
}
setWindowTitle(title);
//updateStructure();
updateUndoRedoStatus();
cursorPositionChanged();
if (documents.singleMode()) {
//outputView->resetMessagesAndLog();
if(currentEditorView()) completerNeedsUpdate();
}
QString finame=getCurrentFileName();
if (finame!="") configManager.lastDocument=finame;
}
void Texmaker::updateMasterDocumentCaption(){
if (documents.singleMode()){
ToggleAct->setText(tr("Define Current Document as 'Master Document'"));
statusLabelMode->setText(QString(" %1 ").arg(tr("Normal Mode")));
} else {
QString shortName = documents.masterDocument->getFileInfo().fileName();
ToggleAct->setText(tr("Normal Mode (current master document: ")+shortName+")");
statusLabelMode->setText(QString(" %1 ").arg(tr("Master Document")+ ": "+shortName));
}
}
void Texmaker::currentEditorChanged() {
UpdateCaption();
if (!currentEditorView()) return;
if (configManager.watchedMenus.contains("main/view/documents"))
updateToolBarMenu("main/view/documents");
if (currentEditorView()) {
EditorSpellerChanged(currentEditorView()->getSpeller());
currentEditorView()->lastUsageTime = QDateTime::currentDateTime();
}
}
void Texmaker::EditorTabMoved(int from,int to){
//documents.aboutToUpdateLayout();
documents.move(from,to);
//documents.updateLayout();
updateOpenDocumentMenu(false);
}
void Texmaker::editorAboutToChangeByTabClick(LatexEditorView *edFrom, LatexEditorView *edTo) {
Q_UNUSED(edTo);
saveEditorCursorToHistory(edFrom);
}
void Texmaker::showMarkTooltipForLogMessage(QList<int> errors) {
if (!currentEditorView()) return;
REQUIRE(outputView->getLogWidget());
REQUIRE(outputView->getLogWidget()->getLogModel());
QString msg = outputView->getLogWidget()->getLogModel()->htmlErrorTable(errors);
currentEditorView()->setLineMarkToolTip(msg);
}
void Texmaker::NewDocumentStatus() {
LatexEditorView* edView = currentEditorView();
if (!edView) return;
int index=EditorTabs->currentIndex();
if (qobject_cast<QEditor*>(sender()) && edView->editor!=sender()){
edView=0;
for (int i=0;i<EditorTabs->count();i++)
if (qobject_cast<LatexEditorView*>(EditorTabs->widget(i))->editor==sender()){
edView= qobject_cast<LatexEditorView*>(EditorTabs->widget(i));
index=i;
break;
}
if (!edView) return;
}
QEditor * ed = edView->editor;
actSave->setEnabled(ed->isContentModified() || ed->fileName().isEmpty());
static QIcon modified = getRealIcon("modified"), empty = QIcon(":/images/empty.png"); //cache icons, getRealIcon is *really* slow
EditorTabs->setTabIcon(index, ed->isContentModified() ? modified : empty);
QString tabText = edView->displayName().replace("&", "&&");
if (EditorTabs->tabText(index) != tabText) {
EditorTabs->setTabText(index, tabText);
updateOpenDocumentMenu(true);
}
// child ?
LatexDocument *doc=edView->document;
LatexDocument *masterDoc=doc->getTopMasterDocument();
QString tooltip=QDir::toNativeSeparators(ed->fileName());
if(masterDoc!=doc){
tooltip+=tr("\nincluded document in %1").arg(masterDoc->getName());
}
EditorTabs->setTabToolTip(index, tooltip);
if (currentEditorView()->editor->getFileCodec()) {
QTextCodec *codec = currentEditorView()->editor->getFileCodec();
statusTbEncoding->setText(codec->name()+" ");
QStringList aliases;
foreach (const QByteArray& b, codec->aliases()) {
aliases << QString(b);
}
if (!aliases.isEmpty()) {
statusTbEncoding->setToolTip(tr("Encoding Aliases: ") + aliases.join(", "));
} else {
statusTbEncoding->setToolTip(tr("Encoding"));
}
}
else {
statusTbEncoding->setText(tr("Encoding")+" ");
statusTbEncoding->setToolTip(tr("Encoding"));
}
}
void Texmaker::NewDocumentLineEnding(){
if (!currentEditorView()) return;
QDocument::LineEnding le = currentEditorView()->editor->document()->lineEnding();
if (le==QDocument::Conservative) le= currentEditorView()->editor->document()->originalLineEnding();
switch (le) {
#ifdef Q_OS_WIN32
case QDocument::Local:
#endif
case QDocument::Windows:
getManagedAction("main/edit/lineend/crlf")->setChecked(true);
break;
case QDocument::Mac:
getManagedAction("main/edit/lineend/cr")->setChecked(true);
break;
default:
getManagedAction("main/edit/lineend/lf")->setChecked(true);
}
}
void Texmaker::updateUndoRedoStatus() {
if (currentEditor()) {
actSave->setEnabled(!currentEditor()->document()->isClean() || currentEditor()->fileName().isEmpty());
bool canUndo=currentEditor()->document()->canUndo();
if(!canUndo && configManager.svnUndo){
QVariant zw=currentEditor()->property("undoRevision");
int undoRevision=zw.canConvert<int>()?zw.toInt():0;
if(undoRevision>=0)
canUndo=true;
}
actUndo->setEnabled(canUndo);
actRedo->setEnabled(currentEditor()->document()->canRedo());
} else {
actSave->setEnabled(false);
actUndo->setEnabled(false);
actRedo->setEnabled(false);
}
}
LatexEditorView *Texmaker::currentEditorView() const {
return EditorTabs->currentEditorView();
}
QEditor* Texmaker::currentEditor() const{
LatexEditorView* edView = currentEditorView();
if (!edView) return 0;
return edView->editor;
}
void Texmaker::configureNewEditorView(LatexEditorView *edit) {
REQUIRE(m_languages);REQUIRE(edit->codeeditor);
m_languages->setLanguage(edit->codeeditor->editor(), ".tex");
//edit->setFormats(m_formats->id("environment"),m_formats->id("referenceMultiple"),m_formats->id("referencePresent"),m_formats->id("referenceMissing"));
connect(edit->editor, SIGNAL(undoAvailable(bool)), this, SLOT(updateUndoRedoStatus()));
connect(edit->editor, SIGNAL(requestClose()),&documents,SLOT(requestedClose()));
connect(edit->editor, SIGNAL(redoAvailable(bool)), this, SLOT(updateUndoRedoStatus()));
connect(edit->editor, SIGNAL(contentModified(bool)), this, SLOT(NewDocumentStatus()));
connect(edit->editor->document(), SIGNAL(lineEndingChanged(int)), this, SLOT(NewDocumentLineEnding()));
connect(edit->editor, SIGNAL(cursorPositionChanged()), this, SLOT(cursorPositionChanged()));
connect(edit->editor, SIGNAL(cursorHovered()), this, SLOT(cursorHovered()));
connect(edit->editor, SIGNAL(emitWordDoubleClicked()), this, SLOT(cursorHovered()));
connect(edit, SIGNAL(showMarkTooltipForLogMessage(QList<int>)),this,SLOT(showMarkTooltipForLogMessage(QList<int>)));
connect(edit, SIGNAL(needCitation(const QString&)),this,SLOT(InsertBibEntry(const QString&)));
connect(edit, SIGNAL(showPreview(QString)),this,SLOT(showPreview(QString)));
connect(edit, SIGNAL(showImgPreview(QString)),this,SLOT(showImgPreview(QString)));
connect(edit, SIGNAL(showPreview(QDocumentCursor)),this,SLOT(showPreview(QDocumentCursor)));
connect(edit, SIGNAL(gotoDefinition(QDocumentCursor)),this,SLOT(editGotoDefinition(QDocumentCursor)));
connect(edit, SIGNAL(syncPDFRequested(QDocumentCursor)), this, SLOT(syncPDFViewer(QDocumentCursor)));
connect(edit, SIGNAL(openFile(QString)),this,SLOT(openExternalFile(QString)));
connect(edit, SIGNAL(openFile(QString,QString)),this,SLOT(openExternalFile(QString,QString)));
connect(edit, SIGNAL(bookmarkRemoved(QDocumentLineHandle*)), bookmarks, SLOT(bookmarkDeleted(QDocumentLineHandle*)));
connect(edit, SIGNAL(bookmarkAdded(QDocumentLineHandle*,int)), bookmarks, SLOT(bookmarkAdded(QDocumentLineHandle*,int)));
connect(edit, SIGNAL(mouseBackPressed()), this, SLOT(goBack()));
connect(edit, SIGNAL(mouseForwardPressed()), this, SLOT(goForward()));
connect(edit, SIGNAL(cursorChangeByMouse()), this, SLOT(saveCurrentCursorToHistory()));
connect(edit, SIGNAL(colonTyped()), this, SLOT(NormalCompletion()));
connect(edit, SIGNAL(openInternalDocViewer(QString,QString)),this,SLOT(openInternalDocViewer(QString,QString)));
connect(edit, SIGNAL(searchExtendToggled(bool)),this,SLOT(searchExtendToggled(bool)));
connect(edit->editor,SIGNAL(fileReloaded()),this,SLOT(fileReloaded()));
connect(edit->editor,SIGNAL(fileInConflict()),this,SLOT(fileInConflict()));
connect(edit->editor,SIGNAL(fileAutoReloading(QString)),this,SLOT(fileAutoReloading(QString)));
if (Guardian::instance()) { // Guardian is not yet there when this is called at program startup
connect(edit->editor,SIGNAL(slowOperationStarted()), Guardian::instance(), SLOT(slowOperationStarted()));
connect(edit->editor,SIGNAL(slowOperationEnded()), Guardian::instance(), SLOT(slowOperationEnded()));
}
connect(edit, SIGNAL(linesChanged(QString,const void*,QList<LineInfo>,int)), grammarCheck, SLOT(check(QString,const void*,QList<LineInfo>,int)));
connect(edit, SIGNAL(spellerChanged(QString)), this, SLOT(EditorSpellerChanged(QString)));
edit->setSpellerManager(&spellerManager);
edit->setSpeller("<default>");
}
//complete the new editor view configuration (edit->document is set)
void Texmaker::configureNewEditorViewEnd(LatexEditorView *edit,bool reloadFromDoc,bool hidden){
REQUIRE(edit->document);
//patch Structure
//disconnect(edit->editor->document(),SIGNAL(contentsChange(int, int))); // force order of contentsChange update
connect(edit->editor->document(),SIGNAL(contentsChange(int, int)),edit->document,SLOT(patchStructure(int,int)));
//connect(edit->editor->document(),SIGNAL(contentsChange(int, int)),edit,SLOT(documentContentChanged(int,int))); now directly called by patchStructure
connect(edit->editor->document(),SIGNAL(lineRemoved(QDocumentLineHandle*)),edit->document,SLOT(patchStructureRemoval(QDocumentLineHandle*)));
connect(edit->editor->document(),SIGNAL(lineDeleted(QDocumentLineHandle*)),edit->document,SLOT(patchStructureRemoval(QDocumentLineHandle*)));
connect(edit->document,SIGNAL(updateCompleter()),this,SLOT(completerNeedsUpdate()));
connect(edit->editor,SIGNAL(needUpdatedCompleter()), this, SLOT(needUpdatedCompleter()));
connect(edit->document,SIGNAL(importPackage(QString)),this,SLOT(importPackage(QString)));
connect(edit->document, SIGNAL(bookmarkLineUpdated(int)), bookmarks, SLOT(updateLineWithBookmark(int)));
connect(edit,SIGNAL(thesaurus(int,int)),this,SLOT(editThesaurus(int,int)));
connect(edit,SIGNAL(changeDiff(QPoint)),this,SLOT(editChangeDiff(QPoint)));
connect(edit,SIGNAL(saveCurrentCursorToHistoryRequested()),this,SLOT(saveCurrentCursorToHistory()));
edit->document->saveLineSnapshot(); // best guess of the lines used during last latex compilation
if(!hidden){
EditorTabs->insertEditor(edit, reloadFromDoc ? documents.documents.indexOf(edit->document,0) : -1);
updateOpenDocumentMenu(false);
edit->editor->setFocus();
UpdateCaption();
NewDocumentStatus();
}
}
LatexEditorView* Texmaker::getEditorViewFromFileName(const QString &fileName, bool checkTemporaryNames){
LatexDocument* document=documents.findDocument(fileName, checkTemporaryNames);
if (!document) return 0;
return document->getEditorView();
}
QString Texmaker::getCurrentFileName() {
return documents.getCurrentFileName();
}
QString Texmaker::getAbsoluteFilePath(const QString & relName, const QString &extension){
return documents.getAbsoluteFilePath(relName, extension);
}
QString Texmaker::getRelativeFileName(const QString & file,QString basepath,bool keepSuffix){
return getRelativeBaseNameToPath(file,basepath,true,keepSuffix);
}
bool Texmaker::ActivateEditorForFile(QString f, bool checkTemporaryNames, bool setFocus) {
LatexEditorView* edView = getEditorViewFromFileName(f, checkTemporaryNames);
if (!edView) return false;
saveCurrentCursorToHistory();
if (!EditorTabs->containsEditor(edView)) return false;
EditorTabs->setCurrentEditor(edView);
if (setFocus) {
edView->editor->setFocus();
}
return true;
}
///////////////////FILE//////////////////////////////////////
LatexEditorView *Texmaker::editorViewForLabel(LatexDocument *doc, const QString &label) {
// doc can be any document, in which the label is valid
REQUIRE_RET(doc, 0);
QMultiHash<QDocumentLineHandle*,int> result = doc->getLabels(label);
if (result.count() <= 0) return 0;
QDocumentLine line(result.keys().first());
LatexDocument *targetDoc = qobject_cast<LatexDocument *>(line.document());
REQUIRE_RET(targetDoc, 0);
return qobject_cast<LatexEditorView *>(targetDoc->getEditorView());
}
void guessLanguageFromContent(QLanguageFactory* m_languages, QEditor* e){
QDocument* doc = e->document();
if (doc->lineCount() == 0) return;
if (doc->line(0).text().startsWith("<?xml") ||
doc->line(0).text().startsWith("<!DOCTYPE"))
m_languages->setLanguage(e, ".xml");
}
LatexEditorView* Texmaker::load(const QString &f , bool asProject, bool hidden,bool recheck) {
QString f_real=f;
#ifdef Q_OS_WIN32
QRegExp regcheck("/([a-zA-Z]:[/\\\\].*)");
if (regcheck.exactMatch(f)) f_real=regcheck.cap(1);
#endif
#ifndef NO_POPPLER_PREVIEW
if (f_real.endsWith(".pdf",Qt::CaseInsensitive)) {
if (PDFDocument::documentList().isEmpty())
newPdfPreviewer();
PDFDocument::documentList().first()->loadFile(f_real,QString(f_real).replace(".pdf", ".tex"));
PDFDocument::documentList().first()->show();
PDFDocument::documentList().first()->setFocus();
return 0;
}
#endif
if (f_real.endsWith(".log",Qt::CaseInsensitive) &&
txsConfirm(QString("Do you want to load file %1 as LaTeX log file?").arg(QFileInfo(f).completeBaseName()))) {
outputView->getLogWidget()->loadLogFile(f,documents.getTemporaryCompileFileName());
setLogMarksVisible(true);
return 0;
}
if(!hidden)
raise();
//test is already opened
LatexEditorView* existingView = getEditorViewFromFileName(f_real);
LatexDocument *doc;
if (!existingView) {
doc = documents.findDocumentFromName(f_real);
if (doc) existingView = doc->getEditorView();
}
if (existingView) {
if (asProject) documents.setMasterDocument(existingView->document);
if(existingView->document->isHidden()){
existingView->editor->setLineWrapping(configManager.editorConfig->wordwrap>0);
documents.deleteDocument(existingView->document,true);
existingView->editor->setSilentReloadOnExternalChanges(existingView->document->remeberAutoReload);
documents.addDocument(existingView->document,false);
EditorTabs->insertEditor(existingView);
updateOpenDocumentMenu(false);
updateStructure(false,existingView->document,true);
existingView->editor->setFocus();
UpdateCaption();
NewDocumentStatus();
return existingView;
}
EditorTabs->setCurrentEditor(existingView);
return existingView;
}
// find closed master doc
if(doc){
LatexEditorView *edit = new LatexEditorView(0,configManager.editorConfig,doc);
edit->setLatexPackageList(&latexPackageList);
edit->document=doc;
edit->editor->setFileName(doc->getFileName());
disconnect(edit->editor->document(),SIGNAL(contentsChange(int, int)),edit->document,SLOT(patchStructure(int,int)));
configureNewEditorView(edit);
if (edit->editor->fileInfo().suffix()!="tex")
m_languages->setLanguage(edit->editor, f_real);
if (!edit->editor->languageDefinition())
guessLanguageFromContent(m_languages, edit->editor);
doc->setLineEnding(edit->editor->document()->originalLineEnding());
doc->setEditorView(edit); //update file name (if document didn't exist)
configureNewEditorViewEnd(edit,!hidden,hidden);
//edit->document->initStructure();
//updateStructure(true);
if(!hidden){
ShowStructure();
bookmarks->restoreBookmarks(edit);
}
return edit;
}
//load it otherwise
if (!QFile::exists(f_real)) return 0;
QFile file(f_real);
if (!file.open(QIODevice::ReadOnly)) {
if(!hidden)
QMessageBox::warning(this,tr("Error"), tr("You do not have read permission to the file %1.").arg(f_real));
return 0;
}
file.close();
bool bibTeXmodified=documents.bibTeXFilesModified;
doc=new LatexDocument(this);
LatexEditorView *edit = new LatexEditorView(0,configManager.editorConfig,doc);
edit->setLatexPackageList(&latexPackageList);
if(hidden)
edit->editor->setLineWrapping(false); //disable linewrapping in hidden docs to speed-up updates
configureNewEditorView(edit);
edit->document=documents.findDocument(f_real);
if (!edit->document) {
edit->document=doc;
edit->document->setEditorView(edit);
documents.addDocument(edit->document,hidden);
} else edit->document->setEditorView(edit);
if (edit->editor->fileInfo().suffix()!="tex")
m_languages->setLanguage(edit->editor, f_real);
//QTime time;
//time.start();
edit->editor->load(f_real,QDocument::defaultCodec());
if (!edit->editor->languageDefinition())
guessLanguageFromContent(m_languages, edit->editor);
//qDebug() << "Load time: " << time.elapsed();
edit->editor->document()->setLineEndingDirect(edit->editor->document()->originalLineEnding());
edit->document->setEditorView(edit); //update file name (if document didn't exist)
configureNewEditorViewEnd(edit,asProject,hidden);
//check for svn conflict
if(!hidden){
checkSVNConflicted();
MarkCurrentFileAsRecent();
}
documents.updateMasterSlaveRelations(doc,recheck);
if(recheck){
edit->updateLtxCommands();
}
if(!hidden){
if (QFile::exists(f_real + ".recover.bak~")
&& QFileInfo(f_real + ".recover.bak~").lastModified() > QFileInfo(f_real).lastModified()) {
if (txsConfirm(tr("A crash recover file from %1 has been found for \"%2\".\nDo you want to restore it?").arg(QFileInfo(f_real + ".recover.bak~").lastModified().toString()).arg(f_real))){
QFile f(f_real + ".recover.bak~");
if (f.open(QFile::ReadOnly)) {
QByteArray ba = f.readAll();
QString recovered = QTextCodec::codecForMib(MIB_UTF8)->toUnicode(ba); //TODO: chunk loading?
edit->document->setText(recovered, true);
} else txsWarning(tr("Failed to open recover file \"%1\".").arg(f_real + ".recover.bak~"));
}
}
}
updateStructure(true,doc,true);
if(!hidden)
ShowStructure();
bookmarks->restoreBookmarks(edit);
if (asProject) documents.setMasterDocument(edit->document);
if (outputView->getLogWidget()->logPresent()) {
updateLogEntriesInEditors();
setLogMarksVisible(true);
}
if (!bibTeXmodified)
documents.bibTeXFilesModified=false; //loading a file can change the list of included bib files, but we won't consider that as a modification of them, because then they don't have to be recompiled
LatexDocument* master = edit->document->getTopMasterDocument();
if (master) foreach (const FileNamePair& fnp, edit->document->mentionedBibTeXFiles().values()) {
Q_ASSERT(!fnp.absolute.isEmpty());
master->lastCompiledBibTeXFiles.insert(fnp.absolute);
}
#ifndef Q_OS_MAC
if(!hidden){
if (windowState() == Qt::WindowMinimized || !isVisible() || !QApplication::activeWindow()) {
show();
if (windowState()==Qt::WindowMinimized)
setWindowState((windowState() & ~Qt::WindowMinimized) | Qt::WindowActive);
show();
raise();
QApplication::setActiveWindow(this);
activateWindow();
setFocus();
edit->editor->setFocus();
}
}
//raise();
//#ifdef Q_OS_WIN32
// if (IsIconic (this->winId())) ShowWindow(this->winId(), SW_RESTORE);
//#endif
#endif
runScriptsInList(Macro::ST_LOAD_THIS_FILE, doc->localMacros);
emit infoLoadFile(f_real);
return edit;
}
void Texmaker::completerNeedsUpdate(){
mCompleterNeedsUpdate=true;
}
void Texmaker::needUpdatedCompleter(){
if (mCompleterNeedsUpdate)
updateCompleter();
}
void Texmaker::updateUserToolMenu(){
CommandMapping cmds = buildManager.getAllCommands();
QStringList order = buildManager.getCommandsOrder();
QStringList ids;
QStringList displayName;
for (int i=0;i<order.size();i++){
const CommandInfo &ci = cmds.value(order[i]);
if (!ci.user) continue;
ids << ci.id;
displayName << ci.displayName;
}
configManager.updateListMenu("main/tools/user", displayName, "cmd", true, SLOT(commandFromAction()), Qt::ALT+Qt::SHIFT+Qt::Key_F1, false, 0);
QMenu* m = getManagedMenu("main/tools/user"); REQUIRE(m);
QList<QAction *> actions = m->actions();
for (int i=0;i<actions.size();i++)
actions[i]->setData(BuildManager::TXS_CMD_PREFIX+ids[i]);
}
#include "QMetaMethod"
void Texmaker::linkToEditorSlot(QAction* act, const char* methodName, const QList<QVariant>& args){
REQUIRE(act);
connectUnique(act, SIGNAL(triggered()), this, SLOT(relayToEditorSlot()));
act->setProperty("primarySlot", QString(SLOT(relayToEditorSlot())));
QByteArray signature = createMethodSignature(methodName, args);
if (!args.isEmpty())
act->setProperty("args", QVariant::fromValue<QList<QVariant> >(args));
for (int i=0;i<LatexEditorView::staticMetaObject.methodCount();i++)
#if QT_VERSION>=0x050000
if (signature == LatexEditorView::staticMetaObject.method(i).methodSignature()) {
act->setProperty("editorViewSlot", methodName);
return;
} //else qDebug() << LatexEditorView::staticMetaObject.method(i).signature();
for (int i=0;i<QEditor::staticMetaObject.methodCount();i++)
if (signature == QEditor::staticMetaObject.method(i).methodSignature()) {
act->setProperty("editorSlot", methodName);
return;
}
#else
if (signature == LatexEditorView::staticMetaObject.method(i).signature()) {
act->setProperty("editorViewSlot", methodName);
return;
} //else qDebug() << LatexEditorView::staticMetaObject.method(i).signature();
for (int i=0;i<QEditor::staticMetaObject.methodCount();i++)
if (signature == QEditor::staticMetaObject.method(i).signature()) {
act->setProperty("editorSlot", methodName);
return;
}
#endif
qDebug() << methodName << signature;
Q_ASSERT(false);
}
void Texmaker::relayToEditorSlot(){
if (!currentEditorView()) return;
QAction* act = qobject_cast<QAction*>(sender());
REQUIRE(act);
if (act->property("editorViewSlot").isValid()) QMetaObjectInvokeMethod(currentEditorView(), qPrintable(act->property("editorViewSlot").toString()), act->property("args").value<QList<QVariant> >());
else if (act->property("editorSlot").isValid()) QMetaObjectInvokeMethod(currentEditor(), qPrintable(act->property("editorSlot").toString()), act->property("args").value<QList<QVariant> >());
}
void Texmaker::relayToOwnSlot(){
QAction* act = qobject_cast<QAction*>(sender());
REQUIRE(act && act->property("slot").isValid());
QMetaObjectInvokeMethod(this, qPrintable(act->property("slot").toString()), act->property("args").value<QList<QVariant> >());
}
void Texmaker::autoRunScripts(){
QStringList vers = QString(QT_VERSION_STR).split('.');
Q_ASSERT(vers.length() >= 2);
int major = vers.at(0).toInt();
int minor = vers.at(1).toInt();
if (!hasAtLeastQt(major,minor))
txsWarning(tr("%1 has been compiled with Qt %2, but is running with Qt %3.\nPlease get the correct runtime library (e.g. .dll or .so files).\nOtherwise there might be random errors and crashes.")
.arg(TEXSTUDIO).arg(QT_VERSION_STR).arg(qVersion()));
runScripts(Macro::ST_TXS_START);
}
void Texmaker::runScripts(int trigger){
runScriptsInList(trigger, configManager.completerConfig->userMacros);
}
void Texmaker::runScriptsInList(int trigger, const QList<Macro> &scripts) {
foreach (const Macro ¯o, scripts) {
if (macro.isActiveForTrigger((Macro::SpecialTrigger)trigger))
insertUserTag(macro.tag, trigger);
}
}
void Texmaker::fileNewInternal(QString fileName) {
LatexDocument *doc = new LatexDocument(this);
LatexEditorView *edit = new LatexEditorView (0, configManager.editorConfig, doc);
edit->setLatexPackageList(&latexPackageList);
if (configManager.newFileEncoding)
edit->editor->setFileCodec(configManager.newFileEncoding);
else
edit->editor->setFileCodec(QTextCodec::codecForName("utf-8"));
doc->clearUndo(); // inital file codec setting should not be undoable
edit->editor->setFileName(fileName);
configureNewEditorView(edit);
edit->document = doc;
edit->document->setEditorView(edit);
documents.addDocument(edit->document);
configureNewEditorViewEnd(edit);
edit->updateLtxCommands();
if(!fileName.isEmpty())
fileSave(true);
}
void Texmaker::fileNew(QString fileName) {
fileNewInternal(fileName);
emit infoNewFile();
}
void Texmaker::fileAutoReloading(QString fname){
LatexDocument* document=documents.findDocument(fname);
if (!document) return;
document->initClearStructure();
}
void Texmaker::fileReloaded(){
QEditor *mEditor = qobject_cast<QEditor *>(sender());
if(mEditor==currentEditor()){
currentEditorView()->document->initClearStructure();
updateStructure(true);
}else{
LatexDocument* document=documents.findDocument(mEditor->fileName());
if (!document) return;
document->initClearStructure();
document->patchStructure(0,-1);
}
}
void Texmaker::fileMakeTemplate() {
if (!currentEditorView())
return;
MakeTemplateDialog templateDialog(TemplateManager::userTemplateDir(), currentEditor()->fileName());
if (templateDialog.exec()) {
// save file
QString fn = templateDialog.suggestedFile();
QString old_name=currentEditor()->fileName();
QTextCodec *mCodec=currentEditor()->getFileCodec();
currentEditor()->setFileCodec(QTextCodec::codecForName("utf-8"));
currentEditor()->save(fn);
currentEditor()->setFileName(old_name);
currentEditor()->setFileCodec(mCodec);
// save metaData
QFileInfo fi(fn);
fn = fi.absoluteFilePath();
fn.remove(fn.lastIndexOf('.'), 4);
fn.append(".json");
QFile file(fn);
if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
txsInformation(tr("Could not write template meta data:") + "\n" + fn);
} else {
QTextStream out(&file);
out.setCodec("UTF-8");
out << templateDialog.generateMetaData();
file.close();
}
}
}
void Texmaker::templateEdit(const QString &fname){
load(fname, false);
}
void Texmaker::fileNewFromTemplate() {
TemplateManager tmplMgr;
connectUnique(&tmplMgr, SIGNAL(editRequested(QString)), this, SLOT(templateEdit(QString)));
TemplateSelector *dialog = tmplMgr.createLatexTemplateDialog();
if (!dialog->exec()) return;
TemplateHandle th = dialog->selectedTemplate();
if (!th.isValid()) return;
if (dialog->createInFolder()) {
th.createInFolder(dialog->creationFolder());
if (th.isMultifile()) {
QDir dir(dialog->creationFolder());
foreach (const QString &f, th.filesToOpen()) {
QFileInfo fi(dir, f);
if (fi.exists() && fi.isFile())
load(fi.absoluteFilePath());
}
} else {
QDir dir(dialog->creationFolder());
QFileInfo fi(dir, QFileInfo(th.file()).fileName());
load(fi.absoluteFilePath());
}
} else {
QString fname = th.file();
QFile file(fname);
if (!file.exists()) {
txsWarning(tr("File not found:")+QString("\n%1").arg(fname));
return;
}
if (!file.open(QIODevice::ReadOnly)) {
txsWarning(tr("You do not have read permission to this file:")+QString("\n%1").arg(fname));
return;
}
//set up new editor with template
fileNewInternal();
LatexEditorView *edit = currentEditorView();
QString mTemplate;
QTextStream in(&file);
in.setCodec(QTextCodec::codecForMib(MIB_UTF8));
while (!in.atEnd()) {
QString line = in.readLine();
mTemplate+=line+"\n";
}
CodeSnippet toInsert(mTemplate, false);
bool flag=edit->editor->flag(QEditor::AutoIndent);
edit->editor->setFlag(QEditor::AutoIndent,false);
toInsert.insert(edit->editor);
edit->editor->setFlag(QEditor::AutoIndent,flag);
edit->editor->setCursorPosition(0,0, false);
edit->editor->nextPlaceHolder();
edit->editor->ensureCursorVisible(QEditor::KeepSurrounding);
emit infoNewFromTemplate();
}
delete dialog;
}
void Texmaker::insertTableTemplate() {
QEditor *m_edit=currentEditor();
if(!m_edit)
return;
QDocumentCursor c=m_edit->cursor();
if(!LatexTables::inTableEnv(c))
return;
// select Template
TemplateManager tmplMgr;
connectUnique(&tmplMgr, SIGNAL(editRequested(QString)), this, SLOT(templateEdit(QString)));
if (tmplMgr.tableTemplateDialogExec()) {
QString fname = tmplMgr.selectedTemplateFile();
QFile file(fname);
if (!file.exists()) {
txsWarning(tr("File not found:")+QString("\n%1").arg(fname));
return;
}
if (!file.open(QIODevice::ReadOnly)) {
txsWarning(tr("You do not have read permission to this file:")+QString("\n%1").arg(fname));
return;
}
QString tableDef=LatexTables::getSimplifiedDef(c);
QString tableText=LatexTables::getTableText(c);
//remove table
c.removeSelectedText();
m_edit->setCursor(c);
// split table text into line/column list
QStringList values;
QList<int> starts;
QString env;
//tableText.remove("\n");
tableText.remove("\\hline");
if(tableText.startsWith("\\begin")){
LatexParser::resolveCommandOptions(tableText,0,values,&starts);
env=values.takeFirst();
env.remove(0,1);
env.remove(env.length()-1,1);
// special treatment for tabu/longtabu
if((env=="tabu"||env=="longtabu")&&values.count()<1){
int startExtra=env.length()+8;
int endExtra=tableText.indexOf("{",startExtra);
if(endExtra>=0 && endExtra>startExtra){
QString textHelper=tableText;
textHelper.remove(startExtra,endExtra-startExtra); // remove to/spread definition
values.clear();
starts.clear();
LatexParser::resolveCommandOptions(textHelper,0,values,&starts);
for(int i=1;i<starts.count();i++){
starts[i]+=endExtra-startExtra;
}
}
if(!values.isEmpty())
values.takeFirst();
}
if(LatexTables::tabularNames.contains(env)){
if(!values.isEmpty()){
int i=starts.at(1);
i+=values.first().length();
tableText.remove(0,i);
}
}
if(LatexTables::tabularNamesWithOneOption.contains(env)){
if(values.size()>1){
int i=starts.at(2);
i+=values.at(1).length();
tableText.remove(0,i);
}
}
tableText.remove(QRegExp("\\\\end\\{"+env+"\\}$"));
}
tableText.replace("\\endhead","\\\\");
QStringList lines=tableText.split("\\\\");
QList<QStringList> tableContent;
foreach(QString line,lines){
//line=line.simplified();
if(line.isEmpty() || line=="\n")
continue;
QStringList elems=line.split(QRegExp("&"));
if(elems.count()>0){
if(elems[0].startsWith("\n"))
elems[0]=elems[0].mid(1);
}
//QList<QString>::iterator i;
/*for(i=elems.begin();i!=elems.end();i++){
QString elem=*i;
*i=elem.simplified();
}*/
// handle \& correctly
for(int i=elems.size()-1;i>=0;--i){
if(elems.at(i).endsWith("\\")){
QString add=elems.at(i)+elems.at(i+1);
elems.replace(i,add);
elems.removeAt(i+1);
}
}
tableContent<<elems;
}
LatexTables::generateTableFromTemplate(currentEditorView(),fname,tableDef,tableContent,env);
}
}
void Texmaker::alignTableCols() {
if (!currentEditor()) return;
QDocumentCursor cur(currentEditor()->cursor());
if(!cur.isValid())
return;
LatexTables::alignTableCols(cur);
}
void Texmaker::fileOpen() {
QString currentDir=QDir::homePath();
if (!configManager.lastDocument.isEmpty()) {
QFileInfo fi(configManager.lastDocument);
if (fi.exists() && fi.isReadable()) {
currentDir=fi.absolutePath();
}
}
QStringList files = QFileDialog::getOpenFileNames(this,tr("Open Files"),currentDir,fileFilters, &selectedFileFilter);
recheckLabels=false; // impede label rechecking on hidden docs
QList<LatexEditorView*>listViews;
foreach (const QString& fn, files)
listViews<<load(fn);
// update ref/labels in one go;
QList<LatexDocument*> completedDocs;
foreach(LatexEditorView* edView,listViews){
if(!edView)
continue;
LatexDocument *docBase=edView->getDocument();
foreach(LatexDocument *doc,docBase->getListOfDocs()){
doc->recheckRefsLabels();
if(completedDocs.contains(doc))
continue;
LatexEditorView *edView=doc->getEditorView();
if(edView){
edView->updateLtxCommands(true);
completedDocs<<doc->getListOfDocs();
}
}
}
recheckLabels=true;
// update completer
if(currentEditorView())
updateCompleter(currentEditorView());
}
void Texmaker::fileRestoreSession(bool showProgress, bool warnMissing){
QFileInfo f(QDir(configManager.configBaseDir), "lastSession.txss");
Session s;
if (f.exists()) {
if (!s.load(f.filePath())) {
txsCritical(tr("Loading of last session failed."));
}
} else {
// fallback to loading from the config (import the session saved by TXS <= 2.5.1)
s.load(configManager);
}
restoreSession(s, showProgress, warnMissing);
}
void Texmaker::fileSave(const bool saveSilently) {
if (!currentEditor())
return;
if (currentEditor()->fileName()=="" || !QFileInfo(currentEditor()->fileName()).exists()){
removeDiffMarkers();// clean document from diff markers first
fileSaveAs(currentEditor()->fileName(),saveSilently);
} else {
/*QFile file( *filenames.find( currentEditorView() ) );
if ( !file.open( QIODevice::WriteOnly ) )
{
QMessageBox::warning( this,tr("Error"),tr("The file could not be saved. Please check if you have write permission."));
return;
}*/
removeDiffMarkers();// clean document from diff markers first
currentEditor()->save();
currentEditor()->document()->markViewDirty();//force repaint of line markers (yellow -> green)
MarkCurrentFileAsRecent();
if(configManager.autoCheckinAfterSave && !saveSilently) {
checkin(currentEditor()->fileName());
if(configManager.svnUndo) currentEditor()->document()->clearUndo();
}
emit infoFileSaved(currentEditor()->fileName());
}
UpdateCaption();
//updateStructure(); (not needed anymore for autoupdate)
}
void Texmaker::fileSaveAs(const QString& fileName,const bool saveSilently) {
if (!currentEditorView())
return;
// select a directory/filepath
QString currentDir=QDir::homePath();
if (fileName.isEmpty()) {
if (currentEditor()->fileInfo().isFile()) {
currentDir = currentEditor()->fileInfo().absoluteFilePath();
} else {
if (!configManager.lastDocument.isEmpty())
currentDir = configManager.lastDocument;
static QString saveAsDefault;
configManager.registerOption("Files/Save As Default",&saveAsDefault,"?a)/document");
currentDir = buildManager.parseExtendedCommandLine(saveAsDefault, currentDir, currentDir).value(0, currentDir);
}
} else {
currentDir = fileName;
/*QFileInfo currentFile(fileName);
if (currentFile.absoluteDir().exists())
currentDir = fileName;*/
}
// get a file name
QString fn =fileName;
if(!saveSilently || fn.isEmpty()) {
fn = QFileDialog::getSaveFileName(this,tr("Save As"),currentDir,fileFilters, &selectedFileFilter);
if (!fn.isEmpty()) {
static QRegExp fileExt("\\*(\\.[^ )]+)");
if (fileExt.indexIn(selectedFileFilter) > -1) {
//add
int lastsep=qMax(fn.lastIndexOf("/"),fn.lastIndexOf("\\"));
int lastpoint=fn.lastIndexOf(".");
if (lastpoint <= lastsep) //if both aren't found or point is in directory name
fn.append(fileExt.cap(1));
}
}
}
if (!fn.isEmpty()) {
if (getEditorViewFromFileName(fn) && getEditorViewFromFileName(fn) != currentEditorView()) {
// trying to save with same name as another already existing file
LatexEditorView *otherEdView = getEditorViewFromFileName(fn);
if (!otherEdView->document->isClean()) {
txsWarning(tr("Saving under the name\n"
"%1\n"
"is currently not possible because a modified version of a file\n"
"with this name is open in TeXstudio. You have to save or close\n"
"this other file before you can overwrite it.").arg(fn));
return;
}
// other editor does not contain unsaved changes, so it can be closed
LatexEditorView *currentEdView = currentEditorView();
EditorTabs->setCurrentEditor(otherEdView);
fileClose();
EditorTabs->setCurrentEditor(currentEdView);
}
// save file
removeDiffMarkers();// clean document from diff markers first
currentEditor()->save(fn);
currentEditorView()->document->setEditorView(currentEditorView()); //update file name
MarkCurrentFileAsRecent();
//update Master/Child relations
LatexDocument *doc=currentEditorView()->document;
documents.updateMasterSlaveRelations(doc);
if(configManager.autoCheckinAfterSave){
if(svnadd(currentEditor()->fileName())){
checkin(currentEditor()->fileName(),"txs auto checkin",configManager.svnKeywordSubstitution);
} else {
//create simple repository
svncreateRep(currentEditor()->fileName());
svnadd(currentEditor()->fileName());
checkin(currentEditor()->fileName(),"txs auto checkin",configManager.svnKeywordSubstitution);
}
// set SVN Properties if desired
if(configManager.svnKeywordSubstitution){
QString cmd = BuildManager::CMD_SVN + " propset svn:keywords \"Date Author HeadURL Revision\" \""+currentEditor()->fileName()+"\"";
statusLabelProcess->setText(QString(" svn propset svn:keywords "));
runCommand(cmd, 0);
}
}
EditorTabs->setTabText(EditorTabs->currentIndex(),currentEditor()->name().replace("&","&&"));
EditorTabs->setTabToolTip(EditorTabs->currentIndex(), QDir::toNativeSeparators(currentEditor()->fileName()));
updateOpenDocumentMenu(true);
if (currentEditor()->fileInfo().suffix()!="tex")
m_languages->setLanguage(currentEditor(), fn);
emit infoFileSaved(currentEditor()->fileName());
}
UpdateCaption();
}
void Texmaker::fileSaveAll() {
fileSaveAll(true,true);
}
void Texmaker::fileSaveAll(bool alsoUnnamedFiles, bool alwaysCurrentFile) {
//LatexEditorView *temp = new LatexEditorView(EditorView,colorMath,colorCommand,colorKeyword);
//temp=currentEditorView();
REQUIRE(EditorTabs);
LatexEditorView *currentEdView = currentEditorView();
foreach (LatexEditorView *edView, EditorTabs->editors()) {
REQUIRE(edView->editor);
if (edView->editor->fileName().isEmpty()){
if ((alsoUnnamedFiles || (alwaysCurrentFile && edView==currentEdView) ) ) {
EditorTabs->setCurrentEditor(edView);
fileSaveAs();
} else if (!edView->document->getTemporaryFileName().isEmpty())
edView->editor->saveCopy(edView->document->getTemporaryFileName());
//else if (edView->editor->isInConflict()) {
//edView->editor->save();
//}
} else if (edView->editor->isContentModified() || edView->editor->isInConflict()){
removeDiffMarkers();// clean document from diff markers first
edView->editor->save(); //only save modified documents
if (edView->editor->fileName().endsWith(".bib")) {
QString temp=edView->editor->fileName();
temp=temp.replace(QDir::separator(),"/");
documents.bibTeXFilesModified = documents.bibTeXFilesModified || documents.mentionedBibTeXFiles.contains(temp);//call bibtex on next compilation (this would also set as soon as the user switch to a tex file, but he could compile before switching)
}
emit infoFileSaved(edView->editor->fileName());
}
//currentEditor()->save();
//UpdateCaption();
}
if (currentEditorView() != currentEdView)
EditorTabs->setCurrentEditor(currentEdView);
//UpdateCaption();
}
//TODO: handle svn in all these methods
void Texmaker::fileUtilCopyMove(bool move){
QString fn = documents.getCurrentFileName();
if (fn.isEmpty()) return;
QString newfn = QFileDialog::getSaveFileName(this,move ? tr("Rename/Move") : tr("Copy"),fn,fileFilters, &selectedFileFilter);
if (newfn.isEmpty()) return;
if (fn == newfn) return;
QFile::Permissions permissions = QFile(fn).permissions();
if (move) fileSaveAs(newfn, true);
else currentEditor()->saveCopy(newfn);
if (documents.getCurrentFileName() != newfn) return;
if (move) QFile(fn).remove();
QFile(newfn).setPermissions(permissions); //keep permissions. (better: actually move the file, keeping the inode. but then all that stuff (e.g. master/slave) has to be updated here
}
void Texmaker::fileUtilDelete(){
QString fn = documents.getCurrentFileName();
if (fn.isEmpty()) return;
if (txsConfirmWarning(tr("Do you really want to delete the file \"%1\"?").arg(fn)))
QFile(fn).remove();
}
void Texmaker::fileUtilRevert(){
if (!currentEditor()) return;
QString fn = documents.getCurrentFileName();
if (fn.isEmpty()) return;
if (txsConfirmWarning(tr("Do you really want to revert the file \"%1\"?").arg(documents.getCurrentFileName())))
currentEditor()->reload();
}
void Texmaker::fileUtilPermissions(){
QString fn = documents.getCurrentFileName();
if (fn.isEmpty()) return;
QFile f(fn);
int permissionsRaw = f.permissions();
int permissionsUnixLike = ((permissionsRaw & 0x7000) >> 4) | (permissionsRaw & 0x0077); //ignore qt "user" flags
QString permissionsUnixLikeHex = QString::number(permissionsUnixLike, 16);
QString permissions;
const QString PERMISSIONSCODES = "rwx";
int flag = QFile::ReadUser; REQUIRE(QFile::ReadUser == 0x400);
int temp = permissionsUnixLike;
for (int b=0;b<3;b++) {
for (int i=0;i<3;i++, flag >>= 1)
permissions += (temp & flag) ? PERMISSIONSCODES[i] : QChar('-');
flag >>= 1;
}
QString oldPermissionsUnixLikeHex = permissionsUnixLikeHex, oldPermissions = permissions;
UniversalInputDialog uid;
uid.addVariable(&permissionsUnixLikeHex, tr("Numeric permissions"));
uid.addVariable(&permissions, tr("Verbose permissions"));
if (uid.exec() == QDialog::Accepted && (permissionsUnixLikeHex != oldPermissionsUnixLikeHex || permissions != oldPermissions)) {
if (permissionsUnixLikeHex != oldPermissionsUnixLikeHex)
permissionsRaw = permissionsUnixLikeHex.toInt(0, 16);
else {
permissionsRaw = 0;
int flag = QFile::ReadUser;
int p = 0;
for (int b=0;b<3;b++) {
for (int i=0;i<3;i++, flag >>= 1) {
if (permissions[p] == '-') p++;
else if (permissions[p] == PERMISSIONSCODES[i]) {
permissionsRaw |= flag;
p++;
} else if (!QString("rwx").contains(permissions[p])) {
txsWarning("invalid character in permission: "+permissions[p]);
return;
}
if (p >= permissions.length()) p=0; //wrap around
}
flag >>= 1;
}
}
permissionsRaw = ((permissionsRaw << 4) & 0x7000) | permissionsRaw; //use qt "user" as owner flags
f.setPermissions(QFile::Permissions(permissionsRaw)) ;
}
}
void Texmaker::fileUtilCopyFileName(){
QApplication::clipboard()->setText(documents.getCurrentFileName());
}
void Texmaker::fileUtilCopyMasterFileName(){
QApplication::clipboard()->setText(documents.getCompileFileName());
}
void Texmaker::fileClose() {
if (!currentEditorView()) return;
bookmarks->updateBookmarks(currentEditorView());
QFileInfo fi = currentEditorView()->document->getFileInfo();
repeatAfterFileSavingFailed:
if (currentEditorView()->editor->isContentModified()) {
switch (QMessageBox::warning(this, TEXSTUDIO,
tr("The document \"%1\" contains unsaved work. "
"Do you want to save it before closing?").arg(currentEditorView()->displayName()),
tr("Save and Close"), tr("Don't Save and Close"), tr("Cancel"),
0,
2)) {
case 0:
fileSave();
if (currentEditorView()->editor->isContentModified())
goto repeatAfterFileSavingFailed;
documents.deleteDocument(currentEditorView()->document);
break;
case 1:
documents.deleteDocument(currentEditorView()->document);
break;
case 2:
default:
return;
break;
}
} else documents.deleteDocument(currentEditorView()->document);
updateOpenDocumentMenu();
//UpdateCaption(); unnecessary as called by tabChanged (signal)
#ifndef NO_POPPLER_PREVIEW
//close associated embedded pdf viewer
foreach(PDFDocument *viewer,PDFDocument::documentList())
if (viewer->autoClose && viewer->getMasterFile()==fi)
viewer->close();
#endif
}
void Texmaker::fileCloseAll() {
closeAllFilesAsking();
documents.setMasterDocument(0);
UpdateCaption();
}
void Texmaker::fileExit() {
if (canCloseNow())
qApp->quit();
}
bool Texmaker::closeAllFilesAsking(){
while (currentEditorView()) {
repeatAfterFileSavingFailed:
if (currentEditorView()->editor->isContentModified()) {
switch (QMessageBox::warning(this, TEXSTUDIO,
tr("The document \"%1\" contains unsaved work. "
"Do you want to save it before closing?").arg(currentEditorView()->displayName()),
tr("Save and Close"), tr("Don't Save and Close"), tr("Cancel"),
0,
2)) {
case 0:
fileSave();
if (currentEditorView()->editor->isContentModified())
goto repeatAfterFileSavingFailed;
documents.deleteDocument(currentEditorView()->document);
break;
case 1:
documents.deleteDocument(currentEditorView()->document);
break;
case 2:
default:
updateOpenDocumentMenu();
return false;
}
} else
documents.deleteDocument(currentEditorView()->document);
}
#ifndef NO_POPPLER_PREVIEW
foreach (PDFDocument* viewer, PDFDocument::documentList())
viewer->close();
#endif
updateOpenDocumentMenu();
return true;
}
bool Texmaker::canCloseNow(){
#ifndef NO_POPPLER_PREVIEW
foreach (PDFDocument* viewer, PDFDocument::documentList())
viewer->saveGeometryToConfig();
#endif
SaveSettings();
bool accept = closeAllFilesAsking();
if (accept){
if (userMacroDialog) delete userMacroDialog;
spellerManager.unloadAll(); //this saves the ignore list
}
programStopped = true;
Guardian::shutdown();
return accept;
}
void Texmaker::closeEvent(QCloseEvent *e) {
if (canCloseNow()) e->accept();
else e->ignore();
}
void Texmaker::updateUserMacros(bool updateMenu){
if (updateMenu) configManager.updateUserMacroMenu();
for (int i=0; i<configManager.completerConfig->userMacros.size(); i++) {
configManager.completerConfig->userMacros[i].parseTriggerLanguage(m_languages);
}
}
void Texmaker::centerFileSelector(){
if (!fileSelector) return;
fileSelector.data()->setCentered(centralWidget()->geometry());
}
void Texmaker::fileOpenRecent() {
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
QString fn = action->data().toString();
if (!QFile::exists(fn)) {
if (txsConfirmWarning(tr("The file \"%1\" does not exist anymore. Do you want to remove it from the recent file list?").arg(fn))){
if (configManager.recentFilesList.removeAll(fn))
configManager.updateRecentFiles();
return;
}
}
load(fn);
}
void Texmaker::fileOpenAllRecent() {
foreach (const QString& s, configManager.recentFilesList)
load(s);
}
QRect appendToBottom(QRect r, const QRect& s){
r.setBottom(r.bottom() + s.height());
return r;
}
void Texmaker::fileRecentList(){
if (fileSelector) fileSelector.data()->deleteLater();
fileSelector = new FileSelector(this, true);
fileSelector.data()->init(QStringList() << configManager.recentProjectList << configManager.recentFilesList, 0);
connect(fileSelector.data(), SIGNAL(fileChoosen(QString,int,int,int)), SLOT(fileDocumentOpenFromChoosen(QString,int,int,int)));
fileSelector.data()->setVisible(true);
centerFileSelector();
}
void Texmaker::fileDocumentOpenFromChoosen(const QString& doc, int duplicate, int lineNr, int column){
Q_UNUSED(duplicate);
if (!QFile::exists(doc)) {
if (txsConfirmWarning(tr("The file \"%1\" does not exist anymore. Do you want to remove it from the recent file list?").arg(doc))){
if (configManager.recentFilesList.removeAll(doc) + configManager.recentProjectList.removeAll(doc) > 0)
configManager.updateRecentFiles();
return;
}
}
if (!load(doc, duplicate < configManager.recentProjectList.count(doc))) return;
if (lineNr < 0) return;
REQUIRE(currentEditor());
currentEditor()->setCursorPosition(lineNr, column);
}
bool mruEditorViewLessThan(const LatexEditorView* e1, const LatexEditorView* e2)
{
return e1->lastUsageTime > e2->lastUsageTime;
}
void Texmaker::viewDocumentList(){
if (fileSelector) fileSelector.data()->deleteLater();
fileSelector = new FileSelector(this, false);
QStringList sl;
LatexEditorView *curEdView = currentEditorView();
int curIndex = 0;
QList<LatexEditorView*> editors = EditorTabs->editors();
if (configManager.mruDocumentChooser) {
qSort(editors.begin(), editors.end(), mruEditorViewLessThan);
if (editors.size() > 1)
if (editors.first() == currentEditorView())
curIndex = 1;
}
int i = 0;
foreach (LatexEditorView *edView, editors){
sl << edView->displayName();
if (!configManager.mruDocumentChooser && edView == curEdView) curIndex = i;
i++;
}
fileSelector.data()->init(sl, curIndex);
connect(fileSelector.data(), SIGNAL(fileChoosen(QString,int,int,int)), SLOT(viewDocumentOpenFromChoosen(QString,int,int,int)));
fileSelector.data()->setVisible(true);
centerFileSelector();
}
void Texmaker::viewDocumentOpenFromChoosen(const QString& doc, int duplicate, int lineNr, int column){
if (duplicate < 0) return;
foreach (LatexEditorView *edView, EditorTabs->editors()) {
QString name = edView->displayName();
if (name == doc) {
duplicate -= 1;
if (duplicate < 0) {
EditorTabs->setCurrentWidget(edView);
if (lineNr >= 0)
edView->editor->setCursorPosition(lineNr, column);
edView->setFocus();
return;
}
}
}
}
void Texmaker::fileOpenFirstNonOpen(){
foreach (const QString& f, configManager.recentFilesList)
if (!getEditorViewFromFileName(f)){
load(f);
break;
}
}
void Texmaker::fileOpenRecentProject() {
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
QString fn = action->data().toString();
if (!QFile::exists(fn)) {
if (txsConfirmWarning(tr("The file \"%1\" does not exist anymore. Do you want to remove it from the recent file list?").arg(fn))){
if (configManager.recentProjectList.removeAll(fn))
configManager.updateRecentFiles();
return;
}
}
load(fn, true);
}
void Texmaker::loadSession(const QString &fileName) {
Session s;
if (!s.load(fileName)) {
txsCritical(tr("Loading of session failed."));
return;
}
restoreSession(s);
}
void Texmaker::fileLoadSession() {
QString openDir = QDir::homePath();
if (currentEditorView()) {
LatexDocument *doc = currentEditorView()->document;
if (doc->getMasterDocument()) {
openDir = doc->getMasterDocument()->getFileInfo().path();
} else {
openDir = doc->getFileInfo().path();
}
}
QString fn = QFileDialog::getOpenFileName(this, tr("Load Session"), openDir, tr("TeXstudio Session") + " (*." + Session::fileExtension() + ")");
if (fn.isNull()) return;
loadSession(fn);
recentSessionList->addFilenameToList(fn);
}
void Texmaker::fileSaveSession() {
QString openDir = QDir::homePath();
if (currentEditorView()) {
LatexDocument *doc = currentEditorView()->document;
if (doc->getMasterDocument()) {
openDir = replaceFileExtension(doc->getMasterDocument()->getFileName(), Session::fileExtension());
} else {
openDir = replaceFileExtension(doc->getFileName(), Session::fileExtension());
}
}
QString fn = QFileDialog::getSaveFileName(this, tr("Save Session"), openDir, tr("TeXstudio Session") + " (*." + Session::fileExtension() + ")");
if (fn.isNull()) return;
if (!getCurrentSession().save(fn)) {
txsCritical(tr("Saving of session failed."));
return;
}
recentSessionList->addFilenameToList(fn);
}
void Texmaker::restoreSession(const Session &s, bool showProgress, bool warnMissing) {
fileCloseAll();
cursorHistory->setInsertionEnabled(false);
QProgressDialog progress(this);
if (showProgress) {
progress.setMaximum(s.files().size());
progress.setCancelButton(0);
progress.setMinimumDuration(3000);
progress.setLabel(new QLabel());
}
recheckLabels=false; // impede label rechecking on hidden docs
bookmarks->setBookmarks(s.bookmarks()); // set before loading, so that bookmarks are automatically restored on load
QStringList missingFiles;
for (int i=0; i<s.files().size(); i++) {
FileInSession f = s.files().at(i);
if (showProgress) {
progress.setValue(i);
progress.setLabelText(QFileInfo(f.fileName).fileName());
}
LatexEditorView* edView=load(f.fileName, f.fileName==s.masterFile(),false,false);
if (edView) {
int line = f.cursorLine;
int col = f.cursorCol;
if (line >= edView->document->lineCount()) {
line = 0;
col = 0;
} else {
if (edView->document->line(line).length() < col) {
col = 0;
}
}
edView->editor->setCursorPosition(line, col);
edView->editor->scrollToFirstLine(f.firstLine);
edView->document->foldLines(f.foldedLines);
} else {
missingFiles.append(f.fileName);
}
}
// update ref/labels in one go;
QList<LatexDocument*> completedDocs;
foreach(LatexDocument *doc,documents.getDocuments()){
doc->recheckRefsLabels();
if(completedDocs.contains(doc))
continue;
LatexEditorView *edView=doc->getEditorView();
if(edView){
edView->updateLtxCommands(true);
completedDocs<<doc->getListOfDocs();
}
}
recheckLabels=true;
if (showProgress) {
progress.setValue(progress.maximum());
}
ActivateEditorForFile(s.currentFile());
cursorHistory->setInsertionEnabled(true);
if (!s.PDFFile().isEmpty()) {
runInternalCommand("txs:///view-pdf-internal", QFileInfo(s.PDFFile()), s.PDFEmbedded()?"--embedded":"--windowed");
}
// update completer
if(currentEditorView())
updateCompleter(currentEditorView());
if (warnMissing && !missingFiles.isEmpty()) {
txsInformation(tr("The following files could not be loaded:") + "\n" + missingFiles.join("\n"));
}
}
Session Texmaker::getCurrentSession() {
Session s;
foreach (LatexEditorView *edView, EditorTabs->editors()) {
FileInSession f;
f.fileName = edView->editor->fileName();
f.cursorLine = edView->editor->cursor().lineNumber();
f.cursorCol = edView->editor->cursor().columnNumber();
f.firstLine = edView->editor->getFirstVisibleLine();
f.foldedLines = edView->document->foldedLines();
s.addFile(f);
}
s.setMasterFile(documents.singleMode()?"":documents.masterDocument->getFileName());
s.setCurrentFile(currentEditorView()?currentEditor()->fileName():"");
s.setBookmarks(bookmarks->getBookmarks());
#ifndef NO_POPPLER_PREVIEW
if (!PDFDocument::documentList().isEmpty()) {
PDFDocument *doc = PDFDocument::documentList().at(0);
s.setPDFEmbedded(doc->embeddedMode);
s.setPDFFile(doc->fileName());
}
#endif
return s;
}
void Texmaker::MarkCurrentFileAsRecent(){
configManager.addRecentFile(getCurrentFileName(),documents.masterDocument == currentEditorView()->document);
}
//////////////////////////// EDIT ///////////////////////
void Texmaker::editUndo() {
if (!currentEditorView()) return;
QVariant zw=currentEditor()->property("undoRevision");
int undoRevision=zw.canConvert<int>()?zw.toInt():0;
if(currentEditor()->document()->canUndo()){
currentEditor()->undo();
if(undoRevision>0) {
undoRevision=-1;
currentEditor()->setProperty("undoRevision",undoRevision);
}
}else{
if(configManager.svnUndo && (undoRevision>=0)){
svnUndo();
}
}
}
void Texmaker::editRedo() {
if (!currentEditorView()) return;
QVariant zw=currentEditor()->property("undoRevision");
int undoRevision=zw.canConvert<int>()?zw.toInt():0;
if(currentEditor()->document()->canRedo()){
currentEditorView()->editor->redo();
} else {
if(configManager.svnUndo && (undoRevision>0)){
svnUndo(true);
}
}
}
void Texmaker::editDebugUndoStack(){
if (!currentEditor()) return;
QString history = currentEditor()->document()->debugUndoStack();
fileNew();
currentEditor()->document()->setText(history, false);
}
void Texmaker::editCopy() {
if ((!currentEditor() || !currentEditor()->hasFocus()) &&
outputView->childHasFocus() ) {
outputView->copy();
return;
}
if (!currentEditorView()) return;
currentEditorView()->editor->copy();
}
void Texmaker::editPaste() {
if (!currentEditorView()) return;
const QMimeData *d = QApplication::clipboard()->mimeData();
if (d->hasUrls()) {
QList<QUrl> uris=d->urls();
bool onlyLocalImages = true;
for (int i=0; i<uris.length(); i++) {
QFileInfo fi = QFileInfo(uris.at(i).toLocalFile());
if (!fi.exists() || !InsertGraphics::imageFormats().contains(fi.suffix())) {
onlyLocalImages = false;
break;
}
}
if (onlyLocalImages) {
for (int i=0; i<uris.length(); i++) {
QuickGraphics(uris.at(i).toLocalFile());
}
} else {
currentEditorView()->paste();
}
} else {
currentEditorView()->paste();
}
}
void Texmaker::editPasteLatex() {
if (!currentEditorView()) return;
// manipulate clipboard text
QClipboard *clipboard = QApplication::clipboard();
QString originalText = clipboard->text();
QString newText=textToLatex(originalText);
//clipboard->setText(newText);
// insert
//currentEditorView()->editor->paste();
QMimeData md;
md.setText(newText);
currentEditorView()->editor->insertFromMimeData(&md);
}
void Texmaker::convertToLatex() {
if (!currentEditorView()) return;
// get selection and change it
QString originalText = currentEditor()->cursor().selectedText();
QString newText=textToLatex(originalText);
// insert
currentEditor()->write(newText);
}
void Texmaker::editEraseLine() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
c.beginEditBlock();
c.removeSelectedText(); // reduces multi-line selections to a single line
c.eraseLine();
c.endEditBlock();
}
void Texmaker::editEraseEndLine() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
c.movePosition(1,QDocumentCursor::EndOfLine,QDocumentCursor::KeepAnchor);
currentEditorView()->editor->setCursor(c);
currentEditorView()->editor->cut();
}
void Texmaker::editMoveLineUp() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
QDocumentCursor anchor(c.document(), c.anchorLineNumber(), c.anchorColumnNumber());
QDocumentCursor start = c.selectionStart();
QDocumentCursor end = c.selectionEnd();
if (start.lineNumber() <= 0) return;
start.movePosition(1, QDocumentCursor::StartOfLine);
end.movePosition(1, QDocumentCursor::EndOfLine);
QDocumentCursor edit(start, end);
edit.beginEditBlock();
QString text = edit.selectedText();
edit.removeSelectedText();
edit.eraseLine();
edit.movePosition(1, QDocumentCursor::PreviousLine);
edit.movePosition(1, QDocumentCursor::StartOfLine);
edit.insertText(text+"\n");
edit.endEditBlock();
c.movePosition(1, QDocumentCursor::Up);
anchor.movePosition(1, QDocumentCursor::Up);
currentEditorView()->editor->setCursor(QDocumentCursor(anchor, c));
}
void Texmaker::editMoveLineDown() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
QDocumentCursor anchor(c.document(), c.anchorLineNumber(), c.anchorColumnNumber());
QDocumentCursor start = c.selectionStart();
QDocumentCursor end = c.selectionEnd();
if (end.lineNumber() >= c.document()->lineCount()-1) return;
start.movePosition(1, QDocumentCursor::StartOfLine);
end.movePosition(1, QDocumentCursor::EndOfLine);
QDocumentCursor edit(start, end);
edit.beginEditBlock();
QString text = edit.selectedText();
edit.removeSelectedText();
edit.eraseLine();
edit.movePosition(1, QDocumentCursor::EndOfLine);
edit.insertText("\n"+text);
edit.endEditBlock();
c.movePosition(1, QDocumentCursor::Down);
anchor.movePosition(1, QDocumentCursor::Down);
currentEditorView()->editor->setCursor(QDocumentCursor(anchor, c));
}
void Texmaker::editDuplicateLine() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
QDocumentCursor start = c.selectionStart();
QDocumentCursor end = c.selectionEnd();
start.movePosition(1, QDocumentCursor::StartOfLine);
end.movePosition(1, QDocumentCursor::EndOfLine);
QDocumentCursor edit(start, end);
//edit.beginEditBlock();
QString text = edit.selectedText();
start.insertText(text+"\n");
currentEditorView()->editor->setCursor(c);
}
void Texmaker::editEraseWordCmdEnv(){
if (!currentEditorView()) return;
QDocumentCursor cursor = currentEditorView()->editor->cursor();
QString line=cursor.line().text();
QString command, value;
// Hack to fix problem problem reported in bug report 3443336 (see also detailed description there):
// findContext does not work at beginning of commands. Actually it would need
// pre-context and post-context otherwise, what context is either ambigous, like in
// \cmd|\cmd or it cannot work simultaneously at beginning and and (you cannot assign
// the context for |\cmd and \cmd| even if \cmd is surrounded by spaces. The latter
// both assignments make sense for editEraseWordCmdEnv().
//
// pre-context and post-context may be added when revising the latex parser
//
// Prelimiary solution part I:
// Predictable behaviour on selections: do nothing except in easy cases
if (cursor.hasSelection()) {
QRegExp partOfWordOrCmd("\\\\?\\w*");
if (!partOfWordOrCmd.exactMatch(cursor.selectedText()))
return;
}
// Prelimiary solution part II:
// If the case |\cmd is encountered, we shift the
// cursor by one to \|cmd so the regular erase approach works.
int col = cursor.columnNumber();
if ((col < line.count()) // not at end of line
&& (line.at(col) == '\\') // likely a command/env - check further
&& (col==0 || line.at(col-1).isSpace())) // cmd is at start or previous char is space: non-ambiguous situation like word|\cmd
// don't need to finally check for command |\c should be handled like \|c for any c (even space and empty)
{
cursor.movePosition(1);
}
switch (latexParser.findContext(line, cursor.columnNumber(), command, value)){
case LatexParser::Command:
if (command=="\\begin" || command=="\\end"){
//remove environment (surrounding)
currentEditorView()->editor->document()->beginMacro();
cursor.movePosition(1,QDocumentCursor::EndOfWord);
cursor.movePosition(1,QDocumentCursor::StartOfWord,QDocumentCursor::KeepAnchor);
cursor.movePosition(1,QDocumentCursor::PreviousCharacter,QDocumentCursor::KeepAnchor);
cursor.removeSelectedText();
// remove curly brakets as well
if(cursor.nextChar()==QChar('{')){
cursor.deleteChar();
line=cursor.line().text();
int col=cursor.columnNumber();
int i=findClosingBracket(line,col);
if(i>-1) {
cursor.movePosition(i-col+1,QDocumentCursor::NextCharacter,QDocumentCursor::KeepAnchor);
cursor.removeSelectedText();
QDocument* doc=currentEditorView()->editor->document();
QString searchWord="\\end{"+value+"}";
QString inhibitor="\\begin{"+value+"}";
bool backward=(command=="\\end");
int step=1;
if(backward) {
qSwap(searchWord,inhibitor);
step=-1;
}
int startLine=cursor.lineNumber();
int startCol=cursor.columnNumber();
int endLine=doc->findLineContaining(searchWord,startLine,Qt::CaseSensitive,backward);
int inhibitLine=doc->findLineContaining(inhibitor,startLine,Qt::CaseSensitive,backward); // not perfect (same line end/start ...)
while (inhibitLine>0 && endLine>0 && inhibitLine*step<endLine*step) {
endLine=doc->findLineContaining(searchWord,endLine+step,Qt::CaseSensitive,backward); // not perfect (same line end/start ...)
inhibitLine=doc->findLineContaining(inhibitor,inhibitLine+step,Qt::CaseSensitive,backward);
}
if(endLine>-1){
line=doc->line(endLine).text();
int start=line.indexOf(searchWord);
cursor.moveTo(endLine,start);
cursor.movePosition(searchWord.length(),QDocumentCursor::NextCharacter,QDocumentCursor::KeepAnchor);
cursor.removeSelectedText();
cursor.moveTo(startLine,startCol); // move cursor back to text edit pos
}
}
}
currentEditorView()->editor->document()->endMacro();
}else{
currentEditorView()->editor->document()->beginMacro();
cursor.movePosition(1,QDocumentCursor::EndOfWord);
cursor.movePosition(1,QDocumentCursor::StartOfWord,QDocumentCursor::KeepAnchor);
cursor.movePosition(1,QDocumentCursor::PreviousCharacter,QDocumentCursor::KeepAnchor);
cursor.removeSelectedText();
// remove curly brakets as well
if(cursor.nextChar()==QChar('{')){
cursor.deleteChar();
line=cursor.line().text();
int col=cursor.columnNumber();
int i=findClosingBracket(line,col);
if(i>-1) {
cursor.moveTo(cursor.lineNumber(),i);
cursor.deleteChar();
cursor.moveTo(cursor.lineNumber(),col);
}
}
currentEditorView()->editor->document()->endMacro();
}
break;
default:
//cursor.movePosition(1,QDocumentCursor::StartOfWord);
cursor.select(QDocumentCursor::WordUnderCursor);
cursor.removeSelectedText();
break;
}
currentEditorView()->editor->setCursor(cursor);
}
void Texmaker::editGotoDefinition(QDocumentCursor c) {
if (!currentEditorView()) return;
if (!c.isValid()) c=currentEditor()->cursor();
QString command, value;
saveCurrentCursorToHistory();
switch (latexParser.findContext(c.line().text(), c.columnNumber(), command, value)) {
case LatexParser::Reference:
{
LatexEditorView *edView = editorViewForLabel(qobject_cast<LatexDocument *>(c.document()), value);
if (!edView) return;
if (edView != currentEditorView()) {
EditorTabs->setCurrentEditor(edView);
}
edView->gotoToLabel(value);
break;
}
case LatexParser::Citation:
{
QString bibID = trimLeft(getParamItem(c.line().text(), c.columnNumber()));
// try local \bibitems
bool found = currentEditorView()->gotoToBibItem(bibID);
if (found) break;
// try bib files
QString bibFile = currentEditorView()->document->findFileFromBibId(bibID);
LatexEditorView* edView = getEditorViewFromFileName(bibFile);
if (!edView) {
if (!load(bibFile)) return;
edView = currentEditorView();
}
int line = edView->document->findLineRegExp("@\\w+{\\s*"+bibID, 0, Qt::CaseSensitive, true, true);
if (line < 0) {
line = edView->document->findLineContaining(bibID); // fallback in case the above regexp does not reflect the most general case
if (line < 0) return;
}
int col = edView->document->line(line).text().indexOf(bibID);
if (col<0) col = 0;
gotoLine(line, col, edView);
break;
}
default:; //TODO: Jump to command definition
}
}
void Texmaker::editHardLineBreak(){
if (!currentEditorView()) return;
UniversalInputDialog dialog;
dialog.addVariable(&configManager.lastHardWrapColumn, tr("Insert hard line breaks after so many characters:"));
dialog.addVariable(&configManager.lastHardWrapSmartScopeSelection, tr("Smart scope selecting"));
dialog.addVariable(&configManager.lastHardWrapJoinLines, tr("Join lines before wrapping"));
if (dialog.exec()==QDialog::Accepted)
currentEditorView()->insertHardLineBreaks(configManager.lastHardWrapColumn, configManager.lastHardWrapSmartScopeSelection, configManager.lastHardWrapJoinLines);
}
void Texmaker::editHardLineBreakRepeat() {
if (!currentEditorView()) return;
currentEditorView()->insertHardLineBreaks(configManager.lastHardWrapColumn, configManager.lastHardWrapSmartScopeSelection, configManager.lastHardWrapJoinLines);
}
void Texmaker::editSpell() {
if (!currentEditorView()) {
txsWarning(tr("No document open"));
return;
}
SpellerUtility *su = spellerManager.getSpeller(currentEditorView()->getSpeller());
if (!su) return; // getSpeller already gives a warning message
if (su->name() == "<none>") {
txsWarning(tr("No dictionary available."));
return;
}
if (!spellDlg) spellDlg=new SpellerDialog(this, su);
spellDlg->setEditorView(currentEditorView());
spellDlg->startSpelling();
}
void Texmaker::editThesaurus(int line,int col) {
if (!ThesaurusDialog::retrieveDatabase()) {
QMessageBox::warning(this,tr("Error"), tr("Can't load Thesaurus Database"));
return;
}
ThesaurusDialog *thesaurusDialog=new ThesaurusDialog(this);
QString word;
if (currentEditorView()) {
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
if(line>-1 && col>-1){
m_cursor.moveTo(line,col);
}
if(m_cursor.hasSelection()) word=m_cursor.selectedText();
else {
m_cursor.select(QDocumentCursor::WordUnderCursor);
word=m_cursor.selectedText();
}
word=latexToPlainWord(word);
thesaurusDialog->setSearchWord(word);
if (thesaurusDialog->exec()){
QString replace=thesaurusDialog->getReplaceWord();
m_cursor.document()->clearLanguageMatches();
m_cursor.insertText(replace);
}
}
delete thesaurusDialog;
}
void Texmaker::editChangeLineEnding() {
if (!currentEditorView()) return;
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
currentEditorView()->editor->document()->setLineEnding(QDocument::LineEnding(action->data().toInt()));
UpdateCaption();
}
void Texmaker::editSetupEncoding() {
if (!currentEditorView()) return;
EncodingDialog enc(this,currentEditorView()->editor);
enc.exec();
UpdateCaption();
}
void Texmaker::editInsertUnicode(){
if (!currentEditorView()) return;
QDocumentCursor c=currentEditor()->cursor();
if (!c.isValid()) return;
int curPoint = 0;
if (c.hasSelection()) {
QString sel = c.selectedText();
if (sel.length() == 1) curPoint = sel[0].unicode();
else if (sel.length() == 2 && sel.at(0).isHighSurrogate() && sel.at(1).isLowSurrogate()) {
curPoint = sel.toUcs4().value(0, 0);
} else c.setAnchorColumnNumber(c.columnNumber());
currentEditor()->setCursor(c);
}
QPoint offset;
UnicodeInsertion * uid = new UnicodeInsertion (currentEditorView(), curPoint);
if (!currentEditor()->getPositionBelowCursor(offset, uid->width(), uid->height())){
delete uid;
return;
}
connect(uid, SIGNAL(insertCharacter(QString)), currentEditor(), SLOT(insertText(QString)));
connect(uid, SIGNAL(destroyed()), currentEditor(), SLOT(setFocus()));
connect(currentEditor(), SIGNAL(cursorPositionChanged()), uid, SLOT(close()));
connect(currentEditor(), SIGNAL(visibleLinesChanged()), uid, SLOT(close()));
connect(currentEditor()->document(), SIGNAL(contentsChanged()), uid, SLOT(close()));
uid->move(currentEditor()->mapTo(uid->parentWidget(), offset));
this->unicodeInsertionDialog = uid;
uid->show();
uid->setFocus();
}
void Texmaker::editIndentSection() {
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
QDocumentSelection sel = entry->document->sectionSelection(entry);
// replace list
QStringList m_replace;
m_replace << "\\subparagraph" << "\\paragraph" << "\\subsubsection" << "\\subsection" << "\\section" << "\\chapter";
// replace sections
QString m_line;
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
for (int l=sel.startLine; l<sel.endLine; l++) {
currentEditorView()->editor->setCursorPosition(l,0);
m_cursor=currentEditorView()->editor->cursor();
m_line=currentEditorView()->editor->cursor().line().text();
QString m_old="";
foreach(const QString& elem,m_replace) {
if (m_old!="") m_line.replace(elem,m_old);
m_old=elem;
}
m_cursor.movePosition(1,QDocumentCursor::EndOfLine, QDocumentCursor::KeepAnchor);
currentEditor()->setCursor(m_cursor);
currentEditor()->insertText(m_line);
}
}
void Texmaker::editUnIndentSection() {
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
QDocumentSelection sel = entry->document->sectionSelection(entry);
QStringList m_replace;
m_replace << "\\chapter" << "\\section" << "\\subsection" << "\\subsubsection" << "\\paragraph" << "\\subparagraph" ;
// replace sections
QString m_line;
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
for (int l=sel.startLine; l<sel.endLine; l++) {
currentEditorView()->editor->setCursorPosition(l,0);
m_cursor=currentEditorView()->editor->cursor();
m_line=currentEditorView()->editor->cursor().line().text();
QString m_old="";
foreach(const QString& elem,m_replace) {
if (m_old!="") m_line.replace(elem,m_old);
m_old=elem;
}
m_cursor.movePosition(1,QDocumentCursor::EndOfLine, QDocumentCursor::KeepAnchor);
currentEditor()->setCursor(m_cursor);
currentEditor()->insertText(m_line);
}
}
void Texmaker::editSectionCopy() {
// called by action
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
QDocumentSelection sel = entry->document->sectionSelection(entry);
editSectionCopy(sel.startLine+1,sel.endLine);
}
void Texmaker::editSectionCut() {
// called by action
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
QDocumentSelection sel = entry->document->sectionSelection(entry);
editSectionCut(sel.startLine+1,sel.endLine);
//UpdateStructure();
}
void Texmaker::editSectionCopy(int startingLine, int endLine) {
if (!currentEditorView()) return;
currentEditorView()->editor->setCursorPosition(startingLine-1,0);
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
//m_cursor.movePosition(1, QDocumentCursor::NextLine, QDocumentCursor::KeepAnchor);
m_cursor.setSilent(true);
m_cursor.movePosition(endLine-startingLine, QDocumentCursor::NextLine, QDocumentCursor::KeepAnchor);
m_cursor.movePosition(0,QDocumentCursor::EndOfLine,QDocumentCursor::KeepAnchor);
currentEditorView()->editor->setCursor(m_cursor);
currentEditorView()->editor->copy();
}
void Texmaker::editSectionCut(int startingLine, int endLine) {
if (!currentEditorView()) return;
currentEditorView()->editor->setCursorPosition(startingLine-1,0);
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
m_cursor.setSilent(true);
m_cursor.movePosition(endLine-startingLine, QDocumentCursor::NextLine, QDocumentCursor::KeepAnchor);
m_cursor.movePosition(0,QDocumentCursor::EndOfLine,QDocumentCursor::KeepAnchor);
currentEditorView()->editor->setCursor(m_cursor);
currentEditorView()->editor->cut();
}
void Texmaker::editSectionPasteBefore() {
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
editSectionPasteBefore(entry->getRealLineNumber());
//UpdateStructure();
}
void Texmaker::editSectionPasteAfter() {
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || !entry->document->getEditorView()) return;
EditorTabs->setCurrentEditor(entry->document->getEditorView());
QDocumentSelection sel=entry->document->sectionSelection(entry);
editSectionPasteAfter(sel.endLine);
//UpdateStructure();
}
void Texmaker::editSectionPasteAfter(int line) {
REQUIRE(currentEditorView());
if (line>=currentEditorView()->editor->document()->lines()) {
currentEditorView()->editor->setCursorPosition(line-1,0);
QDocumentCursor c=currentEditorView()->editor->cursor();
c.movePosition(1,QDocumentCursor::End,QDocumentCursor::MoveAnchor);
currentEditor()->setCursor(c);
currentEditor()->insertText("\n");
} else {
currentEditor()->setCursorPosition(line,0);
currentEditor()->insertText("\n");
currentEditor()->setCursorPosition(line,0);
}
currentEditorView()->paste();
}
void Texmaker::editSectionPasteBefore(int line) {
REQUIRE(currentEditor());
currentEditor()->setCursorPosition(line,0);
currentEditor()->insertText("\n");
currentEditor()->setCursorPosition(line,0);
currentEditorView()->paste();
}
void Texmaker::editTextToLowercase() {
if (!currentEditorView()) return;
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
QString text = m_cursor.selectedText();
if (text.isEmpty()) return;
m_cursor.beginEditBlock();
m_cursor.insertText(text.toLower());
m_cursor.endEditBlock();
}
void Texmaker::editTextToUppercase() {
if (!currentEditorView()) return;
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
QString text = m_cursor.selectedText();
if (text.isEmpty()) return;
m_cursor.beginEditBlock();
m_cursor.insertText(text.toUpper());
m_cursor.endEditBlock();
}
/*!
* Converts the selected text to title case. Small words like a,an etc. are not converted.
* \param smart: Words containing capital letters are not converted because the are assumed to be acronymes.
*/
void Texmaker::editTextToTitlecase(bool smart) {
if (!currentEditorView()) return;
QDocumentCursor m_cursor=currentEditorView()->editor->cursor();
QString text = m_cursor.selectedText();
if (text.isEmpty()) return;
m_cursor.beginEditBlock();
// easier to be done in javascript
scriptengine* eng = new scriptengine();
eng->setEditorView(currentEditorView());
QString script =
"/* \n" \
" * To Title Case 2.1 – http://individed.com/code/to-title-case/ \n" \
" * Copyright © 2008–2013 David Gouch. Licensed under the MIT License.\n" \
"*/ \n" \
"String.prototype.toTitleCase = function(){\n" \
"var smallWords = /^(a|an|and|as|at|but|by|en|for|if|in|nor|of|on|or|per|the|to|vs?\\.?|via)$/i;\n" \
"return this.replace(/[A-Za-z0-9\\u00C0-\\u00FF]+[^\\s-]*/g, function(match, index, title){\n" \
"if (index > 0 && index + match.length !== title.length &&\n" \
" match.search(smallWords) > -1 && title.charAt(index - 2) !== \":\" &&\n" \
" (title.charAt(index + match.length) !== '-' || title.charAt(index - 1) === '-') &&\n" \
" title.charAt(index - 1).search(/[^\\s-]/) < 0) {\n" \
" return match.toLowerCase();\n" \
"}\n";
if (smart) {
script +=
"if (match.substr(1).search(/[A-Z]|\\../) > -1) {\n" \
"return match;\n" \
"}\n" \
"return match.charAt(0).toUpperCase() + match.substr(1);\n";
} else {
script +=
"return match.charAt(0).toUpperCase() + match.substr(1).toLowerCase();\n";
}
script +=
"});\n" \
"};\n" \
"cursor.insertText(cursor.selectedText().toTitleCase())";
eng->setScript(script);
eng->run();
if (!eng->globalObject) delete eng;
m_cursor.endEditBlock();
}
void Texmaker::editTextToTitlecaseSmart() {
editTextToTitlecase(true);
}
void Texmaker::editFind(){
#ifndef NO_POPPLER_PREVIEW
QWidget* w = QApplication::focusWidget();
while (w && !qobject_cast<PDFDocument*>(w))
w = w->parentWidget();
if (qobject_cast<PDFDocument*>(w)){
PDFDocument* focusedPdf = qobject_cast<PDFDocument*>(w);
if (focusedPdf->embeddedMode) {
focusedPdf->search();
return;
}
}
#endif
if (!currentEditor()) return;
currentEditor()->find();
}
/////////////// CONFIG ////////////////////
void Texmaker::ReadSettings(bool reread) {
QuickDocumentDialog::registerOptions(configManager);
QuickBeamerDialog::registerOptions(configManager);
buildManager.registerOptions(configManager);
configManager.registerOption("Files/Default File Filter", &selectedFileFilter);
configManager.registerOption("PDFSplitter",&pdfSplitterRel,0.5);
configManager.buildManager=&buildManager;
scriptengine::buildManager=&buildManager;
scriptengine::app=this;
QSettings *config=configManager.readSettings(reread);
completionBaseCommandsUpdated=true;
config->beginGroup("texmaker");
QRect screen = QApplication::desktop()->availableGeometry();
int w= config->value("Geometries/MainwindowWidth",screen.width()-100).toInt();
int h= config->value("Geometries/MainwindowHeight",screen.height()-100).toInt() ;
int x= config->value("Geometries/MainwindowX",screen.x()+10).toInt();
int y= config->value("Geometries/MainwindowY",screen.y()+10).toInt() ;
int screenNumber = QApplication::desktop()->screenNumber(QPoint(x,y));
screen = QApplication::desktop()->availableGeometry(screenNumber);
if (!screen.contains(x,y)) {
// top left is not on screen
x = screen.x() + 10;
y = screen.y() + 10;
if (x+w > screen.right()) w = screen.width()-100;
if (y+h > screen.height()) h = screen.height()-100;
}
resize(w,h);
move(x,y);
windowstate=config->value("MainWindowState").toByteArray();
stateFullScreen=config->value("MainWindowFullssscreenState").toByteArray();
tobemaximized=config->value("MainWindow/Maximized",false).toBool();
tobefullscreen=config->value("MainWindow/FullScreen",false).toBool();
documents.model->setSingleDocMode(config->value("StructureView/SingleDocMode",false).toBool());
QList<QStringList> defaults = QList<QStringList>()
<< (QStringList() << "\\part")
<< (QStringList() << "\\chapter")
<< (QStringList() << "\\section")
<< (QStringList() << "\\subsection")
<< (QStringList() << "\\subsubsection")
<< (QStringList() << "\\paragraph")
<< (QStringList() << "\\subparagraph");
latexParser.structureCommandLists.clear();
for (int level=0; level<defaults.length(); level++) {
QStringList cmds = config->value("Structure/Structure Level " + QString::number(level+1)).toStringList();
if (!cmds.isEmpty()) {
for (int i=0; i<cmds.length(); i++) {
if (!cmds[i].startsWith("\\")) cmds[i].prepend("\\");
}
latexParser.structureCommandLists << cmds;
} else {
latexParser.structureCommandLists << defaults[level];
}
}
spellerManager.setIgnoreFilePrefix(configManager.configFileNameBase);
spellerManager.setDictPaths(configManager.parseDirList(configManager.spellDictDir));
spellerManager.setDefaultSpeller(configManager.spellLanguage);
ThesaurusDialog::setUserPath(configManager.configFileNameBase);
ThesaurusDialog::prepareDatabase(configManager.thesaurus_database);
MapForSymbols= new QVariantMap;
*MapForSymbols=config->value("Symbols/Quantity").toMap();
hiddenLeftPanelWidgets=config->value("Symbols/hiddenlists","").toString();
symbolFavorites=config->value("Symbols/Favorite IDs",QStringList()).toStringList();
configManager.editorKeys = QEditor::getEditOperations(false); //this will also initialize the default keys
configManager.editorAvailableOperations=QEditor::getAvailableOperations();
if (config->value("Editor/Use Tab for Move to Placeholder",false).toBool()) {
//import deprecated option
QEditor::addEditOperation(QEditor::NextPlaceHolder, Qt::ControlModifier, Qt::Key_Tab);
QEditor::addEditOperation(QEditor::PreviousPlaceHolder, Qt::ShiftModifier | Qt::ControlModifier, Qt::Key_Backtab);
QEditor::addEditOperation(QEditor::CursorWordLeft, Qt::ControlModifier, Qt::Key_Left);
QEditor::addEditOperation(QEditor::CursorWordRight, Qt::ControlModifier, Qt::Key_Right);
};
// import and remove old key mapping
{config->beginGroup("Editor Key Mapping");
QStringList sl = config->childKeys();
if (!sl.empty()) {
foreach (const QString& key, sl) {
int k = key.toInt();
if (k==0) continue;
int operationID = config->value(key).toInt();
QString defaultKey = configManager.editorKeys.key(operationID);
if (!defaultKey.isNull()) {
configManager.editorKeys.remove(defaultKey);
}
configManager.editorKeys.insert(QKeySequence(k).toString(), config->value(key).toInt());
}
QEditor::setEditOperations(configManager.editorKeys);
config->remove("");
}
config->endGroup();}
config->beginGroup("Editor Key Mapping New");
QStringList sl = config->childKeys();
QSet<int>manipulatedOps;
if (!sl.empty()) {
foreach (const QString& key, sl) {
if (key.isEmpty()) continue;
int operationID = config->value(key).toInt();
if(!manipulatedOps.contains(operationID)){ // remove predefined keys only once
QStringList defaultKeys = configManager.editorKeys.keys(operationID);
if (!defaultKeys.isEmpty()) {
foreach(const QString elem,defaultKeys){
configManager.editorKeys.remove(elem);
}
manipulatedOps.insert(operationID);
}
}
configManager.editorKeys.insert(key, operationID);
}
QEditor::setEditOperations(configManager.editorKeys);
}
config->endGroup();
config->endGroup();
config->beginGroup("formats");
m_formats = new QFormatFactory(":/qxs/defaultFormats.qxf", this); //load default formats from resource file
if (config->contains("data/styleHint/bold")) {
//rename data/styleHint/* => data/wordRepetition/*
config->beginGroup("data");
config->beginGroup("styleHint");
QStringList temp = config->childKeys();
config->endGroup();
foreach (const QString& s, temp) config->setValue("wordRepetition/"+s, config->value("styleHint/"+s));
config->remove("styleHint");
config->endGroup();
}
m_formats->load(*config,true); //load customized formats
config->endGroup();
// read usageCount from file of its own.
if (!reread) {
LatexCompleterConfig *conf=configManager.completerConfig;
QFile file(configManager.configBaseDir+"wordCount.usage");
if(file.open(QIODevice::ReadOnly)){
QDataStream in(&file);
quint32 magicNumer,version;
in >> magicNumer >> version;
if (magicNumer==(quint32)0xA0B0C0D0 && version==1){
in.setVersion(QDataStream::Qt_4_0);
uint key;
int length,usage;
conf->usage.clear();
while (!in.atEnd()) {
in >> key >> length >> usage;
if(usage>0){
conf->usage.insert(key,qMakePair(length,usage));
}
}
}
}
}
documents.settingsRead();
configManager.editorConfig->settingsChanged();
}
void Texmaker::SaveSettings(const QString& configName) {
bool asProfile=!configName.isEmpty();
configManager.centralVisible=centralToolBar->isVisible();
// update completion usage
LatexCompleterConfig *conf=configManager.completerConfig;
#ifndef NO_POPPLER_PREVIEW
//pdf viewer embedded open ?
if(!PDFDocument::documentList().isEmpty()){
PDFDocument* doc=PDFDocument::documentList().first();
if(doc->embeddedMode){
QList<int> sz=mainHSplitter->sizes(); // set widths to 50%, eventually restore user setting
int sum=0;
int last=0;
foreach(int i,sz){
sum+=i;
last=i;
}
if(last>10)
pdfSplitterRel=1.0*last/sum;
}
}
#endif
QSettings *config=configManager.saveSettings(configName);
config->beginGroup("texmaker");
QList<int> sizes;
QList<int>::Iterator it;
if(!asProfile){
if(isFullScreen()){
config->setValue("MainWindowState",windowstate);
config->setValue("MainWindowFullssscreenState",saveState(1));
}else {
config->setValue("MainWindowState",saveState(0));
config->setValue("MainWindowFullssscreenState",stateFullScreen);
}
config->setValue("MainWindow/Maximized", isMaximized());
config->setValue("MainWindow/FullScreen", isFullScreen());
config->setValue("Geometries/MainwindowWidth", width());
config->setValue("Geometries/MainwindowHeight", height());
config->setValue("Geometries/MainwindowX", x());
config->setValue("Geometries/MainwindowY", y());
config->setValue("Files/RestoreSession",ToggleRememberAct->isChecked());
config->setValue("centralVSplitterState", centralVSplitter->saveState());
config->setValue("GUI/outputView/visible", outputView->isVisible());
Session s = getCurrentSession();
s.save(QFileInfo(QDir(configManager.configBaseDir), "lastSession.txss").filePath());
}
for(int i=0;i<struct_level.count();i++)
config->setValue("Structure/Structure Level "+QString::number(i+1),struct_level[i]);
MapForSymbols->clear();
foreach(QTableWidgetItem *elem,symbolMostused){
int cnt=elem->data(Qt::UserRole).toInt();
if (cnt<1) continue;
QString text=elem->data(Qt::UserRole+2).toString();
if(MapForSymbols->value(text).toInt()>cnt) cnt=MapForSymbols->value(text).toInt();
MapForSymbols->insert(text,cnt);
}
config->setValue("Symbols/Quantity",*MapForSymbols);
config->setValue("Symbols/Favorite IDs",symbolFavorites);
config->setValue("Symbols/hiddenlists",leftPanel->hiddenWidgets());
config->setValue("StructureView/SingleDocMode",documents.model->getSingleDocMode());
QHash<QString, int> keys = QEditor::getEditOperations(true);
config->remove("Editor/Use Tab for Move to Placeholder");
config->beginGroup("Editor Key Mapping New");
if (!keys.empty() || !config->childKeys().empty()) {
config->remove("");
QHash<QString, int>::const_iterator i = keys.begin();
while (i != keys.constEnd()) {
if(!i.key().isEmpty()) //avoid crash
config->setValue(i.key(), i.value());
++i;
}
}
config->endGroup();
config->endGroup();
config->beginGroup("formats");
QFormatFactory defaultFormats(":/qxs/defaultFormats.qxf", this); //load default formats from resource file
m_formats->save(*config,&defaultFormats);
config->endGroup();
// save usageCount in file of its own.
if(!asProfile){
QFile file(configManager.configBaseDir+"wordCount.usage");
if(file.open(QIODevice::WriteOnly)){
QDataStream out(&file);
out << (quint32)0xA0B0C0D0; //magic number
out << (qint32)1; //version
out.setVersion(QDataStream::Qt_4_0);
QMap<uint, QPair<int,int> >::const_iterator i = conf->usage.constBegin();
while (i != conf->usage.constEnd()) {
QPair<int,int> elem=i.value();
if(elem.second>0){
out << i.key();
out << elem.first;
out << elem.second;
}
++i;
}
}
}
if (asProfile)
delete config;
}
////////////////// STRUCTURE ///////////////////
void Texmaker::ShowStructure() {
leftPanel->setCurrentWidget(structureTreeView);
}
void Texmaker::updateStructure(bool initial,LatexDocument *doc,bool hidden) {
// collect user define tex commands for completer
// initialize List
if ((!currentEditorView() || !currentEditorView()->document) && !doc) return;
if(!doc)
doc = currentEditorView()->document;
if(initial){
//int len=doc->lineCount();
if(doc->patchStructure(0,-1))
doc->patchStructure(0,-1); // do a second run, if packages are load (which might define new commands)
// admitedly this solution is expensive (though working)
//TODO: does not working when entering \usepackage in text ... !
doc->updateMagicCommentScripts();
configManager.completerConfig->userMacros << doc->localMacros;
updateUserMacros();
}
else {
doc->updateStructure();
}
if(!hidden){
updateCompleter(doc->getEditorView());
cursorPositionChanged();
}
//structureTreeView->reset();
}
void Texmaker::clickedOnStructureEntry(const QModelIndex & index){
const StructureEntry* entry = LatexDocumentsModel::indexToStructureEntry(index);
if (!entry) return;
if (!entry->document) return;
if (QApplication::mouseButtons()==Qt::RightButton) return; // avoid jumping to line if contextmenu is called
LatexDocument *doc=entry->document;
switch (entry->type){
case StructureEntry::SE_DOCUMENT_ROOT:
if (entry->document->getEditorView())
EditorTabs->setCurrentEditor(entry->document->getEditorView());
else
load(entry->document->getFileName());
break;
case StructureEntry::SE_OVERVIEW:
break;
case StructureEntry::SE_MAGICCOMMENT:
if(entry->valid){
QString s=entry->title;
QString name;
QString val;
doc->splitMagicComment(s, name, val);
if ((name.toLower() == "texroot")||(name.toLower() == "root")){
QString fname=doc->findFileName(val);
load(fname);
break;
}
}
case StructureEntry::SE_SECTION:
case StructureEntry::SE_TODO:
case StructureEntry::SE_LABEL:{
int lineNr=-1;
mDontScrollToItem = entry->type!=StructureEntry::SE_SECTION;
LatexEditorView* edView=entry->document->getEditorView();
QEditor::MoveFlags mflags = QEditor::NavigationToHeader;
if (!entry->document->getEditorView()){
lineNr=entry->getRealLineNumber();
edView=load(entry->document->getFileName());
if (!edView) return;
mflags &= ~QEditor::Animated;
//entry is now invalid
} else lineNr=LatexDocumentsModel::indexToStructureEntry(index)->getRealLineNumber();
gotoLine(lineNr,0,edView, mflags);
break;
}
case StructureEntry::SE_INCLUDE:
case StructureEntry::SE_BIBTEX:{
saveCurrentCursorToHistory();
QString defaultExt=entry->type==StructureEntry::SE_BIBTEX?".bib":".tex";
openExternalFile(entry->title,defaultExt,entry->document);
break;
}
}
}
void Texmaker::editRemovePlaceHolders(){
if (!currentEditor()) return;
for (int i=currentEditor()->placeHolderCount();i>=0;i--)
currentEditor()->removePlaceHolder(i);
currentEditor()->viewport()->update();
}
void Texmaker::editRemoveCurrentPlaceHolder() {
if (!currentEditor()) return;
currentEditor()->removePlaceHolder(currentEditor()->currentPlaceHolder());
}
//////////TAGS////////////////
void Texmaker::NormalCompletion() {
if (!currentEditorView()) return;
LatexEditorView *view=currentEditorView();
// complete text if no command is present
QDocumentCursor c = currentEditorView()->editor->cursor();
QString eow=getCommonEOW();
int i=0;
int col=c.columnNumber();
QString word=c.line().text();
while (c.columnNumber()>0 && !eow.contains(c.previousChar())) {
c.movePosition(1,QDocumentCursor::PreviousCharacter);
i++;
}
QString command,value;
LatexParser::ContextType ctx=view->lp.findContext(word, c.columnNumber(), command, value);
switch(ctx){
case LatexParser::Command:
if(mCompleterNeedsUpdate) updateCompleter();
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST);
break;
case LatexParser::Environment:
if(mCompleterNeedsUpdate) updateCompleter();
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST);
break;
case LatexParser::Reference:
if(mCompleterNeedsUpdate) updateCompleter();
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_REF);
break;
case LatexParser::Citation:
if(mCompleterNeedsUpdate) updateCompleter();
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_CITE);
break;
case LatexParser::Graphics:
{QString fn=documents.getCompileFileName();
QFileInfo fi(fn);
completer->setWorkPath(fi.absolutePath());
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_GRAPHIC);}
break;
case LatexParser::ArgEx:
{
QSet<QPair<QString,int> > helper=view->lp.specialTreatmentCommands[command];
QPair<QString,int> elem;
int pos=1;
bool found=false;
foreach(elem,helper){
if(elem.second==pos){
found=true;
break;
}
}
if(found){
if(mCompleterNeedsUpdate) updateCompleter();
QString context="%"+elem.first;
completer->setWorkPath(context);
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_SPECIALOPTION);}
}
break;
case LatexParser::OptionEx:
{
QSet<QPair<QString,int> > helper=view->lp.specialTreatmentCommands[command];
QPair<QString,int> elem;
int pos=0;
bool found=false;
foreach(elem,helper){
if(elem.second==pos){
found=true;
break;
}
}
if(found){
if(mCompleterNeedsUpdate) updateCompleter();
QString context="%"+elem.first;
completer->setWorkPath(context);
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_SPECIALOPTION);}
}
break;
case LatexParser::Keyval:
if(command.endsWith("#c")){
command.chop(2);
}
completer->setWorkPath(command);
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_KEYVAL);
break;
case LatexParser::KeyvalValue:{
//figure out keyval
if(command.endsWith("#c")){
command.chop(2);
}
int i=c.columnNumber();
while(i>0 && word.at(i-1).isLetter())
i--;
if(word.at(i-1)==QChar('=')){
int j=--i;
while(i>0 && (word.at(i-1).isLetter()||word.at(i-1)==' '))
i--;
QString key=word.mid(i,j-i).simplified();
completer->setWorkPath(command+"/"+key);
if(completer->existValues())
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_KEYVAL);
}
break;
}
case LatexParser::Package:
if(latexParser.possibleCommands["%usepackage"].contains(command)){
QString preambel;
if(command.endsWith("theme")){ // special treatment for \usetheme
preambel=command;
preambel.remove(0,4);
preambel.prepend("beamer");
currentPackageList.clear();
foreach(QString elem,latexPackageList){
if(elem.startsWith(preambel))
currentPackageList<<elem.mid(preambel.length());
}
completer->setPackageList(¤tPackageList);
}else{
completer->setPackageList(&latexPackageList);
}
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_FORCE_PACKAGE);
break;
}
default:
if (i>1) {
QString my_text=currentEditorView()->editor->text();
int end=0;
int k=0; // number of occurences of search word.
word=word.mid(col-i,i);
//TODO: Boundary needs to specified more exactly
//TODO: type in text needs to be excluded, if not already present
QSet<QString> words;
while ((i=my_text.indexOf(QRegExp("\\b"+word),end))>0) {
end=my_text.indexOf(QRegExp("\\b"),i+1);
if (end>i) {
if (word==my_text.mid(i,end-i)) {
k=k+1;
if (k==2) words << my_text.mid(i,end-i);
} else {
if (!words.contains(my_text.mid(i,end-i)))
words << my_text.mid(i,end-i);
}
} else {
if (word==my_text.mid(i,end-i)) {
k=k+1;
if (k==2) words << my_text.mid(i,end-i);
} else {
if (!words.contains(my_text.mid(i,end-i)))
words << my_text.mid(i,my_text.length()-i);
}
}
}
completer->setAdditionalWords(words,CT_NORMALTEXT);
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_NORMAL_TEXT);
}
}
}
void Texmaker::InsertEnvironmentCompletion() {
if (!currentEditorView()) return;
if(mCompleterNeedsUpdate) updateCompleter();
QDocumentCursor c = currentEditorView()->editor->cursor();
if(c.hasSelection()){
currentEditor()->cutBuffer=c.selectedText();
c.removeSelectedText();
}
QString eow=getCommonEOW();
while (c.columnNumber()>0 && !eow.contains(c.previousChar())) c.movePosition(1,QDocumentCursor::PreviousCharacter);
static const QString environmentStart = "\\begin{";
currentEditor()->document()->clearLanguageMatches();
if (!c.line().text().left(c.columnNumber()).endsWith(environmentStart)){
c.insertText(environmentStart);//remaining part is up to the completion engine
}
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST);
}
// tries to complete normal text
// only starts up if already 2 characters have been typed in
void Texmaker::InsertTextCompletion() {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditorView()->editor->cursor();
QString eow=getCommonEOW();
int i=0;
int col=c.columnNumber();
QString word=c.line().text();
while (c.columnNumber()>0 && !eow.contains(c.previousChar())) {
c.movePosition(1,QDocumentCursor::PreviousCharacter);
i++;
}
if (i>1) {
QString my_text=currentEditorView()->editor->text();
int end=0;
int k=0; // number of occurences of search word.
word=word.mid(col-i,i);
//TODO: Boundary needs to specified more exactly
//TODO: type in text needs to be excluded, if not already present
QSet<QString> words;
while ((i=my_text.indexOf(QRegExp("\\b"+word),end))>0) {
end=my_text.indexOf(QRegExp("\\b"),i+1);
if (end>i) {
if (word==my_text.mid(i,end-i)) {
k=k+1;
if (k==2) words << my_text.mid(i,end-i);
} else {
if (!words.contains(my_text.mid(i,end-i)))
words << my_text.mid(i,end-i);
}
} else {
if (word==my_text.mid(i,end-i)) {
k=k+1;
if (k==2) words << my_text.mid(i,end-i);
} else {
if (!words.contains(my_text.mid(i,end-i)))
words << my_text.mid(i,my_text.length()-i);
}
}
}
completer->setAdditionalWords(words, CT_NORMALTEXT);
currentEditorView()->complete(LatexCompleter::CF_FORCE_VISIBLE_LIST | LatexCompleter::CF_NORMAL_TEXT);
}
}
void Texmaker::InsertTag(const QString &Entity, int dx, int dy) {
if (!currentEditorView()) return;
int curline,curindex;
currentEditor()->getCursorPosition(curline,curindex);
currentEditor()->write(Entity);
if (dy==0) currentEditor()->setCursorPosition(curline,curindex+dx);
else if (dx==0) currentEditor()->setCursorPosition(curline+dy,0);
else currentEditor()->setCursorPosition(curline+dy,curindex+dx);
currentEditor()->setFocus();
// outputView->setMessage("");
//logViewerTabBar->setCurrentIndex(0);
//OutputTable->hide();
//logpresent=false;
}
/*!
\brief Inserts a citation at the cursor position.
\a text may be either a complete (also custom) command like \mycite{key} or just the key. In the
latter case it is expanded to \cite{key}. Key may also be a comma separated list of keys.
The cursor context is evaluated: If it is within a citation command only the key is inserted at the correct
position within the existing citation. If not, the whole command is inserted.
*/
void Texmaker::InsertCitation(const QString &text) {
QString citeCmd, citeKey;
if (text.length() > 1 && text.at(0) == '\\') {
LatexParser::ContextType ctx = latexParser.findContext(text, 1, citeCmd, citeKey);
if (LatexParser::Command != ctx) {
citeCmd = "";
citeKey = text;
}
} else {
citeCmd = "";
citeKey = text;
}
if (!currentEditorView()) return;
QDocumentCursor c=currentEditor()->cursor();
QString line = c.line().text();
int cursorCol = c.columnNumber();
QString command, value;
LatexParser::ContextType context = latexParser.findContext(line, cursorCol, command, value);
// Workaround: findContext yields Citation for \cite{..}|\n, but cursorCol is beyond the line,
// which causes a crash when determining the insertCol later on.
if (context == LatexParser::Citation && cursorCol == line.length() && cursorCol > 0) cursorCol--;
// if cursor is directly behind a cite command, isert into that command
if (context != LatexParser::Citation && cursorCol > 0) {
LatexParser::ContextType prevContext = LatexParser::Unknown;
prevContext = latexParser.findContext(line, cursorCol-1, command, value);
if (prevContext == LatexParser::Citation) {
cursorCol--;
context = prevContext;
}
}
int insertCol = -1;
if (context == LatexParser::Command && latexParser.possibleCommands["%cite"].contains(command)) {
insertCol = line.indexOf('{', cursorCol)+1;
} else if (context == LatexParser::Citation) {
if (cursorCol <= 0) return; // should not be possible,
if (line.at(cursorCol) == '{' || line.at(cursorCol) == ',') {
insertCol = cursorCol+1;
} else if (line.at(cursorCol-1) == '{' || line.at(cursorCol-1) == ',') {
insertCol = cursorCol;
} else {
int nextComma = line.indexOf(',', cursorCol);
int closingBracket = line.indexOf('}', cursorCol);
if (nextComma >= 0 && (closingBracket == -1 || closingBracket > nextComma)) {
insertCol = nextComma+1;
} else if (closingBracket >= 0) {
insertCol = closingBracket;
}
}
} else {
QString tag;
if (citeCmd.isEmpty())
tag = citeCmd = "\\cite{"+citeKey+"}";
else
tag = text;
InsertTag(tag, tag.length());
return;
}
if (insertCol < 0 || insertCol >= line.length()) return;
currentEditor()->setCursorPosition(c.lineNumber(), insertCol);
// now the insertCol is either behind '{', behind ',' or at '}'
if (insertCol > 0 && line.at(insertCol-1) == '{') {
if (line.at(insertCol) == '}') {
InsertTag(citeKey, citeKey.length());
} else {
InsertTag(citeKey+",", citeKey.length()+1);
}
} else if (insertCol > 0 && line.at(insertCol-1) == ',') {
InsertTag(citeKey+",", citeKey.length()+1);
} else {
InsertTag(","+citeKey, citeKey.length()+1);
}
}
void Texmaker::InsertFormula(const QString &formula) {
if (!currentEditorView()) return;
QString fm = formula;
QDocumentCursor cur = currentEditorView()->editor->cursor();
//TODO: Is there a more elegant solution to determine if the cursor is inside a math environment.
QDocumentLine dl = cur.line();
int col = cur.columnNumber();
QList<int> mathFormats = QList<int>() << m_formats->id("numbers") << m_formats->id("math-keyword");
int mathDelimiter = m_formats->id("math-delimiter");
mathFormats.removeAll(0); // keep only valid entries in list
if (mathFormats.contains(dl.getFormatAt(col))) { // inside math
fm = fm.mid(1, fm.length()-2); // removes surrounding $...$
} else if (dl.getFormatAt(col) == mathDelimiter) { // on delimiter
while (col>0 && dl.getFormatAt(col-1) == mathDelimiter) col--;
if (mathFormats.contains(dl.getFormatAt(col))) { // was an end-delimiter
cur.setColumnNumber(col);
currentEditorView()->editor->setCursor(cur);
fm = fm.mid(1, fm.length()-2); // removes surrounding $...$
} else {
//TODO is terhe a better way than hard coding? Since there is no difference in the formats between
//start and end tags. \[|\] is hard identify without.
QString editorFormula = dl.text().mid(col);
if (editorFormula.startsWith("\\[")) {
col+=2;
currentEditorView()->editor->setCursor(cur);
fm = fm.mid(1, fm.length()-2); // removes surrounding $...$
} else if (editorFormula.startsWith("$")) {
col+=1;
currentEditorView()->editor->setCursor(cur);
fm = fm.mid(1, fm.length()-2); // removes surrounding $...$
} else {
qDebug() << "Unknown math formula tag. Giving up trying to locate formula boundaries.";
}
}
}
InsertTag(fm, fm.length());
}
void Texmaker::InsertSymbolPressed(QTableWidgetItem *) {
mb=QApplication::mouseButtons();
}
void Texmaker::InsertSymbol(QTableWidgetItem *item) {
if (mb==Qt::RightButton) return; // avoid jumping to line if contextmenu is called
QString code_symbol;
if (item) {
int cnt=item->data(Qt::UserRole).toInt();
if(item->data(Qt::UserRole+1).isValid()) {
item=item->data(Qt::UserRole+1).value<QTableWidgetItem*>();
cnt=item->data(Qt::UserRole).toInt();
}
if(configManager.insertUTF && item->data(Qt::UserRole+4).isValid()){
code_symbol=item->data(Qt::UserRole+4).toString();
}else{
code_symbol=item->text();
}
item->setData(Qt::UserRole,cnt+1);
InsertTag(code_symbol,code_symbol.length(),0);
SetMostUsedSymbols(item);
}
}
void Texmaker::InsertXmlTag(QListWidgetItem *item)
{
if (!currentEditorView()) return;
if (item && !item->font().bold()){
QString code=item->data(Qt::UserRole).toString();
QDocumentCursor c = currentEditorView()->editor->cursor();
CodeSnippet(code).insertAt(currentEditorView()->editor,&c);
currentEditorView()->editor->setFocus();
}
}
void Texmaker::insertXmlTagFromToolButtonAction(){
if (!currentEditorView()) return;
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
QToolButton *button = comboToolButtonFromAction(action);
if (!button) return;
button->setDefaultAction(action);
QString tagsID = button->property("tagsID").toString();
int tagCategorySep=tagsID.indexOf("/",5);
XmlTagsListWidget* tagsWidget = findChild<XmlTagsListWidget*>(tagsID.left(tagCategorySep));
if (!tagsWidget) return;
QString code=tagsWidget->tagsFromTagTxt(action->text());
CodeSnippet(code).insert(currentEditorView()->editor);
currentEditorView()->editor->setFocus();
}
void Texmaker::callToolButtonAction(){
QAction *action = qobject_cast<QAction *>(sender());
QToolButton *button = comboToolButtonFromAction(action);
REQUIRE(button && button->defaultAction() && button->menu());
button->setDefaultAction(action);
QString menuID = button->property("menuID").toString();
QMenu* menu=configManager.getManagedMenu(menuID);
if (!menu) return;
int index = button->menu()->actions().indexOf(action);
REQUIRE(index >= 0);
REQUIRE(index < menu->actions().size());
QList<QAction *> actions = menu->actions();
for (int i=0;i<actions.size();i++) {
if (actions[i]->isSeparator()) continue;
if (index == 0) {
actions[i]->trigger();
break;
} else index--;
}
}
void Texmaker::InsertFromAction() {
LatexEditorView *edView=currentEditorView();
if (!edView) return;
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
if(completer->isVisible())
completer->close();
/*QDocumentCursor c = currentEditorView()->editor->cursor();
CodeSnippet cs=CodeSnippet(action->data().toString());
cs.insertAt(currentEditorView()->editor,&c);*/
edView->insertMacro(action->data().toString(),QRegExp(),0,true);
generateMirror();
outputView->setMessage(CodeSnippet(action->whatsThis(), false).lines.join("\n"));
}
}
void Texmaker::InsertBib() {
if (!currentEditorView()) return;
//currentEditorView()->editor->viewport()->setFocus();
QString tag;
tag=QString("\\bibliography{");
tag +=currentEditor()->fileInfo().completeBaseName();
tag +=QString("}\n");
InsertTag(tag,0,1);
outputView->setMessage(QString("The argument to \\bibliography refers to the bib file (without extension)\n")+
"which should contain your database in BibTeX format.\n"+
"TeXstudio inserts automatically the base name of the TeX file");
}
void Texmaker::InsertStruct() {
QString actData, tag;
if (!currentEditorView()) return;
//currentEditorView()->editor->viewport()->setFocus();
QAction *action = qobject_cast<QAction *>(sender());
if (action) {
actData=action->data().toString();
StructDialog *stDlg = new StructDialog(this,actData);
if (stDlg->exec()) {
if (stDlg->ui.checkBox->isChecked()) {
tag=actData+"{";
} else {
tag=actData+"*{";
}
tag +=stDlg->ui.TitlelineEdit->text();
tag +=QString("}\n");
InsertTag(tag,0,1);
//updateStructure(); automatically done
}
}
}
void Texmaker::QuickTabular() {
if (!currentEditorView()) return;
QString al="";
QString vs="";
QString hs="";
QString tag;
TabDialog *quickDlg = new TabDialog(this,"Tabular");
//TODO: move this in tabdialog.h
if (quickDlg->exec()) {
int y = quickDlg->ui.spinBoxRows->value();
int x = quickDlg->ui.spinBoxColumns->value();
if ((quickDlg->ui.comboSeparator->currentIndex())==0) vs=QString("|");
if ((quickDlg->ui.comboSeparator->currentIndex())==1) vs=QString("||");
if ((quickDlg->ui.comboSeparator->currentIndex())==2) vs=QString("");
if ((quickDlg->ui.comboSeparator->currentIndex())==3) vs=QString("@{}");
tag = QString("\\begin{tabular}{")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==0) al=QString("c")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==1) al=QString("l")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==2) al=QString("r")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==3) al=QString("p{}")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==4) al=QString(">{\\centering\\arraybackslash}p{}")+vs;
if ((quickDlg->ui.comboAlignment->currentIndex())==5) al=QString(">{\\raggedleft\\arraybackslash}p{}")+vs;
if (quickDlg->ui.checkBox->isChecked()) {
hs=QString("\\hline ");
if (quickDlg->ui.checkBoxMargin->isChecked()) hs+="\\rule[-2ex]{0pt}{5.5ex} ";
}
for (int j=0; j<x; j++) {
tag +=al;
}
tag +=QString("}\n");
for (int i=0; i<y; i++) {
tag +=hs;
for (int j=0; j<x-1; j++) {
QTableWidgetItem * item =quickDlg->ui.tableWidget->item(i,j);
if (item) tag +=item->text()+ QString(" & ");
else tag +=QString(" & ");
}
QTableWidgetItem * item =quickDlg->ui.tableWidget->item(i,x-1);
if (item) tag +=item->text()+ QString(" \\\\ \n");
else tag +=QString(" \\\\ \n");
}
if (quickDlg->ui.checkBox->isChecked()) tag +=QString("\\hline \n\\end{tabular} ");
else tag +=QString("\\end{tabular} ");
InsertTag(tag,0,0);
}
}
void Texmaker::QuickArray() {
if (!currentEditorView()) return;
//TODO: move this in arraydialog class
QString al;
ArrayDialog *arrayDlg = new ArrayDialog(this,"Array");
if (arrayDlg->exec()) {
int y = arrayDlg->ui.spinBoxRows->value();
int x = arrayDlg->ui.spinBoxColumns->value();
QString env=arrayDlg->ui.comboEnvironment->currentText();
QString tag = QString("\\begin{")+env+"}";
if (env=="array") {
tag+="{";
if ((arrayDlg->ui.comboAlignment->currentIndex())==0) al=QString("c");
if ((arrayDlg->ui.comboAlignment->currentIndex())==1) al=QString("l");
if ((arrayDlg->ui.comboAlignment->currentIndex())==2) al=QString("r");
for (int j=0; j<x; j++) {
tag +=al;
}
tag+="}";
}
tag +=QString("\n");
for (int i=0; i<y-1; i++) {
for (int j=0; j<x-1; j++) {
QTableWidgetItem * item =arrayDlg->ui.tableWidget->item(i,j);
if (item) tag +=item->text()+ QString(" & ");
else tag +=QString(" & ");
}
QTableWidgetItem * item =arrayDlg->ui.tableWidget->item(i,x-1);
if (item) tag +=item->text()+ QString(" \\\\ \n");
else tag +=QString(" \\\\ \n");
}
for (int j=0; j<x-1; j++) {
QTableWidgetItem * item =arrayDlg->ui.tableWidget->item(y-1,j);
if (item) tag +=item->text()+ QString(" & ");
else tag +=QString(" & ");
}
QTableWidgetItem * item =arrayDlg->ui.tableWidget->item(y-1,x-1);
if (item) tag +=item->text()+ QString("\n\\end{")+env+"} ";
else tag +=QString("\n\\end{")+env+"} ";
InsertTag(tag,0,0);
}
}
// returns true if line is inside in the specified environment. In that case start and end lines of the environment are supplied
bool findEnvironmentLines(const QDocument *doc, const QString &env, int line, int &startLine, int &endLine, int scanRange) {
QString name, arg;
startLine = -1;
for (int l=line; l>=0; l--) {
if (scanRange>0 && line-l > scanRange) break;
if (findTokenWithArg(doc->line(l).text(), "\\end{", name, arg) && name == env) {
if (l<line) return false;
}
if (findTokenWithArg(doc->line(l).text(), "\\begin{", name, arg) && name == env) {
startLine = l;
break;
}
}
if (startLine == -1) return false;
endLine = -1;
for (int l=line; l<doc->lineCount(); l++) {
if (scanRange>0 && l-line > scanRange) break;
if (findTokenWithArg(doc->line(l).text(), "\\end{", name, arg) && name == env) {
endLine = l;
break;
}
if (findTokenWithArg(doc->line(l).text(), "\\begin{", name, arg) && name == env) {
if (l>line) return false; //second begin without end
}
}
if (endLine == -1) return false;
return true;
}
void Texmaker::QuickGraphics(const QString &graphicsFile) {
if (!currentEditorView()) return;
InsertGraphics *graphicsDlg = new InsertGraphics(this, configManager.insertGraphicsConfig);
QEditor *editor = currentEditor();
int startLine, endLine, cursorLine, cursorCol;
editor->getCursorPosition(cursorLine, cursorCol);
QDocument* doc=editor->document();
QDocumentCursor cur = currentEditor()->cursor();
QDocumentCursor origCur = cur;
origCur.setAutoUpdated(true);
bool hasCode = false;
if (findEnvironmentLines(doc, "figure", cursorLine, startLine, endLine, 20)) {
cur.moveTo(startLine, 0, QDocumentCursor::MoveAnchor);
cur.moveTo(endLine+1, 0, QDocumentCursor::KeepAnchor);
hasCode = true;
} else if (findEnvironmentLines(doc, "figure*", cursorLine, startLine, endLine, 20)) {
cur.moveTo(startLine, 0, QDocumentCursor::MoveAnchor);
cur.moveTo(endLine+1, 0, QDocumentCursor::KeepAnchor);
hasCode = true;
} else if (findEnvironmentLines(doc, "center", cursorLine, startLine, endLine, 3)) {
cur.moveTo(startLine, 0, QDocumentCursor::MoveAnchor);
cur.moveTo(endLine+1, 0, QDocumentCursor::KeepAnchor);
hasCode = true;
} else if (currentEditor()->text(cursorLine).contains("\\includegraphics")) {
cur.moveTo(cursorLine, 0, QDocumentCursor::MoveAnchor);
cur.moveTo(cursorLine+1, 0, QDocumentCursor::KeepAnchor);
hasCode = true;
}
if (hasCode) {
editor->setCursor(cur);
graphicsDlg->setCode(cur.selectedText());
}
QFileInfo docInfo=currentEditorView()->document->getFileInfo();
graphicsDlg->setTexFile(docInfo);
graphicsDlg->setMasterTexFile(currentEditorView()->document->parent->getCompileFileName());
if (!graphicsFile.isNull()) graphicsDlg->setGraphicsFile(graphicsFile);
if (graphicsDlg->exec()) {
QString code = graphicsDlg->getCode();
cur.beginEditBlock();
editor->cursor().replaceSelectedText(code);
if (editor->cursor().hasSelection()) {
editor->setCursor(cur.selectionEnd());
}
cur.endEditBlock();
} else {
editor->setCursor(origCur);
}
delete graphicsDlg;
}
void Texmaker::QuickMath() {
#ifdef Q_OS_WIN
connectUnique(MathAssistant::instance(), SIGNAL(formulaReceived(QString)), this, SLOT(InsertFormula(QString)));
MathAssistant::instance()->exec();
#endif
}
void Texmaker::QuickTabbing() {
if (!currentEditorView()) return;
TabbingDialog *tabDlg = new TabbingDialog(this,"Tabbing");
if (tabDlg->exec()) {
int x = tabDlg->ui.spinBoxColumns->value();
int y = tabDlg->ui.spinBoxRows->value();
QString s=tabDlg->ui.lineEdit->text();
QString tag = QString("\\begin{tabbing}\n");
for (int j=1; j<x; j++) {
tag +="\\hspace{"+s+"}\\=";
}
tag+="\\kill\n";
for (int i=0; i<y-1; i++) {
for (int j=1; j<x; j++) {
tag +=" \\> ";
}
tag+="\\\\ \n";
}
for (int j=1; j<x; j++) {
tag +=" \\> ";
}
tag += QString("\n\\end{tabbing} ");
InsertTag(tag,0,2);
}
}
void Texmaker::QuickLetter() {
QString tag=QString("\\documentclass[");
LetterDialog *ltDlg = new LetterDialog(this,"Letter");
if (ltDlg->exec()) {
if (!currentEditorView() ||
currentEditorView()->getDocument()->lineCount() > 1 || // first faster than text().isEmpty on large documents
!currentEditorView()->getDocument()->text().isEmpty())
{
fileNew();
Q_ASSERT(currentEditorView());
}
tag+=ltDlg->ui.comboBoxPt->currentText()+QString(",");
tag+=ltDlg->ui.comboBoxPaper->currentText()+QString("]{letter}");
tag+=QString("\n");
if (ltDlg->ui.comboBoxEncoding->currentText()!="NONE") tag+=QString("\\usepackage[")+ltDlg->ui.comboBoxEncoding->currentText()+QString("]{inputenc}");
if (ltDlg->ui.comboBoxEncoding->currentText().startsWith("utf8x")) tag+=QString(" \\usepackage{ucs}");
tag+=QString("\n");
if (ltDlg->ui.checkBox->isChecked()) tag+=QString("\\usepackage{amsmath}\n\\usepackage{amsfonts}\n\\usepackage{amssymb}\n");
tag+="\\address{your name and address} \n";
tag+="\\signature{your signature} \n";
tag+="\\begin{document} \n";
tag+="\\begin{letter}{name and address of the recipient} \n";
tag+="\\opening{saying hello} \n \n";
tag+="write your letter here \n \n";
tag+="\\closing{saying goodbye} \n";
tag+="%\\cc{Cclist} \n";
tag+="%\\ps{adding a postscript} \n";
tag+="%\\encl{list of enclosed material} \n";
tag+="\\end{letter} \n";
tag+="\\end{document}";
if (ltDlg->ui.checkBox->isChecked()) {
InsertTag(tag,9,5);
} else {
InsertTag(tag,9,2);
}
}
}
void Texmaker::QuickDocument() {
QuickDocumentDialog *startDlg = new QuickDocumentDialog(this,tr("Quick Start"));
startDlg->Init();
if (startDlg->exec()) {
if (!currentEditorView() ||
currentEditorView()->getDocument()->lineCount() > 1 || // first faster than text().isEmpty on large documents
!currentEditorView()->getDocument()->text().isEmpty())
{
fileNew();
Q_ASSERT(currentEditorView());
}
Q_ASSERT(currentEditor());
currentEditorView()->insertMacro(startDlg->getNewDocumentText());
QTextCodec* codec = LatexParser::QTextCodecForLatexName(startDlg->document_encoding);
if (codec && codec != currentEditor()->document()->codec()){
currentEditor()->document()->setCodec(codec);
UpdateCaption();
}
}
delete startDlg;
}
void Texmaker::QuickBeamer() {
QuickBeamerDialog *startDlg = new QuickBeamerDialog(this,tr("Quick Beamer Presentation"));
startDlg->Init();
if (startDlg->exec()) {
if (!currentEditorView() ||
currentEditorView()->getDocument()->lineCount() > 1 || // first faster than text().isEmpty on large documents
!currentEditorView()->getDocument()->text().isEmpty())
{
fileNew();
Q_ASSERT(currentEditorView());
}
Q_ASSERT(currentEditor());
currentEditorView()->insertMacro(startDlg->getNewDocumentText());
QTextCodec* codec = LatexParser::QTextCodecForLatexName(startDlg->document_encoding);
if (codec && codec != currentEditor()->document()->codec()){
currentEditor()->document()->setCodec(codec);
UpdateCaption();
}
}
delete startDlg;
}
void Texmaker::InsertBibEntryFromAction(){
if (!currentEditorView()) return;
QAction* action=qobject_cast<QAction*>(sender());
if (!action) return;
QString insertText=BibTeXDialog::textToInsert(action->data().toString());
if (!insertText.isEmpty())
CodeSnippet(insertText, false).insert(currentEditor());
}
void Texmaker::InsertBibEntry(const QString& id){
QStringList possibleBibFiles;
int usedFile=0;
if (currentEditor()){
if (currentEditor()->fileName().isEmpty())
possibleBibFiles.prepend(tr("<Current File>"));
else {
usedFile=documents.mentionedBibTeXFiles.indexOf(currentEditor()->fileName());
if (usedFile<0 && !documents.mentionedBibTeXFiles.empty()) usedFile=0;
}
}
foreach (const QString &s, documents.mentionedBibTeXFiles)
possibleBibFiles << QFileInfo(s).fileName();
BibTeXDialog* bd=new BibTeXDialog(0,possibleBibFiles,usedFile,id);
if (bd->exec()){
usedFile=bd->resultFileId;
if (usedFile<0 || usedFile>=possibleBibFiles.count()) fileNew();
else if (currentEditor()->fileName().isEmpty() && usedFile==0); //stay in current editor
else if (QFileInfo(currentEditor()->fileName())==QFileInfo(possibleBibFiles[usedFile])); //stay in current editor
else {
if (currentEditor()->fileName().isEmpty()) usedFile--;
load(documents.mentionedBibTeXFiles[usedFile]);
currentEditor()->setCursorPosition(currentEditor()->document()->lines()-1,0);
bd->resultString="\n"+bd->resultString;
}
CodeSnippet(bd->resultString, false).insert(currentEditor());
}
delete bd;
}
void Texmaker::SetBibTypeFromAction() {
QMenu *menu = getManagedMenu("main/bibliography/type");
QAction *act = qobject_cast<QAction *>(sender());
if (!act) return;
if (menu) {
menu->setTitle(QString(tr("Type: %1")).arg(act->text()));
}
bool isBibtex = (act->data().toString() == "bibtex");
bibtexEntryActions->setVisible(isBibtex);
biblatexEntryActions->setVisible(!isBibtex);
BibTeXDialog::setBibType(isBibtex ? BibTeXDialog::BIBTEX : BibTeXDialog::BIBLATEX);
}
void Texmaker::insertUserTag() {
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
int id = action->data().toInt();
const QString& userTag=configManager.completerConfig->userMacros.value(id,Macro()).tag;
insertUserTag(userTag);
}
void Texmaker::insertUserTag(const QString& macro, int triggerId){
//dont'check that, if (!currentEditorView()) return; insertMacro is 0 save
currentEditorView()->insertMacro(macro, QRegExp(), triggerId);
}
void Texmaker::editMacros() {
if (!userMacroDialog) {
userMacroDialog = new UserMenuDialog(0,tr("Edit User &Tags"),m_languages);
foreach (const Macro& m, configManager.completerConfig->userMacros) {
if(m.name=="TMX:Replace Quote Open" || m.name=="TMX:Replace Quote Close" || m.document)
continue;
userMacroDialog->addMacro(m);
}
userMacroDialog->init();
connect(userMacroDialog, SIGNAL(accepted()), SLOT(macroDialogAccepted()));
connect(userMacroDialog, SIGNAL(runScript(QString)), SLOT(insertUserTag(QString)));
}
userMacroDialog->show();
userMacroDialog->setFocus();
}
void Texmaker::macroDialogAccepted(){
configManager.completerConfig->userMacros.clear();
for (int i=0; i<userMacroDialog->macroCount(); i++) {
configManager.completerConfig->userMacros << userMacroDialog->getMacro(i);
}
for (int i=0;i<documents.documents.size();i++)
configManager.completerConfig->userMacros << documents.documents[i]->localMacros;
updateUserMacros();
completer->updateAbbreviations();
userMacroDialog->deleteLater();
userMacroDialog = 0;
}
void Texmaker::InsertRef(const QString &refCmd) {
//updateStructure();
LatexEditorView* edView=currentEditorView();
QStringList labels;
if(edView && edView->document){
QList<LatexDocument*> docs;
docs << edView->document->getListOfDocs();
foreach(const LatexDocument* doc,docs)
labels << doc->labelItems();
} else return;
labels.sort();
UniversalInputDialog dialog;
dialog.addVariable(&labels, tr("Labels:"));
if (dialog.exec() && !labels.isEmpty()) {
QString tag=refCmd+"{"+labels.first()+"}";
InsertTag(tag,tag.length(),0);
} else
InsertTag(refCmd+"{}",refCmd.length()+1,0);
}
void Texmaker::InsertRef() {
InsertRef("\\ref");
}
void Texmaker::InsertEqRef() {
InsertRef("\\eqref");
}
void Texmaker::InsertPageRef() {
InsertRef("\\pageref");
}
void Texmaker::createLabelFromAction()
{
QAction *act = qobject_cast<QAction *>(sender());
if (!act) return;
StructureEntry *entry = qvariant_cast<StructureEntry *>(act->data());
if (!entry || !entry->document) return;
// find editor and line nr
int lineNr=entry->getRealLineNumber();
int level = entry->level;
mDontScrollToItem = entry->type!=StructureEntry::SE_SECTION;
LatexEditorView* edView=entry->document->getEditorView();
QEditor::MoveFlags mflags = QEditor::NavigationToHeader;
if (!edView){
edView=load(entry->document->getFileName());
if (!edView) return;
mflags &= ~QEditor::Animated;
//entry is now invalid
}
REQUIRE(edView->getDocument());
if (lineNr < 0) return; //not found. (document was closed)
// find column position after structure command
QString lineText = edView->getDocument()->line(lineNr).text();
int pos = -1;
Q_ASSERT(level < latexParser.structureCommandLists.length());
foreach (const QString &cmd, latexParser.structureCommandLists[level]) {
pos = lineText.indexOf(cmd);
if (pos >= 0) {
pos += cmd.length();
// workaround for starred commands: \section*{Cap}
if ((lineText.length() > pos+1) && lineText.at(pos) == '*') pos++;
break;
}
}
if (pos < 0) return; // could not find associated command
// advance pos behind options, and use title to guess a label
QList<CommandArgument> args = getCommandOptions(lineText, pos, &pos);
QString label = "sec:";
if (args.length()>0) {
label+=args.at(0).value.toLower();
label.replace(' ','-');
}
if (label.contains('\\') || label.contains('$')) { // title too complicated to extract label: fall back
label = "sec:";
}
gotoLine(lineNr,pos,edView,mflags);
InsertTag(QString("\\label{%1}").arg(label),7);
QDocumentCursor cur(edView->editor->cursor());
cur.movePosition(label.length(),QDocumentCursor::NextCharacter,QDocumentCursor::KeepAnchor);
edView->editor->setCursor(cur);
}
void Texmaker::changeTextCodec() {
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
bool ok;
int mib = action->data().toInt(&ok);
if (!ok) return;
if (!currentEditorView()) return;
currentEditorView()->editor->setFileCodec(QTextCodec::codecForMib(mib));
UpdateCaption();
}
void Texmaker::EditorSpellerChanged(const QString &name) {
foreach (QAction *act, statusTbLanguage->actions()) {
if (act->data().toString() == name) {
act->setChecked(true);
break;
}
}
if (name == "<default>") {
statusTbLanguage->setText(spellerManager.defaultSpellerName());
} else {
statusTbLanguage->setText(name);
}
}
void Texmaker::ChangeEditorSpeller() {
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
if (!currentEditorView()) return;
if (!currentEditorView()->setSpeller(action->data().toString())) {
// restore activity of previous action
foreach (QAction *act, statusTbLanguage->actions()) {
if (act->data().toString() == currentEditorView()->getSpeller()) {
act->setChecked(true);
break;
}
}
}
}
void Texmaker::InsertSpellcheckMagicComment() {
if (currentEditorView()) {
QString name = currentEditorView()->getSpeller();
if (name=="<default>") {
name = spellerManager.defaultSpellerName();
}
currentEditorView()->document->updateMagicComment("spellcheck", name, true);
}
}
void Texmaker::addMagicRoot() {
if (currentEditorView()) {
LatexDocument *doc=currentEditorView()->getDocument();
if(!doc) return;
QString name=doc->getTopMasterDocument()->getFileName();
name=getRelativeFileName(name,doc->getFileName(),true);
currentEditorView()->document->updateMagicComment("root", name, true);
}
}
void Texmaker::addMagicCoding() {
if (currentEditorView()) {
QString name=currentEditor()->getFileCodec()->name();
currentEditorView()->document->updateMagicComment("encoding", name, true);
}
}
///////////////TOOLS////////////////////
bool Texmaker::runCommand(const QString& commandline, QString* buffer, QTextCodec* codecForBuffer) {
fileSaveAll(buildManager.saveFilesBeforeCompiling==BuildManager::SFBC_ALWAYS, buildManager.saveFilesBeforeCompiling==BuildManager::SFBC_ONLY_CURRENT_OR_NAMED);
if (documents.getTemporaryCompileFileName()=="") {
if (buildManager.saveFilesBeforeCompiling==BuildManager::SFBC_ONLY_NAMED && currentEditorView()){
QString tmpName = buildManager.createTemporaryFileName();
currentEditor()->saveCopy(tmpName);
currentEditorView()->document->setTemporaryFileName(tmpName);
} else {
QMessageBox::warning(this,tr("Error"),tr("Can't detect the file name.\nYou have to save a document before you can compile it."));
return false;
}
}
QString finame=documents.getTemporaryCompileFileName();
if (finame == "") {
txsWarning(tr("Can't detect the file name"));
return false;
}
int ln = currentEditorView() ? currentEditorView()->editor->cursor().lineNumber() + 1 : 0;
return buildManager.runCommand(commandline, finame, getCurrentFileName(), ln, buffer, codecForBuffer);
}
void Texmaker::runInternalPdfViewer(const QFileInfo& master, const QString& options){
#ifndef NO_POPPLER_PREVIEW
QStringList ol = options.split(" ");
for (int i=ol.size()-1;i>=0;i--)
if (!ol[i].startsWith("-")) ol.removeAt(i);
else if (ol[i].startsWith("--")) ol[i] = ol[i].mid(2);
else ol[i] = ol[i].mid(1);
bool preserveExisting = ol.contains("preserve-existing"); //completely ignore all existing internal viewers
bool preserveExistingEmbedded = ol.contains("preserve-existing-embedded"); //completely ignore all existing embedded internal viewers
bool preserveExistingWindowed = ol.contains("preserve-existing-windowed"); //completely ignore all existing windowed internal viewers
bool preserveDuplicates = ol.contains("preserve-duplicates"); //open the document only in one pdf viewer
bool embedded = ol.contains("embedded"); //if a new pdf viewer is opened, use the embedded mode
bool windowed = ol.contains("windowed"); //if a new pdf viewer is opened, use the windowed mode (default)
bool closeAll = ol.contains("close-all"); //close all existing viewers
bool closeEmbedded = closeAll || ol.contains("close-embedded"); //close all embedded existing viewer
bool closeWindowed = closeAll || ol.contains("close-windowed"); //close all windowed existing viewer
bool autoClose;
if (embedded) autoClose = ! ol.contains("no-auto-close"); //Don't close the viewer, if the corresponding document is closed
else autoClose = ol.contains("auto-close"); //Close the viewer, if the corresponding document is closed
bool focus = 0; //1: always, 0: auto, -1: never
if (ol.contains("focus")) focus = 1;
else if (ol.contains("no-focus")) focus = -1;
if (!(embedded || windowed || closeEmbedded || closeWindowed)) windowed = true; //default
//embedded/windowed are mutual exclusive
//no viewer will be opened, if one already exist (unless it was closed by a explicitely given close command)
QList<PDFDocument*> oldPDFs = PDFDocument::documentList();
if (preserveExisting) oldPDFs.clear();
if (preserveExistingWindowed)
for (int i=oldPDFs.size() - 1; i >= 0; i--)
if (!oldPDFs[i]->embeddedMode)
oldPDFs.removeAt(i);
if (preserveExistingEmbedded)
for (int i=oldPDFs.size() - 1; i >= 0; i--)
if (oldPDFs[i]->embeddedMode)
oldPDFs.removeAt(i);
//if closing and opening is set, reuse the first document (reuse = optimization, so it does not close a viewer and creates an equal viewer afterwards)
PDFDocument* reuse = 0;
if ((embedded || windowed) && (closeEmbedded || closeWindowed) && !oldPDFs.isEmpty() ) {
for (int i=0;i<oldPDFs.size();i++)
if (oldPDFs[i]->embeddedMode == embedded){
reuse = oldPDFs.takeAt(i);
break;
}
}
//close old
for (int i=oldPDFs.size()-1;i>=0;i--)
if ( (oldPDFs[i]->embeddedMode && closeEmbedded) ||
(!oldPDFs[i]->embeddedMode && closeWindowed) )
oldPDFs[i]->close(), oldPDFs.removeAt(i);
//open new
if (!embedded && !windowed) return;
if (reuse) oldPDFs.insert(0, reuse);
if (oldPDFs.isEmpty()){
PDFDocument* doc = qobject_cast<PDFDocument*>(newPdfPreviewer(embedded));
REQUIRE(doc);
doc->autoClose = autoClose;
oldPDFs << doc;
}
QString pdfDefFile = BuildManager::parseExtendedCommandLine("?am.pdf", master).first();
QString pdfFile = buildManager.findFile(pdfDefFile, buildManager.additionalPdfPaths);
if (pdfFile == "") pdfFile = pdfDefFile; //use old file name, so pdf viewer shows reasonable error message
int ln = 0;
if (currentEditorView()) {
ln = currentEditorView()->editor->cursor().lineNumber();
int originalLineNumber = currentEditorView()->document->lineToLineSnapshotLineNumber(currentEditorView()->editor->cursor().line());
if (originalLineNumber >= 0) ln = originalLineNumber;
}
foreach (PDFDocument* viewer, oldPDFs) {
bool focusViewer = (focus == 1) || (focus == 0 && !viewer->embeddedMode);
viewer->loadFile(pdfFile, master, focusViewer);
int pg = viewer->syncFromSource(getCurrentFileName(), ln , focusViewer);
viewer->fillRenderCache(pg);
if (preserveDuplicates) break;
}
#if QT_VERSION>=0x050000 && defined Q_OS_MAC
if(embedded)
setMenuBar(configManager.menuParentsBar);
#endif
if(embedded){
if(configManager.viewerEnlarged)
enlargeEmbeddedPDFViewer();
}
#else
txsCritical(tr("You have called the command to open the internal pdf viewer.\nHowever, you are using a version of TeXstudio that was compiled without the internal pdf viewer."));
#endif
}
bool Texmaker::checkProgramPermission(const QString& program, const QString& cmdId, LatexDocument* master){
static const QRegExp txsCmd(QRegExp::escape(BuildManager::TXS_CMD_PREFIX) + "([^/ [{]+))");
if (txsCmd.exactMatch(program)) return true;
static QStringList programWhiteList; configManager.registerOption("Tools/Program Whitelist", &programWhiteList, QStringList() << "latex" << "pdflatex");
if (programWhiteList.contains(program)) return true;
if (buildManager.hasCommandLine(program)) return true;
if (!master) return false;
QString id = master->getMagicComment("document-id");
if (id.contains("=")) return false;
static QStringList individualProgramWhiteList; configManager.registerOption("Tools/Individual Program Whitelist", &individualProgramWhiteList, QStringList());
if (!id.isEmpty() && individualProgramWhiteList.contains(id+"="+program)) return true;
int t = QMessageBox::warning(0, TEXSTUDIO,
tr("The document \"%1\" wants to override the command \"%2\" with \"%3\".\n\n"
"Do you want to allow and run the new, overriding command?\n\n"
"(a) Yes, allow the new command for this document (only if you trust this document)\n"
"(b) Yes, allow the new command to be used for all documents (only if you trust the new command to handle arbitrary documents)\n"
"(c) No, do not use the command \"%3\" and run the default \"%2\" command"
).arg(master?master->getFileName():"").arg(cmdId).arg(program),
tr("(a) allow for this document"),
tr("(b) allow for all documents"),
tr("(c) use the default command"), 0, 2);
if (t == 2) return false;
if (t == 1) {
programWhiteList.append(program);
return true;
}
if (id.isEmpty()) {
id = QUuid::createUuid().toString();
master->updateMagicComment("document-id", id, true);
if (master->getMagicComment("document-id") != id) return false;
}
individualProgramWhiteList.append(id+"="+program);
return true;
}
void Texmaker::runBibliographyIfNecessary(const QFileInfo& mainFile){
if (!configManager.runLaTeXBibTeXLaTeX) return;
if (runBibliographyIfNecessaryEntered) return;
//LatexDocument* master = currentEditorView()->document->getTopMasterDocument(); //crashes if masterdoc is defined but closed
LatexDocument* master = documents.getMasterDocumentForDoc(); //TODO: use mainFile master
REQUIRE(master);
QList<LatexDocument*> docs = master->getListOfDocs();
QSet<QString> bibFiles;
foreach (const LatexDocument* doc, docs)
foreach (const FileNamePair& bf, doc->mentionedBibTeXFiles())
bibFiles.insert(bf.absolute);
if (bibFiles == master->lastCompiledBibTeXFiles) {
QFileInfo bbl(BuildManager::parseExtendedCommandLine("?am.bbl", documents.getTemporaryCompileFileName()).first());
if (bbl.exists()) {
bool bibFilesChanged = false;
QDateTime bblChanged = bbl.lastModified();
foreach (const QString& bf, bibFiles){
//qDebug() << bf << ": "<<QFileInfo(bf).lastModified()<<" "<<bblChanged;
if (QFileInfo(bf).exists() && QFileInfo(bf).lastModified() > bblChanged) {
bibFilesChanged = true;
break;
}
}
if (!bibFilesChanged) return;
} else return;
} else master->lastCompiledBibTeXFiles = bibFiles;
runBibliographyIfNecessaryEntered = true;
buildManager.runCommand(BuildManager::CMD_RECOMPILE_BIBLIOGRAPHY, mainFile);
runBibliographyIfNecessaryEntered = false;
}
void Texmaker::runInternalCommand(const QString& cmd, const QFileInfo& mainfile, const QString& options){
if (cmd == BuildManager::CMD_VIEW_PDF_INTERNAL || (cmd.startsWith(BuildManager::CMD_VIEW_PDF_INTERNAL) && cmd[BuildManager::CMD_VIEW_PDF_INTERNAL.length()] == ' '))
runInternalPdfViewer(mainfile, options);
else if (cmd == BuildManager::CMD_CONDITIONALLY_RECOMPILE_BIBLIOGRAPHY)
runBibliographyIfNecessary(mainfile);
else if (cmd == BuildManager::CMD_VIEW_LOG) {
loadLog();
ViewLog();
}
else txsWarning(tr("Unknown internal command: %1").arg(cmd));
}
void Texmaker::commandLineRequested(const QString& cmdId, QString* result, bool *){
LatexDocument* master = documents.getMasterDocumentForDoc();
if (!master) return;
QString magic = master->getMagicComment("TXS-program:"+cmdId);
if (!magic.isEmpty()) {
if (!checkProgramPermission(magic, cmdId, master)) return;
*result = magic;
return;
}
if (cmdId != "quick" && cmdId != "compile" && cmdId != "view") return;
QString program = master->getMagicComment("program");
if (program.isEmpty()) program = master->getMagicComment("TS-program");
if (program.isEmpty()) return;
if (program == "pdflatex" || program == "latex" || program == "xelatex" || program == "luatex" || program == "lualatex") {
//TODO: don't replicate build logic here
QString viewer = BuildManager::CMD_VIEW_PDF;
QString compiler = BuildManager::CMD_PDFLATEX;
if (program == "latex") viewer = BuildManager::CMD_VIEW_DVI, compiler = BuildManager::CMD_LATEX;
else if (program == "xelatex") compiler = BuildManager::CMD_XELATEX;
else if (program == "luatex" || program == "lualatex") compiler = BuildManager::CMD_LUALATEX;
//else {} // pdflatex (default)
if (cmdId == "quick") *result = BuildManager::chainCommands(compiler, viewer);
else if (cmdId == "compile") *result = compiler;
else if (cmdId == "view") *result = viewer;
} else if (cmdId == "quick" && checkProgramPermission(program, cmdId, master)) *result = program;
}
void Texmaker::beginRunningCommand(const QString& commandMain, bool latex, bool pdf, bool async){
if (pdf) {
runningPDFCommands++;
if (async && pdf) runningPDFAsyncCommands++;
#ifndef NO_POPPLER_PREVIEW
PDFDocument::isCompiling = true;
PDFDocument::isMaybeCompiling |= runningPDFAsyncCommands > 0;
#endif
if (configManager.autoCheckinAfterSave) {
QFileInfo fi(documents.getTemporaryCompileFileName());
fi.setFile(fi.path()+"/"+fi.baseName()+".pdf");
if(fi.exists() && !fi.isWritable()){
//pdf not writeable, needs locking ?
svnLock(fi.filePath());
}
}
}
if (latex) {
outputView->resetMessagesAndLog(!configManager.showMessagesWhenCompiling);//log to old (whenever latex is called)
foreach (LatexEditorView *edView, EditorTabs->editors()) {
edView->document->saveLineSnapshot();
}
}
else outputView->resetMessages(!configManager.showMessagesWhenCompiling);
statusLabelProcess->setText(QString(" %1 ").arg(buildManager.getCommandInfo(commandMain).displayName));
}
void Texmaker::connectSubCommand(ProcessX* p, bool showStdoutLocally){
connect(p, SIGNAL(standardErrorRead(QString)), outputView, SLOT(insertMessageLine(QString)));
if (p->showStdout()) {
p->setShowStdout((configManager.showStdoutOption == 2) || (showStdoutLocally && configManager.showStdoutOption == 1));
connect(p, SIGNAL(standardOutputRead(QString)), outputView, SLOT(insertMessageLine(QString)));
}
}
void Texmaker::beginRunningSubCommand(ProcessX* p, const QString& commandMain, const QString& subCommand, const RunCommandFlags& flags){
if (commandMain != subCommand)
statusLabelProcess->setText(QString(" %1: %2 ").arg(buildManager.getCommandInfo(commandMain).displayName).arg(buildManager.getCommandInfo(subCommand).displayName));
if (flags & RCF_COMPILES_TEX)
clearLogEntriesInEditors();
//outputView->resetMessages();
connectSubCommand(p, (RCF_SHOW_STDOUT & flags));
}
void Texmaker::endRunningSubCommand(ProcessX* p, const QString& commandMain, const QString& subCommand, const RunCommandFlags& flags){
if (p->exitCode() && (flags & RCF_COMPILES_TEX) && !LogExists()) {
if (!QFileInfo(QFileInfo(documents.getTemporaryCompileFileName()).absolutePath()).isWritable())
txsWarning(tr("You cannot compile the document in a non writable directory."));
else
txsWarning(tr("Could not start %1.").arg( buildManager.getCommandInfo(commandMain).displayName + ":" + buildManager.getCommandInfo(subCommand).displayName + ":\n" + p->getCommandLine()));
}
if ((flags & RCF_CHANGE_PDF) && !(flags & RCF_WAITFORFINISHED) && (runningPDFAsyncCommands > 0)) {
runningPDFAsyncCommands--;
#ifndef NO_POPPLER_PREVIEW
if (runningPDFAsyncCommands <= 0) PDFDocument::isMaybeCompiling = false;
#endif
}
}
void Texmaker::endRunningCommand(const QString& commandMain, bool latex, bool pdf, bool async){
Q_UNUSED(commandMain)
Q_UNUSED(async);
if (pdf) {
runningPDFCommands--;
#ifndef NO_POPPLER_PREVIEW
if (runningPDFCommands <= 0)
PDFDocument::isCompiling = false;
#endif
}
statusLabelProcess->setText(QString(" %1 ").arg(tr("Ready")));
if (latex) emit infoAfterTypeset();
}
void Texmaker::processNotification(const QString& message){
outputView->insertMessageLine(message+"\n");
}
void Texmaker::commandFromAction(){
QAction* act = qobject_cast<QAction*>(sender());
if (!act) return;
runCommand(act->data().toString());
}
void Texmaker::CleanAll() {
CleanDialog cleanDlg(this);
if (cleanDlg.checkClean(documents)) {
cleanDlg.exec();
} else {
txsInformation(tr("No open project or tex file to clean."));
}
}
void Texmaker::WebPublish() {
if (!currentEditorView()) {
txsWarning(tr("No document open"));
return;
}
if (!currentEditorView()->editor->getFileCodec()) return;
fileSave();
QString finame=documents.getCompileFileName();
WebPublishDialog *ttwpDlg = new WebPublishDialog(this,configManager.webPublishDialogConfig, &buildManager,
currentEditorView()->editor->getFileCodec());
ttwpDlg->ui.inputfileEdit->setText(finame);
ttwpDlg->exec();
delete ttwpDlg;
}
void Texmaker::WebPublishSource(){
if (!currentEditor()) return;
QDocumentCursor cur = currentEditor()->cursor();
QString html = currentEditor()->document()->exportAsHtml(cur.hasSelection()?cur:QDocumentCursor(), true);
fileNew(getCurrentFileName()+".html");
currentEditor()->insertText(html);
/*QLabel* htmll = new QLabel(html, this);
htmll->show();
htmll->resize(300,300);*/
}
void Texmaker::AnalyseText() {
if (!currentEditorView()) {
txsWarning(tr("No document open"));
return;
}
if (!textAnalysisDlg) {
textAnalysisDlg = new TextAnalysisDialog(this,tr("Text Analysis"));
connect(textAnalysisDlg,SIGNAL(destroyed()),this,SLOT(AnalyseTextFormDestroyed()));
}
if (!textAnalysisDlg) return;
textAnalysisDlg->setEditor(currentEditorView()->editor);//->document(), currentEditorView()->editor->cursor());
textAnalysisDlg->init();
textAnalysisDlg->interpretStructureTree(currentEditorView()->document->baseStructure);
textAnalysisDlg->show();
textAnalysisDlg->raise(); //not really necessary, since the dlg is always on top
textAnalysisDlg->activateWindow();
}
void Texmaker::AnalyseTextFormDestroyed() {
textAnalysisDlg=0;
}
void Texmaker::GenerateRandomText(){
if (!currentEditorView()){
txsWarning(tr("The random text generator constructs new texts from existing words, so you have to open some text files"));
return;
}
QStringList allLines;
foreach (LatexEditorView *edView, EditorTabs->editors())
allLines << edView->editor->document()->textLines();
RandomTextGenerator generator(this, allLines);
generator.exec();
}
//////////////// MESSAGES - LOG FILE///////////////////////
bool Texmaker::LogExists() {
QString finame=documents.getTemporaryCompileFileName();
if (finame=="")
return false;
QString logname=getAbsoluteFilePath(QFileInfo(finame).completeBaseName(),".log");
QFileInfo fic(logname);
if (fic.exists() && fic.isReadable()) return true;
else return false;
}
bool Texmaker::loadLog() {
outputView->getLogWidget()->resetLog();
if (!documents.getCurrentDocument()) return false;
QString finame=documents.getTemporaryCompileFileName();
if (finame=="") {
QMessageBox::warning(this,tr("Error"),tr("File must be saved and compiling before you can view the log"));
return false;
}
QString logname=buildManager.findFile(getAbsoluteFilePath(QFileInfo(finame).completeBaseName(),".log"), buildManager.additionalLogPaths);
QFileInfo fic(logname);
return outputView->getLogWidget()->loadLogFile(logname,documents.getTemporaryCompileFileName());
}
void Texmaker::showLog() {
outputView->showPage(outputView->LOG_PAGE);
}
//shows the log (even if it is empty)
void Texmaker::ViewLog() {
showLog();
setLogMarksVisible(true);
if (configManager.goToErrorWhenDisplayingLog && HasLatexErrors()) {
int errorMarkID = outputView->getLogWidget()->getLogModel()->markID(LT_ERROR);
if (!gotoMark(false, errorMarkID)) {
gotoMark(true, errorMarkID);
}
}
}
void Texmaker::ViewLogOrReRun(LatexCompileResult* result){
loadLog();
REQUIRE(result);
if (HasLatexErrors()) {
ViewLog();
*result = LCR_ERROR;
} else {
*result = LCR_NORMAL;
if (outputView->getLogWidget()->getLogModel()->existsReRunWarning())
*result = LCR_RERUN;
else if (configManager.runLaTeXBibTeXLaTeX) {
//run bibtex if citation is unknown to bibtex but contained in an included bib file
QStringList missingCitations = outputView->getLogWidget()->getLogModel()->getMissingCitations();
bool runBibTeX = false;
foreach (const QString & s,missingCitations) {
for (int i=0; i<documents.mentionedBibTeXFiles.count();i++){
if (!documents.bibTeXFiles.contains(documents.mentionedBibTeXFiles[i])) continue;
BibTeXFileInfo& bibTex=documents.bibTeXFiles[documents.mentionedBibTeXFiles[i]];
for (int i=0; i<bibTex.ids.count();i++)
if (bibTex.ids[i] == s) {
runBibTeX = true;
break;
}
if (runBibTeX) break;
}
}
if (runBibTeX)
*result = LCR_RERUN_WITH_BIBLIOGRAPHY;
}
}
}
////////////////////////// ERRORS /////////////////////////////
// changes visibilita of log markers in all editors
void Texmaker::setLogMarksVisible(bool visible) {
foreach (LatexEditorView *edView, EditorTabs->editors()) {
edView->setLogMarksVisible(visible);
}
QAction *act = getManagedAction("main/tools/logmarkers");
if (act) act->setChecked(visible);
}
// removes the log entries from all editors
void Texmaker::clearLogEntriesInEditors() {
foreach (LatexEditorView *edView, EditorTabs->editors()) {
edView->clearLogMarks();
}
}
// adds the current log entries to all editors
void Texmaker::updateLogEntriesInEditors() {
clearLogEntriesInEditors();
LatexLogModel* logModel = outputView->getLogWidget()->getLogModel();
QHash<QString, LatexEditorView*> tempFilenames; //temporary maps the filenames (as they appear in this log!) to the editor
int errorMarkID = QLineMarksInfoCenter::instance()->markTypeId("error");
int warningMarkID = QLineMarksInfoCenter::instance()->markTypeId("warning");
int badboxMarkID = QLineMarksInfoCenter::instance()->markTypeId("badbox");
for (int i = logModel->count()-1; i >= 0; i--) {
if (logModel->at(i).oldline!=-1){
LatexEditorView* edView;
if (tempFilenames.contains(logModel->at(i).file)) edView=tempFilenames.value(logModel->at(i).file);
else{
edView=getEditorViewFromFileName(logModel->at(i).file, true);
tempFilenames[logModel->at(i).file]=edView;
}
if (edView) {
int markID;
switch (logModel->at(i).type) {
case LT_ERROR: markID = errorMarkID; break;
case LT_WARNING: markID = warningMarkID; break;
case LT_BADBOX: markID = badboxMarkID; break;
default: markID = -1;
}
edView->addLogEntry(i, logModel->at(i).oldline-1, markID);
}
}
}
}
bool Texmaker::HasLatexErrors() {
return outputView->getLogWidget()->getLogModel()->found(LT_ERROR);
}
bool Texmaker::gotoNearLogEntry(int lt, bool backward, QString notFoundMessage) {
if (!outputView->getLogWidget()->logPresent()) {
loadLog();
}
if (outputView->getLogWidget()->logPresent()) {
if (outputView->getLogWidget()->getLogModel()->found((LogType) lt)){
showLog();
setLogMarksVisible(true);
return gotoMark(backward, outputView->getLogWidget()->getLogModel()->markID((LogType) lt));
} else {
txsInformation(notFoundMessage);
}
}
return false;
}
void Texmaker::ClearMarkers() {
setLogMarksVisible(false);
}
//////////////// HELP /////////////////
void Texmaker::LatexHelp() {
QString latexHelp=findResourceFile("latex2e.html");
if (latexHelp=="")
QMessageBox::warning(this,tr("Error"),tr("File not found"));
else if (!QDesktopServices::openUrl("file:///"+latexHelp))
QMessageBox::warning(this,tr("Error"),tr("Could not open browser"));
}
void Texmaker::UserManualHelp() {
QString locale = QString(QLocale::system().name()).left(2);
if (locale.length() < 2 || locale!="fr") locale = "en";
QString latexHelp=findResourceFile("usermanual_"+locale+".html");
if (latexHelp=="")
QMessageBox::warning(this,tr("Error"),tr("File not found"));
else if (!QDesktopServices::openUrl("file:///"+latexHelp))
QMessageBox::warning(this,tr("Error"),tr("Could not open browser"));
}
void Texmaker::TexdocHelp() {
QString selection;
QStringList packages;
if (currentEditorView()) {
selection = currentEditorView()->editor->cursor().selectedText();
foreach (const QString &key, currentEditorView()->document->parent->cachedPackages.keys()) {
if (currentEditorView()->document->parent->cachedPackages[key].completionWords.isEmpty())
// remove empty packages which probably do not exist
continue;
packages << LatexPackage::keyToPackageName(key);
}
packages.removeDuplicates();
packages.removeAll("latex-209");
packages.removeAll("latex-dev");
packages.removeAll("latex-l2tabu");
packages.removeAll("latex-document");
packages.removeAll("latex-mathsymbols");
packages.removeAll("tex");
}
Help::instance()->execTexdocDialog(packages, selection);
}
void Texmaker::HelpAbout() {
AboutDialog *abDlg = new AboutDialog(0); //if parent!=0 the focus is wrong after pdf viewer about call
abDlg->exec();
delete abDlg;
}
////////////// OPTIONS //////////////////////////////////////
void Texmaker::GeneralOptions() {
QMap<QString,QVariant> oldCustomEnvironments = configManager.customEnvironments;
bool oldModernStyle = modernStyle;
bool oldSystemTheme = useSystemTheme;
int oldReplaceQuotes = configManager.replaceQuotes;
autosaveTimer.stop();
m_formats->modified = false;
bool realtimeChecking=configManager.editorConfig->realtimeChecking;
bool inlineSpellChecking=configManager.editorConfig->inlineSpellChecking;
bool inlineCitationChecking=configManager.editorConfig->inlineCitationChecking;
bool inlineReferenceChecking=configManager.editorConfig->inlineReferenceChecking;
bool inlineSyntaxChecking=configManager.editorConfig->inlineSyntaxChecking;
QString additionalBibPaths=configManager.additionalBibPaths;
QStringList loadFiles=configManager.completerConfig->getLoadedFiles();
#if QT_VERSION<0x050000
if (configManager.possibleMenuSlots.isEmpty()) {
for (int i=0;i<staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append(staticMetaObject.method(i).signature());
for (int i=0;i<QEditor::staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append("editor:"+QString(QEditor::staticMetaObject.method(i).signature()));
for (int i=0;i<LatexEditorView::staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append("editorView:"+QString(LatexEditorView::staticMetaObject.method(i).signature()));
configManager.possibleMenuSlots = configManager.possibleMenuSlots.filter(QRegExp("^[^*]+$"));
}
#else
if (configManager.possibleMenuSlots.isEmpty()) {
for (int i=0;i<staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append(staticMetaObject.method(i).methodSignature());
for (int i=0;i<QEditor::staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append("editor:"+QString(QEditor::staticMetaObject.method(i).methodSignature()));
for (int i=0;i<LatexEditorView::staticMetaObject.methodCount();i++) configManager.possibleMenuSlots.append("editorView:"+QString(LatexEditorView::staticMetaObject.method(i).methodSignature()));
configManager.possibleMenuSlots = configManager.possibleMenuSlots.filter(QRegExp("^[^*]+$"));
}
#endif
if (configManager.execConfigDialog()) {
QApplication::setOverrideCursor(Qt::WaitCursor);
configManager.editorConfig->settingsChanged();
spellerManager.setDictPaths(configManager.parseDirList(configManager.spellDictDir));
spellerManager.setDefaultSpeller(configManager.spellLanguage);
GrammarCheck::staticMetaObject.invokeMethod(grammarCheck, "init", Qt::QueuedConnection, Q_ARG(LatexParser, latexParser), Q_ARG(GrammarCheckerConfig, *configManager.grammarCheckerConfig));
if (configManager.autoDetectEncodingFromLatex || configManager.autoDetectEncodingFromChars) QDocument::setDefaultCodec(0);
else QDocument::setDefaultCodec(configManager.newFileEncoding);
QDocument::removeGuessEncodingCallback(&ConfigManager::getDefaultEncoding);
QDocument::removeGuessEncodingCallback(&LatexParser::guessEncoding);
if (configManager.autoDetectEncodingFromLatex)
QDocument::addGuessEncodingCallback(&LatexParser::guessEncoding);
if (configManager.autoDetectEncodingFromChars)
QDocument::addGuessEncodingCallback(&ConfigManager::getDefaultEncoding);
ThesaurusDialog::prepareDatabase(configManager.thesaurus_database);
if (additionalBibPaths != configManager.additionalBibPaths) documents.updateBibFiles(true);
//update highlighting ???
bool updateHighlighting=(inlineSpellChecking!=configManager.editorConfig->inlineSpellChecking);
updateHighlighting|=(inlineCitationChecking!=configManager.editorConfig->inlineCitationChecking);
updateHighlighting|=(inlineReferenceChecking!=configManager.editorConfig->inlineReferenceChecking);
updateHighlighting|=(inlineSyntaxChecking!=configManager.editorConfig->inlineSyntaxChecking);
updateHighlighting|=(realtimeChecking!=configManager.editorConfig->realtimeChecking);
updateHighlighting|=(additionalBibPaths!=configManager.additionalBibPaths);
// check for change in load completion files
QStringList newLoadedFiles=configManager.completerConfig->getLoadedFiles();
foreach(const QString& elem,newLoadedFiles){
if(loadFiles.removeAll(elem)==0)
updateHighlighting=true;
if(updateHighlighting)
break;
}
if(!loadFiles.isEmpty())
updateHighlighting=true;
buildManager.clearPreviewPreambleCache();//possible changed latex command / preview behaviour
if (currentEditorView()) {
foreach (LatexEditorView *edView, EditorTabs->editors()) {
edView->updateSettings();
if(updateHighlighting){
if(configManager.editorConfig->realtimeChecking){
edView->updateLtxCommands();
edView->documentContentChanged(0,edView->document->lines());
edView->document->updateCompletionFiles(false,true);
}else{
edView->clearOverlays();
}
}
}
if (m_formats->modified)
QDocument::setFont(QDocument::font(), true);
UpdateCaption();
if (documents.indentIncludesInStructure!=configManager.indentIncludesInStructure) {
documents.indentIncludesInStructure = configManager.indentIncludesInStructure;
foreach (LatexDocument* doc, documents.documents)
updateStructure(false, doc);
}
}
if (oldReplaceQuotes != configManager.replaceQuotes)
updateUserMacros();
//custom toolbar
setupToolBars();
// custom evironments
bool customEnvironmentChanged = configManager.customEnvironments != oldCustomEnvironments;
if (customEnvironmentChanged){
updateTexQNFA();
}
//completion
completionBaseCommandsUpdated=true;
completerNeedsUpdate();
completer->setConfig(configManager.completerConfig);
//update changed line mark colors
QList<QLineMarkType> &marks = QLineMarksInfoCenter::instance()->markTypes();
for (int i=0;i<marks.size();i++)
if (m_formats->format("line:"+marks[i].id).background.isValid())
marks[i].color = m_formats->format("line:"+marks[i].id).background;
else
marks[i].color = Qt::transparent;
// update all docuemnts views as spellcheck may be different
QEditor::setEditOperations(configManager.editorKeys,true);
foreach (LatexEditorView *edView, EditorTabs->editors()) {
QEditor* ed = edView->editor;
ed->document()->markFormatCacheDirty();
ed->update();
}
if (oldModernStyle != modernStyle || oldSystemTheme != useSystemTheme) {
setupMenus();
setupDockWidgets();
}
updateUserToolMenu();
QApplication::restoreOverrideCursor();
}
if(configManager.autosaveEveryMinutes>0){
autosaveTimer.start(configManager.autosaveEveryMinutes*1000*60);
}
#ifndef NO_POPPLER_PREVIEW
foreach (PDFDocument *viewer, PDFDocument::documentList()) {
viewer->reloadSettings();
}
#endif
}
void Texmaker::executeCommandLine(const QStringList& args, bool realCmdLine) {
// parse command line
QStringList filesToLoad;
bool activateMasterMode = false;
int line=-1;
int col=0;
QString cite;
#ifndef NO_POPPLER_PREVIEW
int page=-1;
bool pdfViewerOnly = false;
#endif
for (int i = 0; i < args.size(); ++i) {
if (args[i]=="") continue;
if (args[i][0] != '-') filesToLoad << args[i];
//-form is for backward compatibility
if (args[i] == "--master") activateMasterMode=true;
if (args[i] == "--line" && i+1<args.size()) {
QStringList lineCol = args[++i].split(":");
line = lineCol.at(0).toInt()-1;
if (lineCol.count() >= 2) {
col = lineCol.at(1).toInt();
if ((col)<0) col = 0;
}
}
if (args[i] == "--insert-cite" && i+1<args.size()) {
cite = args[++i];
}
#ifndef NO_POPPLER_PREVIEW
if (args[i] == "--pdf-viewer-only") pdfViewerOnly = true;
if (args[i] == "--page") page = args[++i].toInt()-1;
#endif
}
#ifndef NO_POPPLER_PREVIEW
if (pdfViewerOnly) {
if (PDFDocument::documentList().isEmpty())
newPdfPreviewer();
foreach (PDFDocument* viewer, PDFDocument::documentList()) {
if (!filesToLoad.isEmpty()) viewer->loadFile(filesToLoad.first(), QFileInfo());
connect(viewer,SIGNAL(destroyed()), SLOT(deleteLater()));
viewer->show();
viewer->setFocus();
if (page!=-1) viewer->goToPage(page);
}
hide();
return;
}
#endif
// execute command line
foreach(const QString& fileToLoad,filesToLoad){
QFileInfo ftl(fileToLoad);
if (fileToLoad != "") {
if (ftl.exists()) {
if (ftl.suffix() == Session::fileExtension()) {
loadSession(ftl.filePath());
} else {
load(fileToLoad, activateMasterMode);
}
} else if (ftl.absoluteDir().exists()) {
fileNew(ftl.absoluteFilePath());
if (activateMasterMode) {
if (documents.singleMode()) ToggleMode(); //will save the new file
else {
ToggleMode();
ToggleMode();
}
}
//return ;
}
}
}
if (line!=-1){
QApplication::processEvents();
gotoLine(line, col, 0, QEditor::KeepSurrounding | QEditor::ExpandFold);
QTimer::singleShot(1000,currentEditor(),SLOT(ensureCursorVisible()));
}
if (!cite.isNull()) {
InsertCitation(cite);
}
#ifndef QT_NO_DEBUG
//execute test after command line is known
if (realCmdLine){ //only at start
executeTests(args);
if (args.contains("--update-translations")) {
generateAddtionalTranslations();
}
}
#endif
if (realCmdLine) Guardian::summon();
}
void Texmaker::executeTests(const QStringList &args){
QFileInfo myself(QCoreApplication::applicationFilePath());
if (args.contains("--disable-tests")) return;
#if !defined(QT_NO_DEBUG) && !defined(NO_TESTS)
bool allTests = args.contains("--execute-all-tests")
//execute all tests once a week or if command paramter is set
|| (configManager.debugLastFullTestRun.daysTo(myself.lastModified())>6);
if (args.contains("--execute-tests") || myself.lastModified()!=configManager.debugLastFileModification || allTests) {
fileNew();
if (!currentEditorView() || !currentEditorView()->editor)
QMessageBox::critical(0,"wtf?","test failed",QMessageBox::Ok);
if (allTests) configManager.debugLastFullTestRun=myself.lastModified();
TestManager testManager;
connect(&testManager, SIGNAL(newMessage(QString)), this, SLOT(showTestProgress(QString)));
QString result = testManager.execute(allTests?TestManager::TL_ALL:TestManager::TL_FAST, currentEditorView(),currentEditorView()->codeeditor,currentEditorView()->editor, &buildManager);
m_languages->setLanguageFromName(currentEditorView()->editor, "TXS Test Results");
currentEditorView()->editor->setText(result, false);
configManager.debugLastFileModification=QFileInfo(QCoreApplication::applicationFilePath()).lastModified();
}
#endif
}
void Texmaker::showTestProgress(const QString &message) {
outputView->insertMessageLine(message);
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents | QEventLoop::ExcludeSocketNotifiers);
}
void Texmaker::generateAddtionalTranslations(){
QStringList translations;
translations << "/******************************************************************************";
translations << " * Do not manually edit this file. It is automatically generated by a call to";
translations << " * texstudio --update-translations";
translations << " * This generates some additional translations which lupdate doesn't find";
translations << " * (e.g. from uiconfig.xml, color names, qnfa format names) ";
translations << " ******************************************************************************/";
translations << "#undef UNDEFINED";
translations << "#ifdef UNDEFINED";
translations << "static const char* translations[] = {";
QRegExp commandOnly("\\\\['`^\"~=.^]?[a-zA-Z]*(\\{\\})* *"); //latex command
//copy menu item text
QFile xmlFile(":/uiconfig.xml");
xmlFile.open(QIODevice::ReadOnly);
QDomDocument xml;
xml.setContent(&xmlFile);
QDomNode current = xml.documentElement();
CodeSnippet::debugDisableAutoTranslate = true;
while (!current.isNull()) {
QDomNamedNodeMap attribs = current.attributes();
QString text = attribs.namedItem("text").nodeValue();
if (text!="" && !commandOnly.exactMatch(text))
translations << "QT_TRANSLATE_NOOP(\"ConfigManager\", \""+text.replace("\\","\\\\").replace("\"","\\\"")+"\"), ";
QString insert = attribs.namedItem("insert").nodeValue();
if (insert != "") {
CodeSnippet cs(insert, false);
for (int i=0;i<cs.placeHolders.size();i++)
for (int j=0;j<cs.placeHolders[i].size();j++)
if (cs.placeHolders[i][j].flags & CodeSnippetPlaceHolder::Translatable)
translations << "QT_TRANSLATE_NOOP(\"CodeSnippet_PlaceHolder\", \""+cs.lines[i].mid(cs.placeHolders[i][j].offset,cs.placeHolders[i][j].length)+"\"), ";
}
if (current.hasChildNodes()) current=current.firstChild();
else if (!current.nextSibling().isNull()) current=current.nextSibling();
else if (!current.parentNode().isNull()) current = current.parentNode().nextSibling();
else current = current.parentNode();
}
CodeSnippet::debugDisableAutoTranslate = false;
//copy
QFile xmlFile2(":/qxs/defaultFormats.qxf");
xmlFile2.open(QIODevice::ReadOnly);
xml.setContent(&xmlFile2);
QDomNodeList formats=xml.documentElement().elementsByTagName("format");
for (int i=0;i<formats.size();i++)
translations << "QT_TRANSLATE_NOOP(\"QFormatConfig\", \""+formats.at(i).attributes().namedItem("id").nodeValue()+"\"), ";
translations << "QT_TRANSLATE_NOOP(\"QFormatConfig\", \"normal\"),";
for (int i=0;i<configManager.managedToolBars.size();i++)
translations << "QT_TRANSLATE_NOOP(\"Texmaker\",\""+configManager.managedToolBars[i].name+"\"),";
foreach (const QString &s, m_languages->languages())
translations << "QT_TRANSLATE_NOOP(\"Texmaker\", \""+s+"\", \"Format name of language definition \"), ";
translations << "\"\"};";
translations << "#endif\n\n";
QFile translationFile("additionaltranslations.cpp");
translationFile.open(QIODevice::WriteOnly);
translationFile.write(translations.join("\n").toLatin1());
translationFile.close();
}
void Texmaker::onOtherInstanceMessage(const QString &msg) { // Added slot for messages to the single instance
show();
activateWindow();
executeCommandLine(msg.split("#!#"),false);
}
void Texmaker::ToggleMode() {
//QAction *action = qobject_cast<QAction *>(sender());
if (!documents.singleMode()) documents.setMasterDocument(0);
else if (currentEditorView()) {
if (getCurrentFileName()=="")
fileSave();
if (getCurrentFileName()=="") {
QMessageBox::warning(this,tr("Error"),tr("You have to save the file before switching to master mode!"));
return;
}
documents.setMasterDocument(currentEditorView()->document);
}
completerNeedsUpdate();
}
////////////////// VIEW ////////////////
void Texmaker::gotoNextDocument() {
// TODO check: can we have managed action connecting to the EditorView slot directly? Then we could remove this slot
EditorTabs->gotoNextDocument();
}
void Texmaker::gotoPrevDocument() {
// TODO check: can we have managed action connecting to the EditorView slot directly? Then we could remove this slot
EditorTabs->gotoPrevDocument();
}
void Texmaker::gotoOpenDocument(){
QAction* act = qobject_cast<QAction*>(sender());
REQUIRE(act);
int doc = act->data().toInt();
EditorTabs->setCurrentIndex(doc);
}
void Texmaker::updateOpenDocumentMenu(bool localChange){
if (localChange) {
Q_ASSERT(currentEditorView());
int idx = EditorTabs->currentIndex();
QString id = "doc"+QString::number(idx);
QMenu* menu = configManager.getManagedMenu("main/view/documents");
configManager.newManagedAction(menu, id, currentEditorView()->displayName().replace("&","&&"), SLOT(gotoOpenDocument()))->setData(idx);
return;
}
QStringList sl;
foreach (LatexEditorView *edView, EditorTabs->editors()) {
sl << (edView->displayName().replace("&", "&&"));
}
configManager.updateListMenu("main/view/documents", sl, "doc", false, SLOT(gotoOpenDocument()), 0, false, 0);
}
void Texmaker::focusEditor(){
raise();
activateWindow();
if (currentEditorView())
currentEditorView()->setFocus();
}
void Texmaker::focusViewer(){
#ifndef NO_POPPLER_PREVIEW
QList<PDFDocument*> viewers = PDFDocument::documentList();
if (viewers.isEmpty()) return;
if (viewers.count() > 1 && currentEditorView()) {
// try: PDF for current file
QFileInfo currentFile = currentEditorView()->getDocument()->getFileInfo();
foreach (PDFDocument* viewer, viewers) {
if (viewer->getMasterFile() == currentFile) {
viewer->focus();
return;
}
}
// try: PDF for master file
LatexDocument *masterDoc = documents.getMasterDocumentForDoc(0);
if (masterDoc) {
QFileInfo masterFile = masterDoc->getFileInfo();
foreach (PDFDocument* viewer, viewers) {
if (viewer->getMasterFile() == masterFile) {
viewer->focus();
return;
}
}
}
}
// fall back to first
viewers.at(0)->focus();
#endif
}
void Texmaker::viewCloseSomething(){
if (fileSelector){
fileSelector.data()->deleteLater();
return;
}
if (buildManager.stopBuildAction()->isEnabled()) {
buildManager.stopBuildAction()->trigger();
return;
}
if (unicodeInsertionDialog) {
unicodeInsertionDialog->close();
return;
}
if (completer && completer->isVisible() && completer->close())
return;
#ifndef NO_POPPLER_PREVIEW
QWidget* w = QApplication::focusWidget();
while (w && !qobject_cast<PDFDocument*>(w))
w = w->parentWidget();
if (qobject_cast<PDFDocument*>(w)) {
PDFDocument* focusedPdf = qobject_cast<PDFDocument*>(w);
if (focusedPdf->embeddedMode) {
focusedPdf->closeSomething();
focusedPdf->widget()->setFocus();
return;
}
}
#endif
if (textAnalysisDlg) {
textAnalysisDlg->close();
return;
}
if (currentEditorView() && currentEditorView()->closeSomething())
return;
if (outputView->isVisible() && configManager.useEscForClosingLog) {
outputView->hide();
return;
}
#ifndef NO_POPPLER_PREVIEW
foreach (PDFDocument* doc, PDFDocument::documentList())
if (doc->embeddedMode) {
doc->close();
return;
}
#endif
if(windowState()==Qt::WindowFullScreen && !configManager.disableEscForClosingFullscreen){
stateFullScreen=saveState(1);
setWindowState(Qt::WindowNoState);
restoreState(windowstate,0);
fullscreenModeAction->setChecked(false);
return;
}
QTime ct = QTime::currentTime();
if (ct.second() % 5 != 0) return;
for (int i=2;i<63;i++) if (ct.minute() != i && ct.minute() % i == 0) return;
txsInformation("<html><head></head><body><img src=':/images/egg.png'></body></html>");
}
void Texmaker::setFullScreenMode() {
if(!fullscreenModeAction->isChecked()) {
stateFullScreen=saveState(1);
showNormal();
restoreState(windowstate,0);
#if QT_VERSION < 0x040701
setUnifiedTitleAndToolBarOnMac(true);
#endif
}
else {
windowstate=saveState(0);
#if QT_VERSION < 0x040701
setUnifiedTitleAndToolBarOnMac(false); //prevent crash, see https://bugreports.qt-project.org/browse/QTBUG-16274?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
#endif
showFullScreen();
restoreState(stateFullScreen,1);
}
}
void Texmaker::viewAlignWindows() {
QWidgetList windows = QApplication::topLevelWidgets();
#ifndef NO_POPPLER_PREVIEW
// find first pdf viewer window
PDFDocument *pdfViewer = 0;
foreach (QWidget *w, windows) {
pdfViewer = qobject_cast<PDFDocument *>(w);
if (pdfViewer) break;
}
int splitXpos = frameGeometry().right();
int frameWidth = frameGeometry().width() - width();
int frameHeight = frameGeometry().height() - height();
// main window "full size" to the left
QRect screen = QApplication::desktop()->availableGeometry(this);
move(screen.topLeft());
resize(splitXpos - screen.left() - frameWidth, screen.height()-frameHeight);
// pdfViewer "full size" to the left
if (pdfViewer) {
pdfViewer->move(splitXpos, screen.top());
pdfViewer->resize(screen.right() - frameGeometry().right() - frameWidth, screen.height()-frameHeight);
}
#endif
}
void Texmaker::viewSetHighlighting(QAction *act) {
if (!currentEditor()) return;
currentEditorView()->clearOverlays();
m_languages->setLanguageFromName(currentEditor(), act->data().toString());
// TODO: Check if reCheckSyntax is really necessary. Setting the language emits (among others) contentsChange(0, lines)
currentEditorView()->reCheckSyntax();
}
void Texmaker::showHighlightingMenu() {
// check active item just before showing the menu. So we don't have to keep track of the languages, e.g. when switching editors
if (!currentEditor()) return;
QLanguageDefinition *ld = currentEditor()->languageDefinition();
if (ld) {
foreach (QAction *act, highlightLanguageActions->actions()) {
if (act->data().toString() == ld->language()) {
act->setChecked(true);
break;
}
}
}
}
void Texmaker::viewCollapseBlock() {
if (!currentEditorView()) return;
currentEditorView()->foldBlockAt(false,currentEditorView()->editor->cursor().lineNumber());
}
void Texmaker::viewExpandBlock() {
if (!currentEditorView()) return;
currentEditorView()->foldBlockAt(true,currentEditorView()->editor->cursor().lineNumber());
}
void Texmaker::pdfClosed(){
#ifndef NO_POPPLER_PREVIEW
PDFDocument* from = qobject_cast<PDFDocument*>(sender());
if(from){
if(from->embeddedMode){
shrinkEmbeddedPDFViewer(true);
QList<int> sz=mainHSplitter->sizes(); // set widths to 50%, eventually restore user setting
int sum=0;
int last=0;
foreach(int i,sz){
sum+=i;
last=i;
}
pdfSplitterRel=1.0*last/sum;
}
}
//QTimer::singleShot(100, this, SLOT(restoreMacMenuBar()));
#endif
}
void Texmaker::restoreMacMenuBar(){
#if QT_VERSION<0x050000 && defined Q_OS_MAC
//workaround to restore mac menubar
menuBar()->setNativeMenuBar(false);
menuBar()->setNativeMenuBar(true);
#endif
}
QObject* Texmaker::newPdfPreviewer(bool embedded){
#ifndef NO_POPPLER_PREVIEW
PDFDocument* pdfviewerWindow=new PDFDocument(configManager.pdfDocumentConfig,embedded);
if(embedded){
mainHSplitter->addWidget(pdfviewerWindow);
QList<int> sz=mainHSplitter->sizes(); // set widths to 50%, eventually restore user setting
int sum=0;
foreach(int i,sz){
sum+=i;
}
sz.clear();
if(pdfSplitterRel<0.1 || pdfSplitterRel>0.9) //sanity check
pdfSplitterRel=0.5;
sz << sum-qRound(pdfSplitterRel*sum);
sz << qRound(pdfSplitterRel*sum);
mainHSplitter->setSizes(sz);
}
connect(pdfviewerWindow, SIGNAL(triggeredAbout()), SLOT(HelpAbout()));
connect(pdfviewerWindow, SIGNAL(triggeredEnlarge()), SLOT(enlargeEmbeddedPDFViewer()));
connect(pdfviewerWindow, SIGNAL(triggeredShrink()), SLOT(shrinkEmbeddedPDFViewer()));
connect(pdfviewerWindow, SIGNAL(triggeredManual()), SLOT(UserManualHelp()));
connect(pdfviewerWindow, SIGNAL(documentClosed()), SLOT(pdfClosed()));
connect(pdfviewerWindow, SIGNAL(triggeredQuit()), SLOT(fileExit()));
connect(pdfviewerWindow, SIGNAL(triggeredConfigure()), SLOT(GeneralOptions()));
connect(pdfviewerWindow, SIGNAL(syncSource(const QString&, int, bool, QString)), SLOT(syncFromViewer(const QString &, int, bool, QString)));
connect(pdfviewerWindow, SIGNAL(focusEditor()), SLOT(focusEditor()));
connect(pdfviewerWindow, SIGNAL(runCommand(const QString&, const QFileInfo&, const QFileInfo&, int)), &buildManager, SLOT(runCommand(const QString&, const QFileInfo&, const QFileInfo&, int)));
connect(pdfviewerWindow, SIGNAL(triggeredClone()), SLOT(newPdfPreviewer()));
PDFDocument* from = qobject_cast<PDFDocument*>(sender());
if (from) {
pdfviewerWindow->loadFile(from->fileName(), from->getMasterFile(), true);
pdfviewerWindow->goToPage(from->widget()->getPageIndex());
}//load file before enabling sync or it will jump to the first page
foreach (PDFDocument* doc, PDFDocument::documentList()) {
if (doc == pdfviewerWindow) continue;
connect(doc, SIGNAL(syncView(QString,QFileInfo,int)), pdfviewerWindow, SLOT(syncFromView(QString,QFileInfo,int)));
connect(pdfviewerWindow, SIGNAL(syncView(QString,QFileInfo, int)), doc, SLOT(syncFromView(QString,QFileInfo,int)));
}
return pdfviewerWindow;
#else
return 0;
#endif
}
void Texmaker::masterDocumentChanged(LatexDocument * doc){
Q_UNUSED(doc);
Q_ASSERT(documents.singleMode()==!documents.masterDocument);
if (documents.singleMode()){
outputView->resetMessagesAndLog();
} else {
configManager.addRecentFile(documents.masterDocument->getFileName(),true);
int pos=EditorTabs->currentIndex();
EditorTabs->moveTab(pos,0);
}
updateMasterDocumentCaption();
updateOpenDocumentMenu();
}
void Texmaker::aboutToDeleteDocument(LatexDocument * doc){
emit infoFileClosed();
for (int i=configManager.completerConfig->userMacros.size()-1;i>=0;i--)
if (configManager.completerConfig->userMacros[i].document == doc)
configManager.completerConfig->userMacros.removeAt(i);
}
//*********************************
void Texmaker::dragEnterEvent(QDragEnterEvent *event) {
if (event->mimeData()->hasFormat("text/uri-list")) event->acceptProposedAction();
}
void Texmaker::dropEvent(QDropEvent *event) {
QList<QUrl> uris=event->mimeData()->urls();
QStringList imageFormats = InsertGraphics::imageFormats();
saveCurrentCursorToHistory();
bool alreadyMovedCursor = false;
for (int i=0; i<uris.length(); i++) {
QFileInfo fi = QFileInfo(uris.at(i).toLocalFile());
if (imageFormats.contains(fi.suffix().toLower()) && currentEditor()) {
if (!alreadyMovedCursor) {
QPoint p = currentEditor()->mapToContents(currentEditor()->mapToFrame(currentEditor()->mapFrom(this, event->pos())));
QDocumentCursor cur = currentEditor()->cursorForPosition(p);
cur.beginEditBlock();
if (!cur.atLineStart()) {
if (!cur.movePosition(1, QDocumentCursor::NextBlock, QDocumentCursor::MoveAnchor)) {
cur.movePosition(1, QDocumentCursor::EndOfBlock, QDocumentCursor::MoveAnchor);
cur.insertLine();
}
}
currentEditor()->setCursor(cur);
cur.endEditBlock();
alreadyMovedCursor = true;
}
QuickGraphics(uris.at(i).toLocalFile());
} else if (fi.suffix() == Session::fileExtension()) {
loadSession(fi.filePath());
} else
load(fi.filePath());
}
event->acceptProposedAction();
raise();
}
void Texmaker::changeEvent(QEvent *e) {
switch (e->type()) {
case QEvent::LanguageChange:
if (configManager.lastLanguage==configManager.language) return; //don't update if config not changed
//QMessageBox::information(0,"rt","retranslate",0);
setupMenus();
setupDockWidgets();
UpdateCaption();
updateMasterDocumentCaption();
break;
default:
break;
}
}
void Texmaker::resizeEvent(QResizeEvent *e){
centerFileSelector();
QMainWindow::resizeEvent(e);
}
#if (QT_VERSION > 0x050000) && (defined(Q_OS_MAC))
// workaround for qt/osx not handling all possible shortcuts esp. alt+key/esc
bool Texmaker::eventFilter(QObject *obj, QEvent *event)
{
if(obj->objectName()=="ConfigDialogWindow" || obj->objectName()=="ShortcutComboBox")
return false; // don't handle keys from shortcutcombo (config)
if(event->type()==QEvent::KeyPress){
//qDebug()<<obj->objectName();
//qDebug()<<obj->metaObject()->className();
QKeyEvent *keyEvent=static_cast<QKeyEvent*>(event);
QString modifier = QString::null;
if (keyEvent->modifiers() & Qt::ShiftModifier)
modifier += "Shift+";
if (keyEvent->modifiers() & Qt::ControlModifier)
modifier += "Ctrl+";
if (keyEvent->modifiers() & Qt::AltModifier)
modifier += "Alt+";
if (keyEvent->modifiers() & Qt::MetaModifier)
modifier += "Meta+";
QString key = QKeySequence(keyEvent->key()).toString();
QKeySequence result(modifier + key);
if((keyEvent->key()==0)||((keyEvent->modifiers()==0)&&(key!="Esc")) || (keyEvent->modifiers()&Qt::MetaModifier) || (keyEvent->modifiers() & Qt::ControlModifier) || (keyEvent->modifiers() & Qt::KeypadModifier))
return false; // no need to handle these
if(configManager.specialShortcuts.contains(result)){
QAction *act=configManager.specialShortcuts.value(result);
if(act)
act->trigger();
return true;
}
return false;
}
return false;
}
#endif
//***********************************
void Texmaker::SetMostUsedSymbols(QTableWidgetItem* item) {
bool changed=false;
int index=symbolMostused.indexOf(item);
if(index<0){
//check whether it was loaded as mosteUsed ...
for(int i=0;i<symbolMostused.count();i++){
QTableWidgetItem *elem=symbolMostused.at(i);
if(elem->data(Qt::UserRole+2)==item->data(Qt::UserRole+2)){
index=i;
item->setData(Qt::UserRole+1,QVariant::fromValue(elem));
int cnt=elem->data(Qt::UserRole).toInt();
elem->setData(Qt::UserRole,cnt+1);
elem->setData(Qt::UserRole+3,QVariant::fromValue(item));//reference to original item for removing later
item=elem;
break;
}
}
if(index<0){
QTableWidgetItem *elem=item->clone();
item->setData(Qt::UserRole+1,QVariant::fromValue(elem));
elem->setData(Qt::UserRole+3,QVariant::fromValue(item));//reference to original item for removing later
symbolMostused.append(elem);
if(symbolMostused.size()<=12)
changed=true;
}
}
if(index>-1){
symbolMostused.removeAt(index);
while(index>0&&symbolMostused[index-1]->data(Qt::UserRole).toInt()<item->data(Qt::UserRole).toInt()){
index--;
}
symbolMostused.insert(index,item);
changed=true;
}
if(changed) MostUsedSymbolWidget->SetUserPage(symbolMostused);
}
void Texmaker::updateCompleter(LatexEditorView* edView) {
QSet<QString> words;
if (configManager.parseBibTeX) documents.updateBibFiles();
if(!edView)
edView=currentEditorView();
QList<LatexDocument*> docs;
LatexParser ltxCommands=LatexParser::getInstance();
if(edView && edView->document){
// determine from which docs data needs to be collected
docs=edView->document->getListOfDocs();
// collect user commands and references
foreach(LatexDocument* doc,docs){
words.unite(doc->userCommandList());
words.unite(doc->additionalCommandsList());
ltxCommands.append(doc->ltxCommands);
}
}
// collect user commands and references
foreach(const LatexDocument* doc,docs){
foreach(const QString& refCommand, latexParser.possibleCommands["%ref"]){
QString temp='@'+refCommand+"{%1}";
foreach (const QString& l, doc->labelItems())
words.insert(temp.arg(l));
}
}
if (configManager.parseBibTeX){
QStringList bibIds;
QStringList collected_mentionedBibTeXFiles;
foreach(const LatexDocument* doc,docs){
collected_mentionedBibTeXFiles<<doc->listOfMentionedBibTeXFiles();
}
for (int i=0; i<collected_mentionedBibTeXFiles.count();i++){
if (!documents.bibTeXFiles.contains(collected_mentionedBibTeXFiles[i])){
qDebug("BibTeX-File %s not loaded",collected_mentionedBibTeXFiles[i].toLatin1().constData());
continue; //wtf?s
}
BibTeXFileInfo& bibTex=documents.bibTeXFiles[collected_mentionedBibTeXFiles[i]];
// add citation to completer for direct citation completion
bibIds<<bibTex.ids;
}
//handle bibitem definitions
foreach(const LatexDocument* doc,docs){
bibIds<<doc->bibItems();
}
//automatic use of cite commands
QStringList citationCommands;
foreach(const QString& citeCommand, latexParser.possibleCommands["%cite"]){
QString temp='@'+citeCommand+"{@}";
citationCommands.append(temp);
words.insert(temp);
/*foreach (const QString &value, bibIds)
words.insert(temp.arg(value));*/
}
foreach(QString citeCommand, latexParser.possibleCommands["%citeExtended"]){
QString temp='@'+citeCommand.replace("%<bibid%>","@");
citationCommands.append(temp);
words.insert(temp);
}
completer->setAdditionalWords(citationCommands.toSet(),CT_CITATIONCOMMANDS);
completer->setAdditionalWords(bibIds.toSet(),CT_CITATIONS);
}
completionBaseCommandsUpdated=false;
completer->setAdditionalWords(words,CT_COMMANDS);
// add keyval completion
foreach(const QString &elem,ltxCommands.possibleCommands.keys()){
if(elem.startsWith("key%")){
QString name=elem.mid(4);
if(name.endsWith("#c"))
name.chop(2);
if(!name.isEmpty()){
completer->setKeyValWords(name,ltxCommands.possibleCommands[elem]);
}
}
}
// add context completion
LatexCompleterConfig* config=completer->getConfig();
if(config){
foreach(const QString &elem,config->specialCompletionKeys){
completer->setContextWords(ltxCommands.possibleCommands[elem],elem);
}
}
if(edView) edView->viewActivated();
GrammarCheck::staticMetaObject.invokeMethod(grammarCheck, "init", Qt::QueuedConnection, Q_ARG(LatexParser, latexParser), Q_ARG(GrammarCheckerConfig, *configManager.grammarCheckerConfig));
updateHighlighting();
mCompleterNeedsUpdate=false;
}
void Texmaker::outputPageChanged(const QString &id) {
if (id == outputView->LOG_PAGE && !outputView->getLogWidget()->logPresent()) {
if (!loadLog())
return;
if (HasLatexErrors())
ViewLog();
}
}
void Texmaker::jumpToSearch(QDocument* doc, int lineNumber){
REQUIRE(qobject_cast<LatexDocument*>(doc));
if(currentEditor() && currentEditor()->document()==doc && currentEditor()->cursor().lineNumber()==lineNumber)
{
QDocumentCursor c=currentEditor()->cursor();
int col=c.columnNumber();
gotoLine(lineNumber);
col=outputView->getNextSearchResultColumn(c.line().text() ,col+1);
currentEditor()->setCursorPosition(lineNumber,col,false);
currentEditor()->ensureCursorVisible(QEditor::Navigation);
} else {
gotoLine(lineNumber, doc->getFileName().size()?doc->getFileName():qobject_cast<LatexDocument*>(doc)->getTemporaryFileName());
int col=outputView->getNextSearchResultColumn(currentEditor()->document()->line(lineNumber).text() ,0);
currentEditor()->setCursorPosition(lineNumber,col,false);
currentEditor()->ensureCursorVisible(QEditor::Navigation);
outputView->showPage(outputView->SEARCH_RESULT_PAGE);
}
QDocumentCursor highlight = currentEditor()->cursor();
highlight.movePosition(outputView->searchExpression().length(), QDocumentCursor::NextCharacter, QDocumentCursor::KeepAnchor);
currentEditorView()->temporaryHighlight(highlight);
}
void Texmaker::gotoLine(int line, int col, LatexEditorView *edView, QEditor::MoveFlags mflags, bool setFocus) {
bool changeCurrentEditor = (edView != currentEditorView());
if (!edView)
edView = currentEditorView(); // default
if (!edView || line<0) return;
saveCurrentCursorToHistory();
if (changeCurrentEditor) {
if(EditorTabs->containsEditor(edView)){
EditorTabs->setCurrentEditor(edView);
mflags &= ~QEditor::Animated;
}else{
load(edView->getDocument()->getFileName());
}
}
edView->editor->setCursorPosition(line,col,false);
edView->editor->ensureCursorVisible(mflags);
if (setFocus) {
edView->editor->setFocus();
}
}
bool Texmaker::gotoLine(int line, const QString &fileName){
LatexEditorView* edView = getEditorViewFromFileName(fileName, true);
QEditor::MoveFlags mflags = QEditor::Navigation;
if (!edView) {
if (!load(fileName)) return false;
mflags &= ~QEditor::Animated;
}
gotoLine(line, 0, edView, mflags);
return true;
}
void Texmaker::gotoLogEntryEditorOnly(int logEntryNumber) {
if (logEntryNumber<0 || logEntryNumber>=outputView->getLogWidget()->getLogModel()->count()) return;
QString fileName = outputView->getLogWidget()->getLogModel()->at(logEntryNumber).file;
if (!ActivateEditorForFile(fileName, true))
if (!load(fileName)) return;
if (currentEditorView()->logEntryToLine.isEmpty()) {
updateLogEntriesInEditors();
}
if (configManager.showLogMarkersWhenClickingLogEntry) {
setLogMarksVisible(true);
}
//get line
QDocumentLineHandle* lh = currentEditorView()->logEntryToLine.value(logEntryNumber, 0);
if (!lh) return;
//goto
gotoLine(currentEditor()->document()->indexOf(lh));
}
bool Texmaker::gotoLogEntryAt(int newLineNumber) {
//goto line
if (newLineNumber<0) return false;
gotoLine(newLineNumber);
//find error number
QDocumentLineHandle* lh=currentEditorView()->editor->document()->line(newLineNumber).handle();
int logEntryNumber=currentEditorView()->lineToLogEntries.value(lh,-1);
if (logEntryNumber==-1) return false;
//goto log entry
outputView->selectLogEntry(logEntryNumber);
QPoint p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
// p.ry()+=2*currentEditorView()->editor->document()->fontMetrics().lineSpacing();
REQUIRE_RET(outputView->getLogWidget()->getLogModel(), true);
QList<int> errors = currentEditorView()->lineToLogEntries.values(lh);
QString msg = outputView->getLogWidget()->getLogModel()->htmlErrorTable(errors);
QToolTip::showText(p, msg, 0);
LatexEditorView::hideTooltipWhenLeavingLine=newLineNumber;
return true;
}
bool Texmaker::gotoMark(bool backward, int id) {
if (!currentEditorView()) return false;
if (backward)
return gotoLogEntryAt(currentEditorView()->editor->document()->findPreviousMark(id,qMax(0,currentEditorView()->editor->cursor().lineNumber()-1),0));
else
return gotoLogEntryAt(currentEditorView()->editor->document()->findNextMark(id,currentEditorView()->editor->cursor().lineNumber()+1));
}
QList<int> Texmaker::findOccurencesApproximate(QString line, const QString& guessedWord) {
QList<int> columns;
// exact match
columns = indicesOf(line, guessedWord);
if (columns.isEmpty()) columns = indicesOf(line, guessedWord, Qt::CaseSensitive);
QString changedWord = guessedWord;
if (columns.isEmpty()) {
//search again and ignore useless characters
QString regex;
for (int i=0;i<changedWord.size();i++)
if (changedWord[i].category() == QChar::Other_Control || changedWord[i].category() == QChar::Other_Format)
changedWord[i] = '\1';
foreach (const QString& x, changedWord.split('\1', QString::SkipEmptyParts))
if (regex.isEmpty()) regex += QRegExp::escape(x);
else regex += ".{0,2}" + QRegExp::escape(x);
QRegExp rx = QRegExp(regex);
columns = indicesOf(line, rx);
if (columns.isEmpty()) {
rx.setCaseSensitivity(Qt::CaseSensitive);
columns = indicesOf(line, rx);
}
}
if (columns.isEmpty()) {
//search again and allow additional whitespace
QString regex;
foreach (const QString & x , changedWord.split(" ",QString::SkipEmptyParts))
if (regex.isEmpty()) regex = QRegExp::escape(x);
else regex+="\\s+"+QRegExp::escape(x);
QRegExp rx = QRegExp(regex);
columns = indicesOf(line, rx);
if (columns.isEmpty()) {
rx.setCaseSensitivity(Qt::CaseSensitive);
columns = indicesOf(line, rx);
}
}
if (columns.isEmpty()) {
int bestMatch = -1, bestScore = 0;
for (int i=0;i<line.size()-guessedWord.size();i++) {
int score = 0;
for (int c = i, s = 0; c < line.size() && s < guessedWord.size(); c++, s++) {
QChar C = line[c], S = guessedWord[s];
if (C == S) score += 5; //perfect match
else if (C.toLower() == S.toLower()) score += 2; //ok match
else if (C.isSpace()) s--; //skip spaces
else if (S.isSpace()) c--; //skip spaces
else if (S.category() == QChar::Other_Control || S.category() == QChar::Other_Format) {
for (s++; s < guessedWord.size() && (guessedWord[s].category() == QChar::Other_Control||guessedWord[s].category() == QChar::Other_Format);s++); //skip nonsense
if (s >= guessedWord.size()) continue;
if (guessedWord[s] == C) { score += 5; continue; }
if (c+1 < line.size() && guessedWord[s] == line[c+1]) { score += 5; c++; continue; }
//also skip next character after that nonsense
}
}
if (score > bestScore) bestScore = score, bestMatch = i;
}
if (bestScore > guessedWord.size()*5 / 3) columns.append(bestMatch); //accept if 0.33 similarity
}
return columns;
}
void Texmaker::syncFromViewer(const QString &fileName, int line, bool activate, const QString& guessedWord){
if (!ActivateEditorForFile(fileName, true, activate))
if (!load(fileName)) return;
shrinkEmbeddedPDFViewer();
QDocumentLine l = currentEditorView()->document->lineFromLineSnapshot(line);
if (l.isValid()) {
int originalLineNumber = currentEditorView()->document->indexOf(l, line);
if (originalLineNumber >= 0) line = originalLineNumber;
}
gotoLine(line, 0, 0, QEditor::Navigation, activate);
Q_ASSERT(currentEditor());
// guessedWord may appear multiple times -> we highlight them all
QList<int> columns = findOccurencesApproximate(currentEditor()->cursor().line().text(), guessedWord);
if (columns.isEmpty() || guessedWord.isEmpty()) {
// highlight complete line
QDocumentCursor highlight(currentEditor()->document(), line, 0);
highlight.movePosition(1, QDocumentCursor::EndOfLine, QDocumentCursor::KeepAnchor);
currentEditorView()->temporaryHighlight(highlight);
} else {
// highlight all found positions
QDocumentCursor highlight(currentEditor()->document(), line, 0);
foreach (int col, columns) {
int cursorCol = col+guessedWord.length()/2;
highlight.setColumnNumber(cursorCol);
highlight.movePosition(1, QDocumentCursor::StartOfWord, QDocumentCursor::MoveAnchor);
highlight.movePosition(1, QDocumentCursor::EndOfWord, QDocumentCursor::KeepAnchor);
if (!highlight.hasSelection()) { // fallback, if we are not at a word
highlight.setColumnNumber(cursorCol);
highlight.movePosition(1, QDocumentCursor::PreviousCharacter, QDocumentCursor::MoveAnchor);
highlight.movePosition(1, QDocumentCursor::NextCharacter, QDocumentCursor::KeepAnchor);
}
currentEditor()->setCursorPosition(currentEditor()->cursor().lineNumber(), cursorCol,false);
currentEditor()->ensureCursorVisible(QEditor::KeepSurrounding | QEditor::ExpandFold);
currentEditorView()->temporaryHighlight(highlight);
}
}
if (activate) {
raise();
show();
activateWindow();
if (isMinimized()) showNormal();
}
}
void Texmaker::goBack() {
QDocumentCursor currentCur;
if (currentEditorView()) currentCur = currentEditorView()->editor->cursor();
setGlobalCursor(cursorHistory->back(currentCur));
}
void Texmaker::goForward() {
QDocumentCursor currentCur;
if (currentEditorView()) currentCur = currentEditorView()->editor->cursor();
setGlobalCursor(cursorHistory->forward(currentCur));
}
void Texmaker::setGlobalCursor(const QDocumentCursor &c) {
if (c.isValid()) {
LatexDocument *doc = qobject_cast<LatexDocument*>(c.document());
if (doc && doc->getEditorView()) {
LatexEditorView *edView = doc->getEditorView();
QEditor::MoveFlags mflags = QEditor::KeepSurrounding | QEditor::ExpandFold;
if (edView == currentEditorView()) mflags |= QEditor::Animated;
EditorTabs->setCurrentEditor(edView);
edView->editor->setFocus();
edView->editor->setCursor(c, false);
edView->editor->ensureCursorVisible(mflags);
}
}
}
void Texmaker::fuzzBackForward(){
#ifdef NOT_DEFINED__FUZZER_NEEDED_ONLY_FOR_DEBUGGING_RANDOM_CRASH_OF_CURSOR_HISTORY
int rep = random() % (1+cursorHistory->count());
for (int j = 0; j < rep; j++) goBack();
rep = random() % (1+cursorHistory->count());
for (int j = 0; j < rep; j++) goForward();
#endif
}
void Texmaker::fuzzCursorHistory(){
#ifdef NOT_DEFINED__FUZZER_NEEDED_ONLY_FOR_DEBUGGING_RANDOM_CRASH_OF_CURSOR_HISTORY
QString fillText;
for (int i = 0; i < 100; i++)
fillText += "\n" + QString("foobar abc xyz").repeated(random() % 100);
for (int i = 0; i < 100; i++) {
if (!documents.documents.isEmpty()) {
if (random() % 1000 < 500) documents.deleteDocument(documents.documents[random() % documents.documents.length()]);
fuzzBackForward();
}
if (!documents.documents.isEmpty()) {
QApplication::processEvents();
if (random() % 1000 < 500) documents.deleteDocument(documents.documents[random() % documents.documents.length()]);
fuzzBackForward();
}
fileNew();
currentEditor()->setText(fillText);
QApplication::processEvents();
int rep = random() % 100;
for (int j = 0; j < rep; j++) {
EditorView->setCurrentIndex(EditorView->count());
int l = random() % currentEditor()->document()->lineCount();
int c = random() % (currentEditor()->document()->line(l).length()+100);
currentEditor()->setCursor(currentEditor()->document()->cursor(l, c, random() % 100, random() % 100));
saveCurrentCursorToHistory();
fuzzBackForward();
}
}
#endif
}
void Texmaker::saveCurrentCursorToHistory() {
saveEditorCursorToHistory(currentEditorView());
}
void Texmaker::saveEditorCursorToHistory(LatexEditorView *edView) {
if (!edView) return;
cursorHistory->insertPos(edView->editor->cursor());
}
void Texmaker::StructureContextMenu(const QPoint& point) {
StructureEntry *entry = LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry) return;
if (entry->type==StructureEntry::SE_DOCUMENT_ROOT){
QMenu menu;
if (entry->document != documents.masterDocument) {
menu.addAction(tr("Close document"), this, SLOT(structureContextMenuCloseDocument()));
menu.addAction(tr("Set this document as master document"), this, SLOT(structureContextMenuSwitchMasterDocument()));
} else
menu.addAction(tr("Remove master document role"), this, SLOT(structureContextMenuSwitchMasterDocument()));
if(documents.model->getSingleDocMode()){
menu.addAction(tr("Show all open documents in this tree"), this, SLOT(latexModelViewMode()));
}else{
menu.addAction(tr("Show only current document in this tree"), this, SLOT(latexModelViewMode()));
}
menu.addSeparator();
menu.addAction(tr("Move document to &front"), this, SLOT(moveDocumentToFront()));
menu.addAction(tr("Move document to &end"), this, SLOT(moveDocumentToEnd()));
menu.addSeparator();
menu.addAction(tr("Expand Subitems"), this, SLOT(structureContextMenuExpandSubitems()));
menu.addAction(tr("Collapse Subitems"), this, SLOT(structureContextMenuCollapseSubitems()));
menu.exec(structureTreeView->mapToGlobal(point));
}
if (!entry->parent) return;
if (entry->type==StructureEntry::SE_LABEL) {
QMenu menu;
menu.addAction(tr("Insert"),this, SLOT(editPasteRef()))->setData(entry->title);
menu.addAction(tr("Insert as %1").arg("\\ref{...}"),this, SLOT(editPasteRef()))->setData(QString("\\ref{%1}").arg(entry->title));
menu.addAction(tr("Insert as %1").arg("\\pageref{...}"),this, SLOT(editPasteRef()))->setData(QString("\\pageref{%1}").arg(entry->title));
menu.exec(structureTreeView->mapToGlobal(point));
}
if (entry->type==StructureEntry::SE_SECTION) {
QMenu menu(this);
StructureEntry *labelEntry = LatexDocumentsModel::labelForStructureEntry(entry);
if (labelEntry) {
menu.addAction(tr("Insert Label"),this, SLOT(editPasteRef()))->setData(labelEntry->title);
foreach (QString refCmd, configManager.referenceCommandsInContextMenu.split(",")) {
refCmd = refCmd.trimmed();
if (!refCmd.startsWith('\\')) continue;
menu.addAction(QString(tr("Insert %1 to Label", "autoreplaced, e.g.: Insert \\ref to Label").arg(refCmd)),this, SLOT(editPasteRef()))->setData(QString("%1{%2}").arg(refCmd).arg(labelEntry->title));
}
menu.addSeparator();
} else {
menu.addAction(tr("Create Label"),this, SLOT(createLabelFromAction()))->setData(QVariant::fromValue(entry));
menu.addSeparator();
}
menu.addAction(tr("Copy"),this, SLOT(editSectionCopy()));
menu.addAction(tr("Cut"),this, SLOT(editSectionCut()));
menu.addAction(tr("Paste Before"),this, SLOT(editSectionPasteBefore()));
menu.addAction(tr("Paste After"),this, SLOT(editSectionPasteAfter()));
menu.addSeparator();
menu.addAction(tr("Indent Section"),this, SLOT(editIndentSection()));
menu.addAction(tr("Unindent Section"),this, SLOT(editUnIndentSection()));
if (!entry->children.isEmpty()) {
menu.addSeparator();
menu.addAction(tr("Expand Subitems"), this, SLOT(structureContextMenuExpandSubitems()));
menu.addAction(tr("Collapse Subitems"), this, SLOT(structureContextMenuCollapseSubitems()));
}
menu.exec(structureTreeView->mapToGlobal(point));
}
if (entry->type==StructureEntry::SE_MAGICCOMMENT) {
QMenu menu;
menu.addAction(LatexEditorView::tr("Go to Definition"),this, SLOT(moveCursorTodlh()))->setData(QVariant::fromValue(entry));
menu.exec(structureTreeView->mapToGlobal(point));
}
if (entry->type==StructureEntry::SE_INCLUDE) {
QMenu menu;
menu.addAction(LatexEditorView::tr("Open Document"),this, SLOT(openExternalFile()))->setData(QVariant::fromValue(entry));
menu.addAction(LatexEditorView::tr("Go to Definition"),this, SLOT(moveCursorTodlh()))->setData(QVariant::fromValue(entry));
menu.exec(structureTreeView->mapToGlobal(point));
}
}
void Texmaker::openExternalFile(){
QAction *act = qobject_cast<QAction *>(sender());
if (!act) return;
StructureEntry *entry = qvariant_cast<StructureEntry *>(act->data());
if(entry){
openExternalFile(entry->title);
}
}
void Texmaker::structureContextMenuCloseDocument(){
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry) return;
LatexDocument* document = entry->document;
if (!document) return;
if (document->getEditorView()) EditorTabs->closeTab(document->getEditorView());
else if (document == documents.masterDocument) structureContextMenuSwitchMasterDocument();
}
void Texmaker::structureContextMenuSwitchMasterDocument(){
StructureEntry *entry=LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry) return;
LatexDocument* document = entry->document;
if (document == documents.masterDocument) documents.setMasterDocument(0);
else if (document->getFileName()!="") documents.setMasterDocument(document);
else if (document->getEditorView()) { //we have to save the document before
documents.setMasterDocument(0);
EditorTabs->setCurrentEditor(document->getEditorView());
ToggleMode();
}
}
void Texmaker::structureContextMenuExpandSubitems() {
setSubtreeExpanded(structureTreeView, structureTreeView->currentIndex(), true);
}
void Texmaker::structureContextMenuCollapseSubitems() {
setSubtreeExpanded(structureTreeView, structureTreeView->currentIndex(), false);
}
void Texmaker::editPasteRef() {
if (!currentEditorView()) return;
QAction *action = qobject_cast<QAction *>(sender());
if (!action) return;
currentEditor()->write(action->data().toString());
currentEditorView()->setFocus();
}
void Texmaker::previewLatex(){
if (!currentEditorView()) return;
// get selection
QDocumentCursor c = currentEditorView()->editor->cursor();
QDocumentCursor previewc;
if (c.hasSelection()) {
previewc = c; //X o riginalText = c.selectedText();
} else {
// if in math mode, move cursor to opening bracket
//TODO: Is there a more elegant solution to determine the beginning of a math environment.
QDocumentLine dl = c.line();
int col = c.columnNumber();
QList<int> mathFormats = QList<int>() << m_formats->id("numbers") << m_formats->id("math-keyword");
mathFormats.removeAll(0); // keep only valid entries in list
while(col>0 && mathFormats.contains(dl.getFormatAt(col-1))) col --;
c.setColumnNumber(col);
previewc = currentEditorView()->parenthizedTextSelection(c);
}
if (!previewc.hasSelection()) return;
showPreview(previewc,true);
}
void Texmaker::previewAvailable(const QString& imageFile, const PreviewSource& source){
QImage image;
#ifndef NO_POPPLER_PREVIEW
if(imageFile.endsWith(".pdf")){
// special treatment for pdf files (embedded pdf mode)
if(configManager.previewMode == ConfigManager::PM_EMBEDDED){
runInternalCommand("txs:///view-pdf-internal", QFileInfo(imageFile), "--embedded");
if(currentEditorView())
currentEditorView()->setFocus();
return;
}else{
//need to generate an image
Poppler::Document *document = Poppler::Document::load(imageFile);
if(!document)
return;
Poppler::Page *page=document->page(0);
if(!page)
return;
document->setRenderHint(Poppler::Document::Antialiasing);
document->setRenderHint(Poppler::Document::TextAntialiasing);
image=page->renderToImage(120,120);
}
}
#endif
if (configManager.previewMode == ConfigManager::PM_BOTH ||
configManager.previewMode == ConfigManager::PM_PANEL||
(configManager.previewMode == ConfigManager::PM_TOOLTIP_AS_FALLBACK && outputView->isPreviewPanelVisible())) {
outputView->showPage(outputView->PREVIEW_PAGE);
QPixmap img;
if(image.isNull()){
img.load(imageFile);
}else{
img=QPixmap::fromImage(image);
}
outputView->previewLatex(img);
}
if (configManager.previewMode == ConfigManager::PM_BOTH ||
configManager.previewMode == ConfigManager::PM_TOOLTIP||
source.atCursor ||
(configManager.previewMode == ConfigManager::PM_TOOLTIP_AS_FALLBACK && !outputView->isPreviewPanelVisible()) ||
(source.fromLine < 0)) {
QPoint p;
if(source.atCursor)
p=currentEditorView()->getHoverPosistion();
else
p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
QRect screen = QApplication::desktop()->screenGeometry();
QPixmap img;
if(image.isNull()){
img.load(imageFile);
int w=img.width();
if(w>screen.width()) w=screen.width()-2;
QToolTip::showText(p, QString("<img src=\""+imageFile+"\" width=%1 />").arg(w), 0);
}else{
img=QPixmap::fromImage(image);
int w=img.width();
if(w>screen.width()) w=screen.width()-2;
QString text;
#if QT_VERSION >= 0x040700
text= getImageAsText(img,w);
#else
QString tempPath = QDir::tempPath()+QDir::separator()+"."+QDir::separator();
img.save(tempPath+"txs_preview.png","PNG");
buildManager.addPreviewFileName(tempPath+"txs_preview.png");
text=QString("<img src=\""+tempPath+"txs_preview.png\" width=%1 />").arg(w);
#endif
QToolTip::showText(p, text, 0);
}
LatexEditorView::hideTooltipWhenLeavingLine=currentEditorView()->editor->cursor().lineNumber();
}
if (configManager.previewMode == ConfigManager::PM_INLINE && source.fromLine >= 0){
QDocument* doc = currentEditor()->document();
doc->setForceLineWrapCalculation(true);
int toLine = qBound(0, source.toLine, doc->lines() - 1);
for (int l = source.fromLine; l <= toLine; l++ )
if (doc->line(l).getCookie(QDocumentLine::PICTURE_COOKIE).isValid()) {
doc->line(l).removeCookie(QDocumentLine::PICTURE_COOKIE);
doc->line(l).removeCookie(QDocumentLine::PICTURE_COOKIE_DRAWING_POS);
doc->line(l).setFlag(QDocumentLine::LayoutDirty);
if (l != toLine) //must not adjust line toLine here, or will recalculate the document height without preview and scroll away if the preview is very height
doc->adjustWidth(l);
}
QPixmap img;
if(image.isNull()){
img.load(imageFile);
}else{
img=QPixmap::fromImage(image);
}
doc->line(toLine).setCookie(QDocumentLine::PICTURE_COOKIE, QVariant::fromValue<QPixmap>(img));
doc->line(toLine).setFlag(QDocumentLine::LayoutDirty);
doc->adjustWidth(toLine);
}
}
void Texmaker::clearPreview() {
QEditor* edit = currentEditor();
if (!edit) return;
int startLine = 0;
int endLine = 0;
QAction *act = qobject_cast<QAction *>(sender());
if (act && act->data().isValid()) {
// inline preview context menu supplies the calling point in doc coordinates as data
startLine = edit->document()->indexOf(edit->lineAtPosition(act->data().toPoint()));
// slight performance penalty for use of lineNumber(), which is not stictly necessary because
// we convert it back to a QDocumentLine, but easier to handle together with the other cases
endLine = startLine;
act->setData(QVariant());
} else if (edit->cursor().hasSelection()) {
startLine = edit->cursor().selectionStart().lineNumber();
endLine = edit->cursor().selectionEnd().lineNumber();
} else {
startLine = edit->cursor().lineNumber();
endLine = startLine;
}
for (int i=startLine; i<=endLine; i++){
edit->document()->line(i).removeCookie(QDocumentLine::PICTURE_COOKIE);
edit->document()->line(i).removeCookie(QDocumentLine::PICTURE_COOKIE_DRAWING_POS);
edit->document()->adjustWidth(i);
for (int j=currentEditorView()->autoPreviewCursor.size()-1;j>=0;j--)
if (currentEditorView()->autoPreviewCursor[j].selectionStart().lineNumber() <= i &&
currentEditorView()->autoPreviewCursor[j].selectionEnd().lineNumber() >= i){
// remove mark
int sid = edit->document()->getFormatId("previewSelection");
if (!sid) return;
updateEmphasizedRegion(currentEditorView()->autoPreviewCursor[j],-sid);
currentEditorView()->autoPreviewCursor.removeAt(j);
}
}
}
void Texmaker::showImgPreview(const QString& fname){
completerPreview=(sender()==completer); // completer needs signal as answer
QString imageName=fname;
QFileInfo fi(fname);
QString suffix;
QStringList suffixList;
suffixList<<"jpg"<<"jpeg"<<"png"<<"pdf";
if(fi.exists()){
if(!suffixList.contains(fi.suffix()))
return;
suffix=fi.suffix();
}
if(suffix.isEmpty()){
foreach(QString elem,suffixList){
imageName=fname+elem;
fi.setFile(imageName);
if(fi.exists()){
suffix=elem;
break;
}
}
}
suffixList.clear();
suffixList<<"jpg"<<"jpeg"<<"png";
if(suffixList.contains(suffix)){
QPoint p;
//if(previewEquation)
p=currentEditorView()->getHoverPosistion();
//else
// p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
QRect screen = QApplication::desktop()->screenGeometry();
QPixmap img(imageName);
int w = qMin(img.width(), configManager.editorConfig->maxImageTooltipWidth);
w = qMin(w, screen.width()-8);
QString text=QString("<img src=\""+imageName+"\" width=%1 />").arg(w);
if(completerPreview){
emit ImgPreview(text);
}else{
QToolTip::showText(p, text, 0);
LatexEditorView::hideTooltipWhenLeavingLine=currentEditorView()->editor->cursor().lineNumber();
}
}
#ifndef NO_POPPLER_PREVIEW
if(suffix=="pdf"){
//render pdf preview
PDFRenderManager *renderManager=new PDFRenderManager(this,1);
PDFRenderManager::Error error = PDFRenderManager::NoError;
QSharedPointer<Poppler::Document> document = renderManager->loadDocument(imageName, error);
if(error==PDFRenderManager::NoError){
renderManager->renderToImage(0,this,"showImgPreviewFinished",20,20,-1,-1,-1,-1,false,true);
}else{
delete renderManager;
}
}
#endif
}
void Texmaker::showImgPreviewFinished(const QPixmap& pm, int page){
if (!currentEditorView()) return;
Q_UNUSED(page);
QPoint p;
//if(previewEquation)
p=currentEditorView()->getHoverPosistion();
//else
// p=currentEditorView()->editor->mapToGlobal(currentEditorView()->editor->mapFromContents(currentEditorView()->editor->cursor().documentPosition()));
QRect screen = QApplication::desktop()->screenGeometry();
int w=pm.width();
if(w>screen.width()) w=screen.width()-2;
QString text;
#if QT_VERSION >= 0x040700
text= getImageAsText(pm,w);
#else
QString tempPath = QDir::tempPath()+QDir::separator()+"."+QDir::separator();
pm.save(tempPath+"txs_preview.png","PNG");
buildManager.addPreviewFileName(tempPath+"txs_preview.png");
text=QString("<img src=\""+tempPath+"txs_preview.png\" width=%1 />").arg(w);
#endif
if(completerPreview){
emit ImgPreview(text);
}else{
QToolTip::showText(p, text, 0);
LatexEditorView::hideTooltipWhenLeavingLine=currentEditorView()->editor->cursor().lineNumber();
}
#ifndef NO_POPPLER_PREVIEW
PDFRenderManager* renderManager = qobject_cast<PDFRenderManager*>(sender());
delete renderManager;
#endif
}
void Texmaker::showPreview(const QString& text){
LatexEditorView* edView=getEditorViewFromFileName(documents.getCompileFileName()); //todo: temporary compi
if(!edView)
edView=currentEditorView();
if (!edView) return;
int m_endingLine=edView->editor->document()->findLineContaining("\\begin{document}",0,Qt::CaseSensitive);
if (m_endingLine<0) return; // can't create header
QStringList header;
for (int l=0; l<m_endingLine; l++)
header << edView->editor->document()->line(l).text();
if(buildManager.dvi2pngMode==BuildManager::DPM_EMBEDDED_PDF){
header << "\\usepackage[active,tightpage]{preview}"
<< "\\usepackage{varwidth}"
<< "\\AtBeginDocument{\\begin{preview}\\begin{varwidth}{\\linewidth}}"
<<"\\AtEndDocument{\\end{varwidth}\\end{preview}}";
}
header << "\\pagestyle{empty}";// << "\\begin{document}";
buildManager.preview(header.join("\n"), PreviewSource(text, -1, -1, true), documents.getCompileFileName(), edView->editor->document()->codec());
}
void Texmaker::showPreview(const QDocumentCursor& previewc){
if (previewQueueOwner != currentEditorView())
previewQueue.clear();
previewQueueOwner = currentEditorView();
previewQueue.insert(previewc.lineNumber());
// mark region which is previewed, or update
int sid = previewc.document()->getFormatId("previewSelection");
if (sid)
updateEmphasizedRegion(previewc,sid);
QTimer::singleShot(qMax(40,configManager.autoPreviewDelay),this, SLOT(showPreviewQueue())); //slow down or it could create thousands of images
}
void Texmaker::showPreview(const QDocumentCursor& previewc, bool addToList){
REQUIRE(currentEditor());
REQUIRE(previewc.document() == currentEditor()->document());
QString originalText = previewc.selectedText();
if (originalText=="") return;
// get document definitions
//preliminary code ...
const LatexDocument *doc=documents.getMasterDocumentForDoc();
LatexEditorView* edView=(doc && doc->getEditorView())?doc->getEditorView():currentEditorView();
if (!edView) return;
int m_endingLine=edView->editor->document()->findLineContaining("\\begin{document}",0,Qt::CaseSensitive);
if (m_endingLine<0) return; // can't create header
QStringList header;
for (int l=0; l<m_endingLine; l++)
header << edView->editor->document()->line(l).text();
if((buildManager.dvi2pngMode==BuildManager::DPM_EMBEDDED_PDF) && configManager.previewMode != ConfigManager::PM_EMBEDDED){
header << "\\usepackage[active,tightpage]{preview}"
<< "\\usepackage{varwidth}"
<< "\\AtBeginDocument{\\begin{preview}\\begin{varwidth}{\\linewidth}}"
<<"\\AtEndDocument{\\end{varwidth}\\end{preview}}";
}
header << "\\pagestyle{empty}";// << "\\begin{document}";
PreviewSource ps(originalText, previewc.selectionStart().lineNumber(), previewc.selectionEnd().lineNumber(), false);
buildManager.preview(header.join("\n"), ps, documents.getCompileFileName(), edView->editor->document()->codec());
if (!addToList)
return;
if (configManager.autoPreview == ConfigManager::AP_PREVIOUSLY) {
QList<QDocumentCursor> & clist = currentEditorView()->autoPreviewCursor;
int sid = previewc.document()->getFormatId("previewSelection");
for (int i=clist.size()-1;i>=0;i--)
if (clist[i].anchorLineNumber() <= ps.toLine &&
clist[i].lineNumber() >= ps.fromLine){
if(sid>0)
updateEmphasizedRegion(clist[i],-sid);
clist.removeAt(i);
}
QDocumentCursor ss = previewc.selectionStart();
QDocumentCursor se = previewc.selectionEnd();
QDocumentCursor c(ss, se);
c.setAutoUpdated(true);
currentEditorView()->autoPreviewCursor.insert(0,c);
// mark region
if (sid)
updateEmphasizedRegion(c,sid);
}
}
void Texmaker::updateEmphasizedRegion(QDocumentCursor c,int sid){
QDocument *doc=c.document();
QDocumentCursor ss = c.selectionStart();
QDocumentCursor se = c.selectionEnd();
for(int i=ss.anchorLineNumber();i<=se.anchorLineNumber();i++){
int beg = i==ss.anchorLineNumber() ? ss.anchorColumnNumber() : 0;
int en = i==se.anchorLineNumber() ? se.anchorColumnNumber() : doc->line(i).length();
if(sid>0){
doc->line(i).addOverlay(QFormatRange(beg, en-beg, sid));
}else{
// remove overlay if sid <0 (removes -sid)
doc->line(i).clearOverlays(-sid);
}
}
}
void Texmaker::showPreviewQueue(){
if (previewQueueOwner != currentEditorView()) {
previewQueue.clear();
return;
}
if (configManager.autoPreview == ConfigManager::AP_NEVER) {
// remove marks
int sid=previewQueueOwner->document->getFormatId("previewSelection");
if(sid>0){
foreach(const QDocumentCursor &c,previewQueueOwner->autoPreviewCursor){
updateEmphasizedRegion(c,-sid);
}
}
previewQueueOwner->autoPreviewCursor.clear();
previewQueue.clear();
return;
}
foreach (const int line, previewQueue)
foreach (const QDocumentCursor& c, previewQueueOwner->autoPreviewCursor)
if (c.lineNumber() == line)
showPreview(c,false);
previewQueue.clear();
}
void Texmaker::editInsertRefToNextLabel(const QString &refCmd, bool backward) {
if (!currentEditorView()) return;
QDocumentCursor c = currentEditor()->cursor();
int l=c.lineNumber();
int m=currentEditorView()->editor->document()->findLineContaining("\\label",l,Qt::CaseSensitive,backward);
if(!backward && m<l) return;
if(m<0) return;
QDocumentLine dLine=currentEditor()->document()->line(m);
QString mLine=dLine.text();
QRegExp rx("\\\\label\\{(.*)\\}");
if(rx.indexIn(mLine)>-1){
currentEditor()->write(refCmd+"{"+rx.cap(1)+"}");
}
}
void Texmaker::editInsertRefToPrevLabel(const QString &refCmd) {
editInsertRefToNextLabel(refCmd, true);
}
void Texmaker::SymbolGridContextMenu(QWidget* widget, const QPoint& point) {
if (!widget->property("isSymbolGrid").toBool()) return;
if(widget==MostUsedSymbolWidget){
QMenu menu;
menu.addAction(tr("Add to favorites"),this,SLOT(symbolAddFavorite()));
menu.addAction(tr("Remove"),this,SLOT(MostUsedSymbolsTriggered()));
menu.addAction(tr("Remove all"),this,SLOT(MostUsedSymbolsTriggered()));
menu.exec(point);
} else if (widget==FavoriteSymbolWidget) {
QMenu menu;
menu.addAction(tr("Remove from favorites"),this,SLOT(symbolRemoveFavorite()));
menu.addAction(tr("Remove all favorites"),this,SLOT(symbolRemoveAllFavorites()));
menu.exec(point);
} else {
QMenu menu;
menu.addAction(tr("Add to favorites"),this,SLOT(symbolAddFavorite()));
menu.exec(point);
}
}
void Texmaker::symbolAddFavorite(){
SymbolGridWidget* grid=qobject_cast<SymbolGridWidget*>(leftPanel->currentWidget());
if (!grid) return;
QString symbol=grid->getCurrentSymbol();
if (symbol.isEmpty()) return;
if (!symbolFavorites.contains(symbol)) symbolFavorites.append(symbol);
FavoriteSymbolWidget->loadSymbols(symbolFavorites);
}
void Texmaker::symbolRemoveFavorite(){
QString symbol=FavoriteSymbolWidget->getCurrentSymbol();
if (symbol.isEmpty()) return;
symbolFavorites.removeAll(symbol);
FavoriteSymbolWidget->loadSymbols(symbolFavorites);
}
void Texmaker::symbolRemoveAllFavorites(){
symbolFavorites.clear();
FavoriteSymbolWidget->loadSymbols(symbolFavorites);
}
void Texmaker::editorTabContextMenu(const QPoint &point) {
if (point.isNull()) return;
QMenu *documentsMenu = getManagedMenu("main/view/documents");
documentsMenu->exec(EditorTabs->mapToGlobal(point));
}
void Texmaker::MostUsedSymbolsTriggered(bool direct){
QAction *action = 0;
QTableWidgetItem *item=0;
if(!direct){
action = qobject_cast<QAction *>(sender());
item=MostUsedSymbolWidget->currentItem();
}
if(direct || action->text()==tr("Remove")){
if(!direct){
if(item->data(Qt::UserRole+3).isValid()){
QTableWidgetItem *elem=item->data(Qt::UserRole+3).value<QTableWidgetItem*>();
elem->setData(Qt::UserRole+1,QVariant());
}
symbolMostused.removeAll(item);
delete item;
}else{
symbolMostused.clear();
foreach(QTableWidgetItem* elem,MostUsedSymbolWidget->findItems("*",Qt::MatchWildcard)){
if(!elem) continue;
int cnt=elem->data(Qt::UserRole).toInt();
if(symbolMostused.isEmpty()){
symbolMostused.append(elem);
}else {
int index=0;
while(index<symbolMostused.size()&&symbolMostused[index]->data(Qt::UserRole).toInt()>cnt){
index++;
}
symbolMostused.insert(index,elem);
}
}
}
}else{
for(int i=0;symbolMostused.count();i++){
QTableWidgetItem* item=symbolMostused.at(i);
QTableWidgetItem *elem=item->data(Qt::UserRole+3).value<QTableWidgetItem*>();
elem->setData(Qt::UserRole+1,QVariant());
delete item;
symbolMostused.clear();
}
}
// Update Most Used Symbols Widget
MostUsedSymbolWidget->SetUserPage(symbolMostused);
}
void Texmaker::editFindGlobal(){
if(!currentEditor()) return;
QEditor *e=currentEditor();
if(!findDlg)
findDlg=new findGlobalDialog(this);
if(e->cursor().hasSelection()){
findDlg->setSearchWord(e->cursor().selectedText());
}
if(findDlg->exec()){
QList<LatexDocument *> docs;
LatexDocument *doc = currentEditorView()->document;
switch (findDlg->getSearchScope()) {
case 1:
docs << doc;
break;
case 0:
docs << documents.getDocuments();
break;
case 2:
docs << doc->getListOfDocs();
break;
default:
break;
}
//updateFindGlobal(docs,findDlg->getSearchWord(),findDlg->getReplaceWord(),findDlg->isCase(),findDlg->isWords(),findDlg->isRegExp());
outputView->setSearchEditors(docs);
}
}
void Texmaker::updateFindGlobal(int scope){
// scope: 0 current doc, 1 all docs , 2 project
outputView->clearSearch();
LatexEditorView *edView = currentEditorView();
if(!edView)
return;
QList<LatexDocument *> docs;
LatexDocument *doc = currentEditorView()->document;
switch (scope) {
case 0:
docs << doc;
break;
case 1:
docs << documents.getDocuments();
break;
case 2:
docs << doc->getListOfDocs();
break;
default:
break;
}
bool isWord=edView->getSearchIsCase();
bool isCase=edView->getSearchIsWords();
bool isReg=edView->getSearchIsRegExp();
bool linesShown=false;
outputView->setSearchExpression(edView->getSearchText(),edView->getReplaceText(),isCase,isWord,isReg);
foreach(LatexDocument *doc,docs){
if (!doc) continue;
QList<QDocumentLineHandle *> lines;
for(int l=0;l<doc->lineCount();l++){
l=doc->findLineRegExp(edView->getSearchText(),l,isCase ? Qt::CaseSensitive : Qt::CaseInsensitive,isWord,isReg);
if(l>-1) lines << doc->line(l).handle();
if(l==-1) break;
}
if(!lines.isEmpty()){ // don't add empty searches
if (doc->getFileName().isEmpty() && doc->getTemporaryFileName().isEmpty())
doc->setTemporaryFileName(buildManager.createTemporaryFileName());
outputView->addSearch(lines, doc);
outputView->showPage(outputView->SEARCH_RESULT_PAGE);
}
}
if(!linesShown){
outputView->showPage(outputView->SEARCH_RESULT_PAGE);
}
}
// show current cursor position in structure view
void Texmaker::cursorPositionChanged(){
if (!currentEditorView()) return;
int i=currentEditor()->cursor().lineNumber();
// search line in structure
if (currentLine==i) return;
currentLine=i;
LatexDocumentsModel *model=qobject_cast<LatexDocumentsModel*>(structureTreeView->model());
if (!model) return; //shouldn't happen
StructureEntry *newSection=currentEditorView()->document->findSectionForLine(currentLine);
model->setHighlightedEntry(newSection);
if(!mDontScrollToItem)
structureTreeView->scrollTo(model->highlightedEntry());
syncPDFViewer(currentEditor()->cursor(), false);
}
void Texmaker::syncPDFViewer(QDocumentCursor cur, bool inForeground) {
#ifndef NO_POPPLER_PREVIEW
if(PDFDocument::documentList().isEmpty() && inForeground) {
// open new viewer, if none exists
QAction *viewAct = getManagedAction("main/tools/view");
if (viewAct) viewAct->trigger();
return;
}
foreach (PDFDocument* viewer, PDFDocument::documentList()) {
if (inForeground || viewer->followCursor()) {
int lineNumber = cur.isValid() ? cur.lineNumber() : currentLine;
LatexDocument *doc = qobject_cast<LatexDocument *>(cur.document());
if (doc) {
int originalLineNumber = doc->lineToLineSnapshotLineNumber(cur.line());
if (originalLineNumber >= 0) lineNumber = originalLineNumber;
}
viewer->syncFromSource(getCurrentFileName(), lineNumber, false);
}
if (inForeground) {
viewer->raise();
}
}
#endif
}
void Texmaker::fileCheckin(QString filename){
if (!currentEditorView()) return;
QString fn=filename.isEmpty() ? currentEditor()->fileName() : filename;
UniversalInputDialog dialog;
QString text;
dialog.addTextEdit(&text, tr("commit comment:"));
bool wholeDirectory;
dialog.addVariable(&wholeDirectory,tr("check in whole directory ?"));
if (dialog.exec()==QDialog::Accepted){
fileSave(true);
if(wholeDirectory){
fn=QFileInfo(fn).absolutePath();
}
//checkin(fn,text);
if(svnadd(fn)){
checkin(fn,text,configManager.svnKeywordSubstitution);
} else {
//create simple repository
svncreateRep(fn);
svnadd(fn);
checkin(fn,text,configManager.svnKeywordSubstitution);
}
}
}
void Texmaker::fileLockPdf(QString filename){
if (!currentEditorView()) return;
QString finame=filename;
if(finame.isEmpty())
finame=documents.getTemporaryCompileFileName();
QFileInfo fi(finame);
QString basename=fi.baseName();
QString path=fi.path();
fi.setFile(path+"/"+basename+".pdf");
if(!fi.isWritable()){
svnLock(fi.filePath());
}
}
void Texmaker::fileCheckinPdf(QString filename){
if (!currentEditorView()) return;
QString finame=filename;
if(finame.isEmpty())
finame=documents.getTemporaryCompileFileName();
QFileInfo fi(finame);
QString basename=fi.baseName();
QString path=fi.path();
QString fn=path+"/"+basename+".pdf";
SVNSTATUS status=svnStatus(fn);
if(status==SVN_CheckedIn) return;
if(status==SVN_Unmanaged)
svnadd(fn);
fileCheckin(fn);
}
void Texmaker::fileUpdate(QString filename){
if (!currentEditorView()) return;
QString fn=filename.isEmpty() ? currentEditor()->fileName() : filename;
if(fn.isEmpty()) return;
QString cmd=BuildManager::CMD_SVN + " up --non-interactive \""+fn+"\"";
statusLabelProcess->setText(QString(" svn update "));
QString buffer;
runCommand(cmd,&buffer);
outputView->insertMessageLine(buffer);
}
void Texmaker::fileUpdateCWD(QString filename){
if (!currentEditorView()) return;
QString fn=filename.isEmpty() ? currentEditor()->fileName() : filename;
if(fn.isEmpty()) return;
QString cmd=BuildManager::CMD_SVN;
fn=QFileInfo(fn).path();
cmd+=" up --non-interactive \""+fn+"\"";
statusLabelProcess->setText(QString(" svn update "));
QString buffer;
runCommand(cmd, &buffer);
outputView->insertMessageLine(buffer);
}
void Texmaker::checkin(QString fn, QString text, bool blocking){
Q_UNUSED(blocking)
QString cmd=BuildManager::CMD_SVN;
cmd+=" ci -m \""+text+"\" \""+fn+("\"");
statusLabelProcess->setText(QString(" svn check in "));
//TODO: blocking
QString buffer;
runCommand(cmd,&buffer);
LatexEditorView *edView=getEditorViewFromFileName(fn);
if(edView)
edView->editor->setProperty("undoRevision",0);
}
bool Texmaker::svnadd(QString fn,int stage){
QString path=QFileInfo(fn).absolutePath();
if(!QFile::exists(path+"/.svn")){
if(stage<configManager.svnSearchPathDepth){
if(stage>0){
QDir dr(path);
dr.cdUp();
path=dr.absolutePath();
}
if(svnadd(path,stage+1)){
checkin(path);
} else
return false;
} else {
return false;
}
}
QString cmd=BuildManager::CMD_SVN;
cmd+=" add \""+fn+("\"");
statusLabelProcess->setText(QString(" svn add "));
QString buffer;
runCommand(cmd, &buffer);
return true;
}
void Texmaker::svnLock(QString fn){
QString cmd=BuildManager::CMD_SVN;
cmd+=" lock \""+fn+("\"");
statusLabelProcess->setText(QString(" svn lock "));
QString buffer;
runCommand(cmd, &buffer);
}
void Texmaker::svncreateRep(QString fn){
QString cmd=BuildManager::CMD_SVN;
QString admin=BuildManager::CMD_SVNADMIN;
QString path=QFileInfo(fn).absolutePath();
admin+=" create \""+path+"/repo\"";
statusLabelProcess->setText(QString(" svn create repo "));
QString buffer;
runCommand(admin,&buffer);
QString scmd=cmd+" mkdir \"file:///"+path+"/repo/trunk\" -m\"txs auto generate\"";
runCommand(scmd,&buffer);
scmd=cmd+" mkdir \"file:///"+path+"/repo/branches\" -m\"txs auto generate\"";
runCommand(scmd,&buffer);
scmd=cmd+" mkdir \"file:///"+path+"/repo/tags\" -m\"txs auto generate\"";
runCommand(scmd,&buffer);
statusLabelProcess->setText(QString(" svn checkout repo"));
cmd+=" co \"file:///"+path+"/repo/trunk\" \""+path+"\"";
runCommand(cmd,&buffer);
}
void Texmaker::svnUndo(bool redo){
QString cmd_svn=BuildManager::CMD_SVN;
QString fn=currentEditor()->fileName();
// get revisions of current file
QString cmd=cmd_svn+" log \""+fn+"\"";
QString buffer;
runCommand(cmd, &buffer);
QStringList revisions=buffer.split("\n",QString::SkipEmptyParts);
buffer.clear();
QMutableStringListIterator i(revisions);
bool keep=false;
QString elem;
while(i.hasNext()){
elem=i.next();
if(!keep) i.remove();
keep=elem.contains(QRegExp("-{60,}"));
}
QVariant zw=currentEditor()->property("undoRevision");
int undoRevision=zw.canConvert<int>()?zw.toInt():0;
int l=revisions.size();
if(undoRevision>=l-1) return;
if(!redo) undoRevision++;
if(redo) changeToRevision(revisions.at(undoRevision-1),revisions.at(undoRevision));
else changeToRevision(revisions.at(undoRevision),revisions.at(undoRevision-1));
currentEditor()->document()->clearUndo();
if(redo) undoRevision--;
currentEditor()->setProperty("undoRevision",undoRevision);
}
void Texmaker::svnPatch(QEditor *ed,QString diff){
QStringList lines;
//for(int i=0;i<diff.length();i++)
// qDebug()<<diff[i];
if(diff.contains("\r\n")){
lines=diff.split("\r\n");
}else{
if(diff.contains("\n")){
lines=diff.split("\n");
}else{
lines=diff.split("\r");
}
}
for(int i=0;i<lines.length();i++){
//workaround for svn bug
// at times it shows text@@ pos insted of text \n @@ ...
if(lines[i].contains("@@")){
int p=lines[i].indexOf("@@");
lines[i]=lines[i].mid(p);
}
}
for(int i=0;i<3;i++) lines.removeFirst();
if(!lines.first().contains("@@")){
lines.removeFirst();
}
QRegExp rx("@@ -(\\d+),(\\d+)\\s*\\+(\\d+),(\\d+)");
int cur_line;
bool atDocEnd=false;
QDocumentCursor c=ed->cursor();
foreach(const QString& elem,lines){
QChar ch=' ';
if(!elem.isEmpty()){
ch=elem.at(0);
}
if(ch=='@'){
if(rx.indexIn(elem)>-1){
cur_line=rx.cap(3).toInt();
c.moveTo(cur_line-1,0);
}else{
qDebug()<<"Bug";
}
}else{
if(ch=='-'){
atDocEnd=(c.lineNumber()==ed->document()->lineCount()-1);
if(c.line().text()!=elem.mid(1))
qDebug()<<"del:"<<c.line().text()<<elem;
c.eraseLine();
if(atDocEnd) c.deletePreviousChar();
}else{
if(ch=='+'){
atDocEnd=(c.lineNumber()==ed->document()->lineCount()-1);
if(atDocEnd){
c.movePosition(1,QDocumentCursor::EndOfLine,QDocumentCursor::MoveAnchor);
c.insertLine();
}
c.insertText(elem.mid(1));
// if line contains \r, no further line break needed
if(!atDocEnd){
c.insertText("\n");
}
} else {
atDocEnd=(c.lineNumber()==ed->document()->lineCount()-1);
int limit=5;
if(!atDocEnd){
while((c.line().text()!=elem.mid(1))&&(limit>0)&&(c.lineNumber()<ed->document()->lineCount()-1)){
qDebug()<<c.line().text()<<c.lineNumber()<<"<>"<<elem.mid(1);
c.movePosition(1,QDocumentCursor::NextLine,QDocumentCursor::MoveAnchor);
c.movePosition(1,QDocumentCursor::StartOfLine,QDocumentCursor::MoveAnchor);
limit--;
if(limit==0){
qDebug()<<"failed";
}
}
atDocEnd=(c.lineNumber()==ed->document()->lineCount()-1);
if(!atDocEnd){
c.movePosition(1,QDocumentCursor::NextLine,QDocumentCursor::MoveAnchor);
c.movePosition(1,QDocumentCursor::StartOfLine,QDocumentCursor::MoveAnchor);
}
}
}
}
}
}
}
void Texmaker::showOldRevisions(){
// check if a dialog is already open
if(svndlg) return;
//needs to save first if modified
if (!currentEditor())
return;
if (currentEditor()->fileName()=="" || !currentEditor()->fileInfo().exists())
return;
if(currentEditor()->isContentModified()){
removeDiffMarkers();// clean document from diff markers first
currentEditor()->save();
//currentEditorView()->editor->setModified(false);
MarkCurrentFileAsRecent();
checkin(currentEditor()->fileName(),"txs auto checkin",true);
}
UpdateCaption();
QStringList log=svnLog();
if(log.size()<1) return;
svndlg=new QDialog(this);
QVBoxLayout *lay=new QVBoxLayout(svndlg);
QLabel *label=new QLabel(tr("Attention: dialog is automatically closed if the text is manually edited!"),svndlg);
lay->addWidget(label);
cmbLog=new QComboBox(svndlg);
cmbLog->insertItems(0,log);
lay->addWidget(cmbLog);
connect(svndlg,SIGNAL(finished(int)),this,SLOT(svnDialogClosed()));
connect(cmbLog,SIGNAL(currentIndexChanged(QString)),this,SLOT(changeToRevision(QString)));
connect(currentEditor(),SIGNAL(textEdited(QKeyEvent *)),svndlg,SLOT(close()));
currentEditor()->setProperty("Revision",log.first());
svndlg->setAttribute(Qt::WA_DeleteOnClose,true);
svndlg->show();
}
void Texmaker::svnDialogClosed(){
if(cmbLog->currentIndex()==0) currentEditor()->document()->setClean();
svndlg=0;
}
SVNSTATUS Texmaker::svnStatus(QString filename){
QString cmd=BuildManager::CMD_SVN;
cmd+=" st \""+filename+("\"");
statusLabelProcess->setText(QString(" svn status "));
QString buffer;
runCommand(cmd, &buffer);
if(buffer.isEmpty()) return SVN_CheckedIn;
if(buffer.startsWith("?")) return SVN_Unmanaged;
if(buffer.startsWith("M")) return SVN_Modified;
if(buffer.startsWith("C")) return SVN_InConflict;
if(buffer.startsWith("L")) return SVN_Locked;
return SVN_Unknown;
}
void Texmaker::changeToRevision(QString rev,QString old_rev){
QString cmd_svn=BuildManager::CMD_SVN;
QString fn="\""+currentEditor()->fileName()+"\"";
// get diff
QRegExp rx("^[r](\\d+) \\|");
QString old_revision;
if(old_rev.isEmpty()){
disconnect(currentEditor(),SIGNAL(contentModified(bool)),svndlg,SLOT(close()));
QVariant zw=currentEditor()->property("Revision");
Q_ASSERT(zw.isValid());
old_revision= zw.toString();
}else{
old_revision=old_rev;
}
if(rx.indexIn(old_revision)>-1){
old_revision=rx.cap(1);
} else return;
QString new_revision=rev;
if(rx.indexIn(new_revision)>-1){
new_revision=rx.cap(1);
} else return;
QString cmd=cmd_svn+" diff -r "+old_revision+":"+new_revision+" "+fn;
QString buffer;
runCommand(cmd, &buffer, currentEditor()->getFileCodec());
// patch
svnPatch(currentEditor(),buffer);
currentEditor()->setProperty("Revision",rev);
}
QStringList Texmaker::svnLog(){
QString cmd_svn=BuildManager::CMD_SVN;
QString fn="\""+currentEditor()->fileName()+"\"";
// get revisions of current file
QString cmd=cmd_svn+" log "+fn;
QString buffer;
runCommand(cmd, &buffer);
QStringList revisions=buffer.split("\n",QString::SkipEmptyParts);
buffer.clear();
QMutableStringListIterator i(revisions);
bool keep=false;
QString elem;
while(i.hasNext()){
elem=i.next();
if(!keep) i.remove();
keep=elem.contains(QRegExp("-{60,}"));
}
return revisions;
}
bool Texmaker::generateMirror(bool setCur){
if (!currentEditorView()) return false;
QDocumentCursor cursor = currentEditorView()->editor->cursor();
QDocumentCursor oldCursor = cursor;
QString line=cursor.line().text();
QString command, value;
LatexParser::ContextType result=latexParser.findContext(line, cursor.columnNumber(), command, value);
if(result==LatexParser::Environment){
if ((command=="\\begin" || command=="\\end")&& !value.isEmpty()){
//int l=cursor.lineNumber();
if (currentEditor()->currentPlaceHolder()!=-1 &&
currentEditor()->getPlaceHolder(currentEditor()->currentPlaceHolder()).cursor.isWithinSelection(cursor))
currentEditor()->removePlaceHolder(currentEditor()->currentPlaceHolder()); //remove currentplaceholder to prevent nesting
//move cursor to env name
int pos = line.lastIndexOf(command, cursor.columnNumber()) + command.length() + 1;
cursor.selectColumns(pos, pos+value.length());
if (cursor.atLineEnd()||cursor.nextChar()!='}'||cursor.selectedText() != value) // closing brace is missing or wrong env
return false;
//currentEditorView()->editor->setCursor(cursor);
LatexDocument* doc=currentEditorView()->document;
PlaceHolder ph;
ph.cursor=cursor;
ph.autoRemove=true;
ph.autoRemoveIfLeft=true;
// remove curly brakets as well
QString searchWord="\\end{"+value+"}";
QString inhibitor="\\begin{"+value+"}";
bool backward=(command=="\\end");
int step=1;
if(backward) {
qSwap(searchWord,inhibitor);
step=-1;
}
int ln=cursor.lineNumber();
int col=cursor.columnNumber();
bool finished=false;
int nested=0;
int colSearch=0;
int colInhibit=0;
if(step<0)
line=line.left(col);
while(!finished){
if(step>0){
//forward search
colSearch=line.indexOf(searchWord,col);
colInhibit=line.indexOf(inhibitor,col);
}else{
//backward search
colSearch=line.lastIndexOf(searchWord);
colInhibit=line.lastIndexOf(inhibitor);
}
if(colSearch<0 && colInhibit<0){
ln+=step;
if(doc->lines()<=ln || ln<0)
break;
line=doc->line(ln).text();
col=0;
}
if(colSearch>=0 && colInhibit>=0){
if(colSearch*step<colInhibit*step){
if(nested==0){
finished=true;
}
nested--;
col=colSearch+1;
if(step<0)
line=line.left(colSearch);
}else{
if(step>0){
col=colInhibit+1;
}else {
line=line.left(colInhibit);
}
nested++;
}
}else{
if(colSearch>=0){
nested--;
if(nested<0)
finished=true;
if(step>0){
col=colSearch+1;
}else{
line=line.left(colSearch);
}
}
if(colInhibit>=0){
nested++;
if(step>0){
col=colInhibit+1;
}else{
line=line.left(colInhibit);
}
}
}
}
if(finished){
line=doc->line(ln).text();
int start=colSearch;
int offset=searchWord.indexOf("{");
ph.mirrors << currentEditor()->document()->cursor(ln,start+offset+1,ln,start+searchWord.length()-1);
}
/*int endLine=doc->findLineContaining(searchWord,startLine+step,Qt::CaseSensitive,backward);
int inhibitLine=doc->findLineContaining(inhibitor,startLine+step,Qt::CaseSensitive,backward); // not perfect (same line end/start ...)
while (inhibitLine>0 && endLine>0 && inhibitLine*step<endLine*step) {
endLine=doc->findLineContaining(searchWord,endLine+step,Qt::CaseSensitive,backward); // not perfect (same line end/start ...)
inhibitLine=doc->findLineContaining(inhibitor,inhibitLine+step,Qt::CaseSensitive,backward);
}
if(endLine>-1){
line=doc->line(endLine).text();
int start=line.indexOf(searchWord);
int offset=searchWord.indexOf("{");
ph.mirrors << currentEditor()->document()->cursor(endLine,start+offset+1,endLine,start+searchWord.length()-1);
}*/
currentEditor()->addPlaceHolder(ph);
currentEditor()->setPlaceHolder(currentEditor()->placeHolderCount()-1);
if(setCur)
currentEditorView()->editor->setCursor(oldCursor);
return true;
}
}
return false;
}
void Texmaker::generateBracketInverterMirror(){
if (!currentEditor()) return;
REQUIRE(currentEditor()->document() && currentEditor()->document()->languageDefinition());
QDocumentCursor orig, to;
currentEditor()->cursor().getMatchingPair(orig, to, false);
PlaceHolder ph;
ph.cursor = orig.selectionStart();
ph.mirrors << to.selectionStart();
ph.length = orig.selectedText().length();
ph.affector = BracketInvertAffector::instance();
currentEditor()->addPlaceHolder(ph);
currentEditor()->setPlaceHolder(currentEditor()->placeHolderCount()-1);
}
void Texmaker::jumpToBracket(){
if (!currentEditor()) return;
REQUIRE(sender() && currentEditor()->document() && currentEditor()->document()->languageDefinition());
QDocumentCursor orig, to;
const QDocumentCursor se = currentEditor()->cursor().selectionEnd();
se.getMatchingPair(orig, to, false);
if (orig.selectionEnd() == se) currentEditor()->setCursor(to.selectionStart());
else currentEditor()->setCursor(to.selectionEnd());
}
void Texmaker::selectBracket(){
if (!currentEditor()) return;
REQUIRE(sender() && currentEditor()->document());
if (!currentEditor()->document()->languageDefinition()) return;
QDocumentCursor orig, to;
currentEditor()->cursor().getMatchingPair(orig, to, !sender()->property("minimal").toBool());
if (!orig.isValid() && !to.isValid()) return;
if (sender()->property("line").toBool()) {
if (to < orig) to.setColumnNumber(0);
else to.setColumnNumber(to.line().length());
}
QDocumentCursor::sort(orig, to);
if (sender()->property("minimal").toBool()) {
if (orig.hasSelection()) orig = orig.selectionEnd();
if (to.hasSelection()) to = to.selectionStart();
} else {
if (orig.hasSelection()) orig = orig.selectionStart();
if (to.hasSelection()) to = to.selectionEnd();
}
if (sender()->property("backslash").toBool()) {
int backslash = orig.line().text().lastIndexOf('\\', orig.columnNumber());
if (backslash >= 0) orig.setColumnNumber(backslash);
}
currentEditor()->setCursor(currentEditor()->document()->cursor(orig.lineNumber(), orig.columnNumber(), to.lineNumber(), to.columnNumber()));
}
void Texmaker::findMissingBracket(){
if (!currentEditor()) return;
REQUIRE(currentEditor()->document() && currentEditor()->document()->languageDefinition());
QDocumentCursor c = currentEditor()->languageDefinition()->getNextMismatch(currentEditor()->cursor());
if (c.isValid()) currentEditor()->setCursor(c);
}
void Texmaker::openExternalFile(const QString& name,const QString& defaultExt,LatexDocument *doc){
if (!doc) {
if (!currentEditor()) return;
doc=qobject_cast<LatexDocument*>(currentEditor()->document());
}
if (!doc) return;
QStringList curPaths;
if(documents.masterDocument)
curPaths << ensureTrailingDirSeparator(documents.masterDocument->getFileInfo().absolutePath());
if(doc->getMasterDocument())
curPaths << ensureTrailingDirSeparator(doc->getTopMasterDocument()->getFileInfo().absolutePath());
curPaths << ensureTrailingDirSeparator(doc->getFileInfo().absolutePath());
bool loaded = false;
for(int i=0;i<curPaths.count();i++){
const QString& curPath=curPaths.value(i);
if ((loaded=load(getAbsoluteFilePath(curPath+name,defaultExt))))
break;
if ((loaded=load(getAbsoluteFilePath(curPath+name,""))))
break;
if ((loaded=load(getAbsoluteFilePath(name,defaultExt))))
break;
}
if(!loaded) {
Q_ASSERT(curPaths.count()>0);
QFileInfo fi(getAbsoluteFilePath(curPaths[0]+name, defaultExt));
if (txsConfirmWarning(tr("The file \"%1\" does not exist.\nDo you want to create it?").arg(fi.fileName()))) {
int lineNr=-1;
if(currentEditor()){
lineNr=currentEditor()->cursor().lineNumber();
}
if (!fi.absoluteDir().exists())
fi.absoluteDir().mkpath(".");
fileNew(fi.absoluteFilePath());
doc->patchStructure(lineNr,1);
}
}
}
void Texmaker::cursorHovered(){
if(completer->isVisible()) return;
generateMirror(true);
}
void Texmaker::saveProfile(){
QString currentDir=configManager.configBaseDir;
QString fname = QFileDialog::getSaveFileName(this,tr("Save Profile"),currentDir,tr("TXS Profile","filter")+"(*.txsprofile);;"+tr("All files")+" (*)");
QFileInfo info(fname);
if(info.suffix().isEmpty())
fname+=".txsprofile";
SaveSettings(fname);
}
void Texmaker::loadProfile(){
QString currentDir=configManager.configBaseDir;
QString fname = QFileDialog::getOpenFileName(this,tr("Load Profile"),currentDir,tr("TXS Profile","filter")+"(*.txsprofile *.tmxprofile);;"+tr("All files")+" (*)"); //*.tmxprofile for compatibility - may be removed later
if (fname.isNull())
return;
if(QFileInfo(fname).isReadable()){
bool macro=false;
bool userCommand=false;
SaveSettings();
QSettings *profile=new QSettings(fname,QSettings::IniFormat);
QSettings *config=new QSettings(QSettings::IniFormat,QSettings::UserScope,"texstudio","texstudio");
if(profile && config){
QStringList keys = profile->allKeys();
foreach(const QString& key,keys){
//special treatment for macros/usercommands (list maybe shorter than before)
if(key.startsWith("texmaker/Macros")){
if(!macro){ //remove old values
config->beginGroup("texmaker");
config->remove("Macros");
config->endGroup();
configManager.completerConfig->userMacros.clear();
}
QStringList ls = profile->value(key).toStringList();
if (!ls.isEmpty()){
configManager.completerConfig->userMacros.append(Macro(ls));
macro=true;
}
continue;
}
if((key=="texmaker/Tools/User Order")||(key=="texmaker/Tools/Display Names")){
// logic assumes that the user command name is exclusive
QStringList order=config->value(key).toStringList()<<profile->value(key).toStringList();
config->setValue(key,order);
userCommand=true;
continue;
}
config->setValue(key,profile->value(key));
}
}
delete profile;
delete config;
ReadSettings(true);
if(macro)
updateUserMacros();
if(userCommand)
updateUserToolMenu();
} else txsWarning(tr("Failed to read profile file %1.").arg(fname));
}
void Texmaker::addRowCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
int cols=LatexTables::getNumberOfColumns(cur);
if(cols<1) return;
LatexTables::addRow(cur,cols);
}
void Texmaker::addColumnCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
int col=LatexTables::getColumn(cur)+1;
if(col<1) return;
if(col==1 &&cur.atLineStart()) col=0;
LatexTables::addColumn(currentEditorView()->document,currentEditorView()->editor->cursor().lineNumber(),col);
}
void Texmaker::removeColumnCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
// check if cursor has selection
int numberOfColumns=1;
int col=LatexTables::getColumn(cur);
if(cur.hasSelection()){
// if selection span within one row, romove all touched columns
QDocumentCursor c2(cur.document(),cur.anchorLineNumber(),cur.anchorColumnNumber());
if(!LatexTables::inTableEnv(c2)) return;
QString res=cur.selectedText();
if(res.contains("\\\\")) return;
int col2=LatexTables::getColumn(c2);
numberOfColumns=abs(col-col2)+1;
if(col2<col) col=col2;
}
int ln=cur.lineNumber();
for(int i=0;i<numberOfColumns;i++){
LatexTables::removeColumn(currentEditorView()->document,ln,col,0);
}
}
void Texmaker::removeRowCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
LatexTables::removeRow(cur);
}
void Texmaker::cutColumnCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
// check if cursor has selection
int numberOfColumns=1;
int col=LatexTables::getColumn(cur);
if(cur.hasSelection()){
// if selection span within one row, romove all touched columns
QDocumentCursor c2(cur.document(),cur.anchorLineNumber(),cur.anchorColumnNumber());
if(!LatexTables::inTableEnv(c2)) return;
QString res=cur.selectedText();
if(res.contains("\\\\")) return;
int col2=LatexTables::getColumn(c2);
numberOfColumns=abs(col-col2)+1;
if(col2<col) col=col2;
}
int ln=cur.lineNumber();
m_columnCutBuffer.clear();
QStringList lst;
for(int i=0;i<numberOfColumns;i++){
lst.clear();
LatexTables::removeColumn(currentEditorView()->document,ln,col,&lst);
if(m_columnCutBuffer.isEmpty()){
m_columnCutBuffer=lst;
}else{
for(int i=0;i<m_columnCutBuffer.size();i++){
QString add="&";
if(!lst.isEmpty()) add+=lst.takeFirst();
m_columnCutBuffer[i]+=add;
}
}
}
}
void Texmaker::pasteColumnCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
int col=LatexTables::getColumn(cur)+1;
if(col==1 &&cur.atLineStart()) col=0;
LatexTables::addColumn(currentEditorView()->document,currentEditorView()->editor->cursor().lineNumber(),col,&m_columnCutBuffer);
}
void Texmaker::addHLineCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
LatexTables::addHLine(cur);
}
void Texmaker::remHLineCB(){
if (!currentEditorView()) return;
QDocumentCursor cur=currentEditorView()->editor->cursor();
if(!LatexTables::inTableEnv(cur)) return;
LatexTables::addHLine(cur,-1,true);
}
void Texmaker::findWordRepetions(){
if (!currentEditorView()) return;
if(configManager.editorConfig && !configManager.editorConfig->inlineSpellChecking){
QMessageBox::information(this,tr("Problem"),tr("Finding word repetitions only works with activated online spell checking !"),QMessageBox::Ok);
return;
}
QDialog *dlg=new QDialog(this);
dlg->setAttribute(Qt::WA_DeleteOnClose,true);
dlg->setWindowTitle(tr("Find Word Repetitions"));
QGridLayout *layout = new QGridLayout;
layout->setColumnStretch(1, 1);
layout->setColumnStretch(0, 1);
QComboBox *cb = new QComboBox(dlg);
cb->addItems(QStringList() << "spellingMistake" << "wordRepetition" << "wordRepetitionLongRange"<< "badWord" << "grammarMistake" << "grammarMistakeSpecial1" << "grammarMistakeSpecial2" << "grammarMistakeSpecial3" << "grammarMistakeSpecial4");
cb->setCurrentIndex(1);
cb->setObjectName("kind");
cb->setEditable(true); //so people can search for other things as well
QPushButton *btNext= new QPushButton(tr("&Find Next"), dlg);
btNext->setObjectName("next");
QPushButton *btPrev= new QPushButton(tr("&Find Previous"), dlg);
btPrev->setObjectName("prev");
QPushButton *btClose= new QPushButton(tr("&Close"), dlg);
btClose->setObjectName("close");
layout->addWidget(cb,0,0);
layout->addWidget(btNext,0,1);
layout->addWidget(btPrev,0,2);
layout->addWidget(btClose,0,3);
dlg->setLayout(layout);
connect(btNext,SIGNAL(clicked()),this,SLOT(findNextWordRepetion()));
connect(btPrev,SIGNAL(clicked()),this,SLOT(findNextWordRepetion()));
connect(btClose,SIGNAL(clicked()),dlg,SLOT(close()));
dlg->setModal(false);
dlg->show();
dlg->raise();
}
void Texmaker::findNextWordRepetion(){
QPushButton *mButton = qobject_cast<QPushButton *>(sender());
bool backward=mButton->objectName()=="prev";
if (!currentEditorView()) return;
typedef QFormatRange (QDocumentLine::*OverlaySearch) (int, int, int);
OverlaySearch overlaySearch = backward?&QDocumentLine::getLastOverlayBetween:&QDocumentLine::getFirstOverlayBetween;
QComboBox* kind = mButton->parent()->findChild<QComboBox*>("kind");
int overlayType = currentEditorView()->document->getFormatId(kind ? kind->currentText() : "wordRepetition");
QDocumentCursor cur = currentEditor()->cursor();
if (cur.hasSelection()){
if (backward) cur = cur.selectionStart();
else cur = cur.selectionEnd();
}
int lineNr = cur.lineNumber();
QDocumentLine line = cur.line();
int fx = backward?0:(cur.endColumnNumber()+1), tx = backward?cur.startColumnNumber()-1:line.length();
while (line.isValid()){
if (line.hasOverlay(overlayType)){
QFormatRange range = (line.*overlaySearch)(fx, tx, overlayType);
if (range.length > 0){
currentEditor()->setCursor(currentEditor()->document()->cursor(lineNr,range.offset,lineNr,range.offset+range.length));
return;
}
}
if(backward)
lineNr--;
else
lineNr++;
line = currentEditor()->document()->line(lineNr);
fx = 0;
tx = line.length();
}
txsInformation(backward ? tr("Reached beginning of text.") : tr("Reached end of text."));
}
void Texmaker::latexModelViewMode(){
bool mode=documents.model->getSingleDocMode();
documents.model->setSingleDocMode(!mode);
}
void Texmaker::moveDocumentToFront(){
moveDocumentToDest(0);
}
void Texmaker::moveDocumentToEnd(){
moveDocumentToDest(EditorTabs->count()-1);
}
void Texmaker::moveDocumentToDest(int dest){
StructureEntry *entry = LatexDocumentsModel::indexToStructureEntry(structureTreeView->currentIndex());
if (!entry || entry->type != StructureEntry::SE_DOCUMENT_ROOT) return;
int cur = documents.documents.indexOf(entry->document);
if (cur < 0) return;
EditorTabs->moveTab(cur, dest);
EditorTabMoved(cur, dest);
}
void Texmaker::importPackage(QString name){
if(!latexStyleParser){
QString cmd_latex=buildManager.getCommandInfo(BuildManager::CMD_LATEX).commandLine;
QString baseDir;
if(!QFileInfo(cmd_latex).isRelative())
baseDir=QFileInfo(cmd_latex).absolutePath()+"/";
latexStyleParser=new LatexStyleParser(this,configManager.configBaseDir,baseDir+"kpsewhich");
connect(latexStyleParser,SIGNAL(scanCompleted(QString)),this,SLOT(packageScanCompleted(QString)));
connect(latexStyleParser,SIGNAL(finished()),this,SLOT(packageParserFinished()));
latexStyleParser->setAlias(latexParser.packageAliases);
latexStyleParser->start();
QTimer::singleShot(30000,this,SLOT(stopPackageParser()));
}
QString dirName;
if(name.contains("/")){
int i=name.indexOf("/");
dirName="/"+name.mid(i+1);
name=name.left(i);
}
name.chop(4);
name.append(".sty");
latexStyleParser->addFile(name+dirName);
name.chop(4);
name.append(".cls"); // try also cls
latexStyleParser->addFile(name+dirName);
}
void Texmaker::packageScanCompleted(QString name){
QStringList lst=name.split('#');
QString baseName=name;
if(lst.size()>1){
baseName=lst.first();
name=lst.last();
}
foreach(LatexDocument *doc,documents.documents){
if(doc->containsPackage(baseName)){
documents.cachedPackages.remove(name+".cwl"); // TODO: check is this still correct if keys are complex?
doc->updateCompletionFiles(false);
}
}
}
void Texmaker::stopPackageParser(){
if(latexStyleParser)
latexStyleParser->stop();
}
void Texmaker::packageParserFinished(){
delete latexStyleParser;
latexStyleParser=0;
}
void Texmaker::readinAllPackageNames(){
if (!packageListReader) {
// preliminarily use cached packages
QSet<QString> cachedPackages = PackageScanner::readPackageList(QFileInfo(QDir(configManager.configBaseDir), "packageCache.dat").absoluteFilePath());
packageListReadCompleted(cachedPackages);
// start reading actually installed packages
QString cmd_latex=buildManager.getCommandInfo(BuildManager::CMD_LATEX).commandLine;
QString baseDir;
if (!QFileInfo(cmd_latex).isRelative())
baseDir=QFileInfo(cmd_latex).absolutePath()+"/";
#ifdef Q_OS_WIN
bool isMiktex = baseDir.contains("miktex", Qt::CaseInsensitive)
|| (!baseDir.contains("texlive", Qt::CaseInsensitive) && execCommand(baseDir+"latex.exe --version").contains("miktex", Qt::CaseInsensitive));
if (isMiktex)
packageListReader = new MiktexPackageScanner(quotePath(baseDir+"mpm.exe"), configManager.configBaseDir, this);
else
packageListReader = new KpathSeaParser(quotePath(baseDir+"kpsewhich"), this); // TeXlive on windows uses kpsewhich
#else
packageListReader = new KpathSeaParser(quotePath(baseDir+"kpsewhich"), this);
#endif
connect(packageListReader, SIGNAL(scanCompleted(QSet<QString>)), this, SLOT(packageListReadCompleted(QSet<QString>)));
packageListReader->start();
}
}
void Texmaker::packageListReadCompleted(QSet<QString> packages){
latexPackageList = packages;
if (qobject_cast<PackageScanner*>(sender())) {
PackageScanner::savePackageList(packages, QFileInfo(QDir(configManager.configBaseDir), "packageCache.dat").absoluteFilePath());
packageListReader->wait();
delete packageListReader;
packageListReader=0;
}
foreach(LatexDocument *doc,documents.getDocuments()){
LatexEditorView *edView=doc->getEditorView();
if(edView)
edView->updatePackageFormats();
}
}
QString Texmaker::clipboardText(const QClipboard::Mode& mode) const{
return QApplication::clipboard()->text(mode);
}
void Texmaker::setClipboardText(const QString& text, const QClipboard::Mode& mode){
QApplication::clipboard()->setText(text, mode);
}
int Texmaker::getVersion() const{
return TXSVERSION_NUMERIC;
}
void Texmaker::updateTexQNFA() {
QLanguageFactory::LangData m_lang=m_languages->languageData("(La)TeX");
QFile f(configManager.configBaseDir + "languages/tex.qnfa");
if (!f.exists()) {
f.setFileName(findResourceFile("qxs/tex.qnfa"));
}
QDomDocument doc;
doc.setContent(&f);
for (QMap<QString, QVariant>::const_iterator i = configManager.customEnvironments.constBegin(); i != configManager.customEnvironments.constEnd(); ++i){
QString mode=configManager.enviromentModes.value(i.value().toInt(),"verbatim");
addEnvironmentToDom(doc,i.key(),mode);
}
//detected math envs
for (QMap<QString, QString>::const_iterator i = detectedEnvironmentsForHighlighting.constBegin(); i != detectedEnvironmentsForHighlighting.constEnd(); ++i){
QString envMode=i.value()=="verbatim" ? "verbatim" : "numbers";
QString env=i.key();
if(env.contains('*')){
env.replace("*","\\*");
}
addEnvironmentToDom(doc,env,envMode);
}
// structure commands
addStructureCommandsToDom(doc, latexParser.structureCommandLists);
QLanguageDefinition *oldLaTeX = 0, *newLaTeX = 0;
oldLaTeX = m_lang.d;
Q_ASSERT(oldLaTeX);
QNFADefinition::load(doc,&m_lang,m_formats);
m_languages->addLanguage(m_lang);
newLaTeX = m_lang.d;
Q_ASSERT(oldLaTeX != newLaTeX);
if (!EditorTabs) return;
documents.enablePatch(false);
foreach (LatexEditorView *edView, EditorTabs->editors()) {
QEditor* ed = edView->editor;
if (ed->languageDefinition() == oldLaTeX) {
ed->setLanguageDefinition(newLaTeX);
ed->highlight();
}
}
documents.enablePatch(true);
}
/// Updates the highlighting of environments specified via environmentAliases
void Texmaker::updateHighlighting(){
QStringList envList;
envList<<"math"<<"verbatim";
bool updateNecessary=false;
QMultiHash<QString, QString>::const_iterator it = latexParser.environmentAliases.constBegin();
while (it != latexParser.environmentAliases.constEnd()) {
if(envList.contains(it.value())){
if(!detectedEnvironmentsForHighlighting.contains(it.key())){
detectedEnvironmentsForHighlighting.insert(it.key(),it.value());
updateNecessary=true;
}
}
++it;
}
foreach(LatexDocument *doc,documents.getDocuments()){
QMultiHash<QString, QString>::const_iterator it = doc->ltxCommands.environmentAliases.constBegin();
while (it != doc->ltxCommands.environmentAliases.constEnd()) {
if(envList.contains(it.value())){
if(!detectedEnvironmentsForHighlighting.contains(it.key())){
detectedEnvironmentsForHighlighting.insert(it.key(),it.value());
updateNecessary=true;
}
}
++it;
}
}
if(!updateNecessary)
return;
updateTexQNFA();
updateUserMacros(false); //update macros depending on the language to newLatex
}
void Texmaker::toggleGrammar(int type){
QAction* a = qobject_cast<QAction*>(sender());
REQUIRE(a);
LatexEditorView::setGrammarOverlayDisabled(type, !a->isChecked());
//a->setChecked(!a->isChecked());
for (int i=0;i<documents.documents.size();i++)
if (documents.documents[i]->getEditorView())
documents.documents[i]->getEditorView()->updateGrammarOverlays();
}
void Texmaker::fileDiff(){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
//remove old markers
removeDiffMarkers();
QString currentDir=QDir::homePath();
if (!configManager.lastDocument.isEmpty()) {
QFileInfo fi(configManager.lastDocument);
if (fi.exists() && fi.isReadable()) {
currentDir=fi.absolutePath();
}
}
QStringList files = QFileDialog::getOpenFileNames(this,tr("Open Files"),currentDir,tr("LaTeX Files (*.tex);;All Files (*)"), &selectedFileFilter);
if(files.isEmpty())
return;
//
LatexDocument* doc2=diffLoadDocHidden(files.first());
doc2->setObjectName("diffObejct");
doc2->setParent(doc);
diffDocs(doc,doc2);
//delete doc2;
// show changes (by calling LatexEditorView::documentContentChanged)
LatexEditorView *edView=currentEditorView();
edView->documentContentChanged(0,edView->document->lines());
}
void Texmaker::jumpNextDiff(){
QEditor *m_edit=currentEditor();
if(!m_edit)
return;
QDocumentCursor c=m_edit->cursor();
if(c.hasSelection()){
int l,col;
c.endBoundary(l,col);
c.moveTo(l,col);
}
LatexDocument *doc=documents.currentDocument;
//search for next diff
int lineNr=c.lineNumber();
QVariant var=doc->line(lineNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE);
if(var.isValid()){
DiffList lineData=var.value<DiffList>();
for(int j=0;j<lineData.size();j++){
DiffOp op=lineData.at(j);
if(op.start+op.length>c.columnNumber()){
c.moveTo(lineNr,op.start);
c.moveTo(lineNr,op.start+op.length,QDocumentCursor::KeepAnchor);
m_edit->setCursor(c);
return;
}
}
}
lineNr++;
for(;lineNr<doc->lineCount();lineNr++) {
var=doc->line(lineNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE);
if(var.isValid()){
break;
}
}
if(var.isValid()){
DiffList lineData=var.value<DiffList>();
DiffOp op=lineData.first();
c.moveTo(lineNr,op.start);
c.moveTo(lineNr,op.start+op.length,QDocumentCursor::KeepAnchor);
m_edit->setCursor(c);
}
}
void Texmaker::jumpPrevDiff(){
QEditor *m_edit=currentEditor();
if(!m_edit)
return;
QDocumentCursor c=m_edit->cursor();
if(c.hasSelection()){
int l,col;
c.beginBoundary(l,col);
c.moveTo(l,col);
}
LatexDocument *doc=documents.currentDocument;
//search for next diff
int lineNr=c.lineNumber();
QVariant var=doc->line(lineNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE);
if(var.isValid()){
DiffList lineData=var.value<DiffList>();
for(int j=lineData.size()-1;j>=0;j--){
DiffOp op=lineData.at(j);
if(op.start<c.columnNumber()){
c.moveTo(lineNr,op.start);
c.moveTo(lineNr,op.start+op.length,QDocumentCursor::KeepAnchor);
m_edit->setCursor(c);
return;
}
}
}
lineNr--;
for(;lineNr>=0;lineNr--) {
var=doc->line(lineNr).getCookie(QDocumentLine::DIFF_LIST_COOCKIE);
if(var.isValid()){
break;
}
}
if(var.isValid()){
DiffList lineData=var.value<DiffList>();
DiffOp op=lineData.last();
c.moveTo(lineNr,op.start);
c.moveTo(lineNr,op.start+op.length,QDocumentCursor::KeepAnchor);
m_edit->setCursor(c);
}
}
void Texmaker::removeDiffMarkers(bool theirs){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
diffRemoveMarkers(doc,theirs);
QList<QObject *>lst=doc->children();
foreach (QObject* o, lst)
delete o;
LatexEditorView *edView=currentEditorView();
edView->documentContentChanged(0,edView->document->lines());
}
void Texmaker::editChangeDiff(QPoint pt){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
bool theirs=(pt.x()<0);
int ln=pt.x();
if(ln<0)
ln=-ln-1;
int col=pt.y();
diffChange(doc,ln,col,theirs);
LatexEditorView *edView=currentEditorView();
edView->documentContentChanged(0,edView->document->lines());
}
void Texmaker::fileDiffMerge(){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
diffMerge(doc);
LatexEditorView *edView=currentEditorView();
edView->documentContentChanged(0,edView->document->lines());
}
LatexDocument* Texmaker::diffLoadDocHidden(QString f){
QString f_real=f;
#ifdef Q_OS_WIN32
QRegExp regcheck("/([a-zA-Z]:[/\\\\].*)");
if (regcheck.exactMatch(f)) f_real=regcheck.cap(1);
#endif
if (!QFile::exists(f_real)) return 0;
LatexDocument *doc=new LatexDocument(this);
//LatexEditorView *edit = new LatexEditorView(0,configManager.editorConfig,doc);
//edit->document=doc;
//edit->document->setEditorView(edit);
QFile file(f_real);
if (!file.open(QIODevice::ReadOnly)) {
QMessageBox::warning(this,tr("Error"), tr("You do not have read permission to this file."));
return 0;
}
file.close();
//if (edit->editor->fileInfo().suffix()!="tex")
// m_languages->setLanguage(edit->editor, f_real);
//QTime time;
//time.start();
//edit->editor->load(f_real,QDocument::defaultCodec());
doc->load(f_real,QDocument::defaultCodec());
//qDebug() << "Load time: " << time.elapsed();
//edit->editor->document()->setLineEndingDirect(edit->editor->document()->originalLineEnding());
//edit->document->setEditorView(edit); //update file name (if document didn't exist)
return doc;
}
void Texmaker::fileDiff3(){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
//remove old markers
removeDiffMarkers();
QString currentDir=QDir::homePath();
if (!configManager.lastDocument.isEmpty()) {
QFileInfo fi(configManager.lastDocument);
if (fi.exists() && fi.isReadable()) {
currentDir=fi.absolutePath();
}
}
QStringList files = QFileDialog::getOpenFileNames(this,tr("Open Compare File"),currentDir,tr("LaTeX Files (*.tex);;All Files (*)"), &selectedFileFilter);
if(files.isEmpty())
return;
QStringList basefiles = QFileDialog::getOpenFileNames(this,tr("Open Base File"),currentDir,tr("LaTeX Files (*.tex);;All Files (*)"), &selectedFileFilter);
if(basefiles.isEmpty())
return;
showDiff3(files.first(),basefiles.first());
}
void Texmaker::showDiff3(const QString file1,const QString file2){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
LatexDocument* doc2=diffLoadDocHidden(file1);
doc2->setObjectName("diffObejct");
doc2->setParent(doc);
LatexDocument* docBase=diffLoadDocHidden(file2);
docBase->setObjectName("baseObejct");
docBase->setParent(doc);
diffDocs(doc2,docBase,true);
diffDocs(doc,doc2);
// show changes (by calling LatexEditorView::documentContentChanged)
LatexEditorView *edView=currentEditorView();
edView->documentContentChanged(0,edView->document->lines());
}
void Texmaker::declareConflictResolved(){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return;
QString fn=doc->getFileName();
QString cmd=BuildManager::CMD_SVN;
cmd+=" resolve --accept working \""+fn+("\"");
statusLabelProcess->setText(QString(" svn resolve conflict "));
QString buffer;
runCommand(cmd,&buffer);
checkin(fn,"txs: commit after resolve");
}
void Texmaker::fileInConflict(){
QEditor *mEditor = qobject_cast<QEditor *>(sender());
REQUIRE(mEditor);
if (!QFileInfo(mEditor->fileName()).exists()) //create new qfileinfo to avoid caching
return;
int ret = QMessageBox::warning(this,
tr("Conflict!"),
tr(
"%1\nhas been modified by another application.\n"
"Press \"OK\" to show differences\n"
"Press \"Cancel\"to do nothing.\n"
).arg(mEditor->fileName()),
QMessageBox::Ok
|
QMessageBox::Cancel
);
if(ret==QMessageBox::Ok){
//remove old markers
removeDiffMarkers();
if(!checkSVNConflicted(false)){
LatexDocument* doc2=diffLoadDocHidden(mEditor->fileName());
if(!doc2)
return;
LatexDocument* doc=qobject_cast<LatexDocument*>(mEditor->document());
doc2->setObjectName("diffObejct");
doc2->setParent(doc);
diffDocs(doc,doc2);
//delete doc2;
// show changes (by calling LatexEditorView::documentContentChanged)
LatexEditorView *edView=doc->getEditorView();
if(edView)
edView->documentContentChanged(0,edView->document->lines());
}
}
}
bool Texmaker::checkSVNConflicted(bool substituteContents){
LatexDocument *doc=documents.currentDocument;
if(!doc)
return false;
QString fn=doc->getFileName();
QFileInfo qf(fn+".mine");
if(qf.exists()){
SVNSTATUS status=svnStatus(fn);
if(status==SVN_InConflict){
int ret = QMessageBox::warning(this,
tr("SVN Conflict!"),
tr(
"%1is conflicted with repository.\n"
"Press \"OK\" to show differences instead of the generated source by subversion\n"
"Press \"Cancel\"to do nothing.\n"
).arg(doc->getFileName()),
QMessageBox::Ok
|
QMessageBox::Cancel
);
if(ret==QMessageBox::Ok){
QString path=qf.absolutePath();
QDir dir(path);
dir.setSorting(QDir::Name);
qf.setFile(fn);
QString filter=qf.fileName()+".r*";
QFileInfoList list = dir.entryInfoList(QStringList(filter));
QStringList lst;
foreach(QFileInfo elem,list){
lst<<elem.absoluteFilePath();
}
if(lst.count()!=2)
return false;
if(substituteContents){
QTextCodec *codec=doc->codec();
doc->load(fn+".mine",codec);
}
QString baseFile=lst.takeFirst();
QString compFile=lst.takeFirst();
showDiff3(compFile,baseFile);
return true;
}
}
}
return false;
}
QThread* killAtCrashedThread = 0;
QThread* lastCrashedThread = 0;
void recover(){
Texmaker::recoverFromCrash();
}
void Texmaker::recoverFromCrash(){
bool wasLoop;
QString name = getLastCrashInformation(wasLoop);
if (QThread::currentThread() != QCoreApplication::instance()->thread()) {
QThread* t = QThread::currentThread();
lastCrashedThread = t;
if (qobject_cast<SafeThread*>(t)) qobject_cast<SafeThread*>(t)->crashed = true;
QTimer::singleShot(0, txsInstance, SLOT(threadCrashed()));
while(!programStopped) {
ThreadBreaker::sleep(1);
if (t && t == killAtCrashedThread) {
name += QString(" forced kill in %1").arg((long int)t, sizeof(long int)*2, 16,QChar('0'));
name += QString(" (TXS-Version %1 %2 )").arg(TEXSTUDIO_HG_REVISION).arg(COMPILED_DEBUG_OR_RELEASE);
print_backtrace(name);
exit(1);
}
};
ThreadBreaker::forceTerminate();
return;
}
static int nestedCrashes = 0;
nestedCrashes++;
if (nestedCrashes > 5) { qFatal("Forced kill after recovering failed after: %s\n", qPrintable(name)); exit(1); }
fprintf(stderr, "crashed with signal %s\n", qPrintable(name));
if (nestedCrashes <= 2) {
print_backtrace(name + QString(" (TXS-Version %1 %2 )").arg(TEXSTUDIO_HG_REVISION).arg(COMPILED_DEBUG_OR_RELEASE));
}
//hide editor views in case the error occured during drawing
foreach (LatexEditorView *edView, txsInstance->EditorTabs->editors())
edView->hide();
//save recover information
foreach (LatexEditorView *edView, txsInstance->EditorTabs->editors()) {
QEditor* ed = edView ? edView->editor : 0;
if (ed && ed->isContentModified() && !ed->fileName().isEmpty())
ed->saveEmergencyBackup(ed->fileName()+".recover.bak~");
}
QMessageBox * mb = new QMessageBox(); //Don't use the standard methods like ::critical, because they load an icon, which will cause a crash again with gtk. ; mb must be on the heap, or continuing a paused loop can crash
mb->setWindowTitle(tr("TeXstudio Emergency"));
if (!wasLoop) {
mb->setText(tr( "TeXstudio has CRASHED due to a %1.\nDo you want to keep it running? This may cause data corruption.").arg(name));
mb->setDefaultButton(mb->addButton(tr("Yes, try to recover"), QMessageBox::AcceptRole));
mb->addButton(tr("No, kill the program"), QMessageBox::RejectRole); //can't use destructiverole, it always becomes rejectrole
} else {
mb->setText(tr( "TeXstudio has been paused due to a possible endless loop.\nDo you want to keep the program running? This may cause data corruption."));
mb->setDefaultButton(mb->addButton(tr("Yes, stop the loop and try to recover"), QMessageBox::AcceptRole));
mb->addButton(tr("Yes, continue the loop"), QMessageBox::RejectRole);
mb->addButton(tr("No, kill the program"), QMessageBox::DestructiveRole);
}
//show the dialog (non modal, because on Windows showing the dialog modal here, permanently disables all other windows)
mb->setWindowFlags(Qt::WindowStaysOnTopHint);
mb->setWindowModality(Qt::NonModal);
mb->setModal(false);
mb->show();
QApplication::processEvents(QEventLoop::AllEvents);
mb->setFocus(); //without it, raise doesn't work. If it is in the loop (outside time checking if), the buttons can't be clicked on (windows)
QTime t; t.start();
while (mb->isVisible()) {
QApplication::processEvents(QEventLoop::AllEvents);
if (t.elapsed() > 1000 ) {
mb->raise(); //sometimes the box is not visible behind the main window (windows)
t.restart();
}
ThreadBreaker::msleep(1);
}
//print edit history
int i=0;
foreach (LatexEditorView *edView, txsInstance->EditorTabs->editors()) {
Q_ASSERT(edView);
if (!edView) continue;
QFile tf(QDir::tempPath() + QString("/texstudio_undostack%1%2.txt").arg(i++).arg(edView->editor->fileInfo().completeBaseName()));
if (tf.open(QFile::WriteOnly)){
tf.write(edView->editor->document()->debugUndoStack(100).toLocal8Bit());
tf.close();
};
}
//fprintf(stderr, "result: %i, accept: %i, yes: %i, reject: %i, dest: %i\n",mb->result(),QMessageBox::AcceptRole,QMessageBox::YesRole,QMessageBox::RejectRole,QMessageBox::DestructiveRole);
if (mb->result() == QMessageBox::DestructiveRole || (!wasLoop && mb->result() == QMessageBox::RejectRole)) {
qFatal("Killed on user request after error: %s\n", qPrintable(name));
exit(1);
}
if (wasLoop && mb->result() == QMessageBox::RejectRole) {
delete mb;
Guardian::continueEndlessLoop();
while (1) ;
}
//restore editor views
foreach (LatexEditorView *edView, txsInstance->EditorTabs->editors())
edView->show();
if (!programStopped)
QApplication::processEvents(QEventLoop::AllEvents);
nestedCrashes = 0; //assume it was successfully recovered if it gets this far
while (!programStopped) {
QApplication::processEvents(QEventLoop::AllEvents);
ThreadBreaker::msleep(1);
}
name = "Normal close after " + name;
print_backtrace(name);
exit(0);
}
void Texmaker::threadCrashed(){
bool wasLoop;
QString signal = getLastCrashInformation(wasLoop);
QThread* thread = lastCrashedThread;
QString threadName = "<unknown>";
QString threadId = QString("%1").arg((long)(thread),sizeof(long int)*2,16,QChar('0'));
if (qobject_cast<QThread*>(static_cast<QObject*>(thread)))
threadName = QString("%1 %2").arg(threadId).arg(qobject_cast<QThread*>(thread)->objectName());
fprintf(stderr, "crashed with signal %s in thread %s\n", qPrintable(signal), qPrintable(threadName));
int btn = QMessageBox::warning(this, tr("TeXstudio Emergency"),
tr("TeXstudio has CRASHED due to a %1 in thread %2.\nThe thread has been stopped.\nDo you want to keep TeXstudio running? This may cause data corruption.").arg(signal).arg(threadId),
tr("Yes"), tr("No, kill the program"));
if (btn) {
killAtCrashedThread = thread;
ThreadBreaker::sleep(10);
QMessageBox::warning(this, tr("TeXstudio Emergency"), tr("I tried to die, but nothing happened."));
}
}
void Texmaker::iamalive(){
Guardian::calm();
}
void Texmaker::slowOperationStarted(){
Guardian::instance()->slowOperationStarted();
}
void Texmaker::slowOperationEnded(){
Guardian::instance()->slowOperationEnded();
}
void Texmaker::checkLatexInstall(){
fileNew(tr("System Report") + ".txt");
m_languages->setLanguageFromName(currentEditor(), "Plain text");
QString result;
// run pdflatex
statusLabelProcess->setText(QString("check pdflatex"));
QString buffer;
CommandInfo cmdInfo=buildManager.getCommandInfo(BuildManager::CMD_PDFLATEX);
QString cmd=cmdInfo.getBaseName();
// where is pdflatex located
#ifdef Q_OS_WIN
runCommand("where "+cmd, &buffer);
result="where pdflatex: "+buffer+"\n\n";
#else
runCommand("which "+cmd, &buffer);
result="which pdflatex: "+buffer+"\n\n";
#endif
buffer.clear();
cmd+=" -version";
// run pdflatex
runCommand(cmd, &buffer);
result+="PDFLATEX: "+cmd+"\n";
result+=buffer;
result+="\n\n";
// check env
result+="Environment variables:\n";
buffer.clear();
#ifdef Q_OS_WIN
// TODO: it's not guaranteed that a process started with runCommand has the same environment
// currently that should be the case, as long as we don't start to change the environment in
// runCommand before execution.
// The equivalent to printenv on windows would be set. However this is not a program, but a
// command directly built into cmd.com, so we cannot directly use runCommand("set");
buffer = QProcessEnvironment::systemEnvironment().toStringList().join("\n");
#else
runCommand("printenv", &buffer);
#endif
result+=buffer+"\n";
result+= "\nSetting file:\n";
result+= QDir::toNativeSeparators(configManager.configFileName) + "\n";
result+= "\nCommand configuration in TeXstudio:\n";
const CommandMapping& cmds = buildManager.getAllCommands();
foreach (const CommandInfo& ci, cmds)
result += QString(" %1 (%2)%3: %4\n").arg(ci.displayName).arg(ci.id).arg(ci.rerunCompiler?" (r)":"").arg(ci.commandLine);
result+= "\nAdditional Search Paths:\n";
result+= " Command: "+buildManager.additionalSearchPaths+"\n";
result+= " Log: "+buildManager.additionalLogPaths+"\n";
result+= " Pdf: "+buildManager.additionalPdfPaths+"\n";
currentEditorView()->editor->setText(result, false);
}
void Texmaker::addDocToLoad(QString filename){
//qDebug()<<"fname:"<<filename;
if(filename.isEmpty())
return;
load(filename,false,true,recheckLabels);
}
void Texmaker::moveCursorTodlh(){
QAction *act = qobject_cast<QAction *>(sender());
if (!act) return;
StructureEntry *entry = qvariant_cast<StructureEntry *>(act->data());
LatexDocument *doc=entry->document;
QDocumentLineHandle *dlh=entry->getLineHandle();
LatexEditorView* edView=doc->getEditorView();
if(edView){
int lineNr=-1;
if((lineNr=doc->indexOf(dlh))>=0){
gotoLine(lineNr,0,edView);
}
}
}
void Texmaker::openInternalDocViewer(QString package,const QString command){
#ifndef NO_POPPLER_PREVIEW
runInternalCommand("txs:///view-pdf-internal", QFileInfo(package), "--embedded");
QList<PDFDocument*> pdfs = PDFDocument::documentList();
if(pdfs.count()>0){
pdfs[0]->raise();
PDFDocument* pdf=pdfs.first();
pdf->goToPage(0);
pdf->doFindDialog(command);
if(!command.isEmpty())
pdf->search(command, false, false, false, false);
}
#endif
}
void Texmaker::CloseEnv(){
LatexEditorView* edView=currentEditorView();
if(!edView)
return;
QEditor *m_edit=currentEditor();
if(!m_edit)
return;
QDocumentCursor cursor=m_edit->cursor();
StackEnvironment env;
edView->getEnv(cursor.lineNumber(),env);
LatexDocument *doc=edView->document;
int lineCount=doc->lineCount();
if(lineCount<1)
return;
StackEnvironment env_end;
QDocumentLineHandle *dlh=edView->document->line(lineCount-1).handle();
QVariant envVar=dlh->getCookie(QDocumentLine::STACK_ENVIRONMENT_COOKIE);
if(envVar.isValid())
env_end=envVar.value<StackEnvironment>();
else
return;
if(env.count()>0 && env_end.count()>0){
Environment mostRecentEnv=env.pop();
while(!env_end.isEmpty()){
Environment e=env_end.pop();
if(env_end.isEmpty()) // last env is for internal use only
break;
if(e==mostRecentEnv){ // found, now close it
QString txt="\\end{"+e.name+"}";
m_edit->insertText(txt);
break;
}
}
}
}
void Texmaker::enlargeEmbeddedPDFViewer(){
#ifndef NO_POPPLER_PREVIEW
QList<PDFDocument*> oldPDFs = PDFDocument::documentList();
if(oldPDFs.isEmpty())
return;
PDFDocument* viewer=oldPDFs.first();
if(!viewer->embeddedMode)
return;
centralVSplitter->hide();
configManager.viewerEnlarged=true;
viewer->setStateEnlarged(true);
#endif
}
void Texmaker::shrinkEmbeddedPDFViewer(bool preserveConfig){
#ifndef NO_POPPLER_PREVIEW
centralVSplitter->show();
if(!preserveConfig)
configManager.viewerEnlarged=false;
QList<PDFDocument*> oldPDFs = PDFDocument::documentList();
if(oldPDFs.isEmpty())
return;
PDFDocument* viewer=oldPDFs.first();
if(!viewer->embeddedMode)
return;
viewer->setStateEnlarged(false);
#endif
}
void Texmaker::searchExtendToggled(bool toggled){
// show search result in tools widget
if(!toggled){
outputView->hide();
return;
}
QList<LatexDocument *> docs;
LatexDocument *doc = currentEditorView()->document;
docs << doc;
updateFindGlobal(outputView->getSearchScope());
outputView->setSearchEditors(docs);
}
|