1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
2949
2950
2951
2952
2953
2954
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
2994
2995
2996
2997
2998
2999
3000
3001
3002
3003
3004
3005
3006
3007
3008
3009
3010
3011
3012
3013
3014
3015
3016
3017
3018
3019
3020
3021
3022
3023
3024
3025
3026
3027
3028
3029
3030
3031
3032
3033
3034
3035
3036
3037
3038
3039
3040
3041
3042
3043
3044
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
3062
3063
3064
3065
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
3077
3078
3079
3080
3081
3082
3083
3084
3085
3086
3087
3088
3089
3090
3091
3092
3093
3094
3095
3096
3097
3098
3099
3100
3101
3102
3103
3104
3105
3106
3107
3108
3109
3110
3111
3112
3113
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
3125
3126
3127
3128
3129
3130
3131
3132
3133
3134
3135
3136
3137
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
3148
3149
3150
3151
3152
3153
3154
3155
3156
3157
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
3168
3169
3170
3171
3172
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
3183
3184
3185
3186
3187
3188
3189
3190
3191
3192
3193
3194
3195
3196
3197
3198
3199
3200
3201
3202
3203
3204
3205
3206
3207
3208
3209
3210
3211
3212
3213
3214
3215
3216
3217
3218
3219
3220
3221
3222
3223
3224
3225
3226
3227
3228
3229
3230
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
3242
3243
3244
3245
3246
3247
3248
3249
3250
3251
3252
3253
3254
3255
3256
3257
3258
3259
3260
3261
3262
3263
3264
3265
3266
3267
3268
3269
3270
3271
3272
3273
3274
3275
3276
3277
3278
3279
3280
3281
3282
3283
3284
3285
3286
3287
3288
3289
3290
3291
3292
3293
3294
3295
3296
3297
3298
3299
3300
3301
3302
3303
3304
3305
3306
3307
3308
3309
3310
3311
3312
3313
3314
3315
3316
3317
3318
3319
3320
3321
3322
3323
3324
3325
3326
3327
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
3339
3340
3341
3342
3343
3344
3345
3346
3347
3348
3349
3350
3351
3352
3353
3354
3355
3356
3357
3358
3359
3360
3361
3362
3363
3364
3365
3366
3367
3368
3369
3370
3371
3372
3373
3374
3375
3376
3377
3378
3379
3380
3381
3382
3383
3384
3385
3386
3387
3388
3389
3390
3391
3392
3393
3394
3395
3396
3397
3398
3399
3400
3401
3402
3403
3404
3405
3406
3407
3408
3409
3410
3411
3412
3413
3414
3415
3416
3417
3418
3419
3420
3421
3422
3423
3424
|
/****************************************************************************
**
** Copyright (C) 2015 The Qt Company Ltd.
** Contact: http://www.qt.io/licensing
**
** This file is part of Qt Creator.
**
** Commercial License Usage
** Licensees holding valid commercial Qt licenses may use this file in
** accordance with the commercial license agreement provided with the
** Software or, alternatively, in accordance with the terms contained in
** a written agreement between you and The Qt Company. For licensing terms and
** conditions see http://www.qt.io/terms-conditions. For further information
** use the contact form at http://www.qt.io/contact-us.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
** General Public License version 2.1 or version 3 as published by the Free
** Software Foundation and appearing in the file LICENSE.LGPLv21 and
** LICENSE.LGPLv3 included in the packaging of this file. Please review the
** following information to ensure the GNU Lesser General Public License
** requirements will be met: https://www.gnu.org/licenses/lgpl.html and
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
** In addition, as a special exception, The Qt Company gives you certain additional
** rights. These rights are described in The Qt Company LGPL Exception
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
**
****************************************************************************/
#include "projectexplorer.h"
#include "buildsteplist.h"
#include "configtaskhandler.h"
#include "customwizard/customwizard.h"
#include "deployablefile.h"
#include "deployconfiguration.h"
#include "gcctoolchainfactories.h"
#ifdef WITH_JOURNALD
#include "journaldwatcher.h"
#endif
#include "jsonwizard/jsonwizardfactory.h"
#include "jsonwizard/jsonwizardgeneratorfactory.h"
#include "jsonwizard/jsonwizardpagefactory_p.h"
#include "project.h"
#include "projectexplorersettings.h"
#include "removetaskhandler.h"
#include "unconfiguredprojectpanel.h"
#include "kitfeatureprovider.h"
#include "kitmanager.h"
#include "kitoptionspage.h"
#include "target.h"
#include "toolchainmanager.h"
#include "toolchainoptionspage.h"
#include "copytaskhandler.h"
#include "showineditortaskhandler.h"
#include "vcsannotatetaskhandler.h"
#include "localapplicationruncontrol.h"
#include "allprojectsfilter.h"
#include "allprojectsfind.h"
#include "buildmanager.h"
#include "buildsettingspropertiespage.h"
#include "currentprojectfind.h"
#include "currentprojectfilter.h"
#include "editorsettingspropertiespage.h"
#include "codestylesettingspropertiespage.h"
#include "dependenciespanel.h"
#include "foldernavigationwidget.h"
#include "iprojectmanager.h"
#include "nodesvisitor.h"
#include "appoutputpane.h"
#include "processstep.h"
#include "kitinformation.h"
#include "projectfilewizardextension.h"
#include "projecttreewidget.h"
#include "projectwindow.h"
#include "runsettingspropertiespage.h"
#include "session.h"
#include "projectnodes.h"
#include "sessiondialog.h"
#include "projectexplorersettingspage.h"
#include "buildconfiguration.h"
#include "miniprojecttargetselector.h"
#include "taskhub.h"
#include "customtoolchain.h"
#include "selectablefilesmodel.h"
#include "customwizard/customwizard.h"
#include "devicesupport/desktopdevice.h"
#include "devicesupport/desktopdevicefactory.h"
#include "devicesupport/devicemanager.h"
#include "devicesupport/devicesettingspage.h"
#include "targetsettingspanel.h"
#include "projectpanelfactory.h"
#include "waitforstopdialog.h"
#ifdef Q_OS_WIN
# include "windebuginterface.h"
# include "msvctoolchain.h"
# include "wincetoolchain.h"
#endif
#include "projecttree.h"
#include "projectwelcomepage.h"
#include <extensionsystem/pluginspec.h>
#include <extensionsystem/pluginmanager.h>
#include <coreplugin/icore.h>
#include <coreplugin/id.h>
#include <coreplugin/idocumentfactory.h>
#include <coreplugin/idocument.h>
#include <coreplugin/coreconstants.h>
#include <coreplugin/documentmanager.h>
#include <coreplugin/imode.h>
#include <coreplugin/modemanager.h>
#include <coreplugin/actionmanager/actionmanager.h>
#include <coreplugin/actionmanager/actioncontainer.h>
#include <coreplugin/actionmanager/command.h>
#include <coreplugin/editormanager/editormanager.h>
#include <coreplugin/findplaceholder.h>
#include <coreplugin/vcsmanager.h>
#include <coreplugin/iversioncontrol.h>
#include <coreplugin/fileutils.h>
#include <coreplugin/removefiledialog.h>
#include <texteditor/findinfiles.h>
#include <ssh/sshconnection.h>
#include <utils/algorithm.h>
#include <utils/fileutils.h>
#include <utils/macroexpander.h>
#include <utils/mimetypes/mimedatabase.h>
#include <utils/parameteraction.h>
#include <utils/qtcassert.h>
#include <utils/stringutils.h>
#include <utils/themehelper.h>
#include <QtPlugin>
#include <QDebug>
#include <QFileInfo>
#include <QSettings>
#include <QAction>
#include <QApplication>
#include <QDir>
#include <QFileDialog>
#include <QMenu>
#include <QMessageBox>
#include <QTimer>
/*!
\namespace ProjectExplorer
The ProjectExplorer namespace contains the classes to explore projects.
*/
/*!
\namespace ProjectExplorer::Internal
The ProjectExplorer::Internal namespace is the internal namespace of the
ProjectExplorer plugin.
\internal
*/
/*!
\class ProjectExplorer::ProjectExplorerPlugin
\brief The ProjectExplorerPlugin class contains static accessor and utility
functions to obtain the current project, open projects, and so on.
*/
namespace {
bool debug = false;
}
using namespace Core;
using namespace ProjectExplorer::Internal;
namespace ProjectExplorer {
static Target *activeTarget()
{
Project *project = ProjectTree::currentProject();
return project ? project->activeTarget() : 0;
}
static BuildConfiguration *activeBuildConfiguration()
{
Target *target = activeTarget();
return target ? target->activeBuildConfiguration() : 0;
}
static Kit *currentKit()
{
Target *target = activeTarget();
return target ? target->kit() : 0;
}
class ProjectExplorerPluginPrivate : public QObject
{
Q_DECLARE_TR_FUNCTIONS(ProjectExplorer::ProjectExplorerPlugin)
public:
ProjectExplorerPluginPrivate();
void deploy(QList<Project *>);
int queue(QList<Project *>, QList<Id> stepIds);
void updateContextMenuActions();
void executeRunConfiguration(RunConfiguration *, Core::Id mode);
QPair<bool, QString> buildSettingsEnabledForSession();
QPair<bool, QString> buildSettingsEnabled(Project *pro);
void addToRecentProjects(const QString &fileName, const QString &displayName);
void startRunControl(RunControl *runControl, Core::Id runMode);
void updateActions();
void updateContext();
void updateDeployActions();
void updateRunWithoutDeployMenu();
void buildQueueFinished(bool success);
void buildStateChanged(ProjectExplorer::Project * pro);
void buildProjectOnly();
void handleBuildProject();
void buildProjectContextMenu();
void buildProjectDependenciesContextMenu();
void buildSession();
void rebuildProjectOnly();
void rebuildProject();
void rebuildProjectContextMenu();
void rebuildProjectDependenciesContextMenu();
void rebuildSession();
void deployProjectOnly();
void deployProject();
void deployProjectContextMenu();
void deploySession();
void cleanProjectOnly();
void cleanProject();
void cleanProjectContextMenu();
void cleanProjectDependenciesContextMenu();
void cleanSession();
void cancelBuild();
void loadAction();
void handleUnloadProject();
void unloadProjectContextMenu();
void closeAllProjects();
void newProject();
void showSessionManager();
void updateSessionMenu();
void setSession(QAction *action);
void determineSessionToRestoreAtStartup();
void restoreSession();
void loadSession(const QString &session);
void handleRunProject();
void runProjectContextMenu();
void runProjectWithoutDeploy();
void savePersistentSettings();
void addNewFile();
void handleAddExistingFiles();
void addExistingDirectory();
void addNewSubproject();
void removeProject();
void openFile();
void searchOnFileSystem();
void showInGraphicalShell();
void removeFile();
void deleteFile();
void handleRenameFile();
void handleSetStartupProject();
void setStartupProject(ProjectExplorer::Project *project);
void updateRecentProjectMenu();
void clearRecentProjects();
void openRecentProject(const QString &fileName);
void updateUnloadProjectMenu();
void openTerminalHere();
void invalidateProject(ProjectExplorer::Project *project);
void projectAdded(ProjectExplorer::Project *pro);
void projectRemoved(ProjectExplorer::Project *pro);
void projectDisplayNameChanged(ProjectExplorer::Project *pro);
void startupProjectChanged(); // Calls updateRunAction
void activeTargetChanged();
void activeRunConfigurationChanged();
void slotUpdateRunActions();
void currentModeChanged(Core::IMode *mode, Core::IMode *oldMode);
void updateWelcomePage();
void runConfigurationConfigurationFinished();
public:
QMenu *m_sessionMenu;
QMenu *m_openWithMenu;
QMultiMap<int, QObject*> m_actionMap;
QAction *m_sessionManagerAction;
QAction *m_newAction;
QAction *m_loadAction;
Utils::ParameterAction *m_unloadAction;
Utils::ParameterAction *m_unloadActionContextMenu;
QAction *m_closeAllProjects;
QAction *m_buildProjectOnlyAction;
Utils::ParameterAction *m_buildAction;
QAction *m_buildActionContextMenu;
QAction *m_buildDependenciesActionContextMenu;
QAction *m_buildSessionAction;
QAction *m_rebuildProjectOnlyAction;
Utils::ParameterAction *m_rebuildAction;
QAction *m_rebuildActionContextMenu;
QAction *m_rebuildDependenciesActionContextMenu;
QAction *m_rebuildSessionAction;
QAction *m_cleanProjectOnlyAction;
QAction *m_deployProjectOnlyAction;
Utils::ParameterAction *m_deployAction;
QAction *m_deployActionContextMenu;
QAction *m_deploySessionAction;
Utils::ParameterAction *m_cleanAction;
QAction *m_cleanActionContextMenu;
QAction *m_cleanDependenciesActionContextMenu;
QAction *m_cleanSessionAction;
QAction *m_runAction;
QAction *m_runActionContextMenu;
QAction *m_runWithoutDeployAction;
QAction *m_cancelBuildAction;
QAction *m_addNewFileAction;
QAction *m_addExistingFilesAction;
QAction *m_addExistingDirectoryAction;
QAction *m_addNewSubprojectAction;
QAction *m_removeFileAction;
QAction *m_removeProjectAction;
QAction *m_deleteFileAction;
QAction *m_renameFileAction;
QAction *m_openFileAction;
QAction *m_projectTreeCollapseAllAction;
QAction *m_searchOnFileSystem;
QAction *m_showInGraphicalShell;
QAction *m_openTerminalHere;
Utils::ParameterAction *m_setStartupProjectAction;
QAction *m_projectSelectorAction;
QAction *m_projectSelectorActionMenu;
QAction *m_projectSelectorActionQuick;
QAction *m_runSubProject;
ProjectWindow *m_proWindow;
QString m_sessionToRestoreAtStartup;
QStringList m_profileMimeTypes;
AppOutputPane *m_outputPane;
QList<QPair<QString, QString> > m_recentProjects; // pair of filename, displayname
static const int m_maxRecentProjects = 25;
QString m_lastOpenDirectory;
QPointer<RunConfiguration> m_delayedRunConfiguration;
QList<QPair<RunConfiguration *, Core::Id>> m_delayedRunConfigurationForRun;
bool m_shouldHaveRunConfiguration;
Core::Id m_runMode;
QString m_projectFilterString;
MiniProjectTargetSelector * m_targetSelector;
ProjectExplorerSettings m_projectExplorerSettings;
ProjectWelcomePage *m_welcomePage = nullptr;
IMode *m_projectsMode;
TaskHub *m_taskHub;
KitManager *m_kitManager;
ToolChainManager *m_toolChainManager;
bool m_shuttingDown;
QStringList m_arguments;
QList<ProjectPanelFactory *> m_panelFactories;
#ifdef WITH_JOURNALD
JournaldWatcher *m_journalWatcher;
#endif
};
ProjectExplorerPluginPrivate::ProjectExplorerPluginPrivate() :
m_shouldHaveRunConfiguration(false),
m_runMode(Constants::NO_RUN_MODE),
m_projectsMode(0),
m_kitManager(0),
m_toolChainManager(0),
m_shuttingDown(false)
#ifdef WITH_JOURNALD
, m_journalWatcher(0)
#endif
{
}
class ProjectsMode : public IMode
{
public:
ProjectsMode(QWidget *proWindow)
{
setWidget(proWindow);
setContext(Context(Constants::C_PROJECTEXPLORER));
setDisplayName(QCoreApplication::translate("ProjectExplorer::ProjectsMode", "Projects"));
setIcon(QIcon(QLatin1String(":/projectexplorer/images/mode_project.png")));
setPriority(Constants::P_MODE_SESSION);
setId(Constants::MODE_SESSION);
setContextHelpId(QLatin1String("Managing Projects"));
}
};
static ProjectExplorerPlugin *m_instance = 0;
static ProjectExplorerPluginPrivate *dd = 0;
ProjectExplorerPlugin::ProjectExplorerPlugin()
{
m_instance = this;
dd = new ProjectExplorerPluginPrivate;
}
ProjectExplorerPlugin::~ProjectExplorerPlugin()
{
JsonWizardFactory::destroyAllFactories();
// Force sequence of deletion:
delete dd->m_kitManager; // remove all the profile information
delete dd->m_toolChainManager;
#ifdef WITH_JOURNALD
delete dd->m_journalWatcher;
#endif
ProjectPanelFactory::destroyFactories();
delete dd;
}
ProjectExplorerPlugin *ProjectExplorerPlugin::instance()
{
return m_instance;
}
static void updateActions()
{
dd->updateActions();
}
bool ProjectExplorerPlugin::initialize(const QStringList &arguments, QString *error)
{
Q_UNUSED(error);
qRegisterMetaType<ProjectExplorer::RunControl *>();
qRegisterMetaType<ProjectExplorer::DeployableFile>("ProjectExplorer::DeployableFile");
CustomWizard::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
JsonWizardFactory::setVerbose(arguments.count(QLatin1String("-customwizard-verbose")));
addObject(this);
addAutoReleasedObject(new DeviceManager);
#ifdef WITH_JOURNALD
dd->m_journalWatcher = new JournaldWatcher;
#endif
// Add ToolChainFactories:
#ifdef Q_OS_WIN
addAutoReleasedObject(new WinDebugInterface);
addAutoReleasedObject(new MsvcToolChainFactory);
addAutoReleasedObject(new WinCEToolChainFactory);
#else
addAutoReleasedObject(new LinuxIccToolChainFactory);
#endif
#ifndef Q_OS_MAC
addAutoReleasedObject(new MingwToolChainFactory); // Mingw offers cross-compiling to windows
#endif
addAutoReleasedObject(new GccToolChainFactory);
addAutoReleasedObject(new ClangToolChainFactory);
addAutoReleasedObject(new CustomToolChainFactory);
addAutoReleasedObject(new DesktopDeviceFactory);
dd->m_kitManager = new KitManager; // register before ToolChainManager
dd->m_toolChainManager = new ToolChainManager;
IWizardFactory::registerFeatureProvider(new KitFeatureProvider);
// Register KitInformation:
KitManager::registerKitInformation(new DeviceTypeKitInformation);
KitManager::registerKitInformation(new DeviceKitInformation);
KitManager::registerKitInformation(new ToolChainKitInformation);
KitManager::registerKitInformation(new SysRootKitInformation);
KitManager::registerKitInformation(new EnvironmentKitInformation);
addAutoReleasedObject(new ToolChainOptionsPage);
addAutoReleasedObject(new KitOptionsPage);
addAutoReleasedObject(new TaskHub);
IWizardFactory::registerFactoryCreator([]() -> QList<IWizardFactory *> {
QList<IWizardFactory *> result;
result << CustomWizard::createWizards();
result << JsonWizardFactory::createWizardFactories();
return result;
});
dd->m_welcomePage = new ProjectWelcomePage;
connect(dd->m_welcomePage, &ProjectWelcomePage::manageSessions,
dd, &ProjectExplorerPluginPrivate::showSessionManager);
addObject(dd->m_welcomePage);
auto sessionManager = new SessionManager(this);
connect(sessionManager, &SessionManager::projectAdded,
this, &ProjectExplorerPlugin::fileListChanged);
connect(sessionManager, &SessionManager::aboutToRemoveProject,
dd, &ProjectExplorerPluginPrivate::invalidateProject);
connect(sessionManager, &SessionManager::projectRemoved,
this, &ProjectExplorerPlugin::fileListChanged);
connect(sessionManager, &SessionManager::projectAdded,
dd, &ProjectExplorerPluginPrivate::projectAdded);
connect(sessionManager, &SessionManager::projectRemoved,
dd, &ProjectExplorerPluginPrivate::projectRemoved);
connect(sessionManager, &SessionManager::startupProjectChanged,
dd, &ProjectExplorerPluginPrivate::startupProjectChanged);
connect(sessionManager, &SessionManager::projectDisplayNameChanged,
dd, &ProjectExplorerPluginPrivate::projectDisplayNameChanged);
connect(sessionManager, &SessionManager::dependencyChanged, updateActions);
connect(sessionManager, &SessionManager::sessionLoaded, updateActions);
connect(sessionManager, &SessionManager::sessionLoaded,
dd, &ProjectExplorerPluginPrivate::updateWelcomePage);
ProjectTree *tree = new ProjectTree(this);
connect(tree, &ProjectTree::currentProjectChanged,
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
connect(tree, &ProjectTree::currentNodeChanged,
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
connect(tree, &ProjectTree::currentProjectChanged, updateActions);
addAutoReleasedObject(new CustomWizardMetaFactory<CustomProjectWizard>(IWizardFactory::ProjectWizard));
addAutoReleasedObject(new CustomWizardMetaFactory<CustomWizard>(IWizardFactory::FileWizard));
// For JsonWizard:
JsonWizardFactory::registerPageFactory(new FieldPageFactory);
JsonWizardFactory::registerPageFactory(new FilePageFactory);
JsonWizardFactory::registerPageFactory(new KitsPageFactory);
JsonWizardFactory::registerPageFactory(new ProjectPageFactory);
JsonWizardFactory::registerPageFactory(new SummaryPageFactory);
JsonWizardFactory::registerGeneratorFactory(new FileGeneratorFactory);
JsonWizardFactory::registerGeneratorFactory(new ScannerGeneratorFactory);
dd->m_proWindow = new ProjectWindow;
addAutoReleasedObject(dd->m_proWindow);
Context projecTreeContext(Constants::C_PROJECT_TREE);
dd->m_projectsMode = new ProjectsMode(dd->m_proWindow);
dd->m_projectsMode->setEnabled(false);
addAutoReleasedObject(dd->m_projectsMode);
dd->m_proWindow->layout()->addWidget(new FindToolBarPlaceHolder(dd->m_proWindow));
addAutoReleasedObject(new CopyTaskHandler);
addAutoReleasedObject(new ShowInEditorTaskHandler);
addAutoReleasedObject(new VcsAnnotateTaskHandler);
addAutoReleasedObject(new RemoveTaskHandler);
addAutoReleasedObject(new ConfigTaskHandler(Task::compilerMissingTask(),
Constants::KITS_SETTINGS_PAGE_ID));
ICore::addPreCloseListener([this]() -> bool { return coreAboutToClose(); });
dd->m_outputPane = new AppOutputPane;
addAutoReleasedObject(dd->m_outputPane);
connect(SessionManager::instance(), &SessionManager::projectRemoved,
dd->m_outputPane, &AppOutputPane::projectRemoved);
connect(dd->m_outputPane, &AppOutputPane::runControlStarted,
this, &ProjectExplorerPlugin::runControlStarted);
connect(dd->m_outputPane, &AppOutputPane::runControlFinished,
this, &ProjectExplorerPlugin::runControlFinished);
connect(dd->m_outputPane, &AppOutputPane::runControlFinished,
this, &ProjectExplorerPlugin::updateRunActions);
addAutoReleasedObject(new AllProjectsFilter);
addAutoReleasedObject(new CurrentProjectFilter);
// ProjectPanelFactories
auto editorSettingsPanelFactory = new ProjectPanelFactory;
editorSettingsPanelFactory->setPriority(30);
QString displayName = QCoreApplication::translate("EditorSettingsPanelFactory", "Editor");
editorSettingsPanelFactory->setDisplayName(displayName);
QIcon icon = QIcon(QLatin1String(":/projectexplorer/images/EditorSettings.png"));
editorSettingsPanelFactory->setSimpleCreateWidgetFunction<EditorSettingsWidget>(icon);
ProjectPanelFactory::registerFactory(editorSettingsPanelFactory);
auto codeStyleSettingsPanelFactory = new ProjectPanelFactory;
codeStyleSettingsPanelFactory->setPriority(40);
displayName = QCoreApplication::translate("CodeStyleSettingsPanelFactory", "Code Style");
codeStyleSettingsPanelFactory->setDisplayName(displayName);
icon = QIcon(QLatin1String(":/projectexplorer/images/CodeStyleSettings.png"));
codeStyleSettingsPanelFactory->setSimpleCreateWidgetFunction<CodeStyleSettingsWidget>(icon);
ProjectPanelFactory::registerFactory(codeStyleSettingsPanelFactory);
auto dependenciesPanelFactory = new ProjectPanelFactory;
dependenciesPanelFactory->setPriority(50);
displayName = QCoreApplication::translate("DependenciesPanelFactory", "Dependencies");
dependenciesPanelFactory->setDisplayName(displayName);
icon = QIcon(QLatin1String(":/projectexplorer/images/ProjectDependencies.png"));
dependenciesPanelFactory->setSimpleCreateWidgetFunction<DependenciesWidget>(icon);
ProjectPanelFactory::registerFactory(dependenciesPanelFactory);
auto unconfiguredProjectPanel = new ProjectPanelFactory;
unconfiguredProjectPanel->setPriority(-10);
unconfiguredProjectPanel->setDisplayName(tr("Configure Project"));
unconfiguredProjectPanel->setSupportsFunction([](Project *project){
return project->needsConfiguration();
});
icon = QIcon(QLatin1String(":/projectexplorer/images/unconfigured.png"));
unconfiguredProjectPanel->setSimpleCreateWidgetFunction<TargetSetupPageWrapper>(icon);
ProjectPanelFactory::registerFactory(unconfiguredProjectPanel);
auto targetSettingsPanelFactory = new ProjectPanelFactory;
targetSettingsPanelFactory->setPriority(-10);
displayName = QCoreApplication::translate("TargetSettingsPanelFactory", "Build & Run");
targetSettingsPanelFactory->setDisplayName(displayName);
targetSettingsPanelFactory->setSupportsFunction([](Project *project) {
return project->requiresTargetPanel();
});
targetSettingsPanelFactory->setCreateWidgetFunction([](Project *project) {
return new TargetSettingsPanelWidget(project);
});
ProjectPanelFactory::registerFactory(targetSettingsPanelFactory);
addAutoReleasedObject(new ProcessStepFactory);
addAutoReleasedObject(new AllProjectsFind);
addAutoReleasedObject(new CurrentProjectFind);
addAutoReleasedObject(new LocalApplicationRunControlFactory);
addAutoReleasedObject(new ProjectFileWizardExtension);
// Settings pages
addAutoReleasedObject(new ProjectExplorerSettingsPage);
addAutoReleasedObject(new DeviceSettingsPage);
// context menus
ActionContainer *msessionContextMenu =
ActionManager::createMenu(Constants::M_SESSIONCONTEXT);
ActionContainer *mprojectContextMenu =
ActionManager::createMenu(Constants::M_PROJECTCONTEXT);
ActionContainer *msubProjectContextMenu =
ActionManager::createMenu(Constants::M_SUBPROJECTCONTEXT);
ActionContainer *mfolderContextMenu =
ActionManager::createMenu(Constants::M_FOLDERCONTEXT);
ActionContainer *mfileContextMenu =
ActionManager::createMenu(Constants::M_FILECONTEXT);
ActionContainer *mfile =
ActionManager::actionContainer(Core::Constants::M_FILE);
ActionContainer *menubar =
ActionManager::actionContainer(Core::Constants::MENU_BAR);
// build menu
ActionContainer *mbuild =
ActionManager::createMenu(Constants::M_BUILDPROJECT);
mbuild->menu()->setTitle(tr("&Build"));
menubar->addMenu(mbuild, Core::Constants::G_VIEW);
// debug menu
ActionContainer *mdebug =
ActionManager::createMenu(Constants::M_DEBUG);
mdebug->menu()->setTitle(tr("&Debug"));
menubar->addMenu(mdebug, Core::Constants::G_VIEW);
ActionContainer *mstartdebugging =
ActionManager::createMenu(Constants::M_DEBUG_STARTDEBUGGING);
mstartdebugging->menu()->setTitle(tr("&Start Debugging"));
mdebug->addMenu(mstartdebugging, Core::Constants::G_DEFAULT_ONE);
//
// Groups
//
mbuild->appendGroup(Constants::G_BUILD_BUILD);
mbuild->appendGroup(Constants::G_BUILD_DEPLOY);
mbuild->appendGroup(Constants::G_BUILD_REBUILD);
mbuild->appendGroup(Constants::G_BUILD_CLEAN);
mbuild->appendGroup(Constants::G_BUILD_CANCEL);
mbuild->appendGroup(Constants::G_BUILD_RUN);
msessionContextMenu->appendGroup(Constants::G_SESSION_BUILD);
msessionContextMenu->appendGroup(Constants::G_SESSION_REBUILD);
msessionContextMenu->appendGroup(Constants::G_SESSION_FILES);
msessionContextMenu->appendGroup(Constants::G_SESSION_OTHER);
msessionContextMenu->appendGroup(Constants::G_PROJECT_TREE);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_REBUILD);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
mprojectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FIRST);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_BUILD);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_RUN);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_FILES);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_LAST);
msubProjectContextMenu->appendGroup(Constants::G_PROJECT_TREE);
ActionContainer *runMenu = ActionManager::createMenu(Constants::RUNMENUCONTEXTMENU);
runMenu->setOnAllDisabledBehavior(ActionContainer::Hide);
QIcon runIcon = QIcon(QLatin1String(Constants::ICON_RUN));
runIcon.addPixmap(Utils::ThemeHelper::themedIconPixmap(QLatin1String(Constants::ICON_RUN_SMALL)));
runMenu->menu()->setIcon(runIcon);
runMenu->menu()->setTitle(tr("Run"));
msubProjectContextMenu->addMenu(runMenu, ProjectExplorer::Constants::G_PROJECT_RUN);
mfolderContextMenu->appendGroup(Constants::G_FOLDER_FILES);
mfolderContextMenu->appendGroup(Constants::G_FOLDER_OTHER);
mfolderContextMenu->appendGroup(Constants::G_FOLDER_CONFIG);
mfolderContextMenu->appendGroup(Constants::G_PROJECT_TREE);
mfileContextMenu->appendGroup(Constants::G_FILE_OPEN);
mfileContextMenu->appendGroup(Constants::G_FILE_OTHER);
mfileContextMenu->appendGroup(Constants::G_FILE_CONFIG);
mfileContextMenu->appendGroup(Constants::G_PROJECT_TREE);
// "open with" submenu
ActionContainer * const openWith =
ActionManager::createMenu(ProjectExplorer::Constants::M_OPENFILEWITHCONTEXT);
openWith->setOnAllDisabledBehavior(ActionContainer::Show);
dd->m_openWithMenu = openWith->menu();
dd->m_openWithMenu->setTitle(tr("Open With"));
//
// Separators
//
Command *cmd;
msessionContextMenu->addSeparator(projecTreeContext, Constants::G_SESSION_REBUILD);
msessionContextMenu->addSeparator(projecTreeContext, Constants::G_SESSION_FILES);
mprojectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
msubProjectContextMenu->addSeparator(projecTreeContext, Constants::G_PROJECT_FILES);
mfile->addSeparator(Core::Constants::G_FILE_PROJECT);
mbuild->addSeparator(Constants::G_BUILD_REBUILD);
msessionContextMenu->addSeparator(Constants::G_SESSION_OTHER);
mbuild->addSeparator(Constants::G_BUILD_CANCEL);
mbuild->addSeparator(Constants::G_BUILD_RUN);
mprojectContextMenu->addSeparator(Constants::G_PROJECT_REBUILD);
//
// Actions
//
// new action
dd->m_newAction = new QAction(tr("New Project..."), this);
cmd = ActionManager::registerAction(dd->m_newAction, Constants::NEWPROJECT);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+N")));
msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);
// open action
dd->m_loadAction = new QAction(tr("Load Project..."), this);
cmd = ActionManager::registerAction(dd->m_loadAction, Constants::LOAD);
#ifndef Q_OS_MAC
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+O")));
#endif
msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);
// Default open action
dd->m_openFileAction = new QAction(tr("Open File"), this);
cmd = ActionManager::registerAction(dd->m_openFileAction, Constants::OPENFILE,
projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
dd->m_searchOnFileSystem = new QAction(FileUtils::msgFindInDirectory(), this);
cmd = ActionManager::registerAction(dd->m_searchOnFileSystem, Constants::SEARCHONFILESYSTEM, projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_CONFIG);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
dd->m_showInGraphicalShell = new QAction(FileUtils::msgGraphicalShellAction(), this);
cmd = ActionManager::registerAction(dd->m_showInGraphicalShell, Constants::SHOWINGRAPHICALSHELL,
projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
dd->m_openTerminalHere = new QAction(FileUtils::msgTerminalAction(), this);
cmd = ActionManager::registerAction(dd->m_openTerminalHere, Constants::OPENTERMIANLHERE,
projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OPEN);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
// Open With menu
mfileContextMenu->addMenu(openWith, Constants::G_FILE_OPEN);
// recent projects menu
ActionContainer *mrecent =
ActionManager::createMenu(Constants::M_RECENTPROJECTS);
mrecent->menu()->setTitle(tr("Recent P&rojects"));
mrecent->setOnAllDisabledBehavior(ActionContainer::Show);
mfile->addMenu(mrecent, Core::Constants::G_FILE_OPEN);
connect(mfile->menu(), &QMenu::aboutToShow,
dd, &ProjectExplorerPluginPrivate::updateRecentProjectMenu);
// session menu
ActionContainer *msession = ActionManager::createMenu(Constants::M_SESSION);
msession->menu()->setTitle(tr("Sessions"));
msession->setOnAllDisabledBehavior(ActionContainer::Show);
mfile->addMenu(msession, Core::Constants::G_FILE_OPEN);
dd->m_sessionMenu = msession->menu();
connect(mfile->menu(), &QMenu::aboutToShow,
dd, &ProjectExplorerPluginPrivate::updateSessionMenu);
// session manager action
dd->m_sessionManagerAction = new QAction(tr("Session Manager..."), this);
cmd = ActionManager::registerAction(dd->m_sessionManagerAction, Constants::NEWSESSION);
mfile->addAction(cmd, Core::Constants::G_FILE_OPEN);
cmd->setDefaultKeySequence(QKeySequence());
// unload action
dd->m_unloadAction = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
cmd = ActionManager::registerAction(dd->m_unloadAction, Constants::UNLOAD);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_unloadAction->text());
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
ActionContainer *munload =
ActionManager::createMenu(Constants::M_UNLOADPROJECTS);
munload->menu()->setTitle(tr("Close Project"));
munload->setOnAllDisabledBehavior(ActionContainer::Show);
mfile->addMenu(munload, Core::Constants::G_FILE_PROJECT);
connect(mfile->menu(), &QMenu::aboutToShow,
dd, &ProjectExplorerPluginPrivate::updateUnloadProjectMenu);
// unload session action
dd->m_closeAllProjects = new QAction(tr("Close All Projects and Editors"), this);
cmd = ActionManager::registerAction(dd->m_closeAllProjects, Constants::CLEARSESSION);
mfile->addAction(cmd, Core::Constants::G_FILE_PROJECT);
msessionContextMenu->addAction(cmd, Constants::G_SESSION_FILES);
// build session action
QIcon buildIcon = QIcon(QLatin1String(Constants::ICON_BUILD));
buildIcon.addFile(QLatin1String(Constants::ICON_BUILD_SMALL));
dd->m_buildSessionAction = new QAction(buildIcon, tr("Build All"), this);
cmd = ActionManager::registerAction(dd->m_buildSessionAction, Constants::BUILDSESSION);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+Shift+B")));
mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);
// deploy session
dd->m_deploySessionAction = new QAction(tr("Deploy All"), this);
cmd = ActionManager::registerAction(dd->m_deploySessionAction, Constants::DEPLOYSESSION);
mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);
msessionContextMenu->addAction(cmd, Constants::G_SESSION_BUILD);
// rebuild session action
QIcon rebuildIcon = QIcon(QLatin1String(Constants::ICON_REBUILD));
rebuildIcon.addFile(QLatin1String(Constants::ICON_REBUILD_SMALL));
dd->m_rebuildSessionAction = new QAction(rebuildIcon, tr("Rebuild All"), this);
cmd = ActionManager::registerAction(dd->m_rebuildSessionAction, Constants::REBUILDSESSION);
mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
// clean session
QIcon cleanIcon = QIcon(QLatin1String(Constants::ICON_CLEAN));
cleanIcon.addFile(QLatin1String(Constants::ICON_CLEAN_SMALL));
dd->m_cleanSessionAction = new QAction(cleanIcon, tr("Clean All"), this);
cmd = ActionManager::registerAction(dd->m_cleanSessionAction, Constants::CLEANSESSION);
mbuild->addAction(cmd, Constants::G_BUILD_CLEAN);
msessionContextMenu->addAction(cmd, Constants::G_SESSION_REBUILD);
// build action
dd->m_buildAction = new Utils::ParameterAction(tr("Build Project"), tr("Build Project \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
dd->m_buildAction->setIcon(buildIcon);
cmd = ActionManager::registerAction(dd->m_buildAction, Constants::BUILD);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_buildAction->text());
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+B")));
mbuild->addAction(cmd, Constants::G_BUILD_BUILD);
// Add to mode bar
ModeManager::addAction(cmd->action(), Constants::P_ACTION_BUILDPROJECT);
// deploy action
dd->m_deployAction = new Utils::ParameterAction(tr("Deploy Project"), tr("Deploy Project \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
cmd = ActionManager::registerAction(dd->m_deployAction, Constants::DEPLOY);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_deployAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_DEPLOY);
// rebuild action
dd->m_rebuildAction = new Utils::ParameterAction(tr("Rebuild Project"), tr("Rebuild Project \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
cmd = ActionManager::registerAction(dd->m_rebuildAction, Constants::REBUILD);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_rebuildAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_REBUILD);
// clean action
dd->m_cleanAction = new Utils::ParameterAction(tr("Clean Project"), tr("Clean Project \"%1\""),
Utils::ParameterAction::AlwaysEnabled, this);
cmd = ActionManager::registerAction(dd->m_cleanAction, Constants::CLEAN);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_cleanAction->text());
mbuild->addAction(cmd, Constants::G_BUILD_CLEAN);
// cancel build action
const QIcon stopIcon = Utils::ThemeHelper::themedIcon(QLatin1String(Constants::ICON_STOP_SMALL));
dd->m_cancelBuildAction = new QAction(stopIcon, tr("Cancel Build"), this);
cmd = ActionManager::registerAction(dd->m_cancelBuildAction, Constants::CANCELBUILD);
mbuild->addAction(cmd, Constants::G_BUILD_CANCEL);
// run action
dd->m_runAction = new QAction(runIcon, tr("Run"), this);
cmd = ActionManager::registerAction(dd->m_runAction, Constants::RUN);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+R")));
mbuild->addAction(cmd, Constants::G_BUILD_RUN);
ModeManager::addAction(cmd->action(), Constants::P_ACTION_RUN);
// Run without deployment action
dd->m_runWithoutDeployAction = new QAction(tr("Run Without Deployment"), this);
cmd = ActionManager::registerAction(dd->m_runWithoutDeployAction, Constants::RUNWITHOUTDEPLOY);
mbuild->addAction(cmd, Constants::G_BUILD_RUN);
// build action with dependencies (context menu)
dd->m_buildDependenciesActionContextMenu = new QAction(tr("Build"), this);
cmd = ActionManager::registerAction(dd->m_buildDependenciesActionContextMenu, Constants::BUILDDEPENDCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// build action (context menu)
dd->m_buildActionContextMenu = new QAction(tr("Build Without Dependencies"), this);
cmd = ActionManager::registerAction(dd->m_buildActionContextMenu, Constants::BUILDCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_BUILD);
// rebuild action with dependencies (context menu)
dd->m_rebuildDependenciesActionContextMenu = new QAction(tr("Rebuild"), this);
cmd = ActionManager::registerAction(dd->m_rebuildDependenciesActionContextMenu, Constants::REBUILDDEPENDCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
// rebuild action (context menu)
dd->m_rebuildActionContextMenu = new QAction(tr("Rebuild Without Dependencies"), this);
cmd = ActionManager::registerAction(dd->m_rebuildActionContextMenu, Constants::REBUILDCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
// clean action with dependencies (context menu)
dd->m_cleanDependenciesActionContextMenu = new QAction(tr("Clean"), this);
cmd = ActionManager::registerAction(dd->m_cleanDependenciesActionContextMenu, Constants::CLEANDEPENDCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
// clean action (context menu)
dd->m_cleanActionContextMenu = new QAction(tr("Clean Without Dependencies"), this);
cmd = ActionManager::registerAction(dd->m_cleanActionContextMenu, Constants::CLEANCM, projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_REBUILD);
// build without dependencies action
dd->m_buildProjectOnlyAction = new QAction(tr("Build Without Dependencies"), this);
ActionManager::registerAction(dd->m_buildProjectOnlyAction, Constants::BUILDPROJECTONLY);
// rebuild without dependencies action
dd->m_rebuildProjectOnlyAction = new QAction(tr("Rebuild Without Dependencies"), this);
ActionManager::registerAction(dd->m_rebuildProjectOnlyAction, Constants::REBUILDPROJECTONLY);
// deploy without dependencies action
dd->m_deployProjectOnlyAction = new QAction(tr("Deploy Without Dependencies"), this);
ActionManager::registerAction(dd->m_deployProjectOnlyAction, Constants::DEPLOYPROJECTONLY);
// clean without dependencies action
dd->m_cleanProjectOnlyAction = new QAction(tr("Clean Without Dependencies"), this);
ActionManager::registerAction(dd->m_cleanProjectOnlyAction, Constants::CLEANPROJECTONLY);
// deploy action (context menu)
dd->m_deployActionContextMenu = new QAction(tr("Deploy"), this);
cmd = ActionManager::registerAction(dd->m_deployActionContextMenu, Constants::DEPLOYCM, projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_RUN);
dd->m_runActionContextMenu = new QAction(runIcon, tr("Run"), this);
cmd = ActionManager::registerAction(dd->m_runActionContextMenu, Constants::RUNCONTEXTMENU, projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_RUN);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_RUN);
// add new file action
dd->m_addNewFileAction = new QAction(tr("Add New..."), this);
cmd = ActionManager::registerAction(dd->m_addNewFileAction, Constants::ADDNEWFILE,
projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
// add existing file action
dd->m_addExistingFilesAction = new QAction(tr("Add Existing Files..."), this);
cmd = ActionManager::registerAction(dd->m_addExistingFilesAction, Constants::ADDEXISTINGFILES,
projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
// add existing directory action
dd->m_addExistingDirectoryAction = new QAction(tr("Add Existing Directory..."), this);
cmd = ActionManager::registerAction(dd->m_addExistingDirectoryAction,
Constants::ADDEXISTINGDIRECTORY,
projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
mfolderContextMenu->addAction(cmd, Constants::G_FOLDER_FILES);
// new subproject action
dd->m_addNewSubprojectAction = new QAction(tr("New Subproject..."), this);
cmd = ActionManager::registerAction(dd->m_addNewSubprojectAction, Constants::ADDNEWSUBPROJECT,
projecTreeContext);
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
// unload project again, in right position
dd->m_unloadActionContextMenu = new Utils::ParameterAction(tr("Close Project"), tr("Close Project \"%1\""),
Utils::ParameterAction::EnabledWithParameter, this);
cmd = ActionManager::registerAction(dd->m_unloadActionContextMenu, Constants::UNLOADCM);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_unloadActionContextMenu->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_LAST);
// remove file action
dd->m_removeFileAction = new QAction(tr("Remove File..."), this);
cmd = ActionManager::registerAction(dd->m_removeFileAction, Constants::REMOVEFILE,
projecTreeContext);
cmd->setDefaultKeySequence(QKeySequence::Delete);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
//: Remove project from parent profile (Project explorer view); will not physically delete any files.
dd->m_removeProjectAction = new QAction(tr("Remove Project..."), this);
cmd = ActionManager::registerAction(dd->m_removeProjectAction, Constants::REMOVEPROJECT,
projecTreeContext);
msubProjectContextMenu->addAction(cmd, Constants::G_PROJECT_FILES);
// delete file action
dd->m_deleteFileAction = new QAction(tr("Delete File..."), this);
cmd = ActionManager::registerAction(dd->m_deleteFileAction, Constants::DELETEFILE,
projecTreeContext);
cmd->setDefaultKeySequence(QKeySequence::Delete);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
// renamefile action
dd->m_renameFileAction = new QAction(tr("Rename..."), this);
cmd = ActionManager::registerAction(dd->m_renameFileAction, Constants::RENAMEFILE,
projecTreeContext);
mfileContextMenu->addAction(cmd, Constants::G_FILE_OTHER);
// Not yet used by anyone, so hide for now
// mfolder->addAction(cmd, Constants::G_FOLDER_FILES);
// msubProject->addAction(cmd, Constants::G_FOLDER_FILES);
// mproject->addAction(cmd, Constants::G_FOLDER_FILES);
// set startup project action
dd->m_setStartupProjectAction = new Utils::ParameterAction(tr("Set as Active Project"),
tr("Set \"%1\" as Active Project"),
Utils::ParameterAction::AlwaysEnabled, this);
cmd = ActionManager::registerAction(dd->m_setStartupProjectAction, Constants::SETSTARTUP,
projecTreeContext);
cmd->setAttribute(Command::CA_UpdateText);
cmd->setDescription(dd->m_setStartupProjectAction->text());
mprojectContextMenu->addAction(cmd, Constants::G_PROJECT_FIRST);
// Collapse All.
dd->m_projectTreeCollapseAllAction = new QAction(tr("Collapse All"), this);
cmd = ActionManager::registerAction(dd->m_projectTreeCollapseAllAction, Constants::PROJECTTREE_COLLAPSE_ALL,
projecTreeContext);
const Id treeGroup = Constants::G_PROJECT_TREE;
mfileContextMenu->addSeparator(treeGroup);
mfileContextMenu->addAction(cmd, treeGroup);
msubProjectContextMenu->addSeparator(treeGroup);
msubProjectContextMenu->addAction(cmd, treeGroup);
mfolderContextMenu->addSeparator(treeGroup);
mfolderContextMenu->addAction(cmd, treeGroup);
mprojectContextMenu->addSeparator(treeGroup);
mprojectContextMenu->addAction(cmd, treeGroup);
msessionContextMenu->addSeparator(treeGroup);
msessionContextMenu->addAction(cmd, treeGroup);
// target selector
dd->m_projectSelectorAction = new QAction(this);
dd->m_projectSelectorAction->setCheckable(true);
dd->m_projectSelectorAction->setEnabled(false);
QWidget *mainWindow = ICore::mainWindow();
dd->m_targetSelector = new MiniProjectTargetSelector(dd->m_projectSelectorAction, mainWindow);
connect(dd->m_projectSelectorAction, &QAction::triggered, dd->m_targetSelector, &QWidget::show);
ModeManager::addProjectSelector(dd->m_projectSelectorAction);
dd->m_projectSelectorActionMenu = new QAction(this);
dd->m_projectSelectorActionMenu->setEnabled(false);
dd->m_projectSelectorActionMenu->setText(tr("Open Build and Run Kit Selector..."));
connect(dd->m_projectSelectorActionMenu, &QAction::triggered, dd->m_targetSelector,
&MiniProjectTargetSelector::toggleVisible);
cmd = ActionManager::registerAction(dd->m_projectSelectorActionMenu, Constants::SELECTTARGET);
mbuild->addAction(cmd, Constants::G_BUILD_RUN);
dd->m_projectSelectorActionQuick = new QAction(this);
dd->m_projectSelectorActionQuick->setEnabled(false);
dd->m_projectSelectorActionQuick->setText(tr("Quick Switch Kit Selector"));
connect(dd->m_projectSelectorActionQuick, &QAction::triggered,
dd->m_targetSelector, &MiniProjectTargetSelector::nextOrShow);
cmd = ActionManager::registerAction(dd->m_projectSelectorActionQuick, Constants::SELECTTARGETQUICK);
cmd->setDefaultKeySequence(QKeySequence(tr("Ctrl+T")));
connect(ICore::instance(), &ICore::saveSettingsRequested,
dd, &ProjectExplorerPluginPrivate::savePersistentSettings);
addAutoReleasedObject(new ProjectTreeWidgetFactory);
addAutoReleasedObject(new FolderNavigationWidgetFactory);
addAutoReleasedObject(new DefaultDeployConfigurationFactory);
QSettings *s = ICore::settings();
const QStringList fileNames =
s->value(QLatin1String("ProjectExplorer/RecentProjects/FileNames")).toStringList();
const QStringList displayNames =
s->value(QLatin1String("ProjectExplorer/RecentProjects/DisplayNames")).toStringList();
if (fileNames.size() == displayNames.size()) {
for (int i = 0; i < fileNames.size(); ++i) {
if (QFileInfo(fileNames.at(i)).isFile())
dd->m_recentProjects.append(qMakePair(fileNames.at(i), displayNames.at(i)));
}
}
dd->m_projectExplorerSettings.buildBeforeDeploy =
s->value(QLatin1String("ProjectExplorer/Settings/BuildBeforeDeploy"), true).toBool();
dd->m_projectExplorerSettings.deployBeforeRun =
s->value(QLatin1String("ProjectExplorer/Settings/DeployBeforeRun"), true).toBool();
dd->m_projectExplorerSettings.saveBeforeBuild =
s->value(QLatin1String("ProjectExplorer/Settings/SaveBeforeBuild"), false).toBool();
dd->m_projectExplorerSettings.showCompilerOutput =
s->value(QLatin1String("ProjectExplorer/Settings/ShowCompilerOutput"), false).toBool();
dd->m_projectExplorerSettings.showRunOutput =
s->value(QLatin1String("ProjectExplorer/Settings/ShowRunOutput"), true).toBool();
dd->m_projectExplorerSettings.showDebugOutput =
s->value(QLatin1String("ProjectExplorer/Settings/ShowDebugOutput"), false).toBool();
dd->m_projectExplorerSettings.cleanOldAppOutput =
s->value(QLatin1String("ProjectExplorer/Settings/CleanOldAppOutput"), false).toBool();
dd->m_projectExplorerSettings.mergeStdErrAndStdOut =
s->value(QLatin1String("ProjectExplorer/Settings/MergeStdErrAndStdOut"), false).toBool();
dd->m_projectExplorerSettings.wrapAppOutput =
s->value(QLatin1String("ProjectExplorer/Settings/WrapAppOutput"), true).toBool();
dd->m_projectExplorerSettings.useJom =
s->value(QLatin1String("ProjectExplorer/Settings/UseJom"), true).toBool();
dd->m_projectExplorerSettings.autorestoreLastSession =
s->value(QLatin1String("ProjectExplorer/Settings/AutoRestoreLastSession"), false).toBool();
dd->m_projectExplorerSettings.prompToStopRunControl =
s->value(QLatin1String("ProjectExplorer/Settings/PromptToStopRunControl"), false).toBool();
dd->m_projectExplorerSettings.maxAppOutputLines =
s->value(QLatin1String("ProjectExplorer/Settings/MaxAppOutputLines"), 100000).toInt();
dd->m_projectExplorerSettings.environmentId =
QUuid(s->value(QLatin1String("ProjectExplorer/Settings/EnvironmentId")).toByteArray());
if (dd->m_projectExplorerSettings.environmentId.isNull())
dd->m_projectExplorerSettings.environmentId = QUuid::createUuid();
int tmp = s->value(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"),
Utils::HostOsInfo::isWindowsHost() ? 1 : 0).toInt();
if (tmp < 0 || tmp > ProjectExplorerSettings::StopAll)
tmp = Utils::HostOsInfo::isWindowsHost() ? 1 : 0;
dd->m_projectExplorerSettings.stopBeforeBuild = ProjectExplorerSettings::StopBeforeBuild(tmp);
connect(dd->m_sessionManagerAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::showSessionManager);
connect(dd->m_newAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::newProject);
connect(dd->m_loadAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::loadAction);
connect(dd->m_buildProjectOnlyAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::buildProjectOnly);
connect(dd->m_buildAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleBuildProject);
connect(dd->m_buildActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::buildProjectContextMenu);
connect(dd->m_buildDependenciesActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::buildProjectDependenciesContextMenu);
connect(dd->m_buildSessionAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::buildSession);
connect(dd->m_rebuildProjectOnlyAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::rebuildProjectOnly);
connect(dd->m_rebuildAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::rebuildProject);
connect(dd->m_rebuildActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::rebuildProjectContextMenu);
connect(dd->m_rebuildDependenciesActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::rebuildProjectDependenciesContextMenu);
connect(dd->m_rebuildSessionAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::rebuildSession);
connect(dd->m_deployProjectOnlyAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::deployProjectOnly);
connect(dd->m_deployAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::deployProject);
connect(dd->m_deployActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::deployProjectContextMenu);
connect(dd->m_deploySessionAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::deploySession);
connect(dd->m_cleanProjectOnlyAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cleanProjectOnly);
connect(dd->m_cleanAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cleanProject);
connect(dd->m_cleanActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cleanProjectContextMenu);
connect(dd->m_cleanDependenciesActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cleanProjectDependenciesContextMenu);
connect(dd->m_cleanSessionAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cleanSession);
connect(dd->m_runAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleRunProject);
connect(dd->m_runActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::runProjectContextMenu);
connect(dd->m_runWithoutDeployAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::runProjectWithoutDeploy);
connect(dd->m_cancelBuildAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::cancelBuild);
connect(dd->m_unloadAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleUnloadProject);
connect(dd->m_unloadActionContextMenu, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::unloadProjectContextMenu);
connect(dd->m_closeAllProjects, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::closeAllProjects);
connect(dd->m_addNewFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::addNewFile);
connect(dd->m_addExistingFilesAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleAddExistingFiles);
connect(dd->m_addExistingDirectoryAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::addExistingDirectory);
connect(dd->m_addNewSubprojectAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::addNewSubproject);
connect(dd->m_removeProjectAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::removeProject);
connect(dd->m_openFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::openFile);
connect(dd->m_searchOnFileSystem, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::searchOnFileSystem);
connect(dd->m_showInGraphicalShell, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::showInGraphicalShell);
connect(dd->m_openTerminalHere, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::openTerminalHere);
connect(dd->m_removeFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::removeFile);
connect(dd->m_deleteFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::deleteFile);
connect(dd->m_renameFileAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleRenameFile);
connect(dd->m_setStartupProjectAction, &QAction::triggered,
dd, &ProjectExplorerPluginPrivate::handleSetStartupProject);
connect(dd->m_projectTreeCollapseAllAction, &QAction::triggered,
ProjectTree::instance(), &ProjectTree::collapseAll);
connect(this, &ProjectExplorerPlugin::updateRunActions,
dd, &ProjectExplorerPluginPrivate::slotUpdateRunActions);
connect(this, &ProjectExplorerPlugin::settingsChanged,
dd, &ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu);
auto buildManager = new BuildManager(this, dd->m_cancelBuildAction);
connect(buildManager, &BuildManager::buildStateChanged,
dd, &ProjectExplorerPluginPrivate::buildStateChanged);
connect(buildManager, &BuildManager::buildQueueFinished,
dd, &ProjectExplorerPluginPrivate::buildQueueFinished, Qt::QueuedConnection);
connect(ICore::instance(), &ICore::coreAboutToOpen,
dd, &ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup);
connect(ICore::instance(), &ICore::coreOpened,
dd, &ProjectExplorerPluginPrivate::restoreSession);
connect(ICore::instance(), &ICore::newItemDialogRunningChanged, updateActions);
connect(ICore::instance(), &ICore::newItemDialogRunningChanged,
dd, &ProjectExplorerPluginPrivate::updateContextMenuActions);
dd->updateWelcomePage();
// FIXME: These are mostly "legacy"/"convenience" entries, relying on
// the global entry point ProjectExplorer::currentProject(). They should
// not be used in the Run/Build configuration pages.
Utils::MacroExpander *expander = Utils::globalMacroExpander();
expander->registerFileVariables(Constants::VAR_CURRENTPROJECT_PREFIX,
tr("Current project's main file."),
[this]() -> QString {
Utils::FileName projectFilePath;
if (Project *project = ProjectTree::currentProject())
if (IDocument *doc = project->document())
projectFilePath = doc->filePath();
return projectFilePath.toString();
});
expander->registerVariable(Constants::VAR_CURRENTPROJECT_BUILDPATH,
tr("Full build path of the current project's active build configuration."),
[]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
return bc ? bc->buildDirectory().toUserOutput() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTPROJECT_NAME,
tr("The name of the current project."),
[this]() -> QString {
Project *project = ProjectTree::currentProject();
return project ? project->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_NAME,
tr("The name of the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_FILESYSTEMNAME,
tr("The name of the currently active kit as a filesystem-friendly version."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->fileSystemFriendlyName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTKIT_ID,
tr("The ID of the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
return kit ? kit->id().toString() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTDEVICE_HOSTADDRESS,
tr("The host address of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().host : QString();
});
expander->registerVariable(Constants::VAR_CURRENTDEVICE_SSHPORT,
tr("The SSH port of the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? QString::number(device->sshParameters().port) : QString();
});
expander->registerVariable(Constants::VAR_CURRENTDEVICE_USERNAME,
tr("The username with which to log into the device in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().userName : QString();
});
expander->registerVariable(Constants::VAR_CURRENTDEVICE_PRIVATEKEYFILE,
tr("The private key file with which to authenticate when logging into the device "
"in the currently active kit."),
[]() -> QString {
Kit *kit = currentKit();
const IDevice::ConstPtr device = DeviceKitInformation::device(kit);
return device ? device->sshParameters().privateKeyFile : QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_NAME,
tr("The currently active build configuration's name."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
return bc ? bc->displayName() : QString();
});
expander->registerVariable(Constants::VAR_CURRENTBUILD_TYPE,
tr("The currently active build configuration's type."),
[&]() -> QString {
BuildConfiguration *bc = activeBuildConfiguration();
const BuildConfiguration::BuildType type
= bc ? bc->buildType() : BuildConfiguration::Unknown;
return BuildConfiguration::buildTypeName(type);
});
QString fileDescription = tr("File where current session is saved.");
auto fileHandler = [] { return SessionManager::sessionNameToFileName(SessionManager::activeSession()).toString(); };
expander->registerFileVariables("Session", fileDescription, fileHandler);
expander->registerFileVariables("CurrentSession", fileDescription, fileHandler, false);
QString nameDescription = tr("Name of current session.");
auto nameHandler = [] { return SessionManager::activeSession(); };
expander->registerVariable("Session:Name", nameDescription, nameHandler);
expander->registerVariable("CurrentSession:Name", nameDescription, nameHandler, false);
return true;
}
void ProjectExplorerPluginPrivate::loadAction()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::loadAction";
QString dir = dd->m_lastOpenDirectory;
// for your special convenience, we preselect a pro file if it is
// the current file
if (const IDocument *document = EditorManager::currentDocument()) {
const QString fn = document->filePath().toString();
const bool isProject = dd->m_profileMimeTypes.contains(document->mimeType());
dir = isProject ? fn : QFileInfo(fn).absolutePath();
}
QString filename = QFileDialog::getOpenFileName(ICore::dialogParent(),
tr("Load Project"), dir,
dd->m_projectFilterString);
if (filename.isEmpty())
return;
ProjectExplorerPlugin::OpenProjectResult result = ProjectExplorerPlugin::openProject(filename);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
updateActions();
}
void ProjectExplorerPluginPrivate::unloadProjectContextMenu()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::unloadProjectContextMenu";
if (Project *p = ProjectTree::currentProject())
ProjectExplorerPlugin::unloadProject(p);
}
void ProjectExplorerPluginPrivate::handleUnloadProject()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::unloadProject";
QList<Project *> projects = SessionManager::projects();
QTC_ASSERT(!projects.isEmpty(), return);
ProjectExplorerPlugin::unloadProject(projects.first());
}
void ProjectExplorerPlugin::unloadProject(Project *project)
{
if (BuildManager::isBuilding(project)) {
QMessageBox box;
QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Unload"), QMessageBox::AcceptRole);
QPushButton *cancelClose = box.addButton(tr("Do Not Unload"), QMessageBox::RejectRole);
box.setDefaultButton(cancelClose);
box.setWindowTitle(tr("Unload Project %1?").arg(project->displayName()));
box.setText(tr("The project %1 is currently being built.").arg(project->displayName()));
box.setInformativeText(tr("Do you want to cancel the build process and unload the project anyway?"));
box.exec();
if (box.clickedButton() != closeAnyway)
return;
BuildManager::cancel();
}
IDocument *document = project->document();
if (!document || document->filePath().isEmpty()) //nothing to save?
return;
if (!DocumentManager::saveModifiedDocumentSilently(document))
return;
dd->addToRecentProjects(document->filePath().toString(), project->displayName());
SessionManager::removeProject(project);
updateActions();
}
void ProjectExplorerPluginPrivate::closeAllProjects()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::closeAllProject";
if (!EditorManager::closeAllEditors())
return; // Action has been cancelled
SessionManager::closeAllProjects();
updateActions();
ModeManager::activateMode(Core::Constants::MODE_WELCOME);
}
void ProjectExplorerPlugin::extensionsInitialized()
{
// Register factories for all project managers
QList<IProjectManager*> projectManagers =
ExtensionSystem::PluginManager::getObjects<IProjectManager>();
QStringList allGlobPatterns;
const QString filterSeparator = QLatin1String(";;");
QStringList filterStrings;
auto factory = new IDocumentFactory;
factory->setOpener([this](const QString &fileName) -> IDocument* {
OpenProjectResult result = ProjectExplorerPlugin::openProject(fileName);
if (!result)
showOpenProjectError(result);
return 0;
});
Utils::MimeDatabase mdb;
foreach (IProjectManager *manager, projectManagers) {
const QString mimeType = manager->mimeType();
factory->addMimeType(mimeType);
Utils::MimeType mime = mdb.mimeTypeForName(mimeType);
allGlobPatterns.append(mime.globPatterns());
filterStrings.append(mime.filterString());
dd->m_profileMimeTypes += mimeType;
}
addAutoReleasedObject(factory);
QString allProjectsFilter = tr("All Projects");
allProjectsFilter += QLatin1String(" (") + allGlobPatterns.join(QLatin1Char(' '))
+ QLatin1Char(')');
filterStrings.prepend(allProjectsFilter);
dd->m_projectFilterString = filterStrings.join(filterSeparator);
BuildManager::extensionsInitialized();
DeviceManager::instance()->addDevice(IDevice::Ptr(new DesktopDevice));
DeviceManager::instance()->load();
ToolChainManager::restoreToolChains();
dd->m_kitManager->restoreKits();
}
void ProjectExplorerPluginPrivate::updateRunWithoutDeployMenu()
{
m_runWithoutDeployAction->setVisible(m_projectExplorerSettings.deployBeforeRun);
}
ExtensionSystem::IPlugin::ShutdownFlag ProjectExplorerPlugin::aboutToShutdown()
{
disconnect(ModeManager::instance(), &ModeManager::currentModeChanged,
dd, &ProjectExplorerPluginPrivate::currentModeChanged);
ProjectTree::aboutToShutDown();
dd->m_proWindow->aboutToShutdown(); // disconnect from session
SessionManager::closeAllProjects();
dd->m_projectsMode = 0;
dd->m_shuttingDown = true;
// Attempt to synchronously shutdown all run controls.
// If that fails, fall back to asynchronous shutdown (Debugger run controls
// might shutdown asynchronously).
removeObject(dd->m_welcomePage);
delete dd->m_welcomePage;
removeObject(this);
if (dd->m_outputPane->closeTabs(AppOutputPane::CloseTabNoPrompt /* No prompt any more */))
return SynchronousShutdown;
connect(dd->m_outputPane, &AppOutputPane::allRunControlsFinished,
this, &IPlugin::asynchronousShutdownFinished);
return AsynchronousShutdown;
}
void ProjectExplorerPluginPrivate::newProject()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::newProject";
ICore::showNewItemDialog(tr("New Project", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::ProjectWizard));
updateActions();
}
void ProjectExplorerPluginPrivate::showSessionManager()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::showSessionManager";
if (SessionManager::isDefaultVirgin()) {
// do not save new virgin default sessions
} else {
SessionManager::save();
}
SessionDialog sessionDialog(ICore::mainWindow());
sessionDialog.setAutoLoadSession(dd->m_projectExplorerSettings.autorestoreLastSession);
sessionDialog.exec();
dd->m_projectExplorerSettings.autorestoreLastSession = sessionDialog.autoLoadSession();
updateActions();
IMode *welcomeMode = ModeManager::mode(Core::Constants::MODE_WELCOME);
if (ModeManager::currentMode() == welcomeMode)
updateWelcomePage();
}
void ProjectExplorerPluginPrivate::setStartupProject(Project *project)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::setStartupProject";
if (!project)
return;
SessionManager::setStartupProject(project);
updateActions();
}
void ProjectExplorerPluginPrivate::savePersistentSettings()
{
if (debug)
qDebug()<<"ProjectExplorerPlugin::savePersistentSettings()";
if (dd->m_shuttingDown)
return;
if (!SessionManager::loadingSession()) {
foreach (Project *pro, SessionManager::projects())
pro->saveSettings();
if (SessionManager::isDefaultVirgin()) {
// do not save new virgin default sessions
} else {
SessionManager::save();
}
}
QSettings *s = ICore::settings();
s->setValue(QLatin1String("ProjectExplorer/StartupSession"), SessionManager::activeSession());
s->remove(QLatin1String("ProjectExplorer/RecentProjects/Files"));
QStringList fileNames;
QStringList displayNames;
QList<QPair<QString, QString> >::const_iterator it, end;
end = dd->m_recentProjects.constEnd();
for (it = dd->m_recentProjects.constBegin(); it != end; ++it) {
fileNames << (*it).first;
displayNames << (*it).second;
}
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/FileNames"), fileNames);
s->setValue(QLatin1String("ProjectExplorer/RecentProjects/DisplayNames"), displayNames);
s->setValue(QLatin1String("ProjectExplorer/Settings/BuildBeforeDeploy"), dd->m_projectExplorerSettings.buildBeforeDeploy);
s->setValue(QLatin1String("ProjectExplorer/Settings/DeployBeforeRun"), dd->m_projectExplorerSettings.deployBeforeRun);
s->setValue(QLatin1String("ProjectExplorer/Settings/SaveBeforeBuild"), dd->m_projectExplorerSettings.saveBeforeBuild);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowCompilerOutput"), dd->m_projectExplorerSettings.showCompilerOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowRunOutput"), dd->m_projectExplorerSettings.showRunOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/ShowDebugOutput"), dd->m_projectExplorerSettings.showDebugOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/CleanOldAppOutput"), dd->m_projectExplorerSettings.cleanOldAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/MergeStdErrAndStdOut"), dd->m_projectExplorerSettings.mergeStdErrAndStdOut);
s->setValue(QLatin1String("ProjectExplorer/Settings/WrapAppOutput"), dd->m_projectExplorerSettings.wrapAppOutput);
s->setValue(QLatin1String("ProjectExplorer/Settings/UseJom"), dd->m_projectExplorerSettings.useJom);
s->setValue(QLatin1String("ProjectExplorer/Settings/AutoRestoreLastSession"), dd->m_projectExplorerSettings.autorestoreLastSession);
s->setValue(QLatin1String("ProjectExplorer/Settings/PromptToStopRunControl"), dd->m_projectExplorerSettings.prompToStopRunControl);
s->setValue(QLatin1String("ProjectExplorer/Settings/MaxAppOutputLines"), dd->m_projectExplorerSettings.maxAppOutputLines);
s->setValue(QLatin1String("ProjectExplorer/Settings/EnvironmentId"), dd->m_projectExplorerSettings.environmentId.toByteArray());
s->setValue(QLatin1String("ProjectExplorer/Settings/StopBeforeBuild"), dd->m_projectExplorerSettings.stopBeforeBuild);
}
void ProjectExplorerPlugin::openProjectWelcomePage(const QString &fileName)
{
OpenProjectResult result = openProject(fileName);
if (!result)
showOpenProjectError(result);
}
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProject(const QString &fileName)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::openProject";
OpenProjectResult result = openProjects(QStringList() << fileName);
Project *project = result.project();
if (!project)
return result;
dd->addToRecentProjects(fileName, project->displayName());
SessionManager::setStartupProject(project);
return result;
}
void ProjectExplorerPlugin::showOpenProjectError(const OpenProjectResult &result)
{
if (result)
return;
// Potentially both errorMessage and alreadyOpen could contain information
// that should be shown to the user.
// BUT, if Creator opens only a single project, this can lead
// to either
// - No error
// - A errorMessage
// - A single project in alreadyOpen
// The only place where multiple projects are opened is in session restore
// where the already open case should never happen, thus
// the following code uses those assumptions to make the code simpler
QString errorMessage = result.errorMessage();
if (!errorMessage.isEmpty()) {
// ignore alreadyOpen
QMessageBox::critical(ICore::mainWindow(), tr("Failed to Open Project"), errorMessage);
} else {
// ignore multiple alreadyOpen
Project *alreadyOpen = result.alreadyOpen().first();
ProjectTree::highlightProject(alreadyOpen,
tr("<h3>Project already open</h3>"));
}
}
static QList<IProjectManager*> allProjectManagers()
{
return ExtensionSystem::PluginManager::getObjects<IProjectManager>();
}
static void appendError(QString &errorString, const QString &error)
{
if (error.isEmpty())
return;
if (!errorString.isEmpty())
errorString.append(QLatin1Char('\n'));
errorString.append(error);
}
ProjectExplorerPlugin::OpenProjectResult ProjectExplorerPlugin::openProjects(const QStringList &fileNames)
{
if (debug)
qDebug() << "ProjectExplorerPlugin - opening projects " << fileNames;
const QList<IProjectManager*> projectManagers = allProjectManagers();
QList<Project*> openedPro;
QList<Project *> alreadyOpen;
QString errorString;
foreach (const QString &fileName, fileNames) {
QTC_ASSERT(!fileName.isEmpty(), continue);
const QFileInfo fi(fileName);
const QString filePath = fi.absoluteFilePath();
bool found = false;
foreach (Project *pi, SessionManager::projects()) {
if (filePath == pi->projectFilePath().toString()) {
alreadyOpen.append(pi);
found = true;
break;
}
}
if (found) {
SessionManager::reportProjectLoadingProgress();
continue;
}
Utils::MimeDatabase mdb;
Utils::MimeType mt = mdb.mimeTypeForFile(fileName);
if (mt.isValid()) {
bool foundProjectManager = false;
foreach (IProjectManager *manager, projectManagers) {
if (mt.matchesName(manager->mimeType())) {
foundProjectManager = true;
QString tmp;
if (Project *pro = manager->openProject(filePath, &tmp)) {
QString restoreError;
Project::RestoreResult restoreResult = pro->restoreSettings(&restoreError);
if (restoreResult == Project::RestoreResult::Ok) {
connect(pro, &Project::fileListChanged,
m_instance, &ProjectExplorerPlugin::fileListChanged);
SessionManager::addProject(pro);
openedPro += pro;
} else {
if (restoreResult == Project::RestoreResult::Error)
appendError(errorString, restoreError);
delete pro;
}
}
if (!tmp.isEmpty())
appendError(errorString, tmp);
break;
}
}
if (!foundProjectManager) {
appendError(errorString, tr("Failed opening project \"%1\": No plugin can open project type \"%2\".")
.arg(QDir::toNativeSeparators(fileName))
.arg(mt.name()));
}
} else {
appendError(errorString, tr("Failed opening project \"%1\": Unknown project type.")
.arg(QDir::toNativeSeparators(fileName)));
}
if (fileNames.size() > 1)
SessionManager::reportProjectLoadingProgress();
}
updateActions();
bool switchToProjectsMode = Utils::anyOf(openedPro, &Project::needsConfiguration);
if (!openedPro.isEmpty()) {
if (switchToProjectsMode)
ModeManager::activateMode(Constants::MODE_SESSION);
else
ModeManager::activateMode(Core::Constants::MODE_EDIT);
ModeManager::setFocusToCurrentMode();
}
return OpenProjectResult(openedPro, alreadyOpen, errorString);
}
void ProjectExplorerPluginPrivate::updateWelcomePage()
{
m_welcomePage->reloadWelcomeScreenData();
}
void ProjectExplorerPluginPrivate::currentModeChanged(IMode *mode, IMode *oldMode)
{
if (oldMode && oldMode->id() == Constants::MODE_SESSION)
ICore::saveSettings();
if (mode && mode->id() == Core::Constants::MODE_WELCOME)
updateWelcomePage();
}
void ProjectExplorerPluginPrivate::determineSessionToRestoreAtStartup()
{
// Process command line arguments first:
if (m_instance->pluginSpec()->arguments().contains(QLatin1String("-lastsession")))
m_sessionToRestoreAtStartup = SessionManager::lastSession();
QStringList arguments = ExtensionSystem::PluginManager::arguments();
if (m_sessionToRestoreAtStartup.isNull()) {
QStringList sessions = SessionManager::sessions();
// We have command line arguments, try to find a session in them
// Default to no session loading
foreach (const QString &arg, arguments) {
if (sessions.contains(arg)) {
// Session argument
m_sessionToRestoreAtStartup = arg;
break;
}
}
}
// Handle settings only after command line arguments:
if (m_sessionToRestoreAtStartup.isNull()
&& m_projectExplorerSettings.autorestoreLastSession)
m_sessionToRestoreAtStartup = SessionManager::lastSession();
if (!m_sessionToRestoreAtStartup.isNull())
ModeManager::activateMode(Core::Constants::MODE_EDIT);
}
// Return a list of glob patterns for project files ("*.pro", etc), use first, main pattern only.
QStringList ProjectExplorerPlugin::projectFileGlobs()
{
QStringList result;
Utils::MimeDatabase mdb;
foreach (const IProjectManager *ipm, ExtensionSystem::PluginManager::getObjects<IProjectManager>()) {
Utils::MimeType mimeType = mdb.mimeTypeForName(ipm->mimeType());
if (mimeType.isValid()) {
const QStringList patterns = mimeType.globPatterns();
if (!patterns.isEmpty())
result.append(patterns.front());
}
}
return result;
}
void ProjectExplorerPlugin::updateContextMenuActions()
{
dd->updateContextMenuActions();
}
/*!
This function is connected to the ICore::coreOpened signal. If
there was no session explicitly loaded, it creates an empty new
default session and puts the list of recent projects and sessions
onto the welcome page.
*/
void ProjectExplorerPluginPrivate::restoreSession()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::restoreSession";
// We have command line arguments, try to find a session in them
QStringList arguments = ExtensionSystem::PluginManager::arguments();
if (!dd->m_sessionToRestoreAtStartup.isEmpty() && !arguments.isEmpty())
arguments.removeOne(dd->m_sessionToRestoreAtStartup);
// Massage the argument list.
// Be smart about directories: If there is a session of that name, load it.
// Other than that, look for project files in it. The idea is to achieve
// 'Do what I mean' functionality when starting Creator in a directory with
// the single command line argument '.' and avoid editor warnings about not
// being able to open directories.
// In addition, convert "filename" "+45" or "filename" ":23" into
// "filename+45" and "filename:23".
if (!arguments.isEmpty()) {
const QStringList sessions = SessionManager::sessions();
QStringList projectGlobs = ProjectExplorerPlugin::projectFileGlobs();
for (int a = 0; a < arguments.size(); ) {
const QString &arg = arguments.at(a);
const QFileInfo fi(arg);
if (fi.isDir()) {
const QDir dir(fi.absoluteFilePath());
// Does the directory name match a session?
if (dd->m_sessionToRestoreAtStartup.isEmpty()
&& sessions.contains(dir.dirName())) {
dd->m_sessionToRestoreAtStartup = dir.dirName();
arguments.removeAt(a);
continue;
} else {
// Are there project files in that directory?
const QFileInfoList proFiles
= dir.entryInfoList(projectGlobs, QDir::Files);
if (!proFiles.isEmpty()) {
arguments[a] = proFiles.front().absoluteFilePath();
++a;
continue;
}
}
// Cannot handle: Avoid mime type warning for directory.
qWarning("Skipping directory '%s' passed on to command line.",
qPrintable(QDir::toNativeSeparators(arg)));
arguments.removeAt(a);
continue;
} // Done directories.
// Converts "filename" "+45" or "filename" ":23" into "filename+45" and "filename:23"
if (a && (arg.startsWith(QLatin1Char('+')) || arg.startsWith(QLatin1Char(':')))) {
arguments[a - 1].append(arguments.takeAt(a));
continue;
}
++a;
} // for arguments
} // !arguments.isEmpty()
// Restore latest session or what was passed on the command line
if (!dd->m_sessionToRestoreAtStartup.isEmpty())
SessionManager::loadSession(dd->m_sessionToRestoreAtStartup);
// update welcome page
connect(ModeManager::instance(), &ModeManager::currentModeChanged,
dd, &ProjectExplorerPluginPrivate::currentModeChanged);
connect(dd->m_welcomePage, &ProjectWelcomePage::requestSession,
dd, &ProjectExplorerPluginPrivate::loadSession);
connect(dd->m_welcomePage, &ProjectWelcomePage::requestProject,
m_instance, &ProjectExplorerPlugin::openProjectWelcomePage);
dd->m_arguments = arguments;
QTimer::singleShot(0, m_instance, SLOT(restoreSession2()));
updateActions();
}
void ProjectExplorerPluginPrivate::loadSession(const QString &session)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::loadSession" << session;
SessionManager::loadSession(session);
}
void ProjectExplorerPlugin::restoreSession2()
{
QApplication::processEvents(QEventLoop::ExcludeUserInputEvents);
ICore::openFiles(dd->m_arguments, ICore::OpenFilesFlags(ICore::CanContainLineAndColumnNumbers | ICore::SwitchMode));
}
void ProjectExplorerPluginPrivate::buildStateChanged(Project * pro)
{
if (debug) {
qDebug() << "buildStateChanged";
qDebug() << pro->projectFilePath() << "isBuilding()" << BuildManager::isBuilding(pro);
}
Q_UNUSED(pro)
updateActions();
}
// NBS TODO implement more than one runner
static IRunControlFactory *findRunControlFactory(RunConfiguration *config, Core::Id mode)
{
return ExtensionSystem::PluginManager::getObject<IRunControlFactory>(
[&config, &mode](IRunControlFactory *factory) {
return factory->canRun(config, mode);
});
}
void ProjectExplorerPluginPrivate::executeRunConfiguration(RunConfiguration *runConfiguration, Core::Id runMode)
{
if (!runConfiguration->isConfigured()) {
QString errorMessage;
RunConfiguration::ConfigurationState state = runConfiguration->ensureConfigured(&errorMessage);
if (state == RunConfiguration::UnConfigured) {
m_instance->showRunErrorMessage(errorMessage);
return;
} else if (state == RunConfiguration::Waiting) {
connect(runConfiguration, &RunConfiguration::configurationFinished,
this, &ProjectExplorerPluginPrivate::runConfigurationConfigurationFinished);
m_delayedRunConfigurationForRun.append(qMakePair(runConfiguration, runMode));
return;
}
}
if (IRunControlFactory *runControlFactory = findRunControlFactory(runConfiguration, runMode)) {
emit m_instance->aboutToExecuteProject(runConfiguration->target()->project(), runMode);
QString errorMessage;
RunControl *control = runControlFactory->create(runConfiguration, runMode, &errorMessage);
if (!control) {
m_instance->showRunErrorMessage(errorMessage);
return;
}
startRunControl(control, runMode);
}
}
void ProjectExplorerPlugin::showRunErrorMessage(const QString &errorMessage)
{
// Empty, non-null means 'canceled' (custom executable dialog for libraries), whereas
// empty, null means an error occurred, but message was not set
if (!errorMessage.isEmpty() || errorMessage.isNull())
QMessageBox::critical(ICore::mainWindow(), errorMessage.isNull() ? tr("Unknown error") : tr("Could Not Run"), errorMessage);
}
void ProjectExplorerPlugin::startRunControl(RunControl *runControl, Core::Id runMode)
{
dd->startRunControl(runControl, runMode);
}
void ProjectExplorerPluginPrivate::startRunControl(RunControl *runControl, Core::Id runMode)
{
m_outputPane->createNewOutputWindow(runControl);
m_outputPane->flash(); // one flash for starting
m_outputPane->showTabFor(runControl);
bool popup = (runMode == Constants::NORMAL_RUN_MODE && dd->m_projectExplorerSettings.showRunOutput)
|| ((runMode == Constants::DEBUG_RUN_MODE || runMode == Constants::DEBUG_RUN_MODE_WITH_BREAK_ON_MAIN)
&& m_projectExplorerSettings.showDebugOutput);
m_outputPane->setBehaviorOnOutput(runControl, popup ? AppOutputPane::Popup : AppOutputPane::Flash);
runControl->start();
emit m_instance->updateRunActions();
}
void ProjectExplorerPlugin::initiateInlineRenaming()
{
dd->handleRenameFile();
}
void ProjectExplorerPluginPrivate::buildQueueFinished(bool success)
{
if (debug)
qDebug() << "buildQueueFinished()" << success;
updateActions();
bool ignoreErrors = true;
if (!m_delayedRunConfiguration.isNull() && success && BuildManager::getErrorTaskCount() > 0) {
ignoreErrors = QMessageBox::question(ICore::dialogParent(),
ProjectExplorerPlugin::tr("Ignore All Errors?"),
ProjectExplorerPlugin::tr("Found some build errors in current task.\n"
"Do you want to ignore them?"),
QMessageBox::Yes | QMessageBox::No,
QMessageBox::No) == QMessageBox::Yes;
}
if (m_delayedRunConfiguration.isNull() && m_shouldHaveRunConfiguration) {
QMessageBox::warning(ICore::dialogParent(),
ProjectExplorerPlugin::tr("Run Configuration Removed"),
ProjectExplorerPlugin::tr("The configuration that was supposed to run is no longer "
"available."), QMessageBox::Ok);
}
if (success && ignoreErrors && !m_delayedRunConfiguration.isNull()) {
executeRunConfiguration(m_delayedRunConfiguration.data(), m_runMode);
} else {
if (BuildManager::tasksAvailable())
BuildManager::showTaskWindow();
}
m_delayedRunConfiguration = 0;
m_shouldHaveRunConfiguration = false;
m_runMode = Constants::NO_RUN_MODE;
}
void ProjectExplorerPluginPrivate::runConfigurationConfigurationFinished()
{
RunConfiguration *rc = qobject_cast<RunConfiguration *>(sender());
Core::Id runMode = Constants::NO_RUN_MODE;
for (int i = 0; i < m_delayedRunConfigurationForRun.size(); ++i) {
if (m_delayedRunConfigurationForRun.at(i).first == rc) {
runMode = m_delayedRunConfigurationForRun.at(i).second;
m_delayedRunConfigurationForRun.removeAt(i);
break;
}
}
if (runMode != Constants::NO_RUN_MODE && rc->isConfigured())
executeRunConfiguration(rc, runMode);
}
static QString pathOrDirectoryFor(Node *node, bool dir)
{
Utils::FileName path = node->filePath();
QString location;
FolderNode *folder = node->asFolderNode();
if (node->nodeType() == VirtualFolderNodeType && folder) {
// Virtual Folder case
// If there are files directly below or no subfolders, take the folder path
if (!folder->fileNodes().isEmpty() || folder->subFolderNodes().isEmpty()) {
location = path.toString();
} else {
// Otherwise we figure out a commonPath from the subfolders
QStringList list;
foreach (FolderNode *f, folder->subFolderNodes())
list << f->filePath().toString() + QLatin1Char('/');
location = Utils::commonPath(list);
}
QFileInfo fi(location);
while ((!fi.exists() || !fi.isDir()) && !fi.isRoot())
fi.setFile(fi.absolutePath());
location = fi.absoluteFilePath();
} else {
QFileInfo fi = path.toFileInfo();
// remove any /suffixes, which e.g. ResourceNode uses
// Note this should be removed again by making node->path() a true path again
// That requires changes in both the VirtualFolderNode and ResourceNode
while (!fi.exists() && !fi.isRoot())
fi.setFile(fi.absolutePath());
if (dir)
location = fi.isDir() ? fi.absoluteFilePath() : fi.absolutePath();
else
location = fi.absoluteFilePath();
}
return location;
}
static QString pathFor(Node *node)
{
return pathOrDirectoryFor(node, false);
}
static QString directoryFor(Node *node)
{
return pathOrDirectoryFor(node, true);
}
QString ProjectExplorerPlugin::directoryFor(Node *node)
{
return ProjectExplorer::directoryFor(node);
}
void ProjectExplorerPluginPrivate::updateActions()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::updateActions";
m_newAction->setEnabled(!ICore::isNewItemDialogRunning());
Project *project = SessionManager::startupProject();
Project *currentProject = ProjectTree::currentProject(); // for context menu actions
QPair<bool, QString> buildActionState = buildSettingsEnabled(project);
QPair<bool, QString> buildActionContextState = buildSettingsEnabled(currentProject);
QPair<bool, QString> buildSessionState = buildSettingsEnabledForSession();
QString projectName = project ? project->displayName() : QString();
QString projectNameContextMenu = currentProject ? currentProject->displayName() : QString();
m_unloadAction->setParameter(projectName);
m_unloadActionContextMenu->setParameter(projectNameContextMenu);
// Normal actions
m_buildAction->setParameter(projectName);
m_rebuildAction->setParameter(projectName);
m_cleanAction->setParameter(projectName);
m_buildAction->setEnabled(buildActionState.first);
m_rebuildAction->setEnabled(buildActionState.first);
m_cleanAction->setEnabled(buildActionState.first);
m_buildAction->setToolTip(buildActionState.second);
m_rebuildAction->setToolTip(buildActionState.second);
m_cleanAction->setToolTip(buildActionState.second);
// Context menu actions
m_setStartupProjectAction->setParameter(projectNameContextMenu);
bool hasDependencies = SessionManager::projectOrder(currentProject).size() > 1;
if (hasDependencies) {
m_buildActionContextMenu->setVisible(true);
m_rebuildActionContextMenu->setVisible(true);
m_cleanActionContextMenu->setVisible(true);
} else {
m_buildActionContextMenu->setVisible(false);
m_rebuildActionContextMenu->setVisible(false);
m_cleanActionContextMenu->setVisible(false);
}
m_buildActionContextMenu->setEnabled(buildActionContextState.first);
m_rebuildActionContextMenu->setEnabled(buildActionContextState.first);
m_cleanActionContextMenu->setEnabled(buildActionContextState.first);
m_buildDependenciesActionContextMenu->setEnabled(buildActionContextState.first);
m_rebuildDependenciesActionContextMenu->setEnabled(buildActionContextState.first);
m_cleanDependenciesActionContextMenu->setEnabled(buildActionContextState.first);
m_buildActionContextMenu->setToolTip(buildActionState.second);
m_rebuildActionContextMenu->setToolTip(buildActionState.second);
m_cleanActionContextMenu->setToolTip(buildActionState.second);
// build project only
m_buildProjectOnlyAction->setEnabled(buildActionState.first);
m_rebuildProjectOnlyAction->setEnabled(buildActionState.first);
m_cleanProjectOnlyAction->setEnabled(buildActionState.first);
m_buildProjectOnlyAction->setToolTip(buildActionState.second);
m_rebuildProjectOnlyAction->setToolTip(buildActionState.second);
m_cleanProjectOnlyAction->setToolTip(buildActionState.second);
// Session actions
m_closeAllProjects->setEnabled(SessionManager::hasProjects());
m_unloadAction->setVisible(SessionManager::projects().size() <= 1);
m_unloadAction->setEnabled(SessionManager::projects().size() == 1);
m_unloadActionContextMenu->setEnabled(SessionManager::hasProjects());
ActionContainer *aci =
ActionManager::actionContainer(Constants::M_UNLOADPROJECTS);
aci->menu()->menuAction()->setVisible(SessionManager::projects().size() > 1);
m_buildSessionAction->setEnabled(buildSessionState.first);
m_rebuildSessionAction->setEnabled(buildSessionState.first);
m_cleanSessionAction->setEnabled(buildSessionState.first);
m_buildSessionAction->setToolTip(buildSessionState.second);
m_rebuildSessionAction->setToolTip(buildSessionState.second);
m_cleanSessionAction->setToolTip(buildSessionState.second);
m_cancelBuildAction->setEnabled(BuildManager::isBuilding());
const bool hasProjects = SessionManager::hasProjects();
m_projectSelectorAction->setEnabled(hasProjects);
m_projectSelectorActionMenu->setEnabled(hasProjects);
m_projectSelectorActionQuick->setEnabled(hasProjects);
updateDeployActions();
updateRunWithoutDeployMenu();
}
bool ProjectExplorerPlugin::saveModifiedFiles()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::saveModifiedFiles";
QList<IDocument *> documentsToSave = DocumentManager::modifiedDocuments();
if (!documentsToSave.isEmpty()) {
if (dd->m_projectExplorerSettings.saveBeforeBuild) {
bool cancelled = false;
DocumentManager::saveModifiedDocumentsSilently(documentsToSave, &cancelled);
if (cancelled)
return false;
} else {
bool cancelled = false;
bool alwaysSave = false;
if (!DocumentManager::saveModifiedDocuments(documentsToSave, QString(), &cancelled,
tr("Always save files before build"), &alwaysSave)) {
if (cancelled)
return false;
}
if (alwaysSave)
dd->m_projectExplorerSettings.saveBeforeBuild = true;
}
}
return true;
}
//NBS handle case where there is no activeBuildConfiguration
// because someone delete all build configurations
void ProjectExplorerPluginPrivate::deploy(QList<Project *> projects)
{
QList<Id> steps;
if (m_projectExplorerSettings.buildBeforeDeploy)
steps << Id(Constants::BUILDSTEPS_BUILD);
steps << Id(Constants::BUILDSTEPS_DEPLOY);
queue(projects, steps);
}
QString ProjectExplorerPlugin::displayNameForStepId(Id stepId)
{
if (stepId == Constants::BUILDSTEPS_CLEAN)
return tr("Clean");
if (stepId == Constants::BUILDSTEPS_BUILD)
return tr("Build", "Build step");
if (stepId == Constants::BUILDSTEPS_DEPLOY)
return tr("Deploy");
return tr("Build", "Build step");
}
int ProjectExplorerPluginPrivate::queue(QList<Project *> projects, QList<Id> stepIds)
{
if (debug) {
QStringList projectNames, stepNames;
foreach (const Project *p, projects)
projectNames << p->displayName();
foreach (const Id id, stepIds)
stepNames << id.toString();
qDebug() << "Building" << stepNames << "for projects" << projectNames;
}
if (!m_instance->saveModifiedFiles())
return -1;
if (m_projectExplorerSettings.stopBeforeBuild != ProjectExplorerSettings::StopNone
&& stepIds.contains(Constants::BUILDSTEPS_BUILD)) {
bool stopAll = (m_projectExplorerSettings.stopBeforeBuild == ProjectExplorerSettings::StopAll);
const QList<RunControl *> toStop
= Utils::filtered(m_outputPane->allRunControls(), [&projects, stopAll](RunControl *rc) {
return rc->isRunning() && (stopAll || projects.contains(rc->project()));
});
if (!toStop.isEmpty()) {
bool stopThem = true;
if (m_projectExplorerSettings.prompToStopRunControl) {
QStringList names = Utils::transform(toStop, &RunControl::displayName);
if (QMessageBox::question(ICore::mainWindow(), tr("Stop Applications"),
tr("Stop these applications before building?")
+ QLatin1String("\n\n")
+ names.join(QLatin1Char('\n')))
== QMessageBox::No) {
stopThem = false;
}
}
QList<RunControl *> asyncStop;
if (stopThem) {
foreach (RunControl *rc, toStop) {
if (rc->stop() == RunControl::AsynchronousStop)
asyncStop << rc;
}
}
if (!asyncStop.isEmpty()) {
WaitForStopDialog dialog(asyncStop);
dialog.exec();
if (dialog.canceled())
return -1;
}
}
}
QList<BuildStepList *> stepLists;
QStringList names;
QStringList preambleMessage;
foreach (Project *pro, projects)
if (pro && pro->needsConfiguration())
preambleMessage.append(tr("The project %1 is not configured, skipping it.")
.arg(pro->displayName()) + QLatin1Char('\n'));
foreach (Id id, stepIds) {
foreach (Project *pro, projects) {
if (!pro || pro->needsConfiguration())
continue;
BuildStepList *bsl = 0;
if (id == Constants::BUILDSTEPS_DEPLOY
&& pro->activeTarget()->activeDeployConfiguration())
bsl = pro->activeTarget()->activeDeployConfiguration()->stepList();
else if (pro->activeTarget()->activeBuildConfiguration())
bsl = pro->activeTarget()->activeBuildConfiguration()->stepList(id);
if (!bsl || bsl->isEmpty())
continue;
stepLists << bsl;
names << m_instance->displayNameForStepId(id);
}
}
if (stepLists.isEmpty())
return 0;
if (!BuildManager::buildLists(stepLists, names, preambleMessage))
return -1;
return stepLists.count();
}
void ProjectExplorerPluginPrivate::buildProjectOnly()
{
queue(QList<Project *>() << SessionManager::startupProject(), QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPlugin::buildProject(Project *p)
{
dd->queue(SessionManager::projectOrder(p),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPlugin::requestProjectModeUpdate(Project *p)
{
dd->m_proWindow->projectUpdated(p);
}
void ProjectExplorerPluginPrivate::handleBuildProject()
{
queue(SessionManager::projectOrder(SessionManager::startupProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::buildProjectContextMenu()
{
queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::buildProjectDependenciesContextMenu()
{
queue(SessionManager::projectOrder(ProjectTree::currentProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::buildSession()
{
queue(SessionManager::projectOrder(),
QList<Id>() << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::rebuildProjectOnly()
{
queue(QList<Project *>() << SessionManager::startupProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::rebuildProject()
{
queue(SessionManager::projectOrder(SessionManager::startupProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::rebuildProjectContextMenu()
{
queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::rebuildProjectDependenciesContextMenu()
{
queue(SessionManager::projectOrder(ProjectTree::currentProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::rebuildSession()
{
queue(SessionManager::projectOrder(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN) << Id(Constants::BUILDSTEPS_BUILD));
}
void ProjectExplorerPluginPrivate::deployProjectOnly()
{
deploy(QList<Project *>() << SessionManager::startupProject());
}
void ProjectExplorerPluginPrivate::deployProject()
{
deploy(SessionManager::projectOrder(SessionManager::startupProject()));
}
void ProjectExplorerPluginPrivate::deployProjectContextMenu()
{
deploy(QList<Project *>() << ProjectTree::currentProject());
}
void ProjectExplorerPluginPrivate::deploySession()
{
deploy(SessionManager::projectOrder());
}
void ProjectExplorerPluginPrivate::cleanProjectOnly()
{
queue(QList<Project *>() << SessionManager::startupProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
void ProjectExplorerPluginPrivate::cleanProject()
{
queue(SessionManager::projectOrder(SessionManager::startupProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
void ProjectExplorerPluginPrivate::cleanProjectContextMenu()
{
queue(QList<Project *>() << ProjectTree::currentProject(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
void ProjectExplorerPluginPrivate::cleanProjectDependenciesContextMenu()
{
queue(SessionManager::projectOrder(ProjectTree::currentProject()),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
void ProjectExplorerPluginPrivate::cleanSession()
{
queue(SessionManager::projectOrder(),
QList<Id>() << Id(Constants::BUILDSTEPS_CLEAN));
}
void ProjectExplorerPluginPrivate::handleRunProject()
{
m_instance->runStartupProject(Constants::NORMAL_RUN_MODE);
}
void ProjectExplorerPluginPrivate::runProjectWithoutDeploy()
{
m_instance->runStartupProject(Constants::NORMAL_RUN_MODE, true);
}
void ProjectExplorerPluginPrivate::runProjectContextMenu()
{
Node *node = ProjectTree::currentNode();
ProjectNode *projectNode = node ? node->asProjectNode() : 0;
if (projectNode == ProjectTree::currentProject()->rootProjectNode() || !projectNode) {
m_instance->runProject(ProjectTree::currentProject(), Constants::NORMAL_RUN_MODE);
} else {
QAction *act = qobject_cast<QAction *>(sender());
if (!act)
return;
RunConfiguration *rc = act->data().value<RunConfiguration *>();
if (!rc)
return;
m_instance->runRunConfiguration(rc, Constants::NORMAL_RUN_MODE);
}
}
static bool hasBuildSettings(Project *pro)
{
return Utils::anyOf(SessionManager::projectOrder(pro), [](Project *project) {
return project
&& project->activeTarget()
&& project->activeTarget()->activeBuildConfiguration();
});
}
QPair<bool, QString> ProjectExplorerPluginPrivate::buildSettingsEnabled(Project *pro)
{
QPair<bool, QString> result;
result.first = true;
if (!pro) {
result.first = false;
result.second = tr("No project loaded.");
} else if (BuildManager::isBuilding(pro)) {
result.first = false;
result.second = tr("Currently building the active project.");
} else if (pro->needsConfiguration()) {
result.first = false;
result.second = tr("The project %1 is not configured.").arg(pro->displayName());
} else if (!hasBuildSettings(pro)) {
result.first = false;
result.second = tr("Project has no build settings.");
} else {
const QList<Project *> & projects = SessionManager::projectOrder(pro);
foreach (Project *project, projects) {
if (project
&& project->activeTarget()
&& project->activeTarget()->activeBuildConfiguration()
&& !project->activeTarget()->activeBuildConfiguration()->isEnabled()) {
result.first = false;
result.second += tr("Building \"%1\" is disabled: %2<br>")
.arg(project->displayName(),
project->activeTarget()->activeBuildConfiguration()->disabledReason());
}
}
}
return result;
}
QPair<bool, QString> ProjectExplorerPluginPrivate::buildSettingsEnabledForSession()
{
QPair<bool, QString> result;
result.first = true;
if (!SessionManager::hasProjects()) {
result.first = false;
result.second = tr("No project loaded.");
} else if (BuildManager::isBuilding()) {
result.first = false;
result.second = tr("A build is in progress.");
} else if (!hasBuildSettings(0)) {
result.first = false;
result.second = tr("Project has no build settings.");
} else {
foreach (Project *project, SessionManager::projectOrder(0)) {
if (project
&& project->activeTarget()
&& project->activeTarget()->activeBuildConfiguration()
&& !project->activeTarget()->activeBuildConfiguration()->isEnabled()) {
result.first = false;
result.second += tr("Building \"%1\" is disabled: %2")
.arg(project->displayName(),
project->activeTarget()->activeBuildConfiguration()->disabledReason());
result.second += QLatin1Char('\n');
}
}
}
return result;
}
bool ProjectExplorerPlugin::coreAboutToClose()
{
if (BuildManager::isBuilding()) {
QMessageBox box;
QPushButton *closeAnyway = box.addButton(tr("Cancel Build && Close"), QMessageBox::AcceptRole);
QPushButton *cancelClose = box.addButton(tr("Do Not Close"), QMessageBox::RejectRole);
box.setDefaultButton(cancelClose);
box.setWindowTitle(tr("Close Qt Creator?"));
box.setText(tr("A project is currently being built."));
box.setInformativeText(tr("Do you want to cancel the build process and close Qt Creator anyway?"));
box.exec();
if (box.clickedButton() != closeAnyway)
return false;
}
if (!dd->m_outputPane->aboutToClose())
return false;
return true;
}
static bool hasDeploySettings(Project *pro)
{
return Utils::anyOf(SessionManager::projectOrder(pro), [](Project *project) {
return project->activeTarget()
&& project->activeTarget()->activeDeployConfiguration()
&& !project->activeTarget()->activeDeployConfiguration()->stepList()->isEmpty();
});
}
void ProjectExplorerPlugin::runProject(Project *pro, Core::Id mode, const bool forceSkipDeploy)
{
if (!pro)
return;
if (Target *target = pro->activeTarget())
if (RunConfiguration *rc = target->activeRunConfiguration())
runRunConfiguration(rc, mode, forceSkipDeploy);
}
void ProjectExplorerPlugin::runStartupProject(Core::Id runMode, bool forceSkipDeploy)
{
runProject(SessionManager::startupProject(), runMode, forceSkipDeploy);
}
void ProjectExplorerPlugin::runRunConfiguration(RunConfiguration *rc,
Core::Id runMode,
const bool forceSkipDeploy)
{
if (!rc->isEnabled())
return;
QList<Id> stepIds;
if (!forceSkipDeploy && dd->m_projectExplorerSettings.deployBeforeRun) {
if (dd->m_projectExplorerSettings.buildBeforeDeploy)
stepIds << Id(Constants::BUILDSTEPS_BUILD);
stepIds << Id(Constants::BUILDSTEPS_DEPLOY);
}
Project *pro = rc->target()->project();
int queueCount = dd->queue(SessionManager::projectOrder(pro), stepIds);
if (queueCount < 0) // something went wrong
return;
if (queueCount > 0) {
// delay running till after our queued steps were processed
dd->m_runMode = runMode;
dd->m_delayedRunConfiguration = rc;
dd->m_shouldHaveRunConfiguration = true;
} else {
dd->executeRunConfiguration(rc, runMode);
}
emit m_instance->updateRunActions();
}
void ProjectExplorerPluginPrivate::projectAdded(Project *pro)
{
if (m_projectsMode)
m_projectsMode->setEnabled(true);
// more specific action en and disabling ?
connect(pro, &Project::buildConfigurationEnabledChanged,
this, &ProjectExplorerPluginPrivate::updateActions);
}
void ProjectExplorerPluginPrivate::projectRemoved(Project * pro)
{
if (m_projectsMode)
m_projectsMode->setEnabled(SessionManager::hasProjects());
// more specific action en and disabling ?
disconnect(pro, &Project::buildConfigurationEnabledChanged,
this, &ProjectExplorerPluginPrivate::updateActions);
}
void ProjectExplorerPluginPrivate::projectDisplayNameChanged(Project *pro)
{
addToRecentProjects(pro->projectFilePath().toString(), pro->displayName());
updateActions();
}
void ProjectExplorerPluginPrivate::startupProjectChanged()
{
static QPointer<Project> previousStartupProject = 0;
Project *project = SessionManager::startupProject();
if (project == previousStartupProject)
return;
if (previousStartupProject) {
disconnect(previousStartupProject.data(), &Project::activeTargetChanged,
this, &ProjectExplorerPluginPrivate::activeTargetChanged);
}
previousStartupProject = project;
if (project) {
connect(project, &Project::activeTargetChanged,
this, &ProjectExplorerPluginPrivate::activeTargetChanged);
}
activeTargetChanged();
updateActions();
}
void ProjectExplorerPluginPrivate::activeTargetChanged()
{
static QPointer<Target> previousTarget = 0;
Target *target = 0;
Project *startupProject = SessionManager::startupProject();
if (startupProject)
target = startupProject->activeTarget();
if (target == previousTarget)
return;
if (previousTarget) {
disconnect(previousTarget.data(), &Target::activeRunConfigurationChanged,
this, &ProjectExplorerPluginPrivate::activeRunConfigurationChanged);
}
previousTarget = target;
if (target) {
connect(target, &Target::activeRunConfigurationChanged,
this, &ProjectExplorerPluginPrivate::activeRunConfigurationChanged);
}
activeRunConfigurationChanged();
updateDeployActions();
}
void ProjectExplorerPluginPrivate::activeRunConfigurationChanged()
{
static QPointer<RunConfiguration> previousRunConfiguration = 0;
RunConfiguration *rc = 0;
Project *startupProject = SessionManager::startupProject();
if (startupProject && startupProject->activeTarget())
rc = startupProject->activeTarget()->activeRunConfiguration();
if (rc == previousRunConfiguration)
return;
if (previousRunConfiguration) {
disconnect(previousRunConfiguration.data(), &RunConfiguration::requestRunActionsUpdate,
m_instance, &ProjectExplorerPlugin::updateRunActions);
}
previousRunConfiguration = rc;
if (rc) {
connect(rc, &RunConfiguration::requestRunActionsUpdate,
m_instance, &ProjectExplorerPlugin::updateRunActions);
}
emit m_instance->updateRunActions();
}
void ProjectExplorerPluginPrivate::updateDeployActions()
{
Project *project = SessionManager::startupProject();
bool enableDeployActions = project
&& !BuildManager::isBuilding(project)
&& hasDeploySettings(project);
Project *currentProject = ProjectTree::currentProject();
bool enableDeployActionsContextMenu = currentProject
&& !BuildManager::isBuilding(currentProject)
&& hasDeploySettings(currentProject);
if (m_projectExplorerSettings.buildBeforeDeploy) {
if (hasBuildSettings(project)
&& !buildSettingsEnabled(project).first)
enableDeployActions = false;
if (hasBuildSettings(currentProject)
&& !buildSettingsEnabled(currentProject).first)
enableDeployActionsContextMenu = false;
}
const QString projectName = project ? project->displayName() : QString();
bool hasProjects = SessionManager::hasProjects();
m_deployAction->setParameter(projectName);
m_deployAction->setEnabled(enableDeployActions);
m_deployActionContextMenu->setEnabled(enableDeployActionsContextMenu);
m_deployProjectOnlyAction->setEnabled(enableDeployActions);
bool enableDeploySessionAction = true;
if (m_projectExplorerSettings.buildBeforeDeploy) {
auto hasDisabledBuildConfiguration = [](Project *project) {
return project && project->activeTarget()
&& project->activeTarget()->activeBuildConfiguration()
&& !project->activeTarget()->activeBuildConfiguration()->isEnabled();
};
if (Utils::anyOf(SessionManager::projectOrder(0), hasDisabledBuildConfiguration))
enableDeploySessionAction = false;
}
if (!hasProjects || !hasDeploySettings(0) || BuildManager::isBuilding())
enableDeploySessionAction = false;
m_deploySessionAction->setEnabled(enableDeploySessionAction);
emit m_instance->updateRunActions();
}
bool ProjectExplorerPlugin::canRun(Project *project, Core::Id runMode, QString *whyNot)
{
if (!project) {
if (whyNot)
*whyNot = tr("No active project.");
return false;
}
if (project->needsConfiguration()) {
if (whyNot)
*whyNot = tr("The project \"%1\" is not configured.").arg(project->displayName());
return false;
}
Target *target = project->activeTarget();
if (!target) {
if (whyNot)
*whyNot = tr("The project \"%1\" has no active kit.").arg(project->displayName());
return false;
}
RunConfiguration *activeRC = target->activeRunConfiguration();
if (!activeRC) {
if (whyNot)
*whyNot = tr("The kit \"%1\" for the project \"%2\" has no active run configuration.")
.arg(target->displayName(), project->displayName());
return false;
}
if (!activeRC->isEnabled()) {
if (whyNot)
*whyNot = activeRC->disabledReason();
return false;
}
if (dd->m_projectExplorerSettings.buildBeforeDeploy
&& dd->m_projectExplorerSettings.deployBeforeRun
&& hasBuildSettings(project)) {
QPair<bool, QString> buildState = dd->buildSettingsEnabled(project);
if (!buildState.first) {
if (whyNot)
*whyNot = buildState.second;
return false;
}
}
// shouldn't actually be shown to the user...
if (!findRunControlFactory(activeRC, runMode)) {
if (whyNot)
*whyNot = tr("Cannot run \"%1\".").arg(activeRC->displayName());
return false;
}
if (BuildManager::isBuilding()) {
if (whyNot)
*whyNot = tr("A build is still in progress.");
return false;
}
return true;
}
void ProjectExplorerPluginPrivate::slotUpdateRunActions()
{
Project *project = SessionManager::startupProject();
QString whyNot;
const bool state = ProjectExplorerPlugin::canRun(project, Constants::NORMAL_RUN_MODE, &whyNot);
m_runAction->setEnabled(state);
m_runAction->setToolTip(whyNot);
m_runWithoutDeployAction->setEnabled(state);
}
void ProjectExplorerPluginPrivate::cancelBuild()
{
if (debug)
qDebug() << "ProjectExplorerPlugin::cancelBuild";
if (BuildManager::isBuilding())
BuildManager::cancel();
}
void ProjectExplorerPluginPrivate::addToRecentProjects(const QString &fileName, const QString &displayName)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::addToRecentProjects(" << fileName << ")";
if (fileName.isEmpty())
return;
QString prettyFileName(QDir::toNativeSeparators(fileName));
QList<QPair<QString, QString> >::iterator it;
for (it = m_recentProjects.begin(); it != m_recentProjects.end();)
if ((*it).first == prettyFileName)
it = m_recentProjects.erase(it);
else
++it;
if (m_recentProjects.count() > m_maxRecentProjects)
m_recentProjects.removeLast();
m_recentProjects.prepend(qMakePair(prettyFileName, displayName));
QFileInfo fi(prettyFileName);
m_lastOpenDirectory = fi.absolutePath();
emit m_instance->recentProjectsChanged();
}
void ProjectExplorerPluginPrivate::updateUnloadProjectMenu()
{
ActionContainer *aci = ActionManager::actionContainer(Constants::M_UNLOADPROJECTS);
QMenu *menu = aci->menu();
menu->clear();
foreach (Project *project, SessionManager::projects()) {
QAction *action = menu->addAction(tr("Close Project \"%1\"").arg(project->displayName()));
connect(action, &QAction::triggered,
[project] { ProjectExplorerPlugin::unloadProject(project); } );
}
}
void ProjectExplorerPluginPrivate::updateRecentProjectMenu()
{
typedef QList<QPair<QString, QString> >::const_iterator StringPairListConstIterator;
if (debug)
qDebug() << "ProjectExplorerPlugin::updateRecentProjectMenu";
ActionContainer *aci =
ActionManager::actionContainer(Constants::M_RECENTPROJECTS);
QMenu *menu = aci->menu();
menu->clear();
bool hasRecentProjects = false;
//projects (ignore sessions, they used to be in this list)
const StringPairListConstIterator end = dd->m_recentProjects.constEnd();
for (StringPairListConstIterator it = dd->m_recentProjects.constBegin(); it != end; ++it) {
const QString fileName = it->first;
if (fileName.endsWith(QLatin1String(".qws")))
continue;
QAction *action = menu->addAction(Utils::withTildeHomePath(fileName));
connect(action, &QAction::triggered, this, [this, fileName] {
openRecentProject(fileName);
});
hasRecentProjects = true;
}
menu->setEnabled(hasRecentProjects);
// add the Clear Menu item
if (hasRecentProjects) {
menu->addSeparator();
QAction *action = menu->addAction(QCoreApplication::translate(
"Core", Core::Constants::TR_CLEAR_MENU));
connect(action, &QAction::triggered, this, &ProjectExplorerPluginPrivate::clearRecentProjects);
}
emit m_instance->recentProjectsChanged();
}
void ProjectExplorerPluginPrivate::clearRecentProjects()
{
m_recentProjects.clear();
updateWelcomePage();
}
void ProjectExplorerPluginPrivate::openRecentProject(const QString &fileName)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::openRecentProject()";
if (!fileName.isEmpty()) {
ProjectExplorerPlugin::OpenProjectResult result
= ProjectExplorerPlugin::openProject(fileName);
if (!result)
ProjectExplorerPlugin::showOpenProjectError(result);
}
}
void ProjectExplorerPluginPrivate::invalidateProject(Project *project)
{
if (debug)
qDebug() << "ProjectExplorerPlugin::invalidateProject" << project->displayName();
disconnect(project, &Project::fileListChanged, m_instance, &ProjectExplorerPlugin::fileListChanged);
updateActions();
}
void ProjectExplorerPluginPrivate::updateContextMenuActions()
{
m_addExistingFilesAction->setEnabled(false);
m_addExistingDirectoryAction->setEnabled(false);
m_addNewFileAction->setEnabled(false);
m_addNewSubprojectAction->setEnabled(false);
m_removeProjectAction->setEnabled(false);
m_removeFileAction->setEnabled(false);
m_deleteFileAction->setEnabled(false);
m_renameFileAction->setEnabled(false);
m_addExistingFilesAction->setVisible(true);
m_addExistingDirectoryAction->setVisible(true);
m_addNewFileAction->setVisible(true);
m_addNewSubprojectAction->setVisible(true);
m_removeProjectAction->setVisible(true);
m_removeFileAction->setVisible(true);
m_deleteFileAction->setVisible(true);
m_runActionContextMenu->setVisible(false);
m_openTerminalHere->setVisible(true);
m_showInGraphicalShell->setVisible(true);
m_searchOnFileSystem->setVisible(true);
ActionContainer *runMenu = ActionManager::actionContainer(Constants::RUNMENUCONTEXTMENU);
runMenu->menu()->clear();
runMenu->menu()->menuAction()->setVisible(false);
Node *currentNode = ProjectTree::currentNode();
if (currentNode && currentNode->projectNode()) {
QList<ProjectAction> actions = currentNode->supportedActions(currentNode);
if (ProjectNode *pn = currentNode->asProjectNode()) {
if (ProjectTree::currentProject() && pn == ProjectTree::currentProject()->rootProjectNode()) {
m_runActionContextMenu->setVisible(true);
} else {
QList<RunConfiguration *> runConfigs = pn->runConfigurations();
if (runConfigs.count() == 1) {
m_runActionContextMenu->setVisible(true);
m_runActionContextMenu->setData(QVariant::fromValue(runConfigs.first()));
} else if (runConfigs.count() > 1) {
runMenu->menu()->menuAction()->setVisible(true);
foreach (RunConfiguration *rc, runConfigs) {
QAction *act = new QAction(runMenu->menu());
act->setData(QVariant::fromValue(rc));
act->setText(tr("Run %1").arg(rc->displayName()));
runMenu->menu()->addAction(act);
connect(act, &QAction::triggered,
this, &ProjectExplorerPluginPrivate::runProjectContextMenu);
}
}
}
}
if (currentNode->asFolderNode()) {
// Also handles ProjectNode
m_addNewFileAction->setEnabled(actions.contains(AddNewFile)
&& !ICore::isNewItemDialogRunning());
m_addNewSubprojectAction->setEnabled(currentNode->nodeType() == ProjectNodeType
&& actions.contains(AddSubProject)
&& !ICore::isNewItemDialogRunning());
m_removeProjectAction->setEnabled(currentNode->nodeType() == ProjectNodeType
&& actions.contains(RemoveSubProject));
m_addExistingFilesAction->setEnabled(actions.contains(AddExistingFile));
m_addExistingDirectoryAction->setEnabled(actions.contains(AddExistingDirectory));
m_renameFileAction->setEnabled(actions.contains(Rename));
} else if (currentNode->asFileNode()) {
// Enable and show remove / delete in magic ways:
// If both are disabled show Remove
// If both are enabled show both (can't happen atm)
// If only removeFile is enabled only show it
// If only deleteFile is enable only show it
bool enableRemove = actions.contains(RemoveFile);
m_removeFileAction->setEnabled(enableRemove);
bool enableDelete = actions.contains(EraseFile);
m_deleteFileAction->setEnabled(enableDelete);
m_deleteFileAction->setVisible(enableDelete);
m_removeFileAction->setVisible(!enableDelete || enableRemove);
m_renameFileAction->setEnabled(actions.contains(Rename));
EditorManager::populateOpenWithMenu(m_openWithMenu,
ProjectTree::currentNode()->filePath().toString());
}
if (actions.contains(HidePathActions)) {
m_openTerminalHere->setVisible(false);
m_showInGraphicalShell->setVisible(false);
m_searchOnFileSystem->setVisible(false);
}
if (actions.contains(HideFileActions)) {
m_deleteFileAction->setVisible(false);
m_removeFileAction->setVisible(false);
}
if (actions.contains(HideFolderActions)) {
m_addNewFileAction->setVisible(false);
m_addNewSubprojectAction->setVisible(false);
m_removeProjectAction->setVisible(false);
m_addExistingFilesAction->setVisible(false);
m_addExistingDirectoryAction->setVisible(false);
}
}
}
void ProjectExplorerPluginPrivate::addNewFile()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
QString location = directoryFor(ProjectTree::currentNode());
QVariantMap map;
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(ProjectTree::currentNode()));
if (ProjectTree::currentProject()) {
QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id);
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
}
ICore::showNewItemDialog(tr("New File", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::FileWizard),
location, map);
}
void ProjectExplorerPluginPrivate::addNewSubproject()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
Node *currentNode = ProjectTree::currentNode();
QString location = directoryFor(currentNode);
if (currentNode->nodeType() == ProjectNodeType
&& currentNode->supportedActions(
currentNode).contains(AddSubProject)) {
QVariantMap map;
map.insert(QLatin1String(Constants::PREFERRED_PROJECT_NODE), QVariant::fromValue(currentNode));
if (ProjectTree::currentProject()) {
QList<Id> profileIds = Utils::transform(ProjectTree::currentProject()->targets(), &Target::id);
map.insert(QLatin1String(Constants::PROJECT_KIT_IDS), QVariant::fromValue(profileIds));
}
ICore::showNewItemDialog(tr("New Subproject", "Title of dialog"),
IWizardFactory::wizardFactoriesOfKind(IWizardFactory::ProjectWizard),
location, map);
}
}
void ProjectExplorerPluginPrivate::handleAddExistingFiles()
{
Node *node = ProjectTree::currentNode();
FolderNode *folderNode = node ? node->asFolderNode() : 0;
QTC_ASSERT(folderNode, return);
QStringList fileNames = QFileDialog::getOpenFileNames(ICore::mainWindow(),
tr("Add Existing Files"), directoryFor(ProjectTree::currentNode()));
if (fileNames.isEmpty())
return;
ProjectExplorerPlugin::addExistingFiles(folderNode, fileNames);
}
void ProjectExplorerPluginPrivate::addExistingDirectory()
{
Node *node = ProjectTree::currentNode();
FolderNode *folderNode = node ? node->asFolderNode() : 0;
QTC_ASSERT(folderNode, return);
SelectableFilesDialogAddDirectory dialog(Utils::FileName::fromString(directoryFor(ProjectTree::currentNode())),
QList<Utils::FileName>(), ICore::mainWindow());
dialog.setAddFileFilter(folderNode->addFileFilter());
if (dialog.exec() == QDialog::Accepted)
ProjectExplorerPlugin::addExistingFiles(folderNode, Utils::transform(dialog.selectedFiles(), &Utils::FileName::toString));
}
void ProjectExplorerPlugin::addExistingFiles(FolderNode *folderNode, const QStringList &filePaths)
{
if (!folderNode) // can happen when project is not yet parsed
return;
const QString dir = directoryFor(folderNode);
QStringList fileNames = filePaths;
QStringList notAdded;
folderNode->addFiles(fileNames, ¬Added);
if (!notAdded.isEmpty()) {
const QString message = tr("Could not add following files to project %1:")
.arg(folderNode->projectNode()->displayName()) + QLatin1Char('\n');
const QStringList nativeFiles
= Utils::transform(notAdded,
[](const QString &f) { return QDir::toNativeSeparators(f); });
QMessageBox::warning(ICore::mainWindow(), tr("Adding Files to Project Failed"),
message + nativeFiles.join(QLatin1Char('\n')));
fileNames = Utils::filtered(fileNames,
[¬Added](const QString &f) { return !notAdded.contains(f); });
}
VcsManager::promptToAdd(dir, fileNames);
}
void ProjectExplorerPluginPrivate::removeProject()
{
Node *node = ProjectTree::currentNode();
if (!node)
return;
ProjectNode *subProjectNode = node->projectNode();
if (!subProjectNode)
return;
ProjectNode *projectNode = subProjectNode->parentFolderNode()->asProjectNode();
if (projectNode) {
RemoveFileDialog removeFileDialog(subProjectNode->filePath().toString(), ICore::mainWindow());
removeFileDialog.setDeleteFileVisible(false);
if (removeFileDialog.exec() == QDialog::Accepted)
projectNode->removeSubProjects(QStringList() << subProjectNode->filePath().toString());
}
}
void ProjectExplorerPluginPrivate::openFile()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
EditorManager::openEditor(ProjectTree::currentNode()->filePath().toString());
}
void ProjectExplorerPluginPrivate::searchOnFileSystem()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
TextEditor::FindInFiles::findOnFileSystem(pathFor(ProjectTree::currentNode()));
}
void ProjectExplorerPluginPrivate::showInGraphicalShell()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
FileUtils::showInGraphicalShell(ICore::mainWindow(), pathFor(ProjectTree::currentNode()));
}
void ProjectExplorerPluginPrivate::openTerminalHere()
{
QTC_ASSERT(ProjectTree::currentNode(), return);
FileUtils::openTerminal(directoryFor(ProjectTree::currentNode()));
}
void ProjectExplorerPluginPrivate::removeFile()
{
Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode && currentNode->nodeType() == FileNodeType, return);
FileNode *fileNode = currentNode->asFileNode();
QString filePath = currentNode->filePath().toString();
RemoveFileDialog removeFileDialog(filePath, ICore::mainWindow());
if (removeFileDialog.exec() == QDialog::Accepted) {
const bool deleteFile = removeFileDialog.isDeleteFileChecked();
// remove from project
FolderNode *folderNode = fileNode->parentFolderNode();
Q_ASSERT(folderNode);
if (!folderNode->removeFiles(QStringList(filePath))) {
QMessageBox::warning(ICore::mainWindow(), tr("Removing File Failed"),
tr("Could not remove file %1 from project %2.")
.arg(QDir::toNativeSeparators(filePath))
.arg(folderNode->projectNode()->displayName()));
return;
}
DocumentManager::expectFileChange(filePath);
FileUtils::removeFile(filePath, deleteFile);
DocumentManager::unexpectFileChange(filePath);
}
}
void ProjectExplorerPluginPrivate::deleteFile()
{
Node *currentNode = ProjectTree::currentNode();
QTC_ASSERT(currentNode && currentNode->nodeType() == FileNodeType, return);
FileNode *fileNode = currentNode->asFileNode();
QString filePath = currentNode->filePath().toString();
QMessageBox::StandardButton button =
QMessageBox::question(ICore::mainWindow(),
tr("Delete File"),
tr("Delete %1 from file system?")
.arg(QDir::toNativeSeparators(filePath)),
QMessageBox::Yes | QMessageBox::No);
if (button != QMessageBox::Yes)
return;
FolderNode *folderNode = fileNode->parentFolderNode();
QTC_ASSERT(folderNode, return);
folderNode->deleteFiles(QStringList(filePath));
DocumentManager::expectFileChange(filePath);
if (IVersionControl *vc =
VcsManager::findVersionControlForDirectory(QFileInfo(filePath).absolutePath())) {
vc->vcsDelete(filePath);
}
QFile file(filePath);
if (file.exists()) {
if (!file.remove())
QMessageBox::warning(ICore::mainWindow(), tr("Deleting File Failed"),
tr("Could not delete file %1.")
.arg(QDir::toNativeSeparators(filePath)));
}
DocumentManager::unexpectFileChange(filePath);
}
void ProjectExplorerPluginPrivate::handleRenameFile()
{
QWidget *focusWidget = QApplication::focusWidget();
while (focusWidget) {
ProjectTreeWidget *treeWidget = qobject_cast<ProjectTreeWidget*>(focusWidget);
if (treeWidget) {
treeWidget->editCurrentItem();
return;
}
focusWidget = focusWidget->parentWidget();
}
}
void ProjectExplorerPlugin::renameFile(Node *node, const QString &newFilePath)
{
QString orgFilePath = node->filePath().toFileInfo().absoluteFilePath();
FolderNode *folderNode = node->parentFolderNode();
QString projectFileName = folderNode->projectNode()->filePath().fileName();
if (!folderNode->canRenameFile(orgFilePath, newFilePath)) {
QTimer::singleShot(0, [orgFilePath, newFilePath, projectFileName] {
int res = QMessageBox::question(ICore::mainWindow(),
tr("Project Editing Failed"),
tr("The project file %1 cannot be automatically changed.\n\n"
"Rename %2 to %3 anyway?")
.arg(projectFileName)
.arg(QDir::toNativeSeparators(orgFilePath))
.arg(QDir::toNativeSeparators(newFilePath)));
if (res == QMessageBox::Yes)
FileUtils::renameFile(orgFilePath, newFilePath);
});
return;
}
if (FileUtils::renameFile(orgFilePath, newFilePath)) {
// Tell the project plugin about rename
if (!folderNode->renameFile(orgFilePath, newFilePath)) {
const QString renameFileError
= tr("The file %1 was renamed to %2, but the project file %3 could not be automatically changed.")
.arg(QDir::toNativeSeparators(orgFilePath))
.arg(QDir::toNativeSeparators(newFilePath))
.arg(projectFileName);
QTimer::singleShot(0, [renameFileError]() {
QMessageBox::warning(ICore::mainWindow(),
tr("Project Editing Failed"),
renameFileError);
});
}
} else {
const QString renameFileError = tr("The file %1 could not be renamed %2.")
.arg(QDir::toNativeSeparators(orgFilePath))
.arg(QDir::toNativeSeparators(newFilePath));
QTimer::singleShot(0, [renameFileError]() {
QMessageBox::warning(ICore::mainWindow(),
tr("Cannot Rename File"),
renameFileError);
});
}
}
void ProjectExplorerPluginPrivate::handleSetStartupProject()
{
setStartupProject(ProjectTree::currentProject());
}
void ProjectExplorerPluginPrivate::updateSessionMenu()
{
m_sessionMenu->clear();
QActionGroup *ag = new QActionGroup(m_sessionMenu);
connect(ag, &QActionGroup::triggered, this, &ProjectExplorerPluginPrivate::setSession);
const QString activeSession = SessionManager::activeSession();
foreach (const QString &session, SessionManager::sessions()) {
QAction *act = ag->addAction(session);
act->setData(session);
act->setCheckable(true);
if (session == activeSession)
act->setChecked(true);
}
m_sessionMenu->addActions(ag->actions());
m_sessionMenu->setEnabled(true);
}
void ProjectExplorerPluginPrivate::setSession(QAction *action)
{
QString session = action->data().toString();
if (session != SessionManager::activeSession())
SessionManager::loadSession(session);
}
void ProjectExplorerPlugin::setProjectExplorerSettings(const ProjectExplorerSettings &pes)
{
QTC_ASSERT(dd->m_projectExplorerSettings.environmentId == pes.environmentId, return);
if (dd->m_projectExplorerSettings == pes)
return;
dd->m_projectExplorerSettings = pes;
emit m_instance->settingsChanged();
}
ProjectExplorerSettings ProjectExplorerPlugin::projectExplorerSettings()
{
return dd->m_projectExplorerSettings;
}
QStringList ProjectExplorerPlugin::projectFilePatterns()
{
QStringList patterns;
Utils::MimeDatabase mdb;
foreach (const IProjectManager *pm, allProjectManagers()) {
Utils::MimeType mt = mdb.mimeTypeForName(pm->mimeType());
if (mt.isValid())
patterns.append(mt.globPatterns());
}
return patterns;
}
void ProjectExplorerPlugin::openOpenProjectDialog()
{
const QString path = DocumentManager::useProjectsDirectory() ? DocumentManager::projectsDirectory() : QString();
const QStringList files = DocumentManager::getOpenFileNames(dd->m_projectFilterString, path);
if (!files.isEmpty())
ICore::openFiles(files, ICore::SwitchMode);
}
QList<QPair<QString, QString> > ProjectExplorerPlugin::recentProjects()
{
return dd->m_recentProjects;
}
} // namespace ProjectExplorer
|