Menu

[r6913]: / branches / wxsmith_addons / src / sdk / projectmanager.cpp  Maximize  Restore  History

Download this file

3029 lines (2688 with data), 98.6 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
/*
* This file is part of the Code::Blocks IDE and licensed under the GNU Lesser General Public License, version 3
* http://www.gnu.org/licenses/lgpl-3.0.html
*
* $Revision$
* $Id$
* $HeadURL$
*/
#include "sdk_precomp.h"
#ifndef CB_PRECOMP
#include <wx/datetime.h>
#include <wx/imaglist.h>
#include <wx/frame.h>
#include <wx/menu.h>
#include <wx/splitter.h>
#include <wx/filename.h>
#include "projectmanager.h" // class's header file
#include "sdk_events.h"
#include "manager.h"
#include "configmanager.h"
#include "cbproject.h"
#include "logmanager.h"
#include "pluginmanager.h"
#include "editormanager.h"
#include "uservarmanager.h"
#include "workspaceloader.h"
#include "cbworkspace.h"
#include "cbeditor.h"
#include <wx/dir.h>
#include "globals.h"
#include "cbexception.h" // for cbassert
#endif
#include <vector>
#include <algorithm>
#include "cbauibook.h"
#include <wx/busyinfo.h>
#include <wx/choicdlg.h>
#include <wx/filedlg.h>
#include <wx/progdlg.h>
#include <wx/textdlg.h>
#include <wx/tokenzr.h>
#include <wx/utils.h>
#include "incrementalselectlistdlg.h"
#include "filegroupsandmasks.h"
#include "projectsfilemasksdlg.h"
#include "projectdepsdlg.h"
#include "multiselectdlg.h"
#include "filefilters.h"
#include "confirmreplacedlg.h"
#include "projectfileoptionsdlg.h"
template<> ProjectManager* Mgr<ProjectManager>::instance = 0;
template<> bool Mgr<ProjectManager>::isShutdown = false;
// maximum number of items in "Open with" context menu
static const unsigned int MAX_OPEN_WITH_ITEMS = 20; // keep it in sync with below array!
static const int idOpenWith[] =
{
wxNewId(), wxNewId(), wxNewId(), wxNewId(), wxNewId(),
wxNewId(), wxNewId(), wxNewId(), wxNewId(), wxNewId(),
wxNewId(), wxNewId(), wxNewId(), wxNewId(), wxNewId(),
wxNewId(), wxNewId(), wxNewId(), wxNewId(), wxNewId(),
};
// special entry: force open with internal editor
static const int idOpenWithInternal = wxNewId();
// static
bool ProjectManager::s_CanShutdown = true;
int ID_ProjectManager = wxNewId();
int idMenuSetActiveProject = wxNewId();
int idMenuOpenFile = wxNewId();
int idMenuSaveProject = wxNewId();
int idMenuSaveFile = wxNewId();
int idMenuCloseProject = wxNewId();
int idMenuCloseFile = wxNewId();
int idMenuAddFilePopup = wxNewId();
int idMenuAddFilesRecursivelyPopup = wxNewId();
int idMenuAddFile = wxNewId();
int idMenuAddFilesRecursively = wxNewId();
int idMenuRemoveFolderFilesPopup = wxNewId();
int idMenuOpenFolderFilesPopup = wxNewId();
int idMenuRemoveFilePopup = wxNewId();
int idMenuRemoveFile = wxNewId();
int idMenuRenameFile = wxNewId();
int idMenuProjectNotes = wxNewId();
int idMenuProjectProperties = wxNewId();
int idMenuFileProperties = wxNewId();
int idMenuTreeProjectProperties = wxNewId();
int idMenuTreeFileProperties = wxNewId();
int idMenuGotoFile = wxNewId();
int idMenuExecParams = wxNewId();
int idMenuViewCategorize = wxNewId();
int idMenuViewUseFolders = wxNewId();
int idMenuViewFileMasks = wxNewId();
int idMenuNextProject = wxNewId();
int idMenuPriorProject = wxNewId();
int idMenuProjectTreeProps = wxNewId();
int idMenuProjectUp = wxNewId();
int idMenuProjectDown = wxNewId();
int idMenuViewCategorizePopup = wxNewId();
int idMenuViewUseFoldersPopup = wxNewId();
int idMenuTreeRenameWorkspace = wxNewId();
int idMenuTreeSaveWorkspace = wxNewId();
int idMenuTreeSaveAsWorkspace = wxNewId();
int idMenuTreeCloseWorkspace = wxNewId();
int idMenuAddVirtualFolder = wxNewId();
int idMenuDeleteVirtualFolder = wxNewId();
static const int idMenuFindFile = wxNewId();
static const int idNB = wxNewId();
static const int idNB_TabTop = wxNewId();
static const int idNB_TabBottom = wxNewId();
#ifndef __WXMSW__
/*
Under wxGTK, I have noticed that wxTreeCtrl is not sending a EVT_COMMAND_RIGHT_CLICK
event when right-clicking on the client area.
This is a "proxy" wxTreeCtrl descendant that handles this for us...
*/
class PrjTree : public wxTreeCtrl
{
public:
PrjTree(wxWindow* parent, int id) : wxTreeCtrl(parent, id, wxDefaultPosition, wxDefaultSize, wxTR_EDIT_LABELS | wxTR_DEFAULT_STYLE | wxNO_BORDER) {}
protected:
void OnRightClick(wxMouseEvent& event)
{
if(!this) return;
//Manager::Get()->GetLogManager()->DebugLog("OnRightClick");
int flags;
HitTest(wxPoint(event.GetX(), event.GetY()), flags);
if (flags & (wxTREE_HITTEST_ABOVE | wxTREE_HITTEST_BELOW | wxTREE_HITTEST_NOWHERE))
{
// "proxy" the call
wxCommandEvent e(wxEVT_COMMAND_RIGHT_CLICK, ID_ProjectManager);
wxPostEvent(GetParent(), e);
}
else
event.Skip();
}
DECLARE_EVENT_TABLE();
};
BEGIN_EVENT_TABLE(PrjTree, wxTreeCtrl)
EVT_RIGHT_DOWN(PrjTree::OnRightClick)
END_EVENT_TABLE()
#endif // !__WXMSW__
BEGIN_EVENT_TABLE(ProjectManager, wxEvtHandler)
EVT_TREE_BEGIN_DRAG(ID_ProjectManager, ProjectManager::OnTreeBeginDrag)
EVT_TREE_END_DRAG(ID_ProjectManager, ProjectManager::OnTreeEndDrag)
EVT_TREE_BEGIN_LABEL_EDIT(ID_ProjectManager, ProjectManager::OnBeginEditNode)
EVT_TREE_END_LABEL_EDIT(ID_ProjectManager, ProjectManager::OnEndEditNode)
EVT_TREE_ITEM_ACTIVATED(ID_ProjectManager, ProjectManager::OnProjectFileActivated)
EVT_TREE_ITEM_RIGHT_CLICK(ID_ProjectManager, ProjectManager::OnTreeItemRightClick)
EVT_TREE_KEY_DOWN(ID_ProjectManager, ProjectManager::OnKeyDown)
EVT_COMMAND_RIGHT_CLICK(ID_ProjectManager, ProjectManager::OnRightClick)
EVT_AUINOTEBOOK_TAB_RIGHT_UP(idNB, ProjectManager::OnTabContextMenu)
EVT_MENU_RANGE(idOpenWith[0], idOpenWith[MAX_OPEN_WITH_ITEMS - 1], ProjectManager::OnOpenWith)
EVT_MENU(idOpenWithInternal, ProjectManager::OnOpenWith)
EVT_MENU(idNB_TabTop, ProjectManager::OnTabPosition)
EVT_MENU(idNB_TabBottom, ProjectManager::OnTabPosition)
EVT_MENU(idMenuSetActiveProject, ProjectManager::OnSetActiveProject)
EVT_MENU(idMenuNextProject, ProjectManager::OnSetActiveProject)
EVT_MENU(idMenuPriorProject, ProjectManager::OnSetActiveProject)
EVT_MENU(idMenuProjectUp, ProjectManager::OnSetActiveProject)
EVT_MENU(idMenuProjectDown, ProjectManager::OnSetActiveProject)
EVT_MENU(idMenuTreeRenameWorkspace, ProjectManager::OnRenameWorkspace)
EVT_MENU(idMenuTreeSaveWorkspace, ProjectManager::OnSaveWorkspace)
EVT_MENU(idMenuTreeSaveAsWorkspace, ProjectManager::OnSaveAsWorkspace)
EVT_MENU(idMenuTreeCloseWorkspace, ProjectManager::OnCloseWorkspace)
EVT_MENU(idMenuAddVirtualFolder, ProjectManager::OnAddVirtualFolder)
EVT_MENU(idMenuDeleteVirtualFolder, ProjectManager::OnDeleteVirtualFolder)
EVT_MENU(idMenuAddFile, ProjectManager::OnAddFileToProject)
EVT_MENU(idMenuAddFilesRecursively, ProjectManager::OnAddFilesToProjectRecursively)
EVT_MENU(idMenuRemoveFile, ProjectManager::OnRemoveFileFromProject)
EVT_MENU(idMenuAddFilePopup, ProjectManager::OnAddFileToProject)
EVT_MENU(idMenuAddFilesRecursivelyPopup, ProjectManager::OnAddFilesToProjectRecursively)
EVT_MENU(idMenuRemoveFolderFilesPopup, ProjectManager::OnRemoveFileFromProject)
EVT_MENU(idMenuOpenFolderFilesPopup, ProjectManager::OnOpenFolderFiles)
EVT_MENU(idMenuRemoveFilePopup, ProjectManager::OnRemoveFileFromProject)
EVT_MENU(idMenuRenameFile, ProjectManager::OnRenameFile)
EVT_MENU(idMenuSaveProject, ProjectManager::OnSaveProject)
EVT_MENU(idMenuSaveFile, ProjectManager::OnSaveFile)
EVT_MENU(idMenuCloseProject, ProjectManager::OnCloseProject)
EVT_MENU(idMenuCloseFile, ProjectManager::OnCloseFile)
EVT_MENU(idMenuOpenFile, ProjectManager::OnOpenFile)
EVT_MENU(idMenuProjectNotes, ProjectManager::OnNotes)
EVT_MENU(idMenuProjectProperties, ProjectManager::OnProperties)
EVT_MENU(idMenuFileProperties, ProjectManager::OnProperties)
EVT_MENU(idMenuTreeProjectProperties, ProjectManager::OnProperties)
EVT_MENU(idMenuTreeFileProperties, ProjectManager::OnProperties)
EVT_MENU(idMenuGotoFile, ProjectManager::OnGotoFile)
EVT_MENU(idMenuExecParams, ProjectManager::OnExecParameters)
EVT_MENU(idMenuViewCategorize, ProjectManager::OnViewCategorize)
EVT_MENU(idMenuViewCategorizePopup, ProjectManager::OnViewCategorize)
EVT_MENU(idMenuViewUseFolders, ProjectManager::OnViewUseFolders)
EVT_MENU(idMenuViewUseFoldersPopup, ProjectManager::OnViewUseFolders)
EVT_MENU(idMenuViewFileMasks, ProjectManager::OnViewFileMasks)
EVT_MENU(idMenuFindFile, ProjectManager::OnFindFile)
EVT_IDLE(ProjectManager::OnIdle)
END_EVENT_TABLE()
// class constructor
ProjectManager::ProjectManager()
: m_pTree(0),
m_pWorkspace(0),
m_TreeCategorize(false),
m_TreeUseFolders(true),
m_TreeFreezeCounter(0),
m_IsLoadingProject(false),
m_IsLoadingWorkspace(false),
m_IsClosingProject(false),
m_IsClosingWorkspace(false),
m_InitialDir(_T("")),
m_isCheckingForExternallyModifiedProjects(false),
m_CanSendWorkspaceChanged(false)
{
m_pNotebook = new cbAuiNotebook(Manager::Get()->GetAppWindow(), idNB, wxDefaultPosition, wxDefaultSize, wxAUI_NB_WINDOWLIST_BUTTON);
if (Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/project_tabs_bottom"), false))
m_pNotebook->SetWindowStyleFlag(m_pNotebook->GetWindowStyleFlag() | wxAUI_NB_BOTTOM);
m_InitialDir=wxFileName::GetCwd();
m_pActiveProject = 0L;
m_pProjectToActivate = 0L;
m_pProjects = new ProjectsArray;
m_pProjects->Clear();
// m_pPanel = new wxPanel(parent, wxID_ANY, wxDefaultPosition, wxDefaultSize, wxTAB_TRAVERSAL | wxCLIP_CHILDREN);
InitPane();
m_pFileGroups = new FilesGroupsAndMasks;
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("project_manager"));
m_TreeCategorize = cfg->ReadBool(_T("/categorize_tree"), true);
m_TreeUseFolders = cfg->ReadBool(_T("/use_folders"), true);
RebuildTree();
// register event sinks
Manager::Get()->RegisterEventSink(cbEVT_APP_STARTUP_DONE, new cbEventFunctor<ProjectManager, CodeBlocksEvent>(this, &ProjectManager::OnAppDoneStartup));
// Event handling. This must be THE LAST THING activated on startup.
// Constructors and destructors must always follow the LIFO rule:
// Last in, first out.
Manager::Get()->GetAppWindow()->PushEventHandler(this);
}
// class destructor
ProjectManager::~ProjectManager()
{
// this is a core manager, so it is removed when the app is shutting down.
// in this case, the app has already un-hooked us, so no need to do it ourselves...
// Manager::Get()->GetAppWindow()->RemoveEventHandler(this);
delete m_pWorkspace;
m_pWorkspace = 0;
int count = m_pProjects->GetCount();
for (int i = 0; i < count; ++i)
{
cbProject* project = m_pProjects->Item(i);
if (project)
delete project;
}
m_pProjects->Clear();
delete m_pProjects;m_pProjects = 0;
delete m_pImages;m_pImages = 0;
delete m_pFileGroups;m_pFileGroups = 0;
m_pNotebook->Destroy();
}
void ProjectManager::InitPane()
{
if(Manager::isappShuttingDown())
return;
if(m_pTree)
return;
BuildTree();
m_pNotebook->AddPage(m_pTree, _("Projects"));
}
int ProjectManager::WorkspaceIconIndex(bool read_only)
{
if (read_only)
return (int)fvsWorkspaceReadOnly;
return (int)fvsWorkspace;
}
int ProjectManager::ProjectIconIndex(bool read_only)
{
if (read_only)
return (int)fvsProjectReadOnly;
return (int)fvsProject;
}
int ProjectManager::FolderIconIndex()
{
return (int)fvsFolder;
}
int ProjectManager::VirtualFolderIconIndex()
{
return (int)fvsVirtualFolder;
}
void ProjectManager::BuildTree()
{
#ifndef __WXMSW__
m_pTree = new PrjTree(m_pNotebook, ID_ProjectManager);
#else
m_pTree = new wxTreeCtrl(m_pNotebook, ID_ProjectManager, wxDefaultPosition, wxDefaultSize, wxTR_EDIT_LABELS | wxTR_DEFAULT_STYLE | wxNO_BORDER);
#endif
static const wxString imgs[] = {
// NOTE: Keep in sync with FileVisualState in globals.h!
// The following are related to (editable, source-) file states
_T("file.png"), // fvsNormal
_T("file-missing.png"), // fvsMissing,
_T("file-modified.png"), // fvsModified,
_T("file-readonly.png"), // fvsReadOnly,
// The following are related to version control systems (vc)
_T("rc-file-added.png"), // fvsVcAdded,
_T("rc-file-conflict.png"), // fvsVcConflict,
_T("rc-file-missing.png"), // fvsVcMissing,
_T("rc-file-modified.png"), // fvsVcModified,
_T("rc-file-outofdate.png"), // fvsVcOutOfDate,
_T("rc-file-uptodate.png"), // fvsVcUpToDate,
_T("rc-file-requireslock.png"), // fvsVcRequiresLock,
_T("rc-file-external.png"), // fvsVcExternal,
_T("rc-file-gotlock.png"), // fvsVcGotLock,
_T("rc-file-lockstolen.png"), // fvsVcLockStolen,
_T("rc-file-mismatch.png"), // fvsVcMismatch,
_T("rc-file-noncontrolled.png"), // fvsVcNonControlled,
// The following are related to C::B workspace/project/folder/virtual
_T("workspace.png"), // fvsWorkspace, WorkspaceIconIndex()
_T("workspace-readonly.png"), // fvsWorkspaceReadOnly, WorkspaceIconIndex(true)
_T("project.png"), // fvsProject, ProjectIconIndex()
_T("project-readonly.png"), // fvsProjectReadOnly, ProjectIconIndex(true)
_T("folder_open.png"), // fvsFolder, FolderIconIndex()
_T("vfolder_open.png"), // fvsVirtualFolder, VirtualFolderIconIndex()
wxEmptyString
};
wxBitmap bmp;
m_pImages = new wxImageList(16, 16);
wxString prefix = ConfigManager::ReadDataPath() + _T("/images/");
int i = 0;
while (!imgs[i].IsEmpty())
{
// cbMessageBox(wxString::Format(_T("%d: %s"), i, wxString(prefix + imgs[i]).c_str()));
bmp = cbLoadBitmap(prefix + imgs[i], wxBITMAP_TYPE_PNG); // workspace
m_pImages->Add(bmp);
++i;
}
m_pTree->SetImageList(m_pImages);
// // make sure tree is not "frozen"
// UnfreezeTree(true);
}
void ProjectManager::CreateMenu(wxMenuBar* menuBar)
{
/* TODO (mandrav#1#): Move menu items from main.cpp, here */
if (menuBar)
{
int pos = menuBar->FindMenu(_("Sea&rch"));
wxMenu* menu = menuBar->GetMenu(pos);
if (menu)
menu->Append(idMenuGotoFile, _("Goto file...\tAlt-G"));
pos = menuBar->FindMenu(_("&File"));
menu = menuBar->GetMenu(pos);
if (menu)
{
menu->Insert(menu->GetMenuItemCount() - 1, idMenuFileProperties, _("Properties..."));
menu->Insert(menu->GetMenuItemCount() - 1, wxID_SEPARATOR, _T("")); // instead of AppendSeparator();
}
pos = menuBar->FindMenu(_("&Project"));
menu = menuBar->GetMenu(pos);
if (menu)
{
if (menu->GetMenuItemCount())
menu->AppendSeparator();
menu->Append(idMenuAddFile, _("Add files..."), _("Add files to the project"));
menu->Append(idMenuAddFilesRecursively, _("Add files recursively..."), _("Add files recursively to the project"));
menu->Append(idMenuRemoveFile, _("Remove files..."), _("Remove files from the project"));
/* FIXME (mandrav#1#): Move this submenu creation in a function.
It is duplicated in ShowMenu() */
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("project_manager"));
wxMenu* treeprops = new wxMenu;
treeprops->Append(idMenuProjectUp, _("Move project up\tCtrl-Shift-Up"), _("Move project up in project tree"));
treeprops->Append(idMenuProjectDown, _("Move project down\tCtrl-Shift-Down"), _("Move project down in project tree"));
treeprops->AppendSeparator();
treeprops->Append(idMenuPriorProject, _("Activate prior project\tAlt-F5"), _("Activate prior project in open projects list"));
treeprops->Append(idMenuNextProject, _("Activate next project\tAlt-F6"), _("Activate next project in open projects list"));
treeprops->AppendSeparator();
treeprops->AppendCheckItem(idMenuViewCategorize, _("Categorize by file types"));
treeprops->AppendCheckItem(idMenuViewUseFolders, _("Display folders as on disk"));
treeprops->Check(idMenuViewCategorize, cfg->ReadBool(_T("/categorize_tree"), true));
treeprops->Check(idMenuViewUseFolders, cfg->ReadBool(_T("/use_folders"), true));
treeprops->Append(idMenuViewFileMasks, _("Edit file types && categories..."));
menu->AppendSeparator();
menu->Append(idMenuProjectTreeProps, _("Project tree"), treeprops);
menu->Append(idMenuExecParams, _("Set &programs' arguments..."), _("Set execution parameters for the targets of this project"));
menu->Append(idMenuProjectNotes, _("Notes..."));
menu->Append(idMenuProjectProperties, _("Properties..."));
}
}
}
void ProjectManager::ReleaseMenu(wxMenuBar* /*menuBar*/)
{
}
wxString ProjectManager::GetDefaultPath()
{
wxString path = Manager::Get()->GetConfigManager(_T("project_manager"))->Read(_T("default_path"), wxEmptyString);
if (!path.IsEmpty() && path.Last() != _T('/') && path.Last() != _T('\\'))
path.Append(wxFILE_SEP_PATH);
return path;
}
void ProjectManager::SetDefaultPath(const wxString& path)
{
Manager::Get()->GetConfigManager(_T("project_manager"))->Write(_T("default_path"), path);
}
bool ProjectManager::IsProjectStillOpen(cbProject* project)
{
int count = m_pProjects->GetCount();
for (int i = 0; i < count; ++i)
{
if (m_pProjects->Item(i) == project)
return true;
}
return false;
}
void ProjectManager::SetProject(cbProject* project, bool refresh)
{
if (project != m_pActiveProject)
{
// Only set worksapce as modified, if there was an active project before
if (m_pWorkspace && m_pActiveProject)
m_pWorkspace->SetModified(true);
}
else
return; // already active
if (m_pActiveProject)
m_pTree->SetItemBold(m_pActiveProject->GetProjectNode(), false);
m_pActiveProject = project;
if (m_pActiveProject)
{
wxTreeItemId tid = m_pActiveProject->GetProjectNode();
if (tid)
m_pTree->SetItemBold(m_pActiveProject->GetProjectNode(), true);
}
if (refresh)
RebuildTree();
if (m_pActiveProject)
m_pTree->EnsureVisible(m_pActiveProject->GetProjectNode());
CodeBlocksEvent event(cbEVT_PROJECT_ACTIVATE);
event.SetProject(m_pActiveProject);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
void ProjectManager::ShowMenu(wxTreeItemId id, const wxPoint& pt)
{
if ( !id.IsOk() )
return;
wxString caption;
wxMenu menu;
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(id);
bool is_vfolder = ftd && ftd->GetKind() == FileTreeData::ftdkVirtualFolder;
/* Following code will check for currently compiling project.
* If it finds the selected is project is currently compiling,
* then it will disable some of the options */
bool PopUpMenuOption = true;
ProjectsArray* Projects = Manager::Get()->GetProjectManager()->GetProjects();
if (Projects && ftd
&& (ftd->GetKind() == FileTreeData::ftdkProject
|| ftd->GetKind() == FileTreeData::ftdkFile
|| ftd->GetKind() == FileTreeData::ftdkFolder))
{
int Count = Projects->GetCount();
cbProject* ProjInTree = ftd->GetProject();
for (int i = 0; i < Count; ++i)
{
cbProject* CurProject = Projects->Item(i);
if (ProjInTree->GetTitle().IsSameAs(CurProject->GetTitle()))
{
if(CurProject->GetCurrentlyCompilingTarget())
{
PopUpMenuOption = false;
break;
}
}
}
}
// if it is not the workspace, add some more options
if (ftd)
{
// if it is a project...
if (ftd->GetKind() == FileTreeData::ftdkProject)
{
if (ftd->GetProject() != m_pActiveProject)
menu.Append(idMenuSetActiveProject, _("Activate project"));
menu.Append(idMenuSaveProject, _("Save project"));
menu.Enable(idMenuSaveProject, PopUpMenuOption);
menu.Append(idMenuCloseProject, _("Close project"));
menu.Enable(idMenuCloseProject, PopUpMenuOption);
menu.AppendSeparator();
menu.Append(idMenuAddFilePopup, _("Add files..."));
menu.Enable(idMenuAddFilePopup, PopUpMenuOption);
menu.Append(idMenuAddFilesRecursivelyPopup, _("Add files recursively..."));
menu.Enable(idMenuAddFilesRecursivelyPopup, PopUpMenuOption);
menu.Append(idMenuRemoveFile, _("Remove files..."));
menu.Enable(idMenuRemoveFile, PopUpMenuOption);
menu.AppendSeparator();
menu.Append(idMenuFindFile, _("Find file..."));
menu.Enable(idMenuFindFile, PopUpMenuOption);
menu.AppendSeparator();
menu.Append(idMenuAddVirtualFolder, _("Add new virtual folder..."));
if (is_vfolder)
menu.Append(idMenuDeleteVirtualFolder, _("Delete this virtual folder..."));
}
// if it is a file...
else if (ftd->GetKind() == FileTreeData::ftdkFile)
{
// selected project file
ProjectFile* pf = ftd->GetProjectFile();
// is it already open in the editor?
EditorBase* ed = Manager::Get()->GetEditorManager()->IsOpen(pf->file.GetFullPath());
if (ed)
{
// is it already active?
bool active = Manager::Get()->GetEditorManager()->GetActiveEditor() == ed;
if (!active)
{
caption.Printf(_("Switch to %s"), m_pTree->GetItemText(id).c_str());
menu.Append(idMenuOpenFile, caption);
}
caption.Printf(_("Save %s"), m_pTree->GetItemText(id).c_str());
menu.Append(idMenuSaveFile, caption);
caption.Printf(_("Close %s"), m_pTree->GetItemText(id).c_str());
menu.Append(idMenuCloseFile, caption);
}
else
{
caption.Printf(_("Open %s"), m_pTree->GetItemText(id).c_str());
menu.Append(idMenuOpenFile, caption);
}
// add "Open with" menu
wxMenu* openWith = new wxMenu;
PluginsArray mimes = Manager::Get()->GetPluginManager()->GetMimeOffers();
for (unsigned int i = 0; i < mimes.GetCount() && i < MAX_OPEN_WITH_ITEMS; ++i)
{
cbMimePlugin* plugin = (cbMimePlugin*)mimes[i];
if (plugin && plugin->CanHandleFile(m_pTree->GetItemText(id)))
{
const PluginInfo* info = Manager::Get()->GetPluginManager()->GetPluginInfo(plugin);
openWith->Append(idOpenWith[i], info ? info->title : wxString(_("<Unknown plugin>")));
}
}
openWith->AppendSeparator();
openWith->Append(idOpenWithInternal, _("Internal editor"));
menu.Append(wxID_ANY, _("Open with"), openWith);
if(pf->GetFileState() == fvsNormal && !Manager::Get()->GetEditorManager()->IsOpen(pf->file.GetFullPath()))
{
menu.AppendSeparator();
menu.Append(idMenuRenameFile, _("Rename file..."));
menu.Enable(idMenuRenameFile, PopUpMenuOption);
}
menu.AppendSeparator();
menu.Append(idMenuRemoveFilePopup, _("Remove file from project"));
menu.Enable(idMenuRemoveFilePopup, PopUpMenuOption);
}
// if it is a folder...
else if (ftd->GetKind() == FileTreeData::ftdkFolder)
{
menu.Append(idMenuAddFilePopup, _("Add files..."));
menu.Enable(idMenuAddFilePopup, PopUpMenuOption);
menu.Append(idMenuAddFilesRecursivelyPopup, _("Add files recursively..."));
menu.Enable(idMenuAddFilesRecursivelyPopup, PopUpMenuOption);
menu.AppendSeparator();
menu.Append(idMenuRemoveFile, _("Remove files..."));
menu.Enable(idMenuRemoveFile, PopUpMenuOption);
menu.AppendSeparator();
menu.Append(idMenuFindFile, _("Find file..."));
menu.Enable(idMenuFindFile, PopUpMenuOption);
menu.AppendSeparator();
wxFileName f(ftd->GetFolder());
f.MakeRelativeTo(ftd->GetProject()->GetCommonTopLevelPath());
menu.Append(idMenuRemoveFolderFilesPopup, wxString::Format(_("Remove %s*"), f.GetFullPath().c_str()));
menu.Enable(idMenuRemoveFolderFilesPopup, PopUpMenuOption);
menu.Append(idMenuOpenFolderFilesPopup, wxString::Format(_("Open %s*"), f.GetFullPath().c_str()));
menu.Enable(idMenuOpenFolderFilesPopup, PopUpMenuOption);
}
// if it is a virtual folder
else if (is_vfolder)
{
menu.Append(idMenuAddVirtualFolder, _("Add new virtual folder..."));
menu.Append(idMenuDeleteVirtualFolder, _("Delete this virtual folder"));
menu.AppendSeparator();
menu.Append(idMenuRemoveFile, _("Remove files..."));
menu.Append(idMenuRemoveFolderFilesPopup, wxString::Format(_("Remove %s*"), ftd->GetFolder().c_str()));
menu.Append(idMenuOpenFolderFilesPopup, wxString::Format(_("Open %s*"), ftd->GetFolder().c_str()));
menu.AppendSeparator();
menu.Append(idMenuFindFile, _("Find file..."));
menu.Enable(idMenuFindFile, PopUpMenuOption);
}
// ask any plugins to add items in this menu
Manager::Get()->GetPluginManager()->AskPluginsForModuleMenu(mtProjectManager, &menu, ftd);
// more project options
if (ftd->GetKind() == FileTreeData::ftdkProject)
{
// project
/* FIXME (mandrav#1#): Move this submenu creation in a function.
It is duplicated in CreateMenu() */
menu.AppendSeparator();
ConfigManager *cfg = Manager::Get()->GetConfigManager(_T("project_manager"));
wxMenu* treeprops = new wxMenu;
treeprops->Append(idMenuProjectUp, _("Move project up\tCtrl-Shift-Up"), _("Move project up in project tree"));
treeprops->Append(idMenuProjectDown, _("Move project down\tCtrl-Shift-Down"), _("Move project down in project tree"));
treeprops->AppendSeparator();
treeprops->Append(idMenuPriorProject, _("Activate prior project\tAlt-F5"), _("Activate prior project in open projects list"));
treeprops->Append(idMenuNextProject, _("Activate next project\tAlt-F6"), _("Activate next project in open projects list"));
treeprops->AppendSeparator();
/* NOTE (mandrav#1#): If this is moved in a new function,\
it differs from the block currently in CreateMenu() by the following two IDs */
treeprops->AppendCheckItem(idMenuViewCategorizePopup, _("Categorize by file types"));
treeprops->AppendCheckItem(idMenuViewUseFoldersPopup, _("Display folders as on disk"));
treeprops->Check(idMenuViewCategorizePopup, cfg->ReadBool(_T("/categorize_tree"), true));
treeprops->Check(idMenuViewUseFoldersPopup, cfg->ReadBool(_T("/use_folders"), true));
treeprops->Append(idMenuViewFileMasks, _("Edit file types && categories..."));
menu.Append(idMenuProjectTreeProps, _("Project tree"), treeprops);
menu.Append(idMenuTreeProjectProperties, _("Properties..."));
menu.Enable(idMenuTreeProjectProperties, PopUpMenuOption);
}
// more file options
else if (ftd->GetKind() == FileTreeData::ftdkFile)
{
menu.AppendSeparator();
menu.Append(idMenuTreeFileProperties, _("Properties..."));
}
}
else if (!ftd && m_pWorkspace)
{
menu.Append(idMenuTreeRenameWorkspace, _("Rename workspace..."));
menu.AppendSeparator();
menu.Append(idMenuTreeSaveWorkspace, _("Save workspace"));
menu.Append(idMenuTreeSaveAsWorkspace, _("Save workspace as..."));
menu.AppendSeparator();
menu.Append(idMenuFindFile, _("Find file..."));
menu.AppendSeparator();
menu.Append(idMenuTreeCloseWorkspace, _("Close workspace"));
}
if (menu.GetMenuItemCount() != 0)
m_pTree->PopupMenu(&menu, pt);
}
cbProject* ProjectManager::IsOpen(const wxString& filename)
{
if (filename.IsEmpty())
return 0L;
wxString realFile = realpath(filename);
int count = m_pProjects->GetCount();
for (int i = 0; i < count; ++i)
{
cbProject* project = m_pProjects->Item(i);
if(project)
{
#ifdef __WXMSW__
// MS Windows Filenames are case-insensitive, we have to
// avoid opening the same project if the files are only
// different in upper/lowercase.
if(project->GetFilename().Lower().Matches(realFile.Lower()))
return project;
#else
if (project->GetFilename().Matches(realFile))
return project;
#endif
}
}
return 0L;
}
wxMenu* ProjectManager::GetProjectMenu()
{
wxMenu* result = 0L;
do
{
wxFrame* frame = Manager::Get()->GetAppFrame();
if(!frame)
break;
wxMenuBar* mb = frame->GetMenuBar();
if(!mb)
break;
result = mb->GetMenu(mb->FindMenu(_("&Project")));
break;
}while(false);
return result;
}
cbProject* ProjectManager::LoadProject(const wxString& filename, bool activateIt)
{
cbProject* result = 0;
if (!wxFileExists(filename) || !BeginLoadingProject())
{
return 0;
}
// "Try" block (loop which only gets executed once)
// These blocks are extremely useful in constructs that need
// premature exits. Instead of having multiple return points,
// multiple return values and/or gotos,
// you just break out of the loop (which only gets executed once) to exit.
do
{
cbProject* project = IsOpen(filename);
if (project)
{
// already open
result = project;
break;
}
if (FileTypeOf(filename) == ftCodeBlocksProject)
{
project = new cbProject(filename);
// We need to do this because creating cbProject allows the app to be
// closed in the middle of the operation. So the class destructor gets
// called in the middle of a method call.
if (!project->IsLoaded())
{
delete project;
break;
}
result = project;
}
else // !ftCodeBlocksProject
{
// the plugin handler should call begin/end on its own...
EndLoadingProject(0);
cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
if (plugin)
{
plugin->OpenFile(filename);
}
}
break;
} while(false);
// we 're done
EndLoadingProject(result);
if (activateIt)
{
if (m_IsLoadingWorkspace)
{
// postpone call of SetProject() until EndLoadingWorkspace() is called
// (we must call RebuildTree() before SetProject() is called)
m_pProjectToActivate = result;
}
else
SetProject(result, true);
}
return result;
}
cbProject* ProjectManager::NewProject(const wxString& filename)
{
if (!filename.IsEmpty() && wxFileExists(filename))
{
if (cbMessageBox(_("Project file already exists.\nAre you really sure you want to OVERWRITE it?"),
_("Confirmation"), wxYES_NO | wxICON_QUESTION) == wxID_YES)
{
if (!wxRemoveFile(filename))
{
cbMessageBox(_("Couldn't remove the old project file to create the new one.\nThe file might be read-only?!"),
_("Error"), wxICON_WARNING);
return 0;
}
}
else
return 0;
}
cbProject* prj = IsOpen(filename);
if (!prj && BeginLoadingProject())
{
prj = new cbProject(filename);
EndLoadingProject(prj);
SetProject(prj, !m_IsLoadingWorkspace);
}
return prj;
}
bool ProjectManager::QueryCloseAllProjects()
{
unsigned int i;
if (!Manager::Get()->GetEditorManager()->QueryCloseAll())
return false;
for(i=0;i<m_pProjects->GetCount();i++)
{
// Ask for saving modified projects. However,
// we already asked to save projects' files;
// do not ask again
if(!QueryCloseProject(m_pProjects->Item(i),true))
return false;
}
return true;
}
bool ProjectManager::QueryCloseProject(cbProject *proj,bool dontsavefiles)
{
if(!proj)
return true;
if(proj->GetCurrentlyCompilingTarget())
return false;
if(!dontsavefiles)
if(!proj->QueryCloseAllFiles())
return false;
if (proj->GetModified() && !Manager::IsBatchBuild())
{
wxString msg;
msg.Printf(_("Project '%s' is modified...\nDo you want to save the changes?"), proj->GetTitle().c_str());
switch (cbMessageBox(msg, _("Save project"), wxICON_QUESTION | wxYES_NO | wxCANCEL))
{
case wxID_YES: if (!proj->Save()) return false;
case wxID_NO: break;
case wxID_CANCEL: return false;
}
}
return true;
} // end of QueryCloseProject
bool ProjectManager::CloseAllProjects(bool dontsave)
{
if(!dontsave)
if(!QueryCloseAllProjects())
return false;
FreezeTree();
m_IsClosingProject = true;
while (m_pProjects->GetCount() != 0)
{
// Commented it by Heromyth
// if (!CloseActiveProject(true))
if (!CloseProject(m_pProjects->Item(0), true, false))
{
UnfreezeTree(true);
m_IsClosingProject = false;
return false;
}
}
if (!Manager::IsAppShuttingDown())
RebuildTree();
UnfreezeTree(true);
if(!m_InitialDir.IsEmpty())
wxFileName::SetCwd(m_InitialDir);
m_IsClosingProject = false;
WorkspaceChanged();
return true;
}
bool ProjectManager::CloseProject(cbProject* project, bool dontsave, bool refresh)
{
if (!project)
return true;
if(project->GetCurrentlyCompilingTarget())
return false;
if(!dontsave)
if(!QueryCloseProject(project))
return false;
bool wasActive = project == m_pActiveProject;
if (wasActive)
m_pActiveProject = 0L;
int index = m_pProjects->Index(project);
if (index == wxNOT_FOUND)
return false;
// CloseProject is also called by CloseAllProjects, so we need to save
// the state of m_IsClosingProject.
bool isClosingOtherProjects = m_IsClosingProject;
m_IsClosingProject = true;
Manager::Get()->GetEditorManager()->UpdateProjectFiles(project);
// project->SaveTreeState(m_pTree);
project->SaveLayout();
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
RemoveProjectFromAllDependencies(project);
m_pProjects->Remove(project);
// moved here from cbProject's destructor, because by then
// the list of project files was already emptied...
CodeBlocksEvent event(cbEVT_PROJECT_CLOSE);
event.SetProject(project);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
project->CloseAllFiles(true);
if (refresh)
m_pTree->Delete(project->GetProjectNode());
if (wasActive && m_pProjects->GetCount())
SetProject(m_pProjects->Item(0), refresh);
delete project;
// if (refresh)
// RebuildTree();
if(!m_InitialDir.IsEmpty()) // Restore the working directory
wxFileName::SetCwd(m_InitialDir);
m_IsClosingProject = isClosingOtherProjects;
WorkspaceChanged();
return true;
}
bool ProjectManager::CloseActiveProject(bool dontsave)
{
if (!CloseProject(m_pActiveProject, dontsave))
return false;
if (m_pProjects->GetCount() > 0)
SetProject(m_pProjects->Item(0));
return true;
}
bool ProjectManager::SaveProject(cbProject* project)
{
if (!project)
return false;
if (project->Save())
{
RebuildTree();
return true;
}
return false;
}
bool ProjectManager::SaveProjectAs(cbProject* project)
{
if (!project)
return false;
if (project->SaveAs())
{
RebuildTree();
return true;
}
return false;
}
bool ProjectManager::SaveActiveProject()
{
return SaveProject(m_pActiveProject);
}
bool ProjectManager::SaveActiveProjectAs()
{
return SaveProjectAs(m_pActiveProject);
}
bool ProjectManager::SaveAllProjects()
{
FreezeTree();
int prjCount = m_pProjects->GetCount();
int count = 0;
for (int i = 0; i < prjCount; ++i)
{
cbProject* project = m_pProjects->Item(i);
bool isModified = project->GetModified();
if (isModified && SaveProject(project))
++count;
}
UnfreezeTree(true);
return count == prjCount;
}
void ProjectManager::MoveProjectUp(cbProject* project, bool warpAround)
{
if (!project)
return;
int idx = m_pProjects->Index(project);
if (idx == wxNOT_FOUND)
return; // project not opened in project manager???
if (idx == 0)
{
if (!warpAround)
return;
else
idx = m_pProjects->Count();
}
m_pProjects->RemoveAt(idx--);
m_pProjects->Insert(project, idx);
RebuildTree();
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
// re-select the project
wxTreeItemId node = project->GetProjectNode();
cbAssert(node.IsOk());
m_pTree->SelectItem(node, true);
}
void ProjectManager::MoveProjectDown(cbProject* project, bool warpAround)
{
if (!project)
return;
int idx = m_pProjects->Index(project);
if (idx == wxNOT_FOUND)
return; // project not opened in project manager???
if (idx == (int)m_pProjects->Count() - 1)
{
if (!warpAround)
return;
else
idx = 0;
}
m_pProjects->RemoveAt(idx++);
m_pProjects->Insert(project, idx);
RebuildTree();
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
// re-select the project
wxTreeItemId node = project->GetProjectNode();
cbAssert(node.IsOk());
m_pTree->SelectItem(node, true);
}
cbWorkspace* ProjectManager::GetWorkspace()
{
if (!m_pWorkspace)
{
m_pWorkspace = new cbWorkspace(_T(""));
m_pWorkspace->SetTitle(_("Workspace"));
m_pWorkspace->SetModified(false);
}
return m_pWorkspace;
}
bool ProjectManager::LoadWorkspace(const wxString& filename)
{
if (!BeginLoadingWorkspace())
return false;
m_pWorkspace = new cbWorkspace(filename);
EndLoadingWorkspace();
if (m_pProjects->GetCount() > 0 && !m_pActiveProject)
SetProject(m_pProjects->Item(0), false);
return m_pWorkspace && m_pWorkspace->IsOK();
}
bool ProjectManager::SaveWorkspace()
{
return GetWorkspace()->Save();
}
bool ProjectManager::SaveWorkspaceAs(const wxString& filename)
{
return GetWorkspace()->SaveAs(filename);
}
bool ProjectManager::QueryCloseWorkspace()
{
if(!m_pWorkspace)
return true;
// don't ask to save the default workspace, if blank workspace is used on app startup
if (m_pWorkspace->IsDefault() && Manager::Get()->GetConfigManager(_T("app"))->ReadBool(_T("/environment/blank_workspace"), true) == true)
return true;
if (m_pWorkspace->GetModified())
{
// workspace needs save
wxString msg;
msg.Printf(_("Workspace '%s' is modified. Do you want to save it?"), m_pWorkspace->GetTitle().c_str());
switch (cbMessageBox(msg,
_("Save workspace"),
wxYES_NO | wxCANCEL | wxICON_QUESTION))
{
case wxID_YES: SaveWorkspace(); break;
case wxID_CANCEL: return false;
default: break;
}
}
if(!QueryCloseAllProjects())
return false;
return true;
}
bool ProjectManager::CloseWorkspace()
{
bool result = false;
m_IsClosingWorkspace = true;
if (m_pWorkspace)
{
if (!QueryCloseWorkspace())
{
m_IsClosingWorkspace = false;
return false;
}
if (!CloseAllProjects(false))
{
m_IsClosingWorkspace = false;
return false;
}
delete m_pWorkspace;
m_pWorkspace = 0;
if (m_pTree)
{
m_pTree->SetItemText(m_TreeRoot, _("Workspace"));
if (!Manager::IsAppShuttingDown())
RebuildTree(); // update the workspace icon if required
}
result = true;
}
else
result = CloseAllProjects(false);
m_IsClosingWorkspace = false;
WorkspaceChanged();
return result;
}
// This function is static for your convenience :)
bool ProjectManager::IsBusy()
{
if(Manager::IsAppShuttingDown())
{
return true;
}
ProjectManager* projman = Manager::Get()->GetProjectManager();
if(!projman)
{
return true;
}
return projman->IsLoadingOrClosing();
}
bool ProjectManager::IsLoadingOrClosing()
{
return (m_IsLoadingProject || m_IsLoadingWorkspace || m_IsClosingProject || m_IsClosingWorkspace);
}
bool ProjectManager::IsLoadingProject()
{
return m_IsLoadingProject;
}
bool ProjectManager::IsLoadingWorkspace()
{
return m_IsLoadingWorkspace;
}
bool ProjectManager::IsLoading()
{
return (m_IsLoadingProject || m_IsLoadingWorkspace);
}
bool ProjectManager::IsClosingProject()
{
return m_IsClosingProject;
}
bool ProjectManager::IsClosingWorkspace()
{
return m_IsClosingWorkspace;
}
void ProjectManager::FreezeTree()
{
if (!m_pTree)
return;
++m_TreeFreezeCounter;
m_pTree->Freeze();
}
void ProjectManager::UnfreezeTree(bool /*force*/)
{
if (!m_pTree)
return;
if (m_TreeFreezeCounter){
--m_TreeFreezeCounter;
m_pTree->Thaw();
}
}
void ProjectManager::RebuildTree()
{
FreezeTree();
int count = m_pProjects->GetCount();
for (int i = 0; i < count; ++i)
{
cbProject* project = m_pProjects->Item(i);
if (project)
project->SaveTreeState(m_pTree);
}
m_pTree->DeleteAllItems();
wxString title;
bool read_only = false;
if (m_pWorkspace)
{
title = m_pWorkspace->GetTitle();
wxString ws_file = m_pWorkspace->GetFilename();
read_only = ( !ws_file.IsEmpty() && wxFile::Exists(ws_file.c_str())
&& !wxFile::Access(ws_file.c_str(), wxFile::write) );
}
if (title.IsEmpty())
title = _("Workspace");
m_TreeRoot = m_pTree->AddRoot(title, WorkspaceIconIndex(read_only), WorkspaceIconIndex(read_only));
for (int i = 0; i < count; ++i)
{
cbProject* project = m_pProjects->Item(i);
if (project)
{
project->BuildTree(m_pTree, m_TreeRoot, m_TreeCategorize, m_TreeUseFolders, m_pFileGroups);
m_pTree->SetItemBold(project->GetProjectNode(), project == m_pActiveProject);
}
}
m_pTree->Expand(m_TreeRoot);
for (int i = 0; i < count; ++i)
{
cbProject* project = m_pProjects->Item(i);
if (project)
project->RestoreTreeState(m_pTree);
}
UnfreezeTree();
}
int ProjectManager::DoAddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets)
{
if (!project)
return 0;
// do we have to ask for target?
if (targets.GetCount() == 0)
{
// if project has only one target, use this
if (project->GetBuildTargetsCount() == 1)
targets.Add(0);
// else display multiple target selection dialog
else
{
targets = AskForMultiBuildTargetIndex(project);
if (targets.GetCount() == 0)
return 0;
}
}
// make sure filename is relative to project path
wxFileName fname(filename);
fname.Normalize(wxPATH_NORM_DOTS | wxPATH_NORM_ABSOLUTE, project->GetBasePath());
fname.MakeRelativeTo(project->GetBasePath());
// add the file to the first selected target
ProjectFile* pf = project->AddFile(targets[0], fname.GetFullPath());
if (pf)
{
// if the file was added succesfully,
// add to this file the rest of the selected targets...
for (size_t i = 0; i < targets.GetCount(); ++i)
{
ProjectBuildTarget* target = project->GetBuildTarget(targets[i]);
if (target)
pf->AddBuildTarget(target->GetTitle());
}
}
return targets.GetCount();
}
int ProjectManager::AddFileToProject(const wxString& filename, cbProject* project, int target)
{
if (!project)
project = GetActiveProject();
wxArrayInt targets;
targets.Add(target);
if (AddFileToProject(filename, project, targets) == 1)
return targets[0];
return -1;
}
int ProjectManager::AddFileToProject(const wxString& filename, cbProject* project, wxArrayInt& targets)
{
if (!project)
project = GetActiveProject();
int ret = DoAddFileToProject(filename, project, targets);
if (ret > 0)
{
CodeBlocksEvent event(cbEVT_PROJECT_FILE_ADDED);
event.SetProject(project);
event.SetString(filename);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
return ret;
}
int ProjectManager::AddMultipleFilesToProject(const wxArrayString& filelist, cbProject* project, int target)
{
if (!project)
project = GetActiveProject();
wxArrayInt targets;
targets.Add(target);
if (AddMultipleFilesToProject(filelist, project, targets) == 1)
return targets[0];
return -1;
}
int ProjectManager::AddMultipleFilesToProject(const wxArrayString& filelist, cbProject* project, wxArrayInt& targets)
{
wxProgressDialog progress(_("Project Manager"), _("Please wait while adding files to project..."), filelist.GetCount(), Manager::Get()->GetAppFrame());
if (!project)
project = GetActiveProject();
project->BeginAddFiles();
wxArrayString addedFiles; // to know which files were added succesfully
for (unsigned int i = 0; i < filelist.GetCount(); ++i)
{
if (DoAddFileToProject(filelist[i], project, targets) != 0)
addedFiles.Add(filelist[i]);
progress.Update(i);
}
if (addedFiles.GetCount() != 0)
{
for (unsigned int i = 0; i < addedFiles.GetCount(); ++i)
{
CodeBlocksEvent event(cbEVT_PROJECT_FILE_ADDED);
event.SetProject(project);
event.SetString(addedFiles[i]);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
}
project->EndAddFiles();
return targets.GetCount();
}
int ProjectManager::AskForBuildTargetIndex(cbProject* project)
{
cbProject* prj = project;
if (!prj)
prj = GetActiveProject();
if (!prj)
return -1;
// ask for target
wxArrayString array;
int count = prj->GetBuildTargetsCount();
for (int i = 0; i < count; ++i)
array.Add(prj->GetBuildTarget(i)->GetTitle());
int target = wxGetSingleChoiceIndex(_("Select the target:"), _("Project targets"), array);
return target;
}
wxArrayInt ProjectManager::AskForMultiBuildTargetIndex(cbProject* project)
{
wxArrayInt indices;
cbProject* prj = project;
if (!prj)
prj = GetActiveProject();
if (!prj)
return indices;
// ask for target
wxArrayString array;
int count = prj->GetBuildTargetsCount();
for (int i = 0; i < count; ++i)
array.Add(prj->GetBuildTarget(i)->GetTitle());
MultiSelectDlg dlg(0, array, true, _("Select the targets this file should belong to:"));
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK)
indices = dlg.GetSelectedIndices();
return indices;
}
void ProjectManager::DoOpenFile(ProjectFile* pf, const wxString& filename)
{
// Basic stuff: We can only open files that are still present
wxFileName the_file(filename);
if (!the_file.FileExists())
{
wxString msg;
msg.Printf(_("Could not open the file '%s'.\nThe file does not exist."), filename.c_str());
cbMessageBox(msg, _("Error"));
pf->SetFileState(fvsMissing);
Manager::Get()->GetLogManager()->LogError(msg);
return;
}
FileType ft = FileTypeOf(filename);
if (ft == ftHeader || ft == ftSource)
{
// C/C++ header/source files, always get opened inside Code::Blocks
cbEditor* ed = Manager::Get()->GetEditorManager()->Open(filename);
if (ed)
{
ed->SetProjectFile(pf);
ed->Activate();
}
else
{
wxString msg;
msg.Printf(_("Failed to open '%s'."), filename.c_str());
Manager::Get()->GetLogManager()->LogError(msg);
}
}
else
{
// first look for custom editors
// if that fails, try MIME handlers
EditorBase* eb = Manager::Get()->GetEditorManager()->IsOpen(filename);
if (eb && !eb->IsBuiltinEditor())
{
// custom editors just get activated
eb->Activate();
return;
}
// not a recognized file type
cbMimePlugin* plugin = Manager::Get()->GetPluginManager()->GetMIMEHandlerForFile(filename);
if (!plugin)
{
wxString msg;
msg.Printf(_("Could not open file '%s'.\nNo handler registered for this type of file."), filename.c_str());
Manager::Get()->GetLogManager()->LogError(msg);
}
else if (plugin->OpenFile(filename) != 0)
{
const PluginInfo* info = Manager::Get()->GetPluginManager()->GetPluginInfo(plugin);
wxString msg;
msg.Printf(_("Could not open file '%s'.\nThe registered handler (%s) could not open it."), filename.c_str(), info ? info->title.c_str() : wxString(_("<Unknown plugin>")).c_str());
Manager::Get()->GetLogManager()->LogError(msg);
}
}
}
void ProjectManager::DoOpenSelectedFile()
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
{
ProjectFile* f = ftd->GetProjectFile();
if (f)
{
DoOpenFile(f, f->file.GetFullPath());
}
}
}
bool ProjectManager::CausesCircularDependency(cbProject* base, cbProject* dependsOn)
{
if (!base || !dependsOn)
return false;
// 1st check is both projects are the same one
if (base == dependsOn)
return true;
const ProjectsArray* arr = GetDependenciesForProject(dependsOn);
if (arr)
{
// now check deeper
for (size_t i = 0; i < arr->GetCount(); ++i)
{
if (CausesCircularDependency(base, arr->Item(i)))
return true;
}
}
// if we reached here, no possibility of circular dependency :)
return false;
}
bool ProjectManager::AddProjectDependency(cbProject* base, cbProject* dependsOn)
{
if (!base || !dependsOn)
return false;
// avoid circular dependencies
if (CausesCircularDependency(base, dependsOn))
return false;
ProjectsArray* arr = 0;
DepsMap::iterator it = m_ProjectDeps.find(base);
if (it == m_ProjectDeps.end())
{
// create a ProjectsArray* to hold the dependencies for base
arr = new ProjectsArray;
m_ProjectDeps[base] = arr;
}
else
arr = it->second;
// add dependency only if not already there
if (arr->Index(dependsOn) == wxNOT_FOUND)
{
arr->Add(dependsOn);
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
#if wxCHECK_VERSION(2, 9, 0)
Manager::Get()->GetLogManager()->DebugLog(F(_T("%s now depends on %s (%d deps)"), base->GetTitle().wx_str(), dependsOn->GetTitle().wx_str(), arr->GetCount()));
#else
Manager::Get()->GetLogManager()->DebugLog(F(_T("%s now depends on %s (%d deps)"), base->GetTitle().c_str(), dependsOn->GetTitle().c_str(), arr->GetCount()));
#endif
}
return true;
}
void ProjectManager::RemoveProjectDependency(cbProject* base, cbProject* doesNotDependOn)
{
if (!base || !doesNotDependOn)
return;
DepsMap::iterator it = m_ProjectDeps.find(base);
if (it == m_ProjectDeps.end())
return; // nothing to remove
ProjectsArray* arr = it->second;
arr->Remove(doesNotDependOn);
#if wxCHECK_VERSION(2, 9, 0)
Manager::Get()->GetLogManager()->DebugLog(F(_T("%s now does not depend on %s (%d deps)"), base->GetTitle().wx_str(), doesNotDependOn->GetTitle().wx_str(), arr->GetCount()));
#else
Manager::Get()->GetLogManager()->DebugLog(F(_T("%s now does not depend on %s (%d deps)"), base->GetTitle().c_str(), doesNotDependOn->GetTitle().c_str(), arr->GetCount()));
#endif
// if it was the last dependency, delete the array
if (!arr->GetCount())
{
m_ProjectDeps.erase(it);
delete arr;
}
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
}
void ProjectManager::ClearProjectDependencies(cbProject* base)
{
if (!base)
return;
DepsMap::iterator it = m_ProjectDeps.find(base);
if (it == m_ProjectDeps.end())
return; // nothing to remove
delete it->second;
m_ProjectDeps.erase(it);
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
Manager::Get()->GetLogManager()->DebugLog(_T("Removed all deps from ") + base->GetTitle());
}
void ProjectManager::RemoveProjectFromAllDependencies(cbProject* base)
{
if (!base)
return;
DepsMap::iterator it = m_ProjectDeps.begin();
while (it != m_ProjectDeps.end())
{
if (it->first == base)
{
++it;
continue;
}
ProjectsArray* arr = it->second;
// only check projects that do have a dependencies array
if (!arr)
{
++it;
continue;
}
int index = arr->Index(base);
if (index != wxNOT_FOUND)
arr->RemoveAt(index);
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
// if it was the last dependency, delete the array
if (!arr->GetCount())
{
DepsMap::iterator it2 = it++;
m_ProjectDeps.erase(it2);
delete arr;
}
else
++it;
}
#if wxCHECK_VERSION(2, 9, 0)
Manager::Get()->GetLogManager()->DebugLog(F(_T("Removed %s from all deps"), base->GetTitle().wx_str()));
#else
Manager::Get()->GetLogManager()->DebugLog(F(_T("Removed %s from all deps"), base->GetTitle().c_str()));
#endif
}
const ProjectsArray* ProjectManager::GetDependenciesForProject(cbProject* base)
{
DepsMap::iterator it = m_ProjectDeps.find(base);
if (it != m_ProjectDeps.end())
return it->second;
return 0;
}
void ProjectManager::ConfigureProjectDependencies(cbProject* base)
{
ProjectDepsDlg dlg(Manager::Get()->GetAppWindow(), base);
PlaceWindow(&dlg);
dlg.ShowModal();
}
// events
void ProjectManager::OnTabContextMenu(wxAuiNotebookEvent& /*event*/)
{
wxMenu* NBmenu = new wxMenu();
NBmenu->Append(idNB_TabTop, _("Tabs at top"));
NBmenu->Append(idNB_TabBottom, _("Tabs at bottom"));
m_pNotebook->PopupMenu(NBmenu);
delete NBmenu;
}
void ProjectManager::OnTabPosition(wxCommandEvent& event)
{
long style = m_pNotebook->GetWindowStyleFlag();
style &= ~wxAUI_NB_BOTTOM;
if (event.GetId() == idNB_TabBottom)
style |= wxAUI_NB_BOTTOM;
m_pNotebook->SetWindowStyleFlag(style);
m_pNotebook->Refresh();
// (style & wxAUI_NB_BOTTOM) saves info only about the the tabs position
Manager::Get()->GetConfigManager(_T("app"))->Write(_T("/environment/project_tabs_bottom"), (bool)(style & wxAUI_NB_BOTTOM));
}
void ProjectManager::OnTreeBeginDrag(wxTreeEvent& event)
{
// what item do we start dragging?
wxTreeItemId id = event.GetItem();
if (!id.IsOk())
return;
// if no data associated with it, disallow
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(id);
if (!ftd)
return;
// if no project, disallow
cbProject* prj = ftd->GetProject();
if (!prj)
return;
// allow only if the project approves
if (!prj->CanDragNode(m_pTree, id))
return;
// allowed
m_DraggingItem = id;
event.Allow();
}
void ProjectManager::OnTreeEndDrag(wxTreeEvent& event)
{
wxTreeItemId from = m_DraggingItem;
wxTreeItemId to = event.GetItem();
m_DraggingItem.Unset();
// are both items valid?
if (!from.IsOk() || !to.IsOk())
return;
// if no data associated with any of them, disallow
FileTreeData* ftd1 = (FileTreeData*)m_pTree->GetItemData(from);
FileTreeData* ftd2 = (FileTreeData*)m_pTree->GetItemData(to);
if (!ftd1 || !ftd2)
return;
// if no project or different projects, disallow
cbProject* prj1 = ftd1->GetProject();
cbProject* prj2 = ftd2->GetProject();
if (!prj1 || prj1 != prj2)
return;
// allow only if the project approves
if (!prj1->NodeDragged(m_pTree, from, to))
return;
event.Allow();
}
void ProjectManager::OnProjectFileActivated(wxTreeEvent& event)
{
#ifdef USE_OPENFILES_TREE
if(!MiscTreeItemData::OwnerCheck(event,m_pTree,this))
return;
#endif
wxTreeItemId id = event.GetItem();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(id);
if (ftd && ftd->GetKind() == FileTreeData::ftdkProject)
{
if (ftd->GetProject() != m_pActiveProject)
{
SetProject(ftd->GetProject(), false);
}
// prevent item expand state toggle when project is activated
// toggle it one time so that it is toggled back by wx
m_pTree->IsExpanded(id) ? m_pTree->Collapse(id) : m_pTree->Expand(id);
}
else if (ftd && (ftd->GetKind() == FileTreeData::ftdkVirtualGroup || ftd->GetKind() == FileTreeData::ftdkFolder))
{
m_pTree->IsExpanded(id) ? m_pTree->Collapse(id) : m_pTree->Expand(id);
}
else if (!ftd && m_pWorkspace)
{
m_pTree->IsExpanded(m_TreeRoot) ? m_pTree->Collapse(m_TreeRoot) : m_pTree->Expand(m_TreeRoot);
}
else
DoOpenSelectedFile();
}
void ProjectManager::OnExecParameters(wxCommandEvent& /*event*/)
{
if (m_pActiveProject)
m_pActiveProject->SelectTarget(-1, true);
}
void ProjectManager::OnRightClick(wxCommandEvent& /*event*/)
{
//Manager::Get()->GetLogManager()->DebugLog("OnRightClick");
wxMenu menu;
// ask any plugins to add items in this menu
Manager::Get()->GetPluginManager()->AskPluginsForModuleMenu(mtProjectManager, &menu);
// if plugins added to this menu, add a separator
if (menu.GetMenuItemCount() != 0)
menu.AppendSeparator();
menu.AppendCheckItem(idMenuViewCategorizePopup, _("Categorize by file types"));
menu.AppendCheckItem(idMenuViewUseFoldersPopup, _("Display folders as on disk"));
menu.AppendSeparator();
menu.Append(idMenuViewFileMasks, _("Edit file types && categories..."));
menu.Check(idMenuViewCategorizePopup, m_TreeCategorize);
menu.Check(idMenuViewUseFoldersPopup, m_TreeUseFolders);
wxPoint pt = wxGetMousePosition();
pt = m_pTree->ScreenToClient(pt);
m_pTree->PopupMenu(&menu, pt);
}
void ProjectManager::OnTreeItemRightClick(wxTreeEvent& event)
{
#ifdef USE_OPENFILES_TREE
if(!MiscTreeItemData::OwnerCheck(event,m_pTree,this))
return;
#endif
if(m_IsLoadingProject)
{
wxBell();
return;
}
//Manager::Get()->GetLogManager()->DebugLog("OnTreeItemRightClick");
m_pTree->SelectItem(event.GetItem());
ShowMenu(event.GetItem(), event.GetPoint());
}
void ProjectManager::OnRenameWorkspace(wxCommandEvent& /*event*/)
{
if (m_pWorkspace)
{
wxString text = wxGetTextFromUser(_("Please enter the new name for the workspace:"), _("Rename workspace"), m_pWorkspace->GetTitle());
if (!text.IsEmpty())
{
m_pWorkspace->SetTitle(text);
m_pTree->SetItemText(m_TreeRoot, m_pWorkspace->GetTitle());
}
}
}
void ProjectManager::OnSaveWorkspace(wxCommandEvent& /*event*/)
{
if (m_pWorkspace)
{
SaveWorkspace();
}
}
void ProjectManager::OnSaveAsWorkspace(wxCommandEvent& /*event*/)
{
if (m_pWorkspace)
{
SaveWorkspaceAs(_T(""));
}
}
void ProjectManager::OnCloseWorkspace(wxCommandEvent& /*event*/)
{
if (m_pWorkspace)
{
CloseWorkspace();
}
}
void ProjectManager::OnSetActiveProject(wxCommandEvent& event)
{
if (event.GetId() == idMenuSetActiveProject)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
SetProject(ftd->GetProject(), false);
}
else if (event.GetId() == idMenuPriorProject)
{
int index = m_pProjects->Index(m_pActiveProject);
if (index == wxNOT_FOUND)
return;
--index;
if (index < 0)
index = m_pProjects->GetCount() - 1;
SetProject(m_pProjects->Item(index), false);
}
else if (event.GetId() == idMenuNextProject)
{
int index = m_pProjects->Index(m_pActiveProject);
if (index == wxNOT_FOUND)
return;
++index;
if (index == (int)m_pProjects->GetCount())
index = 0;
SetProject(m_pProjects->Item(index), false);
}
else if (event.GetId() == idMenuProjectUp)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
MoveProjectUp(ftd->GetProject());
}
else if (event.GetId() == idMenuProjectDown)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
MoveProjectDown(ftd->GetProject());
}
}
void ProjectManager::OnAddFilesToProjectRecursively(wxCommandEvent& event)
{
cbProject* prj = 0;
wxString basePath;
if (event.GetId() == idMenuAddFilesRecursively)
{
prj = GetActiveProject();
if (prj)
basePath = prj->GetBasePath();
}
else
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
{
prj = ftd->GetProject();
if (prj)
{
basePath = ftd->GetFolder();
if (!wxDirExists(basePath))
basePath = prj->GetBasePath();
}
}
}
if (!prj)
return;
wxString dir = ChooseDirectory(m_pTree,
_("Add files recursively..."),
basePath,
wxEmptyString,
false,
false);
if (dir.IsEmpty())
return;
wxArrayInt targets;
// ask for target only if more than one
if (prj->GetBuildTargetsCount() == 1)
targets.Add(0);
// generate list of files to add
wxArrayString array;
wxDir::GetAllFiles(dir, &array, wxEmptyString, wxDIR_FILES | wxDIR_DIRS);
if (array.GetCount() == 0)
return;
// for usability reasons, remove any directory entries from the list...
unsigned int i = 0;
while (i < array.GetCount())
{
// discard directories, as well as some well known SCMs control folders ;)
// also discard C::B project files
if (wxDirExists(array[i]) ||
array[i].Contains(_T("\\.svn\\")) ||
array[i].Contains(_T("/.svn/")) ||
array[i].Contains(_T("\\CVS\\")) ||
array[i].Contains(_T("/CVS/")) ||
array[i].Lower().Matches(_T("*.cbp")))
{
array.RemoveAt(i);
}
else
++i;
}
wxString wild;
for (unsigned i = 0; i < m_pFileGroups->GetGroupsCount(); i++)
wild += m_pFileGroups->GetFileMasks(i);
MultiSelectDlg dlg(0, array, wild, _("Select the files to add to the project:"));
PlaceWindow(&dlg);
if (dlg.ShowModal() != wxID_OK)
return;
array = dlg.GetSelectedStrings();
// finally add the files
AddMultipleFilesToProject(array, prj, targets);
RebuildTree();
}
void ProjectManager::OnAddFileToProject(wxCommandEvent& event)
{
cbProject* prj = 0;
wxString basePath;
if (event.GetId() == idMenuAddFile)
{
prj = GetActiveProject();
if (prj)
basePath = prj->GetBasePath();
}
else
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
{
prj = ftd->GetProject();
if (prj)
{
basePath = ftd->GetFolder();
if (!wxDirExists(basePath))
basePath = prj->GetBasePath();
}
}
}
if (!prj)
return;
wxFileDialog dlg(Manager::Get()->GetAppWindow(),
_("Add files to project..."),
basePath,
wxEmptyString,
FileFilters::GetFilterString(),
wxFD_OPEN | wxFD_MULTIPLE | wxFD_FILE_MUST_EXIST | compatibility::wxHideReadonly);
dlg.SetFilterIndex(FileFilters::GetIndexForFilterAll());
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK)
{
wxArrayInt targets;
// ask for target only if more than one
if (prj->GetBuildTargetsCount() == 1)
targets.Add(0);
wxArrayString array;
dlg.GetPaths(array);
AddMultipleFilesToProject(array, prj, targets);
RebuildTree();
}
}
void ProjectManager::OnRemoveFileFromProject(wxCommandEvent& event)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
cbProject* prj = ftd->GetProject();
if (!prj)
return;
wxString oldpath = prj->GetCommonTopLevelPath();
if (event.GetId() == idMenuRemoveFile)
{
// remove multiple-files
wxArrayString files;
for (int i = 0; i < prj->GetFilesCount(); ++i)
{
files.Add(prj->GetFile(i)->relativeFilename);
}
if (files.Count()==0)
{
cbMessageBox(_("This project does not contain any files to remove."),
_("Error"), wxICON_WARNING);
return;
}
wxString msg;
msg.Printf(_("Select files to remove from %s:"), prj->GetTitle().c_str());
MultiSelectDlg dlg(0, files, true, msg);
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK)
{
wxArrayInt indices = dlg.GetSelectedIndices();
if (indices.GetCount() == 0)
return;
if (cbMessageBox(_("Are you sure you want to remove these files from the project?"),
_("Confirmation"),
wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT) != wxID_YES)
{
return;
}
prj->BeginRemoveFiles();
// we iterate the array backwards, because if we iterate it normally,
// when we remove the first index, the rest becomes invalid...
for (int i = (int)indices.GetCount() - 1; i >= 0; --i)
{
Manager::Get()->GetLogManager()->DebugLog(F(_T("Removing index %d"), indices[i]));
ProjectFile* pf = prj->GetFile(indices[i]);
RemoveFileFromProject(pf, prj);
}
prj->CalculateCommonTopLevelPath();
prj->EndRemoveFiles();
RebuildTree();
}
}
else if (event.GetId() == idMenuRemoveFilePopup)
{
ProjectFile *prjfile = ftd->GetProjectFile();
if (prjfile)
{
// remove single file
prj->BeginRemoveFiles();
RemoveFileFromProject(prjfile, prj);
prj->CalculateCommonTopLevelPath();
if (prj->GetCommonTopLevelPath() == oldpath)
m_pTree->Delete(sel);
prj->EndRemoveFiles();
RebuildTree();
}
}
else if (event.GetId() == idMenuRemoveFolderFilesPopup)
{
// remove all files from a folder
if (cbMessageBox(_("Are you sure you want to recursively remove from the project all the files under this folder?"),
_("Confirmation"),
wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT) != wxID_YES)
{
return;
}
bool is_virtual = ftd->GetKind() == FileTreeData::ftdkVirtualFolder;
if (is_virtual || ftd->GetKind() == FileTreeData::ftdkFolder)
{
prj->BeginRemoveFiles();
RemoveFilesRecursively(sel);
prj->EndRemoveFiles();
}
prj->CalculateCommonTopLevelPath();
if (prj->GetCommonTopLevelPath() == oldpath && !is_virtual)
m_pTree->Delete(sel);
else if (is_virtual)
prj->VirtualFolderDeleted(m_pTree, sel);
RebuildTree();
}
}
void ProjectManager::OnSaveProject(wxCommandEvent& WXUNUSED(event))
{
wxTreeItemId sel = m_pTree->GetSelection();
if(FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel))
{
if(cbProject* Project = ftd->GetProject())
{
//TODO : does it make sense TO not save project file while compiling ??
if(m_IsLoadingProject || Project->GetCurrentlyCompilingTarget())
{
wxBell();
}
else
{
SaveProject(Project);
}
}
}
} // end of OnSaveProject
void ProjectManager::OnCloseProject(wxCommandEvent& WXUNUSED(event))
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
cbProject *proj = 0;
if (ftd)
proj = ftd->GetProject();
if(proj)
{
if(m_IsLoadingProject || proj->GetCurrentlyCompilingTarget())
{
wxBell();
}
else
CloseProject(proj);
}
if (m_pProjects->GetCount() > 0 && !m_pActiveProject)
SetProject(m_pProjects->Item(0), false);
Manager::Get()->GetAppWindow()->Refresh();
}
void ProjectManager::OnSaveFile(wxCommandEvent& WXUNUSED(event))
{
wxTreeItemId sel = m_pTree->GetSelection();
if(FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel))
{
if(cbProject* Project = ftd->GetProject())
{
if(ProjectFile* File = Project->GetFile(ftd->GetFileIndex()))
{
Manager::Get()->GetEditorManager()->Save(File->file.GetFullPath());
}
}
}
} // end of OnSaveFile
void ProjectManager::OnCloseFile(wxCommandEvent& WXUNUSED(event))
{
wxTreeItemId sel = m_pTree->GetSelection();
if (FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel))
{
if(cbProject* Project = ftd->GetProject())
{
if(ProjectFile* File = Project->GetFile(ftd->GetFileIndex()))
{
Manager::Get()->GetEditorManager()->Close(File->file.GetFullPath());
}
}
}
} // end of OnCloseFile
void ProjectManager::OnOpenFile(wxCommandEvent& WXUNUSED(event))
{
DoOpenSelectedFile();
}
void ProjectManager::OnOpenFolderFiles(wxCommandEvent& event)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
// open all files from a folder
if (cbMessageBox(_("Are you sure you want to recursively open from the project all the files under this folder?"),
_("Confirmation"),
wxICON_QUESTION | wxYES_NO | wxNO_DEFAULT) != wxID_YES)
{
return;
}
if ( ftd->GetKind() == FileTreeData::ftdkFolder
|| ftd->GetKind() == FileTreeData::ftdkVirtualFolder )
{
OpenFilesRecursively(sel);
}
event.Skip();
}
void ProjectManager::OnOpenWith(wxCommandEvent& event)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (ftd)
{
cbProject* project = ftd->GetProject();
ProjectFile* f = project->GetFile(ftd->GetFileIndex());
if (f)
{
wxString filename = f->file.GetFullPath();
if (event.GetId() == idOpenWithInternal)
{
cbEditor* ed = Manager::Get()->GetEditorManager()->Open(filename);
if (ed)
{
ed->SetProjectFile(f);
ed->Show(true);
return;
}
}
else
{
PluginsArray mimes = Manager::Get()->GetPluginManager()->GetMimeOffers();
cbMimePlugin* plugin = (cbMimePlugin*)mimes[event.GetId() - idOpenWith[0]];
if (plugin && plugin->OpenFile(filename) == 0)
return;
}
wxString msg;
msg.Printf(_("Failed to open '%s'."), filename.c_str());
Manager::Get()->GetLogManager()->LogError(msg);
}
}
}
void ProjectManager::OnNotes(wxCommandEvent& WXUNUSED(event))
{
if(cbProject* project = GetActiveProject())
{
project->ShowNotes(false, true);
}
}
void ProjectManager::OnProperties(wxCommandEvent& event)
{
if (event.GetId() == idMenuProjectProperties)
{
wxString backupTitle = m_pActiveProject ? m_pActiveProject->GetTitle() : _T("");
if (m_pActiveProject && m_pActiveProject->ShowOptions())
{
// make sure that cbEVT_PROJECT_ACTIVATE
// is sent (maybe targets have changed)...
// rebuild tree only if title has changed
SetProject(m_pActiveProject, backupTitle != m_pActiveProject->GetTitle());
}
}
else if (event.GetId() == idMenuTreeProjectProperties)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
cbProject* project = ftd ? ftd->GetProject() : m_pActiveProject;
wxString backupTitle = project ? project->GetTitle() : _T("");
if (project && project->ShowOptions() && project == m_pActiveProject)
{
// rebuild tree and make sure that cbEVT_PROJECT_ACTIVATE
// is sent (maybe targets have changed)...
// rebuild tree only if title has changed
SetProject(project, backupTitle != project->GetTitle());
}
// if project title has changed, update the appropriate tab tooltips
wxString newTitle = project->GetTitle();
if(backupTitle != newTitle)
{
cbAuiNotebook* nb = Manager::Get()->GetEditorManager()->GetNotebook();
if(nb)
{
wxString toolTip;
for(size_t i = 0; i < nb->GetPageCount(); ++i)
{
toolTip = nb->GetPage(i)->GetName();
if(toolTip.EndsWith(_("Project: ") + backupTitle))
{
toolTip.Replace(_("Project: ") + backupTitle,_("Project: ") + newTitle);
nb->SetTabToolTip(nb->GetPage(i), toolTip);
}
}
}
}
}
else if (event.GetId() == idMenuTreeFileProperties)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
cbProject* project = ftd ? ftd->GetProject() : m_pActiveProject;
if (project)
{
if (ftd && ftd->GetFileIndex() != -1)
{
ProjectFile* pf = project->GetFile(ftd->GetFileIndex());
if (pf)
pf->ShowOptions(Manager::Get()->GetAppWindow());
}
}
}
else // active editor properties
{
cbEditor* ed = Manager::Get()->GetEditorManager()->GetBuiltinActiveEditor();
if (ed)
{
ProjectFile* pf = ed->GetProjectFile();
if (pf)
pf->ShowOptions(Manager::Get()->GetAppWindow());
else
{
// active editor not-in-project
ProjectFileOptionsDlg dlg(Manager::Get()->GetAppWindow(), ed->GetFilename());
PlaceWindow(&dlg);
dlg.ShowModal();
}
}
}
}
struct ProjectFileRelativePathCmp
{
bool operator()(ProjectFile* f1, ProjectFile* f2)
{ return f1->relativeFilename.Cmp(f2->relativeFilename) < 0; }
};
struct ProjectFileAbsolutePathCmp
{
bool operator()(ProjectFile* f1, ProjectFile* f2)
{ return f1->file.GetFullPath().Cmp(f2->file.GetFullPath()) < 0; }
};
struct ProjectFileAbsolutePathEqual
{
bool operator()(ProjectFile* f1, ProjectFile* f2)
{ return f1->file.GetFullPath() == f2->file.GetFullPath(); }
};
void ProjectManager::OnGotoFile(wxCommandEvent& /*event*/)
{
if (!m_pActiveProject)
{
Manager::Get()->GetLogManager()->DebugLog(_T("No active project!"));
return;
}
typedef std::vector<ProjectFile*> ProjectFiles;
ProjectFiles files;
for (size_t proj_index = 0; proj_index < m_pProjects->GetCount(); ++proj_index)
{
cbProject *project = (*m_pProjects)[proj_index];
for (int i = 0; i < project->GetFilesCount(); ++i)
files.push_back(project->GetFile(i));
}
if (!files.empty())
{
std::sort(files.begin(), files.end(), ProjectFileAbsolutePathCmp());
ProjectFiles::iterator last = std::unique(files.begin(), files.end(), ProjectFileAbsolutePathEqual());
if (last != files.end())
{
files.erase(last, files.end());
}
std::sort(files.begin(), files.end(), ProjectFileRelativePathCmp());
}
class Iterator : public IncrementalSelectIterator
{
public:
Iterator(ProjectFiles &files) : m_Files(files)
{ ; }
virtual long GetCount() const
{ return m_Files.size(); }
virtual wxString GetItem(long index) const
{ return m_Files[index]->relativeFilename; }
private:
ProjectFiles &m_Files;
};
Iterator iterator(files);
IncrementalSelectListDlg dlg(Manager::Get()->GetAppWindow(), iterator,
_("Select file..."), _("Please select file to open:"));
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK)
{
long selection = dlg.GetSelection();
if (selection != -1)
DoOpenFile(files[selection], files[selection]->file.GetFullPath());
}
}
void ProjectManager::OnViewCategorize(wxCommandEvent& event)
{
m_TreeCategorize = event.IsChecked();
Manager::Get()->GetAppFrame()->GetMenuBar()->Check(idMenuViewCategorize, m_TreeCategorize);
Manager::Get()->GetConfigManager(_T("project_manager"))->Write(_T("/categorize_tree"), m_TreeCategorize);
RebuildTree();
}
void ProjectManager::OnViewUseFolders(wxCommandEvent& event)
{
m_TreeUseFolders = event.IsChecked();
Manager::Get()->GetAppFrame()->GetMenuBar()->Check(idMenuViewUseFolders, m_TreeUseFolders);
Manager::Get()->GetConfigManager(_T("project_manager"))->Write(_T("/use_folders"), m_TreeUseFolders);
RebuildTree();
}
void ProjectManager::OnViewFileMasks(wxCommandEvent& /*event*/)
{
ProjectsFileMasksDlg dlg(Manager::Get()->GetAppWindow(), m_pFileGroups);
PlaceWindow(&dlg);
if (dlg.ShowModal() == wxID_OK)
{
m_pFileGroups->Save();
RebuildTree();
}
}
wxTreeItemId ProjectManager::FindItem( wxTreeItemId Node, const wxString& Search) const
{
wxTreeItemIdValue cookie;
wxTreeItemId item = m_pTree->GetFirstChild(Node, cookie );
while( item.IsOk() )
{
if( Search.IsSameAs( m_pTree->GetItemText( item ) ) )
{
return item;
}
else if( m_pTree->ItemHasChildren( item ) )
{
wxTreeItemId SearchId = FindItem( item, Search );
if( SearchId.IsOk() )
{
return SearchId;
}
}
item = m_pTree->GetNextChild(Node, cookie);
} // end while
wxTreeItemId notFound;
return notFound;
} // end of FindItem
void ProjectManager::OnFindFile(wxCommandEvent& /*event*/)
{
wxString text = wxGetTextFromUser(_("Please enter the name of the file you are searching:"), _("Find file..."));
if( !text.IsEmpty() )
{
wxTreeItemId sel = m_pTree->GetSelection();
wxTreeItemId found = FindItem( sel, text );
if( found.IsOk() )
{
m_pTree->UnselectAll();
m_pTree->SelectItem( found );
}
else
{
cbMessageBox(_("The file couldn't be found!"), _(""), wxICON_INFORMATION);
}
}
} // end of OnFindFile
void ProjectManager::OnAddVirtualFolder(wxCommandEvent& /*event*/)
{
wxString fld = wxGetTextFromUser(_("Please enter the new virtual folder path:"), _("New virtual folder"));
if (fld.IsEmpty())
return;
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
cbProject* prj = ftd->GetProject();
if (!prj)
return;
prj->VirtualFolderAdded(m_pTree, sel, fld);
// RebuildTree();
}
void ProjectManager::OnDeleteVirtualFolder(wxCommandEvent& /*event*/)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
cbProject* prj = ftd->GetProject();
if (!prj)
return;
prj->VirtualFolderDeleted(m_pTree, sel);
RebuildTree();
}
void ProjectManager::OnBeginEditNode(wxTreeEvent& event)
{
// what item do we start editing?
wxTreeItemId id = event.GetItem();
if (!id.IsOk())
{
event.Veto();
return;
}
// if no data associated with it, disallow
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(id);
if (!ftd)
{
event.Veto();
return;
}
// only allow editing virtual folders
if (ftd->GetKind() != FileTreeData::ftdkVirtualFolder)
event.Veto();
}
void ProjectManager::OnEndEditNode(wxTreeEvent& event)
{
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(event.GetItem());
if (!ftd)
{
event.Veto();
return;
}
cbProject* prj = ftd->GetProject();
if (!prj)
{
event.Veto();
return;
}
if (!prj->VirtualFolderRenamed(m_pTree, event.GetItem(), event.GetLabel()))
event.Veto();
// RebuildTree();
}
void ProjectManager::OnUpdateUI(wxUpdateUIEvent& event)
{
event.Skip();
}
void ProjectManager::OnIdle(wxIdleEvent& event)
{
event.Skip();
}
void ProjectManager::OnAppDoneStartup(CodeBlocksEvent& event)
{
// we do not send the workspace loaded event yet because: a) We don't know
// if there's a workspace yet, and b) app.cpp hasn't finished init'ing yet.
// We'll let app.cpp send the workspace changed for us when it's done.
m_CanSendWorkspaceChanged = true;
event.Skip();
}
void ProjectManager::OnRenameFile(wxCommandEvent& /*event*/)
{
wxTreeItemId sel = m_pTree->GetSelection();
FileTreeData* ftd = (FileTreeData*)m_pTree->GetItemData(sel);
if (!ftd)
return;
cbProject* prj = ftd->GetProject();
if (!prj)
{
return;
}
if (ftd->GetProjectFile()->AutoGeneratedBy())
{
cbMessageBox(_("Can't rename file because it is auto-generated..."), _("Error"));
return;
}
wxString path = ftd->GetProjectFile()->file.GetPath(wxPATH_GET_VOLUME | wxPATH_GET_SEPARATOR);
wxString name = ftd->GetProjectFile()->file.GetFullName();
wxTextEntryDialog dlg(Manager::Get()->GetAppWindow(), _T("Please enter the new name:"), _T("Rename file"), name, wxOK | wxCANCEL | wxCENTRE);
PlaceWindow(&dlg);
if(dlg.ShowModal() == wxID_OK)
{
wxFileName fn(dlg.GetValue());
wxString new_name = fn.GetFullName();
if(name != new_name)
{
#ifdef __WXMSW__
// only overwrite files, if the names are the same, but with different cases
if (!wxRenameFile(path + name, path + new_name, (name.Lower() == new_name.Lower())))
#else
if (!wxRenameFile(path + name, path + new_name, false))
#endif
{
wxBell();
return;
}
ProjectFile *pf = ftd->GetProjectFile();
pf->Rename(new_name);
RebuildTree();
}
}
}
void ProjectManager::WorkspaceChanged()
{
// We use IsBusy() to check *ALL* the conditions: If we're in the process of
// opening or closing a project, we cannot send the event yet.
// Specifically, *DO NOT* send the event if the application hasn't been
// initialized yet!!
if(!IsBusy() && m_CanSendWorkspaceChanged)
{
CodeBlocksEvent event(cbEVT_WORKSPACE_CHANGED);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
}
}
void ProjectManager::CheckForExternallyModifiedProjects()
{
if(m_isCheckingForExternallyModifiedProjects) // for some reason, a mutex locker does not work???
return;
m_isCheckingForExternallyModifiedProjects = true;
// check also the projects (TO DO : what if we gonna reload while compiling/debugging)
// TODO : make sure the same project is the active one again
ProjectManager* ProjectMgr = Manager::Get()->GetProjectManager();
if( ProjectsArray* Projects = ProjectMgr->GetProjects())
{
bool reloadAll = false;
// make a copy of all the pointers before we start messing with closing and opening projects
// the hash (Projects) could change the order
std::vector<cbProject*> ProjectPointers;
for(unsigned int idxProject = 0; idxProject < Projects->Count(); ++idxProject)
{
ProjectPointers.push_back(Projects->Item(idxProject));
}
for(unsigned int idxProject = 0; idxProject < ProjectPointers.size(); ++idxProject)
{
cbProject* pProject = ProjectPointers[idxProject];
wxFileName fname(pProject->GetFilename());
wxDateTime last = fname.GetModificationTime();
if(last.IsLaterThan(pProject->GetLastModificationTime()))
{ // was modified -> reload
int ret = -1;
if (!reloadAll)
{
Manager::Get()->GetLogManager()->Log(pProject->GetFilename());
wxString msg;
msg.Printf(_("Project %s is modified outside the IDE...\nDo you want to reload it (you will lose any unsaved work)?"),
pProject->GetFilename().c_str());
ConfirmReplaceDlg dlg(Manager::Get()->GetAppWindow(), false, msg);
dlg.SetTitle(_("Reload Project?"));
PlaceWindow(&dlg);
ret = dlg.ShowModal();
reloadAll = ret == crAll;
}
if(reloadAll || ret == crYes)
{
wxString ProjectFileName = pProject->GetFilename();
ProjectMgr->CloseProject(pProject);
ProjectMgr->LoadProject(ProjectFileName);
}
else if (ret == crCancel)
{
break;
}
else if (ret == crNo)
{
pProject->Touch();
}
}
} // end for : idx : idxProject
}
m_isCheckingForExternallyModifiedProjects = false;
} // end of CheckForExternallyModifiedProjects
void ProjectManager::RemoveFileFromProject(ProjectFile *pfile, cbProject* project)
{
if (pfile)
{
if (pfile->AutoGeneratedBy())
{
cbMessageBox(_("Can't remove file because it is auto-generated..."), _("Error"));
return;
}
if (!project)
project = pfile->GetParentProject(); // should actually not be necessary
wxString filename = pfile->file.GetFullPath();
project->RemoveFile(pfile);
CodeBlocksEvent evt(cbEVT_PROJECT_FILE_REMOVED);
evt.SetProject(project);
evt.SetString(filename);
Manager::Get()->GetPluginManager()->NotifyPlugins(evt);
Manager::Get()->GetLogManager()->DebugLog(_T("Removed ") + filename + _T(" from ") + project->GetTitle());
}
else
Manager::Get()->GetLogManager()->DebugLog(_T("Invalid project file!"));
}
void ProjectManager::RemoveFilesRecursively(wxTreeItemId& sel_id)
{
wxTreeItemIdValue cookie;
wxTreeItemId child;
wxString filename;
size_t i = 0;
while (i < m_pTree->GetChildrenCount(sel_id))
{
if (i == 0)
child = m_pTree->GetFirstChild(sel_id, cookie);
else
child = m_pTree->GetNextChild(sel_id, cookie);
if (child.IsOk())
{
FileTreeData* data = (FileTreeData*)m_pTree->GetItemData(child);
if (data)
{
cbProject* prj = data->GetProject();
if (prj && data->GetKind() == FileTreeData::ftdkFile)
{
ProjectFile* pf = data->GetProjectFile();
RemoveFileFromProject(pf, prj);
}
else if (data->GetKind() == FileTreeData::ftdkFolder
|| data->GetKind() == FileTreeData::ftdkVirtualFolder)
{
RemoveFilesRecursively(child);
}
}
++i;
}
else
break;
}
}
void ProjectManager::OpenFilesRecursively(wxTreeItemId& sel_id)
{
wxTreeItemIdValue cookie;
wxTreeItemId child;
wxString filename;
size_t i = 0;
while (i < m_pTree->GetChildrenCount(sel_id))
{
if (i == 0)
child = m_pTree->GetFirstChild(sel_id, cookie);
else
child = m_pTree->GetNextChild(sel_id, cookie);
if (child.IsOk())
{
FileTreeData* data = (FileTreeData*)m_pTree->GetItemData(child);
if (data)
{
cbProject* prj = data->GetProject();
if (prj && data->GetKind() == FileTreeData::ftdkFile)
{
ProjectFile* pf = data->GetProjectFile();
DoOpenFile(pf, pf->file.GetFullPath());
}
else if ( data->GetKind() == FileTreeData::ftdkFolder
|| data->GetKind() == FileTreeData::ftdkVirtualFolder )
{
OpenFilesRecursively(child);
}
}
++i;
}
else
break;
}
}
bool ProjectManager::BeginLoadingProject()
{
if (m_IsLoadingProject)
return false;
if(!Manager::Get()->GetPluginManager()->FindPluginByName(_T("Compiler")))
{
cbMessageBox(_("Deactivating the compiler plugin is most unwise.\n\nIf you intend to open a project, you have to re-activate the compiler plugin first."), _("Error"));
return false;
}
// disallow application shutdown while opening files
s_CanShutdown = false;
// flag project loading
m_IsLoadingProject = true;
return true;
}
void ProjectManager::EndLoadingProject(cbProject* project)
{
s_CanShutdown = true;
if (!m_IsLoadingProject)
return;
if (project)
{
bool newAddition = m_pProjects->Index(project) == -1;
if (newAddition)
{
m_pProjects->Add(project);
project->LoadLayout();
}
if (!m_IsLoadingWorkspace)
{
if (newAddition)
project->BuildTree(m_pTree, m_TreeRoot, m_TreeCategorize, m_TreeUseFolders, m_pFileGroups);
else
RebuildTree();
m_pTree->Expand(project->GetProjectNode());
m_pTree->Expand(m_TreeRoot); // make sure the root node is open
}
if (m_pWorkspace)
m_pWorkspace->SetModified(true);
// if loading a workspace, avoid sending the event now
// we 'll send them after all projects have been loaded
// (look in LoadWorkspace)
if (!m_IsLoadingWorkspace)
{
// notify plugins that the project is loaded
// moved here from cbProject::Open() because code-completion
// kicks in too early and the perceived loading time is long...
CodeBlocksEvent event(cbEVT_PROJECT_OPEN);
event.SetProject(project);
Manager::Get()->ProcessEvent(event);
// finally, display project notes (if appropriate)
if (project->GetShowNotesOnLoad())
project->ShowNotes(true);
}
}
/* While loading the project layout, the ProjectManager is still working.
Thus it should be set to Not Busy only at the end.*/
m_IsLoadingProject = false;
// sort out any global user vars that need to be defined now (in a batch) :)
// but only if not loading workspace (else LoadWorkspace() will handle this)
if (!m_IsLoadingWorkspace)
{
Manager::Get()->GetUserVariableManager()->Arrogate();
}
WorkspaceChanged();
}
bool ProjectManager::BeginLoadingWorkspace()
{
if (m_IsLoadingWorkspace)
return false;
m_IsLoadingWorkspace = true;
if (!CloseWorkspace())
{
m_IsLoadingWorkspace = false;
return false; // didn't close
}
FreezeTree();
m_pTree->AppendItem(m_pTree->GetRootItem(), _("Loading workspace..."));
m_pTree->Expand(m_pTree->GetRootItem());
UnfreezeTree();
return true;
}
void ProjectManager::EndLoadingWorkspace()
{
if (!m_IsLoadingWorkspace)
return;
m_IsLoadingWorkspace = false;
if (!m_pWorkspace)
return;
if (m_pWorkspace->IsOK())
{
RebuildTree();
if (m_pActiveProject || m_pProjectToActivate)
{
if (m_pProjectToActivate)
{
SetProject(m_pProjectToActivate, true);
m_pProjectToActivate = 0L;
}
m_pTree->Expand(m_pActiveProject->GetProjectNode());
}
m_pTree->Expand(m_TreeRoot); // make sure the root node is open
m_pTree->SetItemText(m_TreeRoot, m_pWorkspace->GetTitle());
UnfreezeTree(true);
// sort out any global user vars that need to be defined now (in a batch) :)
Manager::Get()->GetUserVariableManager()->Arrogate();
int numNotes = 0;
// and now send the project loaded events
// since we were loading a workspace, these events were not sent before
for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
{
cbProject* project = m_pProjects->Item(i);
// notify plugins that the project is loaded
// moved here from cbProject::Open() because code-completion
// kicks in too early and the perceived loading time is long...
CodeBlocksEvent event(cbEVT_PROJECT_OPEN);
event.SetProject(project);
Manager::Get()->GetPluginManager()->NotifyPlugins(event);
// since we 're iterating anyway, let's count the project notes that should be displayed
if (project->GetShowNotesOnLoad() && !project->GetNotes().IsEmpty())
++numNotes;
}
// finally, display projects notes (if appropriate)
if (numNotes)
{
if (numNotes == 1 || // if only one project has notes, don't bother asking
cbMessageBox(wxString::Format(_("%d projects contain notes that should be displayed on-load.\n"
"Do you want to display them now, one after the other?"),
numNotes),
_("Display project notes?"),
wxICON_QUESTION | wxYES_NO) == wxID_YES)
{
for (size_t i = 0; i < m_pProjects->GetCount(); ++i)
{
cbProject* project = m_pProjects->Item(i);
if (project->GetShowNotesOnLoad())
project->ShowNotes(true);
}
}
}
WorkspaceChanged();
}
else
{
CloseWorkspace();
}
}
void ProjectManager::OnKeyDown(wxTreeEvent& event)
{
const wxKeyEvent& key_event = event.GetKeyEvent();
if( Manager::Get()->GetProjectManager()->GetActiveProject()->GetCurrentlyCompilingTarget() == 0 &&
(key_event.GetKeyCode() == WXK_DELETE || key_event.GetKeyCode() == WXK_NUMPAD_DELETE))
{
wxCommandEvent command(0, idMenuRemoveFilePopup);
OnRemoveFileFromProject(command);
}
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.