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 9255 9256 9257 9258 9259 9260 9261 9262 9263 9264 9265 9266 9267 9268 9269 9270 9271 9272 9273 9274 9275 9276 9277 9278 9279 9280 9281 9282 9283 9284 9285 9286 9287 9288 9289 9290 9291 9292 9293 9294 9295 9296 9297 9298 9299 9300 9301 9302 9303 9304 9305 9306 9307 9308 9309 9310 9311 9312 9313 9314 9315 9316 9317 9318 9319 9320 9321 9322 9323 9324 9325 9326 9327 9328 9329 9330 9331 9332 9333 9334 9335 9336 9337 9338 9339 9340 9341 9342 9343 9344 9345 9346 9347 9348 9349 9350 9351 9352 9353 9354 9355 9356 9357 9358 9359 9360 9361 9362 9363 9364 9365 9366 9367 9368 9369 9370 9371 9372 9373 9374 9375 9376 9377 9378 9379 9380 9381 9382 9383 9384 9385 9386 9387 9388 9389 9390 9391 9392 9393 9394 9395 9396 9397 9398 9399 9400 9401 9402 9403 9404 9405 9406 9407 9408 9409 9410 9411 9412 9413 9414 9415 9416 9417 9418 9419 9420 9421 9422 9423 9424 9425 9426 9427 9428 9429 9430 9431 9432 9433 9434 9435 9436 9437 9438 9439 9440 9441 9442 9443 9444 9445 9446 9447 9448 9449 9450 9451 9452 9453 9454 9455 9456 9457 9458 9459 9460 9461 9462 9463 9464 9465 9466 9467 9468 9469 9470 9471 9472 9473 9474 9475 9476 9477 9478 9479 9480 9481 9482 9483 9484 9485 9486 9487 9488 9489 9490 9491 9492 9493 9494 9495 9496 9497 9498 9499 9500 9501 9502 9503 9504 9505 9506 9507 9508 9509 9510 9511 9512 9513 9514 9515 9516 9517 9518 9519 9520 9521 9522 9523 9524 9525 9526 9527 9528 9529 9530 9531 9532 9533 9534 9535 9536 9537 9538 9539 9540 9541 9542 9543 9544 9545 9546 9547 9548 9549 9550 9551 9552 9553 9554 9555 9556 9557 9558 9559 9560 9561 9562 9563 9564 9565 9566 9567 9568 9569 9570 9571 9572 9573 9574 9575 9576 9577 9578 9579 9580 9581 9582 9583 9584 9585 9586 9587 9588 9589 9590 9591 9592 9593 9594 9595 9596 9597 9598 9599 9600 9601 9602 9603 9604 9605 9606 9607 9608 9609 9610 9611 9612 9613 9614 9615 9616 9617 9618 9619 9620 9621 9622 9623 9624 9625 9626 9627 9628 9629 9630 9631 9632 9633 9634 9635 9636 9637 9638 9639 9640 9641 9642 9643 9644 9645 9646 9647 9648 9649 9650 9651 9652 9653 9654 9655 9656 9657 9658 9659 9660 9661 9662 9663 9664 9665 9666 9667 9668 9669 9670 9671 9672 9673 9674 9675 9676 9677 9678 9679 9680 9681 9682 9683 9684 9685 9686 9687 9688 9689 9690 9691 9692 9693 9694 9695 9696 9697 9698 9699 9700 9701 9702 9703 9704 9705 9706 9707 9708 9709 9710 9711 9712 9713 9714 9715 9716 9717 9718 9719 9720 9721 9722 9723 9724 9725 9726 9727 9728 9729 9730 9731 9732 9733 9734 9735 9736 9737 9738 9739 9740 9741 9742 9743 9744 9745 9746 9747 9748 9749 9750 9751 9752 9753 9754 9755 9756 9757 9758 9759 9760 9761 9762 9763 9764 9765 9766 9767 9768 9769 9770 9771 9772 9773 9774 9775 9776 9777 9778 9779 9780 9781 9782 9783 9784 9785 9786 9787 9788 9789 9790 9791 9792 9793 9794 9795 9796 9797 9798 9799 9800 9801 9802 9803 9804 9805 9806 9807 9808 9809 9810 9811 9812 9813 9814 9815 9816 9817 9818 9819 9820 9821 9822 9823 9824 9825 9826 9827 9828 9829 9830 9831 9832 9833 9834 9835 9836 9837 9838 9839 9840 9841 9842 9843 9844 9845 9846 9847 9848 9849 9850 9851 9852 9853 9854 9855 9856 9857 9858 9859 9860 9861 9862 9863 9864 9865 9866 9867 9868 9869 9870 9871 9872 9873 9874 9875 9876 9877 9878 9879 9880 9881 9882 9883 9884 9885 9886 9887 9888 9889 9890 9891 9892 9893 9894 9895 9896 9897 9898 9899 9900 9901 9902 9903 9904 9905 9906 9907 9908 9909 9910 9911 9912 9913 9914 9915 9916 9917 9918 9919 9920 9921 9922 9923 9924 9925 9926 9927 9928 9929 9930 9931 9932 9933 9934 9935 9936 9937 9938 9939 9940 9941 9942 9943 9944 9945 9946 9947 9948 9949 9950 9951 9952 9953 9954 9955 9956 9957 9958 9959 9960 9961 9962 9963 9964 9965 9966 9967 9968 9969 9970 9971 9972 9973 9974 9975 9976 9977 9978 9979 9980 9981 9982 9983 9984 9985 9986 9987 9988 9989 9990 9991 9992 9993 9994 9995 9996 9997 9998 9999 10000 10001 10002 10003 10004 10005 10006 10007 10008 10009 10010 10011 10012 10013 10014 10015 10016 10017 10018 10019 10020 10021 10022 10023 10024 10025 10026 10027 10028 10029 10030 10031 10032 10033 10034 10035 10036 10037 10038 10039 10040 10041 10042 10043 10044 10045 10046 10047 10048 10049 10050 10051 10052 10053 10054 10055 10056 10057 10058 10059 10060 10061 10062 10063 10064 10065 10066 10067 10068 10069 10070 10071 10072 10073 10074 10075 10076 10077 10078 10079 10080 10081 10082 10083 10084 10085 10086 10087 10088 10089 10090 10091 10092 10093 10094 10095 10096 10097 10098 10099 10100 10101 10102 10103 10104 10105 10106 10107 10108 10109 10110 10111 10112 10113 10114 10115 10116 10117 10118 10119 10120 10121 10122 10123 10124 10125 10126 10127 10128 10129 10130 10131 10132 10133 10134 10135 10136 10137 10138 10139 10140 10141 10142 10143 10144 10145 10146 10147 10148 10149 10150 10151 10152 10153 10154 10155 10156 10157 10158 10159 10160 10161 10162 10163 10164 10165 10166 10167 10168 10169 10170 10171 10172 10173 10174 10175 10176 10177 10178 10179 10180 10181 10182 10183 10184 10185 10186 10187 10188 10189 10190 10191 10192 10193 10194 10195 10196 10197 10198 10199 10200 10201 10202 10203 10204 10205 10206 10207 10208 10209 10210 10211 10212 10213 10214 10215 10216 10217 10218 10219 10220 10221 10222 10223 10224 10225 10226 10227 10228 10229 10230 10231 10232 10233 10234 10235 10236 10237 10238 10239 10240 10241 10242 10243 10244 10245 10246 10247 10248 10249 10250 10251 10252 10253 10254 10255 10256 10257 10258 10259 10260 10261 10262 10263 10264 10265 10266 10267 10268 10269 10270 10271 10272 10273 10274 10275 10276 10277 10278 10279 10280 10281 10282 10283 10284 10285 10286 10287 10288 10289 10290 10291 10292 10293 10294 10295 10296 10297 10298 10299 10300 10301 10302 10303 10304 10305 10306 10307 10308 10309 10310 10311 10312 10313 10314 10315 10316 10317 10318 10319 10320 10321 10322 10323 10324 10325 10326 10327 10328 10329 10330 10331 10332 10333 10334 10335 10336 10337 10338 10339 10340 10341 10342 10343 10344 10345 10346 10347 10348 10349 10350 10351 10352 10353 10354 10355 10356 10357 10358 10359 10360 10361 10362 10363 10364 10365 10366 10367 10368 10369 10370 10371 10372 10373 10374 10375 10376 10377 10378 10379 10380 10381 10382 10383 10384 10385 10386 10387 10388 10389 10390 10391 10392 10393 10394 10395 10396 10397 10398 10399 10400 10401 10402 10403 10404 10405 10406 10407 10408 10409 10410 10411 10412 10413 10414 10415 10416 10417 10418 10419 10420 10421 10422 10423 10424 10425 10426 10427 10428 10429 10430 10431 10432 10433 10434 10435 10436 10437 10438 10439 10440 10441 10442 10443 10444 10445 10446 10447 10448 10449 10450 10451 10452 10453 10454 10455 10456 10457 10458 10459 10460 10461 10462 10463 10464 10465 10466 10467 10468 10469 10470 10471 10472 10473 10474 10475 10476 10477 10478 10479 10480 10481 10482 10483 10484 10485 10486 10487 10488 10489 10490 10491 10492 10493 10494 10495 10496 10497 10498 10499 10500 10501 10502 10503 10504 10505 10506 10507 10508 10509 10510 10511 10512 10513 10514 10515 10516 10517 10518 10519 10520 10521 10522 10523 10524 10525 10526 10527 10528 10529 10530 10531 10532 10533 10534 10535 10536 10537 10538 10539 10540 10541 10542 10543 10544 10545 10546 10547 10548 10549 10550 10551 10552 10553 10554 10555 10556 10557 10558 10559 10560 10561 10562 10563 10564 10565 10566 10567 10568 10569 10570 10571 10572 10573 10574 10575 10576 10577 10578 10579 10580 10581 10582 10583 10584 10585 10586 10587 10588 10589 10590 10591 10592 10593 10594 10595 10596 10597 10598 10599 10600 10601 10602 10603 10604 10605 10606 10607 10608 10609 10610 10611 10612 10613 10614 10615 10616 10617 10618 10619 10620 10621 10622 10623 10624 10625 10626 10627 10628 10629 10630 10631 10632 10633 10634 10635 10636 10637 10638 10639 10640 10641 10642 10643 10644 10645 10646 10647 10648 10649 10650 10651 10652 10653 10654 10655 10656 10657 10658 10659 10660 10661 10662 10663 10664 10665 10666 10667 10668 10669 10670 10671 10672 10673 10674 10675 10676 10677 10678 10679 10680 10681 10682 10683 10684 10685 10686 10687 10688 10689 10690 10691 10692 10693 10694 10695 10696 10697 10698 10699 10700 10701 10702 10703 10704 10705 10706 10707 10708 10709 10710 10711 10712 10713 10714 10715 10716 10717 10718 10719 10720 10721 10722 10723 10724 10725 10726 10727 10728 10729 10730 10731 10732 10733 10734 10735 10736 10737 10738 10739 10740 10741 10742 10743 10744 10745 10746 10747 10748 10749 10750 10751 10752 10753 10754 10755 10756 10757 10758 10759 10760 10761 10762 10763 10764 10765 10766 10767 10768 10769 10770 10771 10772 10773 10774 10775 10776 10777 10778 10779 10780 10781 10782 10783 10784 10785 10786 10787 10788 10789 10790 10791 10792 10793 10794 10795 10796 10797 10798 10799 10800 10801 10802 10803 10804 10805 10806 10807 10808 10809 10810 10811 10812 10813 10814 10815 10816 10817 10818 10819 10820 10821 10822 10823 10824 10825 10826 10827 10828 10829 10830 10831 10832 10833 10834 10835 10836 10837 10838 10839 10840 10841 10842 10843 10844 10845 10846 10847 10848 10849 10850 10851 10852 10853 10854 10855 10856 10857 10858 10859 10860 10861 10862 10863 10864 10865 10866 10867 10868 10869 10870 10871 10872 10873 10874 10875 10876 10877 10878 10879 10880 10881 10882 10883 10884 10885 10886 10887 10888 10889 10890 10891 10892 10893 10894 10895 10896 10897 10898 10899 10900 10901 10902 10903 10904 10905 10906 10907 10908 10909 10910 10911 10912 10913 10914 10915 10916 10917 10918 10919 10920 10921 10922 10923 10924 10925 10926 10927 10928 10929 10930 10931 10932 10933 10934 10935 10936 10937 10938 10939 10940 10941 10942 10943 10944 10945 10946 10947 10948 10949 10950 10951 10952 10953 10954 10955 10956 10957 10958 10959 10960 10961 10962 10963 10964 10965 10966 10967 10968 10969 10970 10971 10972 10973 10974 10975 10976 10977 10978 10979 10980 10981 10982 10983 10984 10985 10986 10987 10988 10989 10990 10991 10992 10993 10994 10995 10996 10997 10998 10999 11000 11001 11002 11003 11004 11005 11006 11007 11008 11009 11010 11011 11012 11013 11014 11015 11016 11017 11018 11019 11020 11021 11022 11023 11024 11025 11026 11027 11028 11029 11030 11031 11032 11033 11034 11035 11036 11037 11038 11039 11040 11041 11042 11043 11044 11045 11046 11047 11048 11049 11050 11051 11052 11053 11054 11055 11056 11057 11058 11059 11060 11061 11062 11063 11064 11065 11066 11067 11068 11069 11070 11071 11072 11073 11074 11075 11076 11077 11078 11079 11080 11081 11082 11083 11084 11085 11086 11087 11088 11089 11090 11091 11092 11093 11094 11095 11096 11097 11098 11099 11100 11101 11102 11103 11104 11105 11106 11107 11108 11109 11110 11111 11112 11113 11114 11115 11116 11117 11118 11119 11120 11121 11122 11123 11124 11125 11126 11127 11128 11129 11130 11131 11132 11133 11134 11135 11136 11137 11138 11139 11140 11141 11142 11143 11144 11145 11146 11147 11148 11149 11150 11151 11152 11153 11154 11155 11156 11157 11158 11159 11160 11161 11162 11163 11164 11165 11166 11167 11168 11169 11170 11171 11172 11173 11174 11175 11176 11177 11178 11179 11180 11181 11182 11183 11184 11185 11186 11187 11188 11189 11190 11191 11192 11193 11194 11195 11196 11197 11198 11199 11200 11201 11202 11203 11204 11205 11206 11207 11208 11209 11210 11211 11212 11213 11214 11215 11216 11217 11218 11219 11220 11221 11222 11223 11224 11225 11226 11227 11228 11229 11230 11231 11232 11233 11234 11235 11236 11237 11238 11239 11240 11241 11242 11243 11244 11245 11246 11247 11248 11249 11250 11251 11252 11253 11254 11255 11256 11257 11258 11259 11260 11261 11262 11263 11264 11265 11266 11267 11268 11269 11270 11271 11272 11273 11274 11275 11276 11277 11278 11279 11280 11281 11282 11283 11284 11285 11286 11287 11288 11289 11290 11291 11292 11293 11294 11295 11296 11297 11298 11299 11300 11301 11302 11303 11304 11305 11306 11307 11308 11309 11310 11311 11312 11313 11314 11315 11316 11317 11318 11319 11320 11321 11322 11323 11324 11325 11326 11327 11328 11329 11330 11331 11332 11333 11334 11335 11336 11337 11338 11339 11340 11341 11342 11343 11344 11345 11346 11347 11348 11349 11350 11351 11352 11353 11354 11355 11356 11357 11358 11359 11360 11361 11362 11363 11364 11365 11366 11367 11368 11369 11370 11371 11372 11373 11374 11375 11376 11377 11378 11379 11380 11381 11382 11383 11384 11385 11386 11387 11388 11389 11390 11391 11392 11393 11394 11395 11396 11397 11398 11399 11400 11401 11402 11403 11404 11405 11406 11407 11408 11409 11410 11411 11412 11413 11414 11415 11416 11417 11418 11419 11420 11421 11422 11423 11424 11425 11426 11427 11428 11429 11430 11431 11432 11433 11434 11435 11436 11437 11438 11439 11440 11441 11442 11443 11444 11445 11446 11447 11448 11449 11450 11451 11452 11453 11454 11455 11456 11457 11458 11459 11460 11461 11462 11463 11464 11465 11466 11467 11468 11469 11470 11471 11472 11473 11474 11475 11476 11477 11478 11479 11480 11481 11482 11483 11484 11485 11486 11487 11488 11489 11490 11491 11492 11493 11494 11495 11496 11497 11498 11499 11500 11501 11502 11503 11504 11505 11506 11507 11508 11509 11510 11511 11512 11513 11514 11515 11516 11517 11518 11519 11520 11521 11522 11523 11524 11525 11526 11527 11528 11529 11530 11531 11532 11533 11534 11535 11536
|
#!/usr/bin/wish
# Part of MCU 8051 IDE ( http://https://sourceforge.net/projects/mcu8051ide/ )
############################################################################
# Copyright (C) 2007, 2008, 2009, 2010, 2011, 2012 by Martin Ošmera #
# martin.osmera@gmail.com #
# #
# Copyright (C) 2014 by Moravia Microsystems, s.r.o. #
# martin.osmera@gmail.com #
# #
# 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. #
# #
# This program is distributed in the hope that it will be useful, #
# but WITHOUT ANY WARRANTY; without even the implied warranty of #
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
# GNU General Public License for more details. #
# #
# You should have received a copy of the GNU General Public License #
# along with this program; if not, write to the #
# Free Software Foundation, Inc., #
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. #
############################################################################
# >>> File inclusion guard
if { ! [ info exists _X_TCL ] } {
set _X_TCL _
# <<< File inclusion guard
# --------------------------------------------------------------------------
# DESCRIPTION
# "Provides various dialogues and various variables for various things"
# For instance the "Go to" dialog is placed here
# --------------------------------------------------------------------------
# Dialog for selecting MCU and loading MCU details from definition file
source "${::LIB_DIRNAME}/dialogues/selectmcu.tcl"
namespace eval X {
## General
variable unsaved_projects {} ;# List: List of project object marked as "unsaved"
variable critical_procedure_in_progress 1 ;# Bool: Disable critical procedures (like compilation, start simulator, etc.)
variable foo_procedure_in_progress 0 ;# Bool: Disables some non-critical procedures
variable last_WIN_GEOMETRY {} ;# Last window geometry (main window)
variable actualProject {} ;# Object: Current project
variable openedProjects {} ;# List of opened projects (Object references)
variable actualProjectIdx -1 ;# Index of the current project in $openedProjects
variable project_menu_locked 1 ;# Bool: Indicates than there is at least one opened project
if {!$::MICROSOFT_WINDOWS} {
variable defaultDirectory ${::env(HOME)} ;# Default directory
} else {
variable defaultDirectory ${::env(USERPROFILE)} ;# Default directory
}
variable simulator_enabled {} ;# List of booleans: Simulator engaged
variable editor_lines ;# Number of lines in the current editor
variable fsd_result {} ;# Value returnded by file selection dialog (in some cases)
variable projectmenu {.project_menu} ;# ID of Popup menu for project tabs
variable projectmenu_project {} ;# Object: project selected by project popup menu
variable selectedView ;# Object: Selected editor by editor statusbar popup menu
variable open_f_external_editor 0 ;# Bool: Use procedure __open to open new file for embedded external editor
variable file_recent_files {} ;# List: recently opened files
variable project_recent_files {} ;# List: recently opened projects
variable vhw_recent_files {} ;# List: recently opened Virtual HW files
# List of supported processors
variable available_processors [::SelectMCU::get_available_processors]
variable procedure_exit_in_progress 0 ;# Bool: proc "__exit" in progress
## Doxygen
variable doxygen_run_doxywizard 0 ;# Bool: Run doxywizard
variable doxygen_build_api_doc 0 ;# Bool: Build API documentation
variable doxygen_pid 0 ;# Int: Doxygen PID
variable doxygen_mess_project ;# Object: Project related to running doxygen compilation
## ASCII chart
variable ascii_chart_win_object {} ;# Object: ASCII chart window object
## Interactive 8051 instruction table
variable table_of_instructions_object {} ;# Object: Interactive 8051 instruction table
## 8-Segment LED editor
variable eightsegment_editors {} ;# List: All 8-segment LED display editors invoked
## Base converter
variable base_converters {} ;# List: All base converter objects
## Special calculator
variable spec_calc_objects {} ;# List: All special calculator objects
## UART/RS232 debugger
variable rs232debugger_objects {} ;# List: All "RS232 debugger" objects
## LCD display controlled by HD44780
variable vhw_HD44780_rect ;# Array: Rectangles in dialog "Set display size"
variable vhw_HD44780_canvas ;# Widget: Canvas widget in dialog "Set display size"
variable vhw_HD44780_counter 0 ;# Int: Counter of dialog instances
variable vhw_HD44780_size_lbl ;# Widget: Label showing the LCD size in dialog "Set display size"
variable vhw_HD44780_dialog ;# Widget: Toplevel window of dialog "Set display size"
variable vhw_HD44780_size {0 0} ;# List of Int: LCD display size chosen by the user, {HEIGHT WIDTH}
## Dialog "Go to"
variable goto ;# Line where to go
## Function "Auto-indent"
variable reformat_code_abort ;# Bool: Abort function 'reformat_code'
## Dialog "Find"
variable find_String ;# Search string
variable find_forward_index ;# Search index for forward search
variable find_backward_index ;# Search index for backward search
variable find_option_CS ;# Bool: Case sensitive
variable find_option_notCS ;# Bool: Case insensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable find_allow_selection ;# Bool: There is some selected text in editor
variable find_retry_search ;# Bool: Search restarted from beginning/end
variable find_back_dir ;# Bool: Search backwards (real option)
variable find_history {} ;# List of the last 10 search strings
variable find_next_prev_in_P 0 ;# Bool: Procedure 'find_next_prev' in progress
## Dialog "Replace"
variable replace_String ;# String to replace
variable replace_Replacement ;# Replacement for the search string
variable replace_option_CS ;# Bool: Case sensitive
variable replace_option_back ;# Bool: Search backwards (checkbox)
variable replace_option_cur ;# Book: Search from cursor
variable replace_option_reg ;# Bool: Consider search string to be a regular expression
variable replace_option_prompt ;# Bool: Prompt on replace
variable replace_prompt_opened 0 ;# Bool: Replace prompt dialog opened
variable replace_prompt_return_value ;# Replace prompt dialog return value
variable replace_prompt_geometry ;# Geometry of replace prompt dialog window
variable replace_search_history {} ;# List of the last 10 search strings
variable replace_repl_history {} ;# List of the last 10 replacement strings
## Dialog "Select directory"
variable select_directory_var {} ;# Selected directory
## Dialog "New project"
variable project_new_name {} ;# Name of the new project
variable project_new_dir {} ;# Directory of the new project
## Variable common for "New project" and "Edit project"
variable project_new_processor ;# Processor type (e.g. "8051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
variable project_new_max_xcode ;# Int: Maximum valid value of external program memory
variable project_new_xd_chb ;# Widget: XDATA enable checkbutton
variable project_new_xd_scl ;# Widget: XDATA scale
variable project_new_xd_spb ;# Widget: XDATA spinbox
variable project_new_xc_chb ;# Widget: XCODE enable checkbutton
variable project_new_xc_scl ;# Widget: XCODE scale
variable project_new_xc_spb ;# Widget: XCODE spinbox
## Dialog "Edit project"
variable project_edit_version ;# Project version
variable project_edit_date ;# Project date (last update)
variable project_edit_copyright ;# Copyright information
variable project_edit_license ;# License information
variable project_edit_authors ;# Project authors
variable project_edit_description ;# Project description
variable project_edit_clock ;# Default clock rate
variable project_edit_main_file ;# Project main file
variable project_edit_main_file_clr_but ;# Widget: Project main file clear button
# Some default project values
# format: {{variable value} {variable value} ...}
variable project_edit_defaults {
{project_edit_family 8051 }
{project_edit_clock 12000 }
{project_edit_calc_rad Dec }
{project_edit_calc_ang rad }
}
## Functions related to project management (save, load)
variable project_watches_file ;# File of register watches of the current poject
variable project_todo ;# Todo text
variable project_graph ;# Graph configuration list
variable project_calculator ;# Calculator list (display contents, etc.)
variable project_other_options ;# Other project options
variable project_compiler_options ;# Compiler options
variable project_files ;# List of project files (special format)
variable project_file ;# Full name of the project file
variable project_dir ;# Path to project directory
## Compilation related variables
variable compilation_success_callback {} ;# String: Indented for HW plugins
variable compilation_fail_callback {} ;# String: Indented for HW plugins
variable compilation_mess_project {} ;# Object: Project related to running compilation
variable compilation_successfull 1 ;# Bool: Compilation successful
variable compilation_in_progress 0 ;# Bool: Compiler engaged
variable compilation_progress 0 ;# Variable for compilation progressbar
variable compiler_pid 0 ;# Int: PID of external compiler if used
variable compilation_start_simulator 0 ;# Bool: Start simulator after successful compilation
variable compile_this_file_only 0 ;# Bool: Compile the current file only
## Dialog "Select input/output file"
variable input_file ;# Input file
variable output_file ;# Output file
variable IO ;# Bool: 1 == choose input file; 0 == choose output file
### Dialogues "Hex->Bin; Bin->Hex; Sim->Hex; Sim->Bin; Nomalize Hex"
# Type of conversion
# 0 == Bin -> Hex
# 1 == Hex -> Bin
# 2 == Sim -> Hex
# 3 == Sim -> Bin
variable hex__bin
variable input_file {} ;# Input file
variable output_file {} ;# Output file
## XDATA/CODE/ERAM/EEPROM/UNI memory hexadecimal editors
variable opened_code_mem_windows {} ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects {} ;# List of CODE memory hex editor objects
variable opened_xdata_mem_windows {} ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects {} ;# List of XDATA memory hex editor objects
variable opened_eram_windows {} ;# List of project object with opened ERAM hex editor
variable eram_window_objects {} ;# List of ERAM hex editor objects
variable opened_eeprom_mem_windows {} ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects {} ;# List of data EEPROM hex editor objects
variable opened_eeprom_wr_bf_windows {} ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects {} ;# List of data EEPROM write buffer hex editor objects
variable eeprom_wr_buf_counter 0 ;# Counter of EEPROM write buffer hex editor objects
variable saving_progress 0 ;# Variable for progressbars representing saving progress
variable abort_saving 0 ;# Bool: Abort saving of IHEX8 file
variable independent_hexeditor_count 0 ;# Counter of intances of independent hexadecimal editor
# Path to file defining the last session
variable session_file "${::CONFIG_DIR}/last_session.conf"
## Dialog "Cleanup project folder"
# GLOB patterns in certain order !
variable cleanup_masks {
*.asm~ *.lst~ *.sim~ *.hex~
*.bin~ *.html~ *.tex~ *.wtc~
*.mcu8051ide~ *.m5ihib~ *.cdb~ *.ihx~
*.adf~ *.omf~ *.map~ *.c~
*.h~ *.vhc~ *.vhw~ *.txt~
*~
*.lst *.sim *.hex *.bin *.html *.tex *.m5ihib
*.noi *.obj *.map *.p *.mac *.i *.ihx
*.adf *.adb *.rel *.cdb *.mem *.lnk *.sym
*.omf *.rst *.hashes *bak
}
variable cleanup_files {} ;# List: Files marked for potential removal
## Dialog "Change letter case"
variable change_letter_case_options ;# Options (which fields should be adjusted)
## Dialog "Line to address"
variable line2pc ;# Int: Selected line in source code
variable line2pc_jump 1 ;# Bool: Perform program jump (1) or subprogram call (0)
variable line2pc_line_max ;# Int: Number of lines in the source code
variable line2pc_value_lbl ;# Widget: Label containing PC value
variable line2pc_new_value ;# Int: Resolved address or {}
variable line2pc_org_line ;# Int: Original line
variable line2pc_ok_button ;# Widget: Button "OK"
variable line2pc_file_number ;# Int: File number
## Dialog "File statistics"
variable statistics_counter 0 ;# Int: Counter of invocations of this dialog
## Project details window
variable PROJECTDETAILSWIN ;# ID of project details window
variable projectdetails_last_project {} ;# Project object of the last project details window
## Custom commands related variables
variable custom_cmd_dialog_index 0 ;# Index of results dialog (to keep win IDs unique)
variable custom_command_cmd ;# Array of custom commands (shell scripts)
variable custom_command_options ;# Array of Lists of custom command options
variable custom_command_desc ;# Array of custom command descriptions
variable custom_command_PID ;# Array of custom command PIDs (Process IDentifiers)
variable custom_command_NUM ;# Array of custom command numbers
variable custom_command_counter 0 ;# Counter of custom command invocations
## Initialize custom commands related variables
# Shell scripts
set custom_command_cmd(0) [mc "echo \"This is a custom command\"\necho \"\tYou can configure it in Main menu->Configure->Edit user commands.\"\necho \"\tCustom commands are intended for running external programs from this IDE (e.g. program uploaders)\""]
append custom_command_cmd(0) "\n\n"
append custom_command_cmd(0) "echo \"\"\n"
append custom_command_cmd(0) "echo \"%%URIS == \\\"%URIS\\\"\"\n"
append custom_command_cmd(0) "echo \"%%URI == \\\"%URI\\\"\"\n"
append custom_command_cmd(0) "echo \"%%directory == \\\"%directory\\\"\"\n"
append custom_command_cmd(0) "echo \"%%filename == \\\"%filename\\\"\"\n"
append custom_command_cmd(0) "echo \"%%basename == \\\"%basename\\\"\"\n"
append custom_command_cmd(0) "echo \"%%mainfile == \\\"%mainfile\\\"\"\n"
append custom_command_cmd(0) "echo \"%%line == \\\"%line\\\"\"\n"
append custom_command_cmd(0) "echo \"%%column == \\\"%column\\\"\"\n"
append custom_command_cmd(0) "echo \"%%selection == \\\"%selection\\\"\"\n"
set custom_command_cmd(1) $custom_command_cmd(0)
set custom_command_cmd(2) $custom_command_cmd(0)
# Command options
set custom_command_options(0) {0 1 0 0}
set custom_command_options(1) $custom_command_options(0)
set custom_command_options(2) $custom_command_options(0)
# Command descritpions
set custom_command_desc(0) [mc "More: Main menu -> Configure -> Edit user commands"]
set custom_command_desc(1) $custom_command_desc(0)
set custom_command_desc(2) $custom_command_desc(0)
# Command Thread IDentifiers
set custom_command_PID(0) {}
set custom_command_PID(1) $custom_command_PID(0)
set custom_command_PID(2) $custom_command_PID(0)
# Custom command numbers
set custom_command_NUM(0) {}
set custom_command_NUM(1) $custom_command_NUM(0)
set custom_command_NUM(2) $custom_command_NUM(0)
## Menu and Toolbar related variables
# Menu bar items which require opened project
variable mainmenu_project_dependent_buttons {
{ ".mainMenu"
{ "Edit" "View" "Simulator" "Virtual MCU" "Virtual HW" "Tools"}
} { ".mainMenu.project"
{ "Save" "Edit project" "Close without saving" "Save and close"}
} { ".mainMenu.file"
{ "New" "Open" "Open recent" "Save" "Save as" "Save all" "Close" "Close all" "File statistics"}
} { ".mainMenu.configure"
{ "Configure Compiler"}
}
}
# Menu bar items which require ENGAGED simulator
variable mainmenu_simulator_engaged {
{ ".mainMenu.simulator"
{ "Step" "Step over" "Animate" "Run"
"Jump to line" "Find cursor" "Step back" "Clear highlight"
"Hiberante program" "Resume hibernated program"
}
} { ".mainMenu.virtual_mcu"
{ "Reset" }
}
}
# Menu bar items which require DISENGAGED simulator
variable mainmenu_simulator_disengaged {
{ ".mainMenu.file"
{ "New" "Open" "Close" "Close all"}
} { ".mainMenu.edit"
{ "Undo" "Redo" "Cut" "Paste" "Replace"
"Comment" "Uncomment" "Indent" "Unindent"}
} { ".mainMenu.display"
{ "Read only mode" "Reload"}
}
{ ".mainMenu.simulator"
{ "Debug this file only" }
} { ".mainMenu.tools"
{ "Compile" "Disassemble" "Encoding" "End of line"
"Auto indent" "Change letter case" "Document current function"
"Compile this file"}
}
}
# Menu bar items which are not available when editor is in read only mode
variable mainmenu_editor_readonly {
{ ".mainMenu.edit"
{ "Undo" "Redo" "Cut" "Paste" "Replace"
"Comment" "Uncomment" "Indent" "Unindent"}
} { ".mainMenu.tools"
{ "Auto indent" "Change letter case" "Document current function"}
}
}
# Menu bar items which are not available only for C language
variable mainmenu_editor_c_only {
{ ".mainMenu.tools"
{ "Document current function"}
}
}
# Menu bar items which are not available when external embedded editor is used
variable mainmenu_editor_external_na {
{.mainMenu.tools {
{Encoding} {End of line}
{Auto indent} {Change letter case}
{Export as XHTML} {Export as LaTeX}
{Auto indent} {Change letter case}
{Document current function}
}
} {.mainMenu.file {
{Save} {Save as}
{Save all} {File statistics}
}
} {.mainMenu.display {
{Read only mode} {Switch to command line}
{Highlight} {Show/Hide line numbers}
{Reload} {Show/Hide icon border}
}
} {.mainMenu.simulator {
{Find cursor} {Jump to line}
}
} {.mainMenu {
{Edit}
}
}
}
# Toolbar buttons which require opened project
variable toolbar_project_dependent_buttons {
new open save save_as
save_all close close_all undo
redo cut copy paste
find findnext findprev replace
goto reload clear proj_save
proj_edit proj_close proj_close_imm show_code_mem
show_ext_mem start_sim reset step
stepover animate run assemble
disasm reformat_code toHTML toLaTeX
cleanup custom0 custom1 custom2
change_case forward back clear_hg
intrmon hibernate resume stepback
find_sim_cur line2addr show_exp_mem sfrmap
show_eeprom show_eem_wr_b stopwatch bitmap
uartmon
ledpanel leddisplay ledmatrix mleddisplay
simplekeypad matrixkeypad vhw_open vhw_load
vhw_save vhw_saveas vhw_remove_all hd44780
ds1620 vuterm fintr
stack d52
}
# Toolbar buttons which require ENGAGED simulator
variable toolbar_simulator_engaged {
reset step stepover animate
run clear_hg find_sim_cur line2addr
stepback hibernate resume
}
# Toolbar buttons which require DISENGAGED simulator
variable toolbar_simulator_disengaged {
new open close close_all
undo redo cut copy
paste replace reload assemble
start_sim0 disasm reformat_code change_case
assemble0 d52
}
# Toolbar items which are not available when editor is in read only mode
variable toolbar_editor_readonly {
undo redo cut paste
replace reformat_code change_case
}
# Toolbar items which are not available only for C language
variable toolbar_editor_c_only {
}
# Toolbar items which are not available when external embedded editor is used
variable toolbar_editor_external_na {
save save_as undo redo cut
copy paste find findnext findprev
replace goto reload reformat_code change_case
toHTML toLaTeX find_sim_cur line2addr save_all
}
## This function should be immediately after load of environment.tcl
# @return void
proc initialize {} {
variable projectmenu ;# ID of Popup menu for project tabs
menuFactory {
{command "Save" "$project:proj_save" 0
{__project_pmenu_save}
"filesave" "Save this project"}
{command "Edit project" "$project:proj_edit" 0
{__project_pmenu_edit}
"configure" "Edit additional project detail"}
{separator}
{command "Save and close" "$project:proj_close" 1
{__project_pmenu_close}
"fileclose" "Save and close this project"}
{command "Close without saving" "$project:proj_clsimm" 0
{__project_pmenu_close_imm}
"no" "Close this project"}
{separator}
{command "Move left" "" 5
{__project_move_to_left}
"1leftarrow" "Move this tab to right the beginning of the tab bar"}
{command "Move right" "" 5
{__project_move_to_right}
"1rightarrow" "Move this tab to right the end of the tab bar"}
{separator}
{command "Move to beginning" "" 8
{__project_move_to_beginning}
"2leftarrow" "Move this tab to right the beginning of the tab bar"}
{command "Move to end" "" 9
{__project_move_to_end}
"2rightarrow" "Move this tab to right the end of the tab bar"}
} $projectmenu 0 "::X::" 0 {} [namespace current]
}
## Switch current project
# @parm String project_name - Project object reference
# @return void
proc switch_project {project_name} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable openedProjects ;# List of opened projects (Object references)
variable simulator_enabled ;# List of booleans: Simulator engaged
# Ensure that autocompletion window is closed
::Editor::close_completion_popup_window_NOW
if {$actualProjectIdx != -1 && ([lindex $simulator_enabled $actualProjectIdx] == 1)} {
if {[$actualProject sim_stepover_in_progress]} {
$actualProject sim_stepover
} elseif {[$actualProject sim_run_in_progress]} {
$actualProject sim_run
} elseif {[$actualProject sim_anim_in_progress]} {
$actualProject sim_animate
}
}
set actualProject [string trimleft $project_name {:}]
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
disaena_menu_toolbar_for_current_project
adjust_title
$actualProject adjust_compiler_settings
$actualProject switchfile
}
## Enable / Disable menu and toolbar item according to current state of current project
# @return void
proc disaena_menu_toolbar_for_current_project {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
# This procedure requires at least one opened project
if {$project_menu_locked} {return}
# Adjust state simulator related menu/toolbar items
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
Unlock_simulator_menu
# Enable / Disabled stepback buttons
stepback_button_set_ena [$actualProject simulator_get_SBS_len]
} else {
Lock_simulator_menu
adjust_mainmenu_and_toolbar_to_editor \
${::editor_RO_MODE} \
[expr {1 == [$actualProject editor_procedure {} get_language {}]}]
}
# set MCU name in statusbar, kdb
.statusbarMCU configure -text [$actualProject cget -P_option_mcu_type]
## Disable/Enable menu+toolbar entries related to simulator controls which depends on current MCU
disena_simulator_menu $actualProject
}
## Disable/Enable menu+toolbar entries related to simulator
# +controls which depends on current MCU
# @parm Object project - Current project
# @return void
proc disena_simulator_menu {project} {
# Enable/Disable controls related to hexadecimal editors
ena_dis_menu_buttons 0 {{ ".mainMenu.virtual_mcu"
{ "Show XDATA memory" "Show ERAM" "Show EEPROM write buffer" "Show Data EEPROM"}
}}
ena_dis_iconBar_buttons 0 .mainIconBar. {
show_ext_mem show_exp_mem show_eeprom show_eem_wr_b
}
set toolbar {}
set mainmenu {}
if {[lindex [$project cget -procData] 8]} {
lappend toolbar {show_exp_mem}
lappend mainmenu {Show ERAM}
}
if {[$project cget -P_option_mcu_xdata]} {
lappend toolbar {show_ext_mem}
lappend mainmenu {Show XDATA memory}
}
if {[lindex [$project cget -procData] 32]} {
lappend toolbar {show_eeprom}
lappend toolbar {show_eem_wr_b}
lappend mainmenu {Show EEPROM write buffer}
lappend mainmenu {Show Data EEPROM}
}
ena_dis_menu_buttons 1 [list [list {.mainMenu.virtual_mcu} $mainmenu]]
ena_dis_iconBar_buttons 1 .mainIconBar. $toolbar
}
## Ensure than simulator isn't engaged
# @parm Bool message - Invoke error message if simulator is engaged
# @return Bool - result (1 == is engaged; 0 == is not engaged)
proc simulator_must_be_disabled {message} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProjectIdx ;# Index of the current project in $openedProjects
if {[lindex $simulator_enabled $actualProjectIdx] == {}} {
return 1
}
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
if {$message} {
tk_messageBox \
-parent . \
-title [mc "Unable to comply"] \
-icon info \
-type ok \
-message [mc "Simulator is engaged, shutdown the simulator first."]
}
return 1
}
return 0
}
## New file
# @return void
proc __new {} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# Use dialog "Open file" to create new file with embedded external editor
if {${::Editor::editor_to_use}} {
__open 1
return
}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Create new editor
$actualProject editor_new
set critical_procedure_in_progress 0
}
## Open file
# @parm Bool p_open_f_external_editor=0 - 1 == New file (for embedded external editor); 0 == Open an existing file
# @return void
proc __open {{p_open_f_external_editor 0}} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable open_f_external_editor ;# Bool: Use procedure __open to open new file for embedded external editor
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Parse input arguments
set open_f_external_editor $p_open_f_external_editor
if {$open_f_external_editor} {
set title [mc "New file - MCU 8051 IDE"]
} else {
set title [mc "Open file - MCU 8051 IDE"]
}
# Invoke the file selection dialog
switch -- [file extension [lindex [$actualProject editor_procedure {} getFileName {}] 1]] {
{.asm} {set defaultmask 0}
{.c} {set defaultmask 1}
{.h} {set defaultmask 2}
{.lst} {set defaultmask 3}
default {set defaultmask 4}
}
set directory [lindex [$actualProject editor_procedure {} getFileName {}] 0]
if {$directory == {.}} {
set directory [$actualProject cget -projectPath]
}
catch {delete object fsd}
KIFSD::FSD fsd \
-title $title -directory $directory \
-defaultmask $defaultmask -multiple 1 -filetypes [list \
[list [mc "Assembly language"] {*.asm}] \
[list [mc "C source"] {*.c}] \
[list [mc "C header"] {*.h}] \
[list [mc "Code listing"] {*.lst}] \
[list [mc "All files"] {*}] \
]
# Open file after press of OK button
fsd setokcmd {
foreach filename [X::fsd get] {
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $filename]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$filename"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $filename]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $filename]
}
}
set filename [file normalize $filename]
if {[file isdirectory $filename]} {
tk_messageBox \
-type ok \
-icon warning \
-parent . \
-title [mc "Operation aborted"] \
-message [mc "The file you choosed appears to be a directory:\n%s\n\nSuch an operation doesn't make sense." $filename]
continue
}
# Open the specified file
if {${::X::open_f_external_editor} || [file exists $filename]} {
if {[${::X::actualProject} openfile $filename 1 \
[X::fsd get_window_name] def def 0 0 {}] != {}
} then {
${::X::actualProject} switch_to_last
update idletasks
${::X::actualProject} editor_procedure {} parseAll {}
# Make LST read only
if {[file extension $filename] == {.lst}} {
set ::editor_RO_MODE 1
${::X::actualProject} switch_editor_RO_MODE
}
::X::recent_files_add 1 $filename
}
} else {
if {!${::Editor::editor_to_use}} {
tk_messageBox \
-type ok \
-icon warning \
-parent . \
-title [mc "File not found - MCU 8051 IDE"] \
-message [mc "The selected file do not exist:\n%s" $filename]
}
${::X::actualProject} editor_new
${::X::actualProject} save_as $filename 1
}
}
}
# activate the dialog
fsd activate
adjust_title
set critical_procedure_in_progress 0
}
## Save file
# @return void
proc __save {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Save file
$actualProject editor_procedure {} save {}
set critical_procedure_in_progress 0
}
## Save file under different filename
# @return void
proc __save_as {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Won't save read-only file
if {[$actualProject editor_procedure {} cget {-ro_mode}]} {
return
}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Invoke the dialog
set filename [$actualProject editor_procedure {} getFileName {}]
switch -- [file extension [lindex $filename 1]] {
{.asm} {set defaultmask 0}
{.c} {set defaultmask 1}
{.h} {set defaultmask 2}
default {set defaultmask 3}
}
set directory [lindex [$actualProject editor_procedure {} getFileName {}] 0]
if {$directory == {.}} {
set directory [$actualProject cget -projectPath]
}
catch {delete object fsd}
KIFSD::FSD fsd \
-initialfile [lindex $filename 1] \
-title [mc "Save file - MCU 8051 IDE"] \
-directory $directory \
-defaultmask $defaultmask -multiple 0 -filetypes [list \
[list [mc "Assembly language"] {*.asm}] \
[list [mc "C source"] {*.c}] \
[list [mc "C header"] {*.h}] \
[list [mc "All files"] {*}] \
]
# Save file after press of OK button
fsd setokcmd {
set filename [X::fsd get]
${::X::actualProject} save_as $filename
}
# activate the dialog
fsd activate
set critical_procedure_in_progress 0
}
## Save all opened file of the current project
# @return void
proc __save_all {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Save all opened files
$actualProject editor_save_all
set critical_procedure_in_progress 0
}
## Close the curent file
# @return void
proc __close {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Close file
$actualProject editor_close 1 {}
set critical_procedure_in_progress 0
}
## Close all opened files
# @return void
proc __close_all {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Close all files
$actualProject editor_close_all 1 0
set critical_procedure_in_progress 0
}
## Take back the last operation
# @return void
proc __undo {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Undo
$actualProject editor_procedure {} undo {}
}
## Take back the last undo operation
# @return void
proc __redo {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Redo
$actualProject editor_procedure {} redo {}
}
## Copy selected text to clipboard
# @return void
proc __copy {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Copy
$actualProject editor_procedure {} copy {}
}
## Cut selected text (copy to clipboard and remove)
# @return void
proc __cut {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Cut
$actualProject editor_procedure {} cut {}
}
## Paste text from clipboard
# @return void
proc __paste {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Paste
$actualProject editor_procedure {} paste {}
}
## Indent selected text or the current line
# @return void
proc __indent {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Indent
$actualProject editor_procedure {} indent {}
}
## Unindent selected text or the current line
# @return void
proc __unindent {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Unindent
$actualProject editor_procedure {} unindent {}
}
## Invoke find dialog
# @return void
proc __find {} {
variable actualProject ;# Object: Current project
variable find_String {} ;# Search string
variable find_option_CS ;# Bool: Case sensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable find_allow_selection ;# Bool: There is some selected text in editor
variable find_history ;# List of the last 10 search strings
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {${::Editor::editor_to_use}} {return}
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Determinate selected text
set selectedText [$actualProject editor_procedure {} getselection {}]
if {$selectedText != {}} {
set find_String $selectedText
}
# Create a new toplevel window for the dialog
set win [toplevel .find -class {Find dialog} -bg ${::COMMON_BG_COLOR}]
# String to search for
label $win.findLabel -compound left -image ::ICONS::16::find -text [mc "Text to find:"]
set findFrame [ttk::labelframe $win.findFrame \
-labelwidget $win.findLabel \
-relief flat \
]
pack $findFrame -fill x -expand 1 -pady 10 -padx 5
pack [ttk::combobox $findFrame.entry \
-textvariable X::find_String \
-exportselection 0 \
-values $find_history \
] -fill x -expand 1 -padx 10
DynamicHelp::add $findFrame.entry -text [mc "String to find"]
# Create and pack options labelframe
label $win.optionsLabel -compound left -image ::ICONS::16::configure -text [mc "Options"]
set optionsFrame [ttk::labelframe $win.optionsFrame \
-labelwidget $win.optionsLabel \
]
pack $optionsFrame -fill both -expand 1 -padx 10
# Determinate wheather there is some selected text
if {[$actualProject editor_procedure {} getselection {}] == {}} {
set find_allow_selection 0
} else {
set find_allow_selection 1
}
# Create matrix of option checkbuttons
set col 0 ;# Grid column
set row 0 ;# Grid row
foreach opt { CS back cur sel reg } \
txt { "Case sensitive" "Backwards" "From cursor" "Selected text" "Regular expr." } \
helptext {
"Case sensitive search"
"Search backwards from the specified location"
"Start search from cursor instead of beginning"
"Search within selected text only"
"Use search string as regular expression"
} \
{
# Disable/Enable "in selection" checkbox
if {$opt == {sel} && !$find_allow_selection} {
set state disabled
set X::find_option_sel 0
} else {
set state normal
}
# Create checkbutton
grid [checkbutton $optionsFrame.option_$opt \
-text [mc $txt] \
-variable X::find_option_$opt \
-state $state \
] -column $col -row $row -sticky wns
DynamicHelp::add $optionsFrame.option_$opt -text [mc $helptext]
incr col
if {$col == 2} {
set col 0
incr row
}
}
# Create and pack 'OK' and 'CANCEL' buttons
set buttonFrame [frame $win.buttonFrame]
pack [ttk::button $buttonFrame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::find_FIND} \
] -side left -padx 2
pack [ttk::button $buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::find_CANCEL} \
] -side left -padx 2
pack $buttonFrame -pady 5
# Events binding (Enter == Find; Escape == Cancel)
bind $win <KeyRelease-Return> {X::find_FIND; break}
bind $win <KeyRelease-KP_Enter> {X::find_FIND; break}
bind $win <KeyRelease-Escape> {X::find_CANCEL; break}
# Nessesary window manager options -- for modal window
wm iconphoto $win ::ICONS::16::find
wm title $win [mc "Find - MCU 8051 IDE"]
wm minsize $win 300 210
wm protocol $win WM_DELETE_WINDOW {
X::find_CANCEL
}
wm transient $win .
update
raise $win
catch {grab $win}
focus $findFrame.entry
catch {
$findFrame.entry.e selection range 0 end
}
tkwait window $win
}
## Cancel find dialog -- auxiliary procedure for '__find'
# @return void
proc find_CANCEL {} {
if {![winfo exists .find]} {return}
destroy .find
grab release .find
}
## Perform search -- auxiliary procedure for '__find'
# @return Bool - result
proc find_FIND {} {
variable actualProject ;# Object: Current project
variable find_allow_selection ;# Bool: There is some selected text in editor
variable find_String ;# Search string
variable find_forward_index ;# Search index for forward search
variable find_backward_index ;# Search index for backward search
variable find_option_CS ;# Bool: Case sensitive
variable find_option_notCS ;# Bool: Case insensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable find_retry_search ;# Bool: Search restarted from beginning/end
variable find_back_dir ;# Bool: Search backwards (real option)
variable find_history ;# List of the last 10 search strings
# Append search string to history
if {[lsearch -exact -ascii $find_history $find_String] == -1} {
lappend find_history $find_String
}
# History mustn't contain more than 10 items
if {[llength $find_history] > 10} {
set find_history [lrange $find_history [expr {[llength $find_history] - 10}] end]
}
# New search
set find_retry_search 0 ;# Search has not been restarted
set find_back_dir $find_option_back ;# Search backwards/forwards
# Cancel the find dialog
find_CANCEL
# Check for validity of the search string
if {$find_String == {}} {
return 0
}
# Adjust option "Search in selected text"
set find_option_notCS [expr {!$find_option_CS}]
if {!$find_allow_selection} {
set option_sel 0
} else {
set option_sel $find_option_sel
}
# Perform search
set result [$actualProject editor_procedure {} find [list \
$find_option_cur $find_option_back \
$find_option_reg $find_option_notCS \
$option_sel {} \
$find_String]]
# Search failed -> show error message
if {[lindex $result 0] == -1} {
tk_messageBox -icon warning \
-parent . -type ok \
-title [mc "Unable to execute"] \
-message [lindex $result 1]
return 0
}
# Set search indexes
set find_backward_index [lindex $result 0]
set find_forward_index [lindex $result 1]
# Finalize
set matches [lindex $result 2]
Sbar [mc "Search result: %s matches found" $matches] ;# Show final result
if {$matches == 0} retry_search ;# Ask for retry
# Success
return 1
}
## Retry search -- auxiliary procedure for '__find'
# Useful when search cursor reach beginning/end of the document
# @return Bool result
proc retry_search {} {
variable find_retry_search ;# Bool: Search restarted from beginning/end
variable find_String ;# Search string
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_backward_index ;# Search index for backward search
variable find_forward_index ;# Search index for forward search
variable find_back_dir ;# Bool: Search backwards (real option)
variable find_next_prev_in_P ;# Bool: Procedure 'find_next_prev' in progress
# There is only one allowed retry
if {$find_retry_search || !$find_option_cur} {
set find_retry_search 0
tk_messageBox \
-icon warning \
-type ok \
-title [mc "Find - %s" ${::APPNAME}] \
-message [mc "Search string '%s' not found !" $find_String] \
-parent .
set find_next_prev_in_P 0
return
}
set find_option_cur_tmp $find_option_cur ;# Search cursor
set find_retry_search 1 ;# This is the first retry
# Backward search
if {$find_back_dir} {
if {[tk_messageBox \
-icon question \
-type yesno \
-parent . \
-title [mc "Find - %s" ${::APPNAME}] \
-message [mc "Beginning of document reached\n\nContinue from end ?"] \
] == {yes}} then {
set find_next_prev_in_P 0
set find_backward_index end
set find_forward_index 1.0
set find_option_cur 0
# Retry search
find_next_prev [expr {!$find_option_back}]
}
# Forward search
} else {
if {[tk_messageBox \
-icon question \
-type yesno \
-parent . \
-title [mc "Find - %s" ${::APPNAME}] \
-message [mc "End of document reached\n\nContinue from beginning ?"] \
] == {yes}} then {
set find_next_prev_in_P 0
set find_backward_index end
set find_forward_index 1.0
set find_option_cur 0
# Retry search
find_next_prev $find_option_back
}
}
set find_next_prev_in_P 0
set find_option_cur $find_option_cur_tmp
set find_retry_search 0
}
## Find next occurrence of the search string
# @return void
proc __find_next {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Perform search
find_next_prev 0
}
## Find previous occurrence of the search string
# @return void
proc __find_prev {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Perform search
find_next_prev 1
}
## Find next/previous occurrence of the search string
# @parm Bool back_dir - Search backwards
# @return void
proc find_next_prev {back_dir} {
variable actualProject ;# Object: Current project
variable find_String ;# Search string
variable find_backward_index ;# Search index for backward search
variable find_forward_index ;# Search index for forward search
variable find_option_notCS ;# Bool: Case insensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable find_retry_search ;# Bool: Search restarted from beginning/end
variable find_back_dir ;# Bool: Search backwards (real option)
variable find_next_prev_in_P ;# Bool: Procedure 'find_next_prev' in progress
# This function is not available for exeternal embedded editors
if {${::Editor::editor_to_use}} {return}
# This function cannot run multithreaded
if {$find_next_prev_in_P} {return}
set find_next_prev_in_P 1
# Check for valid search index
if {![info exists find_backward_index]} {
Sbar [mc "Editor: Nothing to search ..."]
set find_next_prev_in_P 0
return
}
# Determinate direction
set find_back_dir [expr {$find_option_back ^ $back_dir}]
# Determinate start index
if {$find_option_cur} {
set editor [[$actualProject get_current_editor_object] cget -editor]
if {$find_back_dir} {
if {[$editor compare $find_forward_index == insert]} {
$editor mark set insert $find_backward_index
}
} else {
if {[$editor compare $find_backward_index == insert]} {
$editor mark set insert $find_forward_index
}
}
set index insert
} else {
if {$find_back_dir} {
set index $find_backward_index
} else {
set index $find_forward_index
}
}
# Perform search
set result [$actualProject editor_procedure {} find [list \
$find_option_cur $find_back_dir \
$find_option_reg $find_option_notCS \
$find_option_sel $index \
$find_String]]
# Set search indexes
set find_backward_index [lindex $result 0]
set find_forward_index [lindex $result 1]
# Finalize
set matches [lindex $result 2]
Sbar [mc "Search result: %s matches found" $matches] ;# Show final result
if {$matches == 0} retry_search ;# Retry search if this one failed
set find_next_prev_in_P 0
}
## Invoke dialog to replace one string with another (in editor)
# @return void
proc __replace {} {
variable actualProject ;# Object: Current project
variable replace_String {} ;# String to replace
variable replace_Replacement {} ;# Replacement for the search string
variable replace_option_CS ;# Bool: Case sensitive
variable replace_option_back ;# Bool: Search backwards (checkbox)
variable replace_option_cur ;# Book: Search from cursor
variable replace_option_reg ;# Bool: Consider search string to be a regular expression
variable replace_option_prompt ;# Bool: Prompt on replace
variable replace_search_history ;# List of the last 10 search strings
variable replace_repl_history ;# List of the last 10 replacement strings
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {${::Editor::editor_to_use}} {return}
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} {return}
if {$critical_procedure_in_progress} {return}
# Determinate selected text
set selectedText [$actualProject editor_procedure {} getselection {}]
if {$selectedText != {}} {
set replace_String $selectedText
}
# Create a new toplevel window for the dialog
set win [toplevel .replace -class {Replace dialog} -bg ${::COMMON_BG_COLOR}]
# Create labelframe "String to find"
label $win.findLabel -compound left -image ::ICONS::16::find -text [mc "Text to find: "]
set findFrame [ttk::labelframe $win.findFrame \
-labelwidget $win.findLabel \
-relief flat \
]
pack $findFrame -fill x -expand 1 -pady 10 -padx 5
pack [ttk::combobox $findFrame.entry \
-textvariable X::replace_String \
-exportselection 0 \
-values $replace_search_history \
] -fill x -expand 1 -padx 10
DynamicHelp::add $findFrame.entry -text [mc "String to replace"]
pack $findFrame
# Create labelframe "Replace with"
set replaceFrame [ttk::labelframe $win.replaceFrame \
-text [mc "Replace with:"] \
-relief flat \
]
pack $replaceFrame -fill x -expand 1 -pady 5 -padx 5
pack [ttk::combobox $replaceFrame.entry \
-textvariable X::replace_Replacement \
-exportselection 0 \
-values $replace_repl_history \
] -fill x -expand 1 -padx 10
DynamicHelp::add $replaceFrame.entry -text [mc "Replacement for search string"]
# Create and pack options checkboxes labelframe
label $win.optionsLabel -compound left -image ::ICONS::16::configure -text [mc "Options"]
set optionsFrame [ttk::labelframe $win.optionsFrame \
-labelwidget $win.optionsLabel \
]
pack $optionsFrame -fill both -expand 1 -padx 10
# Create matrix of option checkboxes
set col 0 ;# Grid column
set row 0 ;# Grid row
foreach opt { CS back cur reg prompt} \
txt { "Case sensitive" "Backwards" "From cursor" "Regular expr." "Prompt on replace"} \
helptext {
"Case sensitive search"
"Search backwards from the specified location"
"Start search from cursor instead of beginning"
"Use search string as regular expression"
"Prompt on replace"
} \
{
# Create checkbutton
grid [checkbutton $optionsFrame.option_$opt \
-text [mc $txt] \
-variable X::replace_option_$opt \
] -column $col -row $row -sticky wns
DynamicHelp::add $optionsFrame.option_$opt -text [mc $helptext]
incr col
if {$col == 2} {
set col 0
incr row
}
}
# Create and pack 'OK' and 'CANCEL' buttons
set buttonFrame [frame $win.buttonFrame]
pack [ttk::button $buttonFrame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::replace_REPLACE} \
] -side left -padx 2
pack [ttk::button $buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::replace_CANCEL} \
] -side left -padx 2
pack $buttonFrame -pady 5
# Events binding (Enter == Replace; Escape == Cancel)
bind $win <KeyRelease-Return> {X::replace_REPLACE; break}
bind $win <KeyRelease-KP_Enter> {X::replace_REPLACE; break}
bind $win <KeyRelease-Escape> {X::replace_CANCEL; break}
# Nessesary window manager options -- for modal window
wm iconphoto $win ::ICONS::16::find
wm title $win [mc "Replace - MCU 8051 IDE"]
wm minsize $win 300 270
wm protocol $win WM_DELETE_WINDOW {
X::replace_CANCEL
}
wm transient $win .
update
raise $win
catch {grab $win}
focus $findFrame.entry
catch {
$findFrame.entry.e selection range 0 end
}
tkwait window $win
}
## Perform replacement -- auxiliary procedure for '__replace'
# @return Bool - result
proc replace_REPLACE {} {
variable actualProject ;# Object: Current project
variable replace_String ;# String to replace
variable replace_Replacement ;# Replacement for the search string
variable replace_option_CS ;# Bool: Case sensitive
variable replace_option_back ;# Bool: Search backwards (checkbox)
variable replace_option_cur ;# Book: Search from cursor
variable replace_option_reg ;# Bool: Consider search string to be a regular expression
variable replace_option_prompt ;# Bool: Prompt on replace
variable replace_search_history ;# List of the last 10 search strings
variable replace_repl_history ;# List of the last 10 replacement strings
# Append search string to history
if {[lsearch -exact -ascii $replace_search_history $replace_String] == -1} {
lappend replace_search_history $replace_String
}
# History mustn't contain more than 10 items
if {[llength $replace_search_history] > 10} {
set replace_search_history [lrange $replace_search_history \
[expr {[llength $replace_search_history] - 10}] end]
}
# Append replace string to history
if {[lsearch -exact -ascii $replace_repl_history $replace_Replacement] == -1} {
lappend replace_repl_history $replace_Replacement
}
# History mustn't contain more than 10 items
if {[llength $replace_repl_history] > 10} {
set replace_repl_history [lrange \
$replace_repl_history \
[expr {[llength $replace_repl_history] - 10}] \
end \
]
}
# Cancel the replace dialog
replace_CANCEL
# Perform replacement
set replace_option_notCS [expr {!$replace_option_CS}]
if {![$actualProject editor_procedure {} replace [list \
$replace_option_cur $replace_option_back \
$replace_option_reg $replace_option_notCS \
$replace_String $replace_Replacement \
$replace_option_prompt X::replace_prompt]
]} then {
if {!$replace_option_cur} {return}
set replace_option_cur_tmp $replace_option_cur
set replace_option_cur 0
# Retry search
if {$replace_option_back} {
if {[tk_messageBox \
-icon question \
-type yesno \
-parent . \
-title [mc "Replace - %s" ${::APPNAME}] \
-message [mc "Beginning of document reached\n\nContinue from end ?"] \
]} then {
replace_REPLACE
}
} else {
if {[tk_messageBox \
-icon question \
-type yesno \
-parent . \
-title [mc "Replace - %s" ${::APPNAME}] \
-message [mc "End of document reached\n\nContinue from beginning ?"] \
]} then {
replace_REPLACE
}
}
set replace_option_cur $replace_option_cur_tmp
}
}
## Cancel replace dialog -- auxiliary procedure for '__replace'
# @return bool
proc replace_CANCEL {} {
destroy .replace
grab release .replace
}
## Invoke dialog "Replace confirmation"
# @return bool
proc replace_prompt {} {
variable replace_prompt_opened ;# Bool: Replace prompt dialog opened
variable replace_prompt_return_value ;# Replace prompt dialog return value
variable replace_prompt_geometry ;# Geometry of replace prompt dialog window
# Dialog already opened -> close it
if {$replace_prompt_opened} {
replace_prompt_DESTROY
# Open the dialog
} else {
set replace_prompt_opened 1
# Create dialog window and restore previous geometry
toplevel .replace_prompt -class {Replace prompt dialog} -bg ${::COMMON_BG_COLOR}
if {[info exists replace_prompt_geometry]} {
wm geometry .replace_prompt $replace_prompt_geometry
}
# Create window header
pack [frame .replace_prompt.topFrame] -fill x -expand 1
pack [label .replace_prompt.topFrame.image \
-image ::ICONS::32::help \
] -side left -padx 10
pack [label .replace_prompt.topFrame.label \
-text [mc "Found an occurrence of your search term.\nWhat do you want to do ?"] \
] -fill both -expand 1 -side right
# Create separator
pack [ttk::separator .replace_prompt.separator -orient horizontal] -fill x -expand 1
pack [frame .replace_prompt.buttonFrame] -fill x -expand 1
# Create buttuns
foreach id { repl relp_close repl_all find_next close } \
text { "Replace" "Replace & close" "Replace all" "Find next" "Close" } \
val { 0 1 2 3 4 } \
under { 0 2 8 0 0 } {
pack [ttk::button .replace_prompt.buttonFrame.$id \
-text [mc $text] -underline $under \
-command "X::replace_prompt_return $val;set wait 1;unset wait" \
] -fill x -expand 1 -side left -padx 5
}
# Set key-events bindings
bind .replace_prompt <Alt-Key-r> {
X::replace_prompt_return 0
set wait 1
unset wait
break
}
bind .replace_prompt <Alt-Key-p> {
X::replace_prompt_return 1
set wait 1
unset wait
break
}
bind .replace_prompt <Alt-Key-a> {
X::replace_prompt_return 2
set wait 1
unset wait
break
}
bind .replace_prompt <Alt-Key-f> {
X::replace_prompt_return 3
set wait 1
unset wait
break
}
bind .replace_prompt <Alt-Key-c> {
X::replace_prompt_return 4
set wait 1
unset wait
break
}
# Nessesary window manager options -- modal window
wm iconphoto .replace_prompt ::ICONS::16::help
wm title .replace_prompt [mc "Replace confirmation - %s" ${::APPNAME}]
wm minsize .replace_prompt 480 100
wm protocol .replace_prompt WM_DELETE_WINDOW {
X::replace_prompt_DESTROY
}
wm transient .replace_prompt .
raise .replace_prompt
vwait ::wait
return $replace_prompt_return_value
}
}
## Cancel replace prompt dialog -- auxiliary procedure for 'replace_prompt'
# @return bool
proc replace_prompt_DESTROY {} {
variable replace_prompt_opened ;# Bool: Replace prompt dialog opened
variable replace_prompt_geometry ;# Geometry of replace prompt dialog window
# Save the current dialog geometry
set replace_prompt_geometry [wm geometry .replace_prompt]
# Destroy dislog window
destroy .replace_prompt
set replace_prompt_opened 0
}
## Cancel replace prompt dialog and set its return value
# @parm Int val - result value of the dialog
# @return void
proc replace_prompt_return {val} {
variable replace_prompt_return_value ;# Replace prompt dialog return value
set replace_prompt_return_value $val
replace_prompt_DESTROY
}
## Select all text in the editor
# @return void
proc __select_all {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Select all
$actualProject editor_procedure {} select_all {}
}
## Invoke dialog "Go to"
# If simulator is engaged the run this: __simulator_set_PC_by_line
# @return void
proc __goto {} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable goto ;# Line where to go
variable editor_lines ;# Number of lines in the current editor
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable simulator_enabled ;# List of booleans: Simulator engaged
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
__simulator_set_PC_by_line
return
}
set goto [$actualProject editor_actLineNumber]
set editor_lines [$actualProject editor_linescount]
# Create dialog window
set goto_opened 1
set win [toplevel .goto -class {Go to dialog} -bg ${::COMMON_BG_COLOR}]
# Create window label frame
label $win.header -text [mc "Go to line"] -image ::ICONS::16::goto -compound left
set topFrame [ttk::labelframe $win.topFrame -labelwidget $win.header -relief flat]
pack $topFrame -expand 1 -fill x -padx 10
# Create scale widget
pack [ttk::scale $topFrame.scale \
-from 1 -to $editor_lines \
-orient horizontal \
-variable X::goto \
-command "
set ::X::goto \[expr {int(\${::X::goto})}\]
$topFrame.spinbox selection range 0 end
#" \
] -side left -expand 1 -fill x -padx 2
DynamicHelp::add $topFrame.scale \
-text [mc "Graphical representation of line where to go"]
# Create spinbox widget
pack [ttk::spinbox $topFrame.spinbox \
-from 1 -to $editor_lines \
-textvariable ::X::goto \
-validate key \
-validatecommand {::X::goto_validate %P}\
-width 6 \
] -side left
DynamicHelp::add $topFrame.spinbox -text [mc "Line where to go"]
# Create and pack 'OK' and 'CANCEL' buttons
set buttonFrame [frame .goto.buttonFrame]
pack [ttk::button $buttonFrame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::goto_OK} \
] -side left -padx 2
pack [ttk::button $buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::goto_CANCEL} \
] -side left -padx 2
pack $buttonFrame -pady 5 -padx 5
# Events binding (Enter == Ok, Esc == CANCEL)
bind $win <KeyRelease-Return> {X::goto_OK; break}
bind $win <KeyRelease-KP_Enter> {X::goto_OK; break}
bind $win <KeyRelease-Escape> {X::goto_CANCEL; break}
# Focus on the Spinbox
focus $topFrame.spinbox
$topFrame.spinbox selection range 0 end
# Nessesary window manager options -- modal window
wm iconphoto $win ::ICONS::16::goto
wm title $win [mc "Go to line - MCU 8051 IDE"]
wm minsize $win 200 100
wm protocol $win WM_DELETE_WINDOW {
X::goto_CANCEL
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Validate value of spinbox in the Go to dialog -- auxiliary procedure for '__goto'
# @parm
# @return bool
proc goto_validate {value} {
variable editor_lines ;# Number of lines in the current editor
if {$value > $editor_lines} {
return 0
} else {
return 1
}
}
## Cancel Go to dialog -- auxiliary procedure for '__goto'
# @return bool
proc goto_CANCEL {} {
destroy .goto
grab release .goto
}
## Go to line -- auxiliary procedure for '__goto'
# @return bool
proc goto_OK {} {
variable actualProject ;# Object: Current project
variable goto ;# Line where to go
# Go to the specified line
$actualProject editor_procedure {} goto $goto
# Destroy dialog window
goto_CANCEL
}
## Comment block of selected text in the editor
# @return void
proc __comment {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} {return}
if {$critical_procedure_in_progress} {return}
# Comment
$actualProject editor_procedure {} comment {}
}
## Uncomment block of selected text in the editor
# @return void
proc __uncomment {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Uncomment
$actualProject editor_procedure {} uncomment {}
}
## Reload the current file
# @return void
proc __reload {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} return
if {$critical_procedure_in_progress} {return}
# Reload
$actualProject filelist_reload_file
}
## Invoke directory selection dialog
# @parm Widget master - GUI parent
# @return void
proc select_directory {master} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
variable select_directory_var {} ;# Selected directory
variable defaultDirectory ;# Default directory
# Determinate initial directory
if {$project_menu_locked} {
set directory {~}
} else {
set directory [$actualProject cget -projectPath]
}
# Invoke the dialog
catch {delete object fsd}
KIFSD::FSD fsd \
-title [mc "Choose directory - MCU 8051 IDE"] \
-directory $directory -fileson 0 -master $master
# Save choice to variable select_directory_var
fsd setokcmd {
set X::select_directory_var [X::fsd get]
}
fsd activate ;# Activate the dialog
# Return path to the selected directory
return $select_directory_var
}
## Invoke dialog "New Project"
# @return void
proc __proj_new {} {
variable available_processors ;# List of supported processors
variable actualProject ;# Object: Current project
variable project_new_name {} ;# Name of the new project
variable project_new_dir {} ;# Directory of the new project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_new_processor {AT89S52};# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena 0 ;# Bool: XDATA memory connected
variable project_new_xcode_ena 0 ;# Bool: XCODE memory connected
variable project_new_xdata 0 ;# Int: Amount of XDATA memory
variable project_new_xcode 0 ;# Int: Amount of XCODE memory
variable project_new_max_xcode 0 ;# Int: Maximum valid value of external program memory
variable project_new_xd_chb ;# Widget: XDATA enable checkbutton
variable project_new_xd_scl ;# Widget: XDATA scale
variable project_new_xd_spb ;# Widget: XDATA spinbox
variable project_new_xc_chb ;# Widget: XCODE enable checkbutton
variable project_new_xc_scl ;# Widget: XCODE scale
variable project_new_xc_spb ;# Widget: XCODE spinbox
if {$critical_procedure_in_progress} {return}
# Create dialog window
set win [toplevel .project_new -class {New project} -bg ${::COMMON_BG_COLOR}]
# Create window header (text and some icon)
set header [frame $win.header]
pack [label $header.image -image ::ICONS::32::wizard] -padx 10 -side left
pack [label $header.text \
-text [mc "Create a new project.\n All entries are required. Other options --> edit project."] \
] -side left -expand 1 -fill x
pack $header -fill both -expand 1
# Create labelframe "General"
set genaral_labelframe [ttk::labelframe $win.general -text [mc "General"]]
# Entry "Project name"
set name [ttk::labelframe $genaral_labelframe.name \
-text [mc "Project name"] \
-relief flat \
]
pack [ttk::entry $name.entry \
-textvariable X::project_new_name \
-width 20 \
] -fill x -expand 1
DynamicHelp::add $name.entry -text [mc "Name of XML file representing the project"]
pack $name -fill x -expand 1 -padx 10 -pady 5
# Entry "Project directory"
set dir [ttk::labelframe $genaral_labelframe.dir \
-text [mc "Project directory"] \
-relief flat \
]
pack [ttk::entry $dir.entry \
-textvariable X::project_new_dir \
-width 20 \
] -side left -fill x -expand 1
DynamicHelp::add $dir.entry -text [mc "Directory where the project file should be located"]
pack [ttk::button $dir.choose \
-image ::ICONS::16::fileopen \
-style Flat.TButton \
-command {
set foo [X::select_directory .project_new]
if {$foo != {}} {
set X::project_new_dir $foo
}
unset foo
} \
] -side left
DynamicHelp::add $dir.choose -text [mc "Choose destination location"]
pack $dir -fill x -expand 1 -padx 10 -pady 5
pack $genaral_labelframe -fill both -expand 1 -pady 10 -padx 10
# Create labelframe "Processor"
set proc_frame [ttk::labelframe $win.proc_frame -text [mc "Processor"]]
set proc_frame_top [frame $proc_frame.top]
set proc_frame_middle [frame $proc_frame.middle]
set proc_frame_middle_left [ttk::labelframe $proc_frame_middle.middle \
-padding 5 -text [mc "External RAM (XDATA)"]]
set proc_frame_middle_right [ttk::labelframe $proc_frame_middle.right \
-padding 5 -text [mc "External ROM/FLASH (XCODE)"]]
# Create components of top frame (Type: <ComboBox> <Button>)
pack [label $proc_frame_top.lbl -text [mc "Type:"]] -side left
pack [ttk::combobox $proc_frame_top.combo \
-values $available_processors \
-state readonly \
-textvariable ::X::project_new_processor \
] -side left -fill x -fill x
bind $proc_frame_top.combo <<ComboboxSelected>> {::X::proj_new_mcu_changed}
DynamicHelp::add $proc_frame_top.combo -text [mc "Selected uC"]
pack [ttk::button $proc_frame_top.but \
-text [mc "Select MCU"] \
-image ::ICONS::16::back \
-compound left \
-command {::X::proj_new_select_mcu .project_new} \
] -side right -after $proc_frame_top.combo -padx 10
DynamicHelp::add $proc_frame_top.but -text [mc "Choose processor from database"]
# Create components of XDATA labelframe
set project_new_xd_chb [checkbutton $proc_frame_middle_left.checkbutton \
-variable ::X::project_new_xdata_ena \
-text [mc "Enable"] \
-command ::X::proj_new_xdata_disena \
]
pack $project_new_xd_chb -anchor w
DynamicHelp::add $proc_frame_middle_left.checkbutton \
-text [mc "Connect external data memory"]
set proc_frame_left_btm [frame $proc_frame_middle_left.btm]
set project_new_xd_scl [ttk::scale $proc_frame_left_btm.scale \
-orient horizontal \
-variable ::X::project_new_xdata \
-from 0 -to 0x10000 \
-command "
set ::X::project_new_xdata \[expr {int(\${::X::project_new_xdata})}\]
$proc_frame_left_btm.spinbox selection range 0 end
#" \
]
DynamicHelp::add $project_new_xd_scl \
-text [mc "Amount of external data memory"]
pack $project_new_xd_scl -fill x -side left -expand 1 -padx 2
set project_new_xd_spb [ttk::spinbox $proc_frame_left_btm.spinbox \
-textvariable ::X::project_new_xdata \
-width 5 -from 0 -to 0x10000 \
-validate all \
-validatecommand {::SelectMCU::validate_xdata %P} \
]
DynamicHelp::add $project_new_xd_spb \
-text [mc "Amount of external data memory"]
pack $project_new_xd_spb -side right -after $project_new_xd_scl
pack $proc_frame_left_btm -fill both -expand 1
# Create components of XCODE labelframe
set project_new_xc_chb [checkbutton $proc_frame_middle_right.checkbutton \
-variable ::X::project_new_xcode_ena \
-text [mc "Enable"] \
-command ::X::proj_new_xcode_disena \
]
pack $project_new_xc_chb -anchor w
DynamicHelp::add $proc_frame_middle_right.checkbutton \
-text [mc "Connect external program memory"]
set proc_frame_right_btm [frame $proc_frame_middle_right.btm]
set project_new_xc_scl [ttk::scale $proc_frame_right_btm.scale \
-orient horizontal \
-variable ::X::project_new_xcode \
-from 0 -to 0x10000 \
-command "
set ::X::project_new_xcode \[expr {int(\${::X::project_new_xcode})}\]
$proc_frame_right_btm.spinbox selection range 0 end
#" \
]
DynamicHelp::add $project_new_xc_scl \
-text [mc "Amount of total program memory minus internal program memory"]
pack $project_new_xc_scl -fill x -side left -expand 1 -padx 2
set project_new_xc_spb [ttk::spinbox $proc_frame_right_btm.spinbox \
-textvariable ::X::project_new_xcode \
-width 5 -from 0 -to 0x10000 \
-validate all \
-validatecommand {::X::proj_new_validate_xcode %P} \
]
DynamicHelp::add $project_new_xc_spb \
-text [mc "Amount of total program memory minus internal program memory"]
pack $project_new_xc_spb -side right -after $project_new_xc_scl
pack $proc_frame_right_btm -fill both -expand 1
pack $proc_frame_top -anchor w -pady 10 -padx 10 -fill x
pack $proc_frame_middle_left -side left -fill x -expand 1 -padx 7
pack $proc_frame_middle_right -side left -fill x -expand 1 -padx 7
pack $proc_frame_middle -fill both -expand 1 -pady 5
pack $proc_frame -fill both -expand 1 -padx 10 -pady 10
# Create 'OK' and 'CANCEL' buttons
set buttonFrame [frame $win.buttonFrame]
pack [ttk::button $buttonFrame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::project_new_OK} \
] -side left -padx 2
pack [ttk::button $buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::project_new_CANCEL} \
] -side left -padx 2
pack $buttonFrame -pady 5
focus -force $name.entry
# Adjust XDATA & XCODE controls
proj_new_mcu_changed
# Events binding (Enter == Ok; Escape == Cancel)
bind $win <Key-Return> {X::project_new_OK; break}
bind $win <Key-KP_Enter> {X::project_new_OK; break}
bind $win <Key-Escape> {X::project_new_CANCEL; break}
# Nessesary window manager options -- modal window
wm iconphoto $win ::ICONS::16::filenew
wm title $win [mc "New project - MCU 8051 IDE"]
wm minsize $win 400 400
wm protocol $win WM_DELETE_WINDOW {
X::project_new_CANCEL
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Binding for processor type combobox -modifycmd
# Usage: ComboBox -modifycmd ::X::proj_new_mcu_changed
# This function gets informations about selected processor
# and adjusts XCODE & XDATA memory controls.
# @return void
proc proj_new_mcu_changed {} {
variable project_new_processor ;# Processor type (e.g. "8051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_max_xcode ;# Int: Maximum valid value of external program memory
variable project_new_xd_chb ;# Widget: XDATA enable checkbutton
variable project_new_xc_chb ;# Widget: XCODE enable checkbutton
variable project_new_xc_scl ;# Widget: XCODE scale
variable project_new_xc_spb ;# Widget: XCODE spinbox
# Get processor details
set details [::SelectMCU::get_processor_details $project_new_processor]
if {$details == {}} {
puts stderr "Unknown error occurred in ::X::proj_new_mcu_changed !\nPlease check your installation."
return
}
# Enable/Disable XDATA memory enable checkbutton
if {[lindex $details 0] != {yes}} {
set project_new_xdata_ena 0
$project_new_xd_chb configure -state disabled
} else {
$project_new_xd_chb configure -state normal
}
# Enable/Disable XCODE memory enable checkbutton
if {[lindex $details 1] != {yes}} {
set project_new_xcode_ena 0
$project_new_xc_chb configure -state disabled
} else {
$project_new_xc_chb configure -state normal
}
# Adjust XCODE memory scale & spinbox maximum value
set project_new_max_xcode [expr {0x10000 - ([lindex $details 2] * 1024)}]
$project_new_xc_scl configure -to $project_new_max_xcode
$project_new_xc_spb configure -to $project_new_max_xcode
# Enable/Disable XDATA & XCODE scale + XDATA & XCODE spinbox
proj_new_xdata_disena
proj_new_xcode_disena
}
## Enable/Disable XDATA scale & spinbox according to $project_new_xdata_ena
# @return void
proc proj_new_xdata_disena {} {
variable project_new_xd_scl ;# Widget: XDATA scale
variable project_new_xd_spb ;# Widget: XDATA spinbox
variable project_new_xdata_ena ;# Bool: XDATA memory connected
# Enable
if {$project_new_xdata_ena} {
$project_new_xd_scl state !disabled
$project_new_xd_spb configure -state normal
# Disable
} else {
$project_new_xd_scl state disabled
$project_new_xd_spb configure -state disabled
}
}
## Enable/Disable XCODE scale & spinbox according to $project_new_xcode_ena
# @return void
proc proj_new_xcode_disena {} {
variable project_new_xc_scl ;# Widget: XCODE scale
variable project_new_xc_spb ;# Widget: XCODE spinbox
variable project_new_xcode_ena ;# Bool: XCODE memory connected
# Enable
if {$project_new_xcode_ena} {
$project_new_xc_scl state !disabled
$project_new_xc_spb configure -state normal
# Disable
} else {
$project_new_xc_scl state disabled
$project_new_xc_spb configure -state disabled
}
}
## Validate content of XCODE spinbox
# @parm String string - string to validate
# @return Bool - true if validation successful
proc proj_new_validate_xcode {string} {
variable project_new_max_xcode ;# Int: Maximum valid value of external program memory
if {![string is digit $string]} {
return 0
}
if {$string == {}} {
return 1
}
if {$string < 0 || $string > $project_new_max_xcode} {
return 0
}
return 1
}
## Invoke MCU selection dialog
# @parm Widget win - parent window
# @return void
proc proj_new_select_mcu {win} {
variable project_new_processor ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
# Determinate initial XDATA memory for the dialog
if {$project_new_xdata_ena} {
set xdata $project_new_xdata
} else {
set xdata 0
}
# Determinate initial XCODE memory for the dialog
if {$project_new_xcode_ena} {
set xcode $project_new_xcode
} else {
set xcode 0
}
# Invoke dialog
set result [SelectMCU::activate $win [list $project_new_processor $xdata $xcode]]
if {$result == {}} {
return
}
# Process results
set project_new_processor [lindex $result 0]
set project_new_xdata [lindex $result 1]
set project_new_xcode [lindex $result 2]
# Adjust XCODE & XDATA checkbuttons
if {$project_new_xdata} {
set project_new_xdata_ena 1
} else {
set project_new_xdata_ena 0
}
if {$project_new_xcode} {
set project_new_xcode_ena 1
} else {
set project_new_xcode_ena 0
}
proj_new_mcu_changed
}
## Cancel dialog "Create new project" -- auxiliary procedure for '__proj_new'
# @return void
proc project_new_CANCEL {} {
grab release .project_new
destroy .project_new
}
## Create new project -- auxiliary procedure for '__proj_new'
# @return void
proc project_new_OK {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
variable project_new_name ;# Name of the new project
variable project_new_dir ;# Directory of the new project
variable project_edit_defaults ;# Some default project values
variable project_edit_clock ;# Default clock rate
variable simulator_enabled ;# List of booleans: Simulator engaged
variable openedProjects ;# List of opened projects (Object references)
variable project_new_processor ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
# This is critical procedure
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check for presence of all nessesary informations
if {$project_new_dir == {} || $project_new_name == {}} {
tk_messageBox \
-icon warning \
-type ok \
-title [mc "Invalid request"] \
-message [mc "Both entries in section general must be filled."] \
-parent .project_new
set critical_procedure_in_progress 0
return 0
}
# Adjust project directory
regsub {[\\\/]$} $project_new_dir {} project_new_dir
# Check for validity of the specified directory
if {![file exists $project_new_dir] || ![file isdirectory $project_new_dir]} {
# Ask for creating a new directory
set result [tk_messageBox \
-icon question \
-type yesno \
-parent .project_new \
-title [mc "Create directory - MCU 8051 IDE"] \
-message [mc "The specified directory does not exist do you want to create it ?"] \
]
if {$result == {yes}} {
# (Yes) -> Create new directory
if {[catch {file mkdir $project_new_dir}]} {
tk_messageBox \
-icon error \
-parent .project_new \
-type ok \
-title [mc "File access error"] \
-message [mc "Creation of directory '%s' FAILED !\nPlease check your permissions." $project_new_dir]
set critical_procedure_in_progress 0
return 0
}
# (No) -> Cancel
} else {
set critical_procedure_in_progress 0
return 0
}
} else {
# Check if this the project does not already exist
if {[file exists "$project_new_dir/$project_new_name.mcu8051ide"]} {
# Ask for owerwrite
if {
[tk_messageBox \
-icon question \
-type yesno \
-default no \
-parent .project_new \
-title [mc "File already exists - MCU 8051 IDE"] \
-message [mc "Some project with the same name already exists in the specified directory. \nDo you want to overwrite it ?"] \
] != {yes}
} then {
# (No) -> Cancel
set critical_procedure_in_progress 0
return 0
}
}
}
# Close the dialog window
project_new_CANCEL
# Set project values to defaults
foreach default $project_edit_defaults {
switch -- [lindex $default 0] {
{project_edit_calc_rad} {
set calc_radix [lindex $default 1]
}
{project_edit_calc_ang} {
set calc_angle [lindex $default 1]
}
default {
set [lindex $default 0] [lindex $default 1]
}
}
}
set project_new_xdata [expr {int($project_new_xdata)}]
set project_new_xcode [expr {int($project_new_xcode)}]
## Format of this list is: {
#+ {version date creator_ver} # tag: tk_mcuide_project
#+ {authors copyright license} # tag: authors copyright license
#+ {type clock xdata xcode} # tag: processor
#+ {watches_file scheme main_file auto_sw_enabled} # tag: options
#+ {grid_mode magnification drawing_on
#+ mark_flags_true_state mark_flags_latched
#+ mark_flags_output active_page} # tag: graph
#+ {description todo} # tag: descriptin todo
#+ {radix angle_unit # tag: calculator
#+ display0 display1 display2
#+ memory0 memory1 memory2
#+ frequency time mode}
#+ {other_options} # tag: other_options
#+ {compiler_options}
#+ {files_count {current_file # tag: files
#+ current_file2 pwin_sash pwin_orient}
#+ { # tag: file actual_line md5_hash path bookmarks breakpoints
#+ name active o_bookmark p_bookmark
#+ file_index read_only actual_line md5_hash
#+ path bookmarks breakpoints eol
#+ enc highlight notes
#+ }
#+ ...
#+ }
#+ }
set project_data [list \
[list {} [clock format [clock seconds] -format {%D}] {}]\
[list [file tail [file normalize ~]] {} {}] \
[list \
$project_new_processor \
$project_edit_clock \
$project_new_xdata \
$project_new_xcode] \
[list {} {} {} 1] \
[list {y} 0 0 \
[string repeat 0 170] \
[string repeat 0 170] \
[string repeat 0 170] \
{state} \
] \
[list {} {}] \
[list $calc_radix $calc_angle {} {} {} {} {} {}] \
{} {} \
[list 0 [list {} {} 0 {}]] \
]
# Create a new project file
if {[catch {
set prj_file [open "$project_new_dir/$project_new_name.mcu8051ide" w 0640]
}]} then {
# Failed
tk_messageBox \
-parent . \
-type ok \
-icon error \
-message [mc "Unable to write to file:\n\"%s\"" "$project_new_dir/$project_new_name.mcu8051ide"]
set critical_procedure_in_progress 0
return
}
# Fill in the file with project definition data
puts -nonewline $prj_file [Project::create_project_file_as_string $project_data]
close $prj_file
set done 0
# Insure than the project descriptor is unique
set projectDescriptor [regsub -all -- {\s} $project_new_name {-}]
regsub -all {[\\\/\.\,`\!@#\$%\^&:\;\|\*\"\(\)\[\]\{\}]} $projectDescriptor \
{_} projectDescriptor
set projectDescriptor "project_${projectDescriptor}"
if {[lsearch -exact -ascii ${X::openedProjects} $projectDescriptor] != -1} {
append project_new_name {(0)}
append projectDescriptor {_0}
while {1} {
if {[lsearch -exact -ascii ${X::openedProjects} $projectDescriptor] == -1} {break}
regexp {\d+$} $projectDescriptor index
regsub {_\d+$} $projectDescriptor {} projectDescriptor
regexp {\d+\)$} $project_new_name index
set index [string trimright $index {\)}]
regsub {\(\d+\)$} $project_new_name {} project_new_name
incr index
append project_new_name "($index)"
append projectDescriptor "_$index"
}
}
# Show project notebook
if {$project_menu_locked} {
pack .mainFrame.mainNB -expand 1 -fill both
}
# Open created project
lappend openedProjects $projectDescriptor
lappend simulator_enabled 0
MainTab ::$projectDescriptor $project_new_name $project_new_dir $project_new_name.mcu8051ide $project_data
switch_project $projectDescriptor
::X::recent_files_add 0 [file join [file normalize $project_new_dir] $project_new_name.mcu8051ide]
# Project opened
if {$project_menu_locked} {
Unlock_project_menu
}
disaena_menu_toolbar_for_current_project
# set MCU name in status bar, kdb
.statusbarMCU configure -text $project_new_processor
set critical_procedure_in_progress 0
}
## Disable menu items and functions functions which are
# available only if there is at least one opened project
# @return void
proc Lock_project_menu {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable toolbar_project_dependent_buttons ;# Toolbar buttons which require opened project
variable mainmenu_project_dependent_buttons ;# Menu bar items which require opened project
# Hide project notebook
pack forget .mainFrame.mainNB
# Disable menu items
set project_menu_locked 1
ena_dis_menu_buttons 0 $mainmenu_project_dependent_buttons
ena_dis_iconBar_buttons 0 .mainIconBar. $toolbar_project_dependent_buttons
adjust_mm_and_tb_ext_editor
}
## Enable menu items and functions functions which are available only if there
# is at least one opened project and create NoteBook for project tabs
# @return void
proc Unlock_project_menu {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable toolbar_project_dependent_buttons ;# Toolbar buttons which require opened project
variable mainmenu_project_dependent_buttons ;# Menu bar items which require opened project
variable toolbar_simulator_engaged ;# Toolbar buttons which require ENGAGED simulator
variable mainmenu_simulator_engaged ;# Menu bar items which require ENGAGED simulator
# Enable menu items
set project_menu_locked 0
ena_dis_menu_buttons 1 $mainmenu_project_dependent_buttons
ena_dis_menu_buttons 0 $mainmenu_simulator_engaged
ena_dis_iconBar_buttons 1 .mainIconBar. $toolbar_project_dependent_buttons
ena_dis_iconBar_buttons 0 .mainIconBar. $toolbar_simulator_engaged
adjust_mm_and_tb_ext_editor
}
## Disable menu entries and toolbar buttons which are functional on when simulator is on
# @return void
proc Lock_simulator_menu {} {
variable toolbar_simulator_disengaged ;# Toolbar buttons which require DISENGAGED simulator
variable toolbar_simulator_engaged ;# Toolbar buttons which require ENGAGED simulator
variable mainmenu_simulator_engaged ;# Menu bar items which require ENGAGED simulator
variable mainmenu_simulator_disengaged ;# Menu bar items which require DISENGAGED simulator
ena_dis_menu_buttons 1 $mainmenu_simulator_disengaged
ena_dis_menu_buttons 0 $mainmenu_simulator_engaged
ena_dis_iconBar_buttons 1 .mainIconBar. $toolbar_simulator_disengaged
ena_dis_iconBar_buttons 0 .mainIconBar. $toolbar_simulator_engaged
adjust_mm_and_tb_ext_editor
}
## Enable menu entries and toolbar buttons which are functional on when simulator is on
# @return void
proc Unlock_simulator_menu {} {
variable toolbar_simulator_disengaged ;# Toolbar buttons which require DISENGAGED simulator
variable toolbar_simulator_engaged ;# Toolbar buttons which require ENGAGED simulator
variable mainmenu_simulator_engaged ;# Menu bar items which require ENGAGED simulator
variable mainmenu_simulator_disengaged ;# Menu bar items which require DISENGAGED simulator
ena_dis_menu_buttons 0 $mainmenu_simulator_disengaged
ena_dis_menu_buttons 1 $mainmenu_simulator_engaged
ena_dis_iconBar_buttons 0 .mainIconBar. $toolbar_simulator_disengaged
ena_dis_iconBar_buttons 1 .mainIconBar. $toolbar_simulator_engaged
adjust_mm_and_tb_ext_editor
}
## Open project
# @return void
proc __proj_open {} {
variable defaultDirectory ;# Default directory
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Invoke project selection dialog
catch {delete object fsd}
KIFSD::FSD fsd \
-title [mc "Open project - MCU 8051 IDE"] \
-directory $defaultDirectory \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc "MCU 8051 IDE project"] {*.mcu8051ide} ] \
[list [mc "All files"] {*} ] \
]
# Open the selected after press of OK button
fsd setokcmd {
set filename [X::fsd get]
X::fsd deactivate
if {![Project::open_project_file $filename]} {
tk_messageBox \
-type ok \
-icon warning \
-parent . \
-title [mc "Error - MCU 8051 IDE"] \
-message [mc "Unable to load file: %s" $filename]
} else {
${::X::actualProject} editor_procedure {} highlight_visible_area {}
::X::recent_files_add 0 $filename
}
}
fsd activate ;# Activate the dialog
adjust_title
disaena_menu_toolbar_for_current_project
set critical_procedure_in_progress 0
}
## Retrieve project related data from object of the current project
# @parm Bool all_info - All data (include to do list and such)
# @return void
proc Project_retrieve_data_from_application {all_info} {
variable actualProject ;# Object: Current project
variable project_new_processor ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
variable project_edit_version ;# Project version
variable project_edit_date ;# Project date (last update)
variable project_edit_copyright ;# Copyright information
variable project_edit_license ;# License information
variable project_edit_authors ;# Project authors
variable project_edit_description ;# Project description
variable project_edit_main_file ;# Project main file
variable project_watches_file ;# File of register watches definition
variable project_todo ;# Todo text
variable project_graph ;# Graph configuration list
variable project_calculator ;# Calculator list (display contents, etc.)
variable project_other_options ;# Other project options
variable project_compiler_options ;# Compiler options
variable project_files ;# List of project files (special format)
variable project_file ;# Full name of the project file
variable project_dir ;# Path to project directory
variable project_edit_clock ;# Default clock rate
variable project_scenario_file ;# Scenario file
set project_edit_version [ $actualProject cget -P_information_version ]
set project_edit_date [ $actualProject cget -P_information_date ]
set project_edit_authors [ $actualProject cget -G_information_authors ]
set project_edit_copyright [ $actualProject cget -G_information_copyright ]
set project_edit_license [ $actualProject cget -G_information_license ]
set project_edit_clock [ $actualProject cget -P_option_clock ]
set project_edit_description [ $actualProject cget -project_description ]
set project_new_processor [ $actualProject cget -P_option_mcu_type ]
set project_new_xdata [ $actualProject cget -P_option_mcu_xdata ]
set project_new_xcode [ $actualProject cget -P_option_mcu_xcode ]
set project_edit_main_file [ $actualProject cget -P_option_main_file ]
set project_new_xdata_ena 0
set project_new_xcode_ena 0
if {$project_new_xdata} {set project_new_xdata_ena 1}
if {$project_new_xcode} {set project_new_xcode_ena 1}
if {$all_info} {
set project_graph [ $actualProject graph_get_config ]
set project_todo [ $actualProject TodoProc_read_text_as_sgml ]
set project_calculator [ $actualProject get_calculator_list ]
set project_other_options [ $actualProject cget -other_options ]
set project_files [ $actualProject get_project_files_list ]
set project_file [ $actualProject cget -projectFile ]
set project_dir [ $actualProject cget -projectPath ]
set project_watches_file [ $actualProject getWatchesFileName ]
set project_scenario_file [ $actualProject pale_get_scenario_filename ]
set project_compiler_options [ $actualProject get_compiler_config ]
}
}
## Free some resources reserved by procedure 'Project_retrieve_data_from_application'
# @return void
proc Project_RDFA_cleanup {} {
variable project_watches_file {} ;# File of register watches of the current poject
variable project_scenario_file {} ;# Scenario file
variable project_todo {} ;# Todo text
variable project_graph {} ;# Graph configuration list
variable project_calculator {} ;# Calculator list (display contents, etc.)
variable project_other_options {} ;# Other project options
variable project_compiler_options {} ;# Compiler options
variable project_files {} ;# List of project files (special format)
variable project_file {} ;# Full name of the project file
variable project_dir {} ;# Path to project directory
variable project_edit_clock {} ;# Default clock rate
}
## Save the current project
# @return void
proc __proj_save {} {
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable project_edit_version ;# Project version
variable project_edit_date ;# Project date (last update)
variable project_edit_copyright ;# Copyright information
variable project_edit_license ;# License information
variable project_edit_authors ;# Project authors
variable project_edit_description ;# Project description
variable project_edit_clock ;# Default clock rate
variable project_edit_main_file ;# Project main file
variable project_todo ;# Todo text
variable project_graph ;# Graph configuration list
variable project_calculator ;# Calculator list (display contents, etc.)
variable project_other_options ;# Other project options
variable project_compiler_options ;# Compiler options
variable project_files ;# List of project files (special format)
variable project_file ;# Full name of the project file
variable project_dir ;# Path to project directory
variable project_watches_file ;# File of register watches of the current poject
variable project_new_processor ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable project_scenario_file ;# Scenario file
if {$project_menu_locked} {return}
# Do not attempt to save a project with read only flag set
if {[$actualProject cget -S_flag_read_only]} {
puts "Read-only project, saving aborted."
return
}
# This is critical procedure
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Save register watches definition file
if {[$actualProject rightPanel_watch_modified]} {
$actualProject rightPanel_watch_save {} 1
}
# Save PALE Virtual HW connections
if {[$actualProject pale_modified]} {
$actualProject pale_save_scenario_file
}
# Create project definition data
Project_retrieve_data_from_application 1
set project_data [list \
[list \
[Project::escape_curlies $project_edit_version] \
[Project::escape_curlies $project_edit_date] \
${::VERSION}] \
[list \
$project_edit_authors \
[Project::escape_curlies $project_edit_copyright] \
[Project::escape_curlies $project_edit_license]] \
[list \
$project_new_processor \
$project_edit_clock \
$project_new_xdata \
$project_new_xcode] \
[list \
$project_watches_file \
$project_scenario_file \
$project_edit_main_file \
[$actualProject get_file_switching_enabled]] \
$project_graph \
[list \
[Project::escape_curlies $project_edit_description] \
[Project::escape_curlies $project_todo]] \
$project_calculator \
[Project::escape_curlies $project_other_options] \
[list $project_compiler_options] \
$project_files \
]
set project_data [Project::create_project_file_as_string $project_data]
set filename "$project_dir/$project_file"
Project_RDFA_cleanup
# Create backup copy for the project file
if {[file exists $filename]} {
catch {
file rename -force $filename "$filename~"
}
}
# Save project definition file
if {[catch {
set prj_file [open $filename w 0640]
}]} then {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to write to file:\n\"%s\"" $filename]
set critical_procedure_in_progress 0
return
}
puts -nonewline $prj_file $project_data
close $prj_file
# Done ...
Sbar [mc "Project saved to %s" $filename]
set critical_procedure_in_progress 0
}
## Invoke dialog "Edit project"
# @parm Bool choose_MCU_now=0 - Invoke MCU selection dialog right away and inore other config options ...
# @return void
proc __proj_edit {{choose_MCU_now 0}} {
variable actualProject ;# Object: Current project
variable available_processors ;# List of supported processors
variable project_edit_version ;# Project version
variable project_edit_date ;# Project date (last update)
variable project_edit_copyright ;# Copyright information
variable project_edit_license ;# License information
variable project_edit_authors ;# Project authors
variable project_edit_description ;# Project description
variable project_edit_clock ;# Default clock rate
variable project_edit_main_file ;# Project main file
variable project_edit_main_file_clr_but ;# Widget: Project main file clear button
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable project_new_processor {8051} ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena 0 ;# Bool: XDATA memory connected
variable project_new_xcode_ena 0 ;# Bool: XCODE memory connected
variable project_new_xdata 0 ;# Int: Amount of XDATA memory
variable project_new_xcode 0 ;# Int: Amount of XCODE memory
variable project_new_max_xcode 0 ;# Int: Maximum valid value of external program memory
variable project_new_xd_chb ;# Widget: XDATA enable checkbutton
variable project_new_xd_scl ;# Widget: XDATA scale
variable project_new_xd_spb ;# Widget: XDATA spinbox
variable project_new_xc_chb ;# Widget: XCODE enable checkbutton
variable project_new_xc_scl ;# Widget: XCODE scale
variable project_new_xc_spb ;# Widget: XCODE spinbox
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Retrieve existing informations about the project
Project_retrieve_data_from_application 0
# Create dialog window
set win [toplevel .project_edit -class {Edit project} -bg ${::COMMON_BG_COLOR}]
# Create main frames (top.left; top.right; bottom)
set top_frame [frame $win.top]
set bottom_frame [frame $win.bottom]
set top_left_frame [frame $top_frame.left]
set top_right_frame [frame $top_frame.right]
## GENERAL INFORMATION (version, date, authors, copyright, license)
label $win.lb_general_info_label \
-compound left \
-text [mc "General information"] \
-image ::ICONS::16::contents
set lb_general_info [ttk::labelframe $top_left_frame.lb_general_info \
-labelwidget $win.lb_general_info_label -padding 7 \
]
pack $lb_general_info -fill both -expand 1
set bframe [frame $lb_general_info.bframe]
pack $bframe -fill x -expand 1 -anchor w
# version
grid [Label $bframe.version_label \
-text [mc "Version"] \
-helptext [mc "Project version (any string)"] \
] -row 1 -column 1 -sticky w
grid [ttk::entry $bframe.version_entry \
-textvariable X::project_edit_version \
-validate key \
-validatecommand {::X::project_edit_validate %P} \
] -row 1 -column 2 -sticky we -columnspan 2
DynamicHelp::add $bframe.version_entry -text [mc "Project version (any string)"]
# date
grid [Label $bframe.date_label \
-text [mc "Date"] \
-helptext [mc "Project last update"] \
] -row 2 -column 1 -sticky w
grid [ttk::entry $bframe.date_entry \
-textvariable X::project_edit_date \
-validate key \
-validatecommand {::X::project_edit_validate %P} \
] -row 2 -column 2 -sticky we
DynamicHelp::add $bframe.date_entry -text [mc "Project last update"]
# button 'today'
grid [ttk::button $bframe.now \
-style Flat.TButton \
-takefocus 0 \
-image ::ICONS::16::today \
-command {X::project_edit_today} \
] -row 2 -column 3 -sticky e
DynamicHelp::add $bframe.now -text [mc "Fill date entry with the current date"]
# copyright
grid [Label $bframe.copyright_label \
-text [mc "Copyright"] \
-helptext [mc "Copyright information"] \
] -row 3 -column 1 -sticky w
grid [ttk::entry $bframe.copyright_entry \
-textvariable X::project_edit_copyright \
-validate key \
-validatecommand {::X::project_edit_validate %P} \
] -row 3 -column 2 -sticky we -columnspan 2
DynamicHelp::add $bframe.copyright_entry -text [mc "Copyright information"]
# license
grid [Label $bframe.license_label \
-text [mc "License"] \
-helptext [mc "Name of the license"] \
] -row 4 -column 1 -sticky w
grid [ttk::entry $bframe.license_entry \
-textvariable X::project_edit_license \
-validate key \
-validatecommand {::X::project_edit_validate %P} \
] -row 4 -column 2 -sticky we -columnspan 2
DynamicHelp::add $bframe.license_entry -text [mc "Name of the license"]
# authors
set tframe [frame .project_edit.top.left.lb_general_info.tframe]
pack $tframe -fill both -expand 1 -padx 5
pack [Label $tframe.label \
-text [mc "Authors:"] \
-helptext [mc "List of project authors (one per line)"] \
] -anchor w
pack [frame $tframe.frame] -fill both -expand 1
pack [text $tframe.frame.text \
-width 0 -height 0 \
-yscrollcommand "$tframe.frame.scrollbar set" \
] -fill both -expand 1 -side left
$tframe.frame.text insert end $project_edit_authors
pack [ttk::scrollbar $tframe.frame.scrollbar \
-orient vertical \
-command "$tframe.frame.text yview" \
] -fill y -side right
## Simulator & Compiler (MCU type, XDATA + XCODE memory + CLOCK)
label $win.lb_compiler_label \
-compound left \
-text [mc "Processor"] \
-image ::ICONS::16::kcmmemory
set lb_compiler [ttk::labelframe $top_right_frame.lb_compiler \
-labelwidget $win.lb_compiler_label \
]
set proc_frame_top0 [frame $lb_compiler.top0]
set proc_frame_top1 [frame $lb_compiler.top1]
set proc_frame_middle [frame $lb_compiler.middle]
set proc_frame_middle_left [ttk::labelframe $proc_frame_middle.middle \
-padding 5 -text [mc "External RAM (XDATA)"]]
set proc_frame_middle_right [ttk::labelframe $proc_frame_middle.right \
-padding 5 -text [mc "External ROM/FLASH (XCODE)"]]
# MCU clock frequency
grid [Label $proc_frame_top1.clock_label \
-text [mc "Clock \[kHz\]:"] -width 11 -anchor w \
-helptext [mc "Default clock used by simulator engine"] \
] -row 0 -column 1 -sticky w
grid [ttk::entry $proc_frame_top1.clock_entry \
-width 10 \
-textvariable X::project_edit_clock \
-validate key \
-validatecommand {::X::project_edit_CLOCK_validate %P} \
] -row 0 -column 3 -sticky w
DynamicHelp::add $proc_frame_top1.clock_entry \
-text [mc "Default clock used by simulator engine"]
# Main file
grid [Label $proc_frame_top1.file_label \
-text [mc "Main file:"] -width 11 -anchor w \
-helptext [mc "Project main file (e.g. main.c)\n(empty string means always compile current file)"] \
] -row 1 -column 1 -sticky w
set project_edit_main_file_clr_but [ttk::button \
$proc_frame_top1.clear_but \
-style Flat.TButton \
-takefocus 0 \
-image ::ICONS::16::locationbar_erase \
-command {
set ::X::project_edit_main_file {}
::X::proj_edit_mf_validator {}
} \
-state disabled \
]
DynamicHelp::add $proc_frame_top1.clear_but -text [mc "Clear"]
grid $project_edit_main_file_clr_but -row 1 -column 2 -sticky w
grid [ttk::entry $proc_frame_top1.file_entry \
-width 25 \
-validate all \
-validatecommand {::X::proj_edit_mf_validator %P} \
-textvariable X::project_edit_main_file \
] -row 1 -column 3 -sticky we
proj_edit_mf_validator ${::X::project_edit_main_file}
DynamicHelp::add $proc_frame_top1.file_entry \
-text [mc "Project main file (e.g. main.c)\n(empty string means always compile current file)"]
grid [ttk::button $proc_frame_top1.file_select_but \
-style Flat.TButton \
-takefocus 0 \
-image ::ICONS::16::fileopen \
-command {X::project_edit_select_main_file} \
] -row 1 -column 4 -sticky e -pady 5
DynamicHelp::add $proc_frame_top1.file_select_but -text [mc "Select main file"]
# Create components of top frame (Type: <ComboBox> <Button>)
pack [label $proc_frame_top0.lbl -text [mc "Type:"] -width 14 -anchor w] -side left
pack [ttk::combobox $proc_frame_top0.combo \
-values $available_processors \
-state readonly \
-textvariable ::X::project_new_processor\
] -side left -fill x
bind $proc_frame_top0.combo <<ComboboxSelected>> {::X::proj_new_mcu_changed}
DynamicHelp::add $proc_frame_top0.combo -text [mc "Selected uC"]
pack [ttk::button $proc_frame_top0.but \
-text [mc "Select MCU"] \
-image ::ICONS::16::back \
-compound left \
-command {::X::proj_new_select_mcu .project_edit} \
] -side right -after $proc_frame_top0.combo -padx 5
DynamicHelp::add $proc_frame_top0.combo -text [mc "Choose processor from database"]
# Create components of XDATA labelframe
set project_new_xd_chb [checkbutton $proc_frame_middle_left.checkbutton \
-variable ::X::project_new_xdata_ena \
-text [mc "Enable"] \
-command ::X::proj_new_xdata_disena \
]
pack $project_new_xd_chb -anchor w
DynamicHelp::add $proc_frame_middle_left.checkbutton \
-text [mc "Connect external data memory"]
set proc_frame_left_btm [frame $proc_frame_middle_left.btm]
set project_new_xd_scl [ttk::scale $proc_frame_left_btm.scale \
-orient horizontal \
-variable ::X::project_new_xdata \
-from 0 -to 0x10000 \
-command "
set ::X::project_new_xdata \[expr {int(\${::X::project_new_xdata})}\]
$proc_frame_left_btm.spinbox selection range 0 end
#" \
]
DynamicHelp::add $project_new_xd_scl \
-text [mc "Size of external data memory"]
pack $project_new_xd_scl -fill x -side left -expand 1 -padx 2
set project_new_xd_spb [ttk::spinbox $proc_frame_left_btm.spinbox \
-textvariable ::X::project_new_xdata \
-width 5 -from 0 -to 0x10000 \
-validate all \
-validatecommand {::SelectMCU::validate_xdata %P} \
]
DynamicHelp::add $project_new_xd_spb \
-text [mc "Size of external data memory"]
pack $project_new_xd_spb -side right -after $project_new_xd_scl
pack $proc_frame_left_btm -fill both -expand 1
proj_new_xdata_disena
# Create components of XCODE labelframe
set project_new_xc_chb [checkbutton $proc_frame_middle_right.checkbutton \
-variable ::X::project_new_xcode_ena \
-text [mc "Enable"] \
-command ::X::proj_new_xcode_disena \
]
pack $project_new_xc_chb -anchor w
DynamicHelp::add $proc_frame_middle_right.checkbutton \
-text [mc "Connect external program memory"]
set proc_frame_right_btm [frame $proc_frame_middle_right.btm]
set project_new_xc_scl [ttk::scale $proc_frame_right_btm.scale \
-orient horizontal \
-variable ::X::project_new_xcode \
-from 0 -to 0x10000 \
-command "
set ::X::project_new_xcode \[expr {int(\${::X::project_new_xcode})}\]
$proc_frame_right_btm.spinbox selection range 0 end
#" \
]
DynamicHelp::add $project_new_xc_scl \
-text [mc "Amount of total program memory minus internal program memory"]
pack $project_new_xc_scl -fill x -side left -expand 1 -padx 2
set project_new_xc_spb [ttk::spinbox $proc_frame_right_btm.spinbox \
-textvariable ::X::project_new_xcode \
-width 5 -from 0 -to 0x10000 \
-validate all \
-validatecommand {::X::proj_new_validate_xcode %P} \
]
DynamicHelp::add $project_new_xc_spb \
-text [mc "Amount of total program memory minus internal program memory"]
pack $project_new_xc_spb -side right -after $project_new_xc_scl
pack $proc_frame_right_btm -fill both -expand 1
proj_new_xcode_disena
pack $proc_frame_top0 -anchor w -pady 5 -padx 10
pack $proc_frame_top1 -anchor w -pady 5 -padx 10
pack $proc_frame_middle_left -side left -fill x -expand 1 -padx 7
pack $proc_frame_middle_right -side left -fill x -expand 1 -padx 7
pack $proc_frame_middle -fill both -expand 1 -pady 5
pack $lb_compiler -fill both -expand 1
# Adjust XDATA & XCODE controls - TODO why is this needed here?
# editor window has just been created, user hasn't made any selections yet
# meaning that mcu has not changed
proj_new_mcu_changed
# Martin: Oh yes, now I remeber :) proj_new_mcu_changed has to be called here in order to ensure that the
# scale widgets don't offer values out of range. Try to remove the call and then invoke the project
# editing dialog and you will see.
## PROJECT DESCRIPTION
label $win.lb_desc_label \
-compound left \
-text [mc "Project description"] \
-image ::ICONS::16::edit
set lb_desc [ttk::labelframe $bottom_frame.lb_desc \
-labelwidget $win.lb_desc_label -padding 7 \
]
pack $lb_desc -fill both -expand 1
pack [text $lb_desc.text \
-width 0 -height 7 \
-yscrollcommand "$lb_desc.scrollbar set" \
] -fill both -expand 1 -side left
$lb_desc.text insert end $project_edit_description
pack [ttk::scrollbar $lb_desc.scrollbar \
-orient vertical \
-command "$lb_desc.text yview" \
] -side right -fill y
# Pack main frames
pack $top_left_frame -fill both -expand 1 -padx 5 -side left -pady 10
pack $top_right_frame -fill both -expand 1 -padx 5 -side right -pady 10
pack $top_frame -fill both -expand 1 -pady 5
pack $bottom_frame -fill both -expand 1 -pady 5 -padx 5
# Buttons 'Ok' and 'Cancel'
pack [ttk::separator $win.separator -orient horizontal] -pady 5 -fill x
set buttons [frame $win.buttons]
pack [ttk::button $buttons.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::project_edit_OK} \
] -side left -padx 5
pack [ttk::button $buttons.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::project_edit_CANCEL} \
] -side left -padx 5
pack $buttons -anchor center -pady 5
# Setup some nessesary window manager options -- for modal window
wm iconphoto $win ::ICONS::16::edit
wm title $win [mc "Edit project - MCU 8051 IDE"]
wm minsize $win 660 440
wm protocol $win WM_DELETE_WINDOW {
X::project_edit_CANCEL
}
wm transient $win .
if {$choose_MCU_now} {
wm withdraw $win
proj_new_select_mcu .
project_edit_OK
return
}
update
catch {grab $win}
raise $win
tkwait window $win
}
## Project main file EntryBox validator
# Enables/Disables project main file clear button
# @parm String string - EntryBox contents
# @return Bool - allways 1
proc proj_edit_mf_validator {string} {
variable project_edit_main_file_clr_but ;# Widget: Project main file clear button
if {[string length $string]} {
$project_edit_main_file_clr_but configure -state normal
} else {
$project_edit_main_file_clr_but configure -state disabled
}
return 1
}
## Select project main file
# -- Auxiliary procedure for __proj_edit
# @return void
proc project_edit_select_main_file {} {
variable project_edit_main_file ;# Project main file
variable actualProject ;# Object: Current project
set ext [file extension $project_edit_main_file]
if {$ext == {.asm} || $ext == {.inc}} {
set defaultmask 0
} elseif {$ext == {.c} || $ext == {.cpp} || $ext == {.cc} || $ext == {.cxx}} {
set defaultmask 1
} elseif {$ext == {.h}} {
set defaultmask 2
} else {
set defaultmask 3
}
catch {delete object fsd}
KIFSD::FSD fsd \
-initialfile $project_edit_main_file \
-directory [$actualProject cget -projectPath] \
-title [mc "Select main file - %s - MCU 8051 IDE" $actualProject] \
-defaultmask $defaultmask -multiple 0 -filetypes [list \
[list [mc "Assembly language"] {*.asm} ] \
[list [mc "C source"] {*.c} ] \
[list [mc "C header"] {*.h} ] \
[list [mc "All files"] {*} ] \
]
fsd setokcmd {
set ::X::project_edit_main_file [X::fsd get]
if {![string first [$::X::actualProject cget -projectPath] $::X::project_edit_main_file]} {
set ::X::project_edit_main_file \
[string replace $::X::project_edit_main_file \
0 [string length [$::X::actualProject cget -projectPath]]]
::X::proj_edit_mf_validator ${::X::project_edit_main_file}
}
}
fsd activate
}
## Validate content of entry wingets in dialog "Edit project"
# -- axiliary procedure for '__proj_edit'
# @parm String string - String to validate
# @return Bool - result
proc project_edit_validate {string} {
if {[string length $string] > 40} {
return 0
} else {
return 1
}
}
## Set project date to today -- axiliary procedure for '__proj_edit'
# @return void
proc project_edit_today {} {
variable project_edit_date ;# Project date (last update)
set sec [clock seconds]
set project_edit_date [clock format $sec -format {%D}]
}
## Validate content of clock entry in dialog "Edit project"
# -- axiliary procedure for '__proj_edit'
# @parm String number - String to validate
# @return Bool - result
proc project_edit_CLOCK_validate {number} {
if {![regexp {^\d+(\.\d*)?$} $number]} {return 0}
if {$number > 99999} {return 0}
return 1
}
## Cancel dialog "Edit project" -- auxiliary procedure for '__proj_edit'
# @return void
proc project_edit_CANCEL {} {
grab release .project_edit
destroy .project_edit
}
## Save project values -- auxiliary procedure for '__proj_edit'
# @return void
proc project_edit_OK {} {
variable actualProject ;# Object: Current project
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable project_edit_version ;# Project version
variable project_edit_date ;# Project date (last update)
variable project_edit_copyright ;# Copyright information
variable project_edit_license ;# License information
variable project_edit_clock ;# Default clock rate
variable project_edit_main_file ;# Project main file
variable project_new_processor ;# Processor type (e.g. "AT89C2051")
variable project_new_xdata_ena ;# Bool: XDATA memory connected
variable project_new_xcode_ena ;# Bool: XCODE memory connected
variable project_new_xdata ;# Int: Amount of XDATA memory
variable project_new_xcode ;# Int: Amount of XCODE memory
variable project_new_xc_spb ;# Widget: XCODE spinbox
variable project_edit_defaults ;# Some default project values
variable projectdetails_last_project {} ;# Project object of the last project details window
# Adjust XCODE & XDATA values
if {!$project_new_xdata_ena} {
set project_new_xdata 0
}
if {!$project_new_xcode_ena} {
set project_new_xcode 0
}
# Set MCU name in status bar, kdb
.statusbarMCU configure -text $project_new_processor
# Adjust values
if {$project_edit_clock == {}} {
set project_edit_clock [lindex $project_edit_defaults {1 1}]
}
set project_edit_clock [string trimright $project_edit_clock {.}]
set project_new_xdata [expr {int($project_new_xdata)}]
set project_new_xcode [expr {int($project_new_xcode)}]
# Determinate original values
set xdata_prev [$actualProject cget -P_option_mcu_xdata]
set xcode_prev [$actualProject cget -P_option_mcu_xcode]
set proc_prev [$actualProject cget -P_option_mcu_type]
# Change object variables
foreach parm {
P_option_mcu_xdata P_option_mcu_xcode P_information_version
P_information_date G_information_license G_information_copyright
P_option_clock P_option_mcu_type P_option_main_file
} \
value {
project_new_xdata project_new_xcode project_edit_version
project_edit_date project_edit_license project_edit_copyright
project_edit_clock project_new_processor project_edit_main_file
} \
{
$actualProject configure -$parm [subst -nocommands "\$$value"]
}
$actualProject Simulator_set_clock $project_edit_clock
$actualProject configure -project_description \
[.project_edit.bottom.lb_desc.text get 1.0 end-1c]
$actualProject configure -G_information_authors \
[.project_edit.top.left.lb_general_info.tframe.frame.text get 1.0 end-1c]
## Adjust simulator control panel, register watches and hex editors
# Hex editors
close_hexedit eram $actualProject
close_hexedit eeprom $actualProject
close_hexedit eeprom_wr_bf $actualProject
if {$xdata_prev != $project_new_xdata} {
close_hexedit xdata $actualProject
$actualProject simulator_resize_xdata_memory $project_new_xdata
}
if {$xcode_prev != $project_new_xcode} {
close_hexedit code $actualProject
$actualProject simulator_resize_code_memory \
[expr {$project_new_xcode + 0x10000 - [$project_new_xc_spb cget -to]}]
}
# Simulator control panel and register watches
if {$proc_prev != $project_new_processor} {
change_processor $project_new_processor
}
# Adjust register watches
if {$xdata_prev != $project_new_xdata && $proc_prev == $project_new_processor} {
$actualProject rightPanel_watch_force_enable
$actualProject rightPanel_watch_sync_all
$actualProject rightPanel_watch_disable
}
# Menu and toolbar
disena_simulator_menu $actualProject
# Finalize
Sbar [mc "New values saved."]
project_edit_CANCEL ;# Close the dialog
return 1
}
## Change current MCU even in running simulator
# @parm String new_processor - Processor type
# @return void
proc change_processor {new_processor} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable actualProject ;# Object: Current project
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProjectIdx ;# Index of the current project in $openedProjects
set intr_mon_opeded [$actualProject interrupt_monitor_is_opened]
set was_enabled [lindex $simulator_enabled $actualProjectIdx]
if {$was_enabled} {
set tmp $critical_procedure_in_progress
set critical_procedure_in_progress 0
__initiate_sim
}
$actualProject configure -P_option_mcu_type $new_processor
$actualProject configure -procData \
[SelectMCU::get_processor_details $new_processor]
$actualProject refresh_project_available_SFR
$actualProject stack_monitor_monitor_close
$actualProject interrupt_monitor_close
$actualProject uart_monitor_close
$actualProject simulator_initialize_mcu
$actualProject SimGUI_clean_up
$actualProject simulator_itialize_simulator_control_panel
$actualProject graph_itialize_simulator_graph_panel {}
$actualProject sfrmap_commit_new_sfr_set
$actualProject rightPanel_watch_force_enable
$actualProject rightPanel_watch_sync_all
$actualProject rightPanel_watch_disable
$actualProject sfr_watches_commit_new_sfr_set
$actualProject pale_MCU_changed
$actualProject stopwatch_clear_all C
$actualProject stopwatch_clear_all O
if {$was_enabled} {
__initiate_sim
set critical_procedure_in_progress $tmp
}
if {$intr_mon_opeded} {
$actualProject interrupt_monitor_invoke_dialog
}
# Refresh syntax highligh in all editors
foreach e [$actualProject cget -editors] {
$e parseAll
}
}
## Close the current project
# @return void
proc __proj_close {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
__proj_save ;# Save project
$actualProject editor_close_all 0 1 ;# Close all opened files
close_project ;# Close project
}
## Close the current project without saving
# @return Bool - project closed
proc __proj_close_imm {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
if {$project_menu_locked} {return}
set modified 0
foreach e [$actualProject cget -editors] {
if {[$e cget -modified]} {
set modified 1
break
}
}
set response {yes}
# Invoke confirmation dialog
if {$modified} {
set response [tk_messageBox \
-icon question \
-parent . \
-type yesno \
-title [mc "Requesting confirmation %s" ${::APPNAME}] \
-message [mc "Are you sure want to close the project without saving changes ?"] \
]
}
# Close project
if {$response == {yes}} {
close_project
return 1
} else {
return 0
}
}
## Close the current project -- auxiliary procedure for '__proj_close_imm' and '__proj_close'
# @return void
proc close_project {} {
variable compilation_mess_project ;# Object: Project related to running compilation
variable compilation_in_progress ;# Bool: Compiler engaged
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable openedProjects ;# List of opened projects (Object references)
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable simulator_enabled ;# List of booleans: Simulator engaged
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
# Make sure that there are no help windows visible
remove_all_help_windows
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Abort running compilation
if {$compilation_in_progress && $compilation_mess_project == $actualProject} {
__abort_compilation
}
# Abort running simulation
if {$actualProjectIdx != -1 && ([lindex $simulator_enabled $actualProjectIdx] == 1)} {
set critical_procedure_in_progress 0
__initiate_sim
set critical_procedure_in_progress 1
}
# Delete project object
close_hexedit xdata $actualProject
close_hexedit code $actualProject
close_hexedit eram $actualProject
close_hexedit eeprom $actualProject
delete object $actualProject
# Adjust list of opened project and simlator started flag
set openedProjects [lreplace $openedProjects $actualProjectIdx $actualProjectIdx]
set simulator_enabled [lreplace $simulator_enabled $actualProjectIdx $actualProjectIdx]
# Raise nex tab or disable project menu and procedures
if {[llength $openedProjects] > 0} {
set actualProjectIdx 0
set actualProject [lindex $openedProjects $actualProjectIdx]
${::main_nb} raise [string trimleft $actualProject {:}]
} else {
set project_menu_locked 1
Lock_project_menu
}
set critical_procedure_in_progress 0
update
foreach project $openedProjects {
$project bottomNB_redraw_pane
}
}
## Compile current file
# @parm Bool force=0 - Force compilation -- ignore running critical procedure
# @parm Bool compilation_start_simulator=0 - Start simulator after successful compilation
# @parm Bool compile_this_file_only=0 - Compile current file only (not the main file)
# @return Bool - result or {}
proc __compile {{force 0} {_compilation_start_simulator 0} {_compile_this_file_only 0}} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable compilation_successfull ;# Bool: Compilation successfull
variable actualProject ;# Object: Current project
variable compilation_in_progress ;# Bool: Compiler engaged
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable compiler_pid ;# Int: PID of external compiler, if used
variable compilation_start_simulator ;# Bool: Start simulator after successful compilation
variable compile_this_file_only ;# Bool: Compile the current file only
variable compilation_mess_project ;# Object: Project related to running compilation
if {!${::APPLICATION_LOADED}} {
return {}
}
# It is not allowed to compile the source code while simulator is engaged
if {[lindex $simulator_enabled $actualProjectIdx]} {
return {}
}
if {$project_menu_locked} {return}
if {!$force && $critical_procedure_in_progress} {return}
if {$compilation_in_progress} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to run assembler"] \
-message [mc "Something is already running in background."]
return 0
}
set compile_this_file_only $_compile_this_file_only
set compilation_start_simulator $_compilation_start_simulator
# Compilation started
set compilation_mess_project $actualProject
set compilation_successfull 1
set result 0
set compiler_pid 0
set compilation_in_progress 1
set Compiler::Settings::ABORT_VARIABLE 0
# Save current file
if {![$actualProject editor_procedure {} save {}]} {
set compilation_in_progress 0
return 0
}
# Raise tab "Messages"
$actualProject bottomNB_show_up {Messages}
# Determinate name of file to compile
if {$compile_this_file_only} {
set input_file {}
} else {
set input_file [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
}
if {[lindex $input_file 1] == {}} {
set input_file [$actualProject editor_procedure {} getFileName {}]
set language [$actualProject editor_procedure {} get_language {}]
} else {
set ext [string trimleft [file extension [lindex $input_file 1]] {.}]
if {$ext == {c} || $ext == {h} || $ext == {cxx} || $ext == {cpp} || $ext == {cc}} {
set language 1
} elseif {$ext == {lst}} {
set language 2
} else {
set language 0
}
}
# Adjust filename
set cur_dir [lindex $input_file 0]
set input_file_name [lindex $input_file 1]
if {[regexp {\.[^\.]*$} $input_file_name input_file_extension]} {
regsub {\.[^\.]*$} $input_file_name {} input_file_name
set input_file_extension [string range $input_file_extension 1 end]
} else {
set input_file_extension {}
}
# Asjust file extension
if {$input_file_extension == {h}} {
set input_file_extension {c}
} elseif {$input_file_extension == {lst}} {
set input_file_extension {asm}
}
# Adjust statusbar
Sbar [mc "Compiling ..."]
make_progressBar_on_Sbar
compilation_progress
# Determinate memory limits
set iram_size [lindex [$actualProject cget -procData] 3]
set eram_size [lindex [$actualProject cget -procData] 8]
set xram_size [$actualProject cget -P_option_mcu_xdata]
if {$eram_size > $xram_size} {
set xram_size $eram_size
}
set code_size [expr {
([lindex [$actualProject cget -procData] 2] * 1024)
+
[$actualProject cget -P_option_mcu_xcode]
}]
## C language
if {$language == 1} {
if {!${::PROGRAM_AVAILABLE(sdcc)} && !${::PROGRAM_AVAILABLE(sdcc-sdcc)}} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Compiler not found"] \
-message [mc "Unable to find sdcc, please install sdcc and restart MCU 8051 IDE"]
} else {
# Start compiler
set compiler_pid [::ExternalCompiler::compile_C \
$cur_dir $input_file_name.$input_file_extension \
$iram_size $xram_size $code_size \
]
return 2
}
## Assembly language
} else {
# Check if the choosen assembler is available in the system
set available 0
switch -- $::ExternalCompiler::selected_assembler {
0 { ;# Native assembler
set available 1
set assembler_name [mc "MCU 8051 IDE Native assembler"]
set assembler_cmd {mcu8051ide --assemble}
}
1 { ;# ASEM-51
set available ${::PROGRAM_AVAILABLE(asem)}
set assembler_name "ASEM-51"
set assembler_cmd {asem}
}
2 { ;# ASL
set available ${::PROGRAM_AVAILABLE(asl)}
set assembler_name "ASL"
set assembler_cmd {asl}
}
3 { ;# AS31
set available ${::PROGRAM_AVAILABLE(as31)}
set assembler_name "AS31"
set assembler_cmd {as31}
}
default {
error "Unknown internal error -- Invalid ID of the selected assembler"
}
}
if {!$available} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "%s assembler not found" $assembler_name] \
-message [mc "Unable to run program \"%s\". Please check if you have installed this assembler or choose a different one in compiler configuration dialog." $assembler_cmd]
finalize_compilation 0
return 0
}
# Execute compiler
switch -- $::ExternalCompiler::selected_assembler {
0 { ;# Native assembler
# Adjust compiler settings
set ::Compiler::Settings::TEXT_OUPUT_COMMAND X::messages_text_append
set ::Compiler::Settings::UPDATE_COMMAND {update}
set ::Compiler::Settings::iram_size $iram_size
set ::Compiler::Settings::xram_size $xram_size
set ::Compiler::Settings::code_size $code_size
set ::PreProcessor::check_sfr_usage 1
set ::PreProcessor::available_SFR [string tolower [$actualProject cget -available_SFR]]
# Perform code compilation
if {[catch {
set result [Compiler::compile \
[$actualProject cget -projectPath] \
$cur_dir $input_file_name $input_file_extension \
]
}]} then {
puts stderr "Compiler crashed: \"${::errorInfo}\""
tk_messageBox \
-parent . \
-icon error \
-type ok \
-title [mc "Compiler crash - MCU 8051 IDE"] \
-message [mc "Compiler crashed, we are terribly sorry about that.\n\nPlease report this bug via project web or mail to author and please don't forget to include source code on which this error occurred."]
}
::Compiler::free_resources
set Compiler::Settings::ABORT_VARIABLE 0
}
1 { ;# ASEM-51
set compiler_pid [::ExternalCompiler::asem51_compile $cur_dir \
$input_file_name.$input_file_extension \
[$actualProject cget -projectPath] \
]
return 2
}
2 { ;# ASL
set compiler_pid [::ExternalCompiler::asl_compile $cur_dir \
$input_file_name.$input_file_extension \
[$actualProject cget -projectPath] \
]
return 2
}
3 { ;# AS31
set compiler_pid [::ExternalCompiler::as31_compile $cur_dir \
$input_file_name.$input_file_extension \
[$actualProject cget -projectPath] \
]
return 2
}
default {
error "Unknown internal error -- Invalid ID of the selected assembler"
}
}
}
finalize_compilation $result
return $result
}
## Compile the current file or the main file if it has not been already compiled
# @parm String success_callback - Procedure to call upon successfull compilation
# @parm String fail_callback - Procedure to call upon failed compilation
# @return void
proc compile_if_nessesary_and_callback {success_callback fail_callback} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
variable compilation_in_progress ;# Bool: Compiler engaged
variable compilation_success_callback ;# String: Indented for HW plugins
variable compilation_fail_callback ;# String: Indented for HW plugins
if {$project_menu_locked} {
return
}
set compilation_success_callback $success_callback
set compilation_fail_callback $fail_callback
set full_file_name [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
set relative_name [lindex $full_file_name 1]
if {$relative_name == {}} {
set full_file_name [$actualProject editor_procedure {} getFileName {}]
set language [$actualProject editor_procedure {} get_language {}]
set relative_name [lindex $full_file_name 1]
} else {
set ext [string trimleft [file extension $relative_name] {.}]
if {$ext == {c} || $ext == {h} || $ext == {cxx} || $ext == {cpp} || $ext == {cc}} {
set language 1
} elseif {$ext == {lst}} {
set language 2
} else {
set language 0
}
}
set full_file_name [file join [lindex $full_file_name 0] [lindex $full_file_name 1]]
set full_file_name [file rootname $full_file_name]
if {$language != 1} {
append full_file_name {.adf}
} else {
append full_file_name {.hashes}
}
if {![catch {
# C language
if {$language == 1} {
set hashes_file [open $full_file_name r]
set expected_md5s [read $hashes_file]
close $hashes_file
# Assembly language
} elseif {$language == 0} {
set expected_md5s {}
set simulator_file [open $full_file_name r]
while {![eof $simulator_file]} {
set line [gets $simulator_file]
if {$line == {} || [regexp {^\s*#} $line]} {
continue
}
set expected_md5s $line
break
}
close $simulator_file
# Invalid request!
} else {
error "Invalid request!"
}
}]} then {
if {[verify_md5_hashes 1 $expected_md5s [file dirname $full_file_name]]} {
__compile
return
}
} else {
__compile
return
}
eval "$compilation_success_callback"
}
## Finalize compilation process
# Auxiliary procedure for procedures: __compile && ext_compilation_complete
# @parm Bool result - 1 == Compilation successfull; 0 == Compilation failed
# @return void
proc finalize_compilation {result} {
variable compilation_in_progress ;# Bool: Compiler engaged
variable compilation_success_callback ;# String: Indented for HW plugins
variable compilation_fail_callback ;# String: Indented for HW plugins
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
set critical_procedure_in_progress 0
# Adjust statusbar
destroy_progressBar_on_Sbar
if {$result} {
Sbar [mc "Compilation successful"]
if {$compilation_success_callback != {}} {
eval "$compilation_success_callback"
set compilation_fail_callback {}
set compilation_success_callback {}
}
} else {
Sbar [mc "Compilation failed"]
if {$compilation_fail_callback != {}} {
eval "$compilation_fail_callback"
set compilation_fail_callback {}
set compilation_success_callback {}
}
}
# Done ...
set compilation_in_progress 0
}
## Handle text output from external or internal compiler
# @parm String text - Output from external compiler
# @return void
proc compilation_message args {
variable compilation_successfull ;# Bool: Compilation successfull
variable compilation_mess_project ;# Object: Project related to running compilation
set args [string replace \
[regsub -all "\\\{" \
[regsub -all "\\\}" \
[lindex $args 0]\
"\}"] \
"\{"] \
0 0]
# Backspace characters
set idx 0
while {1} {
set idx [string first "\b" $args $idx]
if {$idx == -1} {
break
}
set args [string replace $args [expr {$idx - 1}] [expr {$idx + 1}]]
incr idx -1
}
if {[$compilation_mess_project messages_text_append [string trimright $args]]} {
set compilation_successfull 0
}
}
## External compiler finnished its work
# @return void
proc ext_compilation_complete {} {
variable compilation_mess_project ;# Object: Project related to running compilation
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable openedProjects ;# List of opened projects (Object references)
variable compilation_start_simulator ;# Bool: Start simulator after successful compilation
variable compile_this_file_only ;# Bool: Compile the current file only
variable compilation_successfull ;# Bool: Compilation successfull
finalize_compilation $compilation_successfull
# Conditionaly start simulator
if {$compilation_start_simulator && $compilation_successfull} {
set actualProject_org $actualProject
set actualProjectIdx_org $actualProjectIdx
set actualProject $compilation_mess_project
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
__initiate_sim $compile_this_file_only
set actualProject $actualProject_org
set actualProjectIdx $actualProjectIdx_org
} elseif {$compilation_start_simulator && !$compilation_successfull} {
tk_messageBox \
-parent . \
-icon error \
-type ok \
-title [mc "Compilation failed"] \
-message [mc "Compilation failed, see messages for details."]
}
}
## Abort running compilation -- auxiliary procedure for '__compile'
# @return void
proc __abort_compilation {} {
variable compilation_in_progress ;# Bool: Compiler engaged
variable doxygen_pid ;# Int: Doxygen PID
variable compiler_pid ;# Int: PID of external compiler if used
set Compiler::Settings::ABORT_VARIABLE 1
destroy_progressBar_on_Sbar
if {!$::MICROSOFT_WINDOWS} { ;# There is no kill command on Microsoft Windows
# Kill doxygen
if {${doxygen_pid} != {}} {
foreach pid $doxygen_pid {
if {$pid == [pid] || $pid == 0} {
continue
}
catch {
exec -- kill -9 $pid
}
}
}
# Kill external compiler
if {${compiler_pid} != {}} {
foreach pid $compiler_pid {
if {$pid == [pid] || $pid == 0} {
continue
}
catch {
exec -- kill -9 $pid
}
}
}
}
set compilation_in_progress 0
set compiler_pid 0
set doxygen_pid 0
}
## Create progressbar on status bar (showing compilation progress)
# -- auxiliary procedure for '__compile'
# @return void
proc make_progressBar_on_Sbar {} {
# Frame
pack [frame .statusbarR] -in .statusbarF -side right
# Label "Compilation"
pack [label .status_sim_label \
-text [mc "Compilation: "] \
] -in .statusbarR -side left
# Button "Abort"
pack [ttk::button .status_sim_button \
-text [mc "Abort"] \
-image ::ICONS::16::cancel \
-compound left \
-command {X::__abort_compilation} \
] -in .statusbarR -side left
# Progressbar
pack [ttk::progressbar .status_sim_prog \
-maximum 1000 \
-mode indeterminate \
-variable X::compilation_progress \
-length 100 \
] -in .statusbarR -side left
}
## Destroy progressbar on status bar (showing compilation progress)
# -- auxiliary procedure for '__compile'
# @return void
proc destroy_progressBar_on_Sbar {} {
catch {
destroy .statusbarR
destroy .status_sim_label
destroy .status_sim_button
destroy .status_sim_prog
}
}
## Increment progreesbar on statusbar (compilation progress)
# -- auxiliary procedure for '__compile'
# @return void
proc compilation_progress {} {
variable compilation_progress ;# Variable for compilation progressbar
variable compilation_in_progress ;# Bool: Compiler engaged
if {!$compilation_in_progress} {return}
incr compilation_progress
if {$compilation_progress > 100} {
set compilation_progress 0
}
after 200 {X::compilation_progress}
}
## Append text to messages text (bottom panel - tab "Messages")
# @parm String text - Text to append
# @return Bool - True if error occurred
proc messages_text_append {text} {
variable actualProject ;# Object: Current project
variable compilation_mess_project ;# Object: Project related to running compilation
variable compilation_successfull ;# Bool: Compilation successfull
set result [$compilation_mess_project messages_text_append $text]
if {$result} {
set compilation_successfull 0
}
return $result
}
## Copy selected text in messages text to clipboard (bottom panel - tab "Messages")
# @return void
proc __copy_messages_text {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Copy
$actualProject copy_messages_text
}
## Select all text in messages text (bottom panel - tab "Messages")
# @return void
proc __select_all_messages_text {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Select all
$actualProject select_all_messages_text
}
## Clear content of messages text (bottom panel - tab "Messages")
# @return void
proc __clear_messages_text {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# CLear
$actualProject clear_messages_text
}
## Export content of the current editor as XHTML/LaTeX
# -- auxiliary procedure for '__toHTML' and '__toLaTeX'
# @parm String - Target type ('-html' or '-latex')
# @parm String - Title of the dialog window
# @return void
proc exportToX args {
variable actualProject ;# Object: Current project
variable compilation_progress ;# Variable for compilation progressbar
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable fsd_result ;# Value returnded by file selection dialog (in some cases)
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Expect 2 arguments
if {[llength $args] != 2} {
error "expected exactly 2 arguments"
}
# Check if the editor isn't empty
if {
[$actualProject editor_procedure {} getLinesCount {}] == 1
&&
[$actualProject editor_procedure {} getLineContent 1] == {}
} then {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to comply"] \
-message [mc "This editor seems to be empty"]
return
}
# Determinate target file type (html/latex)
set targetType [lindex $args 0]
# Compilation started
set compilation_progress 1
# Determinate maximum value for progress bar
set max [$actualProject editor_procedure {} highlight_all_count_of_iterations {}]
incr max
# Create diwlog window
set win [toplevel .exportToX_dialog -class [mc "Export dialog"] -bg ${::COMMON_BG_COLOR}]
wm withdraw $win
# Label and progress bar
set main_frame [frame $win.main_frame]
pack [label $main_frame.header \
-text [mc "Finishing syntax highlight ..."] \
] -pady 10 -padx 20 -anchor w
pack [ttk::progressbar $main_frame.progress_bar \
-maximum $max \
-mode determinate \
-variable {X::compilation_progress} \
-length 430 \
] -fill y
pack $main_frame -fill x -expand 1
# Button abort
pack [ttk::button $win.abort_button \
-text [mc "Abort"] \
-command "X::exportToX_abort $targetType" \
-image ::ICONS::16::cancel \
-compound left \
] -pady 5
# Determinate target file name
set file [$actualProject editor_procedure {} getFileName {}]
set filename [lindex $file 1]
if {[lindex $file 0] != {}} {
set dir [lindex $file 0]
} else {
set dir [$actualProject cget -projectPath]
}
regsub {\.[^\.]*$} $filename {} filename
if {$targetType == "-html"} {
set suffix {html}
} else {
set suffix {tex}
}
append filename {.} $suffix
catch {delete object fsd}
KIFSD::FSD fsd \
-initialfile $filename -directory $dir \
-title [mc "Export as %s - MCU 8051 IDE" [lindex $args 1]] \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc [string toupper $suffix] {file}] "*.$suffix"] \
[list [mc "All files"] {*}] \
]
fsd setokcmd {
set ::X::fsd_result [X::fsd get]
}
set fsd_result {}
fsd activate
set filename $fsd_result
if {[file isdirectory $filename] || ![string length $filename]} {
exportToX_abort $targetType
return
}
if {![regexp {\.\w+$} $filename]} {
append filename {.} $suffix
}
# Create backup file
if {[file exists $filename] && [file isfile $filename]} {
if {![file writable $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "Permission denied"] \
-message [mc "Unable to access file: %s" $filename]
exportToX_abort $targetType
return
}
# Ask user for overwrite existing file
if {[tk_messageBox \
-type yesno \
-icon question \
-parent . \
-title [mc "Overwrite file"] \
-message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $filename]]
] != {yes}
} then {
exportToX_abort $targetType
return
}
# Create a backup file
catch {
file rename -force $filename "$filename~"
}
}
# Open target file
if {[catch {
set file [open $filename w 0640]
}]} then {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "Permission denied"] \
-message [mc "Unable to write to file: \"%s\"" $filename]
exportToX_abort $targetType
return
}
# Set window attributes
if {![winfo exists $win]} {return}
wm iconphoto $win ::ICONS::16::html
wm deiconify $win
wm title $win [mc "[lindex $args 1] - MCU 8051 IDE"]
wm minsize $win 450 110
wm protocol $win WM_DELETE_WINDOW {
exportToX_abort
}
wm transient $win .
catch {grab $win}
raise $win
update
# Highlight all lines in the editor
$actualProject editor_procedure {} highlight_all {}
if {![winfo exists $win]} {return}
# Ajust window (Second stage)
set max [$actualProject editor_procedure {} getDataAsXHTML_count_of_iterations {}]
incr max
$main_frame.header configure -text [mc "Converting ..."]
$main_frame.progress_bar configure -maximum $max
set compilation_progress 1
update
# Export and write data
if {$targetType == "-html"} {
$actualProject editor_procedure {} getDataAsXHTML $file
} elseif {$targetType == "-latex"} {
$actualProject editor_procedure {} getDataAsLaTeX $file
} else {
error "Unknown argument: $targetType\n\tpossible vaues are: -html -latex"
}
close $file
exportToX_abort $targetType
# Show result
Sbar [mc "Exported data saved to %s" $filename]
}
## Abort export content of the current editor as XHTML/LaTeX
# -- auxiliary procedure for '__toHTML' and '__toLaTeX'
# @parm String - Target type ('-html' or '-latex')
# @return void
proc exportToX_abort {targetType} {
variable actualProject ;# Object: Current project
# Abort export
if {$targetType == "-html"} {
$actualProject editor_procedure {} getDataAsXHTML_abort_now {}
} elseif {$targetType == "-latex"} {
$actualProject editor_procedure {} getDataAsLaTeX_abort_now {}
} else {
error "Unknown argument: $targetType\n\tpossible vaues are: -html -latex"
}
# Destroy dialog window
destroy .exportToX_dialog
grab release .exportToX_dialog
}
## Export data contained in the current editor as XHTML
# @return void
proc __toHTML {} {
exportToX -html "Export to XHTML"
}
## Export data contained in the current editor as LaTeX
# @return void
proc __toLaTeX {} {
exportToX -latex "Export to LaTeX"
}
## Exit program
# - Ask for saving unsaved files and projects
# - Save all projects
# - Save session file
# - Exit
# @parm Bool do_not_print_exit_message=0 - Print message "Exiting on user request"
# @parm Bool force=0 - Do not allow user to cancel the request
# @return void
proc __exit {{do_not_print_exit_message 0} {force 0}} {
variable openedProjects ;# List of opened projects (Object references)
variable actualProject ;# Object: Current project
variable compilation_in_progress ;# Bool: Compiler engaged
variable procedure_exit_in_progress ;# Bool: proc "__exit" in progress
variable unsaved_projects ;# List: List of project object marked as "unsaved"
variable eightsegment_editors ;# List: All 8-Segment LED display editors invoked
variable spec_calc_objects ;# List: All special calculator objects
variable rs232debugger_objects ;# List: All "RS232 debugger" objects
# If application is not loaded -> exit immediately
if {!${::APPLICATION_LOADED}} {
exit
}
# This procedure cannot be recursive
if {$procedure_exit_in_progress} {
return
}
set procedure_exit_in_progress 1
# Ask hardware whether it's ready for exit
foreach project $openedProjects {
if {![$project hw_manager_comfirm_exit]} {
set procedure_exit_in_progress 0
return
}
}
foreach obj [concat $eightsegment_editors $spec_calc_objects $rs232debugger_objects] {
catch {
delete object $obj
}
}
# Cancel running compilation
if {$compilation_in_progress} {
__abort_compilation
}
# Determinate list of unsaved projects
set unsaved_projects {}
foreach project $openedProjects {
foreach editor [$project cget -editors] {
catch {
if {[$editor cget -modified]} {
lappend unsaved_projects [list $project $editor]
}
}
}
}
# Ask user for saving unsaved files -- use proc 'shutdown_dialog'
if {[llength $unsaved_projects] != 0} {
switch -- [shutdown_dialog $force] {
0 { ;# SAVESELECTED
set i 0
foreach unsaved $unsaved_projects {
set bool [subst -nocommands "\$::unsavedfile$i"]
if {$bool == 1} {
[lindex [lindex $unsaved_projects $i] 1] save
}
incr i
}
}
1 { ;# SAVEALL
set last_project {}
foreach project $unsaved_projects {
set project [lindex $project 0]
if {$last_project == $project} {continue}
set last_project $project
$project editor_save_all
}
}
2 { ;# DISCARD
}
3 { ;# CANCEL
set procedure_exit_in_progress 0
return 0
}
}
}
# Stop watching for modifications in designaded files
FSnotifications::stop
if {!$do_not_print_exit_message} {
puts [mc "\nExiting program on user request ..."]
}
# Save session
if {[catch {
save_session
} result]} then {
puts stderr [mc "An error occurred when saving the last session"]
puts stderr $result
}
# Withdraw main window
wm withdraw .
# Withdraw all PALE windows
foreach project $openedProjects {
$project pale_withdraw_all_windows
}
update
# Save all projects
foreach project $openedProjects {
$project kill_childern
set actualProject $project
puts [mc "Saving project: %s" $project]
__proj_save
}
# Kill the spell checker used by the editor
if {!$::MICROSOFT_WINDOWS} {
::Editor::kill_spellchecker_process
}
puts [mc "Program terminated"]
exit
}
## Save the current session
# @return void
proc save_session {} {
variable openedProjects ;# List of opened projects (Object references)
variable actualProject ;# Object: Current project
variable session_file ;# Path to file defining the last session
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable line2pc_jump ;# Bool: Perform program jump (1) or subprogram call (0)
variable find_option_CS ;# Bool: Case sensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable replace_option_CS ;# Bool: Case sensitive
variable replace_option_back ;# Bool: Search backwards (checkbox)
variable replace_option_cur ;# Book: Search from cursor
variable replace_option_reg ;# Bool: Consider search string to be a regular expression
variable file_recent_files ;# List: recently opened files
variable project_recent_files ;# List: recently opened projects
variable vhw_recent_files ;# List: recently opened Virtual HW files
variable base_converters ;# List: All base converter objects
variable change_letter_case_options ;# Options (which fields should be adjusted)
# Create configuration directory if it is not exist already
if {![file exists ${::CONFIG_DIR}] || ![file isdirectory ${::CONFIG_DIR}]} {
if {[catch {[file mkdir ${::CONFIG_DIR}]}]} {
tk_messageBox \
-type ok \
-icon error \
-title [mc "Permission denied"] \
-message [mc "Unable to save running configuration"]
return 0
}
}
# Get project dependent options
if {([llength $openedProjects] > 0) && ($actualProject != {})} {
array set ::CONFIG [subst {
LINE_NUMBERS [$actualProject cget -lineNumbers]
ICON_BORDER [$actualProject cget -iconBorder]
LEFT_PANEL [$actualProject isLeftPanelVisible]
RIGHT_PANEL [$actualProject isRightPanelVisible]
BOTTOM_PANEL [$actualProject isBottomPanelVisible]
LEFT_PANEL_SIZE [$actualProject getLeftPanelSize]
RIGHT_PANEL_SIZE [$actualProject getRightPanelSize]
BOTTOM_PANEL_SIZE [$actualProject getBottomPanelSize]
LEFT_PANEL_ACTIVE_PAGE {[$actualProject getLeftPanelActivePage]}
RIGHT_PANEL_ACTIVE_PAGE {[$actualProject getRightPanelActivePage]}
BOTTOM_PANEL_ACTIVE_PAGE {[$actualProject getBottomPanelActivePage]}
SUBP_MON_CONFIG {[$actualProject subprograms_get_config]}
FS_BROWSER_MASK {[$actualProject fs_browser_get_current_mask]}
FIND_IN_FILES_CONFIG {[$actualProject findinfiles_get_config]}
STOPWATCH_CONFIG {[$actualProject stopwatch_get_config]}
C_VARS_VIEW_CONF {[$actualProject cvarsview_get_config]}
BITMAP_CONFIG {[$actualProject bitmap_get_config]}
HW_MANAGER_CONFIG {[$actualProject hw_manager_get_cfg]}
REGWATCHES_CONFIG {[$actualProject rightPanel_watch_get_config]}
FILE_NOTES {[$actualProject get_file_notes_config]}
}]
}
# Get project independent options
array set ::CONFIG [subst {
KIFSD_CONFIG {[::KIFSD::FSD::get_config_array]}
HEXEDIT_CONFIG {[::HexEditDlg::getConfig]}
FIND_OPTIONS {[list $find_option_CS \
$find_option_back \
$find_option_cur \
$find_option_sel \
$find_option_reg]}
REPLACE_OPTIONS {[list $replace_option_CS \
$replace_option_back \
$replace_option_cur \
$replace_option_reg]}
INTR_MON_GEOMETRY {${::InterruptMonitor::geometry}}
OPEN_WITH_DLG {${::FileList::open_with}}
SYMBOL_VIEWER_CONFIG {${::SymbolViewer::config_list}}
LINE2PC_JUMP {$line2pc_jump}
FILE_RECENT_FILES {$file_recent_files}
PROJECT_RECENT_FILES {$project_recent_files}
VHW_RECENT_FILES {$vhw_recent_files}
EIGHT_SEG_EDITOR {${::EightSegment::config}}
SPEC_CALC {${::SpecCalc::config}}
ASK_ON_FILE_OPEN {${::FileList::ask__append_file_to_project}}
RS232_DEBUGGER {${::RS232Debugger::config_list}}
STACK_MON_GEOMETRY {${::StackMonitor::geometry}}
STACK_MON_COLLAPSED {${::StackMonitor::collapsed}}
SPELL_CHECK_ENABLED {${::Editor::spellchecker_enabled}}
SPELL_CHECK_DICTIONARY {${::Editor::spellchecker_dictionary}}
UART_MON_GEOMETRY {${::UARTMonitor::geometry}}
SHOW_PALE_WARN {${::Graph::show_sim_per_warn}}
}]
set ::CONFIG(LETTER_CASE) {}
for {set i 0} {$i < 21} {incr i} {
lappend ::CONFIG(LETTER_CASE) $change_letter_case_options($i)
}
set ::CONFIG(BASE_CONVERTERS) {}
foreach obj $base_converters {
lappend ::CONFIG(BASE_CONVERTERS) [$obj get_config]
}
# Open session file
if {[catch {
set file [open $session_file w 0640]
}]} then {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "Access denied"] \
-message [mc "Unable to write to file: \"%s\"" $session_file]
return
}
# Write session file
puts $file "# ${::APPNAME}"
puts $file "# Please do not modify this file manually.\n"
puts $file "# booleans"
if {$::MICROSOFT_WINDOWS} {
if {[wm state .] == {zoomed}} {
puts $file "WINDOW_ZOOMED = 1"
} else {
puts $file "WINDOW_ZOOMED = 0"
}
} else {
puts $file "WINDOW_ZOOMED = [wm attributes . -zoomed]"
}
puts $file "LINE_NUMBERS = $::CONFIG(LINE_NUMBERS)"
puts $file "ICON_BORDER = $::CONFIG(ICON_BORDER)"
puts $file "LEFT_PANEL = $::CONFIG(LEFT_PANEL)"
puts $file "RIGHT_PANEL = $::CONFIG(RIGHT_PANEL)"
puts $file "BOTTOM_PANEL = $::CONFIG(BOTTOM_PANEL)"
puts $file "TOOLBAR_VISIBLE = $::CONFIG(TOOLBAR_VISIBLE)"
puts $file "BREAKPOINTS_ALLOWED = $::CONFIG(BREAKPOINTS_ALLOWED)"
puts $file "LINE2PC_JUMP = $::CONFIG(LINE2PC_JUMP)"
puts $file "ASK_ON_FILE_OPEN = $::CONFIG(ASK_ON_FILE_OPEN)"
puts $file "SHOW_EDITOR_TAB_BAR = $::CONFIG(SHOW_EDITOR_TAB_BAR)"
puts $file "STACK_MON_COLLAPSED = $::CONFIG(STACK_MON_COLLAPSED)"
puts $file "SPELL_CHECK_ENABLED = $::CONFIG(SPELL_CHECK_ENABLED)"
puts $file "SHOW_PALE_WARN = $::CONFIG(SHOW_PALE_WARN)"
puts $file "\n# integers"
puts $file "LEFT_PANEL_SIZE = $::CONFIG(LEFT_PANEL_SIZE)"
puts $file "RIGHT_PANEL_SIZE = $::CONFIG(RIGHT_PANEL_SIZE)"
puts $file "BOTTOM_PANEL_SIZE = $::CONFIG(BOTTOM_PANEL_SIZE)"
puts $file "VALIDATION_LEVEL = $::CONFIG(VALIDATION_LEVEL)"
puts $file "\n# strings"
puts $file "LEFT_PANEL_ACTIVE_PAGE = \"$::CONFIG(LEFT_PANEL_ACTIVE_PAGE)\""
puts $file "RIGHT_PANEL_ACTIVE_PAGE = \"$::CONFIG(RIGHT_PANEL_ACTIVE_PAGE)\""
puts $file "BOTTOM_PANEL_ACTIVE_PAGE = \"$::CONFIG(BOTTOM_PANEL_ACTIVE_PAGE)\""
puts $file "OPEN_WITH_DLG = \"$::CONFIG(OPEN_WITH_DLG)\""
puts $file "FS_BROWSER_MASK = \"$::CONFIG(FS_BROWSER_MASK)\""
puts $file "FILE_RECENT_FILES = \"$::CONFIG(FILE_RECENT_FILES)\""
puts $file "PROJECT_RECENT_FILES = \"$::CONFIG(PROJECT_RECENT_FILES)\""
puts $file "VHW_RECENT_FILES = \"$::CONFIG(VHW_RECENT_FILES)\""
puts $file "SPELL_CHECK_DICTIONARY = \"$::CONFIG(SPELL_CHECK_DICTIONARY)\""
puts $file "\n# lists"
puts $file "CLEANUP_OPTIONS = \"[regsub -all {\s+} $::CONFIG(CLEANUP_OPTIONS) { }]\""
puts $file "FIND_OPTIONS = \"$::CONFIG(FIND_OPTIONS)\""
puts $file "REPLACE_OPTIONS = \"$::CONFIG(REPLACE_OPTIONS)\""
puts $file "LETTER_CASE = \"$::CONFIG(LETTER_CASE)\""
puts $file "KIFSD_CONFIG = \"$::CONFIG(KIFSD_CONFIG)\""
puts $file "HEXEDIT_CONFIG = \"$::CONFIG(HEXEDIT_CONFIG)\""
puts $file "SUBP_MON_CONFIG = \"$::CONFIG(SUBP_MON_CONFIG)\""
puts $file "FIND_IN_FILES_CONFIG = \"$::CONFIG(FIND_IN_FILES_CONFIG)\""
puts $file "SYMBOL_VIEWER_CONFIG = \"$::CONFIG(SYMBOL_VIEWER_CONFIG)\""
puts $file "STOPWATCH_CONFIG = \"$::CONFIG(STOPWATCH_CONFIG)\""
puts $file "C_VARS_VIEW_CONF = \"$::CONFIG(C_VARS_VIEW_CONF)\""
puts $file "BITMAP_CONFIG = \"$::CONFIG(BITMAP_CONFIG)\""
puts $file "HW_MANAGER_CONFIG = \"$::CONFIG(HW_MANAGER_CONFIG)\""
puts $file "REGWATCHES_CONFIG = \"$::CONFIG(REGWATCHES_CONFIG)\""
puts $file "FILE_NOTES = \"$::CONFIG(FILE_NOTES)\""
puts $file "EIGHT_SEG_EDITOR = \"$::CONFIG(EIGHT_SEG_EDITOR)\""
puts $file "BASE_CONVERTERS = \"$::CONFIG(BASE_CONVERTERS)\""
puts $file "SPEC_CALC = \"$::CONFIG(SPEC_CALC)\""
puts $file "RS232_DEBUGGER = \"$::CONFIG(RS232_DEBUGGER)\""
puts $file "\n# other"
puts $file "WINDOW_GEOMETRY = \"[wm geometry .]\""
puts $file "ACTIVE_PROJECT = $actualProjectIdx"
puts $file "INTR_MON_GEOMETRY = \"$::CONFIG(INTR_MON_GEOMETRY)\""
puts $file "STACK_MON_GEOMETRY = \"$::CONFIG(STACK_MON_GEOMETRY)\""
puts $file "UART_MON_GEOMETRY = \"$::CONFIG(UART_MON_GEOMETRY)\""
set projects [list]
foreach prj $openedProjects {
if {![$prj cget -S_flag_read_only]} { ;# Do not reopen read-only projects
lappend projects [file join \
[$prj cget -projectPath]\
[$prj cget -projectFile]\
]
}
}
puts $file "OPENED_PROJECTS = ($projects)"
# Finalize
close $file
return 1
}
## Restore previous session
# @return Bool - session file found
proc restore_session {} {
variable session_file ;# Path to file defining the last session
variable line2pc_jump ;# Bool: Perform program jump (1) or subprogram call (0)
variable find_option_CS ;# Bool: Case sensitive
variable find_option_back ;# Bool: Search backwards (checkbox)
variable find_option_cur ;# Book: Search from cursor
variable find_option_sel ;# Bool: Search only in the seleted text
variable find_option_reg ;# Bool: Consider search string to be a regular expression
variable replace_option_CS ;# Bool: Case sensitive
variable replace_option_back ;# Bool: Search backwards (checkbox)
variable replace_option_cur ;# Book: Search from cursor
variable replace_option_reg ;# Bool: Consider search string to be a regular expression
variable file_recent_files ;# List: recently opened files
variable project_recent_files ;# List: recently opened projects
variable vhw_recent_files ;# List: recently opened Virtual HW files
variable change_letter_case_options ;# Options (which fields should be adjusted)
# Set default values
array set ::CONFIG {
WINDOW_ZOOMED 0
LINE_NUMBERS 1
ICON_BORDER 1
LEFT_PANEL 1
RIGHT_PANEL 1
BOTTOM_PANEL 1
LEFT_PANEL_SIZE 193
RIGHT_PANEL_SIZE 329
BOTTOM_PANEL_SIZE 190
LEFT_PANEL_ACTIVE_PAGE opened_files
RIGHT_PANEL_ACTIVE_PAGE Watches
BOTTOM_PANEL_ACTIVE_PAGE Simulator
WINDOW_GEOMETRY 800x600
ACTIVE_PROJECT {}
OPENED_PROJECTS {}
VALIDATION_LEVEL 2
TOOLBAR_VISIBLE 1
BREAKPOINTS_ALLOWED 1
CLEANUP_OPTIONS {
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
}
FIND_OPTIONS {1 0 1 0 0}
REPLACE_OPTIONS {1 0 0 0}
LETTER_CASE {- - - - - - - - - - - - - - - - - - - - -}
KIFSD_CONFIG {}
HEXEDIT_CONFIG {+0+0 hex 0 left}
INTR_MON_GEOMETRY {850x270}
UART_MON_GEOMETRY {850x270}
SHOW_PALE_WARN 1
SUBP_MON_CONFIG {1 1}
OPEN_WITH_DLG {}
FS_BROWSER_MASK {*.asm}
FIND_IN_FILES_CONFIG {1 0 1 {} {*.asm,*.c,*.h} {}}
SYMBOL_VIEWER_CONFIG {1 1 1 1 1 1 1 0 0 0 620x450}
LINE2PC_JUMP 1
STOPWATCH_CONFIG {{} 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0}
C_VARS_VIEW_CONF {400}
BITMAP_CONFIG {}
HW_MANAGER_CONFIG {}
FILE_RECENT_FILES {}
PROJECT_RECENT_FILES {}
VHW_RECENT_FILES {}
REGWATCHES_CONFIG {1 1 0}
FILE_NOTES {1 200}
EIGHT_SEG_EDITOR {
{0 0 1 1 2 2 3 3 4 4 5 5 6 6 7 7}
{0 0 1 0 2 0 3 0 4 0 5 0 6 0 7 0}
}
BASE_CONVERTERS {}
SPEC_CALC {}
ASK_ON_FILE_OPEN 1
SHOW_EDITOR_TAB_BAR 1
RS232_DEBUGGER {9600 n 8 1 1 0 {} {} 0 0}
STACK_MON_GEOMETRY {}
STACK_MON_COLLAPSED 1
SPELL_CHECK_ENABLED 1
SPELL_CHECK_DICTIONARY {}
}
# Set default dictionary for the spell checking
set ::CONFIG(SPELL_CHECK_DICTIONARY) [join \
[list \
[string tolower [lindex [split [::msgcat::mclocale] {_}] 0]] \
[string toupper [lindex [split [::msgcat::mclocale] {_}] 1]] \
] \
{_} \
]
if {$::MICROSOFT_WINDOWS} {
lset ::CONFIG(FIND_IN_FILES_CONFIG) 3 ${::env(USERPROFILE)}
}
set default_CLEANUP_OPTIONS {
1 1 1 1 1 1 1 1 1 1 1 1 1 1
1 1 1 1 1 1 1 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0
}
set default_FIND_OPTIONS {1 0 1 0 0}
set default_REPLACE_OPTIONS {1 0 0 0}
set session_file_exists [file exists $session_file]
# Parse session file
if {!$::CLI_OPTION(defaults) && $session_file_exists} {
# List of keys which may appear in the session file
set acceptable_keys {
LINE_NUMBERS ICON_BORDER LEFT_PANEL
BOTTOM_PANEL LEFT_PANEL_SIZE RIGHT_PANEL_SIZE
BOTTOM_PANEL_SIZE LEFT_PANEL_ACTIVE_PAGE RIGHT_PANEL_ACTIVE_PAGE
BOTTOM_PANEL_ACTIVE_PAGE WINDOW_GEOMETRY ACTIVE_PROJECT
OPENED_PROJECTS RIGHT_PANEL KIFSD_CONFIG
VALIDATION_LEVEL TOOLBAR_VISIBLE CLEANUP_OPTIONS
BREAKPOINTS_ALLOWED FIND_OPTIONS REPLACE_OPTIONS
LETTER_CASE HEXEDIT_CONFIG INTR_MON_GEOMETRY
SUBP_MON_CONFIG OPEN_WITH_DLG FS_BROWSER_MASK
FIND_IN_FILES_CONFIG SYMBOL_VIEWER_CONFIG LINE2PC_JUMP
STOPWATCH_CONFIG C_VARS_VIEW_CONF BITMAP_CONFIG
HW_MANAGER_CONFIG FILE_RECENT_FILES PROJECT_RECENT_FILES
REGWATCHES_CONFIG EIGHT_SEG_EDITOR VHW_RECENT_FILES
BASE_CONVERTERS WINDOW_ZOOMED SPEC_CALC
ASK_ON_FILE_OPEN SHOW_EDITOR_TAB_BAR RS232_DEBUGGER
FILE_NOTES STACK_MON_GEOMETRY STACK_MON_COLLAPSED
SPELL_CHECK_ENABLED SPELL_CHECK_DICTIONARY UART_MON_GEOMETRY
SHOW_PALE_WARN
}
# List of datatypes for these keys
set datatypes {
B B B
B I I
I S S
S G S
S B S
I B S
B S S
S S G
S S S
S S B
S S S
S S S
S S S
S B S
B B S
S S B
B S G
B
}
# Open session file
set file [open $session_file r]
while {1} {
# Break on EOF
if {[eof $file]} {
close $file
break
}
# Get and adjust line
set line [gets $file]
regsub {\s*#.*$} $line {} line
if {$line == {}} {continue}
# Determinate key and value
regexp {^\w+} $line key
regexp {\=.*$} $line value
set value [string replace $value 0 0]
set key [string trim $key]
set value [string trim $value "\" \t"]
# Check for valid key
set keyIndex [lsearch -exact -ascii $acceptable_keys $key]
if {$keyIndex == -1} {
puts stderr "Unrecognized key: '$key'"
continue
}
# Check for valid datatype
set dt [lindex $datatypes $keyIndex]
switch -- $dt {
B { ;# Boolean
if {![string is boolean -strict $value]} {
puts stderr "Invalid value '$value', expected boolean"
continue
}
}
I { ;# unsigned Integer
if {![string is integer -strict $value]} {
puts stderr "Invalid value '$value', expected integer"
continue
}
}
S { ;# String
}
G { ;# window Geometry
if {![regexp {=?\d+x\d+(\+\d+\+\d+)?} $value]} {
puts stderr "Invalid value '$value', expected win. geometry (key == $key)"
continue
}
}
}
# Parse key "OPENED_PROJECTS"
if {$key == {OPENED_PROJECTS}} {
set value [string trim $value {( )}]
}
# Set appropriate value of config array
set ::CONFIG($key) $value
}
}
# Validate some configuration values
if {![regexp {^\s*([01]\s+){45}[01]\s*$} $::CONFIG(CLEANUP_OPTIONS)]} {
puts stderr "Invalid record CLEANUP_OPTIONS -- setting to default value"
set ::CONFIG(CLEANUP_OPTIONS) $default_CLEANUP_OPTIONS
}
if {![regexp {^\s*[01]\s[01]\s[01]\s[01]\s[01]\s*$} $::CONFIG(FIND_OPTIONS)]} {
puts stderr "Invalid record FIND_OPTIONS -- setting to default value"
set ::CONFIG(FIND_OPTIONS) $default_FIND_OPTIONS
}
if {![regexp {^\s*[01]\s[01]\s[01]\s[01]\s*$} $::CONFIG(REPLACE_OPTIONS)]} {
puts stderr "Invalid record REPLACE_OPTIONS -- setting to default value"
set ::CONFIG(REPLACE_OPTIONS) $default_REPLACE_OPTIONS
}
if {![regexp {^\s*[01]\s+[01]\s+[01]\s*$} $::CONFIG(REGWATCHES_CONFIG)]} {
puts stderr "Invalid record REGWATCHES_CONFIG -- setting to default value"
set ::CONFIG(REGWATCHES_CONFIG) {1 1 0}
}
# Adjust some configuration values
set line2pc_jump $::CONFIG(LINE2PC_JUMP)
set find_option_CS [lindex $::CONFIG(FIND_OPTIONS) 0]
set find_option_back [lindex $::CONFIG(FIND_OPTIONS) 1]
set find_option_cur [lindex $::CONFIG(FIND_OPTIONS) 2]
set find_option_sel [lindex $::CONFIG(FIND_OPTIONS) 3]
set find_option_reg [lindex $::CONFIG(FIND_OPTIONS) 4]
set replace_option_CS [lindex $::CONFIG(REPLACE_OPTIONS) 0]
set replace_option_back [lindex $::CONFIG(REPLACE_OPTIONS) 1]
set replace_option_cur [lindex $::CONFIG(REPLACE_OPTIONS) 2]
set replace_option_reg [lindex $::CONFIG(REPLACE_OPTIONS) 3]
set file_recent_files $::CONFIG(FILE_RECENT_FILES)
set project_recent_files $::CONFIG(PROJECT_RECENT_FILES)
set vhw_recent_files $::CONFIG(VHW_RECENT_FILES)
for {set i 0} {$i < 21} {incr i} {
set val [lindex $::CONFIG(LETTER_CASE) $i]
if {$val != {U} && $val != {L} && $val != {-}} {
set val {-}
}
set change_letter_case_options($i) $val
}
if {!$::CLI_OPTION(defaults)} {
if {$::CLI_OPTION(ignore_last)} {
set ::CONFIG(OPENED_PROJECTS) {}
}
if {$::CLI_OPTION(open_project) != {}} {
set ::CONFIG(OPENED_PROJECTS) [list $::CLI_OPTION(open_project)]
}
}
# Return result
return $session_file_exists
}
## Invoke dialog "Exit program"
# @parm Bool force=0 - Do not allow user to cancel the request
# @return Int - result
# '0' == Save selected
# '1' == Save all
# '2' == Discard
# '3' == Cancel
proc shutdown_dialog {{force 0}} {
variable unsaved_projects ;# List: List of project object marked as "unsaved"
catch {unset ::exit_dialog_result}
# Create dialog window
set dialog [toplevel .save_multiple_projects -class {Save multimple} -bg ${::COMMON_BG_COLOR}]
# Create the top part of dialog (Header and some icon)
pack [frame $dialog.topframe] -fill x -expand 1
pack [label $dialog.topframe.image \
-image ::ICONS::32::fileclose \
] -side left -padx 10
pack [label $dialog.topframe.message \
-text [mc "The following documents have been modified,\ndo you want to save them before closing ?"] \
] -side right -fill x -expand 1
# Create the middle part of the dialog (list of unsaved files)
ttk::labelframe $dialog.lf -text [mc "Unsaved files"] -labelanchor nw -padding 5
set last_project {}
set i 0
foreach unsaved $unsaved_projects {
# Project name
if {[lindex $unsaved 0] != $last_project} {
set last_project [lindex $unsaved 0]
pack [label $dialog.lf.chp$i \
-text [mc "Project: \"%s\"" [$last_project cget -projectName]] \
-image ::ICONS::16::kcmdevices \
-compound left \
] -anchor w -padx 20 -pady 5
}
# Unsaved files
set ::unsavedfile$i 1
pack [checkbutton $dialog.lf.chb$i \
-text [[lindex $unsaved 1] cget -filename] \
-variable ::unsavedfile$i \
] -anchor w -padx 60
incr i
}
# Create the bottom part of the dialog (buttons)
ttk::separator $dialog.separator -orient horizontal
frame $dialog.f
# button SAVESELECTED
pack [ttk::button $dialog.f.b_save_selected \
-text [mc "Save selected"] \
-underline 0 \
-compound left \
-image ::ICONS::16::filesave \
-command {set ::exit_dialog_result 0} \
] -side left -padx 5
bind $dialog.f.b_save_selected <Return> {set ::exit_dialog_result 0}
bind $dialog.f.b_save_selected <KP_Enter> {set ::exit_dialog_result 0}
# button SAVEALL
pack [ttk::button $dialog.f.b_save_all \
-text [mc "Save all"] \
-underline 5 \
-compound left \
-image ::ICONS::16::save_all \
-command {set ::exit_dialog_result 1} \
] -side left -padx 5
bind $dialog.f.b_save_all <Return> {set ::exit_dialog_result 1}
bind $dialog.f.b_save_all <KP_Enter> {set ::exit_dialog_result 1}
# button DESTROY
pack [ttk::button $dialog.f.b_discard \
-text [mc "Discard"] \
-underline 0 \
-compound left \
-image ::ICONS::16::editdelete \
-command {set ::exit_dialog_result 2} \
] -side left -padx 5
bind $dialog.f.b_discard <Return> {set ::exit_dialog_result 2}
bind $dialog.f.b_discard <KP_Enter> {set ::exit_dialog_result 2}
# button CANCEL
if {!$force} {
pack [ttk::button $dialog.f.b_cancel \
-text [mc "Cancel"] \
-underline 0 \
-compound left \
-image ::ICONS::16::button_cancel \
-command {set ::exit_dialog_result 3} \
] -side left -padx 5
bind $dialog.f.b_cancel <Return> {set ::exit_dialog_result 3}
bind $dialog.f.b_cancel <KP_Enter> {set ::exit_dialog_result 3}
}
# Pack GUI parts
pack $dialog.lf -fill both -expand 1 -pady 10 -padx 10
pack $dialog.separator -fill x -expand 1 -padx 10
pack $dialog.f -pady 5 -padx 5
# Set key-events bindings
bind $dialog <Alt-Key-s> {set ::exit_dialog_result 0}
bind $dialog <Alt-Key-a> {set ::exit_dialog_result 1}
bind $dialog <Alt-Key-d> {set ::exit_dialog_result 2}
bind $dialog <Alt-Key-c> {set ::exit_dialog_result 3}
# Window manager options -- modal window
wm iconphoto $dialog ::ICONS::16::exit
wm title $dialog [mc "Exit program - MCU 8051 IDE"]
wm state $dialog normal
wm minsize $dialog 350 200
grab $dialog
focus -force $dialog.f.b_save_all
wm transient $dialog .
if {!$force} {
wm protocol $dialog WM_DELETE_WINDOW "
grab release $dialog
destroy $dialog
set ::exit_dialog_result 3
"
} else {
wm protocol $dialog WM_DELETE_WINDOW "
tk_messageBox \
-parent $dialog \
-type ok \
-icon warning \
-title {[mc {Attention}]} \
-message {[mc {You have to chose one action}]}
"
}
vwait ::exit_dialog_result
grab release $dialog
destroy $dialog
return ${::exit_dialog_result}
}
## Simulator: STEPBACK
# @return void
proc __stepback {} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if simulator is engaged
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
set critical_procedure_in_progress 0
return
}
# Check if simulator isn't busy
if {[$actualProject sim_is_busy]} {
Sbar [mc "Simulator is busy"]
set critical_procedure_in_progress 0
return
}
# Perform program step
stepback_button_set_ena [$actualProject stepback]
set lineNum [$actualProject simulator_getCurrentLine]
if {$lineNum != {}} {
$actualProject move_simulator_line $lineNum
} else {
$actualProject editor_procedure {} unset_simulator_line {}
}
$actualProject Simulator_sync_PC_etc
# Finalize
set critical_procedure_in_progress 0
}
## Simulator: STEP
# @return void
proc __step {} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if simulator is engaged
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
set critical_procedure_in_progress 0
return
}
# Check if simulator isn't busy
if {[$actualProject sim_is_busy]} {
Sbar [mc "Simulator is busy"]
set critical_procedure_in_progress 0
return
}
# Perform program step
set lineNum [$actualProject step]
if {$lineNum != {}} {
$actualProject move_simulator_line $lineNum
} else {
$actualProject editor_procedure {} unset_simulator_line {}
}
stepback_button_set_ena [$actualProject simulator_get_SBS_len]
$actualProject Simulator_sync_PC_etc
# Finalize
set critical_procedure_in_progress 0
}
## Simulator: STEPOVER
# @return void
proc __stepover {} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if simulator is engaged
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
set critical_procedure_in_progress 0
return
}
# Check if simulator isn't busy
if {[$actualProject sim_run_in_progress] || [$actualProject sim_anim_in_progress]} {
Sbar [mc "Simulator is busy"]
set critical_procedure_in_progress 0
return
}
# Change button image (simulator control panel)
$actualProject invert_stepover_button
# Perform program step
set lineNum [$actualProject sim_stepover]
if {$lineNum != {}} {
$actualProject move_simulator_line $lineNum
} else {
$actualProject editor_procedure {} unset_simulator_line {}
}
stepback_button_set_ena [$actualProject simulator_get_SBS_len]
$actualProject invert_stepover_button ;# Change button image (simulator control panel)
$actualProject Simulator_sync_PC_etc ;# Synchronize PC and Time
}
## Simulator: ANIMATE
# @return void
proc __animate {} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if simulator is engaged
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
set critical_procedure_in_progress 0
return
}
# Check if simulator isn't busy
if {[$actualProject sim_run_in_progress] || [$actualProject sim_stepover_in_progress]} {
Sbar [mc "Simulator is busy"]
set critical_procedure_in_progress 0
return
}
stepback_button_set_ena [$actualProject simulator_get_SBS_len]
$actualProject invert_animate_button ;# Change button image (simulator control panel)
$actualProject sim_animate ;# Start simulator in mode "animate"
$actualProject invert_animate_button ;# Change button image (simulator control panel)
}
## Simulator: RUN
# @return void
proc __run {} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if simulator isn't already engaged
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
set critical_procedure_in_progress 0
return
}
# Check if simulator isn't busy
if {[$actualProject sim_anim_in_progress] || [$actualProject sim_stepover_in_progress]} {
Sbar [mc "Simulator is busy"]
set critical_procedure_in_progress 0
return
}
# Change button image (simulator control panel)
$actualProject invert_run_button
## Start simulator
# Remove simulator cursor from editor
$actualProject editor_procedure {} unset_simulator_line {}
# Engage mode "run"
set line_num [$actualProject sim_run]
if {$line_num != {}} {
$actualProject move_simulator_line $line_num
} else {
$actualProject editor_procedure {} unset_simulator_line {}
}
# Adjust simulator control panel
$actualProject invert_run_button
stepback_button_set_ena [$actualProject simulator_get_SBS_len]
# Synchronize
$actualProject Simulator_sync ;# Simulator GUI (registers)
$actualProject Simulator_sync_clock ;# Simulator GUI (time)
$actualProject Simulator_sync_PC_etc ;# Simulator GUI (PC, Watchdog, etc.)
refresh_xram_mem_window $actualProject ;# XDATA memory hexadecimal editor
refresh_eram_mem_window $actualProject ;# EDATA memory hexadecimal editor
refresh_eeprom_mem_window $actualProject ;# Data EEPROM hexadecimal editor
}
## Simulator: RESET
# @parm Char arg - reset mode
# '-' == no change (IRAM and XRAM)
# '0' == all zeroes (IRAM and XRAM)
# '1' == all ones (IRAM and XRAM)
# 'r' == random values (IRAM and XRAM)
# @return void
proc __reset {arg} {
variable simulator_enabled ;# List of booleans: Simulator engaged
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
if {$project_menu_locked} {return}
# This function is critical + simulator must be on
if {$critical_procedure_in_progress} {return}
if {![lindex $simulator_enabled $actualProjectIdx]} {
Sbar [mc "Simulator is not started"]
return
}
set critical_procedure_in_progress 1
# Clear program time
$actualProject simulator_clear_overall_time
# Clear graph
$actualProject clear_graph
# Perform reset
$actualProject Simulator_reset $arg
$actualProject simulator_setWatchDogTimer 0
# Move simulator cursor in editor to the beginning of the program
foreach editor [$actualProject cget -editors] {
$editor unset_simulator_line
}
$actualProject move_simulator_line [$actualProject simulator_getCurrentLine]
# Synchronize with Hex editor and Register watches on right panel
if {$arg != {-}} {
refresh_xram_mem_window $actualProject
refresh_eram_mem_window $actualProject
refresh_eeprom_mem_window $actualProject
$actualProject rightPanel_watch_sync_all
}
# Inform code memory hexadecimal editor about the reset
program_counter_changed $actualProject 0
# Finalize
set critical_procedure_in_progress 0
}
## Start/Shutdown simulator
# @parm Bool current_file_only=0 - Load debug file for the current file only (not the main file)
# @return void
proc __initiate_sim {{current_file_only 0}} {
variable actualProject ;# Object: Current project
variable simulator_enabled ;# List of booleans: Simulator engaged
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Clear program timer
$actualProject simulator_clear_overall_time
# Shutdown simulator
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
lset simulator_enabled $actualProjectIdx 0 ;# Simlulator disabled (set flag)
$actualProject Simulator_shutdown ;# Shutdown simulator engine
$actualProject sim_disable ;# Disable widgets of simulator GUI
$actualProject sfr_watches_disable ;# Disable SFR watches
$actualProject rightPanel_watch_disable ;# Disable widgets of register watches
$actualProject sfrmap_setEnabled 0 ;# Disable SFR map
$actualProject bitmap_setEnabled 0 ;# Disable map of bit area
$actualProject thaw ;# Unlock menus in file lists
line2pc_safely_close ;# Safely Close dialog "Line to address"
$actualProject subprograms_setEnabled 0 ;# Disable list of subprograms
$actualProject cvarsview_setEnabled 0 ;# Disable C vars view
$actualProject stack_monitor_set_enabled 0 ;# Disable stack monitor
update
Lock_simulator_menu ;# Lock simulator menu and toolbar
$actualProject interrupt_monitor_disable_buttons;# Disable interrupt monitor
# Remove simulator pointers
foreach editor [$actualProject cget -editors] {
$editor unset_simulator_line
}
# Inform code memory hexadecimal editor about that
set idx [lsearch -exact -ascii $opened_code_mem_windows [string trimleft $actualProject {:}]]
if {$idx != -1} {
[lindex $code_mem_window_objects $idx] simulator_stared_stopped 0
}
# Start simulator
} else {
# Get ID of currently active page on bottom notebook
set bottom_page_ID [$actualProject getBottomPanelActivePage]
# Determinate name of simulator data file
set full_file_name [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
set relative_name [lindex $full_file_name 1]
if {$current_file_only || $relative_name == {}} {
set full_file_name [$actualProject editor_procedure {} getFileName {}]
set language [$actualProject editor_procedure {} get_language {}]
set relative_name [lindex $full_file_name 1]
} else {
set ext [string trimleft [file extension $relative_name] {.}]
if {$ext == {c} || $ext == {h} || $ext == {cxx} || $ext == {cpp} || $ext == {cc}} {
set language 1
} elseif {$ext == {lst}} {
set language 2
} else {
set language 0
}
}
set full_file_name [file join [lindex $full_file_name 0] [lindex $full_file_name 1]]
set full_file_name [file rootname $full_file_name]
if {$language == 1} {
append full_file_name {.cdb}
} else {
append full_file_name {.adf}
}
# Try to open the file and determinate expected MD5 hash
if {![catch {
# C language
if {$language == 1} {
set hashes_file [open "[file rootname $full_file_name].hashes" {r}]
set expected_md5s [read $hashes_file]
close $hashes_file
# Assembly language
} elseif {$language == 0} {
set expected_md5s {}
set simulator_file [open $full_file_name r]
while {![eof $simulator_file]} {
set line [gets $simulator_file]
if {$line == {} || [regexp {^\s*#} $line]} {
continue
}
set expected_md5s $line
break
}
close $simulator_file
# Invalid request!
} else {
error "Invalid request!"
}
}]} then {
# MD5 hash verification failed -> ask for recompilation
if {($language == 0 || $language == 1) && [verify_md5_hashes 1 $expected_md5s [file dirname $full_file_name]]} {
# Ask for recompilation
set response [
tk_messageBox \
-parent . \
-icon question \
-type yesno \
-default {yes} \
-title [mc "Recompile ?"] \
-message [mc "MD5 hashes verification failed. That probably means than some source files have been modified since last compilation.\n\nDo you want to recompile the code ?"] \
]
if {$response != {yes}} {
set critical_procedure_in_progress 0
return
}
## Compile the source code
set compilation_result [__compile 1 1]
# (0) Compilation failed
if {!$compilation_result} {
tk_messageBox \
-parent . \
-icon error \
-type ok \
-title [mc "Compilation failed"] \
-message [mc "Compilation failed, see messages for details."]
set critical_procedure_in_progress 0
return
# (2) External compiler used
} elseif {$compilation_result == 2} {
return
}
}
# Unable to open the simulator data file -> ask for recompilation
} else {
# Ask for recompilation
set response [
tk_messageBox \
-parent . \
-icon question \
-type yesno \
-title [mc "File not found"] \
-message [mc "Simulator data file not found.\nDo you want create it ?"]
]
if {$response != {yes}} {
set critical_procedure_in_progress 0
return
}
## Compile the source code
set compilation_result [__compile 1 1]
# (0) Compilation failed
if {!$compilation_result} {
tk_messageBox \
-parent . \
-icon error \
-type ok \
-title [mc "Compilation failed"] \
-message [mc "Compilation failed, see messages for details."]
set critical_procedure_in_progress 0
return
# (2) External compiler used
} elseif {$compilation_result == 2} {
return
}
set full_file_name [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
if {[lindex $full_file_name 1] == {}} {
set full_file_name [$actualProject editor_procedure {} getFileName {}]
}
set full_file_name [file join [lindex $full_file_name 0] [lindex $full_file_name 1]]
regsub {\.[^\.]*$} $full_file_name {} full_file_name
append full_file_name {.adf}
}
# Open simulator data file
if {[catch {
set simulator_file [open $full_file_name r]
}]} then {
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unable to start simulator"] \
-message [mc "Unable to read simulator file. Possibly you have disabled generation of simulator file in compiler configuration dialog."]
set critical_procedure_in_progress 0
return
}
# Try to load IHX file if C language is used
if {$language == 1} {
if {[catch {
set hex_file [open "[file rootname $full_file_name].ihx" r]
} result]} then {
puts stderr $result
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to find hex file"] \
-message [mc "Unable to open:\n'%s'" "[file rootname $full_file_name].ihx"]
return
}
}
$actualProject freeze ;# Switch filelist to "Simulator mode"
update
# Raise tab "Simulator" on the bottom panel
if {[lsearch {Graph Simulator CVarsView} $bottom_page_ID] == -1} {
$actualProject bottomNB_show_up {Simulator}
} else {
$actualProject bottomNB_show_up $bottom_page_ID
}
## Engage simulator
lset simulator_enabled $actualProjectIdx 1 ;# Set simulator enabled flag to True
$actualProject sim_enable ;# Enable simulator GUI
$actualProject sfr_watches_enable ;# Enable SFR watches
$actualProject sfrmap_setEnabled 1 ;# Enable SFR map
$actualProject bitmap_setEnabled 1 ;# Enable map of bit area
# Load program into simulator engine
if {$language == 1} {
if {[$actualProject load_program_from_cdb \
[file rootname $full_file_name].c \
$simulator_file $hex_file \
]} {
seek $simulator_file 0
$actualProject cvarsview_load_cdb $simulator_file
}
close $hex_file
} else {
$actualProject load_program_from_adf $simulator_file
}
# Autoload list of defined symbolic name into register watches
$actualProject rightPanel_watch_autoload [file rootname $full_file_name].lst
# Some more initialization
close $simulator_file ;# Close simulator data file
$actualProject clear_graph ;# Clear graph
$actualProject Simulator_sync ;# Synchronize simulator (due to reset)
$actualProject rightPanel_watch_enable ;# Enable entry widgets in register watches
$actualProject subprograms_setEnabled 1 ;# Enable list of subprograms
$actualProject cvarsview_setEnabled 1 ;# Enable C vars view
$actualProject stack_monitor_set_enabled 1 ;# Enable stack monitor
$actualProject Simulator_initiate ;# Initialize simulator engine
$actualProject interrupt_monitor_enable_buttons ;# Enable interrupt monitor
__sim_clear_highlight ;# Clear all highlights
# Reset virtual MCU
set critical_procedure_in_progress 0
__reset -
set critical_procedure_in_progress 1
# Load breakpoints into simulator engine
set found 0
set editor {}
set editors [$actualProject cget -editors]
foreach filename [$actualProject simulator_get_list_of_filenames] {
set found 0
foreach editor $editors {
if {$filename == [$editor cget -fullFileName]} {
set found 1
break
}
}
if {$found} {
$actualProject Simulator_import_breakpoints \
$filename [$editor getBreakpoints]
} else {
$actualProject Simulator_import_breakpoints $filename {}
}
}
# Detect and report invalid breakpoints
$actualProject report_invalid_breakpoints
$actualProject now_frozen
# Set simulator cursor in editor to the first OP code
$actualProject move_simulator_line [$actualProject simulator_getCurrentLine]
refresh_code_mem_window $actualProject ;# Synchronize CODE memory hex editor
update
Unlock_simulator_menu ;# Unlock simulator menu and toolbar
stepback_button_set_ena 0 ;# Disable StepBack controls
# Inform code memory hexadecimal editor about that
set idx [lsearch -exact -ascii $opened_code_mem_windows [string trimleft $actualProject {:}]]
if {$idx != -1} {
[lindex $code_mem_window_objects $idx] simulator_stared_stopped 1
}
}
# Finalize
set critical_procedure_in_progress 0
}
## Verify MD5 hashes for the given files (only for current project)
# @parm Bool save_files - Save modified files mentioned in the given list
# @parm List hashes - {hash filename hash filename ...}
# @parm String dir - Directory where the function will search for the files mentioned in "$hashes"
# @return Int - Final result
# 0 == All correct
# 1 == Verification failed
# 2 == File access error
proc verify_md5_hashes {save_files hashes dir} {
variable actualProject ;# Object: Current project
# Local variables
set len [llength $hashes] ;# Length of the given list of hashes and files
set filenames {} ;# List of filenames only
set md5_hashes {} ;# List of md5 hashes only
# Separate filenames and hashes
for {set i 0; set j 1} {$i < $len} {incr i 2; incr j 2} {
lappend filenames [file join $dir [lindex $hashes $j]]
lappend md5_hashes [lindex $hashes $i]
}
set len [expr {int($len/2)}]
# Save mentioned files
if {$save_files} {
set idx 0
set e_filenames {}
set editors [$actualProject cget -editors]
# Determinate list of opened files
foreach editor $editors {
set filename [$editor cget -fullFileName]
if {$filename == {}} {
continue
}
lappend e_filenames $filename
}
# Save files
for {set i 0} {$i < $len} {incr i} {
set idx [lsearch $e_filenames [lindex $filenames $i]]
if {$idx == -1} {continue}
if {[[lindex $editors $idx] cget -modified]} {
[lindex $editors $idx] save
}
}
}
# Check MD5s
for {set i 0} {$i < $len} {incr i} {
set recorded_md5 [lindex $md5_hashes $i]
if {[catch {
set computed_md5 [::md5::md5 -hex -file [lindex $filenames $i]]
}]} then {
return 2
}
if {$recorded_md5 != $computed_md5} {
return 1
}
}
return 0
}
## Invoke file selection dialog to normalize IHEX8 file
# @return void
proc __normalize_hex {} {
variable input_file ;# Input file
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
if {$critical_procedure_in_progress} {return}
# Invoke dialog to select input file
set input_file {}
select_input_output 1 {hex} .
if {$input_file == {}} {return}
# File name is not valid -> invoke error message
if {
$input_file == {} ||
![file exists $input_file] ||
![file isfile $input_file] ||
(!$::MICROSOFT_WINDOWS && ![file writable $input_file]) ||
(!$::MICROSOFT_WINDOWS && ![file readable $input_file])
} then {
tk_messageBox \
-parent . -icon warning \
-title [mc "Error - MCU 8051 IDE"] \
-message [mc "Unable to gain unlimited access to the given file"]
# File name is valid -> normalize its content
} else {
# Progress dialog
create_progress_bar .prgDl \
. \
{} \
"Parsing file: $input_file" \
::IHexTools::progress \
1 \
[mc "Parsing file ..."] \
::ICONS::16::bottom1 \
[mc "Abort"] \
{set ::IHexTools::abort 1}
# Read file
set file [open $input_file r]
set data [read $file]
close $file
# Normalize content
set ::IHexTools::update 1
catch {.prgDl.f.progressbar configure -maximum [::IHexTools::get_number_of_iterations $data]}
::IHexTools::load_hex_data $data
if {!${::IHexTools::abort} && !${::IHexTools::error_count}} {
catch {.prgDl.f.progressbar configure -maximum 16}
set data [::IHexTools::get_hex_data]
}
# Destroy progress dialog
catch {destroy .prgDl}
# No errors occurred -> rewrite file
if {!${::IHexTools::error_count}} {
if {[catch {
set file [open $input_file w 0640]
}]} then {
tk_messageBox \
-type ok \
-icon error \
-parent . \
-title [mc "Permission denied"] \
-message [mc "Unable to open file:\n\"%s\"\nfor writing" $input_file]
return
} else {
puts -nonewline $file $data
close $file
}
# Errors occurred -> Invoke error message dialog
} else {
# Create dialog window
set dialog [toplevel .error_message_dialog -class {Error dialog} -bg ${::COMMON_BG_COLOR}]
# Create main frame (text widget and scrolbar)
set main_frame [frame $dialog.main_frame]
# Create text widget
set text [text $main_frame.text \
-yscrollcommand "$main_frame.scrollbar set" \
-width 0 -height 0 \
]
pack $text -side left -fill both -expand 1
# Create scrollbar
pack [ttk::scrollbar $main_frame.scrollbar \
-orient vertical \
-command "$text yview" \
] -side right -fill y
# Pack main frame and create button "Close"
pack $main_frame -fill both -expand 1
pack [ttk::button $dialog.ok_button \
-text [mc "Close"] \
-command "grab release $dialog; destroy $dialog" \
]
# Show error string and disable the text widget
$text insert end ${::IHexTools::error_string}
$text configure -state disabled
# Set window attributes
wm iconphoto $dialog ::ICONS::16::status_unknown
wm title $dialog [mc "Error(s) occurred while parsing IHEX file - %s" ${::APPNAME}]
wm minsize $dialog 500 250
wm protocol $dialog WM_DELETE_WINDOW [mc "grab release %s; destroy %s" $dialog $dialog]
wm transient $dialog .
grab $dialog
raise $dialog
tkwait window $dialog
}
# Free resources reserved during normalization
::IHexTools::free_resources
}
}
## Invoke dialog for converting Binary files to Intel® HEX 8 files
# @return void
proc __bin2hex {} {
variable hex__bin ;# Type of conversion
set hex__bin 0
hex2bin2hex
}
## Invoke dialog for converting Intel® HEX 8 files to Binary files
# @return void
proc __hex2bin {} {
variable hex__bin ;# Type of conversion
set hex__bin 1
hex2bin2hex
}
## Invoke dialog for converting Simulator data files to Intel® HEX 8 files
# @return void
proc __sim2hex {} {
variable hex__bin ;# Type of conversion
set hex__bin 2
hex2bin2hex
}
## Invoke dialog for converting Simulator data files to Binary files
# @return void
proc __sim2bin {} {
variable hex__bin ;# Type of conversion
set hex__bin 3
hex2bin2hex
}
## Invoke conversion dialog -- auxiliary procedure for '__bin2hex', '__hex2bin', '__sim2hex', '__sim2bin'
# @return void
proc hex2bin2hex {} {
variable input_file ;# Input file
variable output_file ;# Output file
variable hex__bin ;# Type of conversion
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
if {$critical_procedure_in_progress} {return}
# Create dialog window
set win [toplevel .hex2bin2hex_dialog -class {Conversion} -bg ${::COMMON_BG_COLOR}]
set mainframe [frame $win.frame]
# Label, Entry and Button "Input file"
grid [Label $mainframe.lbl_input \
-text [mc "Input file"] \
-helptext [mc "File to convert"] \
] -column 1 -row 1 -sticky w
grid [ttk::entry $mainframe.entry_input \
-textvariable X::input_file \
-width 50 \
] -column 2 -row 1 -sticky we
DynamicHelp::add $mainframe.entry_input -text [mc "File to convert"]
grid [ttk::button $mainframe.button_select_input_file \
-image ::ICONS::16::fileopen \
-takefocus 0 \
-style Flat.TButton \
-command {
# Determinate file suffix
if {${::X::hex__bin} == 0} {
set mask {bin}
} elseif {${::X::hex__bin} == 1} {
set mask {{hex,ihx}}
} else {
set mask {adf}
}
# Invoke file selection dialog
X::select_input_output 1 $mask .hex2bin2hex_dialog
} \
] -column 3 -row 1 -sticky e
DynamicHelp::add $mainframe.button_select_input_file \
-text [mc "Invoke dialog to select input file"]
# Label, Entry and Button "Output file"
grid [Label $mainframe.lbl_output \
-text [mc "Output file"] \
-helptext [mc "File where to save result"] \
] -column 1 -row 2 -sticky w
grid [ttk::entry $mainframe.entry_output \
-textvariable X::output_file \
-width 50 \
] -column 2 -row 2 -sticky we
DynamicHelp::add $mainframe.entry_output \
-text [mc "File where to save result"]
grid [ttk::button $mainframe.button_select_output_file \
-image ::ICONS::16::fileopen \
-style Flat.TButton \
-command {
# Determinate file suffix
if {${::X::hex__bin} == 0} {
set mask {{hex,ihx}}
} elseif {${::X::hex__bin} == 1} {
set mask {bin}
} elseif {${::X::hex__bin} == 2} {
set mask {{hex,ihx}}
} elseif {${::X::hex__bin} == 3} {
set mask {bin}
}
# Invoke file selection dialog
X::select_input_output 0 $mask .hex2bin2hex_dialog
} \
] -column 3 -row 2 -sticky e
DynamicHelp::add $mainframe.button_select_output_file \
-text [mc "Invoke dialog to select output file"]
# Create separator
grid [ttk::separator $mainframe.separator \
-orient horizontal \
] -column 1 -columnspan 3 -row 3 -sticky we -pady 10
# Create buttons "Ok" and "Cancel"
set button_frame [frame $mainframe.button_frame]
pack [ttk::button $button_frame.button_ok \
-text [mc "Ok"] \
-command {X::hex2bin2hex_OK} \
-compound left \
-image ::ICONS::16::ok \
] -side left -padx 5
pack [ttk::button $button_frame.button_cancel \
-text [mc "Cancel"] \
-command {X::hex2bin2hex_CANCEL} \
-compound left \
-image ::ICONS::16::button_cancel \
] -side left -padx 5
grid $button_frame -column 1 -columnspan 3 -row 4
# Set window title
if {$hex__bin == 0} {
wm title $win [mc "Convert Binary file to Intel HEX 8 - MCU 8051 IDE"]
} elseif {$hex__bin == 1} {
wm title $win [mc "Convert Intel HEX 8 to binary file - MCU 8051 IDE"]
} elseif {$hex__bin == 2} {
wm title $win [mc "Convert sim file to Intel HEX 8 - MCU 8051 IDE"]
}
pack $mainframe -fill both -expand 1 -padx 5 -pady 5
# Event bindings (Enter == Ok; Escape == Cancel)
bind $win <KeyRelease-Return> {X::hex2bin2hex_OK; break}
bind $win <KeyRelease-KP_Enter> {X::hex2bin2hex_OK; break}
bind $win <KeyRelease-Escape> {X::hex2bin2hex_CANCEL; break}
# Set window attributes -- modal window
wm iconphoto $win ::ICONS::16::bottom1
wm minsize $win 450 100
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW {
X::hex2bin2hex_CANCEL
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Increment compilation progress variable and call update command
# @return void
proc update_progress {} {
variable compilation_progress ;# Variable for compilation progressbar
incr compilation_progress
update
}
## Set maximum for progressbar in file conversion dialog
# -- internal auxiliary procedure for 'hex2bin2hex_OK'
# @parm Int max - value to set
# @return void
proc hex2bin2hex_set_progress_max {max} {
.hex2bin2hex_dialog.button_frame.progress_bar configure -maximum $max
}
## Perform file conversion -- auxiliary procedure for 'hex2bin2hex'
# @return void
proc hex2bin2hex_OK {} {
variable input_file ;# Input file
variable output_file ;# Output file
variable hex__bin ;# Type of conversion
# Check if input and output file names are not empty strings
if {$input_file == {} || $output_file == {}} {
tk_messageBox \
-parent .hex2bin2hex_dialog \
-icon warning -type ok \
-title "MCU 8051 IDE" \
-message [mc "Both entries must be filled"]
return
}
# Normalize name of input file
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $input_file]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$input_file"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $input_file]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $input_file]
}
}
set input_file [file normalize $input_file]
# Normalize name of output file
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $output_file]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$output_file"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $output_file]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $output_file]
}
}
set output_file [file normalize $output_file]
set win .hex2bin2hex_dialog
bind $win <KeyRelease-Return> {}
bind $win <KeyRelease-KP_Enter> {}
bind $win <KeyRelease-Escape> {}
# Diable entry widgets in file selection dialog
foreach wdg [subst {
$win.frame.entry_input
$win.frame.entry_output
$win.frame.button_select_input_file
$win.frame.button_select_output_file
}] {
$wdg configure -state disabled
}
# Destroy buttons "Ok" and "Cancel"
destroy $win.frame.button_frame.button_ok
destroy $win.frame.button_frame.button_cancel
# Change window size
wm minsize $win 450 170
# Create staus label, progressbar and Abort button
set status_label [label $win.frame.button_frame.status_label -justify left]
set progressbar [ttk::progressbar \
$win.frame.button_frame.progress_bar \
-variable ::IHexTools::progress \
-mode determinate \
-length 440 \
]
pack $status_label -anchor w -padx 10
pack $progressbar -pady 15
pack [ttk::button $win.frame.button_frame.button_ok \
-text [mc "Abort"] \
-image ::ICONS::16::cancel \
-compound left \
-command {X::hex2bin2hex_ABORT} \
] -pady 5
# Create backup copy for output file
if {[file exists $output_file] && [file isfile $output_file]} {
if {![file writable $output_file]} {
tk_messageBox \
-type ok \
-icon error \
-parent $win \
-title [mc "Permission denied"] \
-message [mc "Unable to access file: %s" $output_file]
hex2bin2hex_CANCEL
return
}
# Ask user for overwrite existing file
if {[tk_messageBox \
-type yesno \
-icon question \
-parent $win \
-title [mc "Overwrite file"] \
-message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $output_file]]
] != {yes}
} then {
hex2bin2hex_CANCEL
return
}
# Create a backup file
catch {
file rename -force $output_file "$output_file~"
}
}
# Read input file
if {[catch {
set file [open $input_file r]
fconfigure $file -translation binary
set data [read $file]
close $file
}]} then {
tk_messageBox \
-type ok \
-icon warning \
-parent $win \
-title [mc "File not found - MCU 8051 IDE"] \
-message [mc "Unable to open file '%s'" $input_file]
} else {
# Update progress variable
set ::IHexTools::update 1
# Perform cnversion
switch -- $hex__bin {
0 { ;# Bin -> Hex
$status_label configure -text [mc "Loading file ..."]
::IHexTools::load_bin_data $data
set data {}
if {!${::IHexTools::abort} && !${::IHexTools::error_count}} {
$status_label configure -text [mc "Saving file ..."]
$progressbar configure -maximum 16
set data [::IHexTools::get_hex_data]
}
}
1 { ;# Hex -> Bin
$status_label configure -text [mc "Loading file ..."]
$progressbar configure -maximum [::IHexTools::get_number_of_iterations $data]
::IHexTools::load_hex_data $data
set data {}
if {!${::IHexTools::abort} && !${::IHexTools::error_count}} {
$status_label configure -text [mc "Saving file ..."]
$progressbar configure -maximum 16
set data [::IHexTools::get_bin_data]
}
}
2 { ;# Sim -> Hex
$status_label configure -text [mc "Loading file ..."]
$progressbar configure -maximum [::IHexTools::get_number_of_iterations $data]
::IHexTools::load_sim_data $data
set data {}
if {!${::IHexTools::abort} && !${::IHexTools::error_count}} {
$status_label configure -text [mc "Saving file ..."]
$progressbar configure -maximum 16
set data [::IHexTools::get_hex_data]
}
}
3 { ;# Sim -> Bin
$status_label configure -text [mc "Loading file ..."]
$progressbar configure -maximum [::IHexTools::get_number_of_iterations $data]
::IHexTools::load_sim_data $data
set data {}
if {!${::IHexTools::abort} && !${::IHexTools::error_count}} {
$status_label configure -text [mc "Saving file ..."]
$progressbar configure -maximum 16
set data [::IHexTools::get_bin_data]
}
}
default {
set data {}
}
}
# Write output file
if {[string length $data]} {
if {[catch {
set file [open $output_file w 0640]
}]} then {
tk_messageBox \
-type ok \
-icon error \
-parent . \
-title [mc "Permission denied"] \
-message [mc "Unable to open file:\n\"%s\"\nfor writing" $output_file]
hex2bin2hex_CANCEL
return
} else {
fconfigure $file -translation binary
puts -nonewline $file $data
close $file
}
}
}
# If errors occurred -> Invoke error message dialog
if {${::IHexTools::error_count}} {
# Create dialog window
set dialog [toplevel .error_message_dialog -class {Error dialog} -bg ${::COMMON_BG_COLOR}]
# Create main frame (text and scrollbar)
set main_frame [frame $dialog.main_frame]
set text [text $main_frame.text \
-yscrollcommand "$main_frame.scrollbar set" \
-width 0 -height 0 \
]
pack $text -side left -fill both -expand 1
pack [ttk::scrollbar $main_frame.scrollbar \
-orient vertical \
-command "$text yview" \
] -side right -fill y
pack $main_frame -fill both -expand 1
# Create button "Close"
pack [ttk::button $dialog.ok_button \
-text [mc "Close"] \
-command "grab release $dialog; destroy $dialog"\
]
$text insert end ${::IHexTools::error_string}
$text configure -state disabled
# Set window attributes -- modal window
wm iconphoto $dialog ::ICONS::16::no
wm title $dialog [mc "Corrupted file - MCU 8051 IDE"]
wm minsize $dialog 520 250
wm protocol $dialog WM_DELETE_WINDOW "grab release $dialog; destroy $dialog"
wm transient $dialog .hex2bin2hex_dialog
grab $dialog
raise $dialog
tkwait window $dialog
}
# Close original dialog
hex2bin2hex_CANCEL
}
## Abort file conversion -- auxiliary procedure for 'hex2bin2hex'
# @return void
proc hex2bin2hex_ABORT {} {
set ::IHexTools::abort 1
}
## Close file conversion dialog -- auxiliary procedure for 'hex2bin2hex'
# @return void
proc hex2bin2hex_CANCEL {} {
::IHexTools::free_resources
grab release .hex2bin2hex_dialog
destroy .hex2bin2hex_dialog
}
## Invoke file selection dialog to select input or output file
# Result is stored in variable '::X::input_file' or '::X::output_file'
# @parm Bool io - 1 == Input; 0 == Output
# @parm String mask - File suffix
# @parm Widget master - GUI parent
# @return void
proc select_input_output {io mask master} {
variable IO ;# Bool: 1 == choose input file; 0 == choose output file
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
set IO $io
if {[llength $openedProjects]} {
set project_dir [${::X::actualProject} cget -ProjectDir]
} else {
set project_dir ${::env(HOME)}
}
# Invoke the dialog
catch {delete object fsd}
KIFSD::FSD fsd \
-title [mc "Open file - MCU 8051 IDE"] \
-directory $project_dir \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc "Input file"] "*.$mask"] \
[list [mc "All files"] {*}] \
]
# Ok button
fsd setokcmd {
set filename [X::fsd get]
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $filename]} {
set filename "$project_dir/$filename"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $filename]} {
set filename [file join $project_dir $filename]
}
}
set filename [file normalize $filename]
if {${X::IO}} {
set X::input_file $filename
} else {
set X::output_file $filename
}
}
fsd activate ;# Activate the dialog
}
## Invoke dialog "Disassemble"
# @return void
proc __disasm {} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Invoke the file selection dialog
catch {delete object fsd}
KIFSD::FSD fsd \
-title [mc "Open file - MCU 8051 IDE"] \
-directory [$actualProject cget -projectPath] \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc "IHEX 8"] {*.{hex,ihx}}] \
[list [mc "All files"] {*}] \
]
# Open file after press of OK button
fsd setokcmd {
X::fsd deactivate
set filename [X::fsd get]
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $filename]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$filename"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $filename]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $filename]
}
}
set filename [file normalize $filename]
if {
![file exists $filename] ||
![file isfile $filename] ||
(!$::MICROSOFT_WINDOWS && ![file readable $filename])
} then {
tk_messageBox \
-type ok \
-icon warning \
-parent . \
-title [mc "File not found - MCU 8051 IDE"] \
-message [mc "The selected file %s does not exist." $filename]
} else {
set data [X::decompile $filename]
if {$data != {}} {
${::X::actualProject} background_open $data
if {[lindex ${X::simulator_enabled} ${X::actualProjectIdx}] == 0} {
${::X::actualProject} switch_to_last
}
} else {
tk_messageBox \
-type ok \
-parent . \
-icon warning \
-title [mc "Disassembly failed"] \
-message [mc "Disassembly failed -- see messages for details"]
}
}
}
# activate the dialog
fsd activate
set critical_procedure_in_progress 0
}
## Disaaemble the given file -- auxiliary procedure for '__disasm'
# @parm String filename - name of IHEX8 file to disassemble
# @return String - resulting source code
proc decompile {filename} {
variable compilation_in_progress ;# Bool: Compiler engaged
variable compilation_mess_project ;# Object: Project related to running compilation
variable actualProject ;# Object: Current project
set compilation_in_progress 1
set compilation_mess_project $actualProject
messages_text_append [mc "\nLoading IHEX file ..."]
# Open the specified file
if {[catch {
set file [open $filename r]
}]} then {
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unable to open file"] \
-message [mc "Unable to read file '%s'" $filename]
return {}
}
# Adjust GUI
make_progressBar_on_Sbar ;# Create compilation progress bar on status bar
compilation_progress ;# Initialize compilation progress bar
$actualProject bottomNB_show_up {Messages} ;# Raise tab "Messages" on bottom panel
# Setup compiler
set Compiler::Settings::ABORT_VARIABLE 0
set Compiler::Settings::TEXT_OUPUT_COMMAND X::messages_text_append
set Compiler::Settings::UPDATE_COMMAND {update}
# Perform disassembly
set data {}
set ::IHexTools::update 1
::IHexTools::load_hex_data [read $file]
if {!${::IHexTools::error_count} && !${::IHexTools::abort}} {
messages_text_append [mc "Successful"]
set data [::disassembler::compile [::IHexTools::get_hex_data]]
set ::disassembler::asm {}
}
close $file
# Finalize
set Compiler::Settings::ABORT_VARIABLE 0
destroy_progressBar_on_Sbar
set compilation_in_progress 0
# Write error messages
if {${::IHexTools::error_count}} {
messages_text_append ${::IHexTools::error_string}
messages_text_append [mc "FAILED"]
}
# Free resources reserved during disassembly
::IHexTools::free_resources
return $data
}
## Show/Hide Line numbers (in Editor)
# @return void
proc __show_hine_LineN {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Show/Hide line numbers
$actualProject show_hide_lineNumbers
}
## Show/Hide Icon border (in Editor)
# @return void
proc __show_hine_IconB {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Show/Hide Icon border
$actualProject show_hide_IconBorder
}
## Redraw pane windows -- binding for event <Configure>
# @return void
proc redraw_panes {} {
variable last_WIN_GEOMETRY ;# Last window geometry (main window)
variable openedProjects ;# List of opened projects (Object references)
# Window geometry unchanged -> return
if {$last_WIN_GEOMETRY == [wm geometry .]} {
return
# Refresh last window geometry variable
} else {
set last_WIN_GEOMETRY [wm geometry .]
}
# Gain window height and width
evaluate_new_window_geometry
# Bottom NoteBook
if {${::last_WIN_GEOMETRY_width} != ${::WIN_GEOMETRY_width}} {
set ::last_WIN_GEOMETRY_width ${::WIN_GEOMETRY_width}
foreach project $openedProjects {
catch {
$project leftpanel_redraw_pane
$project right_panel_redraw_pane
$project todo_panel_redraw_pane
}
}
}
# Right panel & File notes
if {${::last_WIN_GEOMETRY_height} != ${::WIN_GEOMETRY_height}} {
set ::last_WIN_GEOMETRY_height ${::WIN_GEOMETRY_height}
foreach project $openedProjects {
catch {
$project bottomNB_redraw_pane
}
}
}
}
## Invoke dialog "About"
# @return void
proc __about {} {
# Create dialog window
set win [toplevel .about -class [mc "About dialog"] -bg ${::COMMON_BG_COLOR}]
# Create dialog header
pack [label $win.header \
-compound left \
-image [image create photo \
-format png \
-file "${::ROOT_DIRNAME}/icons/other/Moravia_Microsystems.png" \
] \
-text " ${::APPNAME}" \
-font [font create \
-size -20 \
-family {helvetica}]
] -side top -pady 5
# Display short information about current translation
set translation_info "Translated into _Language_ by _Name_ (_country_) <_email_>"
if {[mc $translation_info] != $translation_info} {
pack [label $win.trans_info \
-text [mc $translation_info] \
-font [font create \
-size -12 \
-family {helvetica}]
] -side top -pady 2
}
# Create notebook
set nb [ModernNoteBook $win.nb]
# Create tab "About"
set about_tab [$nb insert end {About} -text [mc "About"]]
pack [text $about_tab.text \
-width 0 -height 0 -cursor left_ptr \
-yscrollcommand "$about_tab.scrollbar set" \
-font [font create \
-size [expr {int(-12 * $::font_size_factor)}] \
-family {helvetica}] \
] -fill both -expand 1 -side left
pack [ttk::scrollbar $about_tab.scrollbar \
-orient vertical \
-command "$about_tab.text yview" \
] -fill y -side right
# fill in the about tab
$about_tab.text insert end "${::APPNAME}\n"
$about_tab.text insert end [mc "An open source IDE for MCS-51 based microconrollers for POSIX Systems, this software is licenced under the GNU GPL v2 licence. You can find more at the project web page http://www.moravia-microsystems.com/mcu-8051-ide/\n"]
$about_tab.text insert end "\n(c) 2007, 2008, 2009, 2010, 2011, 2012 Martin Ošmera <mailto:martin.osmera@gmail.com>\n"
$about_tab.text insert end "\n(c) 2014 Moravia Micorsystems, s.r.o. <mailto:martin.osmera@gmail.com>\n"
if {$::MICROSOFT_WINDOWS} {
$about_tab.text insert end "\n"
$about_tab.text insert end [mc "You are currently using version for Microsoft® Windows®.\n"]
$about_tab.text insert end "(This version was made using the FreeWrap tool, by Dennis R. LaBelle <freewrapmgr@users.sourceforge.net>.)\n"
}
create_link_tag_in_text_widget $about_tab.text
convert_all_https_to_links $about_tab.text
# Finalize text widget creation
$about_tab.text configure -state disabled
# Create tab "Thanks to"
set thanks_tab [$nb insert end {Thanks} -text [mc "Thanks to"]]
pack [text $thanks_tab.text \
-width 0 -height 0 -cursor left_ptr \
-yscrollcommand "$thanks_tab.scrollbar set" \
] -fill both -expand 1 -side left
pack [ttk::scrollbar $thanks_tab.scrollbar \
-orient vertical \
-command "$thanks_tab.text yview" \
] -fill y -side right
$thanks_tab.text insert end [mc "Special thanks to Kara Blackowiak (USA) for submitting various help file fixes.\n\n"]
$thanks_tab.text insert end [mc "Thanks to Yuanhui Zhang for bug reports and help with debugging.\n"]
$thanks_tab.text insert end [mc "Thanks to Fabricio Alcalde for bug reports and suggestions.\n"]
$thanks_tab.text insert end [mc "Thanks to Marek Nožka for help with debugging.\n"]
$thanks_tab.text insert end [mc "Thanks to Miroslav Hradílek for bug reports.\n"]
$thanks_tab.text insert end [mc "Thanks to Trevor Spiteri for help with debugging (patches) the HD44780 simulator.\n"]
$thanks_tab.text insert end [mc "Thanks to Kostya V. Ivanov for significant bug fixes.\n"]
$thanks_tab.text insert end [mc "Thanks to Shakthi Kannan for including this IDE in FEL.\n\n"]
$thanks_tab.text insert end [mc "Thanks to all the SDCC developers.\n"]
$thanks_tab.text configure -state disabled
# Create tab "License"
set license_tab [$nb insert end {License} -text [mc "License"]]
pack [text $license_tab.text \
-width 0 -height 0 \
-yscrollcommand "$license_tab.scrollbar set" \
-font [font create \
-family $::DEFAULT_FIXED_FONT \
-size -12 \
] \
] -fill both -expand 1 -side left
pack [ttk::scrollbar $license_tab.scrollbar \
-orient vertical \
-command "$license_tab.text yview" \
] -fill y -side right
# Fill in the license tab
if {[file exists "${::ROOT_DIRNAME}/data/license.txt"]} {
$license_tab.text insert end [read [open "${::ROOT_DIRNAME}/data/license.txt" {r}]]
} else {
$license_tab.text insert end [mc "FILE \"license.txt\" WAS NOT FOUND\n\n"]
$license_tab.text insert end [mc "Text of the license agreement is not available,\n"]
$license_tab.text insert end [mc "please check your installation."]
}
$license_tab.text configure -state disabled
# Pack NoteBook
pack [$nb get_nb] -fill both -expand 1 -side top -padx 10
$nb raise {About}
# Create button "Close"
pack [ttk::button $win.close \
-text [mc "Close"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::about_CLOSE} \
] -side bottom -pady 5
# Events binding (Enter, Escape == Close)
bind $win <KeyRelease-Return> {X::about_CLOSE; break}
bind $win <KeyRelease-KP_Enter> {X::about_CLOSE; break}
bind $win <KeyRelease-Escape> {X::about_CLOSE; break}
# Focus on button "Close"
focus $win.close
# Window manager options -- modal window
wm iconphoto $win ::ICONS::16::mcu8051ide
wm title $win [mc "About - MCU 8051 IDE"]
wm minsize $win 620 320
wm protocol $win WM_DELETE_WINDOW {
X::about_CLOSE
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Close dialog "About" -- auxiliary procedure for '__about'
# @return void
proc about_CLOSE {} {
grab release .about
destroy .about
}
## Auto indent source code in the current editor
# @return void
proc __reformat_code {} {
variable actualProject ;# Object: Current project
variable editor_lines ;# Number of lines in the current editor
variable compilation_progress ;# Variable for compilation progressbar
variable reformat_code_abort ;# Bool: Abort function 'reformat_code'
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# C language
if {[$actualProject editor_procedure {} get_language {}] == 1} {
if {$::MICROSOFT_WINDOWS} { ;# Not implemented yet on Microsoft Windows
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Sorry, unable to comply"] \
-message [mc "Unable to indent C source without program indent, MCU 8051 IDE is unable to localize this program on Microsoft Windows operating system. So this feature is not available in version for MS Windows. Correction of this limitation is planed but right now it's not available."]
set critical_procedure_in_progress 0
return
}
# Check for program "indent"
if {!${::PROGRAM_AVAILABLE(indent)}} {
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unable to comply"] \
-message [mc "Unable to indent C source without program indent, please install indent and restart MCU 8051 IDE."]
set critical_procedure_in_progress 0
return
}
# Save file
if {![$actualProject editor_procedure {} save {}]} {
set critical_procedure_in_progress 0
return
}
# Perform indention and refresh editor
set filename [$actualProject editor_procedure {} getFileName {}]
set filename [file join [lindex $filename 0] [lindex $filename 1]]
if {[catch {exec -- indent -kr -npro $filename} result]} {
puts stderr $result
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unable to comply"] \
-message [mc "Unable to indent C source code.\n\n%s" $result]
} else {
$actualProject filelist_reload_file
}
# Assembly language
} else {
# Prepare
set reformat_code_abort 0 ;# Reset auto indention abort flag
set editor_lines [$actualProject editor_linescount] ;# Number of lines in the editor
set compilation_progress 0 ;# Reset compilation progress variable
set editor [$actualProject editor_procedure {} cget -editor] ;# Editor widget
set lastLine [$actualProject editor_actLineNumber] ;# Current line
set new_content {} ;# Initialize new content string
set max [expr {$editor_lines / 10}]
if {!$max} {
set max 1
}
# Create progress dialog
create_progress_bar .prgDl \
. \
{} \
[::mc "Reformatting code"] \
::X::compilation_progress \
$max \
[mc "Reformatting code"] \
::ICONS::16::filter \
[mc "Abort"] \
{::X::reformat_code_stop}
$editor configure -autoseparators 0
# Perform auto indention
set new_content [reformat_code_core [$editor get 1.0 end]]
$editor delete 1.0 end
# Insert new content in the editor
$editor insert end [string replace $new_content {end-1} end]
$actualProject editor_procedure {} parseAll {}
$actualProject editor_procedure {} goto $lastLine
$editor edit separator
$editor configure -autoseparators 1
# Finalize
catch {
destroy .prgDl ;# Destroy progress dialog
}
}
set critical_procedure_in_progress 0
}
## Abort auto indention -- auxiliary procedure for '__reformat_code'
# @return void
proc reformat_code_stop {} {
variable reformat_code_abort ;# Bool: Abort function 'reformat_code'
set reformat_code_abort 1
}
## Perform auto indention -- auxiliary procedure for '__reformat_code'
# @parm String data - data to parse
# @return String - result
proc reformat_code_core {data} {
variable compilation_progress ;# Variable for compilation progressbar
variable reformat_code_abort ;# Bool: Abort function 'reformat_code'
set idx 1 ;# Line number
set new_content {} ;# Resulting string
# Parse input data (line by line)
set data [split $data "\n"]
foreach line $data {
if {$reformat_code_abort} {break} ;# Conditional abort
incr idx ;# Increment line number
# Replace lines containg only white space with empty lines
if {[regexp {^\s*$} $line]} {
append new_content "\n"
if {![expr {$idx % 10}]} {
incr compilation_progress
}
continue
}
# Line fields
set field_0 {} ;# 1st field (labels, constants, etc.)
set field_1 {} ;# 2nd field (instructins, directives, macros, etc.)
set field_2 {} ;# 3rd field (operands, arguments, etc.)
set field_3 {} ;# 4th field (comments only)
# Determinate line with replaced strings and chars with underscores
set line_tmp $line
while {1} {
if {![regexp {'[^']+'} $line_tmp str]} {break}
set len [string length $str]
regsub {'[^']+'} $line_tmp [string repeat {_} $len] line_tmp
}
# Determinate comment field (field_3)
set commentBegin [string first {;} $line_tmp]
if {$commentBegin != -1} {
set field_3 [string range $line $commentBegin end]
regsub {\s*;.*$} $line_tmp {} line_tmp
set line [string range $line 0 [expr {$commentBegin - 1}]]
}
# Determinate fields 0 and 1
set pos 0
for {set j 0} {$j < 2} {incr j} {
if {![regexp {^\s*[^\s]+} $line_tmp str]} {break}
set len [string length $str]
set i [expr {$len - 1}]
set space [string repeat { } $len]
regsub {^\s*[^\s]+} $line_tmp $space line_tmp
set field_$j [regsub {^\s+} [string range $line $pos $i] {}]
set line [string replace $line $pos $i $space]
incr pos $len
}
# Remove leading white space from Field 2
set field_2 [regsub {^\s+} $line {}]
# Handle situation when there is no space between label and the 1st field
if {[regexp {[^\s:]+:[^\s:]+} $field_0]} {
set j [string first {:} $field_0]
append field_1 $field_2
set field_2 $field_1
set field_1 [string range $field_0 [expr {$j + 1}] end]
set field_0 [string range $field_0 0 $j]
}
# Field 1 >> Field 2; Field 0 -> Field 1; "" -> Field 0;
if {[string index $field_1 0] == {.}} {
set field_1_without_leading_dot [string range $field_1 1 end]
} else {
set field_1_without_leading_dot $field_1
}
if {
[regexp {^\.?\w+$} $field_0] &&
![regexp {^\d} $field_0] &&
[lsearch -exact -ascii ${::ASMsyntaxHighlight::directive_type2} \
[string toupper $field_1_without_leading_dot]] == -1
} then {
append field_1 $field_2
set field_2 $field_1
set field_1 {}
if {[string toupper $field_0] != {ENDM} && [string toupper $field_0] != {.ENDM}} {
set field_1 $field_0
set field_0 {}
}
}
# If line contains only comment then Field 3 -> Field 1
if {
$field_3 != {} &&
$field_0 == {} &&
$field_1 == {} &&
$field_2 == {} &&
$commentBegin != 0
} then {
set field_1 $field_3
set field_3 {}
}
# Adjust space between operans/arguments
set field_2_new {}
if {$field_2 != {}} {
# Strings/Chars to underscores
set field_2_tmp $field_2
while {1} {
if {![regexp {'[^']+'} $field_2_tmp str]} {break}
set len [string length $str]
regsub {'[^']+'} $field_2_tmp [string repeat {_} $len] field_2_tmp
}
# Recomposite Field 2
while {1} {
set i [string first {,} $field_2_tmp]
if {$i == -1} {
append field_2_new {, }
append field_2_new [string trim $field_2]
break
}
append field_2_new {, }
append field_2_new [string trim [string range $field_2 0 [expr {$i - 1}]]]
set field_2 [string range $field_2 [expr {$i + 1}] end]
set field_2_tmp [string range $field_2_tmp [expr {$i + 1}] end]
}
set field_2 [string trimleft $field_2_new {, }]
}
# Recomposite line
set line $field_0
if {$field_1 != {}} {
append line "\t"
append line $field_1
}
if {$field_2 != {}} {
append line "\t"
append line $field_2
}
if {$field_3 != {}} {
# Adjust field 3 (insure appropriate number of leading tabs)
if {$line != {}} {
set i -1
set spaces 0
set correction 0
set falseLength [string length $line]
while {1} {
set i [string first "\t" $line [expr {$i + 1}]]
if {$i == -1} {break}
set spaces [expr {8 - (($i + $correction) % 8)}]
set spaces_1 [expr {$spaces - 1}]
incr correction $spaces_1
incr falseLength $spaces_1
}
set spaces [expr {4 - ($falseLength / 8)}]
if {$spaces < 1} {
set spaces 1
}
append line [string repeat "\t" $spaces]
}
append line $field_3
}
# Append new line to the result
append new_content $line
append new_content "\n"
if {![expr {$idx % 10}]} {
incr compilation_progress
}
}
# Return result
return $new_content
}
## Invoke dialog "Clean up project folder"
# @return void
proc __cleanup {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$critical_procedure_in_progress} {return}
# Create dialog window
set win [toplevel .cleanup -class [mc "Options dialog"] -bg ${::COMMON_BG_COLOR}]
set bottom_frame [frame $win.buttonFrame]
set status_bar_lbl [label $bottom_frame.status_bar \
-justify left -anchor w \
]
# Create label frames
set backup_labelframe [ttk::labelframe $win.backup_labelframe \
-text [mc "Backup files"] \
]
set other_labelframe [ttk::labelframe $win.other_labelframe \
-text [mc "Other files"] \
]
set i 0 ;# Checkbutton index
# Fill in top labelframe
set row 0 ;# Row in the grid
set col 0 ;# Column in the grid
foreach text {
*.asm~ *.lst~ *.sim~ *.hex~ *.bin~ *.html~
*.tex~ *.wtc~ *.mcu8051ide~ *.m5ihib~ *.cdb~
*.ihx~ *.adf~ *.omf~ *.map~ *.c~ *.h~
*.vhc~ *.vhw~ *.txt~ *~
} ID {
asm lst sim hex bin html
tex wtc mcu8051ide m5ihib cdb
ihx adf omf map c h
vhc vhw txt all_bc
} helptext {
{Assembly language sources}
{Code listing files}
{Assembly debug files (before v1.0.5)}
{IHEX object code files}
{Binary object code files}
{HTML files}
{TeX sources}
{Register watches definition files}
{MCU 8051 IDE project}
{Hibernated programs}
{SDCC debug files}
{SDCC IHEX8 object files}
{MCU 8051 IDE Assembler debug files}
{OMF-51 object files}
{SDCC: The memory map for the load module}
{C sources}
{C headers}
{Virtual Hardware Component}
{Virtual Hardware}
{Text files}
{All backup files}
} \
{
set helptext [mc $helptext]
set button [checkbutton $backup_labelframe.$ID \
-text $text -anchor w \
-command "::X::cleanup_option $i" \
-variable __cleanup_$ID \
]
grid $button -row $row -column $col -sticky w -padx 5
if {[lindex $::CONFIG(CLEANUP_OPTIONS) $i] != {0}} {
$button select
} else {
$button deselect
}
bind $button <Enter> "$status_bar_lbl configure -text {$helptext}"
bind $button <Leave> "$status_bar_lbl configure -text {}"
incr i
incr col
if {$col == 4} {
set col 0
incr row
}
}
# Fill in bottom labelframe
set row 0 ;# Row in the grid
set col 0 ;# Column in the grid
foreach text {
*.lst *.sim *.hex *.bin *.html *.tex *.m5ihib
*.noi *.obj *.map *.p *.mac *.i *.ihx
*.adf *.adb *.rel *.cdb *.mem *.lnk *.sym
*.omf *.rst *.hashes *.bak
} ID {
lst sim hex bin html tex m5ihib
noi obj map p mac i ihx
adf adb rel cdb mem lnk sym
omf rst hashes bak
} helptext {
{Code listing files}
{Assembly debug files (before v1.0.5)}
{IHEX object code files}
{Binary object code files}
{HTML files}
{TeX sources}
{Hibernated programs}
{ASL: NoICE-compatible command file}
{ASL: Atmel debug file used by the AVR tools}
{SDCC: The memory map for the load module}
{ASL object files}
{Macro definition file}
{Macro output files}
{SDCC IHEX8 object files}
{MCU 8051 IDE Assembler debug files}
{SDCC Assembler debug files}
{SDCC: Object file created by the assembler}
{SDCC debug files}
{SDCC: A file with a summary of the memory usage}
{SDCC: Linker script}
{SDCC: Symbol listing for the source file}
{OMF-51 object files}
{SDCC: Listing file updated with linkedit information}
{MD5 hashes for C source files}
{Doxygen backup file}
} \
{
set helptext [mc $helptext]
set button [checkbutton $other_labelframe.$ID \
-text $text -anchor w \
-command "::X::cleanup_option $i" \
-variable __cleanup__$ID \
]
grid $button -row $row -column $col -sticky w -padx 5
if {[lindex $::CONFIG(CLEANUP_OPTIONS) $i] != {0}} {
$button select
} else {
$button deselect
}
bind $button <Enter> "$status_bar_lbl configure -text {$helptext}"
bind $button <Leave> "$status_bar_lbl configure -text {}"
incr i
incr col
if {$col == 4} {
set col 0
incr row
}
}
# Set column sizes
grid columnconfigure $backup_labelframe 0 -minsize 130
grid columnconfigure $backup_labelframe 1 -minsize 130
grid columnconfigure $backup_labelframe 2 -minsize 130
grid columnconfigure $backup_labelframe 3 -minsize 130
grid columnconfigure $other_labelframe 0 -minsize 130
grid columnconfigure $other_labelframe 1 -minsize 130
grid columnconfigure $other_labelframe 2 -minsize 130
grid columnconfigure $other_labelframe 3 -minsize 130
# Pack label frames
pack $backup_labelframe -fill both -expand 1 -padx 10 -pady 5
pack $other_labelframe -fill both -expand 1 -padx 10 -pady 5
# Create 'OK' and 'CANCEL' buttons
pack $status_bar_lbl -side left -fill x -expand 1
pack [ttk::button $win.buttonFrame.ok \
-text [mc "Remove files"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::cleanup_OK} \
] -side left -padx 2
pack [ttk::button $win.buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::cleanup_CANCEL} \
] -side left -padx 2
pack $bottom_frame -pady 5 -fill x -padx 5
# Events binding (Enter == Ok; Esc == Cancel)
bind $win <KeyRelease-Return> {X::cleanup_OK; break}
bind $win <KeyRelease-KP_Enter> {X::cleanup_OK; break}
bind $win <KeyRelease-Escape> {X::cleanup_CANCEL; break}
# Set window attributes -- modal window
wm iconphoto .cleanup ::ICONS::16::emptytrash
wm title .cleanup [mc "Cleanup project folder - MCU 8051 IDE"]
wm minsize .cleanup 360 310
wm resizable .cleanup 0 0
wm protocol .cleanup WM_DELETE_WINDOW {
X::cleanup_CANCEL
}
wm transient .cleanup .
grab .cleanup
raise .cleanup
tkwait window .cleanup
}
## Change cleanup option -- auxiliary procedure for '__cleanup'
# @parm Int idx - checkbutton index
# @return void
proc cleanup_option {idx} {
lset ::CONFIG(CLEANUP_OPTIONS) $idx \
[expr {[lindex $::CONFIG(CLEANUP_OPTIONS) $idx] == {0}}]
}
## Start cleanup -- auxiliary procedure for '__cleanup'
# @return void
proc cleanup_OK {} {
variable cleanup_masks ;# GLOB patterns
variable cleanup_files ;# List: Files marked for potential removal
variable actualProject ;# Object: Current project
# Determinate list of GLOB expressions of selected for removal
set dir [$actualProject cget -projectPath]
set cleanup_files [list]
foreach mask $cleanup_masks bool $::CONFIG(CLEANUP_OPTIONS) {
if {$bool} {
lappend cleanup_files $mask
}
}
# Determinate list of files selected for removal
set files_n [list]
catch { ;# For Microsoft Windows it has to be enclosed by catch
foreach f $cleanup_files {
append files_n { } [glob -directory $dir -nocomplain -type f $f]
}
}
set cleanup_files [lsort -unique $files_n]
# Finalize
cleanup_ask
}
## Proceed with the project folder clean up
# @return void
proc cleanup_PROCEED {} {
variable cleanup_files ;# List: Files marked for potential removal
# Invoke confirmation dialog
if {
[tk_messageBox \
-parent .cleanup_ask \
-icon question \
-type yesno \
-title [mc "Cleanup project folder"] \
-message [mc "Are you sure ?"] \
] != {yes}
} then {
return
}
# Remove the specified files
set count 0
foreach file $cleanup_files {
if {[catch {
file delete -force -- $file
}]} then {
puts stderr "Unable to delete file: $file"
} else {
incr count
}
}
tk_messageBox \
-parent .cleanup_ask \
-icon info \
-type ok \
-title [mc "Cleanup project folder"] \
-message [mc "%d file(s) removed." $count]
cleanup_CANCEL ;# Close dialog window
}
## Close dialog "Clean up project folder" -- auxiliary procedure for 'cleanup_OK'
# @return void
proc cleanup_CANCEL {} {
variable cleanup_files ;# List: Files marked for potential removal
set cleanup_files [list]
destroy .cleanup
}
## Show results of files removal -- auxiliary procedure for 'cleanup_OK'
# @return void
proc cleanup_ask {} {
variable cleanup_files ;# List: Files marked for potential removal
# Create dialog window
set win [toplevel .cleanup_ask -class {Confirmation dialog} -bg ${::COMMON_BG_COLOR}]
# Create window header
pack [label $win.header_label \
-text [mc "These files will be removed"] \
-font [font create \
-size [expr {int(-20 * $::font_size_factor)}] \
-family {helvetica}]
] -anchor center -side top -fill x
# Create top frame (text widget and scrollbar)
set frame [frame $win.top_frame]
# Create text widget and its scrollbar
set scrollbar [ttk::scrollbar $frame.scrollbar \
-command "$frame.text yview" \
-orient vertical \
]
set text [text $frame.text \
-yscrollcommand "$frame.scrollbar set" \
-width 1 -height 1 \
-cursor left_ptr \
]
# Fill in the text widget
foreach txt $cleanup_files {
# On MS Windows change '/' to '\' in file path
if {$::MICROSOFT_WINDOWS} {
regsub -all {/} $txt "\\" txt
}
$text insert end $txt
$text insert end "\n"
}
$text configure -state disabled
# Pack scrollbar and the text widget
pack $scrollbar -side right -fill y
pack $text -side left -fill both -expand 1
pack $frame -side top -fill both -expand 1 -pady 5 -padx 5
# Pack the top frame and create button "Ok"
set but_frame [frame $win.but_frame]
pack [ttk::button $but_frame.ok_button \
-text [mc "Proceed"] \
-compound left \
-image ::ICONS::16::ok \
-command "
::X::cleanup_PROCEED
destroy $win
" \
] -side left -padx 5
pack [ttk::button $but_frame.cancel_button \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command [list destroy $win] \
] -side left -padx 5
focus -force $but_frame.ok_button
pack $but_frame -side bottom -anchor e -pady 5 -pady 5
# Set window attributes -- modal window
wm iconphoto $win ::ICONS::16::emptytrash
wm title $win [mc "Cleanup project folder - MCU 8051 IDE"]
wm minsize $win 520 300
wm protocol $win WM_DELETE_WINDOW "grab release $win; destroy $win"
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Execute custom command
# @parm Int cmd_num - command number
# @return void
proc __exec_custom_cmd {cmd_num} {
variable custom_command_cmd ;# Array of custom commands (shell scripts)
variable custom_command_options ;# Array of Lists of custom command options
variable custom_command_PID ;# Array of custom command TIDs (Thread IDentifiers)
variable custom_command_NUM ;# Array of custom command numbers
variable custom_command_counter ;# Counter of custom command invocations
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if the command is not already running
if {$custom_command_PID($cmd_num) != {}} {
if {[tk_messageBox \
-parent . \
-icon warning \
-type yesno \
-title [mc "Confirm termination - MCU 8051 IDE"] \
-message [mc "This process is already in progress. Do you want to terminate it ?"]
] == {yes}} {
if {!$::MICROSOFT_WINDOWS} { ;# There is no kill command on Microsoft Windows
if {$custom_command_PID($cmd_num) != {}} {
foreach pid $custom_command_PID($cmd_num) {
if {$pid == [pid] || $pid == 0} {
continue
}
catch {
exec -- /bin/sh -c "kill -s 9 \$(ps -o pid --no-headers --ppid $pid)"
}
}
}
}
custom_cmd_icon_reset $custom_command_NUM($cmd_num)
}
set critical_procedure_in_progress 0
return
}
# Invoke confiramation dialog (if requested)
if {[lindex $custom_command_options($cmd_num) 0]} {
if {
[tk_messageBox \
-parent . \
-icon question \
-type yesno \
-title [mc "Confirmation required"] \
-message [mc "Do you really want to execute\ncustom command %s ?" $cmd_num] \
] != {yes}
} then {
set critical_procedure_in_progress 0
return
}
}
# Adjust button icon on main toolbar
if {[winfo exists .mainIconBar.custom$cmd_num]} {
.mainIconBar.custom$cmd_num configure \
-image ::ICONS::22::gear${cmd_num}_play
}
# Perform variables substitution in the command string
set cmd $custom_command_cmd($cmd_num)
regsub -all {%%} $cmd "\a" cmd
if {[regexp {%} $cmd]} {
# Determinate editor object reference
set editor [$actualProject get_current_editor_object]
regsub -all {%URL} $cmd {%URI} cmd
if {[regexp {%URIS} $cmd]} {
set URIS {}
foreach e [$actualProject cget -editors] {
set url [$e cget -fullFileName]
if {[regexp {\s} $url]} {
append URIS "\"" $url "\"" { }
} else {
append URIS $url { }
}
}
regsub -all {%URIS} $cmd [string replace $URIS end end] cmd
}
if {[regexp {%URI} $cmd]} {
regsub -all {%URI} $cmd [$editor cget -fullFileName] cmd
}
if {[regexp {%directory} $cmd]} {
regsub -all {%directory} $cmd [$actualProject cget -projectPath] cmd
}
if {[regexp {%filename} $cmd]} {
regsub -all {%filename} $cmd [$editor cget -filename] cmd
}
if {[regexp {%basename} $cmd]} {
regsub -all {%basename} $cmd [file tail [file rootname [$editor cget -filename]]] cmd
}
if {[regexp {%mainfile} $cmd]} {
regsub -all {%mainfile} $cmd [$actualProject cget -P_option_main_file] cmd
}
if {!${::Editor::editor_to_use}} {
if {[regexp {%line} $cmd]} {
regsub -all {%line} $cmd [$editor get_current_line_number] cmd
}
if {[regexp {%column} $cmd]} {
regexp {\d+$} [[$editor cget -editor] index insert] col
regsub -all {%column} $cmd $col cmd
}
if {[regexp {%selection} $cmd]} {
regsub -all {%selection} $cmd [$editor getselection] cmd
}
if {[regexp {%text} $cmd]} {
regsub -all {%text} $cmd [$editor getdata] cmd
}
} else {
if {[regsub -all {%(line|column|selection|text)} $cmd {} cmd]} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Warning - Custom command"] \
-message [mc "Some variables in user command could not be resolved."]
}
}
}
regsub -all "\a" $cmd {%} cmd
## Execute the specified command
set custom_command_NUM($cmd_num) $custom_command_counter
# Run in terminal
if {[lindex $custom_command_options($cmd_num) 3] && $::PROGRAM_AVAILABLE(urxvt)} {
exec_custom_cmd_in_terminal $cmd_num $cmd
custom_cmd_icon_reset $custom_command_NUM($cmd_num)
# Run normally
} else {
set custom_command_PID($cmd_num) [exec -- tclsh \
${::LIB_DIRNAME}/custom_command.tcl [tk appname] \
$custom_command_NUM($cmd_num) << $cmd & \
]
}
incr custom_command_counter
# Finalize
set critical_procedure_in_progress 0
}
## Invoke dialog "Custom command finished"
# -- auxiliary procedure for '__exec_custom_cmd'
# @parm Int num - Command number
# @parm String result - Result string
# @return void
proc custom_cmd_finish {num result} {
variable custom_command_options ;# Array of Lists of custom command options
# Set toolbar button icon to default and determinate command index
set i [custom_cmd_icon_reset $num]
if {$i == {}} {return}
# Check if result dialogues are allowed
if {![lindex $custom_command_options($i) 1]} {return}
# Invoke results dialog
invoke_custom_cmd_dialog $i {#00DD00} [mc "Custom command finished"] $result
}
## Invoke dialog "Custom command failed"
# -- auxiliary procedure for '__exec_custom_cmd'
# @parm Int num - Command number
# @parm String result - Result string
# @return void
proc custom_cmd_error {num result} {
variable custom_command_options ;# Array of Lists of custom command options
# Set toolbar button icon to default and determinate command index
set i [custom_cmd_icon_reset $num]
if {$i == {}} {return}
# Check if error dialogues are allowed
if {[lindex $custom_command_options($i) 2]} {return}
# Invoke error dialog
invoke_custom_cmd_dialog $i {#DD0000} [mc "Custom command failed"] $result
}
## Execute custom command in terminal emulator
# @parm Int cmd_num - Number of the custom command to execute
# @parm String cmd - Command string to execute
# @return void
proc exec_custom_cmd_in_terminal {cmd_num cmd} {
variable custom_cmd_dialog_index ;# Index of results dialog (to keep win IDs unique)
incr custom_cmd_dialog_index
# Create dialog window
set win [toplevel .custom_cmd_dialog${custom_cmd_dialog_index} -class {Custom command running} -bg ${::COMMON_BG_COLOR}]
# Create dialog header
pack [label $win.header_label \
-compound left \
-text [mc "Custom command %s - MCU 8051 IDE" $cmd_num] \
-image ::ICONS::22::gear${cmd_num}_play \
-font [font create \
-family {helvetica} \
-size [expr {int(-20 * $::font_size_factor)}] \
-weight bold \
] \
] -pady 5
# Create main frame (text widget and scrollbar)
set main_frame [frame $win.main_frame -container 1]
bind $main_frame <Destroy> [list destroy $win]
pack $main_frame -fill both -expand 1 -padx 5 -pady 5
# Set window attributes
wm iconphoto $win ::ICONS::16::gear
wm title $win [mc "Custom command %s - MCU 8051 IDE" $cmd_num]
wm minsize $win 550 300
wm protocol $win WM_DELETE_WINDOW {}
update
# Run terminal emulator
if {[catch {
set terminal_pid [exec -- urxvt \
-embed [expr [winfo id $main_frame]] \
-hold -sr -b 0 -w 0 -bg ${::Terminal::configuration(bg)}\
-fg ${::Terminal::configuration(fg)} \
-fn "xft:${::Terminal::configuration(font_family)}:pixelsize=${::Terminal::configuration(font_size)}" \
-e bash -i -c $cmd \
& \
]
} result]} then {
destroy $win
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unknow error"] \
-message [mc "Unable to execute your script in the urxvt terminal emulator."]
puts stderr $result
} else {
wm protocol $win WM_DELETE_WINDOW [list ::X::close_custom_cmd_term $terminal_pid $win]
}
}
## Close terminal emulator with a custom command
# @parm Int pid - Terminal PID
# @parm Widget dialog - Dialog window in which the terminal is mapped
# @return void
proc close_custom_cmd_term {pid dialog} {
# Get list of child processes of the terminal
set children [list]
catch {
set children [exec -- /bin/sh -c "ps -o pid --no-headers --ppid $pid"]
}
# Ask user, if he/she wishes to kill the children, if there are any
if {
[llength $children]
&&
[tk_messageBox \
-parent $dialog \
-icon question \
-type yesno \
-title [mc "Kill the script?"] \
-message [mc "Closing this window terminates all child processes of the terminal.\n\nDo you want to proceed?"] \
] != {yes}
} then {
return
}
# Kill the terminal
if {[catch {
exec -- kill $pid &
}]} then {
puts stderr "Something went wrong here..."
puts stderr $::errorInfo
}
}
## Invoke dialog window showing results of some custom command
# -- auxiliary procedure for 'custom_cmd_error' and 'custom_cmd_finish'
# @parm Int i - Index of the custom command (0..2)
# @parm RGB color - Color for dialog header (24-bit RGB color code)
# @parm String label - Text of the dialog header
# @parm String result - Text of the messages area
# @return void
proc invoke_custom_cmd_dialog {i color label result} {
variable custom_cmd_dialog_index ;# Index of results dialog (to keep win IDs unique)
incr custom_cmd_dialog_index
# Create dialog window
set win [toplevel .custom_cmd_dialog${custom_cmd_dialog_index} -class {Custom command finished} -bg ${::COMMON_BG_COLOR}]
# Create dialog header
pack [label $win.header_label \
-compound left \
-fg $color \
-text $label \
-image ::ICONS::22::gear$i \
-font [font create \
-family {helvetica} \
-size [expr {int(-20 * $::font_size_factor)}] \
-weight bold \
] \
] -pady 5
# Create main frame (text widget and scrollbar)
set main_frame [frame $win.main_frame]
set text [text $main_frame.text \
-width 1 -height 1 \
-yscrollcommand "$main_frame.scrollbar set" \
]
pack $text -side left -fill both -expand 1
pack [ttk::scrollbar $main_frame.scrollbar \
-command "$text yview" \
-orient vertical \
] -fill y -side right
pack $main_frame -fill both -expand 1 -pady 5
# Create button "Ok"
pack [ttk::button $win.ok_button \
-text [mc "Ok"] \
-command "destroy $win" \
-compound left \
-image ::ICONS::16::ok \
] -pady 5
# Fill in the text widget and disable it
$text insert end [string replace [regsub -all {\\\{} [regsub -all {\\\}} $result "\}"] "\{"] 0 0]
$text configure -state disabled
# Events binding (Enter/Escape == Ok)
bind $win <KeyRelease-Return> "destroy $win; break"
bind $win <KeyRelease-KP_Enter> "destroy $win; break"
bind $win <KeyRelease-Escape> "destroy $win; break"
# Set window attributes
wm iconphoto $win ::ICONS::16::gear
wm title $win [mc "Custom command %s - MCU 8051 IDE" $i]
wm minsize $win 550 300
wm protocol $win WM_DELETE_WINDOW "destroy $win"
wm transient $win .
}
## Set toolbar button icon to default and determinate index of custom command
# -- auxiliary procedure for 'custom_cmd_error' and 'custom_cmd_finish'
# @parm Int num - Command number
# @return Int - index of the specified custom command (by TID) or {} (means 'not found')
proc custom_cmd_icon_reset {num} {
variable custom_command_NUM ;# Array of custom command numbers
variable custom_command_PID ;# Array of custom command TIDs (Thread IDentifiers)
# Search for command index
set found 0 ;# Bool: Corresponding index found
for {set i 0} {$i < 3} {incr i} {
if {[string equal $custom_command_NUM($i) $num]} {
set found 1
break
}
}
# If index not found -> return {}
if {!$found} {return {}}
# Reset toolbar button icon
if {[winfo exists .mainIconBar.custom$i]} {
.mainIconBar.custom$i configure -image ::ICONS::22::gear${i}
}
# Reset command PID and return result
set custom_command_PID($i) {}
return $i
}
## Invoke welcome dialog
# @return void
proc __welcome_dialog {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
if {$critical_procedure_in_progress} {return}
if {[winfo exists .welcome]} {
return
}
# Create dialog window
set win [toplevel .welcome -class {Welcome dialog} -bg ${::COMMON_BG_COLOR}]
# Create header label
pack [label $win.header_label \
-compound left -fg {#0000DD} \
-text [mc "Welcome to MCU 8051 IDE !"] \
-font [font create \
-family {helvetica} \
-size [expr {int(-20 * $::font_size_factor)}] \
-weight {bold} \
-slant {italic} \
] \
] -pady 10
# Create frame for the text widget and its scrollbar
set text_frame [frame $win.text_frame]
# Create text widget showing the dialog message
set text [text $text_frame.text \
-bg ${::COMMON_BG_COLOR} -takefocus 0 \
-width 0 -heigh 0 -bd 0 \
-cursor left_ptr \
-wrap word \
-yscrollcommand [list $text_frame.scrollbar set] \
-font [font create \
-family {helvetica} \
-size [expr {int(-12 * $::font_size_factor)}] \
] \
]
# Create scrollbar for the text widget
set scrollbar [ttk::scrollbar $text_frame.scrollbar \
-command [list $text yview] \
-orient vertical \
]
# Pack scrollbar and the text widget
pack $text -side left -fill both -expand 1
pack $scrollbar -side right -fill y
pack $text_frame -fill both -expand 1 -padx 15
# Create button "Ok"
pack [ttk::button $win.ok_button \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command "grab release $win; destroy $win" \
] -pady 5
# Create label for opening demostration project
set open_demo_label [label $text.open_demo_label \
-text [mc "Click here to open demonstration project."] \
-justify left \
-fg {#0055FF} \
-cursor hand2 \
-font [font create \
-family {helvetica} \
-size [expr {int(-12 * $::font_size_factor)}] \
] \
-image ::ICONS::16::2_rightarrow \
-compound left \
-padx 5 \
]
bind $open_demo_label <Enter> {%W configure -fg {#00DD00}}
bind $open_demo_label <Leave> {%W configure -fg {#0055FF}}
bind $open_demo_label <Button-1> "
grab release $win
destroy $win
::X::open_demo_project
break
"
# Load images
set image_new ::ICONS::16::filenew
set image_start ::ICONS::16::launch
set image_step ::ICONS::16::goto
set image_list0 ::ICONS::16::dot_r
set image_list1 ::ICONS::16::dot_g
set image_list2 ::ICONS::16::dot
# Create text tags
$text tag configure bold -font [font create \
-family {helvetica} \
-size [expr {int(-12 * $::font_size_factor)}] \
-weight bold \
]
$text tag configure header -font [font create \
-family {helvetica} \
-size [expr {int(-12 * $::font_size_factor)}] \
-weight bold \
-underline 1 \
] -foreground {#0000DD}
# Fill in the text widget
$text insert end [mc "MCU 8051 IDE is a fully featured Integrated Development Environment"]
$text insert end [mc " for MCS-51 based microcontrollers. It's written for POSIX Operating Systems (GNU/Linux, etc.) "]
if {$::MICROSOFT_WINDOWS} {
$text insert end [mc "and since version 1.3.5 it is also available for Microsoft® Windows® operating system."]
}
$text insert end "\n\n"
$text insert end [mc "Main features:"]
$text tag add header {insert linestart} insert
$text insert end "\n\t"
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Editor with syntax highlight, validation and popup-based completion\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "MCS-51 Assembler and Disassembler\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "MCS-51 Simulator (not all MCUs are fully supported!)\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Support for C language (using C compiler SDCC)\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Partial support for some HW tools\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Project management\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Custom editable commands (using shell scripts)\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Dynamic help for instruction at the current line\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Hexadecimal editor for eXternal RAM, Expanded RAM, Code memory, etc.\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Scientific calculator\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Simple hardware simulation (LED's, etc.)\n\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Graph showing voltage levels on ports\n\n"]
$text insert end [mc "Where to start:"]
$text tag add header {insert linestart} insert
$text insert end [mc "\n\t1. Create a new project"]
$text image create end -image $image_new -padx 5
$text insert end "\n\t\t"
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Enter project name\n\t\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Choose project directory\n\t\t"]
$text image create end -image $image_list1 -padx 5
$text insert end [mc "Choose microcontroller (e.g. AT89S52)\n"]
$text insert end [mc "\t2. Write your code in the opened editor and click on "]
$text image create end -image $image_start -padx 5
$text insert end [mc " to start the simulator\n"]
$text insert end [mc "\t3. Step through your program by clicking on "]
$text image create end -image $image_step -padx 5
$text insert end "\n\t----\n\t"
$text window create end -window $open_demo_label
$text insert end ""
$text insert end "\n\n"
$text insert end [mc "Web site:"]
$text tag add bold {insert linestart} insert
$text insert end "\thttp://mcu8051ide.sourceforge.net\n"
$text insert end [mc "Authors:"]
$text tag add bold {insert linestart} insert
$text insert end "\tMartin Ošmera <martin.osmera@gmail.com>\n"
$text insert end [mc "Thank you for using/trying MCU 8051 IDE."]
$text tag add bold {insert linestart} insert
create_link_tag_in_text_widget $text
convert_all_https_to_links $text
$text configure -state disabled
# Set window attributes
wm iconphoto $win ::ICONS::16::info
wm title $win [mc "Welcome to MCU 8051 IDE"]
wm minsize $win 580 400
wm protocol $win WM_DELETE_WINDOW "grab release $win; destroy $win"
wm transient $win .
catch {grab $win}
raise $win
}
## Open demostration project -- auxiliary procedure for '__welcome_dialog'
# @return void
proc open_demo_project {} {
variable openedProjects ;# List of opened projects (Object references)
if {[Project::open_project_file "${::INSTALLATION_DIR}/demo/Demo project.mcu8051ide"]} {
# The demostration project is for reading only, it cannot be saved
[lindex $openedProjects end] set_read_only
}
}
## Invoke dialog "Change letter case"
# @return void
proc __change_letter_case {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable change_letter_case_options ;# Options (which fields should be adjusted)
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 1]} {return}
if {$critical_procedure_in_progress} {return}
# Create dialog window
set win [toplevel .change_letter_case -class [mc "Options dialog"] -bg ${::COMMON_BG_COLOR}]
# Create dialog header
pack [label $win.header \
-compound left \
-image ::ICONS::22::change_case \
-text [mc "Change letter case"] \
-font [font create \
-size [expr {int(-20 * $::font_size_factor)}] \
-family {times}]
] -side top -pady 5
# Create main frame (contains labels and radio buttons)
set main_frame [frame $win.main_frame]
# Create header
foreach column {1 2 3 5 6 7 } \
image {up0 down0 button_cancel up0 down0 button_cancel } \
helptext {
{Uppercase} {Lowercase} {Keep case}
{Uppercase} {Lowercase} {Keep case}
} \
{
grid [Label $main_frame.header_label$column \
-pady 0 -bd 0 -helptext [mc $helptext] \
-image ::ICONS::16::$image \
] -row 0 -column $column -sticky w
}
# Create matrix of radiobuttons and labels
set i 0
set row 1
set col 0
foreach text {
{Hexadecimal number} {Octal number}
{Decimal number} {Binary number}
{Constant} {Generic number}
{Comment} {Control sequence}
{Symbol} {Directive}
{Label} {Instruction}
{SFR register} {Indirect address}
{Immediate hex} {Immediate oct}
{Immediate dec} {Immediate bin}
{Immediate const} {Immediate generic}
{Macro instruction}
} \
{
# Create label
grid [label $main_frame.label$i \
-text [mc $text] -justify left \
-highlightthickness 0 \
-pady 0 -bd 0 \
] -row $row -column [expr {$col * 4}] -sticky w
# Radiobutton "Uppercase"
grid [radiobutton $main_frame.upper$i \
-value {U} -highlightthickness 0 -pady 0 \
-variable ::X::change_letter_case_options($i) \
] -row $row -column [expr {$col * 4 + 1}] -sticky w
# Radiobutton "Lowercase"
grid [radiobutton $main_frame.lower$i \
-value {L} -highlightthickness 0 -pady 0 \
-variable ::X::change_letter_case_options($i) \
] -row $row -column [expr {$col * 4 + 2}] -sticky w
# Radiobutton "Keep"
grid [radiobutton $main_frame.keep$i \
-value {-} -highlightthickness 0 -pady 0 \
-variable ::X::change_letter_case_options($i) \
] -row $row -column [expr {$col * 4 + 3}] -sticky w
incr col
incr i
if {$col > 1} {
set col 0
incr row
}
}
# Set column sizes
grid columnconfigure $main_frame 0 -minsize 140
grid columnconfigure $main_frame 3 -minsize 50
grid columnconfigure $main_frame 4 -minsize 140
# Create button frame
set button_frame [frame $win.button_frame]
# Create buttons "All up", "All down" and "All keep"
foreach image {up0 down0 button_cancel} \
state {U L -} \
{
pack [ttk::button $button_frame.${image}_but \
-compound right \
-text [mc "All "] \
-image ::ICONS::16::$image \
-command "::X::change_letter_case_all_to $state" \
] -side left -padx 2
}
# Create and pack buttons "OK" and "CANCEL"
pack [ttk::button $button_frame.ok_button \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::change_letter_case_OK} \
] -side right -padx 2
pack [ttk::button $button_frame.cancel_button \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::change_letter_case_CANCEL} \
] -side right -padx 2
# Events binding (Enter == Ok; Escape == Cancel)
bind $win <KeyRelease-Return> {::X::change_letter_case_OK; break}
bind $win <KeyRelease-KP_Enter> {::X::change_letter_case_OK; break}
bind $win <KeyRelease-Escape> {::X::change_letter_case_CANCEL; break}
# Pack frames
pack $main_frame -fill both -expand 1 -padx 10 -pady 10
pack $button_frame -side bottom -fill x -padx 5 -pady 5
# Set window attributes
wm iconphoto $win ::ICONS::16::change_case
wm title $win [mc "Change letter case - MCU 8051 IDE"]
wm minsize $win 450 70
wm protocol $win WM_DELETE_WINDOW {
::X::change_letter_case_CANCEL
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
## Perform letter case change -- auxiliary procedure for '__change_letter_case'
# @return void
proc change_letter_case_OK {} {
change_letter_case_CANCEL ;# Close dialog window
change_letter_case_start ;# Perform change
}
## Close "Change letter case" dialog window
# -- auxiliary procedure for '__change_letter_case'
# @return void
proc change_letter_case_CANCEL {} {
grab release .change_letter_case
destroy .change_letter_case
}
## Set all options to the specified state
# -- auxiliary procedure for '__change_letter_case'
# @parm Char state - new state
# 'U' == Uppercase
# 'L' == Lowercase
# '-' == Keep
# @return void
proc change_letter_case_all_to {state} {
variable change_letter_case_options ;# Options (which fields should be adjusted)
for {set i 0} {$i < 21} {incr i} {
set change_letter_case_options($i) $state
}
}
## Perform letter case change -- auxiliary procedure for 'change_letter_case_OK'
# @return void
proc change_letter_case_start {} {
variable actualProject ;# Object: Current project
variable compilation_progress ;# Variable for compilation progressbar
variable change_letter_case_options ;# Options (which fields should be adjusted)
# Check if the current editor is not empty
if {
[$actualProject editor_procedure {} getLinesCount {}] == 1
&&
[$actualProject editor_procedure {} getLineContent 1] == {}
} then {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "Unable to comply"] \
-message [mc "This editor seems to be empty"]
return
}
set compilation_progress 1 ;# Reset compilation progress variable
# Set maximum for 1st progress bar ("Finishing highlight")
set max [$actualProject editor_procedure {} highlight_all_count_of_iterations {}]
incr max
# Create progress dialog window
set win [toplevel .change_letter_case_dialog -class {Progress dialog} -bg ${::COMMON_BG_COLOR}]
# Create label and progress bar
set main_frame [frame $win.main_frame]
pack [label $main_frame.header -text [mc "Finishing highlight ..."]] \
-pady 10 -padx 20 -anchor w
pack [ttk::progressbar $main_frame.progress_bar \
-maximum $max \
-mode determinate \
-variable {X::compilation_progress} \
-length 430 \
] -fill y
pack $main_frame -fill x -expand 1
pack [ttk::button $win.abort_button \
-text [mc "Abort"] \
-image ::ICONS::16::cancel \
-compound left \
-command {X::change_letter_case_abort} \
]
# Create options list
for {set i 0} {$i < 21} {incr i} {
lappend options $change_letter_case_options($i)
}
# Set window attributes
wm iconphoto $win ::ICONS::16::change_case
wm title $win [mc "Change letter case - MCU 8051 IDE"]
wm minsize $win 450 70
wm protocol $win WM_DELETE_WINDOW {
exportToX_abort
}
wm transient $win .
catch {grab $win}
raise $win
update
# Finish highlight
$actualProject editor_procedure {} highlight_all {}
if {![winfo exists $win]} {return}
# Determinate maximum value for the 2nd progress bar ("Formatting")
set max [$actualProject editor_procedure {} change_letter_case_get_count_of_iterations "{$options}"]
incr max
# Change progress bar header label
$main_frame.header configure -text [mc "Formatting ..."]
$main_frame.progress_bar configure -maximum $max
set compilation_progress 1 ;# Reset compilation progress variable
update
# Finaly perform letter case change
$actualProject editor_procedure {} change_letter_case [list $options]
# Close the window
catch {
grab release .change_letter_case_dialog
destroy .change_letter_case_dialog
}
}
## Abort letter case change-- auxiliary procedure for 'change_letter_case_start'
# @return void
proc change_letter_case_abort {} {
variable actualProject ;# Object: Current project
# Abort the procedure in editor
$actualProject editor_procedure {} change_letter_case_abort_now {}
# Close progress dialog
grab release .change_letter_case_dialog
destroy .change_letter_case_dialog
}
## Switch to the previous editor in the current project
# @return void
proc __prev_editor {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Switch editor
$actualProject prev_editor
# Finalize
set critical_procedure_in_progress 0
}
## Switch to the next editor in the current project
# @return void
proc __next_editor {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Switch editor
$actualProject next_editor
# Finalize
set critical_procedure_in_progress 0
}
## Change EOL character in the current editor
# @return void
proc change_EOL {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} {return}
if {$critical_procedure_in_progress} {return}
# Change EOL
$actualProject change_EOL
}
## Change character encoding in the current editor
# @return void
proc change_encoding {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[simulator_must_be_disabled 0]} {return}
if {$critical_procedure_in_progress} {return}
# Change encoding
$actualProject change_encoding
}
## Switch between RO and RW modes in the current editor
# @return void
proc switch_editor_RO_MODE {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {![$actualProject switch_editor_RO_MODE]} {
# Switch the flag back if the operation was unsuccessful
set ::editor_RO_MODE [expr {!$::editor_RO_MODE}]
}
}
## Prepare window "Project details"
# @parm Object project - project object descriptor
# @return void
proc create_project_details {project} {
variable openedProjects ;# List of opened projects (Object references)
variable PROJECTDETAILSWIN ;# ID of project details window
variable projectdetails_last_project ;# Project object of the last project details window
# Check if the given project is a valid object reference
if {[lsearch -ascii -exact $openedProjects $project] == -1} {
return
}
if {$projectdetails_last_project == $project} {
project_details_move
return
} else {
set projectdetails_last_project $project
}
# Destroy previous window
catch {destroy $PROJECTDETAILSWIN}
set authors [$project cget -G_information_authors]
set authors [join [split $authors "\n"] {, }]
if {[string length $authors] > 40} {
set authors [string range $authors 0 36]
append authors {...}
}
# Create window
set PROJECTDETAILSWIN [frame .project_details_win -bg {#BBBBFF}]
set project_details_win [frame $PROJECTDETAILSWIN.frm -bg {#FFFFFF}]
# Create header
pack [label $project_details_win.header \
-text [$project cget -projectName] \
-justify left -pady 0 -padx 15 \
-compound left -anchor w -bg {#BBBBFF} \
-image ::ICONS::16::kcmdevices \
] -fill x
# Create main frame (containing everything except the header)
set main_frame [frame $project_details_win.main_frame -bg {#FFFFFF}]
# File name
grid [label $main_frame.filename_label \
-text [mc "File name:"] \
-fg {#880033} -bg {#FFFFFF} \
-anchor w -pady 0 \
] -row 0 -column 0 -sticky w -pady 0
grid [label $main_frame.filename_value \
-text [$project cget -projectFile] \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 0 -column 1 -sticky w -pady 0
# Path
grid [label $main_frame.path_label \
-text [mc "Path:"] -fg {#880033}\
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 1 -column 0 -sticky w -pady 0
set path [$project cget -projectPath]
if {$::MICROSOFT_WINDOWS} {
regsub -all {/} $path "\\" path
}
grid [label $main_frame.path_value \
-text $path \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 1 -column 1 -sticky w -pady 0
# Separator
grid [ttk::separator $main_frame.sep0 -orient horizontal \
] -row 2 -column 0 -columnspan 2 -sticky we -pady 5
# MCU:
grid [label $main_frame.family_label \
-text [mc "MCU:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 3 -column 0 -sticky w -pady 0
grid [label $main_frame.family_value \
-text [$project cget -P_option_mcu_type]\
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 3 -column 1 -sticky w -pady 0
# XDATA:
grid [label $main_frame.xdata_label \
-text [mc "XDATA:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 4 -column 0 -sticky w -pady 0
grid [label $main_frame.xdata_value \
-text "[$project cget -P_option_mcu_xdata] B" \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 4 -column 1 -sticky w -pady 0
# XCODE:
grid [label $main_frame.xcode_label \
-text [mc "XCODE:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 5 -column 0 -sticky w -pady 0
grid [label $main_frame.xcode_value \
-text "[$project cget -P_option_mcu_xcode] B" \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 5 -column 1 -sticky w -pady 0
# Clock:
grid [label $main_frame.clock_label \
-text [mc "Clock:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 6 -column 0 -sticky w -pady 0
grid [label $main_frame.clock_value \
-text "[$project cget -P_option_clock] kHz" \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 6 -column 1 -sticky w -pady 0
set more_details_available 0
# Version
if {[string length [$project cget -P_information_version]]} {
set more_details_available 1
grid [label $main_frame.ver_label \
-text [mc "Version:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 8 -column 0 -sticky w -pady 0
grid [label $main_frame.ver_value \
-text [$project cget -P_information_version] \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 8 -column 1 -sticky w -pady 0
}
# Date
if {[string length [$project cget -P_information_date]]} {
set more_details_available 1
grid [label $main_frame.date_label \
-text [mc "Date:"] -fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 9 -column 0 -sticky w -pady 0
grid [label $main_frame.date_value \
-anchor w -pady 0 -bg {#FFFFFF} \
-text [$project cget -P_information_date] \
] -row 9 -column 1 -sticky w -pady 0
}
# License
if {[string length [$project cget -G_information_license]]} {
set more_details_available 1
grid [label $main_frame.license_label \
-text [mc "License:"] \
-fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 10 -column 0 -sticky w -pady 0
grid [label $main_frame.license_value \
-text [$project cget -G_information_license] \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 10 -column 1 -sticky w -pady 0
}
# Copyright
if {[string length [$project cget -G_information_copyright]]} {
set more_details_available 1
grid [label $main_frame.copyright_label \
-text [mc "Copyright:"] \
-fg {#0000AA} -bg {#FFFFFF} \
-anchor w -pady 0 \
] -row 11 -column 0 -sticky w -pady 0
grid [label $main_frame.copyright_value \
-anchor w -pady 0 -bg {#FFFFFF} \
-text [$project cget -G_information_copyright] \
] -row 11 -column 1 -sticky w -pady 0
}
# Authors
if {[string length $authors]} {
set more_details_available 1
grid [label $main_frame.authors_label \
-text [mc "Authors:"] \
-fg {#0000AA} \
-anchor w -pady 0 -bg {#FFFFFF} \
] -row 12 -column 0 -sticky w -pady 0
grid [label $main_frame.authors_value \
-text $authors -anchor w \
-pady 0 -bg {#FFFFFF} \
] -row 12 -column 1 -sticky w -pady 0
}
# Separator
if {$more_details_available} {
grid [ttk::separator $main_frame.sep1 -orient horizontal \
] -row 7 -column 0 -columnspan 2 -sticky we -pady 5
}
# Pack main frame
grid columnconfigure $main_frame 0 -minsize 80
pack $main_frame -fill both -expand 1 -padx 8 -pady 3
pack $project_details_win -fill both -expand 1 -padx 2 -pady 2
# Configure the window in a way that it will close when the user clicks on it
foreach w [concat $project_details_win [pack slaves $project_details_win] [grid slaves $main_frame]] {
bind $w <Button-1> {::X::close_project_details}
}
# Show window "Project details"
project_details_move
}
## Move window "Project details"
# @return void
proc project_details_move args {
variable PROJECTDETAILSWIN ;# ID of project details window
# Show the window
catch {
place $PROJECTDETAILSWIN -anchor nw \
-x [expr {[winfo pointerx .] - [winfo rootx .] + 20}] \
-y [expr {[winfo pointery .] - [winfo rooty .] + 20}]
update
raise $PROJECTDETAILSWIN
}
}
## Hide window "Project details"
# @return void
proc close_project_details args {
variable PROJECTDETAILSWIN ;# ID of project details window
# Hide the window
catch {place forget $PROJECTDETAILSWIN}
}
## Invokes menu for manipulating project tab
# @parm Int x - Absolute X coordinate of mouse pointer
# @parm Int y - Absolute Y coordinate of mouse pointer
# Object project - project object descriptor
proc invoke_project_menu {x y project} {
variable projectmenu ;# ID of Popup menu for project tabs
variable projectmenu_project ;# Object: project selected by project popup menu
variable openedProjects ;# List of opened projects (Object references)
# Check if the given project exists (due to a bug in BWidget-1.7)
if {[lsearch -ascii -exact $openedProjects $project] == -1} {
puts stderr "Internal error detected: Please install BWidget-1.8 or higher"
return
}
# Enable/Disable menu entries
set tabindex [${::main_nb} index $project]
if {!$tabindex} {
$projectmenu entryconfigure [::mc "Move to beginning"] -state disabled
$projectmenu entryconfigure [::mc "Move left"] -state disabled
} else {
$projectmenu entryconfigure [::mc "Move to beginning"] -state normal
$projectmenu entryconfigure [::mc "Move left"] -state normal
}
if {$tabindex == ([llength [${::main_nb} pages]] - 1)} {
$projectmenu entryconfigure [::mc "Move right"] -state disabled
$projectmenu entryconfigure [::mc "Move to end"] -state disabled
} else {
$projectmenu entryconfigure [::mc "Move right"] -state normal
$projectmenu entryconfigure [::mc "Move to end"] -state normal
}
# Invoke the menu and set project identifier
set projectmenu_project $project
tk_popup $projectmenu $x $y
}
## Function for project popup menu
# -- Save this project
# @return void
proc __project_pmenu_save {} {
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable projectmenu_project ;# Object: project selected by project popup menu
set tmp $actualProject
set actualProject $projectmenu_project
set tmp_idx $actualProjectIdx
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
__proj_save
set actualProject $tmp
set actualProjectIdx $tmp_idx
}
## Function for project popup menu
# -- Edit this project
# @return void
proc __project_pmenu_edit {} {
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable projectmenu_project ;# Object: project selected by project popup menu
set tmp $actualProject
set actualProject $projectmenu_project
set tmp_idx $actualProjectIdx
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
__proj_edit
set actualProject $tmp
set ctualProjectIdx $tmp_idx
}
## Function for project popup menu
# -- Close this project
# @return void
proc __project_pmenu_close {} {
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable projectmenu_project ;# Object: project selected by project popup menu
# Adjust variables identifing current project
set tmp $actualProject
set tmp_idx $actualProjectIdx
set actualProject $projectmenu_project
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
if {$actualProjectIdx == $tmp_idx} {
set this_closed 1
} else {
set this_closed 0
}
# Close project
__proj_close
}
## Function for project popup menu
# -- Close this project without saving
# @return void
proc __project_pmenu_close_imm {} {
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable projectmenu_project ;# Object: project selected by project popup menu
# Adjust variables identifing current project
set tmp $actualProject
set tmp_idx $actualProjectIdx
set actualProject $projectmenu_project
set actualProjectIdx [lsearch -exact -ascii $openedProjects $actualProject]
if {$actualProjectIdx == $tmp_idx} {
set this_closed 1
} else {
set this_closed 0
}
# Close project and restore variables identifing current project
if {[__proj_close_imm] && !$this_closed} {
if {$tmp_idx > $actualProjectIdx} {
incr tmp_idx -1
}
set actualProjectIdx $tmp_idx
set actualProject $tmp
}
}
## Function for project popup menu
# -- Move this tab left
# @return void
proc __project_move_to_left {} {
variable projectmenu_project ;# Object: project selected by project popup menu
set index [${::main_nb} index $projectmenu_project]
if {!$index} {
return
}
incr index -1
${::main_nb} move $projectmenu_project $index
}
## Function for project popup menu
# -- Move this tab right
# @return void
proc __project_move_to_right {} {
variable projectmenu_project ;# Object: project selected by project popup menu
set index [${::main_nb} index $projectmenu_project]
if {$index == ([llength [${::main_nb} index pages]] - 1)} {
return
}
incr index
${::main_nb} move $projectmenu_project $index
}
## Function for project popup menu
# -- Move this tab to the beginning
# @return void
proc __project_move_to_beginning {} {
variable projectmenu_project ;# Object: project selected by project popup menu
if {![${::main_nb} index $projectmenu_project]} {
return
}
${::main_nb} move $projectmenu_project 0
}
## Function for project popup menu
# -- Move this tab to the end
# @return void
proc __project_move_to_end {} {
variable projectmenu_project ;# Object: project selected by project popup menu
set end [expr {[llength [${::main_nb} pages]] - 1}]
if {[${::main_nb} index $projectmenu_project] == $end} {
return
}
${::main_nb} move $projectmenu_project $end
}
## Invert flag "allow breakpoints"
# @return void
proc __invert_allow_breakpoints {} {
set ::CONFIG(BREAKPOINTS_ALLOWED) [expr {!$::CONFIG(BREAKPOINTS_ALLOWED)}]
}
## Refresh bookmarks in file system browser in all projects
# @return void
proc refresh_bookmarks_in_fs_browsers {} {
variable openedProjects ;# List of opened projects (Object references)
foreach project $openedProjects {
$project filelist_fsb_refresh_bookmarks
}
}
## Invoke dialog "Tip of the day"
# @return void
proc __tip_of_the_day {} {
::Tips::show_tip_of_the_day_win
}
## Refresh program pointer in CODE memory hexadecimal editor
# @parm Object project - Project object
# @parm Int new_PC - New value of PC (-1 after reset)
# @return void
proc program_counter_changed {project new_PC} {
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
set idx [lsearch -exact -ascii $opened_code_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
set opcode [$project getCode $new_PC]
if {[lsearch ${::CompilerConsts::defined_OPCODE} $opcode] == -1} {
set ins_length 1
} else {
set ins_length [lindex $::CompilerConsts::Opcode($opcode) 2]
}
[lindex $code_mem_window_objects $idx] move_program_pointer $new_PC $ins_length
}
}
## Refresh program pointer in CODE memory hexadecimal editor
# @parm Object project - Project object
# @parm Int new_PC - New value of PC (-1 after reset)
# @return void
proc code_hex_editor_directly_move_program_pointer {project new_PC} {
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
set idx [lsearch -exact -ascii $opened_code_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
if {$new_PC != -1} {
set opcode [$project getCode $new_PC]
if {[lsearch ${::CompilerConsts::defined_OPCODE} $opcode] == -1} {
set ins_length 1
} else {
set ins_length [lindex $::CompilerConsts::Opcode($opcode) 2]
}
} else {
set ins_length 0
}
[lindex $code_mem_window_objects $idx] move_program_pointer_directly $new_PC $ins_length
}
}
## Refresh the current page in CODE memory hexadecimal editor
# @parm Object project - Project object
# @return void
proc refresh_code_mem_window {project} {
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
set idx [lsearch -exact -ascii $opened_code_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
[lindex $code_mem_window_objects $idx] refresh
}
}
## Refresh the current page in XDATA memory hexadecimal editor
# @parm Object project - Project object
# @return void
proc refresh_xram_mem_window {project} {
variable opened_xdata_mem_windows ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects ;# List of XDATA memory hex editor objects
set idx [lsearch -exact -ascii $opened_xdata_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
[lindex $xdata_mem_window_objects $idx] refresh
}
}
## Refresh the current page in EDATA memory hexadecimal editor
# @parm Object project - Project object
# @return void
proc refresh_eram_mem_window {project} {
variable opened_eram_windows ;# List of project object with opened ERAM hex editor
variable eram_window_objects ;# List of ERAM hex editor objects
set idx [lsearch -exact -ascii $opened_eram_windows [string trimleft $project {:}]]
if {$idx != -1} {
[lindex $eram_window_objects $idx] refresh
}
}
## Refresh the current page in data EEPROM hexadecimal editor
# @parm Object project - Project object
# @return void
proc refresh_eeprom_mem_window {project} {
variable opened_eeprom_mem_windows ;# List of project object with opened ERAM hex editor
variable eeprom_mem_window_objects ;# List of ERAM hex editor objects
set idx [lsearch -exact -ascii $opened_eeprom_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
[lindex $eeprom_mem_window_objects $idx] refresh
}
}
## Clear background highlight for certain cell in hex editor of data EEPROM
# @parm Int addr - Register address (absolute)
# @parm Object project - Project object
# @return void
proc sync_eeprom_clear_bg_hg {addr project} {
variable opened_eeprom_mem_windows ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects ;# List of data EEPROM hex editor objects
set idx [lsearch -exact -ascii $opened_eeprom_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
[lindex $eeprom_mem_window_objects $idx] set_bg_hg_clr $addr 0
}
}
## Synchronize the specified cell in data EEPROM hexadecimal editor
# @parm String addr - Hexadecimal address (0 - FFFF)
# @parm Int hg -
# 1 == highlight background
# 0 == do not affect bg. highlight
# @parm Object project - Project object
# @return void
proc sync_eeprom_mem_window {addr hg project} {
variable opened_eeprom_mem_windows ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects ;# List of data EEPROM hex editor objects
set idx [lsearch -exact -ascii $opened_eeprom_mem_windows [string trimleft $project {:}]]
if {$idx != -1} {
set obj [lindex $eeprom_mem_window_objects $idx]
$obj reg_sync $addr
if {$hg} {
$obj set_bg_hg_clr [expr "0x$addr"] 1
}
}
}
## Synchronize the specified cell in XDATA/ERAM hexadecimal editor
# @parm String addr - Hexadecimal address (0 - FFFF)
# @parm Object project - Project object
# @return void
proc sync_xram_mem_window {addr project} {
variable opened_xdata_mem_windows ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects ;# List of XDATA memory hex editor objects
variable opened_eram_windows ;# List of project object with opened ERAM hex editor
variable eram_window_objects ;# List of ERAM hex editor objects
set project [string trimleft $project {:}]
# Syncronize XDATA
set idx [lsearch -exact -ascii $opened_xdata_mem_windows $project]
if {$idx != -1} {
[lindex $xdata_mem_window_objects $idx] reg_sync $addr
}
# Syncronize ERAM
set idx [lsearch -exact -ascii $opened_eram_windows $project]
if {$idx != -1} {
[lindex $eram_window_objects $idx] reg_sync $addr
}
}
## Show/Close CODE memory hexadecimal editor
# @return void
proc __show_code_mem {} {
show_X_memory code
}
## Show/Close XDATA memory hexadecimal editor
# @return void
proc __show_ext_mem {} {
show_X_memory xdata
}
## Show/Close ERAM hexadecimal editor
# @return void
proc __show_exp_mem {} {
show_X_memory eram
}
## Show/Close ERAM hexadecimal editor
# @return void
proc __show_eeprom {} {
show_X_memory eeprom
}
## Invoke hex editor dialog
# @see __show_exp_mem, __show_ext_mem, __show_code_mem, __show_eeprom
# @parm String type - memory type (one of {eeprom xdata code eram})
# @return void
proc show_X_memory {type} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable opened_xdata_mem_windows ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects ;# List of XDATA memory hex editor objects
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
variable opened_eram_windows ;# List of project object with opened ERAM hex editor
variable eram_window_objects ;# List of ERAM hex editor objects
variable opened_eeprom_mem_windows ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects ;# List of data EEPROM hex editor objects
if {$project_menu_locked} {return}
# Determinate index of the currently opened hex editor for the current project
switch -- $type {
{xdata} {
if {![$actualProject cget -P_option_mcu_xdata]} {
return
}
set idx [lsearch -exact -ascii $opened_xdata_mem_windows $actualProject]
set list_of_opened {opened_xdata_mem_windows}
set window_objects {xdata_mem_window_objects}
}
{eram} {
if {![lindex [$actualProject cget -procData] 8]} {
return
}
set idx [lsearch -exact -ascii $opened_eram_windows $actualProject]
set list_of_opened {opened_eram_windows}
set window_objects {eram_window_objects}
}
{code} {
set idx [lsearch -exact -ascii $opened_code_mem_windows $actualProject]
set list_of_opened {opened_code_mem_windows}
set window_objects {code_mem_window_objects}
}
{eeprom} {
if {![lindex [$actualProject cget -procData] 32]} {
return
}
set idx [lsearch -exact -ascii $opened_eeprom_mem_windows $actualProject]
set list_of_opened {opened_eeprom_mem_windows}
set window_objects {eeprom_mem_window_objects}
}
}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Close
if {$idx != -1} {
close_hexedit $type $actualProject
set critical_procedure_in_progress 0
return
# Show
} else {
set object "hexedit_${type}_${actualProject}"
HexEditDlg ::$object $actualProject $type
lappend $list_of_opened $actualProject
lappend $window_objects $object
}
# Set filename for code memory and program pointer
if {$type == {code}} {
set filename [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
if {[lindex $filename 1] == {}} {
set filename [$actualProject editor_procedure {} getFileName {}]
}
set filename [file join [lindex $filename 0] [lindex $filename 1]]
set ext [file extension $filename]
set filename [file rootname $filename]
if {$ext == {.c} || $ext == {.h} || $ext == {.cxx} || $ext == {.cpp} || $ext == {.cc}} {
append filename {.ihx}
} else {
append filename {.hex}
}
::$object set_filename $filename
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
program_counter_changed $actualProject [$actualProject getPC]
}
# Highlight cells which are beeing written (EEPROM only)
} elseif {$type == {eeprom}} {
foreach addr [$actualProject simulator_get_eeprom_beeing_written] {
::$object set_bg_hg_clr $addr 1
}
}
# Finalize
set critical_procedure_in_progress 0
}
## Synchronize cell in data EEPROM write buffer with simulator engine
# @parm Int addr - Cell address (0..31)
# @parm Object project - Project object
# @return void
proc sync_eeprom_write_buffer {addr project} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_eeprom_wr_bf_windows ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects ;# List of data EEPROM write buffer hex editor objects
if {$project_menu_locked} {return}
set idx [lsearch -exact -ascii $opened_eeprom_wr_bf_windows [string trimleft $project {:}]]
if {$idx == -1} {return}
[string replace [lindex $eeprom_wr_bf_window_objects $idx] 0 0] \
setValue $addr [$project getEepromWrBufDEC $addr]
}
## Clear data EEPROM write buffer
# @parm Object project - Project object
# @return void
proc clear_eeprom_write_buffer {project} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_eeprom_wr_bf_windows ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects ;# List of data EEPROM write buffer hex editor objects
if {$project_menu_locked} {return}
set idx [lsearch -exact -ascii $opened_eeprom_wr_bf_windows [string trimleft $project {:}]]
if {$idx == -1} {return}
set hexeditor [string replace [lindex $eeprom_wr_bf_window_objects $idx] 0 0]
for {set addr 0} {$addr < 32} {incr addr} {
$hexeditor setValue $addr {}
}
}
## Set offset for data EEPROM write buffer window
# @parm String offset - New offset (format: 0xXXXX or {})
# @parm Object project - Project object
# @return void
proc eeprom_write_buffer_set_offset {offset project} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_eeprom_wr_bf_windows ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects ;# List of data EEPROM write buffer hex editor objects
if {$project_menu_locked} {return}
set idx [lsearch -exact -ascii $opened_eeprom_wr_bf_windows [string trimleft $project {:}]]
if {$idx == -1} {return}
if {$offset == {}} {
set offset [mc "< Undefined >"]
}
[lindex $eeprom_wr_bf_window_objects $idx].offset_frame.val configure -text $offset
}
## Binding for pseudo-events <cell_enter> and <cell_leave> in data EEPROM write buffer hex editor
# Set value of curosor label at the bottom of the window
# This function takes list of attributes with any length gerater
#+ than one but only first two are significant
# @parm Widget - Data EEPROM write buffer window
# @parm Int - Cell address
# @return void
proc eeprom_write_buffer_change_cursor_addr args {
variable foo_procedure_in_progress ;# Bool: Disables some non-critical procedures
if {$foo_procedure_in_progress} {return}
set foo_procedure_in_progress 1
# Parse input arguments
set win [lindex $args 0]
set addr [lindex $args 1]
# Increment the given address by offset
set offset [$win.offset_frame.val cget -text]
if {$addr != {} && [regexp {^0x[0-9a-fA-F]{4}$} $offset]} {
incr addr [expr "$offset"]
}
# Modify content of cursor label
if {$addr == {}} {
$win.bottom_frame.cur_val configure -text { }
} else {
set addr [format %X $addr]
set len [string length $addr]
if {$len < 4} {
set addr "[string repeat {0} [expr {4 - $len}]]$addr"
}
$win.bottom_frame.cur_val configure -text "0x$addr"
}
set foo_procedure_in_progress 0
}
## Invoke hex editor with data EEPROM write buffer
# @return void
proc __show_eeprom_write_buffer {} {
variable actualProject ;# Object: Current project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable opened_eeprom_wr_bf_windows ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects ;# List of data EEPROM write buffer hex editor objects
variable eeprom_wr_buf_counter ;# Counter of EEPROM write buffer hex editor objects
# Check if this function call is valid
if {$project_menu_locked} {return}
if {![lindex [$actualProject cget -procData] 32]} {
return
}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Check if the dialog is not already opened
if {[lsearch -exact -ascii $opened_eeprom_wr_bf_windows $actualProject] != -1} {
close_hexedit eeprom_wr_bf $actualProject
set critical_procedure_in_progress 0
return
}
# Create dialog window
incr eeprom_wr_buf_counter
set win [toplevel .eeprom_write_buffer_${eeprom_wr_buf_counter} -class {EEPROM} -bg ${::COMMON_BG_COLOR}]
# Adjust NS variables
lappend eeprom_wr_bf_window_objects $win
lappend opened_eeprom_wr_bf_windows $actualProject
# Create window header
pack [label $win.header \
-text [mc "%s - EEPROM write buffer" $actualProject] \
] -fill x -pady 10
# Create offset label
set offset_frame [frame $win.offset_frame]
pack [label $offset_frame.lbl \
-text [mc "OFFSET = "] \
-font [font create \
-size [expr {int(-17 * $::font_size_factor)}] \
-weight bold \
-family {helvetica}] \
] -side left
pack [label $offset_frame.val \
-fg {#0000FF} \
-font [font create \
-size [expr {int(-17 * $::font_size_factor)}] \
-weight bold \
-family {helvetica}] \
] -side left
pack $offset_frame -anchor w
# Create middle frame (hexeditor)
set hexeditor [HexEditor ::eeprom_write_buffer_${eeprom_wr_buf_counter} \
$win.mainframe 8 4 2 hex 1 0 4 32 \
]
$hexeditor showHideScrollbar 0
$hexeditor bindCellValueChanged "$actualProject setEepromWrBufDEC"
$hexeditor bindCellEnter "::X::eeprom_write_buffer_change_cursor_addr $win"
$hexeditor bindCellLeave "::X::eeprom_write_buffer_change_cursor_addr $win {}"
for {set i 0} {$i < 32} {incr i} {
$hexeditor setValue $i [$actualProject getEepromWrBufDEC $i]
}
eeprom_write_buffer_set_offset [$actualProject getEepromWrOffsetDEC] $actualProject
$hexeditor focus_left_view
pack $win.mainframe
# Create bottom frame
set bottom_frame [frame $win.bottom_frame]
pack [ttk::button $bottom_frame.close_but \
-text [mc "Close"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command "X::close_hexedit eeprom_wr_bf $actualProject" \
] -side left -anchor w -padx 2 -pady 2
pack [label $bottom_frame.cur_val \
-text { } -fg {#0000FF} \
-font [font create \
-family $::DEFAULT_FIXED_FONT \
-size [expr {int(-12 * $::font_size_factor)}] \
-weight bold \
] \
] -side right -anchor e -padx 5
pack [label $bottom_frame.cur_lbl \
-text [mc "Cursor: "] \
] -side right -anchor e
pack $bottom_frame -side bottom -fill x
# Configure dialog window
wm iconphoto $win ::ICONS::16::kcmmemory
wm title $win [mc "EEPROM write buffer - %s - MCU 8051 IDE" [$actualProject cget -projectName]]
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW \
"X::close_hexedit eeprom_wr_bf $actualProject"
# Finalize
set critical_procedure_in_progress 0
}
## Close hexadecimal editor window
# -- auxiliary procedure for '__show_ext_mem' and '__show_code_mem'
# @parm String type - Editor type ('eeprom', 'eeprom_wr_bf' 'eram', 'code' or 'xdata')
# @parm Object project - Project object descriptor
# @return void
proc close_hexedit {type project} {
variable opened_code_mem_windows ;# List of project object with opened CODE memory hex editor
variable code_mem_window_objects ;# List of CODE memory hex editor objects
variable opened_xdata_mem_windows ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects ;# List of XDATA memory hex editor objects
variable opened_eram_windows ;# List of project object with opened ERAM hex editor
variable eram_window_objects ;# List of ERAM hex editor objects
variable opened_eeprom_mem_windows ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects ;# List of data EEPROM hex editor objects
variable opened_eeprom_wr_bf_windows ;# List of project objects with opened data EEPROM write buffer editor
variable eeprom_wr_bf_window_objects ;# List of data EEPROM write buffer hex editor objects
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
# Close CODE memory editor
if {$type == {code}} {
set opened_windows_var {opened_code_mem_windows}
set window_objects_var {code_mem_window_objects}
set opened_windows $opened_code_mem_windows
set window_objects $code_mem_window_objects
# Close ERAM editor
} elseif {$type == {eram}} {
set opened_windows_var {opened_eram_windows}
set window_objects_var {eram_window_objects}
set opened_windows $opened_eram_windows
set window_objects $eram_window_objects
# Close XDATA memory editor
} elseif {$type == {xdata}} {
set opened_windows_var {opened_xdata_mem_windows}
set window_objects_var {xdata_mem_window_objects}
set opened_windows $opened_xdata_mem_windows
set window_objects $xdata_mem_window_objects
# Close data EEPROM editor
} elseif {$type == {eeprom}} {
set opened_windows_var {opened_eeprom_mem_windows}
set window_objects_var {eeprom_mem_window_objects}
set opened_windows $opened_eeprom_mem_windows
set window_objects $eeprom_mem_window_objects
# Close EEPROM write buffer
} elseif {$type == {eeprom_wr_bf}} {
set opened_windows_var {opened_eeprom_wr_bf_windows}
set window_objects_var {eeprom_wr_bf_window_objects}
set opened_windows $opened_eeprom_wr_bf_windows
set window_objects $eeprom_wr_bf_window_objects
# Close project independent hexadecimal editor
} elseif {$type == {uni}} {
return
# Invalid request
} else {
return
}
# Determinate editor index
set idx [lsearch -exact -ascii $opened_windows $project]
if {$idx == -1} {return}
# Destroy editor object
if {$type == {eeprom_wr_bf}} {
destroy [lindex $window_objects $idx]
} else {
delete object [lindex $window_objects $idx]
}
# Delete references
set $opened_windows_var [lreplace $opened_windows $idx $idx]
set $window_objects_var [lreplace $window_objects $idx $idx]
}
## Adjust main window title to current project and file
# @return void
proc adjust_title {} {
variable actualProject ;# Object: Current project
set title {} ;# New title
# Project opened
if {$actualProject != {}} {
# Gain data from the project
if {[catch {
if {[$actualProject editor_procedure {} cget -modified]} {
append title {[modified] }
}
append title [$actualProject cget -projectName]
append title { : }
append title [$actualProject editor_procedure {} cget -filename]
append title { - MCU 8051 IDE}
wm title . $title
# Error -- default title
}]} then {
wm title . ${::APPNAME}
}
# No project opened -- default title
} else {
wm title . ${::APPNAME}
}
}
## Clear highlight for changed registers in simulator panels
# @return void
proc __sim_clear_highlight {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
variable opened_xdata_mem_windows ;# List of project object with opened XDATA memory hex editor
variable xdata_mem_window_objects ;# List of XDATA memory hex editor objects
variable opened_eram_windows ;# List of project object with opened ERAM hex editor
variable eram_window_objects ;# List of ERAM hex editor objects
variable opened_eeprom_mem_windows ;# List of project object with opened data EEPROM hex editor
variable eeprom_mem_window_objects ;# List of data EEPROM hex editor objects
if {$project_menu_locked} {return}
$actualProject simulator_clear_highlight
$actualProject rightPanel_watch_clear_highlight
$actualProject bitmap_clear_hg
$actualProject sfrmap_clear_hg
set idx [lsearch -exact -ascii $opened_xdata_mem_windows $actualProject]
if {$idx != -1} {
[lindex $xdata_mem_window_objects $idx] clear_highlight
}
set idx [lsearch -exact -ascii $opened_eram_windows $actualProject]
if {$idx != -1} {
[lindex $eram_window_objects $idx] clear_highlight
}
set idx [lsearch -exact -ascii $opened_eeprom_mem_windows $actualProject]
if {$idx != -1} {
[lindex $eeprom_mem_window_objects $idx] clear_highlight
}
}
## Insure than simulator cursor is in editor visible area
# @return void
proc __see_sim_cursor {} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[lindex $simulator_enabled $actualProjectIdx] == 1} {
$actualProject editor_procedure {} see_sim_cursor {}
}
}
## Load value to PC in simulator control panel; line -> address
# @return void
proc __simulator_set_PC_by_line {} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable line2pc ;# Int: Selected line in source code
variable line2pc_jump ;# Bool: Perform program jump (1) or subprogram call (0)
variable line2pc_value_lbl ;# Widget: Label containing PC value
variable line2pc_new_value ;# Int: Resolved address or {}
variable line2pc_org_line ;# Int: Original line
variable line2pc_line_max ;# Int: Number of lines in the source code
variable line2pc_ok_button ;# Widget: Button "OK"
variable line2pc_file_number ;# Int: File number
if {$project_menu_locked} {return}
# Check if simulator is started
if {![lindex $simulator_enabled $actualProjectIdx]} {
return
}
set filename [$actualProject editor_procedure {} cget -fullFileName]
if {[lindex $filename 0] == {}} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to comply"] \
-message [mc "This operation cannot be performed on an untitled file"]
return
}
set line2pc_file_number [$actualProject simulator_get_filenumber $filename]
if {$line2pc_file_number == -1} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to comply"] \
-message [mc "This file does not contain any part of the running program"]
return
}
# Load some NS variables
set line2pc_line_max [$actualProject editor_linescount]
set line2pc_org_line [lindex [$actualProject simulator_getCurrentLine] 0]
set line2pc_new_value [$actualProject simulator_line2address $line2pc_org_line $line2pc_file_number]
set line2pc $line2pc_org_line
# Create dialog window
set win [toplevel .goto_line2pc -class [mc "Goto dialog"] -bg ${::COMMON_BG_COLOR}]
# Create window label frame
label $win.header \
-text [mc "Line to address"] \
-image ::ICONS::16::goto \
-compound left
# Create middle frame
set middle_frame [frame $win.middle_frame]
pack [label $middle_frame.left_lbl \
-text [mc "PC = "] \
-font [font create \
-size [expr {int(-16 * $::font_size_factor)}] \
-weight bold \
-family {helvetica}] \
] -side left
set line2pc_value_lbl [label $middle_frame.right_lbl \
-font [font create \
-size [expr {int(-16 * $::font_size_factor)}] \
-weight bold \
-family {helvetica}] \
]
pack $line2pc_value_lbl -side left
set middle_right_frame [frame $middle_frame.right_frame]
pack [radiobutton $middle_right_frame.jump_rabut \
-variable ::X::line2pc_jump \
-value 1 -text [mc "Program jump"] \
] -anchor w
pack [radiobutton $middle_right_frame.call_rabut \
-variable ::X::line2pc_jump \
-value 0 -text [mc "Subprogram call"] \
] -anchor w
pack $middle_right_frame -side right
pack $middle_frame -padx 5 -fill x -pady 5
# Create and pack 'OK' and 'CANCEL' buttons
set buttonFrame [frame $win.buttonFrame]
set line2pc_ok_button [ttk::button $buttonFrame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command {X::line2pc_OK} \
]
pack $line2pc_ok_button -side left -padx 2
pack [ttk::button $buttonFrame.cancel \
-text [mc "Cancel"] \
-compound left \
-image ::ICONS::16::button_cancel \
-command {X::line2pc_CANCEL} \
] -side left
pack $buttonFrame -after $middle_frame -pady 5 -padx 2
## Create top frame
set topFrame [ttk::labelframe $win.topFrame -labelwidget $win.header -relief flat]
pack $topFrame -expand 1 -fill x -before $middle_frame -padx 5 -pady 5
# Create scale widget
pack [ttk::scale $topFrame.scale \
-from 1 \
-to $line2pc_line_max \
-orient horizontal \
-variable ::X::line2pc \
-command "
set ::X::line2pc \[expr {int(\${::X::line2pc})}\]
::X::line2pc_validate \$::X::line2pc $topFrame.spinbox
$topFrame.spinbox selection range 0 end
#" \
] -side left -expand 1 -fill x -padx 2
DynamicHelp::add $topFrame.scale \
-text [mc "Graphical representation of the line where to go"]
# Create spinbox widget
pack [ttk::spinbox $topFrame.spinbox \
-from 1 -to $line2pc_line_max \
-textvariable ::X::line2pc \
-validate all \
-validatecommand {::X::line2pc_validate %P %W} \
-command "::X::line2pc_validate \$::X::line2pc $topFrame.spinbox" \
-width 4 \
] -side left
DynamicHelp::add $topFrame.spinbox -text [mc "Line where to go"]
# Events binding (Enter == Ok, Esc == CANCEL)
bind $win <KeyRelease-Return> {X::line2pc_OK; break}
bind $win <KeyRelease-KP_Enter> {X::line2pc_OK; break}
bind $win <KeyRelease-Escape> {X::line2pc_CANCEL; break}
# Focus on the Spinbox
focus $topFrame.spinbox
$topFrame.spinbox selection range 0 end
# Nessesary window manager options -- modal window
wm iconphoto $win ::ICONS::16::exec
wm title $win [mc "Line to address"]
wm minsize $win 380 140
wm protocol $win WM_DELETE_WINDOW {
X::line2pc_CANCEL
}
catch {grab $win}
raise $win
tkwait window $win
}
## Validate content od spinbox in dialog "Line to address"
# @parm String content - String to validate
# @return Bool - result
proc line2pc_validate {content line2pc_spinbox} {
variable actualProject ;# Object: Current project
variable line2pc ;# Int: Selected line in source code
variable line2pc_value_lbl ;# Widget: Label containing PC value
variable line2pc_new_value ;# Int: Resolved address or {}
variable line2pc_org_line ;# Int: Original line
variable line2pc_line_max ;# Int: Number of lines in the source code
variable line2pc_ok_button ;# Widget: Button "OK"
variable line2pc_file_number ;# Int: File number
if {$content == {}} {
return 1
}
# Validate the given string
set content [regsub {\..*$} $content {}]
if {![string is digit $content] || ($content > $line2pc_line_max) || ($content < 0)} {
catch {
$line2pc_spinbox configure -style TSpinbox
}
return 0
}
# Try to determinate address in program memory
set content [expr $content]
set line2pc_new_value [$actualProject simulator_line2address $content $line2pc_file_number]
# Fail
if {$line2pc_new_value == {}} {
# Adjust PC value label
$line2pc_value_lbl configure \
-fg {#DD0000} \
-text [mc "Unable to resolve"]
code_hex_editor_directly_move_program_pointer $actualProject -1
$actualProject editor_procedure {} unset_simulator_line {} ;# Adjust editor
$line2pc_ok_button configure -state disabled ;# Adjust Ok button
catch {
$line2pc_spinbox configure -style RedBg.TSpinbox ;# Adjust SpinBox
}
# Success
} else {
# Translate address to hexadecimal system
set addr_in_hex [format %X $line2pc_new_value]
set len [string length $addr_in_hex]
if {$len < 4} {
set addr_in_hex "[string repeat {0} [expr {4 - $len}]]$addr_in_hex"
}
$line2pc_value_lbl configure \
-fg {#00DD00} \
-text "0x$addr_in_hex"
# Adjust editor
code_hex_editor_directly_move_program_pointer $actualProject $line2pc_new_value
$actualProject move_simulator_line [list $content $line2pc_file_number]
$line2pc_ok_button configure -state normal ;# Adjust Ok button
catch {
$line2pc_spinbox configure -style GreenBg.TSpinbox ;# Adjust SpinBox
}
}
return 1
}
## Safely close dialog "Line to address"
# @return void
proc line2pc_safely_close {} {
if {[winfo exists .goto_line2pc]} {
grab release .goto_line2pc
destroy .goto_line2pc
}
}
## Cancel dialog "Line to address"
# @return void
proc line2pc_CANCEL {} {
variable line2pc_org_line ;# Int: Original line
variable actualProject ;# Object: Current project
if {$line2pc_org_line == {}} {
$actualProject editor_procedure {} unset_simulator_line {}
} else {
$actualProject move_simulator_line $line2pc_org_line
}
code_hex_editor_directly_move_program_pointer $actualProject -1
grab release .goto_line2pc
destroy .goto_line2pc
}
## Confirm dialog "Line to address"
# @return void
proc line2pc_OK {} {
variable line2pc_new_value ;# Int: Resolved address or {}
variable actualProject ;# Object: Current project
variable line2pc_jump ;# Bool: Perform program jump (1) or subprogram call (0)
variable line2pc ;# Int: Selected line in source code
if {$line2pc_new_value == {}} {
line2pc_CANCEL
return
}
$actualProject move_simulator_line $line2pc
if {$line2pc_jump} {
$actualProject setPC $line2pc_new_value
} else {
$actualProject simulator_subprog_call $line2pc_new_value
}
code_hex_editor_directly_move_program_pointer $actualProject -1
$actualProject Simulator_sync_PC_etc
grab release .goto_line2pc
destroy .goto_line2pc
}
## Switch to the previous editor in the current project (from editor statusbar popup menu)
# @return void
proc __prev_editor_from_pmenu {} {
variable actualProject ;# Object: Current project
variable selectedView ;# Object: Selected editor view
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Switch editor
$actualProject filelist_editor_selected $selectedView
$actualProject prev_editor
# Finalize
set critical_procedure_in_progress 0
}
## Switch to the next editor in the current project (from editor statusbar popup menu)
# @return void
proc __next_editor_from_pmenu {} {
variable actualProject ;# Object: Current project
variable selectedView ;# Object: Selected editor view
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Switch editor
$actualProject filelist_editor_selected $selectedView
$actualProject next_editor
# Finalize
set critical_procedure_in_progress 0
}
## Switch to editor command line
# @return void
proc __switch_to_cmd_line {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject cmd_line_on
}
## Split editor vertical
# @return void
proc __split_vertical {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject split_vertical
}
## Split editor horizontal
# @return void
proc __split_horizontal {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject split_horizontal
}
## Close current view (editor) from editor statusbar popup menu
# @return void
proc __close_current_view_from_pmenu {} {
variable selectedView ;# Object: Selected editor view
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject close_current_view $selectedView
}
## Close current view (editor)
# @return void
proc __close_current_view {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject close_current_view {}
}
## Enable / Disable stepback controls
# @parm Bool bool - 1 == enable; 0 == disable
# @return void
proc stepback_button_set_ena {bool} {
variable actualProject ;# Object: Current project
if {$bool != 0} {
set boot 1
}
$actualProject stepback_button_set_ena $bool
ena_dis_menu_buttons $bool {{{.mainMenu.simulator} {{Step back}}}}
ena_dis_iconBar_buttons $bool .mainIconBar. {stepback}
}
## Hibernate running program to a file
# This function also invokes file selection dialog to select target file.
# @return void
proc __hibernate {} {
hibernate_or_resume 1
}
## Resume hibernated program
# This function also invokes file selection dialog to select source file.
# @return void
proc __resume {} {
hibernate_or_resume 0
}
## Hibernate running program // Resume hibernated program
# @parm Bool hib_res - 1 == Hiberanate; 0 == Resume
# @return void
proc hibernate_or_resume {hib_res} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
# Simulator must be engaged for this function
if {$project_menu_locked} {return}
if {![lindex $simulator_enabled $actualProjectIdx]} {
return
}
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
set sourcefile [list \
[$actualProject cget -projectPath] \
[$actualProject cget -P_option_main_file] \
]
if {[lindex $sourcefile 1] == {}} {
set sourcefile [$actualProject editor_procedure {} getFileName {}]
}
set sourcefile [file join [lindex $sourcefile 0] [lindex $sourcefile 1]]
set initialfile [file rootname [file tail $sourcefile]]
if {$hib_res} {
set title [mc "Hibernate running program - MCU 8051 IDE"]
set cmd {__hibernate_to}
} else {
set title [mc "Resume hibernated program - MCU 8051 IDE"]
set cmd {__resume_from}
}
# Invoke file selection dialog
catch {delete object fsd}
KIFSD::FSD fsd \
-title $title -initialfile $initialfile \
-directory [$actualProject cget -projectPath] \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc "MCU 8051 IDE hibernated program"] {*.m5ihib} ] \
[list [mc "All files"] {*} ] \
]
# Open file after press of OK button
fsd setokcmd "
::X::fsd deactivate
::X::$cmd \[X::fsd get\] {$sourcefile}
"
# Activate FSD
fsd activate
# Finalize
set critical_procedure_in_progress 0
}
## Hibernate running program to the given file
# @parm String filename - Target file
# @parm String sourcefile - Source file
# @return void
proc __hibernate_to {filename sourcefile} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
# Simulator must be engaged for this function
if {$project_menu_locked} {return}
if {![lindex $simulator_enabled $actualProjectIdx]} {
return
}
# Adjust the given name of the target file
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $filename]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$filename"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $filename]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $filename]
}
}
if {[file extension $filename] == {}} {
append filename {.m5ihib}
}
set filename [file normalize $filename]
# Create backup copy the target file
if {[file exists $filename] && [file isfile $filename]} {
# Ask user for overwrite existing file
if {[tk_messageBox \
-type yesno \
-icon question \
-parent . \
-title [mc "Overwrite file"] \
-message [mc "A file name '%s' already exists. Are you sure you want to overwrite it ?" [file tail $filename]]
] != {yes}
} then {
return
}
# Create a backup file
catch {
file rename -force $filename "$filename~"
}
}
# Hibernate running program
set sourcefile_md5 {}
catch {
set sourcefile_md5 [::md5::md5 -hex -file $sourcefile]
}
if {![$actualProject hibernate_hibernate \
$filename [file tail $sourcefile] $sourcefile_md5 0 \
]} then {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Hibernation failed"] \
-message [mc "Unable to write to file:\n%s\nCheck your permissions." $filename]
}
}
## Resume hibernated program
# @parm String filename - Hibernation file
# @parm String sourcefile - Name of file from which the hibernation file was generated
# @return void
proc __resume_from {filename sourcefile} {
variable actualProject ;# Object: Current project
variable actualProjectIdx ;# Index of the current project in $openedProjects
variable simulator_enabled ;# List of booleans: Simulator engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
# Simulator must be engaged for this function
if {$project_menu_locked} {return}
if {![lindex $simulator_enabled $actualProjectIdx]} {
return
}
# Adjust the given name of the target file
if {!$::MICROSOFT_WINDOWS} { ;# POSIX way
if {![regexp "^(~|/)" $filename]} {
set filename "[${::X::actualProject} cget -ProjectDir]/$filename"
}
} else { ;# Microsoft windows way
if {![regexp {^\w:} $filename]} {
set filename [file join [${::X::actualProject} cget -ProjectDir] $filename]
}
}
set filename [file normalize $filename]
# Resume hibernated program
set result [$actualProject hibernate_resume $filename 0]
# ERROR: Cannot open the specified file
if {$result == 1} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Resumption failed"] \
-message [mc "Unable to read file:\n%s\nCheck your permissions." $filename]
# ERROR: Cannot parse the specified file
} elseif {$result == 2} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Resumption failed"] \
-message [mc "This hibernation is corrupted or it is not MCU 8051 IDE M5IHIB file."]
}
}
## Invoke interrupt monitor window
# @parm Object project_object=actualProject - Project
# @return void
proc __interrupt_monitor args {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[string length $args]} {
$args interrupt_monitor_invoke_dialog
} else {
$actualProject interrupt_monitor_invoke_dialog
}
}
## Invoke UART monitor window
# @return void
proc __uart_monitor args {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject uart_monitor_invoke_dialog
}
## Invoke stack monitor window
# @parm Object project_object=actualProject - Project
# @return void
proc __stack_monitor args {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {[string length $args]} {
$args stack_monitor_invoke_dialog
} else {
$actualProject stack_monitor_invoke_dialog
}
}
## Invoke SFR map window
# @return void
proc __sfr_map {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject sfrmap_invoke_dialog
}
## Show bit adrea
# @return void
proc __bitmap {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject bitmap_invoke_dialog
}
## Adjust application language to variable ::GLOBAL_CONFIG(language)
# @return void
proc switch_language {} {
# ${::GLOBAL_CONFIG(language)}
}
## Set syntax highlight for current editor
# @param Int highlight_num - -1 == None; 0 == Assembler; 1 == ISO C; 2 == Assembler code listing
# @return void
proc __set_highlight {highlight_num} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject editor_procedure {} force_language $highlight_num
}
## Highlight parrern for the current editor has been changed
# @return void
proc highlight_pattern_changed {} {
__set_highlight $::editor_SH
}
## Invoke independent hexadecimal editor
# @return Object - Hex editor object reference
proc __hexeditor {} {
variable independent_hexeditor_count ;# Counter of intances of independent hexadecimal editor
incr independent_hexeditor_count
return [HexEditDlg ::independent_hexeditor_$independent_hexeditor_count {} uni]
}
## Document current function in editor
# @return void
proc __document_current_func {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
$actualProject editor_procedure {} document_current_func {}
}
## Create doxygen configuration file if it does not already exist
# @return void
proc create_doxyfile {} {
variable doxygen_pid ;# Int: Doxygen PID
variable compilation_in_progress ;# Bool: Compiler engaged
variable actualProject ;# Object: Current project
if {$compilation_in_progress} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to comply"] \
-message [mc "Something is already running in background."]
return
}
set compilation_in_progress 1
make_progressBar_on_Sbar
if {[catch {
set path [$actualProject cget -projectPath]
if {$::MICROSOFT_WINDOWS} {
regsub -all {/} $path "\\" path
}
$actualProject messages_text_append "\ncd $path\n"
cd [$actualProject cget -projectPath]
}]} then {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Permission denied"] \
-message [mc "Unable to change directory to '%s'." [$actualProject cget -projectPath]]
return
}
if {!$::MICROSOFT_WINDOWS} {
if {![file exists Doxyfile]} {
$actualProject messages_text_append "doxygen -g Doxyfile\n"
set doxygen_pid [exec -- \
doxygen -g Doxyfile && doxygen -u Doxyfile |& \
tclsh ${::LIB_DIRNAME}/external_command.tcl [tk appname] \
::X::doxygen_finish ::X::doxygen_message & \
]
} else {
$actualProject messages_text_append "doxygen -u Doxyfile\n"
set doxygen_pid [exec -- \
doxygen -u Doxyfile |& tclsh \
${::LIB_DIRNAME}/external_command.tcl [tk appname] \
::X::doxygen_finish ::X::doxygen_message & \
]
}
} else {
if {![file exists Doxyfile]} {
$actualProject messages_text_append "doxygen -g Doxyfile\n"
set doxygen_pid [exec -- \
doxygen -g Doxyfile && doxygen -u Doxyfile \
|& \
"${::INSTALLATION_DIR}/external_command.bat" \
"${::INSTALLATION_DIR}/external_command.exe" \
"[tk appname]" \
::X::doxygen_finish ::X::doxygen_message & \
]
} else {
$actualProject messages_text_append "doxygen -u Doxyfile\n"
set doxygen_pid [exec -- \
doxygen -u Doxyfile \
|& \
"${::INSTALLATION_DIR}/external_command.bat" \
"${::INSTALLATION_DIR}/external_command.exe" \
"[tk appname]" \
::X::doxygen_finish ::X::doxygen_message & \
]
}
}
}
## Handle end of doxygen text output
# @return void
proc doxygen_finish {} {
variable actualProject ;# Object: Current project
variable doxygen_run_doxywizard ;# Bool: Run doxywizard
variable doxygen_build_api_doc ;# Bool: Build API documentation
variable doxygen_pid ;# Int: Doxygen PID
variable compilation_in_progress ;# Bool: Compiler engaged
if {$doxygen_run_doxywizard} {
exec -- doxywizard Doxyfile &
} elseif {$doxygen_build_api_doc} {
set doxygen_build_api_doc 0
if {[catch {
cd [$actualProject cget -projectPath]
}]} then {
$actualProject messages_text_append [mc "\nUnable to change directory to '%s'\n" [$actualProject cget -projectPath]]
destroy_progressBar_on_Sbar
set compilation_in_progress 0
set doxygen_pid 0
return
}
$actualProject messages_text_append "\ndoxygen Doxyfile\n"
set doxygen_pid [exec -- \
doxygen Doxyfile |& tclsh \
${::LIB_DIRNAME}/external_command.tcl [tk appname] \
::X::doxygen_finish ::X::doxygen_message & \
]
}
destroy_progressBar_on_Sbar
set compilation_in_progress 0
set doxygen_pid 0
}
## Handle text output doxygen
# @parm String text - Output from external compiler
# @return void
proc doxygen_message args {
variable doxygen_mess_project ;# Object: Project related to running doxygen compilation
$doxygen_mess_project messages_text_append \
[string replace [regsub -all "\\\{" [regsub -all "\\\}" [lindex $args 0] "\}"] "\{"] 0 0]
}
## Build C API documentation
# @return void
proc __generate_documentation {} {
variable doxygen_mess_project ;# Object: Project related to running doxygen compilation
variable doxygen_build_api_doc ;# Bool: Build API documentation
variable doxygen_pid ;# Int: Doxygen PID
variable compilation_in_progress ;# Bool: Compiler engaged
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {$compilation_in_progress} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to comply"] \
-message [mc "Something is already running in background."]
return
}
set doxygen_mess_project $actualProject
set doxygen_build_api_doc 1
if {!$::PROGRAM_AVAILABLE(doxygen)} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to find Doxygen"] \
-message [mc "Unable to find Doxygen. Please install doxygen and restart MCU 8051 IDE."]
return
}
$actualProject bottomNB_show_up {Messages}
create_doxyfile
}
## Run doxygen graphical front-end
# @return void
proc __run_doxywizard {} {
variable doxygen_mess_project ;# Object: Project related to running doxygen compilation
variable doxygen_run_doxywizard ;# Bool: Run doxywizard
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {!$::PROGRAM_AVAILABLE(doxywizard)} {
tk_messageBox \
-parent . \
-type ok \
-icon warning \
-title [mc "Unable to find doxywizard"] \
-message [mc "Unable to find doxywizard. Please install doxygen and restart MCU 8051 IDE."]
return
}
set doxygen_run_doxywizard 1
set doxygen_mess_project $actualProject
create_doxyfile
}
## Remove doxygen documentation
# @return void
proc __clear_documentation {} {
variable actualProject ;# Object: Current project
variable doxygen_mess_project ;# Object: Project related to running doxygen compilation
variable compilation_in_progress ;# Bool: Compiler engaged
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
set doxygen_mess_project $actualProject
if {[catch {
cd [$actualProject cget -projectPath]
}]} then {
$actualProject messages_text_append [mc "\nError: Unable to change directory to '%s'\n" [$actualProject cget -projectPath]]
return
}
$actualProject bottomNB_show_up {Messages}
$actualProject messages_text_append "\nrm -rfv html/* && rm -rfv latex/* && rm -rfv xml/*\n"
catch {exec -- /bin/sh << \
"rm -rfv html/* && rm -rfv latex/* && rm -rfv xml/*" |& \
tclsh ${::LIB_DIRNAME}/external_command.tcl [tk appname] \
::X::doxygen_message ::X::doxygen_message & \
}
}
## Display file statistic for the current file
# @return void
proc __statistics {} {
variable actualProject ;# Object: Current project
variable statistics_counter ;# Int: Counter of invocations of this dialog
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
# Check if this procedure can be run
if {$project_menu_locked} {return}
if {${::Editor::editor_to_use}} {
tk_messageBox \
-parent . \
-icon warning \
-type ok \
-title [mc "Unable to comply"] \
-message [mc "Unable to gain file statistics while external editor is used"]
return
}
# Create dialog window (not modal)
incr statistics_counter
set win [toplevel .statistics$statistics_counter -class {File statistics} -bg ${::COMMON_BG_COLOR}]
# Local variables
set bold_font [font create -family {helvetica} -size [expr {int(-12 * $::font_size_factor)}] -weight bold]
set normal_font [font create -family {helvetica} -size [expr {int(-12 * $::font_size_factor)}] -weight normal]
set header_font [font create -family {helvetica} -size [expr {int(-20 * $::font_size_factor)}] -weight normal]
set statistics [$actualProject editor_procedure {} getFileStatistics {}]
# Create window header
set dialog_header [label $win.dialog_header \
-width 25 -font $header_font \
-text [lindex [$actualProject editor_procedure {} getFileName {}] 1] \
]
set main_frame [frame $win.main_frame]
# Header: "Characters"
grid [label $main_frame.characters_lbl -pady 0 \
-text [mc "Characters"] -font $bold_font \
] -row 0 -column 0 -columnspan 3 -sticky w
# - Words and numbers
grid [Label $main_frame.c_words_name_lbl \
-text [mc "Words and numbers:"] \
-font $normal_font -pady 0 \
-helptext [mc "Alphanumeric characters and connector punctuation characters"] \
] -row 1 -column 1 -sticky w
grid [label $main_frame.c_words_value_lbl \
-text [lindex $statistics 0] \
-font $normal_font -pady 0 \
] -row 1 -column 2 -sticky e
# - Comments
grid [Label $main_frame.c_comments_name_lbl \
-text [mc "Comments:"] \
-font $normal_font -pady 0 \
-helptext [mc "Characters highlighted as comments"] \
] -row 2 -column 1 -sticky w
grid [label $main_frame.c_comments_value_lbl \
-text [lindex $statistics 1] \
-font $normal_font -pady 0 \
] -row 2 -column 2 -sticky e
# - Other characters
grid [Label $main_frame.c_other_name_lbl \
-text [mc "Other characters:"] \
-font $normal_font -pady 0 \
-helptext [mc "All other characters without EOLs (e.g. spaces and brackets)"] \
] -row 3 -column 1 -sticky w
grid [label $main_frame.c_other_value_lbl \
-text [lindex $statistics 2] \
-font $normal_font -pady 0 \
] -row 3 -column 2 -sticky e
# Separator
grid [ttk::separator $main_frame.sep_0 \
-orient horizontal \
] -row 4 -column 2 -sticky we
# - Total characters
grid [Label $main_frame.c_total_name_lbl \
-text [mc "Total characters:"] \
-font $normal_font -pady 0 \
-helptext [mc "All characters in the text without EOLs"] \
] -row 5 -column 1 -sticky w
grid [label $main_frame.c_total_value_lbl \
-text [lindex $statistics 3] \
-font $normal_font -pady 0 \
] -row 5 -column 2 -sticky e
# Header: "Strings"
grid [label $main_frame.strings_lbl -pady 0 \
-text [mc "Strings"] -font $bold_font \
] -row 7 -column 0 -columnspan 3 -sticky w
# - Words
grid [Label $main_frame.s_words_name_lbl \
-text [mc "Words:"] \
-font $normal_font -pady 0 \
-helptext [mc "Just normal words (not keywords and not comments)"] \
] -row 8 -column 1 -sticky w
grid [label $main_frame.s_words_value_lbl \
-text [lindex $statistics 4] \
-font $normal_font -pady 0 \
] -row 8 -column 2 -sticky e
# - Keywords
grid [Label $main_frame.s_keywords_name_lbl \
-text [mc "Keywords:"] \
-font $normal_font -pady 0 \
-helptext [mc "Instructions, Assembler directives, C directives, C keywords"] \
] -row 9 -column 1 -sticky w
grid [label $main_frame.s_keywords_value_lbl \
-text [lindex $statistics 5] \
-font $normal_font -pady 0 \
] -row 9 -column 2 -sticky e
# - Comments
grid [Label $main_frame.s_comments_name_lbl \
-text [mc "Comments:"] \
-font $normal_font -pady 0 \
-helptext [mc "Words in comments"] \
] -row 10 -column 1 -sticky w
grid [label $main_frame.s_comments_value_lbl \
-text [lindex $statistics 6] \
-font $normal_font -pady 0 \
] -row 10 -column 2 -sticky e
# Separator
grid [ttk::separator $main_frame.sep_1 \
-orient horizontal \
] -row 11 -column 2 -sticky we
# - Total strings
grid [Label $main_frame.s_total_name_lbl \
-text [mc "Total strings:"] \
-font $normal_font -pady 0 \
-helptext [mc "Total number of words in the text"] \
] -row 12 -column 1 -sticky w
grid [label $main_frame.s_total_value_lbl \
-text [lindex $statistics 7] \
-font $normal_font -pady 0 \
] -row 12 -column 2 -sticky e
# Header: "Lines"
grid [label $main_frame.lines_lbl \
-text [mc "Lines"] \
-font $bold_font -pady 0 \
] -row 14 -column 0 -columnspan 3 -sticky w
# - Empty lines
grid [Label $main_frame.l_empty_name_lbl \
-text [mc "Empty lines:"] \
-font $normal_font -pady 0 \
-helptext [mc "Totally empty lines (without even spaces)"] \
] -row 15 -column 1 -sticky w
grid [label $main_frame.l_empty_value_lbl \
-text [lindex $statistics 8] \
-font $normal_font -pady 0 \
] -row 15 -column 2 -sticky e
# - Commented lines
grid [Label $main_frame.l_commented_name_lbl \
-text [mc "Commented lines:"] \
-font $normal_font -pady 0 \
-helptext [mc "Lines which are all commented"] \
] -row 16 -column 1 -sticky w
grid [label $main_frame.l_commented_value_lbl \
-text [lindex $statistics 9] \
-font $normal_font -pady 0 \
] -row 16 -column 2 -sticky e
# - Normal lines
grid [Label $main_frame.l_normal_name_lbl \
-text [mc "Normal lines:"] \
-font $normal_font -pady 0 \
-helptext [mc "Just normal code lines"] \
] -row 17 -column 1 -sticky w
grid [label $main_frame.l_normal_value_lbl \
-text [lindex $statistics 10] \
-font $normal_font -pady 0 \
] -row 17 -column 2 -sticky e
# Separator
grid [ttk::separator $main_frame.sep_2 \
-orient horizontal \
] -row 18 -column 2 -sticky we
# - Total lines
grid [Label $main_frame.l_total_name_lbl \
-text [mc "Total lines:"] \
-font $normal_font -pady 0 \
-helptext [mc "Total number of lines in the text"] \
] -row 19 -column 1 -sticky w
grid [label $main_frame.l_total_value_lbl \
-text [lindex $statistics 11] \
-font $normal_font -pady 0 \
] -row 19 -column 2 -sticky e
# Configure main frame
grid columnconfigure $main_frame 0 -minsize 25
grid columnconfigure $main_frame 1 -weight 1
grid rowconfigure $main_frame 6 -minsize 10
grid rowconfigure $main_frame 13 -minsize 10
# Create and pack 'COPY' and 'OK' buttons
set button_frame [frame $win.button_frame]
pack [ttk::button $button_frame.ok \
-text [mc "Ok"] \
-compound left \
-image ::ICONS::16::ok \
-command "X::statistics_close $statistics_counter" \
] -side right -padx 2
pack [ttk::button $button_frame.copy \
-text [mc "Copy"] \
-compound left \
-image ::ICONS::16::editcopy \
-command "X::statistics_copy $statistics_counter" \
] -side left -padx 2
# Pack dialog frames
pack $dialog_header -side top -fill x -pady 5
pack $main_frame -side top -anchor nw -fill x -pady 15 -padx 10
pack $button_frame -side bottom -anchor se -pady 5 -padx 5
# Set window manager options
wm iconphoto $win ::ICONS::16::graph
wm title $win [mc "File statistics - MCU 8051 IDE"]
wm minsize $win 250 400
wm transient $win .
wm protocol $win WM_DELETE_WINDOW "X::statistics_close $statistics_counter"
update
focus $button_frame.ok
raise $win
}
## Close dialog "File statistics"
# @parm Int dialog_number -
# @return void
proc statistics_close {dialog_number} {
variable statistics_counter ;# Int: Counter of invocations of this dialog
if {![winfo exists .statistics$statistics_counter]} {return}
destroy .statistics$statistics_counter
}
## Copy contents of file statistics dialog to the clipboard
# @parm Int dialog_number -
# @return void
proc statistics_copy {dialog_number} {
variable statistics_counter ;# Int: Counter of invocations of this dialog
if {![winfo exists .statistics$statistics_counter]} {return}
set win .statistics$statistics_counter
set main_frame $win.main_frame
clipboard clear
clipboard append [mc "Statistics for: %s\n\n" [$win.dialog_header cget -text]]
clipboard append [mc "Characters:\n"]
clipboard append [mc " Words and numbers:\t\t%s\n" [$main_frame.c_words_value_lbl cget -text]]
clipboard append [mc " Comments:\t\t\t%s\n" [$main_frame.c_comments_value_lbl cget -text]]
clipboard append [mc " Other characters:\t\t%s\n" [$main_frame.c_other_value_lbl cget -text]]
clipboard append [mc " ------\n"]
clipboard append [mc " Total characters:\t\t%s\n\n" [$main_frame.c_total_value_lbl cget -text]]
clipboard append [mc "Strings:\n"]
clipboard append [mc " Words:\t\t\t%s\n" [$main_frame.s_words_value_lbl cget -text]]
clipboard append [mc " Keywords:\t\t\t%s\n" [$main_frame.s_keywords_value_lbl cget -text]]
clipboard append [mc " Comments:\t\t\t%s\n" [$main_frame.s_comments_value_lbl cget -text]]
clipboard append [mc " ------\n"]
clipboard append [mc " Total strings:\t\t%s\n" [$main_frame.s_total_value_lbl cget -text]]
clipboard append [mc "Lines:\n"]
clipboard append [mc " Empty lines:\t\t\t%s\n" [$main_frame.l_empty_value_lbl cget -text]]
clipboard append [mc " Commented lines:\t\t%s\n" [$main_frame.l_commented_value_lbl cget -text]]
clipboard append [mc " Normal lines:\t\t\t%s\n" [$main_frame.l_normal_value_lbl cget -text]]
clipboard append [mc " ------\n"]
clipboard append [mc " Total lines:\t\t\t%s\n" [$main_frame.l_total_value_lbl cget -text]]
}
## Modify main menu and main toolbar according to configuration of the current editor
# @parm Bool read_only - 1 == Read only; 0 == Normal mode; {} == Do not change
# @parm Bool c_language - 1 == Uses C language; 0 == Uses Assembler; {} == Do not change
# @return void
proc adjust_mainmenu_and_toolbar_to_editor {read_only c_language} {
variable mainmenu_editor_readonly ;# Menu bar items which are not available when editor is in read only mode
variable toolbar_editor_readonly ;# Tool bar items which are not available when editor is in read only mode
variable mainmenu_editor_c_only ;# Menu bar items which are not available only for C language
variable toolbar_editor_c_only ;# Toolbar items which are not available only for C language
# Read only flag
if {$read_only != {}} {
set read_only [expr {!$read_only}]
ena_dis_menu_buttons $read_only $mainmenu_editor_readonly
ena_dis_iconBar_buttons $read_only .mainIconBar. $toolbar_editor_readonly
}
# C language
if {$c_language != {}} {
ena_dis_menu_buttons $c_language $mainmenu_editor_c_only
ena_dis_iconBar_buttons $c_language .mainIconBar. $toolbar_editor_c_only
}
}
## Conditionaly disable menu and toolbar items which
#+ are not available when external editor used
# @return void
proc adjust_mm_and_tb_ext_editor {} {
variable mainmenu_editor_external_na ;# Menu bar items which are not available when external embedded editor is used
variable toolbar_editor_external_na ;# Toolbar items which are not available when external embedded editor is used
if {!${::Editor::editor_to_use}} {
return
}
ena_dis_menu_buttons 0 $mainmenu_editor_external_na
ena_dis_iconBar_buttons 0 .mainIconBar. $toolbar_editor_external_na
}
## Invoke assembly language symbols viewer
# @return void
proc __symb_view {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
# Open dialog window
set obj [SymbolViewer #auto]
# Try to load some file into the viewer
if {!$project_menu_locked} {
set file [$actualProject cget -P_option_main_file]
if {$file == {}} {
set file [$actualProject editor_procedure {} getFileName {}]
set file [file join [lindex $file 0] [lindex $file 1]]
}
if {$file != {}} {
$obj open_file 1 [file rootname $file].lst
}
}
}
## Invoke 8-Segment LED display editor
# @return void
proc __eightsegment {} {
variable eightsegment_editors ;# List: All 8-Segment LED display editors invoked
lappend eightsegment_editors [EightSegment #auto]
}
## Invoke ASCII chart
# @return void
proc __ascii_chart {} {
variable ascii_chart_win_object ;# Object: ASCII chart window object
if {$ascii_chart_win_object != {}} {
if {[$ascii_chart_win_object is_visible]} {
$ascii_chart_win_object raise_window
} else {
$ascii_chart_win_object restore_window
}
} else {
set ascii_chart_win_object [AsciiChart #auto]
}
}
## Switch editor to block selection mode
# @return void
proc __block_selection_mode {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
if {$project_menu_locked} {return}
$actualProject editor_procedure {} switch_sel_mode {}
}
## Invoke stopwatch timer window
# @return void
proc __stopwatch_timer {} {
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable actualProject ;# Object: Current project
if {$project_menu_locked} {return}
$actualProject stopwatch_invoke_dialog
}
## Referesh contents of menu "Open recent"
# @param Int what
# 0 - Recent project files
# 1 - Recent source code files
# 2 - Recent Virtual HW files
# @return void
proc refresh_recent_files {what} {
variable file_recent_files ;# List: recently opened files
variable project_recent_files ;# List: recently opened projects
variable vhw_recent_files ;# List: recently opened Virtual HW files
# Refresh "Recent Virtual HW files"
if {$what == 2} {
# Clean up the menu
.mainMenu.virtual_hw.open_recent delete 0 end
.mainMenu.virtual_hw.load_recent delete 0 end
# Interate over recently opened files and add them to the menu
foreach file $vhw_recent_files {
.mainMenu.virtual_hw.open_recent add command \
-label $file -command [list ::X::open_recent 2 $file]
.mainMenu.virtual_hw.load_recent add command \
-label $file -command [list ::X::open_recent -2 $file]
}
# Refresh "Recent source code file"
} elseif {$what == 1} {
# Clean up the menu
.mainMenu.file.open_recent delete 0 end
# Interate over recently opened files and add them to the menu
foreach file $file_recent_files {
# Determinate file type and appropriate icon
set ext [string trimleft [file extension $file] {.}]
if {$ext == {c}} {
set img {source_c}
} elseif {$ext == {h}} {
set img {source_h}
} elseif {$ext == {cxx} || $ext == {cpp} || $ext == {cc}} {
set img {source_cpp}
} elseif {$ext == {lst}} {
set img {ascii}
} elseif {$ext == {asm}} {
set img {asm}
} else {
set img {ascii}
}
# Create a new menu entry
.mainMenu.file.open_recent add command \
-label $file -compound left -image ::ICONS::16::$img \
-command [list ::X::open_recent $what $file]
}
# Refresh "Recent project file"
} elseif {$what == 0} {
# Clean up the menu
.mainMenu.project.open_recent delete 0 end
# Interate over recently opened files and add them to the menu
foreach file $project_recent_files {
.mainMenu.project.open_recent add command \
-label $file -command [list ::X::open_recent $what $file]
}
}
}
## Open recent file
# @param Int what
# 0 - Recent project files
# 1 - Recent source code files
# 2 - Recent Virtual HW files (OPEN)
# -2 - Recent Virtual HW files (LOAD)
# @param String filename - Name of file to open
# @return void
proc open_recent {what filename} {
variable critical_procedure_in_progress ;# Bool: Disable critical procedures (like compilation, start simulator, etc.)
variable actualProject ;# Object: Current project
variable openedProjects ;# List of opened projects (Object references)
variable vhw_recent_files ;# List: recently opened Virtual HW files
# This function is critical
if {$critical_procedure_in_progress} {return}
set critical_procedure_in_progress 1
# Open "Recent Virtual HW file"
if {$what == 2} {
if {[$actualProject pale_open_scenario $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to read file:\n\"%s\"" $filename]
}
# Load "Recent Virtual HW file"
} elseif {$what == -2} {
if {[$actualProject pale_load_scenarion $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to read file:\n\"%s\"" $filename]
}
# Open "Recent source code file"
} elseif {$what == 1} {
# If there is no project opened -> invalid function call -> abort
if {![llength $openedProjects]} {
set critical_procedure_in_progress 0
return
}
# Open the specified file
if {[$actualProject openfile $filename 1 . def def 0 0 {}] != {}} {
$actualProject switch_to_last
update
$actualProject editor_procedure {} parseAll {}
# Make LST read only
if {[file extension $filename] == {.lst}} {
set ::editor_RO_MODE 1
$actualProject switch_editor_RO_MODE
}
}
# Open "Recent project file"
} elseif {$what == 0} {
# Try to open he specified project file
if {![Project::open_project_file $filename]} {
tk_messageBox \
-type ok \
-icon warning \
-parent . \
-title [mc "Error - MCU 8051 IDE"] \
-message [mc "Unable to load file: %s" $filename]
} else {
$actualProject editor_procedure {} highlight_visible_area {}
}
adjust_title
disaena_menu_toolbar_for_current_project
}
# Unlock critical procedures
set critical_procedure_in_progress 0
}
## Add item into list of recent files
# @param Int what
# 0 - Recent project files
# 1 - Recent source code files
# 2 - Recent Virtual HW files
# @param String filename - Name of file to add
# @return void
proc recent_files_add {what filename} {
variable file_recent_files ;# List: recently opened files
variable project_recent_files ;# List: recently opened projects
variable vhw_recent_files ;# List: recently opened Virtual HW files
# Add "Recent Virtual HW file"
if {$what == 2} {
# Check wheather the specified file is already in the list
set tmp [lsearch -ascii -exact $vhw_recent_files $filename]
if {$tmp != -1} {
set vhw_recent_files [linsert [lreplace $vhw_recent_files $tmp $tmp] 0 $filename]
refresh_recent_files $what
return
}
# Trim list length to 10
if {[llength $vhw_recent_files] >= 10} {
set vhw_recent_files [lreplace $vhw_recent_files end end]
}
# Add new item and refersh menu
set vhw_recent_files [linsert $vhw_recent_files 0 $filename]
refresh_recent_files $what
# Add "Recent source code file"
} elseif {$what == 1} {
# Check wheather the specified file is already in the list
set tmp [lsearch -ascii -exact $file_recent_files $filename]
if {$tmp != -1} {
set file_recent_files [linsert [lreplace $file_recent_files $tmp $tmp] 0 $filename]
refresh_recent_files $what
return
}
# Trim list length to 10
if {[llength $file_recent_files] >= 10} {
set file_recent_files [lreplace $file_recent_files end end]
}
# Add new item and refersh menu
set file_recent_files [linsert $file_recent_files 0 $filename]
refresh_recent_files $what
# Add "Recent project file"
} elseif {$what == 0} {
# Check wheather the specified file is already in the list
set tmp [lsearch -ascii -exact $project_recent_files $filename]
if {$tmp != -1} {
set project_recent_files [linsert [lreplace $project_recent_files $tmp $tmp] 0 $filename]
refresh_recent_files $what
return
}
# Trim list length to 10
if {[llength $project_recent_files] >= 10} {
set project_recent_files [lreplace $project_recent_files end end]
}
# Add new item and refersh menu
set project_recent_files [linsert $project_recent_files 0 $filename]
refresh_recent_files $what
}
}
## Invoke "scribble notepad"
# @return void
proc __notes {} {
Notes #auto {} {}
}
## Invoke "Base converter"
# @return void
proc __base_converter {} {
variable base_converters ;# List: All base converter objects
set obj [BaseConverter #auto]
lappend base_converters ::X::$obj
return $obj
}
## Close "Base converter"
# @return void
proc __base_converter_close {obj} {
variable base_converters ;# List: All base converter objects
set idx [lsearch -ascii -exact $base_converters $obj]
if {$idx != -1} {
set base_converters [lreplace $base_converters $idx $idx]
}
}
## Invoke "LED panel" (section Virtual Hardware)
# @return void
proc __vhw_LED_panel {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [LedPanel #auto $actualProject]
}
## Invoke "LED display" (section Virtual Hardware)
# @return void
proc __vhw_LED_display {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [LedDisplay #auto $actualProject]
}
## Invoke "LED matrix" (section Virtual Hardware)
# @return void
proc __vhw_LED_matrix {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [LedMatrix #auto $actualProject]
}
## Invoke "Virtual UART Terminal" (section Virtual Hardware)
# @return void
proc __vhw_UART_terminal {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [VirtualUARTTerminal #auto $actualProject]
}
## Invoke "File Interface" (section Virtual Hardware)
# @return void
proc __vhw_file_interface {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [PaleFileInterface #auto $actualProject]
}
## Invoke "LCD display controlled by HD44780" (section Virtual Hardware)
# @parm List $display_size={} - Size of the LCD display to create, format: {rows columns}, empty list means invoke size selection dialog
# @return void
#
# Note: If the first argument is omitted then this function will create a "Size selection dialog"
proc __vhw_HD44780 {{display_size {}}} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
variable vhw_HD44780_rect ;# Array: Rectangles in dialog "Set display size"
variable vhw_HD44780_canvas ;# Widget: Canvas widget in dialog "Set display size"
variable vhw_HD44780_counter ;# Int: Counter of dialog instances
variable vhw_HD44780_size_lbl ;# Widget: Label showing the LCD size in dialog "Set display size"
variable vhw_HD44780_dialog ;# Widget: Toplevel window of dialog "Set display size"
variable vhw_HD44780_size ;# List of Int: LCD display size chosen by the user, {HEIGHT WIDTH}
# This function requires at least one project opened
if {$project_menu_locked} {return}
# LCD display size specified -- create the display and return
if {[llength $display_size]} {
set object [LcdHD44780 #auto $actualProject]
$object set_config [list [lindex $display_size 0] [lindex $display_size 1]]
return $object
}
# --------------------------------------------------------------
# Create the size selection dialog
# --------------------------------------------------------------
# Create the dialog window
set dialog [toplevel .set_lcd_size$vhw_HD44780_counter -class {Set display size} -bg ${::COMMON_BG_COLOR}]
# Set some namespace variables
incr vhw_HD44780_counter ;# Int: Counter of dialog instances
set vhw_HD44780_dialog $dialog ;# Widget: Toplevel window of dialog "Set display size"
set vhw_HD44780_size {0 0} ;# List of Int: LCD display size chosen by the user, {HEIGHT WIDTH}
# Create top frame (text: "Set display size" and actual display size)
set top_frame [frame $dialog.top_frame]
pack [label $top_frame.header_lbl \
-text [mc "Set display size"] \
-font [font create \
-size [expr {int(-17 * $::font_size_factor)}] \
-family {helvetica}] \
] -side left -padx 10
set vhw_HD44780_size_lbl [label $top_frame.size_lbl \
-text {0 × 0} \
-text [mc "Set display size"] \
-font [font create \
-size [expr {int(-16 * $::font_size_factor)}] \
-family {helvetica} -weight {bold}] \
]
pack $vhw_HD44780_size_lbl -side right -padx 10
pack $top_frame -fill x
## Create the matrix of rectangles for display size selection
set w 12
set h 17
set x0 3
set x $x0
set y 3
set canvas [canvas $dialog.canvas \
-bg {#FFFFFF} \
-height [expr {2 * ($h + 3) + 6}] \
-width [expr {40 * ($w + 3) + 6}] \
-bd 0 \
-highlightthickness 0 \
]
set vhw_HD44780_canvas $canvas
for {set row 1} {$row <= 2} {incr row} {
for {set col 1} {$col <= 40} {incr col} {
set r [$canvas create rectangle \
$x \
$y \
[expr {$x + $w}] \
[expr {$y + $h}] \
-outline {#0000FF} \
]
incr x $w
incr x 3
set vhw_HD44780_rect($row,$col) $r
$canvas bind $r <Enter> [list ::X::vhw_HD44780_ENTER $row $col]
$canvas bind $r <Leave> [list ::X::vhw_HD44780_ENTER 0 0]
$canvas bind $r <Button-1> [list ::X::vhw_HD44780_GO $row $col]
}
set x $x0
incr y $h
incr y 3
}
pack $canvas
# Set window parameters
wm iconphoto $dialog ::ICONS::16::set_lcd_size
wm title $dialog [mc "Set display size"]
wm resizable $dialog 0 0
wm protocol $dialog WM_DELETE_WINDOW {
X::vhw_HD44780_CANCEL
}
wm transient $dialog .
update
raise $dialog
catch {grab $dialog}
# Wait the dialog window is destroyed
tkwait window $dialog
# If the size was set then create the display
if {[lindex $vhw_HD44780_size 0] && [lindex $vhw_HD44780_size 1]} {
set object [LcdHD44780 #auto $actualProject]
$object set_config [list [lindex $vhw_HD44780_size 0] [lindex $vhw_HD44780_size 1]]
return $object
}
}
## Handle pointer enter event in the canvas widget of the LCD display size selection dialog
# @parm Int target_row - Designated row
# @parm Int target_col - Designated column
# @return void
proc vhw_HD44780_ENTER {target_row target_col} {
variable vhw_HD44780_rect ;# Array: Rectangles in dialog "Set display size"
variable vhw_HD44780_canvas ;# Widget: Canvas widget in dialog "Set display size"
variable vhw_HD44780_size_lbl ;# Widget: Label showing the LCD size in dialog "Set display size"
# Adjust appearance of the matrix of rectangles
for {set row 1} {$row <= 2} {incr row} {
for {set col 1} {$col <= 40} {incr col} {
if {$row <= $target_row && $col <= $target_col} {
set fill {#AAFFDD}
} else {
set fill {#FFFFFF}
}
$vhw_HD44780_canvas itemconfigure $vhw_HD44780_rect($row,$col) -fill $fill
}
}
# Adjust contents of the label displaying the designated size
$vhw_HD44780_size_lbl configure -text [format {%d × %d} $target_row $target_col]
}
## Set display size and close the LCD display size selection dialog
# @parm Int rows - Number of rows
# @parm Int cols - Number of columns
# @return void
proc vhw_HD44780_GO {rows cols} {
variable vhw_HD44780_size ;# List of Int: LCD display size chosen by the user, {HEIGHT WIDTH}
set vhw_HD44780_size [list $rows $cols]
vhw_HD44780_CANCEL
}
## Close the LCD display size selection dialog
# @return void
proc vhw_HD44780_CANCEL {} {
variable vhw_HD44780_dialog ;# Widget: Toplevel window of dialog "Set display size"
if {[winfo exists $vhw_HD44780_dialog]} {
destroy $vhw_HD44780_dialog
}
}
## Invoke "Multiplexed LED display" (section Virtual Hardware)
# @return void
proc __vhw_M_LED_display {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [MultiplexedLedDisplay #auto $actualProject]
}
## Invoke "Simple keypad" (section Virtual Hardware)
# @return void
proc __vhw_keys {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [SimpleKeyPad #auto $actualProject]
}
## Invoke "DS1620 temperature sensor" (section Virtual Hardware)
# @return void
proc __vhw_ds1620 {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [Ds1620 #auto $actualProject]
}
## Invoke "Matrix keypad" (section Virtual Hardware)
# @return void
proc __vhw_matrix_keypad {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
return [MatrixKeyPad #auto $actualProject]
}
## Open VHW file (section Virtual Hardware)
# @return void
proc __open_VHW {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Ask user for save modified VHW scenario
if {[${::X::actualProject} pale_modified]} {
if {[tk_messageBox \
-parent . \
-type yesno \
-icon question \
-title [mc "File modified"] \
-message [mc "The current VHW connections have been modified,\ndo you want to save them before closing ?"]
] == {yes}} then {
if {![$actualProject pale_save]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to write to file:\n\"%s\"" [$actualProject pale_get_scenario_filename]]
}
}
}
# Create file selection dialog
catch {delete object ::fsd}
KIFSD::FSD ::fsd \
-title [mc "Open file - Virtual HW - MCU 8051 IDE"] \
-directory [$actualProject cget -projectPath] \
-defaultmask 0 -multiple 0 -filetypes [list \
[list [mc "All relevant"] {*.{vhw,vhc}}] \
[list [mc "Virtual HW"] {*.vhw}] \
[list [mc "VH component"] {*.vhc}] \
[list [mc "All files"] {*}] \
]
# Open file after press of OK button
::fsd setokcmd {
set filename [::fsd get]
if {[${::X::actualProject} pale_open_scenario $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to read file:\n\"%s\"" $filename]
} else {
::X::recent_files_add 2 $filename
}
}
# activate the dialog
::fsd activate
}
## Import virtual hardware file
# @return void
proc __load_VHW {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Create file selection dialog
catch {delete object ::fsd}
KIFSD::FSD ::fsd \
-title [mc "Load file - Virtual HW - MCU 8051 IDE"] \
-directory [$actualProject cget -projectPath] \
-defaultmask 0 -multiple 1 -filetypes [list \
[list [mc "All relevant"] {*.{vhw,vhc}}] \
[list [mc "Virtual HW"] {*.vhw}] \
[list [mc "VH component"] {*.vhc}] \
[list [mc "All files"] {*}] \
]
# Open file after press of OK button
::fsd setokcmd {
foreach filename [::fsd get] {
if {[${::X::actualProject} pale_load_scenarion $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to read file:\n\"%s\"" $filename]
} else {
::X::recent_files_add 2 $filename
}
}
}
# Activate the dialog
::fsd activate
}
## Save virtual hardware scenario to a file
# @return void
proc __save_VHW {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
if {![$actualProject pale_save]} {
Sbar [mc "Unable to save Virtual HW connections"]
}
}
## Save virtual hardware scenario under a different filename
# @return void
proc __save_as_VHW {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Create file selection dialog
catch {delete object ::fsd}
KIFSD::FSD ::fsd \
-title [mc "Save file - Virtual HW - MCU 8051 IDE"] \
-directory [$actualProject cget -projectPath] \
-initialfile [$actualProject pale_get_scenario_filename]\
-defaultmask 0 -multiple 1 -filetypes [list \
[list [mc "Virtual HW"] {*.vhw}] \
[list [mc "All files"] {*}] \
]
# Open file after press of OK button
::fsd setokcmd {
set abort 0
set filename [::fsd get]
# Ask user for overwrite existing file
if {[file exists $filename]} {
if {[tk_messageBox \
-type yesno \
-icon question \
-parent . \
-title [mc "Overwrite file"] \
-message [mc "A file name '%s' already exists. Do you want to overwrite it ?" [file tail $filename]]
] != {yes}
} then {
set abort 1
}
}
if {!$abort} {
if {![${::X::actualProject} pale_save_as $filename]} {
tk_messageBox \
-parent . \
-type ok \
-icon error \
-title [mc "IO Error"] \
-message [mc "Unable to save file:\n\"%s\"" $filename]
} else {
::X::recent_files_add 2 $filename
}
}
}
# Activate the dialog
::fsd activate
}
## Remove all virtual hardware and forget VHW filename
# @return void
proc __remove_all_VHW {} {
variable actualProject ;# Object: Current project
variable project_menu_locked ;# Bool: Indicates than there is at least one opened project
if {$project_menu_locked} {return}
# Ask user for comfirmation
if {[tk_messageBox \
-type yesno \
-icon question \
-parent . \
-title [mc "Are you sure ?"] \
-message [mc "Do you really want to remove all virtual hardware from the current simulation scenario ?"]
] != {yes}
} then {
return
}
$actualProject pale_forget_all
}
## Toggle full screen mode
# @return void
proc __toggle_fullscreen {} {
# Normal window
if {[wm attributes . -fullscreen]} {
if {[winfo exists .mainIconBar.fullscreen]} {
.mainIconBar.fullscreen configure -image ::ICONS::22::window_fullscreen
}
wm attributes . -fullscreen 0
# Full screen window
} else {
if {[winfo exists .mainIconBar.fullscreen]} {
.mainIconBar.fullscreen configure -image ::ICONS::22::window_nofullscreen
}
wm attributes . -fullscreen 1
}
# Without this help windows won't work properly on MS Windows
if {$::MICROSOFT_WINDOWS} {
after idle {
wm geometry . [wm geometry .]
}
}
# Restore position of bottom pane
after 300 {
foreach project ${::X::openedProjects} {
$project bottomNB_redraw_pane
}
}
}
## Invoke the special calculator
# @return void
proc __spec_calc {} {
variable spec_calc_objects ;# List: All special calculator objects
lappend spec_calc_objects [SpecCalc #auto]
}
## Invoke RS232/UART debugger
# @return void
proc __rs232debugger {} {
variable rs232debugger_objects ;# List: All RS232 Debugger objects
lappend rs232debugger_objects [RS232Debugger #auto]
}
## Invoke a functional diagram of the given type
# @parm Int type -
# @return void
proc __functional_diagram {type} {
}
## Open arbitrary URI in user preffered application
# @parm String uri -- URI to open
# @return void
proc open_uri {uri} {
# On Linux and similars systems we use "xdg-open"
if {!$::MICROSOFT_WINDOWS} {
catch {
exec -- xdg-open $uri &
}
# On MS Windows we use its buildin command "start"
} else {
catch {
exec -- "cmd" "/c" "start [regsub -all {[^/\\]+\s[^/\\]*} $uri {"&"}]" &
}
}
}
## Open project web page in user preferred browser
# @return void
proc __web_page {} {
open_uri {http://mcu8051ide.sourceforge.net}
}
## Open web page for reporting bugs in user preferred browser
# @return void
proc __bug_report {} {
open_uri {http://sourceforge.net/tracker/?group_id=185864&atid=914981}
}
## Open handbook in user preferred PDF reader
# @return void
proc __handbook {} {
if {[file exists "${::INSTALLATION_DIR}/doc/handbook/mcu8051ide.${::GLOBAL_CONFIG(language)}.pdf"]} {
open_uri "${::INSTALLATION_DIR}/doc/handbook/mcu8051ide.${::GLOBAL_CONFIG(language)}.pdf"
} else {
open_uri "${::INSTALLATION_DIR}/doc/handbook/mcu8051ide.en.pdf"
}
}
## Open web page with SDCC manual in user preferred browser
# @return void
proc __sdcc_manual {} {
open_uri {http://sdcc.sourceforge.net/doc/sdccman.html}
}
## Open web page with ASEM-51 manual in user preferred browser
# @return void
proc __asem51_manual {} {
open_uri {http://plit.de/asem-51/docs.htm}
}
## Open interactive 8051 instruction table
# @return void
proc __table_of_instructions {} {
variable table_of_instructions_object ;# Object: Interactive 8051 instruction table
if {$table_of_instructions_object != {}} {
if {[$table_of_instructions_object is_visible]} {
$table_of_instructions_object raise_window
} else {
$table_of_instructions_object restore_window
}
} else {
set table_of_instructions_object [TableOfInstructions #auto]
}
}
## Make sure that there are no help windows visible
# @return void
proc remove_all_help_windows {} {
variable openedProjects ;# List of opened projects (Object references)
foreach project $openedProjects {
$project file_details_win_hide
}
::Editor::close_completion_popup_window_NOW
close_project_details
help_window_hide
}
## Perform secure send command
# Secure means that it will not crash or something like that in case of any errors.
# But instead it will popup an error message to the user (Tk dialog).
# @parm List args - Arguments for the send command
# @return void
proc secure_send args {
if {[catch {
eval "send $args"
} result]} then {
puts stderr "Unknown IO Error :: $result"
return 1
} else {
return 1
}
}
proc __d52 {} {
variable critical_procedure_in_progress ;# Bool: Disables procedures which takes a long time
if {$critical_procedure_in_progress} {return}
# Create dialog window
set win [toplevel .d52_open_dialog -class {Disassemble with D52} -bg ${::COMMON_BG_COLOR}]
set mainframe [frame $win.frame]
# Label, Entry and Button "Input file"
grid [Label $mainframe.lbl_input \
-text [mc "Input file"] \
-helptext [mc "File to disassemble"] \
] -column 1 -row 1 -sticky w
grid [ttk::entry $mainframe.entry_input \
-textvariable X::input_file \
-width 50 \
] -column 2 -row 1 -sticky we
DynamicHelp::add $mainframe.entry_input -text [mc "File to disassemble"]
grid [ttk::button $mainframe.button_select_input_file \
-image ::ICONS::16::fileopen \
-takefocus 0 \
-style Flat.TButton \
-command {
# Invoke file selection dialog
X::select_input_output 1 {{hex,ihx}} .d52_open_dialog
} \
] -column 3 -row 1 -sticky e
DynamicHelp::add $mainframe.button_select_input_file \
-text [mc "Invoke dialog to select input file"]
# Create separator
grid [ttk::separator $mainframe.separator \
-orient horizontal \
] -column 1 -columnspan 3 -row 2 -sticky we -pady 10
# Create buttons "Ok" and "Cancel"
set button_frame [frame $mainframe.button_frame]
pack [ttk::button $button_frame.button_ok \
-text [mc "Ok"] \
-command {X::d52_OK} \
-compound left \
-image ::ICONS::16::ok \
] -side left -padx 5
pack [ttk::button $button_frame.button_cancel \
-text [mc "Cancel"] \
-command {X::d52_CANCEL} \
-compound left \
-image ::ICONS::16::button_cancel \
] -side left -padx 5
grid $button_frame -column 1 -columnspan 3 -row 3
pack $mainframe -fill both -expand 1 -padx 5 -pady 5
# Event bindings (Enter == Ok; Escape == Cancel)
bind $win <KeyRelease-Return> {X::d52_OK; break}
bind $win <KeyRelease-KP_Enter> {X::d52_OK; break}
bind $win <KeyRelease-Escape> {X::d52_CANCEL; break}
# Set window attributes -- modal window
wm iconphoto $win ::ICONS::16::d52
wm title $win [mc "Disassemble with D52 - MCU 8051 IDE"]
wm minsize $win 450 70
wm resizable $win 0 0
wm protocol $win WM_DELETE_WINDOW {
X::d52_CANCEL
}
wm transient $win .
catch {grab $win}
raise $win
tkwait window $win
}
proc d52_CANCEL {} {
catch {
destroy .d52_open_dialog
}
}
proc d52_OK {} {
variable input_file ;# Input file
d52_CANCEL
}
}
# >>> File inclusion guard
}
# <<< File inclusion guard
|