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
|
/***************************************************************
* Name: FreeFileSyncMain.cpp
* Purpose: Code for Application Frame
* Author: ZenJu (zhnmju123@gmx.de)
* Created: 2008-07-16
* Copyright: ZenJu ()
* License:
**************************************************************/
#include "mainDialog.h"
#include <wx/filename.h>
#include "../library/globalFunctions.h"
#include <fstream>
#include <wx/clipbrd.h>
#include "../library/customGrid.h"
using namespace globalFunctions;
int leadingPanel = 0;
MainDialog::MainDialog(wxFrame* frame, const wxString& cfgFileName) :
GuiGenerated(frame),
parent(frame),
stackObjects(0),
filteringInitialized(false),
filteringPending(false),
cmpStatusUpdaterTmp(0)
{
m_bpButtonCompare->SetLabel(_("&Compare"));
m_bpButtonSync->SetLabel(_("&Synchronize"));
m_bpButtonFilter->SetLabel(_("&Filter"));
//initialize sync configuration
readConfigurationFromHD(cfgFileName, true);
leftOnlyFilesActive = true;
leftNewerFilesActive = true;
differentFilesActive = true;
rightNewerFilesActive = true; //do not put these bool values into config.dat!
rightOnlyFilesActive = true; //it's more convenient to have them defaulted at startup
equalFilesActive = false;
updateViewFilterButtons();
//set icons for this dialog
m_bpButton11->SetBitmapLabel(*GlobalResources::bitmapAbout);
m_bpButton10->SetBitmapLabel(*GlobalResources::bitmapExit);
m_bpButtonCompare->SetBitmapLabel(*GlobalResources::bitmapCompare);
m_bpButtonSync->SetBitmapLabel(*GlobalResources::bitmapSync);
m_bpButtonSync->SetBitmapDisabled(*GlobalResources::bitmapSyncDisabled);
m_bpButtonSwap->SetBitmapLabel(*GlobalResources::bitmapSwap);
m_bpButton14->SetBitmapLabel(*GlobalResources::bitmapHelp);
m_bpButton201->SetBitmapLabel(*GlobalResources::bitmapSave);
//prepare drag & drop
m_panel1->SetDropTarget(new FileDropEvent(this, 1));
m_panel2->SetDropTarget(new FileDropEvent(this, 2));
//create a right-click context menu
contextMenu = new wxMenu;
contextMenu->Append(contextManualFilter, _("Filter manually"));
contextMenu->Append(contextCopyClipboard, _("Copy to clipboard\tCTRL+C"));
#ifdef FFS_WIN
contextMenu->Append(contextOpenExplorer, _("Open with Explorer\tD-Click"));
#endif
contextMenu->AppendSeparator();
contextMenu->Append(contextDeleteFiles, _("Delete files\tDEL"));
contextMenu->Connect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainDialog::onContextMenuSelection), NULL, this);
//support for CTRL + C and DEL
m_grid1->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid1ButtonEvent), NULL, this);
m_grid2->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid2ButtonEvent), NULL, this);
m_grid3->Connect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid3ButtonEvent), NULL, this);
//identify leading grid by keyboard input or scroll action
m_grid1->Connect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_TOP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_BOTTOM, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_PAGEUP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_PAGEDOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_THUMBTRACK, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_SCROLLWIN_THUMBRELEASE, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Connect(wxEVT_GRID_LABEL_LEFT_CLICK, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->GetGridWindow()->Connect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid2->Connect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_TOP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_BOTTOM, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_PAGEUP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_PAGEDOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_THUMBTRACK, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_SCROLLWIN_THUMBRELEASE, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Connect(wxEVT_GRID_LABEL_LEFT_CLICK, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->GetGridWindow()->Connect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid3->Connect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->Connect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->Connect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->GetGridWindow()->Connect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
Connect(wxEVT_IDLE, wxEventHandler(MainDialog::OnIdleEvent), NULL, this);
m_grid3->GetGridWindow()->Connect(wxEVT_LEFT_UP, wxEventHandler(MainDialog::OnGrid3LeftMouseUp), NULL, this);
m_grid3->GetGridWindow()->Connect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::OnGrid3LeftMouseDown), NULL, this);
Connect(wxEVT_SIZE, wxEventHandler(MainDialog::onResizeMainWindow), NULL, this);
Connect(wxEVT_MOVE, wxEventHandler(MainDialog::onResizeMainWindow), NULL, this);
wxString toolTip = wxString(_("Legend\n")) +
_("---------\n") +
_("<| file on left side only\n") +
_("|> file on right side only\n") +
_("<< left file is newer\n") +
_(">> right file is newer\n") +
_("!= files are different\n") +
_("== files are equal\n\n") +
_("(-) filtered out from sync-process\n");
m_grid3->GetGridWindow()->SetToolTip(toolTip);
//enable parallel scrolling
m_grid1->setScrollFriends(m_grid1, m_grid2, m_grid3);
m_grid2->setScrollFriends(m_grid1, m_grid2, m_grid3);
m_grid3->setScrollFriends(m_grid1, m_grid2, m_grid3);
//share UI grid data with grids
m_grid1->setGridDataTable(¤tUI_View);
m_grid2->setGridDataTable(¤tUI_View);
m_grid3->setGridDataTable(¤tUI_View);
//disable sync button as long as "compare" hasn't been triggered.
m_bpButtonSync->Disable();
//make filesize right justified on grids
wxGridCellAttr* cellAttributes = m_grid1->GetOrCreateCellAttr(0, 2);
cellAttributes->SetAlignment(wxALIGN_RIGHT,wxALIGN_CENTRE);
m_grid1->SetColAttr(2, cellAttributes);
cellAttributes = m_grid2->GetOrCreateCellAttr(0, 2); //leave these two rows, might be necessary 'cause wxGridCellAttr is ref-counting
cellAttributes->SetAlignment(wxALIGN_RIGHT,wxALIGN_CENTRE); //and SetColAttr takes ownership (means: it will call DecRef())
m_grid2->SetColAttr(2, cellAttributes);
//as the name says: disable them
m_grid3->deactivateScrollbars();
//mainly to update row label sizes...
writeGrid(currentGridData);
//load list of last used configuration files
cfgFileHistory = new wxConfig("FreeFileSync");
for (int i = CfgHistroyLength - 1; i >= 0; --i) //put files in reverse order to history
{
const wxString key = "Selection" + numberToWxString(i);
wxString value;
if (cfgFileHistory->Read(key, &value))
addCfgFileToHistory(value);
}
m_choiceLoad->SetSelection(0);
//select rows only
m_grid1->SetSelectionMode(wxGrid::wxGridSelectRows);
m_grid2->SetSelectionMode(wxGrid::wxGridSelectRows);
m_grid3->SetSelectionMode(wxGrid::wxGridSelectRows);
//set color of selections
wxColour darkBlue(40, 35, 140);
m_grid1->SetSelectionBackground(darkBlue);
m_grid2->SetSelectionBackground(darkBlue);
m_grid3->SetSelectionBackground(darkBlue);
}
MainDialog::~MainDialog()
{
m_grid1->setGridDataTable(0);
m_grid2->setGridDataTable(0);
m_grid3->setGridDataTable(0);
m_grid1->setSortMarker(-1);
m_grid2->setSortMarker(-1);
m_grid1->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid1ButtonEvent), NULL, this);
m_grid2->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid2ButtonEvent), NULL, this);
m_grid3->Disconnect(wxEVT_KEY_DOWN, wxKeyEventHandler(MainDialog::onGrid3ButtonEvent), NULL, this);
m_grid1->Disconnect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_TOP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_BOTTOM, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_PAGEUP, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_PAGEDOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_THUMBTRACK, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_SCROLLWIN_THUMBRELEASE, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->Disconnect(wxEVT_GRID_LABEL_LEFT_CLICK, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid1->GetGridWindow()->Disconnect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid1access), NULL, this);
m_grid2->Disconnect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_TOP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_BOTTOM, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_PAGEUP, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_PAGEDOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_THUMBTRACK, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_SCROLLWIN_THUMBRELEASE, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->Disconnect(wxEVT_GRID_LABEL_LEFT_CLICK, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid2->GetGridWindow()->Disconnect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid2access), NULL, this);
m_grid3->Disconnect(wxEVT_KEY_DOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->Disconnect(wxEVT_SCROLLWIN_LINEUP, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->Disconnect(wxEVT_SCROLLWIN_LINEDOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
m_grid3->GetGridWindow()->Disconnect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::onGrid3access), NULL, this);
Disconnect(wxEVT_IDLE, wxEventHandler(MainDialog::OnIdleEvent), NULL, this);
m_grid3->GetGridWindow()->Disconnect(wxEVT_LEFT_UP, wxEventHandler(MainDialog::OnGrid3LeftMouseUp), NULL, this);
m_grid3->GetGridWindow()->Disconnect(wxEVT_LEFT_DOWN, wxEventHandler(MainDialog::OnGrid3LeftMouseDown), NULL, this);
Disconnect(wxEVT_SIZE, wxEventHandler(MainDialog::onResizeMainWindow), NULL, this);
Disconnect(wxEVT_MOVE, wxEventHandler(MainDialog::onResizeMainWindow), NULL, this);
contextMenu->Disconnect(wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainDialog::onContextMenuSelection), NULL, this);
delete contextMenu;
//write list of last used configuration files
int vectorSize = cfgFileNames.size();
for (int i = 0; i < CfgHistroyLength; ++i)
{
const wxString key = "Selection" + numberToWxString(i);
if (i < vectorSize)
cfgFileHistory->Write(key, cfgFileNames[i]);
else
{
if (cfgFileHistory->Exists(key))
cfgFileHistory->DeleteEntry(key);
}
}
delete cfgFileHistory;
writeConfigurationToHD(FreeFileSync::FFS_LastConfigFile); //don't trow exceptions in destructors
}
void MainDialog::onGrid1access(wxEvent& event)
{
if (leadingPanel != 1)
{
leadingPanel = 1;
m_grid1->SetFocus();
m_grid2->ClearSelection(); //clear selection on grid2
}
event.Skip();
}
void MainDialog::onGrid2access(wxEvent& event)
{
if (leadingPanel != 2)
{
leadingPanel = 2;
m_grid2->SetFocus();
m_grid1->ClearSelection(); //clear selection on grid1
}
event.Skip();
}
void MainDialog::onGrid3access(wxEvent& event)
{
if (leadingPanel != 3)
{
leadingPanel = 3;
m_grid1->ClearSelection(); //clear selection on grid1
m_grid2->ClearSelection(); //clear selection on grid1
}
event.Skip();
}
void MainDialog::filterRangeManual(const set<int>& rowsToFilterOnUI_View)
{
if (rowsToFilterOnUI_View.size() > 0)
{
int currentUI_Size = currentUI_View.size();
bool newSelection = false; //default: deselect range
//leadingRow determines de-/selection of all other rows
int leadingRow = *rowsToFilterOnUI_View.begin();
if (0 <= leadingRow && leadingRow < currentUI_Size)
newSelection = !currentGridData[currentUI_View[leadingRow].linkToCurrentGridData].selectedForSynchronization;
if (hideFiltered)
assert (!newSelection); //if hidefiltered is active, there should be no filtered elements on screen => current element was filtered out
//get all lines that need to be filtered (e.g. if a folder is marked, then its subelements should be marked as well)
set<int> rowsToFilterOnGridData; //rows to filter in backend
for (set<int>::iterator i = rowsToFilterOnUI_View.begin(); i != rowsToFilterOnUI_View.end(); ++i)
{
if (0 <= *i && *i < currentUI_Size)
{
unsigned int gridIndex = currentUI_View[*i].linkToCurrentGridData;
rowsToFilterOnGridData.insert(gridIndex);
FreeFileSync::addSubElements(rowsToFilterOnGridData, currentGridData, currentGridData[gridIndex]);
}
}
//toggle selection of filtered rows
for (set<int>::iterator i = rowsToFilterOnGridData.begin(); i != rowsToFilterOnGridData.end(); ++i)
currentGridData[*i].selectedForSynchronization = newSelection;
set<int> filteredOutRowsOnUI; //determine rows that are currently filtered out on current UI view
//update currentUI_View
for (UI_Grid::iterator i = currentUI_View.begin(); i != currentUI_View.end(); ++i)
{
const FileCompareLine& gridLine = currentGridData[i->linkToCurrentGridData];
i->cmpResult = evaluateCmpResult(gridLine.cmpResult, gridLine.selectedForSynchronization);
if (!gridLine.selectedForSynchronization)
filteredOutRowsOnUI.insert(i - currentUI_View.begin());
}
//signal UI that grids need to be refreshed on next Update()
m_grid1->ForceRefresh();
m_grid2->ForceRefresh();
m_grid3->ForceRefresh();
if (hideFiltered)
{
//some delay to show user the rows he has filtered out before they are removed
Update(); //show changes resulting from ForceRefresh()
wxMilliSleep(400);
//delete rows, that are filtered out:
removeRowsFromVector(currentUI_View, filteredOutRowsOnUI);
//redraw grid necessary to update new dimensions
writeGrid(currentGridData, true); //use UI buffer, no mapping from currentGridData to UI model again, just a re-dimensioning of grids
updateStatusInformation(currentUI_View); //status information has to be recalculated!
}
}
//clear selection on grids
if (hideFiltered)
{
m_grid1->ClearSelection();
m_grid2->ClearSelection();
} //exception for grid 3
m_grid3->ClearSelection();
}
/*grid event choreography:
1. UI-Mouse-Down => OnGridSelectCell
2. UI-Mouse-Up => SelectRangeEvent (if at least two rows are marked)
=> the decision if a range or a single cell is selected can be made only after Mouse-UP. But SelectRangeEvent unfortunately is not always
executed (e.g. if single cell selected)
=> new choreography:
1. UI-Mouse-Down => OnGrid3LeftMouseDown (notify that filtering was initialized: this is needed since under some circumstances it might happen that the program
receives a mouse-up without a preceding mouse-down (double-clicks)
2. UI-Mouse-Up => OnGrid3LeftMouseUp (notify that filtering shall be started on next idle event
3. UI-Mouse-Up => SelectRangeEvent, possibly
4. Idle event => OnIdleEvent
*/
void MainDialog::OnGrid3LeftMouseDown(wxEvent& event)
{
filteringInitialized = true;
event.Skip();
}
void MainDialog::OnGrid3LeftMouseUp(wxEvent& event)
{
filteringPending = true;
event.Skip();
}
void MainDialog::OnIdleEvent(wxEvent& event)
{
//process manually filtered rows
if (filteringPending)
{
filteringPending = false;
if (filteringInitialized) //filteringInitialized is being reset after each selection, since strangely it might happen, that the grid receives
{ //a mouse up event, but no mouse down! (e.g. when window is maximized and cursor is on grid3)
filteringInitialized = false;
filterRangeManual(getSelectedRows());
}
}
//------------------------------------------------------------------------------
//small routine to restore status information after some time
if (stackObjects > 0 ) //check if there is some work to do
{
wxLongLong currentTime = wxGetLocalTimeMillis();
if (currentTime - lastStatusChange > 3000) //restore stackObject after three seconds
{
lastStatusChange = currentTime;
stackObjects--;
m_statusBar1->PopStatusText(1);
}
}
event.Skip();
}
void MainDialog::copySelectionToClipboard(const set<int>& selectedRows, int selectedGrid)
{
if (selectedRows.size() > 0)
{
wxGrid* grid = 0;
switch (selectedGrid)
{
case 1:
grid = m_grid1;
break;
case 2:
grid = m_grid2;
break;
case 3:
grid = m_grid3;
break;
default:
return;
}
wxString clipboardString;
for (set<int>::iterator i = selectedRows.begin(); i != selectedRows.end(); ++i)
{
for (int k = 0; k < grid->GetNumberCols(); ++k)
{
clipboardString+= grid->GetCellValue(*i, k);
if (k != grid->GetNumberCols() - 1)
clipboardString+= '\t';
}
clipboardString+= '\n';
}
if (!clipboardString.IsEmpty())
// Write text to the clipboard
if (wxTheClipboard->Open())
{
// these data objects are held by the clipboard,
// so do not delete them in the app.
wxTheClipboard->SetData( new wxTextDataObject(clipboardString) );
wxTheClipboard->Close();
}
}
}
void removeInvalidRows(set<int>& rows, const int currentUI_Size)
{
set<int> validRows; //temporal table IS needed here
for (set<int>::iterator i = rows.begin(); i != rows.end(); ++i)
if (0 <= *i)
{
if (*i >= currentUI_Size) //set is sorted, so no need to continue here
break;
validRows.insert(*i);
}
rows = validRows;
}
set<int> MainDialog::getSelectedRows()
{
wxGrid* grid = 0;
switch (leadingPanel)
{
case 1:
grid = m_grid1;
break;
case 2:
grid = m_grid2;
break;
case 3:
grid = m_grid3;
break;
default:
return set<int>();
}
set<int> output;
int rowTop, rowBottom; //coords of selection
wxArrayInt selectedRows = grid->GetSelectedRows();
if (!selectedRows.IsEmpty())
{
for (unsigned int i = 0; i < selectedRows.GetCount(); ++i)
output.insert(selectedRows[i]);
}
if (!grid->GetSelectedCols().IsEmpty()) //if a column is selected this is means all rows are marked for deletion
{
for (int k = 0; k < grid->GetNumberRows(); ++k)
output.insert(k);
}
wxGridCellCoordsArray singlySelected = grid->GetSelectedCells();
if (!singlySelected.IsEmpty())
{
for (unsigned int k = 0; k < singlySelected.GetCount(); ++k)
output.insert(singlySelected[k].GetRow());
}
wxGridCellCoordsArray tmpArrayTop = grid->GetSelectionBlockTopLeft();
if (!tmpArrayTop.IsEmpty())
{
wxGridCellCoordsArray tmpArrayBottom = grid->GetSelectionBlockBottomRight();
unsigned int arrayCount = tmpArrayTop.GetCount();
if (arrayCount == tmpArrayBottom.GetCount())
{
for (unsigned int i = 0; i < arrayCount; ++i)
{
rowTop = tmpArrayTop[i].GetRow();
rowBottom = tmpArrayBottom[i].GetRow();
for (int k = rowTop; k <= rowBottom; ++k)
output.insert(k);
}
}
}
removeInvalidRows(output, currentUI_View.size());
return output;
}
class DeleteStatusUpdater : public StatusUpdater
{
public:
DeleteStatusUpdater(bool& unsolvedErrorOccured) : suppressUI_Errormessages(false), unsolvedErrors(unsolvedErrorOccured) {}
~DeleteStatusUpdater() {}
int reportError(const wxString& text)
{
if (suppressUI_Errormessages)
{
unsolvedErrors = true;
return StatusUpdater::continueNext;
}
wxString errorMessage = text + _("\n\nInformation: If you skip the error and continue or abort a re-compare will be necessary!");
ErrorDlg* errorDlg = new ErrorDlg(errorMessage, suppressUI_Errormessages);
int rv = errorDlg->ShowModal();
errorDlg->Destroy();
switch (rv)
{
case ErrorDlg::continueButtonPressed:
unsolvedErrors = true;
return StatusUpdater::continueNext;
case ErrorDlg::retryButtonPressed:
return StatusUpdater::retry;
case ErrorDlg::abortButtonPressed:
{
unsolvedErrors = true;
throw AbortThisProcess();
}
default:
assert (false);
}
return StatusUpdater::continueNext; //dummy return value
}
void updateStatusText(const wxString& text) {}
void initNewProcess(int objectsTotal, double dataTotal, int processID) {}
void updateProcessedData(int objectsProcessed, double dataProcessed) {}
void triggerUI_Refresh() {}
private:
bool suppressUI_Errormessages;
bool& unsolvedErrors;
};
void MainDialog::deleteFilesOnGrid(const set<int>& rowsToDeleteOnUI)
{
if (rowsToDeleteOnUI.size())
{
//map grid lines from UI to grid lines in backend
set<int> rowsToDeleteOnGrid;
for (set<int>::iterator i = rowsToDeleteOnUI.begin(); i != rowsToDeleteOnUI.end(); ++i)
rowsToDeleteOnGrid.insert(currentUI_View[*i].linkToCurrentGridData);
wxString headerText;
wxString filesToDelete;
if (useRecycleBin)
headerText = _("Do you really want to move the following objects(s) to the recycle bin?");
else
headerText = _("Do you really want to delete the following objects(s)?");
for (set<int>::iterator i = rowsToDeleteOnGrid.begin(); i != rowsToDeleteOnGrid.end(); ++i)
{
const FileCompareLine& currentCmpLine = currentGridData[*i];
if (currentCmpLine.fileDescrLeft.objType != isNothing)
filesToDelete+= currentCmpLine.fileDescrLeft.filename + "\n";
if (currentCmpLine.fileDescrRight.objType != isNothing)
filesToDelete+= currentCmpLine.fileDescrRight.filename + "\n";
filesToDelete+= "\n";
}
DeleteDialog* confirmDeletion = new DeleteDialog(headerText, filesToDelete, this); //no destruction needed; attached to main window
switch (confirmDeletion->ShowModal())
{
case DeleteDialog::okayButtonPressed:
{
bool unsolvedErrorOccured = false; //if an error is skipped a re-compare will be necessary!
try
{ //class errors when deleting files/folders
DeleteStatusUpdater deleteStatusUpdater(unsolvedErrorOccured);
FreeFileSync::deleteOnGridAndHD(currentGridData, rowsToDeleteOnGrid, &deleteStatusUpdater, useRecycleBin);
}
catch (AbortThisProcess& theException)
{}
//disable the sync button if errors occured during deletion
if (unsolvedErrorOccured)
m_bpButtonSync->Disable();
//redraw grid neccessary to update new dimensions and for UI-Backend data linkage
writeGrid(currentGridData); //do NOT use UI buffer here
m_grid1->ClearSelection(); //clear selection on grid
m_grid2->ClearSelection(); //clear selection on grid
m_grid3->ClearSelection(); //clear selection on grid
}
break;
case DeleteDialog::cancelButtonPressed:
default:
break;
}
}
}
void MainDialog::openWithFileBrowser(int rowNumber, int gridNr)
{
#ifdef FFS_WIN
if (gridNr == 1)
{
wxString command = "explorer " + FreeFileSync::getFormattedDirectoryName(m_directoryPanel1->GetValue()); //default
if (0 <= rowNumber && rowNumber < int(currentUI_View.size()))
{
wxString filename = currentGridData[currentUI_View[rowNumber].linkToCurrentGridData].fileDescrLeft.filename;
if (!filename.IsEmpty())
command = "explorer /select," + filename;
}
wxExecute(command);
}
else if (gridNr == 2)
{
wxString command = "explorer " + FreeFileSync::getFormattedDirectoryName(m_directoryPanel2->GetValue()); //default
if (0 <= rowNumber && rowNumber < int(currentUI_View.size()))
{
wxString filename = currentGridData[currentUI_View[rowNumber].linkToCurrentGridData].fileDescrRight.filename;
if (!filename.IsEmpty())
command = "explorer /select," + filename;
}
wxExecute(command);
}
#endif // FFS_WIN
}
void MainDialog::pushStatusInformation(const wxString& text)
{
lastStatusChange = wxGetLocalTimeMillis();
++stackObjects;
m_statusBar1->PushStatusText(text, 1);
}
void MainDialog::writeStatusInformation(const wxString& text)
{
stackObjects = 0;
m_statusBar1->SetStatusText(text, 1);
}
void MainDialog::onResizeMainWindow(wxEvent& event)
{
if (!IsMaximized())
{
int width = 0;
int height = 0;
int x = 0;
int y = 0;
GetSize(&width, &height);
GetPosition(&x, &y);
if (width > 0 && height > 0)
{
widthNotMaximized = width;
heightNotMaximized = height;
}
if (x >= 0 && y >= 0) //might be < 0 under some strange circumstances
{
posXNotMaximized = x;
posYNotMaximized = y;
}
}
event.Skip();
}
void MainDialog::onGrid1ButtonEvent(wxKeyEvent& event)
{
//CTRL + C || CTRL + INS
if (event.ControlDown() && event.GetKeyCode() == 67 ||
event.ControlDown() && event.GetKeyCode() == WXK_INSERT)
copySelectionToClipboard(getSelectedRows(), 1);
else if (event.GetKeyCode() == WXK_DELETE)
deleteFilesOnGrid(getSelectedRows());
event.Skip();
}
void MainDialog::onGrid2ButtonEvent(wxKeyEvent& event)
{
//CTRL + C || CTRL + INS
if (event.ControlDown() && event.GetKeyCode() == 67 ||
event.ControlDown() && event.GetKeyCode() == WXK_INSERT)
copySelectionToClipboard(getSelectedRows(), 2);
else if (event.GetKeyCode() == WXK_DELETE)
deleteFilesOnGrid(getSelectedRows());
event.Skip();
}
void MainDialog::onGrid3ButtonEvent(wxKeyEvent& event)
{
//CTRL + C || CTRL + INS
if (event.ControlDown() && event.GetKeyCode() == 67 ||
event.ControlDown() && event.GetKeyCode() == WXK_INSERT)
copySelectionToClipboard(getSelectedRows(), 3);
else if (event.GetKeyCode() == WXK_DELETE)
deleteFilesOnGrid(getSelectedRows());
event.Skip();
}
void MainDialog::OnOpenContextMenu( wxGridEvent& event )
{
set<int> selection = getSelectedRows();
//enable/disable context menu entries
if (selection.size() > 0)
{
contextMenu->Enable(contextManualFilter, true);
contextMenu->Enable(contextCopyClipboard, true);
contextMenu->Enable(contextDeleteFiles, true);
}
else
{
contextMenu->Enable(contextManualFilter, false);
contextMenu->Enable(contextCopyClipboard, false);
contextMenu->Enable(contextDeleteFiles, false);
}
#ifdef FFS_WIN
if ((leadingPanel == 1 || leadingPanel == 2) && selection.size() <= 1)
contextMenu->Enable(contextOpenExplorer, true);
else
contextMenu->Enable(contextOpenExplorer, false);
#endif
//show context menu
PopupMenu(contextMenu);
event.Skip();
}
void MainDialog::onContextMenuSelection(wxCommandEvent& event)
{
set<int> selection;
switch (event.GetId())
{
case contextManualFilter:
filterRangeManual(getSelectedRows());
break;
case contextCopyClipboard:
copySelectionToClipboard(getSelectedRows(), leadingPanel);
break;
case contextOpenExplorer:
selection = getSelectedRows();
if (leadingPanel == 1 || leadingPanel == 2)
{
if (selection.size() == 1)
openWithFileBrowser(*selection.begin(), leadingPanel);
else if (selection.size() == 0)
openWithFileBrowser(-1, leadingPanel);
}
break;
case contextDeleteFiles:
deleteFilesOnGrid(getSelectedRows());
break;
}
event.Skip();
}
void MainDialog::OnEnterLeftDir( wxCommandEvent& event )
{
wxString newDir = m_directoryPanel1->GetValue();
m_dirPicker1->SetPath(newDir);
event.Skip();
}
void MainDialog::OnEnterRightDir( wxCommandEvent& event )
{
wxString newDir = m_directoryPanel2->GetValue();
m_dirPicker2->SetPath(newDir);
event.Skip();
}
void MainDialog::OnDirChangedPanel1(wxFileDirPickerEvent& event)
{
wxString newPath = m_dirPicker1->GetPath();
m_directoryPanel1->SetValue(newPath);
//disable the sync button
m_bpButtonSync->Enable(false);
//clear grids
currentGridData.clear();
writeGrid(currentGridData);
event.Skip();
}
void MainDialog::OnDirChangedPanel2(wxFileDirPickerEvent& event)
{
wxString newPath = m_dirPicker2->GetPath();
m_directoryPanel2->SetValue(newPath);
//disable the sync button
m_bpButtonSync->Enable(false);
//clear grids
currentGridData.clear();
writeGrid(currentGridData);
event.Skip();
}
void MainDialog::clearStatusBar()
{
stackObjects = 0; //prevent old stack objects from popping up
m_statusBar1->SetStatusText("");
m_statusBar1->SetStatusText("", 1);
m_statusBar1->SetStatusText("", 2);
}
wxString getFormattedHistoryElement(const wxString& filename)
{
wxString output = wxFileName(filename).GetFullName();
if (output.EndsWith(".FFS"))
output = output.BeforeLast('.');
return output;
}
//tests if the same filenames are specified, even if they are relative to the current working directory
bool sameFileSpecified(const wxString& file1, const wxString& file2)
{
wxString file1Full = file1;
wxString file2Full = file2;
if (wxFileName(file1).GetPath() == wxEmptyString)
file1Full = wxFileName::GetCwd() + GlobalResources::fileNameSeparator + file1;
if (wxFileName(file2).GetPath() == wxEmptyString)
file2Full = wxFileName::GetCwd() + GlobalResources::fileNameSeparator + file2;
return (file1Full == file2Full);
}
void MainDialog::addCfgFileToHistory(const wxString& filename)
{
//the default configFile should not be in the history
if (sameFileSpecified(FreeFileSync::FFS_LastConfigFile, filename))
return;
bool duplicateEntry = false;
unsigned int duplicatePos = 0;
for (unsigned int i = 0; i < cfgFileNames.size(); ++i)
if (sameFileSpecified(cfgFileNames[i], filename))
{
duplicateEntry = true;
duplicatePos = i;
break;
}
if (duplicateEntry) //if entry is in the list, then jump to element
{
m_choiceLoad->SetSelection(duplicatePos + 1);
}
else
{
cfgFileNames.insert(cfgFileNames.begin(), filename);
m_choiceLoad->Insert(getFormattedHistoryElement(filename), 1); //insert after "Load configuration..."
m_choiceLoad->SetSelection(1);
}
//keep maximal size of history list
if (cfgFileNames.size() > unsigned(CfgHistroyLength))
{
//delete last rows
cfgFileNames.erase(cfgFileNames.end() - 1);
m_choiceLoad->Delete(CfgHistroyLength); //don't forget: m_choiceLoad has (cfgHistroyLength + 1) elements
}
}
void onFilesDropped(const wxString& elementName, wxTextCtrl* txtCtrl, wxDirPickerCtrl* dirPicker)
{
wxString fileName = elementName;
if (wxDirExists(fileName))
{
txtCtrl->SetValue(fileName);
dirPicker->SetPath(fileName);
}
else
{
fileName = wxFileName(fileName).GetPath();
if (wxDirExists(fileName))
{
txtCtrl->SetValue(fileName);
dirPicker->SetPath(fileName);
}
}
}
bool FileDropEvent::OnDropFiles(wxCoord x, wxCoord y, const wxArrayString& filenames)
{
if (filenames.IsEmpty())
return false;
else
{
//disable the sync button
mainDlg->m_bpButtonSync->Disable();
//clear grids
mainDlg->currentGridData.clear();
mainDlg->writeGrid(mainDlg->currentGridData);
mainDlg->clearStatusBar();
const wxString droppedFileName = filenames[0];
//test if ffs config file has been dropped
if (wxFileExists(droppedFileName) && FreeFileSync::isFFS_ConfigFile(droppedFileName))
{
mainDlg->readConfigurationFromHD(droppedFileName);
mainDlg->pushStatusInformation(_("Configuration loaded!"));
}
else if (targetGrid == 1)
onFilesDropped(droppedFileName, mainDlg->m_directoryPanel1, mainDlg->m_dirPicker1);
else if (targetGrid == 2)
onFilesDropped(droppedFileName, mainDlg->m_directoryPanel2, mainDlg->m_dirPicker2);
}
return false;
}
void MainDialog::OnSaveConfig(wxCommandEvent& event)
{
wxString defaultFileName = "SyncSettings.FFS";
//try to use last selected configuration file as default
int selectedItem;
if ((selectedItem = m_choiceLoad->GetSelection()) != wxNOT_FOUND)
if (1 <= selectedItem && unsigned(selectedItem) < m_choiceLoad->GetCount())
if (unsigned(selectedItem - 1) < cfgFileNames.size())
defaultFileName = cfgFileNames[selectedItem - 1];
clearStatusBar();
wxFileDialog* filePicker = new wxFileDialog(this, "", "", defaultFileName, wxString(_("FreeFileSync configuration")) + " (*.FFS)|*.FFS", wxFD_SAVE);
if (filePicker->ShowModal() == wxID_OK)
{
wxString newFileName = filePicker->GetFilename();
if (wxFileExists(newFileName))
{
wxMessageDialog* messageDlg = new wxMessageDialog(this, wxString("\"") + newFileName + "\"" + _(" already exists. Overwrite?"), _("Warning") , wxOK | wxCANCEL);
if (messageDlg->ShowModal() != wxID_OK)
{
pushStatusInformation(_("Saved aborted!"));
return;
}
}
writeConfigurationToHD(newFileName);
pushStatusInformation(_("Configuration saved!"));
}
}
void MainDialog::OnLoadConfiguration(wxCommandEvent& event)
{
int selectedItem;
if ((selectedItem = m_choiceLoad->GetSelection()) != wxNOT_FOUND)
{
wxString newCfgFile;
clearStatusBar();
switch (selectedItem)
{
case 0: //load config from file
wxFileDialog* filePicker = new wxFileDialog(this, "", "", "", wxString(_("FreeFileSync configuration")) + " (*.FFS)|*.FFS", wxFD_OPEN);
if (filePicker->ShowModal() == wxID_OK)
newCfgFile = filePicker->GetFilename();
break;
default:
if (1 <= selectedItem && unsigned(selectedItem) < m_choiceLoad->GetCount())
{
if (unsigned(selectedItem - 1) < cfgFileNames.size())
newCfgFile = cfgFileNames[selectedItem - 1];
}
break;
}
if (!newCfgFile.IsEmpty())
{
if (!wxFileExists(newCfgFile))
wxMessageBox(_("The selected file does not exist anymore!"), _("Warning"), wxOK);
else if (!FreeFileSync::isFFS_ConfigFile(newCfgFile))
wxMessageBox(_("The selected file does not contain a valid configuration!"), _("Warning"), wxOK);
else
{
readConfigurationFromHD(newCfgFile);
pushStatusInformation(_("Configuration loaded!"));
}
}
}
event.Skip();
}
void MainDialog::OnChoiceKeyEvent(wxKeyEvent& event)
{
if (event.GetKeyCode() == WXK_DELETE)
{ //try to delete the currently selected config history item
int selectedItem;
if ((selectedItem = m_choiceLoad->GetSelection()) != wxNOT_FOUND)
if (1 <= selectedItem && unsigned(selectedItem) < m_choiceLoad->GetCount())
if (unsigned(selectedItem - 1) < cfgFileNames.size())
{
//delete selected row
cfgFileNames.erase(cfgFileNames.begin() + selectedItem - 1);
m_choiceLoad->Delete(selectedItem);
}
}
event.Skip();
}
void MainDialog::OnChangeCompareVariant(wxCommandEvent& event)
{
//disable the sync button
m_bpButtonSync->Enable(false);
//clear grids
currentGridData.clear();
writeGrid(currentGridData);
}
void MainDialog::OnClose(wxCloseEvent &event)
{
Destroy();
}
void MainDialog::OnQuit(wxCommandEvent &event)
{
Destroy();
}
void MainDialog::loadDefaultConfiguration()
{
//default values
syncConfiguration.exLeftSideOnly = syncDirRight;
syncConfiguration.exRightSideOnly = syncDirRight;
syncConfiguration.leftNewer = syncDirRight;
syncConfiguration.rightNewer = syncDirRight;
syncConfiguration.different = syncDirRight;
m_radioBtnSizeDate->SetValue(true); //compare algorithm
includeFilter = "*"; //include all files/folders
excludeFilter = ""; //exlude nothing
//set status of filter button
filterIsActive = false; //do not filter by default
updateFilterButton();
//set status of "hide filtered items" checkbox
hideFiltered = false; //show filtered items
m_checkBoxHideFilt->SetValue(hideFiltered);
useRecycleBin = false; //do not use: in case OS doesn't support this, user will have to activate first and then get the error message
hideErrorMessages = false;
widthNotMaximized = wxDefaultCoord;
heightNotMaximized = wxDefaultCoord;
posXNotMaximized = wxDefaultCoord;
posYNotMaximized = wxDefaultCoord;
}
void MainDialog::readConfigurationFromHD(const wxString& filename, bool programStartup)
{
char bigBuffer[10000];
ifstream config(filename.c_str());
if (!config)
{
if (programStartup)
loadDefaultConfiguration();
else
wxMessageBox(wxString(_("Could not read configuration file ")) + "\"" + filename + "\"", _("An exception occured!"), wxOK | wxICON_ERROR);
return;
}
//read FFS identifier
config.get(bigBuffer, FreeFileSync::FFS_ConfigFileID.Len() + 1);
if (wxString(bigBuffer) != FreeFileSync::FFS_ConfigFileID)
{
wxMessageBox(_("The selected file does not contain a valid configuration!"), _("Warning"), wxOK);
config.close();
return;
}
//put filename on list of last used config files
addCfgFileToHistory(filename);
//read sync configuration
syncConfiguration.exLeftSideOnly = SyncDirection(config.get());
syncConfiguration.exRightSideOnly = SyncDirection(config.get());
syncConfiguration.leftNewer = SyncDirection(config.get());
syncConfiguration.rightNewer = SyncDirection(config.get());
syncConfiguration.different = SyncDirection(config.get());
//read compare algorithm
switch (int(config.get()))
{
case compareByTimeAndSize:
m_radioBtnSizeDate->SetValue(true);
break;
case compareByContent:
m_radioBtnContent->SetValue(true);
break;
default:
assert (false);
}
//read column sizes
for (int i = 0; i < m_grid1->GetNumberCols(); ++i)
{
config.getline(bigBuffer, 100, char(0));
m_grid1->SetColSize(i, atoi(bigBuffer));
}
for (int i = 0; i < m_grid2->GetNumberCols(); ++i)
{
config.getline(bigBuffer, 100, char(0));
m_grid2->SetColSize(i, atoi(bigBuffer));
}
//read application window size and position
bool startWindowMaximized = bool(config.get());
config.getline(bigBuffer, 100, char(0));
int widthTmp = atoi(bigBuffer);
config.getline(bigBuffer, 100, char(0));
int heighthTmp = atoi(bigBuffer);
config.getline(bigBuffer, 100, char(0));
int posX_Tmp = atoi(bigBuffer);
config.getline(bigBuffer, 100, char(0));
int posY_Tmp = atoi(bigBuffer);
//apply window size and position at program startup ONLY
if (programStartup)
{
widthNotMaximized = widthTmp;
heightNotMaximized = heighthTmp;
posXNotMaximized = posX_Tmp;
posYNotMaximized = posY_Tmp;
//apply window size and position
SetSize(posXNotMaximized, posYNotMaximized, widthNotMaximized, heightNotMaximized);
Maximize(startWindowMaximized);
}
//read last directory selection
config.getline(bigBuffer, 10000, char(0));
m_directoryPanel1->SetValue(bigBuffer);
if (wxDirExists(bigBuffer))
m_dirPicker1->SetPath(bigBuffer);
config.getline(bigBuffer, 10000, char(0));
m_directoryPanel2->SetValue(bigBuffer);
if (wxDirExists(bigBuffer))
m_dirPicker2->SetPath(bigBuffer);
//read filter settings:
hideFiltered = bool(config.get());
m_checkBoxHideFilt->SetValue(hideFiltered);
filterIsActive = bool(config.get());
updateFilterButton();
//include
config.getline(bigBuffer, 10000, char(0));
includeFilter = bigBuffer;
//exclude
config.getline(bigBuffer, 10000, char(0));
excludeFilter = bigBuffer;
useRecycleBin = bool(config.get());
hideErrorMessages = bool(config.get());
config.close();
}
void MainDialog::writeConfigurationToHD(const wxString& filename)
{
ofstream config(filename.c_str());
if (!config)
{
wxMessageBox(wxString(_("Could not write to ")) + "\"" + filename + "\"", _("An exception occured!"), wxOK | wxICON_ERROR);
return;
}
//put filename on list of last used config files
addCfgFileToHistory(filename);
//write FFS identifier
config<<FreeFileSync::FFS_ConfigFileID.c_str();
//write sync configuration
config<<char(syncConfiguration.exLeftSideOnly)
<<char(syncConfiguration.exRightSideOnly)
<<char(syncConfiguration.leftNewer)
<<char(syncConfiguration.rightNewer)
<<char(syncConfiguration.different);
//write find method
if (m_radioBtnSizeDate->GetValue())
config<<char(compareByTimeAndSize);
else if (m_radioBtnContent->GetValue())
config<<char(compareByContent);
else assert (false);
//write column sizes
for (int i = 0; i < m_grid1->GetNumberCols(); ++i)
config<<m_grid1->GetColSize(i)<<char(0);
for (int i = 0; i < m_grid2->GetNumberCols(); ++i)
config<<m_grid2->GetColSize(i)<<char(0);
//write application window size and position
config<<char(IsMaximized());
//window size
config<<widthNotMaximized<<char(0);
config<<heightNotMaximized<<char(0);
//window position
config<<posXNotMaximized<<char(0);
config<<posYNotMaximized<<char(0);
//write last directory selection
config<<m_directoryPanel1->GetValue().c_str()<<char(0)
<<m_directoryPanel2->GetValue().c_str()<<char(0);
//write filter settings
config<<char(hideFiltered);
config<<char(filterIsActive);
config<<includeFilter.c_str()<<char(0)
<<excludeFilter.c_str()<<char(0);
config<<char(useRecycleBin);
config<<char(hideErrorMessages);
config.close();
}
void MainDialog::OnAbout(wxCommandEvent &event)
{
AboutDlg* aboutDlg = new AboutDlg(this);
aboutDlg->ShowModal();
}
void MainDialog::OnShowHelpDialog(wxCommandEvent &event)
{
HelpDlg* helpDlg = new HelpDlg(this);
helpDlg->ShowModal();
}
void MainDialog::OnFilterButton(wxCommandEvent &event)
{ //toggle filter on/off
filterIsActive = !filterIsActive;
//make sure, button-appearance and "filterIsActive" are in sync.
updateFilterButton();
if (filterIsActive)
FreeFileSync::filterCurrentGridData(currentGridData, includeFilter, excludeFilter);
else
FreeFileSync::removeFilterOnCurrentGridData(currentGridData);
writeGrid(currentGridData);
}
void MainDialog::OnHideFilteredButton(wxCommandEvent &event)
{ //toggle showing filtered rows
hideFiltered = !hideFiltered;
writeGrid(currentGridData);
//make sure, checkbox and "hideFiltered" are in sync
m_checkBoxHideFilt->SetValue(hideFiltered);
}
void MainDialog::OnConfigureFilter(wxHyperlinkEvent &event)
{
wxString beforeImage = includeFilter + wxChar(0) + excludeFilter;
FilterDlg* filterDlg = new FilterDlg(this, includeFilter, excludeFilter);
if (filterDlg->ShowModal() == FilterDlg::okayButtonPressed)
{
wxString afterImage = includeFilter + wxChar(0) + excludeFilter;
if (beforeImage != afterImage) //if filter settings are changed: set filtering to "on"
{
filterIsActive = true;
updateFilterButton();
FreeFileSync::filterCurrentGridData(currentGridData, includeFilter, excludeFilter);
writeGrid(currentGridData);
}
}
//no event.Skip() here, to not start browser
}
void MainDialog::OnLeftOnlyFiles(wxCommandEvent& event)
{
leftOnlyFilesActive = !leftOnlyFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::OnLeftNewerFiles(wxCommandEvent& event)
{
leftNewerFilesActive = !leftNewerFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::OnDifferentFiles(wxCommandEvent& event)
{
differentFilesActive = !differentFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::OnRightNewerFiles(wxCommandEvent& event)
{
rightNewerFilesActive = !rightNewerFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::OnRightOnlyFiles(wxCommandEvent& event)
{
rightOnlyFilesActive = !rightOnlyFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::OnEqualFiles(wxCommandEvent& event)
{
equalFilesActive = !equalFilesActive;
updateViewFilterButtons();
writeGrid(currentGridData);
};
void MainDialog::updateViewFilterButtons()
{
if (leftOnlyFilesActive)
m_bpButton20->SetBitmapLabel(*GlobalResources::bitmapLeftOnly);
else
m_bpButton20->SetBitmapLabel(*GlobalResources::bitmapLeftOnlyDeact);
if (leftNewerFilesActive)
m_bpButton21->SetBitmapLabel(*GlobalResources::bitmapLeftNewer);
else
m_bpButton21->SetBitmapLabel(*GlobalResources::bitmapLeftNewerDeact);
if (differentFilesActive)
m_bpButton22->SetBitmapLabel(*GlobalResources::bitmapDifferent);
else
m_bpButton22->SetBitmapLabel(*GlobalResources::bitmapDifferentDeact);
if (rightNewerFilesActive)
m_bpButton23->SetBitmapLabel(*GlobalResources::bitmapRightNewer);
else
m_bpButton23->SetBitmapLabel(*GlobalResources::bitmapRightNewerDeact);
if (rightOnlyFilesActive)
m_bpButton24->SetBitmapLabel(*GlobalResources::bitmapRightOnly);
else
m_bpButton24->SetBitmapLabel(*GlobalResources::bitmapRightOnlyDeact);
if (equalFilesActive)
m_bpButton25->SetBitmapLabel(*GlobalResources::bitmapEqual);
else
m_bpButton25->SetBitmapLabel(*GlobalResources::bitmapEqualDeact);
}
void MainDialog::updateFilterButton()
{
if (filterIsActive)
{
m_bpButtonFilter->SetBitmapLabel(*GlobalResources::bitmapFilterOn);
m_bpButtonFilter->SetToolTip(_("Filter active: Press again to deactivate"));
}
else
{
m_bpButtonFilter->SetBitmapLabel(*GlobalResources::bitmapFilterOff);
m_bpButtonFilter->SetToolTip(_("Press button to activate filter"));
}
}
void MainDialog::OnCompare(wxCommandEvent &event)
{
if (m_directoryPanel1->GetValue().IsEmpty() || m_directoryPanel2->GetValue().IsEmpty())
{
wxMessageBox(_("Please select directories for both sides!"), _("Information"));
return;
}
clearStatusBar();
//check if directories exist if loaded by config file
if (!wxDirExists(m_directoryPanel1->GetValue()))
{
wxMessageBox(_("Directory on the left does not exist. Please select a new one!"), _("Warning"), wxICON_WARNING);
return;
}
else if (!wxDirExists(m_directoryPanel2->GetValue()))
{
wxMessageBox(_("Directory on the right does not exist. Please select a new one!"), _("Warning"), wxICON_WARNING);
return;
}
wxBeginBusyCursor();
CompareVariant cmpVar = compareByTimeAndSize; //assign a value to suppress compiler warning
if (m_radioBtnSizeDate->GetValue())
cmpVar = compareByTimeAndSize;
else if (m_radioBtnContent->GetValue())
cmpVar = compareByContent;
else assert (false);
try
{ //class handling status display and error messages
CompareStatusUpdater statusUpdater(this);
cmpStatusUpdaterTmp = &statusUpdater;
stackObjects = 0;
//unsigned int startTime3 = GetTickCount();
FreeFileSync::startCompareProcess(currentGridData,
FreeFileSync::getFormattedDirectoryName(m_directoryPanel1->GetValue()),
FreeFileSync::getFormattedDirectoryName(m_directoryPanel2->GetValue()),
cmpVar,
&statusUpdater);
//wxMessageBox(numberToWxString(unsigned(GetTickCount()) - startTime3));
//filter currentGridData if option is set
if (filterIsActive)
FreeFileSync::filterCurrentGridData(currentGridData, includeFilter, excludeFilter);
//once compare is finished enable the sync button
m_bpButtonSync->Enable();
m_bpButtonSync->SetFocus();
writeGrid(currentGridData); //keep it in try/catch to not overwrite status information if compare is abortet
cmpStatusUpdaterTmp = 0;
}
catch (AbortThisProcess& theException)
{
//disable the sync button
m_bpButtonSync->Disable();
}
wxEndBusyCursor();
}
void MainDialog::OnAbortCompare(wxCommandEvent& event)
{
if (cmpStatusUpdaterTmp)
cmpStatusUpdaterTmp->requestAbortion();
}
inline
wxString MainDialog::evaluateCmpResult(const CompareFilesResult result, const bool selectedForSynchronization)
{
if (selectedForSynchronization)
switch (result)
{
case fileOnLeftSideOnly:
return "<|";
break;
case fileOnRightSideOnly:
return "|>";
break;
case rightFileNewer:
return ">>";
break;
case leftFileNewer:
return "<<";
break;
case filesDifferent:
return "!=";
break;
case filesEqual:
return "==";
break;
default:
assert (false);
}
else return constFilteredOut;
}
void MainDialog::writeGrid(const FileCompareResult& gridData, bool useUI_GridCache)
{
if (!useUI_GridCache)
{
//unsigned int startTime = GetTickCount();
mapFileModelToUI(currentUI_View, gridData); //update currentUI_View
//wxMessageBox(wxString("Benchmark: ") + numberToWxString(unsigned(GetTickCount()) - startTime) + " ms");
updateStatusInformation(currentUI_View); //write status information for currentUI_View
}
m_grid1->BeginBatch();
m_grid2->BeginBatch();
m_grid3->BeginBatch();
//all three grids retrieve their data directly from currentUI_View via a pointer!!!
//the only thing left to do is notify the grids to update their sizes (nr of rows), since this has to be communicated via messages by the grids
m_grid1->updateGridSizes();
m_grid2->updateGridSizes();
m_grid3->updateGridSizes();
//enlarge label width to display row numbers correctly
int nrOfRows = m_grid1->GetNumberRows();
if (nrOfRows >= 1)
{
int nrOfDigits = int(floor(log10(double(nrOfRows)) + 1));
m_grid1->SetRowLabelSize(nrOfDigits * 8 + 4);
m_grid2->SetRowLabelSize(nrOfDigits * 8 + 4);
}
//hide sort direction indicator on UI grids
m_grid1->setSortMarker(-1);
m_grid2->setSortMarker(-1);
m_grid1->EndBatch();
m_grid2->EndBatch();
m_grid3->EndBatch();
}
void MainDialog::OnSync( wxCommandEvent& event )
{
//check if there are files/folders that can be synced
bool nothingToSync = true;
for (FileCompareResult::const_iterator i = currentGridData.begin(); i != currentGridData.end(); ++i)
if (i->cmpResult != filesEqual)
{
nothingToSync = false;
break;
}
if (nothingToSync)
{
wxMessageBox(_("Nothing to synchronize. Both directories seem to contain the same data!"), _("Information"), wxICON_WARNING);
return;
}
SyncDialog* syncDlg = new SyncDialog(this);
if (syncDlg->ShowModal() == SyncDialog::StartSynchronizationProcess)
{
wxBeginBusyCursor();
clearStatusBar();
try
{
//class handling status updates and error messages
SyncStatusUpdater statusUpdater(this, hideErrorMessages);
//start synchronization and return elements that were not sync'ed in currentGridData
//unsigned int startTime3 = GetTickCount();
FreeFileSync::startSynchronizationProcess(currentGridData, syncConfiguration, &statusUpdater, useRecycleBin);
//wxMessageBox(numberToWxString(unsigned(GetTickCount()) - startTime3));
}
catch (AbortThisProcess& theException)
{ //do NOT disable the sync button: user might want to try to sync the REMAINING rows
} //m_bpButtonSync->Disable();
//display files that were not processed
writeGrid(currentGridData);
if (currentGridData.size() > 0)
pushStatusInformation(_("Not all items were synchronized! Have a look at the list."));
else
{
pushStatusInformation(_("All items have been synchronized!"));
m_bpButtonSync->Disable();
}
wxEndBusyCursor();
}
}
void MainDialog::OnLeftGridDoubleClick(wxGridEvent& event)
{
openWithFileBrowser(event.GetRow(), 1);
event.Skip();
}
void MainDialog::OnRightGridDoubleClick(wxGridEvent& event)
{
openWithFileBrowser(event.GetRow(), 2);
event.Skip();
}
//these three global variables are ONLY used for the sorting in the following methods
unsigned int currentSortColumn = 0;
bool sortAscending = true;
FileCompareResult* currentGridDataPtr = 0;
inline
bool cmpString(const wxString& a, const wxString& b)
{
if (a.IsEmpty())
return false; // if a and b are empty: false, if a empty, b not empty: also false, since empty rows should be put below on grid
else if (b.IsEmpty())
return true; // empty rows after filled rows: return true
//if a and b not empty:
if (sortAscending)
return (a < b);
else return (a > b);
}
inline
bool cmpLargeInt(const wxULongLong& a, const wxULongLong& b)
{
if (sortAscending)
return (a < b);
return (a > b);
}
bool sortGridLeft(const UI_GridLine& a, const UI_GridLine& b)
{
switch (currentSortColumn)
{
case 0:
return cmpString(a.leftFilename, b.leftFilename);
break;
case 1:
return cmpString(a.leftRelativePath, b.leftRelativePath);
break;
case 2:
ObjectType typeA = (*currentGridDataPtr)[a.linkToCurrentGridData].fileDescrLeft.objType;
ObjectType typeB = (*currentGridDataPtr)[b.linkToCurrentGridData].fileDescrLeft.objType;
//presort types: first files, then directories then empty rows
if (typeA == isNothing)
return false; //empty rows always last
else if (typeB == isNothing)
return true; //empty rows always last
else if (typeA == isDirectory)
return false;
else if (typeB == isDirectory)
return true;
else //use unformatted filesizes and sort by size
return cmpLargeInt((*currentGridDataPtr)[a.linkToCurrentGridData].fileDescrLeft.fileSize, (*currentGridDataPtr)[b.linkToCurrentGridData].fileDescrLeft.fileSize);
break;
case 3:
return cmpString(a.leftDate, b.leftDate);
break;
default:
assert(false);
}
return true; //dummy command
}
bool sortGridRight(const UI_GridLine& a, const UI_GridLine& b)
{
switch (currentSortColumn)
{
case 0:
return cmpString(a.rightFilename, b.rightFilename);
break;
case 1:
return cmpString(a.rightRelativePath, b.rightRelativePath);
break;
case 2:
ObjectType typeA = (*currentGridDataPtr)[a.linkToCurrentGridData].fileDescrRight.objType;
ObjectType typeB = (*currentGridDataPtr)[b.linkToCurrentGridData].fileDescrRight.objType;
//presort types: first files, then directories then empty rows
if (typeA == isNothing)
return false; //empty rows always last
else if (typeB == isNothing)
return true; //empty rows always last
else if (typeA == isDirectory)
return false;
else if (typeB == isDirectory)
return true;
else //use unformatted filesizes and sort by size
return cmpLargeInt((*currentGridDataPtr)[a.linkToCurrentGridData].fileDescrRight.fileSize, (*currentGridDataPtr)[b.linkToCurrentGridData].fileDescrRight.fileSize);
break;
case 3:
return cmpString(a.rightDate, b.rightDate);
break;
default:
assert(false);
}
return true; //dummy command
}
void MainDialog::OnSortLeftGrid(wxGridEvent& event)
{
static bool columnSortAscending[4] = {true, true, false, true};
currentSortColumn = event.GetCol();
currentGridDataPtr = ¤tGridData;
if (0 <= currentSortColumn && currentSortColumn <= 3)
{
sortAscending = columnSortAscending[currentSortColumn];
columnSortAscending[currentSortColumn] = !columnSortAscending[currentSortColumn];
sort(currentUI_View.begin(), currentUI_View.end(), sortGridLeft);
writeGrid(currentGridData, true); //use UI buffer, no mapping from currentGridData to UI model again
//set sort direction indicator on UI
if (sortAscending)
m_grid1->setSortMarker(currentSortColumn, GlobalResources::bitmapSmallUp);
else
m_grid1->setSortMarker(currentSortColumn, GlobalResources::bitmapSmallDown);
m_grid2->setSortMarker(-1);
}
event.Skip();
}
void MainDialog::OnSortRightGrid(wxGridEvent& event)
{
static bool columnSortAscending[4] = {true, true, false, true};
currentSortColumn = event.GetCol();
currentGridDataPtr = ¤tGridData;
if (0 <= currentSortColumn && currentSortColumn <= 3)
{
sortAscending = columnSortAscending[currentSortColumn];
columnSortAscending[currentSortColumn] = !columnSortAscending[currentSortColumn];
sort(currentUI_View.begin(), currentUI_View.end(), sortGridRight);
writeGrid(currentGridData, true);
//set sort direction indicator on UI
m_grid1->setSortMarker(-1);
if (sortAscending)
m_grid2->setSortMarker(currentSortColumn, GlobalResources::bitmapSmallUp);
else
m_grid2->setSortMarker(currentSortColumn, GlobalResources::bitmapSmallDown);
}
event.Skip();
}
void MainDialog::OnSwapDirs( wxCommandEvent& event )
{
//swap directory names
wxString tmp = m_directoryPanel1->GetValue();
m_directoryPanel1->SetValue(m_directoryPanel2->GetValue());
m_directoryPanel2->SetValue(tmp);
//swap grid information
FreeFileSync::swapGrids(currentGridData);
writeGrid(currentGridData);
}
//this sorting method is currently NOT used
bool cmpGridSmallerThan(const UI_GridLine& a, const UI_GridLine& b)
{
wxString cmpStringA;
wxString cmpStringB;
for (int i = 0; i < 4; ++i)
{
switch (i)
{
case 0:
cmpStringA = a.leftRelativePath;
cmpStringB = b.leftRelativePath;
break;
case 1:
cmpStringA = a.leftFilename;
cmpStringB = b.leftFilename;
break;
case 2:
cmpStringA = a.rightRelativePath;
cmpStringB = b.rightRelativePath;
break;
case 3:
cmpStringA = a.rightFilename;
cmpStringB = b.rightFilename;
break;
default:
assert (false);
}
if (cmpStringA.IsEmpty())
cmpStringA = '\255';
if (cmpStringB.IsEmpty())
cmpStringB = '\255';
if (cmpStringA != cmpStringB)
return (cmpStringA < cmpStringB);
}
return (false);
}
void MainDialog::updateStatusInformation(const UI_Grid& visibleGrid)
{
clearStatusBar();
unsigned int objectsOnLeftView = 0;
unsigned int objectsOnRightView = 0;
wxULongLong filesizeLeftView;
wxULongLong filesizeRightView;
for (UI_Grid::const_iterator i = visibleGrid.begin(); i != visibleGrid.end(); ++i)
{
const FileCompareLine& refLine = currentGridData[i->linkToCurrentGridData];
//calculate total number of bytes for each sied
if (refLine.fileDescrLeft.objType != isNothing)
{
filesizeLeftView+= refLine.fileDescrLeft.fileSize;
++objectsOnLeftView;
}
if (refLine.fileDescrRight.objType != isNothing)
{
filesizeRightView+= refLine.fileDescrRight.fileSize;
++objectsOnRightView;
}
}
//show status information on "root" level. This cannot be accomplished in writeGrid since filesizes are already formatted for display there
wxString objectsViewLeft = numberToWxString(objectsOnLeftView);
globalFunctions::includeNumberSeparator(objectsViewLeft);
if (objectsOnLeftView == 1)
m_statusBar1->SetStatusText(wxString(_("1 item on left, ")) + FreeFileSync::formatFilesizeToShortString(filesizeLeftView), 0);
else
m_statusBar1->SetStatusText(objectsViewLeft + _(" items on left, ") + FreeFileSync::formatFilesizeToShortString(filesizeLeftView), 0);
wxString objectsTotal = numberToWxString(currentGridData.size());
globalFunctions::includeNumberSeparator(objectsTotal);
wxString objectsView = numberToWxString(visibleGrid.size());
globalFunctions::includeNumberSeparator(objectsView);
if (currentGridData.size() == 1)
m_statusBar1->SetStatusText(objectsView + _(" of ") + objectsTotal + _(" row in view"), 1);
else
m_statusBar1->SetStatusText(objectsView + _(" of ") + objectsTotal + _(" rows in view"), 1);
wxString objectsViewRight = numberToWxString(objectsOnRightView);
globalFunctions::includeNumberSeparator(objectsViewRight);
if (objectsOnRightView == 1)
m_statusBar1->SetStatusText(wxString(_("1 item on right, ")) + FreeFileSync::formatFilesizeToShortString(filesizeRightView), 2);
else
m_statusBar1->SetStatusText(objectsViewRight + _(" items on right, ") + FreeFileSync::formatFilesizeToShortString(filesizeRightView), 2);
}
void MainDialog::mapFileModelToUI(UI_Grid& output, const FileCompareResult& fileCmpResult)
{
output.clear();
UI_GridLine gridline;
unsigned int currentRow = 0;
wxString fileSize; //tmp string
for (FileCompareResult::const_iterator i = fileCmpResult.begin(); i != fileCmpResult.end(); ++i, ++currentRow)
{
//process UI filter settings
switch (i->cmpResult)
{
case fileOnLeftSideOnly:
if (!leftOnlyFilesActive) continue;
break;
case fileOnRightSideOnly:
if (!rightOnlyFilesActive) continue;
break;
case rightFileNewer:
if (!rightNewerFilesActive) continue;
break;
case leftFileNewer:
if (!leftNewerFilesActive) continue;
break;
case filesDifferent:
if (!differentFilesActive) continue;
break;
case filesEqual:
if (!equalFilesActive) continue;
break;
default:
assert (false);
}
//hide filtered row, if corresponding option is set
if (hideFiltered && !i->selectedForSynchronization)
continue;
if (i->fileDescrLeft.objType == isDirectory)
{
gridline.leftFilename = wxEmptyString;
gridline.leftRelativePath = i->fileDescrLeft.relFilename;
gridline.leftSize = _("<Directory>");
}
else
{
gridline.leftFilename = i->fileDescrLeft.relFilename.AfterLast(GlobalResources::fileNameSeparator);
gridline.leftRelativePath = i->fileDescrLeft.relFilename.BeforeLast(GlobalResources::fileNameSeparator);
if (i->fileDescrLeft.fileSize != 0)
gridline.leftSize = globalFunctions::includeNumberSeparator(fileSize = i->fileDescrLeft.fileSize.ToString());
else
gridline.leftSize = "";
}
gridline.leftDate = i->fileDescrLeft.lastWriteTime;
gridline.cmpResult = evaluateCmpResult(i->cmpResult, i->selectedForSynchronization);
gridline.linkToCurrentGridData = currentRow;
if (i->fileDescrRight.objType == isDirectory)
{
gridline.rightFilename = wxEmptyString;
gridline.rightRelativePath = i->fileDescrRight.relFilename;
gridline.rightSize = _("<Directory>");
}
else
{
gridline.rightFilename = i->fileDescrRight.relFilename.AfterLast(GlobalResources::fileNameSeparator);
gridline.rightRelativePath = i->fileDescrRight.relFilename.BeforeLast(GlobalResources::fileNameSeparator);
if (i->fileDescrRight.fileSize != 0)
gridline.rightSize = globalFunctions::includeNumberSeparator(fileSize = i->fileDescrRight.fileSize.ToString());
else
gridline.rightSize = "";
}
gridline.rightDate = i->fileDescrRight.lastWriteTime;
output.push_back(gridline);
}
//sorting is expensive: ca. 50% bigger runtime for large grids; unsorted doesn't look too bad, so it's disabled
// sort(output.begin(), output.end(), cmpGridSmallerThan);
}
//########################################################################################################
void updateUI_Now()
{
//process UI events and prevent application from "not responding" -> NO performance issue!
wxTheApp->Yield();
// while (wxTheApp->Pending())
// wxTheApp->Dispatch();
}
bool updateUI_IsAllowed()
{
static wxLongLong lastExec = 0;
wxLongLong newExec = wxGetLocalTimeMillis();
if (newExec - lastExec >= uiUpdateInterval) //perform ui updates not more often than necessary
{
lastExec = newExec;
return true;
}
return false;
}
//########################################################################################################
CompareStatusUpdater::CompareStatusUpdater(MainDialog* dlg) :
mainDialog(dlg),
suppressUI_Errormessages(false),
currentProcess(-1)
{
//prevent user input during "compare", do not disable maindialog since abort-button would also be disabled
//it's not nice, but works - even has the advantage that certain actions are still possible: exit, about..
mainDialog->m_radioBtnSizeDate->Disable();
mainDialog->m_radioBtnContent->Disable();
mainDialog->m_bpButtonFilter->Disable();
mainDialog->m_hyperlinkCfgFilter->Disable();
mainDialog->m_checkBoxHideFilt->Disable();
mainDialog->m_bpButtonSync->Disable();
mainDialog->m_dirPicker1->Disable();
mainDialog->m_dirPicker2->Disable();
mainDialog->m_bpButtonSwap->Disable();
mainDialog->m_bpButton20->Disable();
mainDialog->m_bpButton21->Disable();
mainDialog->m_bpButton22->Disable();
mainDialog->m_bpButton23->Disable();
mainDialog->m_bpButton24->Disable();
mainDialog->m_bpButton25->Disable();
mainDialog->m_panel1->Disable();
mainDialog->m_panel2->Disable();
mainDialog->m_panel3->Disable();
mainDialog->m_bpButton201->Disable();
mainDialog->m_choiceLoad->Disable();
mainDialog->m_bpButton10->Disable();
mainDialog->m_bpButton14->Disable();
//show abort button
mainDialog->m_buttonAbort->Show();
mainDialog->m_bpButtonCompare->Hide();
mainDialog->m_buttonAbort->SetFocus();
//display status panel during compare
statusPanel = new CompareStatus(mainDialog);
mainDialog->bSizer1->Insert(1, statusPanel, 0, wxEXPAND | wxALL, 5 );
updateUI_Now();
mainDialog->Layout();
mainDialog->Refresh();
}
CompareStatusUpdater::~CompareStatusUpdater()
{
//reenable complete main dialog
mainDialog->m_radioBtnSizeDate->Enable();
mainDialog->m_radioBtnContent->Enable();
mainDialog->m_bpButtonFilter->Enable();
mainDialog->m_hyperlinkCfgFilter->Enable();
mainDialog->m_checkBoxHideFilt->Enable();
//mainDialog->m_bpButtonSync->Enable(); don't enable this one, this is up to OnCompare to handle its status
mainDialog->m_dirPicker1->Enable();
mainDialog->m_dirPicker2->Enable();
mainDialog->m_bpButtonSwap->Enable();
mainDialog->m_bpButton20->Enable();
mainDialog->m_bpButton21->Enable();
mainDialog->m_bpButton22->Enable();
mainDialog->m_bpButton23->Enable();
mainDialog->m_bpButton24->Enable();
mainDialog->m_bpButton25->Enable();
mainDialog->m_panel1->Enable();
mainDialog->m_panel2->Enable();
mainDialog->m_panel3->Enable();
mainDialog->m_bpButton201->Enable();
mainDialog->m_choiceLoad->Enable();
mainDialog->m_bpButton10->Enable();
mainDialog->m_bpButton14->Enable();
if (abortionRequested)
mainDialog->pushStatusInformation(_("Operation aborted!"));
mainDialog->m_buttonAbort->Hide();
mainDialog->m_bpButtonCompare->Show();
//remove status panel from main window
mainDialog->bSizer1->Detach(statusPanel);
statusPanel->Destroy();
updateUI_Now();
mainDialog->Layout();
mainDialog->Refresh();
}
inline
void CompareStatusUpdater::updateStatusText(const wxString& text)
{
statusPanel->setStatusText_NoUpdate(text);
}
void CompareStatusUpdater::initNewProcess(int objectsTotal, double dataTotal, int processID)
{
currentProcess = processID;
if (currentProcess == FreeFileSync::scanningFilesProcess)
;
else if (currentProcess == FreeFileSync::compareFileContentProcess)
statusPanel->resetCmpGauge(objectsTotal, dataTotal);
else assert(false);
}
inline
void CompareStatusUpdater::updateProcessedData(int objectsProcessed, double dataProcessed)
{
if (currentProcess == FreeFileSync::scanningFilesProcess)
statusPanel->incScannedFiles_NoUpdate(objectsProcessed);
else if (currentProcess == FreeFileSync::compareFileContentProcess)
statusPanel->incProcessedCmpData_NoUpdate(objectsProcessed, dataProcessed);
else assert(false);
}
int CompareStatusUpdater::reportError(const wxString& text)
{
if (suppressUI_Errormessages)
return StatusUpdater::continueNext;
statusPanel->updateStatusPanelNow();
wxString errorMessage = text + _("\n\nContinue with next object, retry or abort comparison?");
ErrorDlg* errorDlg = new ErrorDlg(errorMessage, suppressUI_Errormessages);
int rv = errorDlg->ShowModal();
errorDlg->Destroy();
switch (rv)
{
case ErrorDlg::continueButtonPressed:
return StatusUpdater::continueNext;
case ErrorDlg::retryButtonPressed:
return StatusUpdater::retry;
case ErrorDlg::abortButtonPressed:
{
abortionRequested = true;
throw AbortThisProcess();
}
default:
assert (false);
}
return StatusUpdater::continueNext; //dummy return value
}
inline
void CompareStatusUpdater::triggerUI_Refresh()
{
if (abortionRequested) throw AbortThisProcess(); //abort can be triggered by syncStatusFrame
if (updateUI_IsAllowed()) //test if specific time span between ui updates is over
statusPanel->updateStatusPanelNow();
}
//########################################################################################################
SyncStatusUpdater::SyncStatusUpdater(wxWindow* dlg, bool hideErrorMessages) :
suppressUI_Errormessages(hideErrorMessages)
{
syncStatusFrame = new SyncStatus(this, dlg);
syncStatusFrame->Show();
updateUI_Now();
}
SyncStatusUpdater::~SyncStatusUpdater()
{
//print the results list
unsigned int failedItems = unhandledErrors.GetCount();
wxString result;
if (failedItems)
{
result = wxString(_("Warning: Synchronization failed for ")) + numberToWxString(failedItems) + _(" item(s):\n\n");
for (unsigned int j = 0; j < failedItems; ++j)
result+= unhandledErrors[j] + "\n";
result+= "\n";
}
if (failedItems)
result+= _("Not all items have been synchronized! You may try to synchronize the remaining items again (WITHOUT having to re-compare)!");
else if (abortionRequested)
result+= _("Synchronization aborted: You may try to synchronize remaining items again (WITHOUT having to re-compare)!");
syncStatusFrame->setStatusText_NoUpdate(result);
//notify to syncStatusFrame that current process has ended
if (abortionRequested)
syncStatusFrame->processHasFinished(statusAborted); //enable okay and close events
else if (failedItems)
syncStatusFrame->processHasFinished(statusCompletedWithErrors);
else
syncStatusFrame->processHasFinished(statusCompletedWithSuccess);
}
inline
void SyncStatusUpdater::updateStatusText(const wxString& text)
{
syncStatusFrame->setStatusText_NoUpdate(text);
}
void SyncStatusUpdater::initNewProcess(int objectsTotal, double dataTotal, int processID)
{
assert (processID == FreeFileSync::synchronizeFilesProcess);
syncStatusFrame->resetGauge(objectsTotal, dataTotal);
syncStatusFrame->setCurrentStatus(statusSynchronizing);
}
inline
void SyncStatusUpdater::updateProcessedData(int objectsProcessed, double dataProcessed)
{
syncStatusFrame->incProgressIndicator_NoUpdate(objectsProcessed, dataProcessed);
}
int SyncStatusUpdater::reportError(const wxString& text)
{
if (suppressUI_Errormessages)
{
unhandledErrors.Add(text);
return StatusUpdater::continueNext;
}
syncStatusFrame->updateStatusDialogNow();
wxString errorMessage = text + _("\n\nContinue with next object, retry or abort synchronization?");
ErrorDlg* errorDlg = new ErrorDlg(errorMessage, suppressUI_Errormessages);
int rv = errorDlg->ShowModal();
errorDlg->Destroy();
switch (rv)
{
case ErrorDlg::continueButtonPressed:
unhandledErrors.Add(text);
return StatusUpdater::continueNext;
case ErrorDlg::retryButtonPressed:
return StatusUpdater::retry;
case ErrorDlg::abortButtonPressed:
{
unhandledErrors.Add(text);
abortionRequested = true;
throw AbortThisProcess();
}
default:
assert (false);
}
return StatusUpdater::continueNext; //dummy return value
}
void SyncStatusUpdater::triggerUI_Refresh()
{
if (abortionRequested)
throw AbortThisProcess(); //abort can be triggered by syncStatusFrame
if (updateUI_IsAllowed()) //test if specific time span between ui updates is over
syncStatusFrame->updateStatusDialogNow();
}
|