Menu

[r568]: / branches / multiSCCS / src / MainDlg.cpp  Maximize  Restore  History

Download this file

2949 lines (2739 with data), 124.3 kB

   1
   2
   3
   4
   5
   6
   7
   8
   9
  10
  11
  12
  13
  14
  15
  16
  17
  18
  19
  20
  21
  22
  23
  24
  25
  26
  27
  28
  29
  30
  31
  32
  33
  34
  35
  36
  37
  38
  39
  40
  41
  42
  43
  44
  45
  46
  47
  48
  49
  50
  51
  52
  53
  54
  55
  56
  57
  58
  59
  60
  61
  62
  63
  64
  65
  66
  67
  68
  69
  70
  71
  72
  73
  74
  75
  76
  77
  78
  79
  80
  81
  82
  83
  84
  85
  86
  87
  88
  89
  90
  91
  92
  93
  94
  95
  96
  97
  98
  99
 100
 101
 102
 103
 104
 105
 106
 107
 108
 109
 110
 111
 112
 113
 114
 115
 116
 117
 118
 119
 120
 121
 122
 123
 124
 125
 126
 127
 128
 129
 130
 131
 132
 133
 134
 135
 136
 137
 138
 139
 140
 141
 142
 143
 144
 145
 146
 147
 148
 149
 150
 151
 152
 153
 154
 155
 156
 157
 158
 159
 160
 161
 162
 163
 164
 165
 166
 167
 168
 169
 170
 171
 172
 173
 174
 175
 176
 177
 178
 179
 180
 181
 182
 183
 184
 185
 186
 187
 188
 189
 190
 191
 192
 193
 194
 195
 196
 197
 198
 199
 200
 201
 202
 203
 204
 205
 206
 207
 208
 209
 210
 211
 212
 213
 214
 215
 216
 217
 218
 219
 220
 221
 222
 223
 224
 225
 226
 227
 228
 229
 230
 231
 232
 233
 234
 235
 236
 237
 238
 239
 240
 241
 242
 243
 244
 245
 246
 247
 248
 249
 250
 251
 252
 253
 254
 255
 256
 257
 258
 259
 260
 261
 262
 263
 264
 265
 266
 267
 268
 269
 270
 271
 272
 273
 274
 275
 276
 277
 278
 279
 280
 281
 282
 283
 284
 285
 286
 287
 288
 289
 290
 291
 292
 293
 294
 295
 296
 297
 298
 299
 300
 301
 302
 303
 304
 305
 306
 307
 308
 309
 310
 311
 312
 313
 314
 315
 316
 317
 318
 319
 320
 321
 322
 323
 324
 325
 326
 327
 328
 329
 330
 331
 332
 333
 334
 335
 336
 337
 338
 339
 340
 341
 342
 343
 344
 345
 346
 347
 348
 349
 350
 351
 352
 353
 354
 355
 356
 357
 358
 359
 360
 361
 362
 363
 364
 365
 366
 367
 368
 369
 370
 371
 372
 373
 374
 375
 376
 377
 378
 379
 380
 381
 382
 383
 384
 385
 386
 387
 388
 389
 390
 391
 392
 393
 394
 395
 396
 397
 398
 399
 400
 401
 402
 403
 404
 405
 406
 407
 408
 409
 410
 411
 412
 413
 414
 415
 416
 417
 418
 419
 420
 421
 422
 423
 424
 425
 426
 427
 428
 429
 430
 431
 432
 433
 434
 435
 436
 437
 438
 439
 440
 441
 442
 443
 444
 445
 446
 447
 448
 449
 450
 451
 452
 453
 454
 455
 456
 457
 458
 459
 460
 461
 462
 463
 464
 465
 466
 467
 468
 469
 470
 471
 472
 473
 474
 475
 476
 477
 478
 479
 480
 481
 482
 483
 484
 485
 486
 487
 488
 489
 490
 491
 492
 493
 494
 495
 496
 497
 498
 499
 500
 501
 502
 503
 504
 505
 506
 507
 508
 509
 510
 511
 512
 513
 514
 515
 516
 517
 518
 519
 520
 521
 522
 523
 524
 525
 526
 527
 528
 529
 530
 531
 532
 533
 534
 535
 536
 537
 538
 539
 540
 541
 542
 543
 544
 545
 546
 547
 548
 549
 550
 551
 552
 553
 554
 555
 556
 557
 558
 559
 560
 561
 562
 563
 564
 565
 566
 567
 568
 569
 570
 571
 572
 573
 574
 575
 576
 577
 578
 579
 580
 581
 582
 583
 584
 585
 586
 587
 588
 589
 590
 591
 592
 593
 594
 595
 596
 597
 598
 599
 600
 601
 602
 603
 604
 605
 606
 607
 608
 609
 610
 611
 612
 613
 614
 615
 616
 617
 618
 619
 620
 621
 622
 623
 624
 625
 626
 627
 628
 629
 630
 631
 632
 633
 634
 635
 636
 637
 638
 639
 640
 641
 642
 643
 644
 645
 646
 647
 648
 649
 650
 651
 652
 653
 654
 655
 656
 657
 658
 659
 660
 661
 662
 663
 664
 665
 666
 667
 668
 669
 670
 671
 672
 673
 674
 675
 676
 677
 678
 679
 680
 681
 682
 683
 684
 685
 686
 687
 688
 689
 690
 691
 692
 693
 694
 695
 696
 697
 698
 699
 700
 701
 702
 703
 704
 705
 706
 707
 708
 709
 710
 711
 712
 713
 714
 715
 716
 717
 718
 719
 720
 721
 722
 723
 724
 725
 726
 727
 728
 729
 730
 731
 732
 733
 734
 735
 736
 737
 738
 739
 740
 741
 742
 743
 744
 745
 746
 747
 748
 749
 750
 751
 752
 753
 754
 755
 756
 757
 758
 759
 760
 761
 762
 763
 764
 765
 766
 767
 768
 769
 770
 771
 772
 773
 774
 775
 776
 777
 778
 779
 780
 781
 782
 783
 784
 785
 786
 787
 788
 789
 790
 791
 792
 793
 794
 795
 796
 797
 798
 799
 800
 801
 802
 803
 804
 805
 806
 807
 808
 809
 810
 811
 812
 813
 814
 815
 816
 817
 818
 819
 820
 821
 822
 823
 824
 825
 826
 827
 828
 829
 830
 831
 832
 833
 834
 835
 836
 837
 838
 839
 840
 841
 842
 843
 844
 845
 846
 847
 848
 849
 850
 851
 852
 853
 854
 855
 856
 857
 858
 859
 860
 861
 862
 863
 864
 865
 866
 867
 868
 869
 870
 871
 872
 873
 874
 875
 876
 877
 878
 879
 880
 881
 882
 883
 884
 885
 886
 887
 888
 889
 890
 891
 892
 893
 894
 895
 896
 897
 898
 899
 900
 901
 902
 903
 904
 905
 906
 907
 908
 909
 910
 911
 912
 913
 914
 915
 916
 917
 918
 919
 920
 921
 922
 923
 924
 925
 926
 927
 928
 929
 930
 931
 932
 933
 934
 935
 936
 937
 938
 939
 940
 941
 942
 943
 944
 945
 946
 947
 948
 949
 950
 951
 952
 953
 954
 955
 956
 957
 958
 959
 960
 961
 962
 963
 964
 965
 966
 967
 968
 969
 970
 971
 972
 973
 974
 975
 976
 977
 978
 979
 980
 981
 982
 983
 984
 985
 986
 987
 988
 989
 990
 991
 992
 993
 994
 995
 996
 997
 998
 999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
1432
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
1443
1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
1519
1520
1521
1522
1523
1524
1525
1526
1527
1528
1529
1530
1531
1532
1533
1534
1535
1536
1537
1538
1539
1540
1541
1542
1543
1544
1545
1546
1547
1548
1549
1550
1551
1552
1553
1554
1555
1556
1557
1558
1559
1560
1561
1562
1563
1564
1565
1566
1567
1568
1569
1570
1571
1572
1573
1574
1575
1576
1577
1578
1579
1580
1581
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
1689
1690
1691
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
1706
1707
1708
1709
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
1829
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
1849
1850
1851
1852
1853
1854
1855
1856
1857
1858
1859
1860
1861
1862
1863
1864
1865
1866
1867
1868
1869
1870
1871
1872
1873
1874
1875
1876
1877
1878
1879
1880
1881
1882
1883
1884
1885
1886
1887
1888
1889
1890
1891
1892
1893
1894
1895
1896
1897
1898
1899
1900
1901
1902
1903
1904
1905
1906
1907
1908
1909
1910
1911
1912
1913
1914
1915
1916
1917
1918
1919
1920
1921
1922
1923
1924
1925
1926
1927
1928
1929
1930
1931
1932
1933
1934
1935
1936
1937
1938
1939
1940
1941
1942
1943
1944
1945
1946
1947
1948
1949
1950
1951
1952
1953
1954
1955
1956
1957
1958
1959
1960
1961
1962
1963
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
2036
2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
2096
2097
2098
2099
2100
2101
2102
2103
2104
2105
2106
2107
2108
2109
2110
2111
2112
2113
2114
2115
2116
2117
2118
2119
2120
2121
2122
2123
2124
2125
2126
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
2260
2261
2262
2263
2264
2265
2266
2267
2268
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
2287
2288
2289
2290
2291
2292
2293
2294
2295
2296
2297
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
2312
2313
2314
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
2327
2328
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
2339
2340
2341
2342
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
2356
2357
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
2370
2371
2372
2373
2374
2375
2376
2377
2378
2379
2380
2381
2382
2383
2384
2385
2386
2387
2388
2389
2390
2391
2392
2393
2394
2395
2396
2397
2398
2399
2400
2401
2402
2403
2404
2405
2406
2407
2408
2409
2410
2411
2412
2413
2414
2415
2416
2417
2418
2419
2420
2421
2422
2423
2424
2425
2426
2427
2428
2429
2430
2431
2432
2433
2434
2435
2436
2437
2438
2439
2440
2441
2442
2443
2444
2445
2446
2447
2448
2449
2450
2451
2452
2453
2454
2455
2456
2457
2458
2459
2460
2461
2462
2463
2464
2465
2466
2467
2468
2469
2470
2471
2472
2473
2474
2475
2476
2477
2478
2479
2480
2481
2482
2483
2484
2485
2486
2487
2488
2489
2490
2491
2492
2493
2494
2495
2496
2497
2498
2499
2500
2501
2502
2503
2504
2505
2506
2507
2508
2509
2510
2511
2512
2513
2514
2515
2516
2517
2518
2519
2520
2521
2522
2523
2524
2525
2526
2527
2528
2529
2530
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
2542
2543
2544
2545
2546
2547
2548
2549
2550
2551
2552
2553
2554
2555
2556
2557
2558
2559
2560
2561
2562
2563
2564
2565
2566
2567
2568
2569
2570
2571
2572
2573
2574
2575
2576
2577
2578
2579
2580
2581
2582
2583
2584
2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
2595
2596
2597
2598
2599
2600
2601
2602
2603
2604
2605
2606
2607
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
2629
2630
2631
2632
2633
2634
2635
2636
2637
2638
2639
2640
2641
2642
2643
2644
2645
2646
2647
2648
2649
2650
2651
2652
2653
2654
2655
2656
2657
2658
2659
2660
2661
2662
2663
2664
2665
2666
2667
2668
2669
2670
2671
2672
2673
2674
2675
2676
2677
2678
2679
2680
2681
2682
2683
2684
2685
2686
2687
2688
2689
2690
2691
2692
2693
2694
2695
2696
2697
2698
2699
2700
2701
2702
2703
2704
2705
2706
2707
2708
2709
2710
2711
2712
2713
2714
2715
2716
2717
2718
2719
2720
2721
2722
2723
2724
2725
2726
2727
2728
2729
2730
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
2742
2743
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
2759
2760
2761
2762
2763
2764
2765
2766
2767
2768
2769
2770
2771
2772
2773
2774
2775
2776
2777
2778
2779
2780
2781
2782
2783
2784
2785
2786
2787
2788
2789
2790
2791
2792
2793
2794
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
2807
2808
2809
2810
2811
2812
2813
2814
2815
2816
2817
2818
2819
2820
2821
2822
2823
2824
2825
2826
2827
2828
2829
2830
2831
2832
2833
2834
2835
2836
2837
2838
2839
2840
2841
2842
2843
2844
2845
2846
2847
2848
2849
2850
2851
2852
2853
2854
2855
2856
2857
2858
2859
2860
2861
2862
2863
2864
2865
2866
2867
2868
2869
2870
2871
2872
2873
2874
2875
2876
2877
2878
2879
2880
2881
2882
2883
2884
2885
2886
2887
2888
2889
2890
2891
2892
2893
2894
2895
2896
2897
2898
2899
2900
2901
2902
2903
2904
2905
2906
2907
2908
2909
2910
2911
2912
2913
2914
2915
2916
2917
2918
2919
2920
2921
2922
2923
2924
2925
2926
2927
2928
2929
2930
2931
2932
2933
2934
2935
2936
2937
2938
2939
2940
2941
2942
2943
2944
2945
2946
2947
2948
// CommitMonitor - simple checker for new commits in svn repositories
// Copyright (C) 2007-2010 - Stefan Kueng
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License
// as published by the Free Software Foundation; either version 2
// of the License, or (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software Foundation,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "StdAfx.h"
#include "Resource.h"
#include "MainDlg.h"
#include "URLDlg.h"
#include "OptionsDlg.h"
#include "AboutDlg.h"
#include "UpdateDlg.h"
#include "AppUtils.h"
#include "DirFileEnum.h"
#include <algorithm>
#include <assert.h>
#include <cctype>
#include <regex>
#define FILTERBOXHEIGHT 20
#define FILTERLABELWIDTH 50
CMainDlg::CMainDlg(HWND hParent)
: m_nDragMode(DRAGMODE_NONE)
, m_oldx(-1)
, m_oldy(-1)
, m_boldFont(NULL)
, m_font(NULL)
, m_pURLInfos(NULL)
, m_bBlockListCtrlUI(false)
, m_hTreeControl(NULL)
, m_hListControl(NULL)
, m_hLogMsgControl(NULL)
, m_hToolbarImages(NULL)
, m_hImgList(NULL)
, m_bNewerVersionAvailable(false)
, m_refreshNeeded(false)
{
m_hParent = hParent;
// use the default GUI font, create a copy of it and
// change the copy to BOLD (leave the rest of the font
// the same)
HFONT hFont = (HFONT)GetStockObject(DEFAULT_GUI_FONT);
LOGFONT lf = {0};
GetObject(hFont, sizeof(LOGFONT), &lf);
lf.lfWeight = FW_BOLD;
m_boldFont = CreateFontIndirect(&lf);
}
CMainDlg::~CMainDlg(void)
{
if (m_boldFont)
DeleteObject(m_boldFont);
if (m_font)
DeleteObject(m_font);
if (m_hToolbarImages)
ImageList_Destroy(m_hToolbarImages);
if (m_hImgList)
ImageList_Destroy(m_hImgList);
}
bool CMainDlg::CreateToolbar()
{
m_hwndToolbar = CreateWindowEx(0,
TOOLBARCLASSNAME,
(LPCTSTR)NULL,
WS_CHILD | WS_BORDER | WS_VISIBLE | TBSTYLE_FLAT | TBSTYLE_TOOLTIPS,
0, 0, 0, 0,
*this,
(HMENU)IDR_MAINDLG,
hResource,
NULL);
if (m_hwndToolbar == INVALID_HANDLE_VALUE)
return false;
SendMessage(m_hwndToolbar, TB_BUTTONSTRUCTSIZE, (WPARAM) sizeof(TBBUTTON), 0);
#define MAINDLG_TOOLBARBUTTONCOUNT 11
TBBUTTON tbb[MAINDLG_TOOLBARBUTTONCOUNT];
// create an image list containing the icons for the toolbar
m_hToolbarImages = ImageList_Create(24, 24, ILC_COLOR32 | ILC_MASK, MAINDLG_TOOLBARBUTTONCOUNT, 4);
if (m_hToolbarImages == NULL)
return false;
int index = 0;
HICON hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_GETALL));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MAIN_CHECKREPOSITORIESNOW;
tbb[index].fsState = TBSTATE_ENABLED|BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Check Now");
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_ADD));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MAIN_ADDPROJECT;
tbb[index].fsState = TBSTATE_ENABLED|BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Add Project");
tbb[index].iBitmap = 0;
tbb[index].idCommand = 0;
tbb[index].fsState = TBSTATE_ENABLED;
tbb[index].fsStyle = BTNS_SEP;
tbb[index].dwData = 0;
tbb[index++].iString = 0;
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_EDIT));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MAIN_EDIT;
tbb[index].fsState = BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("E&dit");
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_REMOVE));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MAIN_REMOVE;
tbb[index].fsState = BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Remove");
tbb[index].iBitmap = 0;
tbb[index].idCommand = 0;
tbb[index].fsState = TBSTATE_ENABLED;
tbb[index].fsStyle = BTNS_SEP;
tbb[index].dwData = 0;
tbb[index++].iString = 0;
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_DIFF));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MAIN_SHOWDIFFCHOOSE;
tbb[index].fsState = BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Show Diff");
tbb[index].iBitmap = 0;
tbb[index].idCommand = 0;
tbb[index].fsState = TBSTATE_ENABLED;
tbb[index].fsStyle = BTNS_SEP;
tbb[index].dwData = 0;
tbb[index++].iString = 0;
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_MARKASREAD));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_POPUP_MARKALLASREAD;
tbb[index].fsState = TBSTATE_ENABLED|BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Mark all as read");
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_OPTIONS));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MISC_OPTIONS;
tbb[index].fsState = TBSTATE_ENABLED|BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("&Options");
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_ABOUT));
tbb[index].iBitmap = ImageList_AddIcon(m_hToolbarImages, hIcon);
tbb[index].idCommand = ID_MISC_ABOUT;
tbb[index].fsState = TBSTATE_ENABLED|BTNS_SHOWTEXT;
tbb[index].fsStyle = BTNS_BUTTON;
tbb[index].dwData = 0;
tbb[index++].iString = (INT_PTR)_T("A&bout");
SendMessage(m_hwndToolbar, TB_SETIMAGELIST, 0, (LPARAM)m_hToolbarImages);
SendMessage(m_hwndToolbar, TB_ADDBUTTONS, (WPARAM)index, (LPARAM) (LPTBBUTTON) &tbb);
SendMessage(m_hwndToolbar, TB_AUTOSIZE, 0, 0);
ShowWindow(m_hwndToolbar, SW_SHOW);
return true;
}
LRESULT CMainDlg::DlgFunc(HWND hwndDlg, UINT uMsg, WPARAM wParam, LPARAM lParam)
{
switch (uMsg)
{
case WM_INITDIALOG:
{
InitDialog(hwndDlg, IDI_COMMITMONITOR);
CreateToolbar();
AddToolTip(IDC_FILTERSTRING, _T("Enter a filter string\nPrepend the string with an '-' to negate the filter.\nPrepend the string with an '\\' to filter with a regex."));
// RA Sewell
// Set defaults for the registry values is nothing exists
CRegStdString regAccurevExe = CRegStdString(_T("Software\\CommitMonitor\\AccurevExe"));
wstring sAccurevExe(regAccurevExe);
if (sAccurevExe.size() == 0) {
regAccurevExe = _T("C:\\Program Files\\AccuRev\\bin\\accurev.EXE"); // Writes value to registry
}
CRegStdString regAccurevDiffCmd = CRegStdString(_T("Software\\CommitMonitor\\AccurevDiffCmd"));
wstring sAccurevDiffCmd(regAccurevDiffCmd);
if (sAccurevDiffCmd.size() == 0) {
regAccurevDiffCmd = _T("\"C:\\Program Files\\WinMerge\\WinMergeU.exe\" /e /u /r /dl \"%OLD\" /dr \"%NEW\" \"%1\" \"%2\"");
}
m_hTreeControl = ::GetDlgItem(*this, IDC_URLTREE);
m_hListControl = ::GetDlgItem(*this, IDC_MONITOREDURLS);
m_hLogMsgControl = ::GetDlgItem(*this, IDC_LOGINFO);
m_hFilterControl = ::GetDlgItem(*this, IDC_FILTERSTRING);
::SendMessage(m_hTreeControl, TVM_SETUNICODEFORMAT, 1, 0);
assert(m_pURLInfos);
m_hImgList = ImageList_Create(16, 16, ILC_COLOR32, 6, 6);
if (m_hImgList)
{
HICON hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_PARENTPATHFOLDER));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_PARENTPATHFOLDEROPEN));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_REPOURL));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_REPOURLNEW));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_REPOURLFAIL));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
hIcon = LoadIcon(hResource, MAKEINTRESOURCE(IDI_REPOURLINACTIVE));
ImageList_AddIcon(m_hImgList, hIcon);
DestroyIcon(hIcon);
TreeView_SetImageList(m_hTreeControl, m_hImgList, LVSIL_SMALL);
TreeView_SetImageList(m_hTreeControl, m_hImgList, LVSIL_NORMAL);
}
LOGFONT lf = {0};
HDC hDC = ::GetDC(m_hLogMsgControl);
lf.lfHeight = -MulDiv(8, GetDeviceCaps(hDC, LOGPIXELSY), 72);
lf.lfCharSet = DEFAULT_CHARSET;
_tcscpy_s(lf.lfFaceName, 32, _T("Courier New"));
m_font = ::CreateFontIndirect(&lf);
ReleaseDC(m_hLogMsgControl, hDC);
::SendMessage(m_hLogMsgControl, WM_SETFONT, (WPARAM)m_font, 1);
// initialize the window position infos
RECT rect;
GetClientRect(m_hwndToolbar, &rect);
m_topmarg = rect.bottom+2;
GetClientRect(m_hTreeControl, &rect);
m_xSliderPos = rect.right+4;
GetClientRect(m_hListControl, &rect);
m_ySliderPos = rect.bottom+m_topmarg;
GetClientRect(m_hLogMsgControl, &rect);
m_bottommarg = rect.bottom+4+m_ySliderPos;
GetClientRect(*this, &rect);
m_bottommarg = rect.bottom - m_bottommarg;
// subclass the tree view control to intercept the WM_SETFOCUS messages
m_oldTreeWndProc = (WNDPROC)SetWindowLongPtr(m_hTreeControl, GWLP_WNDPROC, (LONG)TreeProc);
SetWindowLongPtr(m_hTreeControl, GWLP_USERDATA, (LONG)this);
m_oldFilterWndProc = (WNDPROC)SetWindowLongPtr(m_hFilterControl, GWLP_WNDPROC, (LONG)FilterProc);
SetWindowLongPtr(m_hFilterControl, GWLP_USERDATA, (LONG)this);
m_ListCtrl.SubClassListCtrl(m_hListControl);
::SetTimer(*this, TIMER_REFRESH, 1000, NULL);
SendMessage(m_hParent, COMMITMONITOR_SETWINDOWHANDLE, (WPARAM)(HWND)*this, NULL);
CRegStdDWORD regXY(_T("Software\\CommitMonitor\\XY"));
if (DWORD(regXY))
{
CRegStdDWORD regWHWindow(_T("Software\\CommitMonitor\\WHWindow"));
if (DWORD(regWHWindow))
{
CRegStdDWORD regWH(_T("Software\\CommitMonitor\\WH"));
if (DWORD(regWH))
{
// x,y position and width/height are valid
//
// check whether the rectangle is at least partly
// visible in at least one monitor
RECT rc = {0};
rc.left = HIWORD(DWORD(regXY));
rc.top = LOWORD(DWORD(regXY));
rc.right = HIWORD(DWORD(regWHWindow)) + rc.left;
rc.bottom = LOWORD(DWORD(regWHWindow)) + rc.top;
if (MonitorFromRect(&rc, MONITOR_DEFAULTTONULL))
{
SetWindowPos(*this, HWND_TOP, rc.left, rc.top, HIWORD(DWORD(regWHWindow)), LOWORD(DWORD(regWHWindow)), SWP_SHOWWINDOW);
DoResize(HIWORD(DWORD(regWH)), LOWORD(DWORD(regWH)));
// now restore the slider positions
CRegStdDWORD regHorzPos(_T("Software\\CommitMonitor\\HorzPos"));
if (DWORD(regHorzPos))
{
POINT pt;
pt.x = pt.y = DWORD(regHorzPos)+2; // +2 because the slider is 4 pixels wide
PositionChildWindows(pt, true, false);
}
CRegStdDWORD regVertPos(_T("Software\\CommitMonitor\\VertPos"));
if (DWORD(regVertPos))
{
POINT pt;
pt.x = pt.y = DWORD(regVertPos)+2; // +2 because the slider is 4 pixels wide
PositionChildWindows(pt, false, false);
}
// adjust the slider position infos
GetClientRect(m_hTreeControl, &rect);
m_xSliderPos = rect.right+4;
GetClientRect(m_hListControl, &rect);
m_ySliderPos = rect.bottom+m_topmarg;
}
}
}
}
CRegStdDWORD regMaximized(_T("Software\\CommitMonitor\\Maximized"));
if( DWORD(regMaximized) )
{
ShowWindow(*this, SW_MAXIMIZE);
// now restore the slider positions
CRegStdDWORD regHorzPos(_T("Software\\CommitMonitor\\HorzPosZoomed"));
if (DWORD(regHorzPos))
{
POINT pt;
pt.x = pt.y = DWORD(regHorzPos)+2; // +2 because the slider is 4 pixels wide
PositionChildWindows(pt, true, false);
}
CRegStdDWORD regVertPos(_T("Software\\CommitMonitor\\VertPosZoomed"));
if (DWORD(regVertPos))
{
POINT pt;
pt.x = pt.y = DWORD(regVertPos)+2; // +2 because the slider is 4 pixels wide
PositionChildWindows(pt, false, false);
}
// adjust the slider position infos
GetClientRect(m_hTreeControl, &rect);
m_xSliderPos = rect.right+4;
GetClientRect(m_hListControl, &rect);
m_ySliderPos = rect.bottom+m_topmarg;
}
RefreshURLTree(true);
ExtendFrameIntoClientArea(0, 0, 0, IDC_URLTREE);
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDC_INFOLABEL));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDOK));
m_aerocontrols.SubclassControl(GetDlgItem(*this, IDC_EXIT));
if (m_bNewerVersionAvailable)
{
CUpdateDlg dlg(*this);
dlg.DoModal(hResource, IDD_NEWERNOTIFYDLG, *this);
}
}
break;
case WM_SIZE:
{
if (wParam == SIZE_MINIMIZED)
{
EndDialog(*this, IDCANCEL);
return 0;
}
DoResize(LOWORD(lParam), HIWORD(lParam));
}
break;
case WM_SYSCOMMAND:
{
CRegStdDWORD regMaximized(_T("Software\\CommitMonitor\\Maximized"));
if ((wParam & 0xFFF0) == SC_MAXIMIZE)
{
regMaximized = 1;
}
if ((wParam & 0xFFF0) == SC_RESTORE)
{
regMaximized = 0;
}
SaveWndPosition();
return FALSE;
}
break;
case WM_MOVING:
{
#define STICKYSIZE 3
LPRECT pRect = (LPRECT)lParam;
if (pRect)
{
HMONITOR hMonitor = MonitorFromRect(pRect, MONITOR_DEFAULTTONEAREST);
if (hMonitor)
{
MONITORINFO minfo = {0};
minfo.cbSize = sizeof(minfo);
if (GetMonitorInfo(hMonitor, &minfo))
{
int width = pRect->right - pRect->left;
int heigth = pRect->bottom - pRect->top;
if (abs(pRect->left - minfo.rcWork.left) < STICKYSIZE)
{
pRect->left = minfo.rcWork.left;
pRect->right = pRect->left + width;
}
if (abs(pRect->right - minfo.rcWork.right) < STICKYSIZE)
{
pRect->right = minfo.rcWork.right;
pRect->left = pRect->right - width;
}
if (abs(pRect->top - minfo.rcWork.top) < STICKYSIZE)
{
pRect->top = minfo.rcWork.top;
pRect->bottom = pRect->top + heigth;
}
if (abs(pRect->bottom - minfo.rcWork.bottom) < STICKYSIZE)
{
pRect->bottom = minfo.rcWork.bottom;
pRect->top = pRect->bottom - heigth;
}
}
}
}
}
break;
case WM_GETMINMAXINFO:
{
MINMAXINFO * mmi = (MINMAXINFO*)lParam;
mmi->ptMinTrackSize.x = m_xSliderPos + 100;
mmi->ptMinTrackSize.y = m_ySliderPos + 100;
return 0;
}
break;
case WM_COMMAND:
if ((HIWORD(wParam) == EN_CHANGE)&&((HWND)lParam == m_hFilterControl))
{
// start the filter timer
::SetTimer(*this, TIMER_FILTER, FILTER_ELAPSE, NULL);
}
return DoCommand(LOWORD(wParam));
break;
case WM_SETCURSOR:
{
return OnSetCursor((HWND)wParam, LOWORD(lParam), HIWORD(lParam));
}
break;
case WM_MOUSEMOVE:
{
POINT pt = {LOWORD(lParam), HIWORD(lParam)};
return OnMouseMove(wParam, pt);
}
break;
case WM_LBUTTONDOWN:
{
POINT pt = {LOWORD(lParam), HIWORD(lParam)};
return OnLButtonDown(wParam, pt);
}
break;
case WM_LBUTTONUP:
{
POINT pt = {LOWORD(lParam), HIWORD(lParam)};
return OnLButtonUp(wParam, pt);
}
break;
case WM_TIMER:
{
if (wParam == TIMER_LABEL)
{
SetDlgItemText(*this, IDC_INFOLABEL, _T(""));
KillTimer(*this, TIMER_LABEL);
}
else if (wParam == TIMER_FILTER)
{
KillTimer(*this, TIMER_FILTER);
TreeItemSelected(m_hTreeControl, TreeView_GetSelection(m_hTreeControl));
}
else if (wParam == TIMER_REFRESH)
{
const map<wstring, CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
for (map<wstring, CUrlInfo>::const_iterator it = pRead->begin(); it != pRead->end(); ++it)
{
TVINSERTSTRUCT tv = {0};
tv.hParent = FindParentTreeNode(it->first);
tv.hInsertAfter = TVI_SORT;
tv.itemex.mask = TVIF_TEXT|TVIF_PARAM|TVIF_STATE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
WCHAR * str = new WCHAR[it->second.name.size()+10];
// find out if there are some unread entries
int unread = 0;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator logit = it->second.logentries.begin(); logit != it->second.logentries.end(); ++logit)
{
if (!logit->second.read)
unread++;
}
tv.itemex.pszText = str;
tv.itemex.lParam = (LPARAM)&it->first;
HTREEITEM directItem = FindTreeNode(it->first);
if (directItem != TVI_ROOT)
{
// The node already exists, just update the information
tv.itemex.hItem = directItem;
tv.itemex.stateMask = TVIS_SELECTED|TVIS_BOLD|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
tv.itemex.pszText = str;
tv.itemex.cchTextMax = it->second.name.size()+9;
TreeView_GetItem(m_hTreeControl, &tv.itemex);
wstring sTitle = wstring(str);
bool bRequiresUpdate = false;
if (unread)
{
_stprintf_s(str, it->second.name.size()+10, _T("%s (%d)"), it->second.name.c_str(), unread);
tv.itemex.state |= TVIS_BOLD;
tv.itemex.stateMask = TVIS_BOLD;
}
else
{
_tcscpy_s(str, it->second.name.size()+1, it->second.name.c_str());
tv.itemex.state &= ~TVIS_BOLD;
tv.itemex.stateMask = TVIS_BOLD;
}
if (it->second.parentpath)
{
bRequiresUpdate = (tv.itemex.iImage != 0) || (tv.itemex.iSelectedImage != 1);
tv.itemex.iImage = 0;
tv.itemex.iSelectedImage = 1;
}
else
{
if (!it->second.error.empty())
{
bRequiresUpdate = tv.itemex.iImage != 4;
tv.itemex.iImage = 4;
tv.itemex.iSelectedImage = 4;
}
else if (unread)
{
bRequiresUpdate = tv.itemex.iImage != 3;
tv.itemex.iImage = 3;
tv.itemex.iSelectedImage = 3;
}
else if (!it->second.monitored)
{
bRequiresUpdate = tv.itemex.iImage != 5;
tv.itemex.iImage = 5;
tv.itemex.iSelectedImage = 5;
}
else
{
bRequiresUpdate = tv.itemex.iImage != 2;
tv.itemex.iImage = 2;
tv.itemex.iSelectedImage = 2;
}
}
if ((bRequiresUpdate)||(sTitle.compare(str) != 0)||
((tv.itemex.state & TVIS_SELECTED)&&(m_refreshNeeded)))
{
m_refreshNeeded = false;
TreeView_SetItem(m_hTreeControl, &tv.itemex);
if (tv.itemex.state & TVIS_SELECTED)
{
m_bBlockListCtrlUI = true;
int listCount = ListView_GetItemCount(m_hListControl);
int listSelMark = ListView_GetSelectionMark(m_hListControl);
TreeItemSelected(m_hTreeControl, tv.itemex.hItem);
// re-set the currently selected item
int itemsAdded = ListView_GetItemCount(m_hListControl) - listCount;
m_bBlockListCtrlUI = false;
if (ListView_GetItemState(m_hListControl, listSelMark + itemsAdded, LVIS_SELECTED) & LVIS_SELECTED)
{
ListView_SetSelectionMark(m_hListControl, listSelMark + itemsAdded);
ListView_SetItemState(m_hListControl, listSelMark + itemsAdded, LVIS_SELECTED, LVIS_SELECTED);
}
}
}
}
else
{
if (unread)
{
_stprintf_s(str, it->second.name.size()+10, _T("%s (%d)"), it->second.name.c_str(), unread);
tv.itemex.state = TVIS_BOLD;
tv.itemex.stateMask = TVIS_BOLD;
}
else
{
_tcscpy_s(str, it->second.name.size()+1, it->second.name.c_str());
tv.itemex.state = 0;
tv.itemex.stateMask = TVIS_BOLD;
}
m_bBlockListCtrlUI = true;
if (it->second.parentpath)
{
tv.itemex.iImage = 0;
tv.itemex.iSelectedImage = 1;
}
else
{
if (!it->second.error.empty())
{
tv.itemex.iImage = 4;
tv.itemex.iSelectedImage = 4;
}
else if (unread)
{
tv.itemex.iImage = 3;
tv.itemex.iSelectedImage = 3;
}
else
{
tv.itemex.iImage = 2;
tv.itemex.iSelectedImage = 2;
}
}
TreeView_InsertItem(m_hTreeControl, &tv);
TreeView_Expand(m_hTreeControl, tv.hParent, TVE_EXPAND);
m_bBlockListCtrlUI = false;
}
delete [] str;
}
m_pURLInfos->ReleaseReadOnlyData();
::InvalidateRect(m_hListControl, NULL, true);
}
}
break;
case WM_NOTIFY:
{
LPNMHDR lpnmhdr = (LPNMHDR)lParam;
if ((lpnmhdr->code == TVN_SELCHANGED)&&(lpnmhdr->hwndFrom == m_hTreeControl))
{
OnSelectTreeItem((LPNMTREEVIEW)lParam);
return TRUE;
}
if ((lpnmhdr->code == LVN_ITEMCHANGING)&&(lpnmhdr->hwndFrom == m_hListControl))
{
LPNMLISTVIEW lpNMListView = (LPNMLISTVIEW)lParam;
if ((lpNMListView)&&(((lpNMListView->uOldState ^ lpNMListView->uNewState) & LVIS_SELECTED)&&(m_ListCtrl.InfoTextShown())))
{
return TRUE;
}
}
if ((lpnmhdr->code == LVN_ITEMCHANGED)&&(lpnmhdr->hwndFrom == m_hListControl))
{
OnSelectListItem((LPNMLISTVIEW)lParam);
}
if ((lpnmhdr->code == LVN_KEYDOWN)&&(lpnmhdr->hwndFrom == m_hListControl))
{
OnKeyDownListItem((LPNMLVKEYDOWN)lParam);
}
if ((lpnmhdr->code == NM_CUSTOMDRAW)&&(lpnmhdr->hwndFrom == m_hListControl))
{
return OnCustomDrawListItem((LPNMLVCUSTOMDRAW)lParam);
}
if ((lpnmhdr->code == NM_CUSTOMDRAW)&&(lpnmhdr->hwndFrom == m_hTreeControl))
{
return OnCustomDrawTreeItem((LPNMTVCUSTOMDRAW)lParam);
}
if ((lpnmhdr->code == NM_DBLCLK)&&(lpnmhdr->hwndFrom == m_hListControl))
{
OnDblClickListItem((LPNMITEMACTIVATE)lParam);
}
return FALSE;
}
break;
case WM_CONTEXTMENU:
{
POINT pt;
pt.x = GET_X_LPARAM(lParam);
pt.y = GET_Y_LPARAM(lParam);
if (HWND(wParam) == m_hTreeControl)
{
TVHITTESTINFO hittest = {0};
if (pt.x == -1 && pt.y == -1)
{
hittest.hItem = TreeView_GetSelection(m_hTreeControl);
if (hittest.hItem)
{
hittest.flags = TVHT_ONITEM;
RECT rect;
TreeView_GetItemRect(m_hTreeControl, hittest.hItem, &rect, TRUE);
pt.x = rect.left + ((rect.right-rect.left)/2);
pt.y = rect.top + ((rect.bottom - rect.top)/2);
ClientToScreen(m_hTreeControl, &pt);
}
}
else
{
POINT clPt = pt;
::ScreenToClient(m_hTreeControl, &clPt);
hittest.pt = clPt;
TreeView_HitTest(m_hTreeControl, &hittest);
}
if (hittest.flags & TVHT_ONITEM)
{
HTREEITEM hSel = TreeView_GetSelection(m_hTreeControl);
m_bBlockListCtrlUI = true;
TreeView_SelectItem(m_hTreeControl, hittest.hItem);
m_bBlockListCtrlUI = false;
HMENU hMenu = NULL;
wstring tsvninstalled = CAppUtils::GetTSVNPath();
if (tsvninstalled.empty())
hMenu = ::LoadMenu(hResource, MAKEINTRESOURCE(IDR_TREEPOPUP));
else
hMenu = ::LoadMenu(hResource, MAKEINTRESOURCE(IDR_TREEPOPUPTSVN));
hMenu = ::GetSubMenu(hMenu, 0);
TVITEMEX itemex = {0};
itemex.hItem = hittest.hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * info = &pRead->find(*(wstring*)itemex.lParam)->second;
if (info)
{
CheckMenuItem(hMenu, ID_POPUP_ACTIVE, MF_BYCOMMAND | (info->monitored ? MF_CHECKED : MF_UNCHECKED));
if (!info->parentpath)
{
// remove the 'mark all as read' since this is not a parent (SVNParentPath) item
DeleteMenu(hMenu, ID_POPUP_MARKALLASREAD, MF_BYCOMMAND);
}
}
}
m_pURLInfos->ReleaseReadOnlyData();
int cmd = ::TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY , pt.x, pt.y, NULL, *this, NULL);
m_bBlockListCtrlUI = true;
TreeView_SelectItem(m_hTreeControl, hSel);
m_bBlockListCtrlUI = false;
switch (cmd)
{
case ID_POPUP_ADDPROJECTWITHTEMPLATE:
case ID_MAIN_EDIT:
case ID_MAIN_REMOVE:
case ID_POPUP_REPOBROWSER:
case ID_POPUP_SHOWLOG:
{
HTREEITEM hSel = TreeView_GetSelection(m_hTreeControl);
m_bBlockListCtrlUI = true;
TreeView_SelectItem(m_hTreeControl, hittest.hItem);
m_bBlockListCtrlUI = false;
::SendMessage(*this, WM_COMMAND, MAKELONG(cmd, 0), 0);
m_bBlockListCtrlUI = true;
TreeView_SelectItem(m_hTreeControl, hSel);
m_bBlockListCtrlUI = false;
}
break;
case ID_POPUP_MARKALLASREAD:
MarkAllAsRead(hittest.hItem, true);
break;
case ID_POPUP_CHECKNOW:
CheckNow(hittest.hItem);
break;
case ID_POPUP_MARKNODEASREAD:
MarkAllAsRead(hittest.hItem, false);
break;
case ID_POPUP_REFRESHALL:
RefreshAll(hittest.hItem);
break;
case ID_POPUP_ACTIVE:
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
CUrlInfo * info = &pWrite->find(*(wstring*)itemex.lParam)->second;
if (info)
{
info->monitored = !info->monitored;
}
}
m_pURLInfos->ReleaseWriteData();
::SendMessage(m_hParent, COMMITMONITOR_CHANGEDINFO, (WPARAM)false, (LPARAM)0);
break;
}
}
}
else if (HWND(wParam) == m_hListControl)
{
LVHITTESTINFO hittest = {0};
if (pt.x == -1 && pt.y == -1)
{
hittest.iItem = ListView_GetSelectionMark(m_hListControl);
if (hittest.iItem >= 0)
{
hittest.flags = LVHT_ONITEM;
RECT rect;
ListView_GetItemRect(m_hListControl, hittest.iItem, &rect, LVIR_LABEL);
pt.x = rect.left + ((rect.right-rect.left)/2);
pt.y = rect.top + ((rect.bottom - rect.top)/2);
ClientToScreen(m_hListControl, &pt);
}
}
else
{
POINT clPt = pt;
::ScreenToClient(m_hListControl, &clPt);
hittest.pt = clPt;
ListView_HitTest(m_hListControl, &hittest);
}
if (hittest.flags & LVHT_ONITEM)
{
HMENU hMenu = NULL;
wstring tsvninstalled = CAppUtils::GetTSVNPath();
if (tsvninstalled.empty())
hMenu = ::LoadMenu(hResource, MAKEINTRESOURCE(IDR_LISTPOPUP));
else
hMenu = ::LoadMenu(hResource, MAKEINTRESOURCE(IDR_LISTPOPUPTSVN));
hMenu = ::GetSubMenu(hMenu, 0);
UINT uItem = 0;
if ((!wstring(tsvninstalled).empty()) && (!DWORD(CRegStdDWORD(_T("Software\\CommitMonitor\\UseTSVN"), TRUE))))
uItem = 1;
// set the default entry
MENUITEMINFO iinfo = {0};
iinfo.cbSize = sizeof(MENUITEMINFO);
iinfo.fMask = MIIM_STATE;
GetMenuItemInfo(hMenu, uItem, MF_BYPOSITION, &iinfo);
iinfo.fState |= MFS_DEFAULT;
SetMenuItemInfo(hMenu, uItem, MF_BYPOSITION, &iinfo);
// enable the "Open WebViewer" entry if there is one specified
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = TreeView_GetSelection(m_hTreeControl);
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * info = &pRead->find(*(wstring*)itemex.lParam)->second;
if ((info)&&(!info->webviewer.empty()))
{
uItem = wstring(tsvninstalled).empty() ? 1 : 2;
GetMenuItemInfo(hMenu, uItem, MF_BYPOSITION, &iinfo);
iinfo.fState &= ~MFS_DISABLED;
SetMenuItemInfo(hMenu, uItem, MF_BYPOSITION, &iinfo);
}
}
m_pURLInfos->ReleaseReadOnlyData();
int cmd = ::TrackPopupMenu(hMenu, TPM_RETURNCMD | TPM_LEFTALIGN | TPM_NONOTIFY , pt.x, pt.y, NULL, *this, NULL);
switch (cmd)
{
case ID_POPUP_MARKASUNREAD:
{
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
if (itemex.lParam != 0)
{
LVITEM item = {0};
int nItemCount = ListView_GetItemCount(m_hListControl);
for (int i=0; i<nItemCount; ++i)
{
item.mask = LVIF_PARAM|LVIF_STATE;
item.stateMask = LVIS_SELECTED;
item.iItem = i;
ListView_GetItem(m_hListControl, &item);
if (item.state & LVIS_SELECTED)
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
if (pLogEntry)
{
// set the entry as unread
if (pLogEntry->read)
{
pLogEntry->read = false;
// refresh the name of the tree item to indicate the new
// number of unread log messages
// e.g. instead of 'TortoiseSVN (2)', show now 'TortoiseSVN (3)'
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * uinfo = &pRead->find(*(wstring*)itemex.lParam)->second;
// count the number of unread messages
int unread = 0;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator it = uinfo->logentries.begin(); it != uinfo->logentries.end(); ++it)
{
if (!it->second.read)
unread++;
}
WCHAR * str = new WCHAR[uinfo->name.size()+10];
if (unread)
{
_stprintf_s(str, uinfo->name.size()+10, _T("%s (%d)"), uinfo->name.c_str(), unread);
itemex.state = TVIS_BOLD;
itemex.stateMask = TVIS_BOLD;
itemex.iImage = 3;
itemex.iSelectedImage = 3;
}
else
{
_stprintf_s(str, uinfo->name.size()+10, _T("%s"), uinfo->name.c_str());
itemex.state = 0;
itemex.stateMask = TVIS_BOLD;
itemex.iImage = 2;
itemex.iSelectedImage = 2;
}
itemex.pszText = str;
itemex.mask = TVIF_TEXT|TVIF_STATE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
m_refreshNeeded = true;
TreeView_SetItem(m_hTreeControl, &itemex);
}
}
}
}
}
}
m_pURLInfos->ReleaseReadOnlyData();
}
break;
case ID_MAIN_SHOWDIFFTSVN:
case ID_MAIN_SHOWDIFF:
case ID_MAIN_REMOVE:
case ID_MAIN_COPY:
case ID_POPUP_OPENWEBVIEWER:
{
::SendMessage(*this, WM_COMMAND, MAKELONG(cmd, 0), 0);
}
break;
}
}
}
}
break;
case COMMITMONITOR_INFOTEXT:
{
if (lParam)
{
SetDlgItemText(*this, IDC_INFOLABEL, (LPCTSTR)lParam);
}
}
break;
case COMMITMONITOR_LISTCTRLDBLCLICK:
{
// clear the error so it won't show up again
TVITEMEX itemex = {0};
itemex.hItem = TreeView_GetSelection(m_hTreeControl);
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
CUrlInfo * info = &pWrite->find(*(wstring*)itemex.lParam)->second;
info->error.clear();
}
m_pURLInfos->ReleaseWriteData();
::InvalidateRect(m_hTreeControl, NULL, FALSE);
}
break;
default:
return FALSE;
}
return TRUE;
}
LRESULT CMainDlg::DoCommand(int id)
{
switch (id)
{
case IDOK:
{
if (::GetFocus() != GetDlgItem(*this, IDOK))
{
// focus is not on the OK/Hide button
if ((GetFocus() == m_hListControl)&&((GetKeyState(VK_MENU)&0x8000)==0))
{
::SendMessage(*this, WM_COMMAND, MAKELONG(ID_MAIN_SHOWDIFFCHOOSE, 0), 0);
}
if ((GetKeyState(VK_MENU)&0x8000)==0)
break;
}
}
// intentional fall-through
case IDM_EXIT:
case IDCANCEL:
{
SaveWndPosition();
EndDialog(*this, IDCANCEL);
}
break;
case IDC_EXIT:
{
int res = ::MessageBox(*this, _T("Do you really want to quit the CommitMonitor?\nIf you quit, monitoring will stop.\nIf you just want to close the dialog, use the \"Hide\" button.\n\nAre you sure you want to quit the CommitMonitor?"),
_T("CommitMonitor"), MB_ICONQUESTION|MB_YESNO|MB_DEFBUTTON2);
if (res != IDYES)
break;
EndDialog(*this, IDCANCEL);
PostQuitMessage(IDOK);
}
break;
case ID_MAIN_REMOVE:
{
// which control has the focus?
HWND hFocus = ::GetFocus();
if (hFocus == m_hTreeControl)
{
HTREEITEM hItem = TreeView_GetSelection(m_hTreeControl);
if (hItem)
{
TVITEMEX itemex = {0};
itemex.hItem = hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
HTREEITEM hPrev = TVI_ROOT;
map<wstring,CUrlInfo>::iterator it = pWrite->find(*(wstring*)itemex.lParam);
if (it != pWrite->end())
{
wstring mask = it->second.name;
// ask the user if he really wants to remove the url
TCHAR question[4096] = {0};
_stprintf_s(question, 4096, _T("Do you really want to stop monitoring the project\n%s ?"), mask.c_str());
if (::MessageBox(*this, question, _T("CommitMonitor"), MB_ICONQUESTION|MB_YESNO)==IDYES)
{
// delete all fetched and stored diff files
mask += _T("*.*");
CSimpleFileFind sff(CAppUtils::GetDataDir(), mask.c_str());
while (sff.FindNextFileNoDots())
{
DeleteFile(sff.GetFilePath().c_str());
}
int unread = 0;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator logit = it->second.logentries.begin(); logit != it->second.logentries.end(); ++logit)
{
if (!logit->second.read)
unread++;
}
pWrite->erase(it);
if (unread)
::SendMessage(m_hParent, COMMITMONITOR_CHANGEDINFO, (WPARAM)false, (LPARAM)0);
::SendMessage(m_hParent, COMMITMONITOR_REMOVEDURL, 0, 0);
hPrev = TreeView_GetPrevSibling(m_hTreeControl, hItem);
m_pURLInfos->ReleaseWriteData();
m_pURLInfos->Save();
TreeView_DeleteItem(m_hTreeControl, hItem);
if (hPrev == NULL)
hPrev = TreeView_GetRoot(m_hTreeControl);
if ((hPrev)&&(hPrev != TVI_ROOT))
TreeView_SelectItem(m_hTreeControl, hPrev);
else
{
// no more tree items, deactivate the remove button and clear the list control
SetRemoveButtonState();
ListView_DeleteAllItems(m_hListControl);
SetWindowText(m_hLogMsgControl, _T(""));
}
}
else
m_pURLInfos->ReleaseWriteData();
}
else
m_pURLInfos->ReleaseWriteData();
}
}
else if (hFocus == m_hListControl)
{
RemoveSelectedListItems();
}
}
break;
case ID_POPUP_OPENWEBVIEWER:
{
TVITEMEX itemex = {0};
itemex.hItem = TreeView_GetSelection(m_hTreeControl);
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * info = &pRead->find(*(wstring*)itemex.lParam)->second;
if ((info)&&(!info->webviewer.empty()))
{
// replace "%revision" with the new HEAD revision
wstring tag(_T("%revision"));
wstring commandline = info->webviewer;
wstring::iterator it_begin = search(commandline.begin(), commandline.end(), tag.begin(), tag.end());
if (it_begin != commandline.end())
{
// find the revision
LVITEM item = {0};
int nItemCount = ListView_GetItemCount(m_hListControl);
for (int i=0; i<nItemCount; ++i)
{
item.mask = LVIF_PARAM|LVIF_STATE;
item.stateMask = LVIS_SELECTED;
item.iItem = i;
ListView_GetItem(m_hListControl, &item);
if (item.state & LVIS_SELECTED)
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
if (pLogEntry)
{
// prepare the revision
TCHAR revBuf[40] = {0};
_stprintf_s(revBuf, 40, _T("%ld"), pLogEntry->revision);
wstring srev = revBuf;
wstring::iterator it_end= it_begin + tag.size();
commandline.replace(it_begin, it_end, srev);
break;
}
}
}
}
// replace "%url" with the repository url
tag = _T("%url");
it_begin = search(commandline.begin(), commandline.end(), tag.begin(), tag.end());
if (it_begin != commandline.end())
{
wstring::iterator it_end= it_begin + tag.size();
commandline.replace(it_begin, it_end, info->url);
}
// replace "%project" with the project name
tag = _T("%project");
it_begin = search(commandline.begin(), commandline.end(), tag.begin(), tag.end());
if (it_begin != commandline.end())
{
wstring::iterator it_end= it_begin + tag.size();
commandline.replace(it_begin, it_end, info->name);
}
if (!commandline.empty())
{
ShellExecute(*this, _T("open"), commandline.c_str(), NULL, NULL, SW_SHOWNORMAL);
}
}
}
m_pURLInfos->ReleaseReadOnlyData();
}
break;
case ID_POPUP_ADDPROJECTWITHTEMPLATE:
case ID_MAIN_EDIT:
{
CURLDlg dlg;
HTREEITEM hItem = TreeView_GetSelection(m_hTreeControl);
if (hItem)
{
TVITEMEX itemex = {0};
itemex.hItem = hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
dlg.SetInfo(&pRead->find(*(wstring*)itemex.lParam)->second);
wstring origurl = dlg.GetInfo()->url;
if (id == ID_POPUP_ADDPROJECTWITHTEMPLATE)
dlg.ClearForTemplate();
m_pURLInfos->ReleaseReadOnlyData();
if (dlg.DoModal(hResource, IDD_URLCONFIG, *this) == IDOK)
{
CUrlInfo * inf = dlg.GetInfo();
if ((inf)&&inf->name.size())
{
inf->errNr = 0;
inf->error.clear();
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
if ((inf) && (inf->url.size()) && ((origurl.compare(inf->url)) || (id == ID_MAIN_EDIT)))
{
if (id == ID_MAIN_EDIT)
pWrite->erase(*(wstring*)itemex.lParam);
(*pWrite)[inf->url] = *inf;
}
m_pURLInfos->Save();
m_pURLInfos->ReleaseWriteData();
RefreshURLTree(false);
}
}
}
else
m_pURLInfos->ReleaseReadOnlyData();
}
}
break;
case ID_MAIN_CHECKREPOSITORIESNOW:
SendMessage(m_hParent, COMMITMONITOR_GETALL, 0, 0);
break;
case ID_MAIN_ADDPROJECT:
{
CURLDlg dlg;
dlg.DoModal(hResource, IDD_URLCONFIG, *this);
CUrlInfo * inf = dlg.GetInfo();
if ((inf)&&inf->url.size())
{
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
if ((inf)&&inf->url.size())
{
(*pWrite)[inf->url] = *inf;
}
m_pURLInfos->ReleaseWriteData();
m_pURLInfos->Save();
}
RefreshURLTree(false);
}
break;
case ID_MAIN_SHOWDIFF:
{
ShowDiff(false);
}
break;
case ID_MAIN_SHOWDIFFTSVN:
{
ShowDiff(true);
}
break;
case ID_MAIN_SHOWDIFFCHOOSE:
{
wstring tsvninstalled = CAppUtils::GetTSVNPath();
wstring sVer = CAppUtils::GetVersionStringFromExe(tsvninstalled.c_str());
bool bUseTSVN = !(tsvninstalled.empty()) && (_tstoi(sVer.substr(3, 4).c_str()) > 4);
bUseTSVN = bUseTSVN && !!CRegStdDWORD(_T("Software\\CommitMonitor\\UseTSVN"), TRUE);
ShowDiff(bUseTSVN);
}
break;
case ID_MISC_OPTIONS:
{
COptionsDlg dlg(*this);
dlg.SetHiddenWnd(m_hParent);
dlg.SetUrlInfos(m_pURLInfos);
dlg.DoModal(hResource, IDD_OPTIONS, *this);
}
break;
case ID_MISC_ABOUT:
{
::KillTimer(*this, TIMER_REFRESH);
CAboutDlg dlg(*this);
dlg.SetHiddenWnd(m_hParent);
dlg.DoModal(hResource, IDD_ABOUTBOX, *this);
::SetTimer(*this, TIMER_REFRESH, 1000, NULL);
}
break;
case ID_POPUP_MARKALLASREAD:
{
CURLDlg dlg;
HTREEITEM hItem = TreeView_GetSelection(m_hTreeControl);
if (hItem)
{
MarkAllAsRead(hItem, true);
}
}
break;
case ID_MAIN_COPY:
{
if (GetFocus() == m_hLogMsgControl)
{
::SendMessage(m_hLogMsgControl, WM_COPY, 0, 0);
break;
}
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
if (itemex.lParam != 0)
{
wstring sClipboardData;
TCHAR tempBuf[1024];
LVITEM item = {0};
int nItemCount = ListView_GetItemCount(m_hListControl);
for (int i=0; i<nItemCount; ++i)
{
item.mask = LVIF_PARAM|LVIF_STATE;
item.stateMask = LVIS_SELECTED;
item.iItem = i;
ListView_GetItem(m_hListControl, &item);
if (item.state & LVIS_SELECTED)
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
if (pLogEntry)
{
// get the info to put on the clipboard
_stprintf_s(tempBuf, 1024, _T("Revision: %ld\nAuthor: %s\nDate: %s\nMessage:\n"),
pLogEntry->revision,
pLogEntry->author.c_str(),
CAppUtils::ConvertDate(pLogEntry->date).c_str());
sClipboardData += tempBuf;
sClipboardData += pLogEntry->message;
sClipboardData += _T("\n-------------------------------\n");
// now add all changed paths, one path per line
for (map<std::wstring, SVNLogChangedPaths>::const_iterator it = pLogEntry->m_changedPaths.begin(); it != pLogEntry->m_changedPaths.end(); ++it)
{
// action
sClipboardData += it->second.action;
sClipboardData += _T(" : ");
sClipboardData += it->first;
sClipboardData += _T(" ");
if (!it->second.copyfrom_path.empty())
{
sClipboardData += _T("(copied from: ");
sClipboardData += it->second.copyfrom_path;
sClipboardData += _T(", revision ");
_stprintf_s(tempBuf, 1024, _T("%ld)\n"), it->second.copyfrom_revision);
sClipboardData += wstring(tempBuf);
}
else
sClipboardData += _T("\n\n");
}
}
}
}
CAppUtils::WriteAsciiStringToClipboard(sClipboardData, *this);
}
}
break;
case ID_POPUP_REPOBROWSER:
{
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
wstring url = *(wstring*)itemex.lParam;
wstring cmd;
wstring tsvninstalled = CAppUtils::GetTSVNPath();
if (!tsvninstalled.empty())
{
// yes, we have TSVN installed
cmd = wstring(tsvninstalled);
cmd += _T(" /command:repobrowser /path:\"");
cmd += url;
cmd += _T("\"");
CAppUtils::LaunchApplication(cmd);
}
}
break;
case ID_POPUP_SHOWLOG:
{
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
wstring url = *(wstring*)itemex.lParam;
wstring cmd;
wstring tsvninstalled = CAppUtils::GetTSVNPath();
if (!tsvninstalled.empty())
{
// yes, we have TSVN installed
cmd = wstring(tsvninstalled);
cmd += _T(" /command:log /path:\"");
cmd += url;
cmd += _T("\"");
CAppUtils::LaunchApplication(cmd);
}
}
break;
default:
return 0;
}
return 1;
}
void CMainDlg::SetRemoveButtonState()
{
HWND hFocus = ::GetFocus();
if (hFocus == m_hListControl)
{
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_REMOVE, MAKELONG(ListView_GetSelectedCount(m_hListControl) > 0, 0));
}
else
{
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_REMOVE, MAKELONG(TreeView_GetSelection(m_hTreeControl)!=0, 0));
}
}
bool CMainDlg::ShowDiff(bool bUseTSVN)
{
TCHAR buf[4096];
// find the revision we have to show the diff for
int selCount = ListView_GetSelectedCount(m_hListControl);
if (selCount <= 0)
return FALSE; //nothing selected, nothing to show
// Get temp directory and current directory
WCHAR cTempPath[32767];
GetEnvironmentVariable(_T("TEMP"), cTempPath, 32767);
wstring origTempPath = wstring(cTempPath);
GetCurrentDirectory(32767, cTempPath);
wstring origCurDir = wstring(cTempPath);
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
const CUrlInfo * pUrlInfo = &pRead->find(*(wstring*)itemex.lParam)->second;
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
LVITEM item = {0};
int nItemCount = ListView_GetItemCount(m_hListControl);
for (int i=0; i<nItemCount; ++i)
{
item.mask = LVIF_PARAM|LVIF_STATE;
item.stateMask = LVIS_SELECTED;
item.iItem = i;
ListView_GetItem(m_hListControl, &item);
if (item.state & LVIS_SELECTED)
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
// Switch how the diff is done in SVN / Accurev
switch(pUrlInfo->sccs) {
default:
case CUrlInfo::SCCS_SVN:
{
// find the diff name
const CUrlInfo * pInfo = &pRead->find(*(wstring*)itemex.lParam)->second;
// in case the project name has 'path' chars in it, we have to remove those first
_stprintf_s(buf, 4096, _T("%s_%ld.diff"), CAppUtils::ConvertName(pInfo->name).c_str(), pLogEntry->revision);
wstring diffFileName = CAppUtils::GetDataDir();
diffFileName += _T("\\");
diffFileName += wstring(buf);
// construct a title for the diff viewer
_stprintf_s(buf, 4096, _T("%s, revision %ld"), pInfo->name.c_str(), pLogEntry->revision);
wstring title = wstring(buf);
// start the diff viewer
wstring cmd;
wstring tsvninstalled = CAppUtils::GetTSVNPath();
wstring sVer = CAppUtils::GetVersionStringFromExe(tsvninstalled.c_str());
if ((bUseTSVN)&&(!tsvninstalled.empty())&&(_tstoi(sVer.substr(3, 4).c_str()) > 4))
{
// yes, we have TSVN installed
// call TortoiseProc to do the diff for us
cmd = wstring(tsvninstalled);
cmd += _T(" /command:diff /path:\"");
cmd += pInfo->url;
cmd += _T("\" /startrev:");
TCHAR numBuf[100] = {0};
_stprintf_s(numBuf, 100, _T("%ld"), pLogEntry->revision-1);
cmd += numBuf;
cmd += _T(" /endrev:");
_stprintf_s(numBuf, 100, _T("%ld"), pLogEntry->revision);
cmd += numBuf;
CAppUtils::LaunchApplication(cmd);
}
else
{
TCHAR apppath[4096];
GetModuleFileName(NULL, apppath, 4096);
CRegStdString diffViewer = CRegStdString(_T("Software\\CommitMonitor\\DiffViewer"));
if (wstring(diffViewer).empty())
{
cmd = apppath;
cmd += _T(" /patchfile:\"");
}
else
{
cmd = (wstring)diffViewer;
cmd += _T(" \"");
}
cmd += diffFileName;
cmd += _T("\"");
if (wstring(diffViewer).empty())
{
cmd += _T(" /title:\"");
cmd += title;
cmd += _T("\"");
}
// Check if the diff file exists. If it doesn't, we have to fetch
// the diff first
if (!PathFileExists(diffFileName.c_str()))
{
// fetch the diff
SVN svn;
svn.SetAuthInfo(pInfo->username, pInfo->password);
CProgressDlg progDlg;
svn.SetAndClearProgressInfo(&progDlg);
progDlg.SetTitle(_T("Fetching Diff"));
TCHAR dispbuf[MAX_PATH] = {0};
_stprintf_s(dispbuf, MAX_PATH, _T("fetching diff of revision %ld"), pLogEntry->revision);
progDlg.SetLine(1, dispbuf);
progDlg.SetShowProgressBar(false);
progDlg.ShowModeless(*this);
CRegStdString diffParams = CRegStdString(_T("Software\\CommitMonitor\\DiffParameters"));
if (!svn.Diff(pInfo->url, pLogEntry->revision, pLogEntry->revision-1, pLogEntry->revision, true, true, false, diffParams, false, diffFileName, wstring()))
{
progDlg.Stop();
if (svn.Err->apr_err != SVN_ERR_CANCELLED)
::MessageBox(*this, svn.GetLastErrorMsg().c_str(), _T("CommitMonitor"), MB_ICONERROR);
DeleteFile(diffFileName.c_str());
}
else
{
TRACE(_T("Diff fetched for %s, revision %ld\n"), pInfo->url.c_str(), pLogEntry->revision);
progDlg.Stop();
}
}
if (PathFileExists(diffFileName.c_str()))
CAppUtils::LaunchApplication(cmd);
}
}
break;
case CUrlInfo::SCCS_ACCUREV:
{
/* Accurev 'diff' cannot be used as it mutex locks itself to only allow diffing of one
* file at a time... how typical. Therefore we 'pop' (get copies) of the correct versions
* of each file and then diff the directories :)
* TODO: Somehow hold onto and delete the temporary dirs when commit monitor is closed */
CRegStdString accurevExe = CRegStdString(_T("Software\\CommitMonitor\\AccurevExe"));
wchar_t transactionNo[64];
_itow(pLogEntry->revision, transactionNo, 10);
wstring uuid;
CAppUtils::CreateUUIDString(uuid);
wstring newTempPath = wstring(origTempPath);
newTempPath.append(_T("\\"));
newTempPath.append(uuid);
wstring sLatestRev(transactionNo);
wstring sBasisRev = _T("BASIS");
wstring latestDir(newTempPath + _T("\\") + sLatestRev);
wstring basisDir(newTempPath + _T("\\") + sBasisRev);
CreateDirectory(newTempPath.c_str(), NULL);
CreateDirectory(latestDir.c_str(), NULL);
CreateDirectory(basisDir.c_str(), NULL);
// For each file that should be diffed
for (map<std::wstring,SVNLogChangedPaths>::const_iterator it = pLogEntry->m_changedPaths.begin(); it != pLogEntry->m_changedPaths.end(); ++it)
{
// Parse the file and file revision from the stored URL
wstring rawPath = it->first;
int lastBracket = rawPath.rfind(L" (");
rawPath.erase(lastBracket, wstring::npos);
int lastForwardSlash = rawPath.rfind(L"/");
wstring sLatestAccuRevision(rawPath);
sLatestAccuRevision.erase(0, lastForwardSlash+1);
int iAccuRevision = _wtoi(sLatestAccuRevision.c_str());
wchar_t basisRevisionNo[64];
_itow(iAccuRevision-1, basisRevisionNo, 10);
wstring sBasisAccuRevision(basisRevisionNo);
wstring finalPath(rawPath);
int lastSpace = rawPath.rfind(L" ");
finalPath.erase(lastSpace, wstring::npos);
// Can't diff unless there is a version to diff against :)
if (iAccuRevision >= 1) {
// Check out the latest file
// Build the accurev command line
for (int i=0; i<2; i++) {
wstring accurevPopCmd;
wstring rev;
wstring dir;
switch (i) {
default:
case 0:
rev = sLatestAccuRevision;
dir = latestDir;
break;
case 1:
rev = sBasisAccuRevision;
dir = basisDir;
break;
}
/* If this is the basis version, and there is none, since the file was added, then break
* so we only check out the new version. This will then be shown in the directory compare :) */
if ((i == 1) && (iAccuRevision == 1)) break;
accurevPopCmd.append(_T("\""));
accurevPopCmd.append(wstring(accurevExe));
accurevPopCmd.append(_T("\" pop -O -R -v "));
accurevPopCmd.append(pUrlInfo->url);
accurevPopCmd.append(_T("/"));
accurevPopCmd.append(rev);
accurevPopCmd.append(_T(" -L \""));
accurevPopCmd.append(dir);
accurevPopCmd.append(_T("\" \""));
accurevPopCmd.append(finalPath);
accurevPopCmd.append(_T("\""));
// Run accurev to perform the pop command
CAppUtils::LaunchApplication(accurevPopCmd, true, true, true);
}
}
}
CRegStdString diffCmd = CRegStdString(_T("Software\\CommitMonitor\\AccurevDiffCmd"));
wstring finalDiffCmd;
// Build the final diff command
finalDiffCmd.append(wstring(diffCmd));
// Find and replace "%OLD"
int pos = finalDiffCmd.find(_T("%OLD"));
finalDiffCmd.replace(pos, 4, sBasisRev, 0, sBasisRev.size());
// Find and replace "%NEW"
pos = finalDiffCmd.find(_T("%NEW"));
finalDiffCmd.replace(pos, 4, sLatestRev, 0, sLatestRev.size());
// Find and replace "%1"
pos = finalDiffCmd.find(_T("%1"));
finalDiffCmd.replace(pos, 2, basisDir, 0, basisDir.size());
// Find and replace "%2"
pos = finalDiffCmd.find(_T("%2"));
finalDiffCmd.replace(pos, 2, latestDir, 0, latestDir.size());
// Run accurev to perform the diff command
CAppUtils::LaunchApplication(finalDiffCmd, true, false, false);
}
break;
}
}
}
}
m_pURLInfos->ReleaseReadOnlyData();
return TRUE;
}
/******************************************************************************/
/* tree handling */
/******************************************************************************/
void CMainDlg::RefreshURLTree(bool bSelectUnread)
{
// the m_URLInfos member must be up-to-date here
m_bBlockListCtrlUI = true;
// first clear the controls (the data)
ListView_DeleteAllItems(m_hListControl);
TreeView_SelectItem(m_hTreeControl, NULL);
TreeView_DeleteAllItems(m_hTreeControl);
SetWindowText(m_hLogMsgControl, _T(""));
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_SHOWDIFFTSVN, MAKELONG(false, 0));
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_EDIT, MAKELONG(false, 0));
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_REMOVE, MAKELONG(false, 0));
HTREEITEM tvToSel = 0;
// now add a tree item for every entry in m_URLInfos
const map<wstring, CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
for (map<wstring, CUrlInfo>::const_iterator it = pRead->begin(); it != pRead->end(); ++it)
{
TVINSERTSTRUCT tv = {0};
tv.hParent = FindParentTreeNode(it->first);
tv.hInsertAfter = TVI_SORT;
tv.itemex.mask = TVIF_TEXT|TVIF_PARAM|TVIF_STATE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
WCHAR * str = new WCHAR[it->second.name.size()+10];
// find out if there are some unread entries
int unread = 0;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator logit = it->second.logentries.begin(); logit != it->second.logentries.end(); ++logit)
{
if (!logit->second.read)
unread++;
}
if (unread)
{
_stprintf_s(str, it->second.name.size()+10, _T("%s (%d)"), it->second.name.c_str(), unread);
tv.itemex.state = TVIS_BOLD;
tv.itemex.stateMask = TVIS_BOLD;
}
else
{
_tcscpy_s(str, it->second.name.size()+1, it->second.name.c_str());
tv.itemex.state = 0;
tv.itemex.stateMask = 0;
}
tv.itemex.pszText = str;
tv.itemex.lParam = (LPARAM)&it->first;
if (it->second.parentpath)
{
tv.itemex.iImage = 0;
tv.itemex.iSelectedImage = 1;
}
else
{
if (!it->second.error.empty())
{
tv.itemex.iImage = 4;
tv.itemex.iSelectedImage = 4;
}
else if (unread)
{
tv.itemex.iImage = 3;
tv.itemex.iSelectedImage = 3;
}
else
{
tv.itemex.iImage = 2;
tv.itemex.iSelectedImage = 2;
}
}
HTREEITEM hItem = TreeView_InsertItem(m_hTreeControl, &tv);
if (m_lastSelectedProject.compare(it->second.name) == 0)
tvToSel = hItem;
if ((unread)&&(tvToSel == 0))
tvToSel = hItem;
TreeView_Expand(m_hTreeControl, tv.hParent, TVE_EXPAND);
delete [] str;
}
m_pURLInfos->ReleaseReadOnlyData();
m_bBlockListCtrlUI = false;
if ((tvToSel)&&(bSelectUnread))
{
TreeView_SelectItem(m_hTreeControl, tvToSel);
}
else if (tvToSel == NULL)
{
tvToSel = TreeView_GetRoot(m_hTreeControl);
if (TreeView_GetChild(m_hTreeControl, tvToSel))
tvToSel = TreeView_GetChild(m_hTreeControl, tvToSel);
TreeView_SelectItem(m_hTreeControl, tvToSel);
}
::InvalidateRect(m_hListControl, NULL, true);
}
LRESULT CMainDlg::OnCustomDrawTreeItem(LPNMTVCUSTOMDRAW lpNMCustomDraw)
{
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
LRESULT result = CDRF_DODEFAULT;
switch (lpNMCustomDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
result = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
if (!m_bBlockListCtrlUI)
{
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
const CUrlInfo * info = &pRead->find(*(wstring*)lpNMCustomDraw->nmcd.lItemlParam)->second;
COLORREF crText = lpNMCustomDraw->clrText;
if ((info)&&(!info->error.empty() && !info->parentpath))
{
crText = GetSysColor(COLOR_GRAYTEXT);
}
m_pURLInfos->ReleaseReadOnlyData();
// Store the color back in the NMLVCUSTOMDRAW struct.
lpNMCustomDraw->clrText = crText;
}
}
break;
}
return result;
}
HTREEITEM CMainDlg::FindParentTreeNode(const wstring& url)
{
size_t pos = url.find_last_of('/');
wstring parenturl = url.substr(0, pos);
do
{
const map<wstring, CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(parenturl) != pRead->end())
{
m_pURLInfos->ReleaseReadOnlyData();
// we found a parent URL, but now we have to find it in the
// tree view
return FindTreeNode(parenturl);
}
m_pURLInfos->ReleaseReadOnlyData();
pos = parenturl.find_last_of('/');
parenturl = parenturl.substr(0, pos);
if (pos == string::npos)
parenturl.clear();
} while (!parenturl.empty());
return TVI_ROOT;
}
HTREEITEM CMainDlg::FindTreeNode(const wstring& url, HTREEITEM hItem)
{
if (hItem == TVI_ROOT)
hItem = TreeView_GetRoot(m_hTreeControl);
TVITEM item;
item.mask = TVIF_PARAM;
while (hItem)
{
item.hItem = hItem;
TreeView_GetItem(m_hTreeControl, &item);
if (url.compare(*(wstring*)item.lParam) == 0)
return hItem;
HTREEITEM hChild = TreeView_GetChild(m_hTreeControl, hItem);
if (hChild)
{
item.hItem = hChild;
TreeView_GetItem(m_hTreeControl, &item);
hChild = FindTreeNode(url, hChild);
if (hChild != TVI_ROOT)
return hChild;
}
hItem = TreeView_GetNextSibling(m_hTreeControl, hItem);
};
return TVI_ROOT;
}
bool CMainDlg::SelectNextWithUnread(HTREEITEM hItem)
{
if (hItem == TVI_ROOT)
hItem = TreeView_GetRoot(m_hTreeControl);
TVITEM item;
item.mask = TVIF_STATE;
item.stateMask = TVIS_BOLD;
while (hItem)
{
item.hItem = hItem;
TreeView_GetItem(m_hTreeControl, &item);
if (item.state & TVIS_BOLD)
{
TreeView_SelectItem(m_hTreeControl, hItem);
TreeItemSelected(m_hTreeControl, hItem);
ListView_SetSelectionMark(m_hListControl, 0);
ListView_SetItemState(m_hListControl, 0, LVIS_SELECTED, LVIS_SELECTED);
::SetFocus(m_hListControl);
return true;
}
HTREEITEM hChild = TreeView_GetChild(m_hTreeControl, hItem);
if (hChild)
{
item.hItem = hChild;
TreeView_GetItem(m_hTreeControl, &item);
if (SelectNextWithUnread(hChild))
return true;
}
hItem = TreeView_GetNextSibling(m_hTreeControl, hItem);
};
return false;
}
void CMainDlg::OnSelectTreeItem(LPNMTREEVIEW lpNMTreeView)
{
HTREEITEM hSelectedItem = lpNMTreeView->itemNew.hItem;
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_EDIT,
MAKELONG(!!(lpNMTreeView->itemNew.state & TVIS_SELECTED), 0));
SetRemoveButtonState();
if (lpNMTreeView->itemNew.state & TVIS_SELECTED)
{
TreeItemSelected(lpNMTreeView->hdr.hwndFrom, hSelectedItem);
}
else
{
ListView_DeleteAllItems(m_hListControl);
SetWindowText(m_hLogMsgControl, _T(""));
SetDlgItemText(*this, IDC_INFOLABEL, _T(""));
}
SetWindowText(m_hLogMsgControl, _T(""));
}
void CMainDlg::TreeItemSelected(HWND hTreeControl, HTREEITEM hSelectedItem)
{
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * info = &pRead->find(*(wstring*)itemex.lParam)->second;
m_lastSelectedProject = info->name;
if ((!info->error.empty())&&(!info->parentpath))
{
// there was an error when we last tried to access this url.
// Show a message box with the error.
int len = info->error.length()+info->url.length()+1024;
TCHAR * pBuf = new TCHAR[len];
_stprintf_s(pBuf, len, _T("An error occurred the last time CommitMonitor\ntried to access the url: %s\n\n%s\n\nDoubleclick here to clear the error message."), info->url.c_str(), info->error.c_str());
m_ListCtrl.SetInfoText(pBuf);
delete [] pBuf;
}
else
// remove the info text if there's no error
m_ListCtrl.SetInfoText(_T(""));
// show the last update time on the info label
TCHAR updateTime[1000] = {0};
struct tm upTime;
if (_localtime64_s(&upTime, &info->lastchecked) == 0)
{
_tcsftime(updateTime, 1000, _T(" last checked: %X"), &upTime);
SetDlgItemText(*this, IDC_INFOLABEL, updateTime);
}
m_bBlockListCtrlUI = true;
int selMark = ListView_GetSelectionMark(m_hListControl);
DWORD exStyle = LVS_EX_FULLROWSELECT | LVS_EX_DOUBLEBUFFER;
ListView_DeleteAllItems(m_hListControl);
int c = Header_GetItemCount(ListView_GetHeader(m_hListControl))-1;
while (c>=0)
ListView_DeleteColumn(m_hListControl, c--);
ListView_SetExtendedListViewStyle(m_hListControl, exStyle);
LVCOLUMN lvc = {0};
lvc.mask = LVCF_TEXT;
lvc.fmt = LVCFMT_LEFT;
lvc.cx = -1;
lvc.pszText = _T("revision");
ListView_InsertColumn(m_hListControl, 0, &lvc);
lvc.pszText = _T("date");
ListView_InsertColumn(m_hListControl, 1, &lvc);
lvc.pszText = _T("author");
ListView_InsertColumn(m_hListControl, 2, &lvc);
lvc.pszText = _T("log message");
ListView_InsertColumn(m_hListControl, 3, &lvc);
LVITEM item = {0};
TCHAR buf[1024];
int iLastUnread = -1;
int len = GetWindowTextLength(m_hFilterControl);
WCHAR * buffer = new WCHAR[len+1];
GetDlgItemText(*this, IDC_FILTERSTRING, buffer, len+1);
wstring filterstring = wstring(buffer, len);
bool bNegateFilter = false;
if (len)
bNegateFilter = filterstring[0] == '-';
if (bNegateFilter)
{
filterstring = filterstring.substr(1);
}
wstring filterstringlower = filterstring;
std::transform(filterstringlower.begin(), filterstringlower.end(), filterstringlower.begin(), std::tolower);
delete [] buffer;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator it = info->logentries.begin(); it != info->logentries.end(); ++it)
{
// only add entries that match the filter string
bool addEntry = true;
bool useFilter = filterstringlower.size() != 0;
bool bUseRegex = (filterstring.size() > 1)&&(filterstring[0] == '\\');
if (useFilter)
{
if (bUseRegex)
{
try
{
const tr1::wregex regCheck(filterstring.substr(1), tr1::regex_constants::icase | tr1::regex_constants::ECMAScript);
addEntry = tr1::regex_search(it->second.author, regCheck);
if (!addEntry)
{
addEntry = tr1::regex_search(it->second.message, regCheck);
if (!addEntry)
{
_stprintf_s(buf, 1024, _T("%ld"), it->first);
wstring s = wstring(buf);
addEntry = tr1::regex_search(s, regCheck);
}
}
}
catch (exception)
{
bUseRegex = false;
}
if (bNegateFilter)
addEntry = !addEntry;
}
if (!bUseRegex)
{
// search plain text
// note: \Q...\E doesn't seem to work with tr1 - it still
// throws an exception if the regex in between is not a valid regex :(
wstring s = it->second.author;
std::transform(s.begin(), s.end(), s.begin(), std::tolower);
addEntry = s.find(filterstringlower) != wstring::npos;
if (!addEntry)
{
s = it->second.message;
std::transform(s.begin(), s.end(), s.begin(), std::tolower);
addEntry = s.find(filterstringlower) != wstring::npos;
if (!addEntry)
{
_stprintf_s(buf, 1024, _T("%ld"), it->first);
s = buf;
addEntry = s.find(filterstringlower) != wstring::npos;
}
}
if (bNegateFilter)
addEntry = !addEntry;
}
}
if (!addEntry)
continue;
item.mask = LVIF_TEXT|LVIF_PARAM;
item.iItem = 0;
item.lParam = (LPARAM)&it->second;
_stprintf_s(buf, 1024, _T("%ld"), it->first);
item.pszText = buf;
ListView_InsertItem(m_hListControl, &item);
if (it->second.date)
_tcscpy_s(buf, 1024, CAppUtils::ConvertDate(it->second.date).c_str());
else
_tcscpy_s(buf, 1024, _T("(no date)"));
ListView_SetItemText(m_hListControl, 0, 1, buf);
if (it->second.author.size())
_tcscpy_s(buf, 1024, it->second.author.c_str());
else
_tcscpy_s(buf, 1024, _T("(no author)"));
ListView_SetItemText(m_hListControl, 0, 2, buf);
wstring msg = it->second.message;
std::remove(msg.begin(), msg.end(), '\r');
std::replace(msg.begin(), msg.end(), '\n', ' ');
std::replace(msg.begin(), msg.end(), '\t', ' ');
_tcsncpy_s(buf, 1024, msg.c_str(), 1023);
ListView_SetItemText(m_hListControl, 0, 3, buf);
if ((iLastUnread < 0)&&(!it->second.read))
{
iLastUnread = 0;
}
if (iLastUnread >= 0)
iLastUnread++;
}
ListView_SetSelectionMark(m_hListControl, selMark);
m_bBlockListCtrlUI = false;
ListView_SetColumnWidth(m_hListControl, 0, LVSCW_AUTOSIZE_USEHEADER);
ListView_SetColumnWidth(m_hListControl, 1, LVSCW_AUTOSIZE_USEHEADER);
ListView_SetColumnWidth(m_hListControl, 2, LVSCW_AUTOSIZE_USEHEADER);
ListView_SetColumnWidth(m_hListControl, 3, LVSCW_AUTOSIZE_USEHEADER);
ListView_EnsureVisible(m_hListControl, iLastUnread-1, FALSE);
::InvalidateRect(m_hListControl, NULL, false);
}
m_pURLInfos->ReleaseReadOnlyData();
}
void CMainDlg::MarkAllAsRead(HTREEITEM hItem, bool includingChildren)
{
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
bool bChanged = false;
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
CUrlInfo * info = &pWrite->find(*(wstring*)itemex.lParam)->second;
for (map<svn_revnum_t,SVNLogEntry>::iterator it = info->logentries.begin(); it != info->logentries.end(); ++it)
{
if (!it->second.read)
bChanged = true;
it->second.read = true;
}
// refresh the name of the tree item to indicate the new
// number of unread log messages
WCHAR * str = new WCHAR[info->name.size()+10];
_stprintf_s(str, info->name.size()+10, _T("%s"), info->name.c_str());
itemex.state = 0;
itemex.stateMask = TVIS_BOLD;
itemex.pszText = str;
if (info->parentpath)
{
itemex.iImage = 0;
itemex.iSelectedImage = 1;
}
else
{
itemex.iImage = 2;
itemex.iSelectedImage = 2;
}
itemex.mask = TVIF_TEXT|TVIF_STATE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_SetItem(m_hTreeControl, &itemex);
delete [] str;
}
m_pURLInfos->ReleaseWriteData();
if (includingChildren)
{
HTREEITEM hFirstChild = TreeView_GetChild(m_hTreeControl, hItem);
if (hFirstChild)
{
MarkAllAsRead(hFirstChild, includingChildren);
HTREEITEM hNextSibling = TreeView_GetNextSibling(m_hTreeControl, hFirstChild);
while (hNextSibling)
{
MarkAllAsRead(hNextSibling, includingChildren);
hNextSibling = TreeView_GetNextSibling(m_hTreeControl, hNextSibling);
}
}
}
if (bChanged)
::SendMessage(m_hParent, COMMITMONITOR_CHANGEDINFO, (WPARAM)false, (LPARAM)0);
}
void CMainDlg::CheckNow(HTREEITEM hItem)
{
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
wstring url;
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
CUrlInfo * info = &pWrite->find(*(wstring*)itemex.lParam)->second;
url = info->url;
}
m_pURLInfos->ReleaseWriteData();
SendMessage(m_hParent, COMMITMONITOR_GETALL, 0, (LPARAM)url.c_str());
}
void CMainDlg::RefreshAll(HTREEITEM hItem)
{
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
wstring url;
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
CUrlInfo * info = &pWrite->find(*(wstring*)itemex.lParam)->second;
svn_revnum_t lowestRev = 0;
map<svn_revnum_t,SVNLogEntry>::iterator it = info->logentries.begin();
if (it != info->logentries.end())
{
lowestRev = it->second.revision;
}
// set the 'last checked revision to the lowest revision so that
// all the subsequent revisions are fetched again.
info->lastcheckedrev = lowestRev > 0 ? lowestRev-1 : lowestRev;
// and make sure this repository is checked even if the timeout has
// not been reached yet on the next fetch round
info->lastchecked = 0;
url = info->url;
}
m_pURLInfos->ReleaseWriteData();
SendMessage(m_hParent, COMMITMONITOR_GETALL, 0, (LPARAM)url.c_str());
}
/******************************************************************************/
/* list view handling */
/******************************************************************************/
void CMainDlg::OnSelectListItem(LPNMLISTVIEW lpNMListView)
{
if ((m_bBlockListCtrlUI)||(m_ListCtrl.InfoTextShown()))
return;
if ((lpNMListView->uOldState ^ lpNMListView->uNewState) & LVIS_SELECTED)
{
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
LVITEM item = {0};
item.mask = LVIF_PARAM;
item.iItem = lpNMListView->iItem;
ListView_GetItem(m_hListControl, &item);
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
if (pLogEntry)
{
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
if (itemex.lParam == 0)
{
m_pURLInfos->ReleaseReadOnlyData();
return;
}
// set the entry as read
if ((!pLogEntry->read)&&(lpNMListView->uNewState & LVIS_SELECTED))
{
pLogEntry->read = true;
// refresh the name of the tree item to indicate the new
// number of unread log messages
// e.g. instead of 'TortoiseSVN (3)', show now 'TortoiseSVN (2)'
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * uinfo = &pRead->find(*(wstring*)itemex.lParam)->second;
// count the number of unread messages
int unread = 0;
for (map<svn_revnum_t,SVNLogEntry>::const_iterator it = uinfo->logentries.begin(); it != uinfo->logentries.end(); ++it)
{
if (!it->second.read)
unread++;
}
WCHAR * str = new WCHAR[uinfo->name.size()+10];
if (unread)
{
_stprintf_s(str, uinfo->name.size()+10, _T("%s (%d)"), uinfo->name.c_str(), unread);
itemex.state = TVIS_BOLD;
itemex.stateMask = TVIS_BOLD;
itemex.iImage = 3;
itemex.iSelectedImage = 3;
}
else
{
_stprintf_s(str, uinfo->name.size()+10, _T("%s"), uinfo->name.c_str());
itemex.state = 0;
itemex.stateMask = TVIS_BOLD;
itemex.iImage = 2;
itemex.iSelectedImage = 2;
}
itemex.pszText = str;
itemex.mask = TVIF_TEXT|TVIF_STATE|TVIF_IMAGE|TVIF_SELECTEDIMAGE;
TreeView_SetItem(m_hTreeControl, &itemex);
}
// the icon in the system tray needs to be changed back
// to 'normal'
::SendMessage(m_hParent, COMMITMONITOR_CHANGEDINFO, (WPARAM)false, (LPARAM)0);
}
TCHAR buf[1024];
wstring msg;
if (ListView_GetSelectedCount(m_hListControl) > 1)
{
msg = _T("multiple log entries selected. Info for the last selected one:\n-------------------------------\n\n");
}
msg += pLogEntry->message.c_str();
msg += _T("\n\n-------------------------------\n");
// now add all changed paths, one path per line
for (map<std::wstring, SVNLogChangedPaths>::const_iterator it = pLogEntry->m_changedPaths.begin(); it != pLogEntry->m_changedPaths.end(); ++it)
{
// action
msg += it->second.action;
msg += _T(" : ");
msg += it->first;
msg += _T(" ");
if (!it->second.copyfrom_path.empty())
{
msg += _T("(copied from: ");
msg += it->second.copyfrom_path;
msg += _T(", revision ");
_stprintf_s(buf, 1024, _T("%ld)\n"), it->second.copyfrom_revision);
msg += wstring(buf);
}
else
msg += _T("\n");
}
CAppUtils::SearchReplace(msg, _T("\n"), _T("\r\n"));
SetWindowText(m_hLogMsgControl, msg.c_str());
// find the diff name
_stprintf_s(buf, 1024, _T("%s_%ld.diff"), pRead->find(*(wstring*)itemex.lParam)->second.name.c_str(), pLogEntry->revision);
wstring diffFileName = CAppUtils::GetDataDir();
diffFileName += _T("\\");
diffFileName += wstring(buf);
SendMessage(m_hwndToolbar, TB_ENABLEBUTTON, ID_MAIN_SHOWDIFFCHOOSE, MAKELONG(true, 0));
}
m_pURLInfos->ReleaseReadOnlyData();
}
}
void CMainDlg::OnDblClickListItem(LPNMITEMACTIVATE /*lpnmitem*/)
{
bool bUseWebViewer = false;
if (DWORD(CRegStdDWORD(_T("Software\\CommitMonitor\\DblClickWebViewer"), FALSE)))
{
// enable the "Open WebViewer" entry if there is one specified
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = TreeView_GetSelection(m_hTreeControl);
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
const map<wstring,CUrlInfo> * pRead = m_pURLInfos->GetReadOnlyData();
if (pRead->find(*(wstring*)itemex.lParam) != pRead->end())
{
const CUrlInfo * info = &pRead->find(*(wstring*)itemex.lParam)->second;
if ((info)&&(!info->webviewer.empty()))
{
bUseWebViewer = true;
}
}
m_pURLInfos->ReleaseReadOnlyData();
}
if (bUseWebViewer)
::SendMessage(*this, WM_COMMAND, MAKELONG(ID_POPUP_OPENWEBVIEWER, 0), 0);
else
::SendMessage(*this, WM_COMMAND, MAKELONG(ID_MAIN_SHOWDIFFCHOOSE, 0), 0);
}
LRESULT CMainDlg::OnCustomDrawListItem(LPNMLVCUSTOMDRAW lpNMCustomDraw)
{
// First thing - check the draw stage. If it's the control's prepaint
// stage, then tell Windows we want messages for every item.
LRESULT result = CDRF_DODEFAULT;
if (m_bBlockListCtrlUI)
return result;
switch (lpNMCustomDraw->nmcd.dwDrawStage)
{
case CDDS_PREPAINT:
result = CDRF_NOTIFYITEMDRAW;
break;
case CDDS_ITEMPREPAINT:
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)lpNMCustomDraw->nmcd.lItemlParam;
if (!pLogEntry->read)
{
SelectObject(lpNMCustomDraw->nmcd.hdc, m_boldFont);
// We changed the font, so we're returning CDRF_NEWFONT. This
// tells the control to recalculate the extent of the text.
result = CDRF_NEWFONT;
}
}
break;
}
return result;
}
void CMainDlg::OnKeyDownListItem(LPNMLVKEYDOWN pnkd)
{
switch (pnkd->wVKey)
{
case VK_DELETE:
RemoveSelectedListItems();
break;
case 'A':
if (GetKeyState(VK_CONTROL)&0x8000)
{
// select all
int nCount = ListView_GetItemCount(m_hListControl);
if (nCount > 1)
{
m_bBlockListCtrlUI = true;
for (int i=0; i<(nCount-1); ++i)
{
ListView_SetItemState(m_hListControl, i, LVIS_SELECTED, LVIS_SELECTED);
}
m_bBlockListCtrlUI = false;
ListView_SetItemState(m_hListControl, nCount-1, LVIS_SELECTED, LVIS_SELECTED);
// clear the text of the selected log message: there are more than
// one selected now
SetWindowText(m_hLogMsgControl, _T(""));
}
}
break;
case 'N': // next unread
{
int selMark = ListView_GetSelectionMark(m_hListControl);
if (selMark >= 0)
{
// find the next unread message
LVITEM item = {0};
int i = selMark + 1;
int nCount = ListView_GetItemCount(m_hListControl);
do
{
item.mask = LVIF_PARAM;
item.iItem = i;
if (ListView_GetItem(m_hListControl, &item))
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
if ((pLogEntry)&&(!pLogEntry->read))
{
// we have the next unread
ListView_SetSelectionMark(m_hListControl, i);
ListView_SetItemState(m_hListControl, selMark, 0, LVIS_SELECTED);
ListView_SetItemState(m_hListControl, i, LVIS_SELECTED, LVIS_SELECTED);
break;
}
}
++i;
} while (i < nCount);
if (i == nCount)
{
// no unread item found anymore.
if (!SelectNextWithUnread())
{
// also no unread items in other projects
int selMark = ListView_GetSelectionMark(m_hListControl);
if (selMark < ListView_GetItemCount(m_hListControl))
{
ListView_SetItemState(m_hListControl, selMark, 0, LVIS_SELECTED);
ListView_SetSelectionMark(m_hListControl, selMark+1);
ListView_SetItemState(m_hListControl, selMark+1, LVIS_SELECTED, LVIS_SELECTED);
ListView_EnsureVisible(m_hListControl, selMark+1, false);
}
}
}
}
}
break;
case 'B': // back one message
{
int selMark = ListView_GetSelectionMark(m_hListControl);
if (selMark > 0)
{
ListView_SetItemState(m_hListControl, selMark, 0, LVIS_SELECTED);
ListView_SetSelectionMark(m_hListControl, selMark-1);
ListView_SetItemState(m_hListControl, selMark-1, LVIS_SELECTED, LVIS_SELECTED);
ListView_EnsureVisible(m_hListControl, selMark-1, false);
}
}
break;
}
}
void CMainDlg::RemoveSelectedListItems()
{
int selCount = ListView_GetSelectedCount(m_hListControl);
if (selCount <= 0)
return; //nothing selected, nothing to remove
int nFirstDeleted = -1;
HTREEITEM hSelectedItem = TreeView_GetSelection(m_hTreeControl);
// get the url this entry refers to
TVITEMEX itemex = {0};
itemex.hItem = hSelectedItem;
itemex.mask = TVIF_PARAM;
TreeView_GetItem(m_hTreeControl, &itemex);
map<wstring,CUrlInfo> * pWrite = m_pURLInfos->GetWriteData();
if (pWrite->find(*(wstring*)itemex.lParam) != pWrite->end())
{
LVITEM item = {0};
int i = 0;
TCHAR buf[4096];
m_bBlockListCtrlUI = true;
while (i<ListView_GetItemCount(m_hListControl))
{
item.mask = LVIF_PARAM|LVIF_STATE;
item.stateMask = LVIS_SELECTED;
item.iItem = i;
item.lParam = 0;
ListView_GetItem(m_hListControl, &item);
if (item.state & LVIS_SELECTED)
{
SVNLogEntry * pLogEntry = (SVNLogEntry*)item.lParam;
// find the diff name
_stprintf_s(buf, 4096, _T("%s_%ld.diff"), pWrite->find(*(wstring*)itemex.lParam)->second.name.c_str(), pLogEntry->revision);
wstring diffFileName = CAppUtils::GetDataDir();
diffFileName += _T("\\");
diffFileName += wstring(buf);
DeleteFile(diffFileName.c_str());
pWrite->find((*(wstring*)itemex.lParam))->second.logentries.erase(pLogEntry->revision);
ListView_DeleteItem(m_hListControl, i);
if (nFirstDeleted < 0)
nFirstDeleted = i;
}
else
++i;
}
m_bBlockListCtrlUI = false;
}
m_pURLInfos->ReleaseWriteData();
if (nFirstDeleted >= 0)
{
if (ListView_GetItemCount(m_hListControl) > nFirstDeleted)
{
ListView_SetItemState(m_hListControl, nFirstDeleted, LVIS_SELECTED, LVIS_SELECTED);
}
else
{
ListView_SetItemState(m_hListControl, ListView_GetItemCount(m_hListControl)-1, LVIS_SELECTED, LVIS_SELECTED);
}
}
SetRemoveButtonState();
}
/******************************************************************************/
/* tree, list view and dialog resizing */
/******************************************************************************/
void CMainDlg::DoResize(int width, int height)
{
// when we get here, the controls haven't been resized yet
RECT tree, list, log, ex, ok, label, filterlabel, filterbox;
HWND hExit = GetDlgItem(*this, IDC_EXIT);
HWND hOK = GetDlgItem(*this, IDOK);
HWND hLabel = GetDlgItem(*this, IDC_INFOLABEL);
HWND hFilterLabel = GetDlgItem(*this, IDC_FILTERLABEL);
::GetClientRect(m_hTreeControl, &tree);
::GetClientRect(m_hListControl, &list);
::GetClientRect(m_hLogMsgControl, &log);
::GetClientRect(hExit, &ex);
::GetClientRect(hOK, &ok);
::GetClientRect(hLabel, &label);
::GetClientRect(hFilterLabel, &filterlabel);
::GetClientRect(m_hFilterControl, &filterbox);
::InvalidateRect(*this, NULL, TRUE);
HDWP hdwp = BeginDeferWindowPos(9);
hdwp = DeferWindowPos(hdwp, m_hwndToolbar, *this, 0, 0, width, m_topmarg, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, hFilterLabel, *this, m_xSliderPos+4, m_topmarg+5, FILTERLABELWIDTH, 12, SWP_NOZORDER|SWP_NOACTIVATE|SWP_FRAMECHANGED);
hdwp = DeferWindowPos(hdwp, m_hFilterControl, *this, m_xSliderPos+4+FILTERLABELWIDTH, m_topmarg+1, width-m_xSliderPos-4-FILTERLABELWIDTH-4, FILTERBOXHEIGHT-1, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, m_hTreeControl, *this, 0, m_topmarg, m_xSliderPos, height-m_topmarg-m_bottommarg+FILTERBOXHEIGHT+4, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, m_hListControl, *this, m_xSliderPos+4, m_topmarg+FILTERBOXHEIGHT, width-m_xSliderPos-4, m_ySliderPos-m_topmarg+4, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, m_hLogMsgControl, *this, m_xSliderPos+4, m_ySliderPos+8+FILTERBOXHEIGHT, width-m_xSliderPos-4, height-m_bottommarg-m_ySliderPos-4, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, hExit, *this, width-ok.right+ok.left-ex.right+ex.left-3, height-ex.bottom+ex.top, ex.right-ex.left, ex.bottom-ex.top, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, hOK, *this, width-ok.right+ok.left, height-ok.bottom+ok.top, ok.right-ok.left, ok.bottom-ok.top, SWP_NOZORDER|SWP_NOACTIVATE);
hdwp = DeferWindowPos(hdwp, hLabel, *this, 2, height-label.bottom+label.top+2, width-ok.right-ex.right-8, ex.bottom-ex.top, SWP_NOZORDER|SWP_NOACTIVATE);
EndDeferWindowPos(hdwp);
}
bool CMainDlg::OnSetCursor(HWND hWnd, UINT nHitTest, UINT message)
{
UNREFERENCED_PARAMETER(message);
UNREFERENCED_PARAMETER(nHitTest);
if (hWnd == *this)
{
RECT rect;
POINT pt;
GetClientRect(*this, &rect);
GetCursorPos(&pt);
ScreenToClient(*this, &pt);
if (PtInRect(&rect, pt))
{
ClientToScreen(*this, &pt);
// are we right of the tree control?
::GetWindowRect(m_hTreeControl, &rect);
if ((pt.x > rect.right)&&
(pt.y >= rect.top)&&
(pt.y <= rect.bottom))
{
// but left of the list control?
::GetWindowRect(m_hListControl, &rect);
if (pt.x < rect.left)
{
HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZEWE));
SetCursor(hCur);
return TRUE;
}
// maybe we are below the log message list control?
if (pt.y > rect.bottom)
{
::GetWindowRect(m_hLogMsgControl, &rect);
if (pt.y < rect.top)
{
HCURSOR hCur = LoadCursor(NULL, MAKEINTRESOURCE(IDC_SIZENS));
SetCursor(hCur);
return TRUE;
}
}
}
}
}
return FALSE;
}
bool CMainDlg::OnMouseMove(UINT nFlags, POINT point)
{
HDC hDC;
RECT rect, tree, list, treelist, treelistclient, logrect, loglist, loglistclient;
if (m_nDragMode == DRAGMODE_NONE)
return false;
// create an union of the tree and list control rectangle
::GetWindowRect(m_hListControl, &list);
::GetWindowRect(m_hTreeControl, &tree);
::GetWindowRect(m_hLogMsgControl, &logrect);
UnionRect(&treelist, &tree, &list);
treelistclient = treelist;
MapWindowPoints(NULL, *this, (LPPOINT)&treelistclient, 2);
UnionRect(&loglist, &logrect, &list);
loglistclient = loglist;
MapWindowPoints(NULL, *this, (LPPOINT)&loglistclient, 2);
//convert the mouse coordinates relative to the top-left of
//the window
ClientToScreen(*this, &point);
GetClientRect(*this, &rect);
MapWindowPoints(*this, NULL, (LPPOINT)&rect, 2);
point.x -= rect.left;
point.y -= rect.top;
//same for the window coordinates - make them relative to 0,0
LONG tempy = rect.top;
LONG tempx = rect.left;
OffsetRect(&treelist, -tempx, -tempy);
OffsetRect(&loglist, -tempx, -tempy);
if (point.x < treelist.left+REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.left+REPOBROWSER_CTRL_MIN_WIDTH;
if (point.x > treelist.right-REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.right-REPOBROWSER_CTRL_MIN_WIDTH;
if (point.y > loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT;
if (point.y < loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT;
if ((nFlags & MK_LBUTTON) && ((point.x != m_oldx)||(point.y != m_oldy)))
{
hDC = GetDC(*this);
if (hDC)
{
if (m_nDragMode == DRAGMODE_HORIZONTAL)
{
DrawXorBar(hDC, m_oldx+2, treelistclient.top, 4, treelistclient.bottom-treelistclient.top-2);
DrawXorBar(hDC, point.x+2, treelistclient.top, 4, treelistclient.bottom-treelistclient.top-2);
}
else
{
DrawXorBar(hDC, loglistclient.left, m_oldy+2, loglistclient.right-loglistclient.left-2, 4);
DrawXorBar(hDC, loglistclient.left, point.y+2, loglistclient.right-loglistclient.left-2, 4);
}
ReleaseDC(*this, hDC);
}
m_oldx = point.x;
m_oldy = point.y;
}
return true;
}
bool CMainDlg::OnLButtonDown(UINT nFlags, POINT point)
{
UNREFERENCED_PARAMETER(nFlags);
HDC hDC;
RECT rect, tree, list, treelist, treelistclient, logrect, loglist, loglistclient;
// create an union of the tree and list control rectangle
::GetWindowRect(m_hListControl, &list);
::GetWindowRect(m_hTreeControl, &tree);
::GetWindowRect(m_hLogMsgControl, &logrect);
UnionRect(&treelist, &tree, &list);
treelistclient = treelist;
MapWindowPoints(NULL, *this, (LPPOINT)&treelistclient, 2);
UnionRect(&loglist, &logrect, &list);
loglistclient = loglist;
MapWindowPoints(NULL, *this, (LPPOINT)&loglistclient, 2);
//convert the mouse coordinates relative to the top-left of
//the window
ClientToScreen(*this, &point);
GetClientRect(*this, &rect);
MapWindowPoints(*this, NULL, (LPPOINT)&rect, 2);
point.x -= rect.left;
point.y -= rect.top;
//same for the window coordinates - make them relative to 0,0
LONG tempy = rect.top;
LONG tempx = rect.left;
OffsetRect(&treelist, -tempx, -tempy);
OffsetRect(&loglist, -tempx, -tempy);
if ((point.y < loglist.top) ||
(point.y > treelist.bottom))
return false;
m_nDragMode = DRAGMODE_HORIZONTAL;
if ((point.x+rect.left) > list.left)
m_nDragMode = DRAGMODE_VERTICAL;
if (point.x < treelist.left+REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.left+REPOBROWSER_CTRL_MIN_WIDTH;
if (point.x > treelist.right-REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.right-REPOBROWSER_CTRL_MIN_WIDTH;
if (point.y > loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT;
if (point.y < loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT;
SetCapture(*this);
hDC = GetDC(*this);
if (m_nDragMode == DRAGMODE_HORIZONTAL)
DrawXorBar(hDC, point.x+2, treelistclient.top, 4, treelistclient.bottom-treelistclient.top-2);
else
DrawXorBar(hDC, loglistclient.left, point.y+2, loglistclient.right-loglistclient.left-2, 4);
ReleaseDC(*this, hDC);
m_oldx = point.x;
m_oldy = point.y;
return true;
}
bool CMainDlg::OnLButtonUp(UINT nFlags, POINT point)
{
UNREFERENCED_PARAMETER(nFlags);
if (m_nDragMode == DRAGMODE_NONE)
return false;
PositionChildWindows(point, m_nDragMode == DRAGMODE_HORIZONTAL, true);
//convert the mouse coordinates relative to the top-left of
//the window
ClientToScreen(*this, &point);
RECT rect;
GetClientRect(*this, &rect);
MapWindowPoints(*this, NULL, (LPPOINT)&rect, 2);
m_oldx = point.x;
m_oldy = point.y;
ReleaseCapture();
// initialize the window position infos
GetClientRect(m_hTreeControl, &rect);
m_xSliderPos = rect.right+4;
GetClientRect(m_hListControl, &rect);
m_ySliderPos = rect.bottom+m_topmarg+FILTERBOXHEIGHT;
m_nDragMode = DRAGMODE_NONE;
return true;
}
void CMainDlg::PositionChildWindows(POINT point, bool bHorz, bool bShowBar)
{
HDC hDC;
RECT rect, tree, list, treelist, treelistclient, logrect, loglist, loglistclient;
// create an union of the tree and list control rectangle
::GetWindowRect(m_hListControl, &list);
::GetWindowRect(m_hTreeControl, &tree);
::GetWindowRect(m_hLogMsgControl, &logrect);
UnionRect(&treelist, &tree, &list);
treelistclient = treelist;
MapWindowPoints(NULL, *this, (LPPOINT)&treelistclient, 2);
UnionRect(&loglist, &logrect, &list);
loglistclient = loglist;
MapWindowPoints(NULL, *this, (LPPOINT)&loglistclient, 2);
//convert the mouse coordinates relative to the top-left of
//the window
ClientToScreen(*this, &point);
GetClientRect(*this, &rect);
MapWindowPoints(*this, NULL, (LPPOINT)&rect, 2);
POINT point2 = point;
if (point2.x < treelist.left+REPOBROWSER_CTRL_MIN_WIDTH)
point2.x = treelist.left+REPOBROWSER_CTRL_MIN_WIDTH;
if (point2.x > treelist.right-REPOBROWSER_CTRL_MIN_WIDTH)
point2.x = treelist.right-REPOBROWSER_CTRL_MIN_WIDTH;
POINT point3 = point;
if (point3.y < loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT)
point3.y = loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT;
if (point3.y > loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT)
point3.y = loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT;
point.x -= rect.left;
point.y -= rect.top;
//same for the window coordinates - make them relative to 0,0
LONG tempy = treelist.top;
LONG tempx = treelist.left;
OffsetRect(&treelist, -tempx, -tempy);
OffsetRect(&loglist, -tempx, -tempy);
if (point.x < treelist.left+REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.left+REPOBROWSER_CTRL_MIN_WIDTH;
if (point.x > treelist.right-REPOBROWSER_CTRL_MIN_WIDTH)
point.x = treelist.right-REPOBROWSER_CTRL_MIN_WIDTH;
if (point.y > loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.bottom-REPOBROWSER_CTRL_MIN_HEIGHT;
if (point.y < loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT)
point.y = loglist.top+REPOBROWSER_CTRL_MIN_HEIGHT;
if (bShowBar)
{
hDC = GetDC(*this);
if (bHorz)
DrawXorBar(hDC, m_oldx+2, treelistclient.top, 4, treelistclient.bottom-treelistclient.top-2);
else
DrawXorBar(hDC, loglistclient.left, m_oldy+2, loglistclient.right-loglistclient.left-2, 4);
ReleaseDC(*this, hDC);
}
//position the child controls
HDWP hdwp = BeginDeferWindowPos(5);
if (hdwp)
{
if (bHorz)
{
GetWindowRect(m_hTreeControl, &treelist);
treelist.right = point2.x - 2;
MapWindowPoints(NULL, *this, (LPPOINT)&treelist, 2);
hdwp = DeferWindowPos(hdwp, m_hTreeControl, NULL,
treelist.left, treelist.top, treelist.right-treelist.left, treelist.bottom-treelist.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
GetWindowRect(m_hListControl, &loglist);
loglist.left = point2.x + 2;
MapWindowPoints(NULL, *this, (LPPOINT)&loglist, 2);
hdwp = DeferWindowPos(hdwp, GetDlgItem(*this, IDC_FILTERLABEL), NULL,
loglist.left, treelist.top+5, 0, 0, SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER|SWP_NOSIZE);
hdwp = DeferWindowPos(hdwp, m_hFilterControl, NULL,
loglist.left+FILTERLABELWIDTH, treelist.top, loglist.right-FILTERLABELWIDTH, FILTERBOXHEIGHT,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
hdwp = DeferWindowPos(hdwp, m_hListControl, NULL,
loglist.left, treelist.top+FILTERBOXHEIGHT, loglist.right-loglist.left, loglist.bottom-treelist.top-FILTERBOXHEIGHT,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
GetWindowRect(m_hLogMsgControl, &treelist);
treelist.left = point2.x + 2;
MapWindowPoints(NULL, *this, (LPPOINT)&treelist, 2);
hdwp = DeferWindowPos(hdwp, m_hLogMsgControl, NULL,
treelist.left, treelist.top, treelist.right-treelist.left, treelist.bottom-treelist.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
}
else
{
GetWindowRect(m_hListControl, &treelist);
treelist.bottom = point3.y - 2;
MapWindowPoints(NULL, *this, (LPPOINT)&treelist, 2);
hdwp = DeferWindowPos(hdwp, m_hListControl, NULL,
treelist.left, treelist.top, treelist.right-treelist.left, treelist.bottom-treelist.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
GetWindowRect(m_hLogMsgControl, &treelist);
treelist.top = point3.y + 2;
MapWindowPoints(NULL, *this, (LPPOINT)&treelist, 2);
hdwp = DeferWindowPos(hdwp, m_hLogMsgControl, NULL,
treelist.left, treelist.top, treelist.right-treelist.left, treelist.bottom-treelist.top,
SWP_NOACTIVATE|SWP_NOOWNERZORDER|SWP_NOZORDER);
}
EndDeferWindowPos(hdwp);
}
}
void CMainDlg::DrawXorBar(HDC hDC, LONG x1, LONG y1, LONG width, LONG height)
{
static WORD _dotPatternBmp[8] =
{
0x0055, 0x00aa, 0x0055, 0x00aa,
0x0055, 0x00aa, 0x0055, 0x00aa
};
HBITMAP hbm;
HBRUSH hbr, hbrushOld;
hbm = CreateBitmap(8, 8, 1, 1, _dotPatternBmp);
hbr = CreatePatternBrush(hbm);
SetBrushOrgEx(hDC, x1, y1, NULL);
hbrushOld = (HBRUSH)SelectObject(hDC, hbr);
PatBlt(hDC, x1, y1, width, height, PATINVERT);
SelectObject(hDC, hbrushOld);
DeleteObject(hbr);
DeleteObject(hbm);
}
void CMainDlg::SaveWndPosition()
{
RECT rc;
::GetWindowRect(*this, &rc);
if (!IsZoomed(*this))
{
CRegStdDWORD regXY(_T("Software\\CommitMonitor\\XY"));
regXY = MAKELONG(rc.top, rc.left);
CRegStdDWORD regWHWindow(_T("Software\\CommitMonitor\\WHWindow"));
regWHWindow = MAKELONG(rc.bottom-rc.top, rc.right-rc.left);
::GetClientRect(*this, &rc);
CRegStdDWORD regWH(_T("Software\\CommitMonitor\\WH"));
regWH = MAKELONG(rc.bottom-rc.top, rc.right-rc.left);
}
if (IsZoomed(*this))
{
::GetWindowRect(m_hTreeControl, &rc);
::MapWindowPoints(NULL, *this, (LPPOINT)&rc, 2);
CRegStdDWORD regHorzPos(_T("Software\\CommitMonitor\\HorzPosZoomed"));
regHorzPos = rc.right;
CRegStdDWORD regVertPos(_T("Software\\CommitMonitor\\VertPosZoomed"));
::GetWindowRect(m_hListControl, &rc);
::MapWindowPoints(NULL, *this, (LPPOINT)&rc, 2);
regVertPos = rc.bottom;
}
else
{
::GetWindowRect(m_hTreeControl, &rc);
::MapWindowPoints(NULL, *this, (LPPOINT)&rc, 2);
CRegStdDWORD regHorzPos(_T("Software\\CommitMonitor\\HorzPos"));
regHorzPos = rc.right;
CRegStdDWORD regVertPos(_T("Software\\CommitMonitor\\VertPos"));
::GetWindowRect(m_hListControl, &rc);
::MapWindowPoints(NULL, *this, (LPPOINT)&rc, 2);
regVertPos = rc.bottom;
}
}
LRESULT CALLBACK CMainDlg::TreeProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
CMainDlg *pThis = (CMainDlg*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (uMessage == WM_SETFOCUS)
{
pThis->SetRemoveButtonState();
}
return CallWindowProc(pThis->m_oldTreeWndProc, hWnd, uMessage, wParam, lParam);
}
LRESULT CALLBACK CMainDlg::FilterProc(HWND hWnd, UINT uMessage, WPARAM wParam, LPARAM lParam)
{
CMainDlg *pThis = (CMainDlg*)GetWindowLongPtr(hWnd, GWLP_USERDATA);
if (pThis == NULL)
return 0;
if (uMessage == WM_LBUTTONDBLCLK)
{
::SetWindowText(pThis->m_hFilterControl, _T(""));
}
return CallWindowProc(pThis->m_oldFilterWndProc, hWnd, uMessage, wParam, lParam);
}
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.