Source

newspeak / VCSUI.ns3

The default branch has multiple heads

   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
Newspeak3
'StructuredVCS'
class VCSUI usingPlatform: p vcs: vcs ide: ide = NewspeakObject ("The actual source control application

Copyright (c) 2010-2011 Matthias Kleine

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the ''Software''), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED ''AS IS'', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
"|

FileDirectory = p FileDirectory.
SmalltalkImage = p SmalltalkImage.

ExternalLauncher = p ExternalLauncher.
UIManager = p UIManager.
FileStream = p FileStream.


Set = p Set.
OrderedCollection = p OrderedCollection.
Color = p brazil Color.
Gradient = p brazil plumbing Gradient.
hopscotch = p hopscotch.
Subject = hopscotch core Subject.
Presenter = hopscotch core Presenter.
RowComposer = hopscotch composers RowComposer.
ColumnComposer = hopscotch composers ColumnComposer.
BlankFragment = hopscotch fragments BlankFragment.
TextEditorFragment = hopscotch fragments TextEditorFragment.
SeparatorItem = hopscotch SeparatorItem.
Menu = hopscotch Menu.
MenuItem = hopscotch MenuItem.
EditableLinePresenter = hopscotch fragments EditableLinePresenter.
ProgrammingPresenter = ide tools ProgrammingPresenter. 
HopscotchImages = p Hopscotch HopscotchImages.

vcs = vcs.
logger = Delay computation: [vcs core logger].
sourceMirrors = vcs sourceMirrors.
WordMerger = vcs diffing WordMerger.
ClassSourceMirror = vcs sourceMirrors ClassSourceMirror.

STPackageSourceMirror = Delay computation: [vcs stSourceMirrors STPackageSourceMirror].
STClassSourceMirror = Delay computation: [vcs stSourceMirrors STClassSourceMirror].
STExtensionClassSourceMirror = Delay computation: [vcs stSourceMirrors STExtensionClassSourceMirror].



backgroundColor = Color white.
frameColor ::= Color gray: 0.5.

presenters = Presenters new.

SourceControlPresenter = presenters SourceControlPresenter.
LocalRepositoryPresenter = presenters LocalRepositoryPresenter.
RemoteRepositoryPresenter = presenters RemoteRepositoryPresenter.

LocalHistorianPresenter = presenters LocalHistorianPresenter.
RemoteHistorianPresenter = presenters RemoteHistorianPresenter.

IncomingOutgoingPresenter = presenters IncomingOutgoingPresenter.

HistorianRelationPresenter = presenters HistorianRelationPresenter.

ImageBasedChangePresenter = presenters ImageBasedChangePresenter.
MergeHistorianPresenter = presenters MergeHistorianPresenter.

LogPresenter = presenters LogPresenter.
VersionPresenter = presenters VersionPresenter.

theModel ::= OrderedCollection new.
|)
(
class BasePresenter onSubject: subject = ProgrammingPresenter onSubject: subject (
"Provides UI elements common for source control's presenters"|
|)
('accessing'
h2Color = (

	^ Gradient 
		from: (Color h: 240 s: 0.04 v: 0.88) 
		to: (Color h: 240 s: 0.04 v: 0.86)
)
mediumHeadingColor = (

	^ Gradient 
		from: (Color h: 240 s: 0.04 v: 0.88) 
		to: (Color h: 240 s: 0.04 v: 0.86)
)'actions'
refreshSCAfter: block = (

	sendUp refreshSCAfter: block 
)'as yet unclassified'
deferred: block initially: fragment = (
	^(deferred: block) initialContent: fragment
)
removeButtonWithAction: aBlock = (
	^imageButton: {
		HopscotchImages default cancel16px.
		HopscotchImages default cancel16pxOver.
		HopscotchImages default cancel16pxDown}
	action: aBlock
)'combinators'
h1: body = (

	^ majorHeadingBlock: body
)
h2: body = (

	^ (padded: body with: {10. 5. 5. 5.})
		color: h2Color
)
h3: body = (

	^ minorHeadingBlock: body
)
h4: body = (

	^ (padded: body with: {10. 0. 0. 0}) color: minorHeadingColor
)
listPresentersOf: subjects inIncrementsOf: limit = (

	| versionPresenters |
	versionPresenters:: (subjects first: (subjects size min: limit))
		collect: [:each | each presenter].
	^ column: (
		subjects size > limit
			ifTrue: [
				versionPresenters,
				{(remainingDefinitionFor: (subjects allButFirst: limit) limit: limit)}]
			ifFalse: [versionPresenters])
)
remainingDefinitionFor: subjects limit: limit = (

	| restHolder |
	restHolder:: holder: (
		link: '...'
		action: [
			restHolder content: (listPresentersOf: subjects inIncrementsOf: limit)]).
	^ restHolder
))
class MergingUI = (
"A Hopscotch-based UI for displaying and merging 2 or 3 Newspeak source mirrors.

MergeSubjects have access to different versions of the object to be presented. If set to #diff mode, their presenters only show differences between the objects. If set to #merge mode, their presenters also provide tools to choose how to merge.

Several specializations of MergeSubject exist that allow diffing/merging different kinds of objects. A MirrorMergeSubject merges 2 or 3 Newspeak mirrors, represented as a TreeDiff. Specializations exists for different kinds of mirrors. A TextMergeSubject allows diffing/merging plaing strings.

The UIs for diffing and merging are very similar, with the merging UI adding some features to the diffing UI. One could think of implementing the two functionalities as two sets of classes (e.g. ClassMirrorDiffSubject/Presenter and ClassMirrorMergeSubject/Presenter). It seems to be easier with only one set of classes, though. Presenter methods usually have to add new UI elements for the merging case. Currently they can simply do so by adding using ifMerging:. Using one set of classes, the mode becomes part of the model."|
|)
(
class ClassMirrorMergePresenter onSubject: subject = MirrorMergePresenter onSubject: subject (|
	toggle
	headerHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	toggle collapse.
	updateHolders.
)
classHeadingLabeled: labels = (

	^ (h3: (row: labels)) width: 0 elasticity: 1
)
definition = (

	headerHolder:: holder: nil.
	updateHolders.
	toggle::
		heading: [headerHolder]
		details: [detailsDefinition]
		initiallyExpanded: subject interestingChange .

	^(row: {
		toggle width: 0 elasticity: 1.
		columnSeparator}) color: backgroundColor.
)
detailsDefinition = (

	| subjects |
	^ column: {
		subject category presenter.
		subject accessModifier presenter.
		subject name presenter.
		subject constructor presenter.
		subject superclassClause presenter.
		subject classComment presenter.
		subject slotsSource presenter.
		subject initExpressions presenter.
		sortedPresenters: subject unequalClassSubjects.
		sortedPresenters: subject unequalInstanceMethodSubjects
			labeledIfNotEmpty: 'Instance methods'.
		sortedPresenters: subject unequalClassMethodSubjects
			labeledIfNotEmpty: 'Class methods'}
)
headingForSide: side labeled: sideLabel = (
	
	^ classHeadingLabeled: {
		(label: headingLabel asText allBold) color: (colorIndicatingSelectionStatusForSide: side).
		label: ' [', sideLabel, ']'.
		smallBlank.
		linkToSelectSide: side.
		filler.
		(side = #ourSource)
			ifTrue: [revertSourceLink]
			ifFalse: [nothing]}
)
revertSourceLink = (

	^ (subject isMerge not and: [subject canLoadTheirs])
		ifTrue: [
				link: 'revert' action: [
					refreshSCAfter: [subject loadTheirs]]]
		ifFalse: [nothing]
)
sortedPresenters: presenters  labeledIfNotEmpty: label = (

	^ presenters isEmpty
		ifTrue: [nothing]
		ifFalse: [
			column: {
				(padded: (label: label) with: {10. 0. 0. 0.}) color: minorHeadingColor.
				sortedPresenters: presenters}]	
)
sortedPresenters: subjects = (

	^ column: ((subjects asSortedCollection: [:a :b | a sortKey asString < b sortKey asString])
		collect: [:each | each presenter])
)
updateHolders = (

	headerHolder content: headingDefinition
))
class ClassMirrorMergeSubject onModel: model <TreeDiff> = MirrorMergeSubject onModel: model (""|
category = textMergeSubjectFor: #category title: 'Category'.
accessModifier = textMergeSubjectFor: #accessModifier title: 'Access Modifier'.
name = textMergeSubjectFor: #name title: 'Name'.
constructor = textMergeSubjectFor: #constructor title: 'Constructor'.
superclassClause = textMergeSubjectFor: #superclassClause title: 'Superclass Clause'.
classComment = textMergeSubjectFor: #classComment title: 'Comment'.
slotsSource = textMergeSubjectFor: #slotsSource title: 'Slots'.
initExpressions = textMergeSubjectFor: #initExpressions title: 'Init Expressions'.
classes = create: self class for: #classes.
instanceMethods = create: MethodMirrorMergeSubject for: #instanceMethods.
classMethods = create: MethodMirrorMergeSubject for: #classMethods.
|)
('as yet unclassified'
canLoadTheirs = (

	^ treeDiff anyNode isToplevel
)
create: klass for: nodeType = (

	^ Delay computation: [
		| treeDiffs |
		treeDiffs:: treeDiff children select: [:each | each nodeType = nodeType].
		treeDiffs collect: [:each | klass onModel: {each. mode. self}]]
)
createPresenter = (

	^ ClassMirrorMergePresenter onSubject: self
)
loadTheirs = (

	treeDiff left installAsToplevelClass.
)
manualMergeMirrorIfFail: failBlock = (

	^ ClassSourceMirror new
		category: category finalMerge asString;
		accessModifier: accessModifier finalMerge asString;
		name: name finalMerge asString;
		constructor: constructor finalMerge asString;
		superclassClause: superclassClause finalMerge asString;
		classComment: classComment finalMerge asString;
		slotsSource: slotsSource finalMerge asString;
		initExpressions: initExpressions finalMerge asString;
		classes: (presentMirrorsOf: classes ifFail: failBlock);
		instanceMethods: (presentMirrorsOf: instanceMethods ifFail: failBlock);
		classMethods: (presentMirrorsOf: classMethods ifFail: failBlock);
		yourself
)
mirrorIfPresent: presentBlock ifRemoved: removedBlock ifFail: failBlock = (

	removedAfterMerge ifTrue: [^ removedBlock value].
	currentSelection =  #manualMerge ifTrue: [
		^ presentBlock value: (manualMergeMirrorIfFail: failBlock)].
	currentSelection =  #ourSource ifTrue: [
		^ presentBlock value: treeDiff right].
	currentSelection =  #theirSource ifTrue: [
		^ presentBlock value: treeDiff left].
	currentSelection =  #commonAncestorSource ifTrue: [
		^ presentBlock value: treeDiff ancestor].
	failBlock value: 'Unknown side'
)
mirrorMergeSubjects = (

	^ {classes. instanceMethods. classMethods}
)
textMergeSubjects = (

	^ {category. accessModifier. name. constructor. superclassClause. classComment. slotsSource. initExpressions}
)
unequalClassMethodSubjects = (

	^ classMethods reject: [:each | each treeDiff isEquals]
)
unequalClassSubjects = (

	^ classes reject: [:each | each treeDiff isEquals]
)
unequalInstanceMethodSubjects = (

	^ instanceMethods reject: [:each | each treeDiff isEquals]
)) : ('as yet unclassified'
diffSubjectOn: treeDiff = (
	^ onModel: treeDiff withMode: #diff
)
mergeSubjectOn: treeDiff = (

	^ onModel: treeDiff withMode: #merge
)
onModel: treeDiff withMode: mode = (

	^(treeDiff anyNode isPackageMirror 
		ifTrue: [PackageMirrorMergeSubject]
		ifFalse: [ClassMirrorMergeSubject])
			onModel: {treeDiff. mode. nil}
))
class ExtendedClassMirrorMergePresenter onSubject: subject = MirrorMergePresenter onSubject: subject (|
	toggle
	headerHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	toggle collapse.
	updateHolders.
)
classHeadingLabeled: labels = (

	^ (h3: (row: labels)) width: 0 elasticity: 1
)
definition = (

	headerHolder:: holder: nil.
	updateHolders.
	toggle::
		heading: [headerHolder]
		details: [detailsDefinition]
		initiallyExpanded: subject interestingChange .

	^(row: {
		toggle width: 0 elasticity: 1.
		columnSeparator}) color: backgroundColor.
)
detailsDefinition = (

	| subjects |
	^ column: {
		subject name presenter.
		sortedPresenters: subject unequalInstanceMethodSubjects
			labeledIfNotEmpty: 'Instance methods'.
		sortedPresenters: subject unequalClassMethodSubjects
			labeledIfNotEmpty: 'Class methods'}
)
headingForSide: side labeled: sideLabel = (
	
	^ classHeadingLabeled: {
		(label: headingLabel asText allBold) color: (colorIndicatingSelectionStatusForSide: side).
		label: ' [', sideLabel, ']'.
		smallBlank.
		linkToSelectSide: side.
		filler.
		(side = #ourSource)
			ifTrue: [revertSourceLink]
			ifFalse: [nothing]}
)
revertSourceLink = (

	^ (subject isMerge not and: [subject canLoadTheirs])
		ifTrue: [
				link: 'revert' action: [
					refreshSCAfter: [subject loadTheirs]]]
		ifFalse: [nothing]
)
sortedPresenters: presenters  labeledIfNotEmpty: label = (

	^ presenters isEmpty
		ifTrue: [nothing]
		ifFalse: [
			column: {
				(padded: (label: label) with: {10. 0. 0. 0.}) color: minorHeadingColor.
				sortedPresenters: presenters}]	
)
sortedPresenters: subjects = (

	^ column: ((subjects asSortedCollection: [:a :b | a sortKey asString < b sortKey asString])
		collect: [:each | each presenter])
)
updateHolders = (

	headerHolder content: headingDefinition
))
class ExtendedClassMirrorMergeSubject onModel: model <TreeDiff> = MirrorMergeSubject onModel: model (""|

name = textMergeSubjectFor: #name title: 'Name'.
instanceMethods = create: MethodMirrorMergeSubject for: #instanceMethods.
classMethods = create: MethodMirrorMergeSubject for: #classMethods.
|)
('as yet unclassified'
canLoadTheirs = (

	^false
)
create: klass for: nodeType = (

	^ Delay computation: [
		| treeDiffs |
		treeDiffs:: treeDiff children select: [:each | each nodeType = nodeType].
		treeDiffs collect: [:each | klass onModel: {each. mode. self}]]
)
createPresenter = (

	^ ExtendedClassMirrorMergePresenter onSubject: self
)
manualMergeMirrorIfFail: failBlock = (

	^ExtendedClassSourceMirror new
		name: name finalMerge asString;
		instanceMethods: (presentMirrorsOf: instanceMethods ifFail: failBlock);
		classMethods: (presentMirrorsOf: classMethods ifFail: failBlock);
		yourself
)
mirrorIfPresent: presentBlock ifRemoved: removedBlock ifFail: failBlock = (

	removedAfterMerge ifTrue: [^ removedBlock value].
	currentSelection =  #manualMerge ifTrue: [
		^ presentBlock value: (manualMergeMirrorIfFail: failBlock)].
	currentSelection =  #ourSource ifTrue: [
		^ presentBlock value: treeDiff right].
	currentSelection =  #theirSource ifTrue: [
		^ presentBlock value: treeDiff left].
	currentSelection =  #commonAncestorSource ifTrue: [
		^ presentBlock value: treeDiff ancestor].
	failBlock value: 'Unknown side'
)
mirrorMergeSubjects = (

	^ {instanceMethods. classMethods}
)
textMergeSubjects = (

	^ {name}
)
title = (
	^'*', super title
)
unequalClassMethodSubjects = (

	^ classMethods reject: [:each | each treeDiff isEquals]
)
unequalInstanceMethodSubjects = (

	^ instanceMethods reject: [:each | each treeDiff isEquals]
))
class MergePresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
colorIndicatingSelectionStatusForSide: side = (

	^ subject currentSelection = side 
		ifTrue: [Color black]
		ifFalse: [Color gray]
)
elasticTextDisplay: text = (

	^ (textDisplay: text) width: 0 elasticity: 1
)
headingDefinition = (
	^row: {
		headingForSide: #theirSource labeled: 'theirs'.
		halfColumnSeparator.
		ifConflict: [
			headingForSide: #commonAncestorSource labeled: 'common ancestor'].
		"link: '?' action: [self inspect]."
		halfColumnSeparator.
		headingForSide: #ourSource labeled: 'ours'}
)
headingForSide: side labeled: sideLabel = (
	
	^ (h4: (row: {
		(label: headingLabel asText allBold) color: (colorIndicatingSelectionStatusForSide: side).
		smallBlank.
		linkToSelectSide: side})) width:0 elasticity: 1
)
headingLabel = (

	subject isAddition ifTrue: [^subject title, ' was added'].
	subject isDeletion ifTrue: [^subject title, ' was removed'].
	^subject title
)
ifConflict: block = (

	^ subject isConflict
		ifTrue: block
		ifFalse: [nothing]
)
ifMerging: block = (

	^ subject isMerge
		ifTrue: block
		ifFalse: [nothing]
)
linkToSelectSide: side = (

	^ side = subject currentSelection
		ifTrue: [nothing]
		ifFalse: [
			link: 'select' action: [
				chooseSide: side]]
)
textDiffPresenterFor: merger = (

	merger anyChanged ifFalse: [^ nil].
	^ row: {
		elasticTextDisplay: merger leftOut.
		halfColumnSeparator.
		merger bothChanged
			ifTrue: [elasticTextDisplay: merger ancestorOut]
			ifFalse: [nothing].
		halfColumnSeparator.
		elasticTextDisplay: merger rightOut}.
))
class MergeSubject onModel: model = Subject onModel: model ("A merge subjects hold the state of an tree diff or text being merged or diffed
"|
	currentSelection = defaultResult.
|)
('as yet unclassified'
childChoseSide: side = (

	currentSelection = side ifFalse: [
		currentSelection: #manualMerge].
	nil = parentSubject ifFalse: [
		parentSubject childChoseSide: currentSelection]
)
chooseSide: side = (

	currentSelection: side.
	childChoseSide: side
)
defaultResult = (

	subclassResponsibility
)
isChange = (

	^ (self isAddition or: [self isDeletion or: [self isEquals]]) not
)
isMerge = (

	mode = #merge ifTrue: [^true].
	mode = #diff ifTrue: [^false].
	halt.
)
mergeModel = (

	^ model first
)
mode = (

	^ model second
)
parentSubject = (

	^ model third
))
class MethodMirrorMergePresenter onSubject: subject = MirrorMergePresenter onSubject: subject (|


|)
('as yet unclassified'
definition = (

	"Don't show the category unless it was actually changed"
	^ subject category isChange
		ifFalse: [subject mergedSource presenter]
		ifTrue: [column: {
			subject category presenter.
			subject mergedSource presenter}]
))
class MethodMirrorMergeSubject onModel: model <TreeDiff> = MirrorMergeSubject onModel: model (|
mergedSource = textMergeSubjectFor: #source title: title verificationBlock: [:source :failBlock | createMirrorFrom: source ifFail: failBlock].
category = textMergeSubjectFor: #category title: 'Category of ', title.
cachedMirror

|)
('as yet unclassified'
createMirrorFrom: source ifFail: failBlock = (

	| newMirror |
	
	newMirror::  sourceMirrors
		methodMirrorForStream: source asString readStream
		ifError: failBlock.
	newMirror category: category finalMerge asString.
	^ newMirror
)
createPresenter = (

	^ MethodMirrorMergePresenter onSubject: self
)
mirrorIfPresent: presentBlock ifRemoved: removedBlock ifFail: failBlock = (

	removedAfterMerge ifTrue: [^ removedBlock value].
	cachedMirror ifNil: [
		cachedMirror:: createMirrorFrom: mergedSource finalMerge ifFail: failBlock].
	presentBlock value: cachedMirror
)
removedAfterMerge = (

	^ mergedSource finalMerge isEmpty
)
textMergeSubjects = (

	^ {mergedSource. category}
)
title = (

	^ super title
))
class MirrorMergePresenter onSubject: subject = MergePresenter onSubject: subject (|
	
|)
()
class MirrorMergeSubject onModel: model <TreeDiff> = MergeSubject onModel: model (|

|)
('as yet unclassified'
defaultResult = (

	treeDiff changeInfo isEquals ifTrue: [
		^ #ourSource].
	treeDiff changeInfo isLeft ifTrue: [
		^ #theirSource].
	treeDiff changeInfo isRight ifTrue: [
		^ #ourSource].
	^ #manualMerge
)
interestingChange = (

	"I this a change that should be shown by default?"
	^ (isEquals or: [
		isAddition or: [
			isDeletion or: [
				(isMerge and: [treeDiff changeInfo isRight])
					or: ["Hide top-level classes in general unless we're merging"
						isMerge not and: [treeDiff anyNode isToplevel]]]]]) not
)
isAddition = (

	^ treeDiff changeInfo isAddition
)
isConflict = (

	^ treeDiff changeInfo isConflict
)
isDeletion = (

	^ treeDiff changeInfo isDeletion
)
isEquals = (

	^ treeDiff isEquals
)
mirrorMergeSubjects = (

	^ {}
)
removedAfterMerge = (

	currentSelection = #manualMerge ifTrue: [
		^ false].
	currentSelection = #ourSource ifTrue: [
		^ nil = treeDiff right].
	currentSelection = #theirSource ifTrue: [
		^ nil = treeDiff left].
	currentSelection = #commonAncestorSource ifTrue: [
		^ nil = treeDiff ancestor].
	error: 'unknown selection'
)
sortKey = (

	^ {treeDiff nodeType. treeDiff name}
)
textMergeSubjectFor: selector = (

	^ textMergeSubjectFor: selector title: selector
)
textMergeSubjectFor: selector title: title = (

	^ textMergeSubjectFor: selector title: title verificationBlock: nil 
)
textMergeSubjectFor: selector title: title verificationBlock: verificationBlock = (

	^ Delay computation: [
		| lar wordMerger |
		lar:: treeDiff leftAncestorRightCollect: [:each | each perform: selector].
		wordMerger:: WordMerger on: lar.
		(TextMergeSubject onModel: {wordMerger. mode. self})
			title: title;
			verificationBlock: verificationBlock;
			yourself]
)
textMergeSubjects = (

	^ {}
)
title = (

	^ treeDiff name
)
treeDiff = (

	^ mergeModel
))
class PackageMirrorMergePresenter onSubject: subject = MirrorMergePresenter onSubject: subject (|
	toggle
	headerHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	toggle collapse.
	updateHolders.
)
classHeadingLabeled: labels = (

	^ (h3: (row: labels)) width: 0 elasticity: 1
)
definition = (

	headerHolder:: holder: nil.
	updateHolders.
	toggle::
		heading: [headerHolder]
		details: [detailsDefinition]
		initiallyExpanded: subject interestingChange .

	^(row: {
		toggle width: 0 elasticity: 1.
		columnSeparator}) color: backgroundColor.
)
detailsDefinition = (

	| subjects |
	^ column: {
		subject name presenter.
		sortedPresenters: subject unequalClassSubjects.
		sortedPresenters: subject unequalExtendedClassSubjects.
	}
)
headingForSide: side labeled: sideLabel = (
	
	^ classHeadingLabeled: {
		(label: headingLabel asText allBold) color: (colorIndicatingSelectionStatusForSide: side).
		label: ' [', sideLabel, ']'.
		smallBlank.
		linkToSelectSide: side.
		filler.
		(side = #ourSource)
			ifTrue: [revertSourceLink]
			ifFalse: [nothing]}
)
revertSourceLink = (

	^ (subject isMerge not and: [subject canLoadTheirs])
		ifTrue: [
				link: 'revert' action: [
					refreshSCAfter: [subject loadTheirs]]]
		ifFalse: [nothing]
)
sortedPresenters: presenters  labeledIfNotEmpty: label = (

	^ presenters isEmpty
		ifTrue: [nothing]
		ifFalse: [
			column: {
				(padded: (label: label) with: {10. 0. 0. 0.}) color: minorHeadingColor.
				sortedPresenters: presenters}]	
)
sortedPresenters: subjects = (

	^ column: ((subjects asSortedCollection: [:a :b | a sortKey asString < b sortKey asString])
		collect: [:each | each presenter])
)
updateHolders = (

	headerHolder content: headingDefinition
))
class PackageMirrorMergeSubject onModel: model <TreeDiff> = MirrorMergeSubject onModel: model (""|

name = textMergeSubjectFor: #name title: 'Name'.
classes = create: SmalltalkClassMirrorMergeSubject for: #classes.
extendedClasses = create: ExtendedClassMirrorMergeSubject for: #extendedClasses.

|)
('as yet unclassified'
canLoadTheirs = (
	^true
)
create: klass for: nodeType = (

	^ Delay computation: [
		| treeDiffs |
		treeDiffs:: treeDiff children select: [:each | each nodeType = nodeType].
		treeDiffs collect: [:each | klass onModel: {each. mode. self}]]
)
createPresenter = (

	^ PackageMirrorMergePresenter onSubject: self
)
loadTheirs = (

	treeDiff left installAsToplevelClass.
)
manualMergeMirrorIfFail: failBlock = (

	^ SmalltalkPackageSourceMirror new
		name: name finalMerge asString;
		classes: (presentMirrorsOf: classes ifFail: failBlock);
		extendedClasses: (presentMirrorsOf: extendedClasses ifFail: failBlock);
		yourself
)
mirrorIfPresent: presentBlock ifRemoved: removedBlock ifFail: failBlock = (

	removedAfterMerge ifTrue: [^ removedBlock value].
	currentSelection =  #manualMerge ifTrue: [
		^ presentBlock value: (manualMergeMirrorIfFail: failBlock)].
	currentSelection =  #ourSource ifTrue: [
		^ presentBlock value: treeDiff right].
	currentSelection =  #theirSource ifTrue: [
		^ presentBlock value: treeDiff left].
	currentSelection =  #commonAncestorSource ifTrue: [
		^ presentBlock value: treeDiff ancestor].
	failBlock value: 'Unknown side'
)
mirrorMergeSubjects = (

	^ {classes. extendedClasses}
)
textMergeSubjects = (

	^ {name}
)
unequalClassSubjects = (

	^ classes reject: [:each | each treeDiff isEquals]
)
unequalExtendedClassSubjects = (

	^ extendedClasses reject: [:each | each treeDiff isEquals]
))
class SmalltalkClassMirrorMergePresenter onSubject: subject = MirrorMergePresenter onSubject: subject (|
	toggle
	headerHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	toggle collapse.
	updateHolders.
)
classHeadingLabeled: labels = (

	^ (h3: (row: labels)) width: 0 elasticity: 1
)
definition = (

	headerHolder:: holder: nil.
	updateHolders.
	toggle::
		heading: [headerHolder]
		details: [detailsDefinition]
		initiallyExpanded: subject interestingChange .

	^(row: {
		toggle width: 0 elasticity: 1.
		columnSeparator}) color: backgroundColor.
)
detailsDefinition = (

	| subjects |
	^ column: {
		subject category presenter.
		subject name presenter.
		subject superclassName presenter.
		subject classComment presenter.
		subject instanceVariables presenter.
		subject classInstanceVariables presenter.

		sortedPresenters: subject unequalInstanceMethodSubjects
			labeledIfNotEmpty: 'Instance methods'.
		sortedPresenters: subject unequalClassMethodSubjects
			labeledIfNotEmpty: 'Class methods'}
)
headingForSide: side labeled: sideLabel = (
	
	^ classHeadingLabeled: {
		(label: headingLabel asText allBold) color: (colorIndicatingSelectionStatusForSide: side).
		label: ' [', sideLabel, ']'.
		smallBlank.
		linkToSelectSide: side.
		filler.
		(side = #ourSource)
			ifTrue: [revertSourceLink]
			ifFalse: [nothing]}
)
revertSourceLink = (

	^ (subject isMerge not and: [subject canLoadTheirs])
		ifTrue: [
				link: 'revert' action: [
					refreshSCAfter: [subject loadTheirs]]]
		ifFalse: [nothing]
)
sortedPresenters: presenters  labeledIfNotEmpty: label = (

	^ presenters isEmpty
		ifTrue: [nothing]
		ifFalse: [
			column: {
				(padded: (label: label) with: {10. 0. 0. 0.}) color: minorHeadingColor.
				sortedPresenters: presenters}]	
)
sortedPresenters: subjects = (

	^ column: ((subjects asSortedCollection: [:a :b | a sortKey asString < b sortKey asString])
		collect: [:each | each presenter])
)
updateHolders = (

	headerHolder content: headingDefinition
))
class SmalltalkClassMirrorMergeSubject onModel: model <TreeDiff> = MirrorMergeSubject onModel: model (""|
category = textMergeSubjectFor: #category title: 'Category'.
name = textMergeSubjectFor: #name title: 'Name'.
superclassName = textMergeSubjectFor: #superclassName title: 'Superclass'.
classComment = textMergeSubjectFor: #classComment title: 'Comment'.

instanceVariables = textMergeSubjectFor: #instanceVariablesString title: 'Instance Variables'.
classInstanceVariables = textMergeSubjectFor: #classInstanceVariablesString title: 'Class Instance Variables'.
classPoolVariables = textMergeSubjectFor: #classPoolVariablesString title: 'Class Pool Variables'.
sharedPoolVariables = textMergeSubjectFor: #sharedPoolVariablesString title: 'Shared Pool Variables'.

instanceMethods = create: MethodMirrorMergeSubject for: #instanceMethods.
classMethods = create: MethodMirrorMergeSubject for: #classMethods.
|)
('as yet unclassified'
canLoadTheirs = (

	^true
)
create: klass for: nodeType = (

	^ Delay computation: [
		| treeDiffs |
		treeDiffs:: treeDiff children select: [:each | each nodeType = nodeType].
		treeDiffs collect: [:each | klass onModel: {each. mode. self}]]
)
createPresenter = (

	^ SmalltalkClassMirrorMergePresenter onSubject: self
)
manualMergeMirrorIfFail: failBlock = (

	^SmalltalkClassSourceMirror new
		category: category finalMerge asString;
		name: name finalMerge asString;
		superclassName: superclassName finalMerge asString;
		classComment: classComment finalMerge asString;
		instanceVariables: instanceVariables finalMerge asString;
		classInstanceVariables: classInstanceVariables finalMerge asString;
		classPoolVariables: classPoolVariables finalMerge asString;
		sharedPoolVariables: sharedPoolVariables finalMerge asString;
		instanceMethods: (presentMirrorsOf: instanceMethods ifFail: failBlock);
		classMethods: (presentMirrorsOf: classMethods ifFail: failBlock);
		yourself
)
mirrorIfPresent: presentBlock ifRemoved: removedBlock ifFail: failBlock = (

	removedAfterMerge ifTrue: [^ removedBlock value].
	currentSelection =  #manualMerge ifTrue: [
		^ presentBlock value: (manualMergeMirrorIfFail: failBlock)].
	currentSelection =  #ourSource ifTrue: [
		^ presentBlock value: treeDiff right].
	currentSelection =  #theirSource ifTrue: [
		^ presentBlock value: treeDiff left].
	currentSelection =  #commonAncestorSource ifTrue: [
		^ presentBlock value: treeDiff ancestor].
	failBlock value: 'Unknown side'
)
mirrorMergeSubjects = (

	^ {instanceMethods. classMethods}
)
textMergeSubjects = (

	^ {category. name. superclassName. classComment. instanceVariables. classInstanceVariables. classPoolVariables . sharedPoolVariables }
)
unequalClassMethodSubjects = (

	^ classMethods reject: [:each | each treeDiff isEquals]
)
unequalInstanceMethodSubjects = (

	^ instanceMethods reject: [:each | each treeDiff isEquals]
))
class TextMergePresenter onSubject: subject = MergePresenter onSubject: subject (|
theToggle
theHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	updateHolders.
	theToggle collapse
)
definition = (

	subject isEquals
		ifTrue: [^ nothing].
	theHolder:: holder: nil. 
	updateHolders.
	subject isMerge ifTrue: [
		"Don't show our changes by default"
		subject currentSelection = #ourSource ifTrue: [
			theToggle collapse]].
	^ theHolder
)
details = (

	^ column: {
		textDiffPresenterFor: subject merger.
		ifMerging: [manualMergeEditor]}
)
manualMergeEditor = (

	^
		heading: [
			row: {
				(label: 'Manual merge') color: (colorIndicatingSelectionStatusForSide: #manualMerge).
				smallBlank.
				linkToSelectSide: #manualMerge}]
		details: [mergeEditor]
		initiallyExpanded: subject currentSelection = #manualMerge.
)
mergeEditor  = (

	| editor |

	editor:: TextEditorFragment new
		text: subject manualMergeResult;
		acceptResponse: [ | failed |
			failed:: false.
			subject
				storeManualMerge: editor textBeingAccepted
				ifFail: [:msg :pos |
					failed:: true.
					editor showMessage: msg].
			failed ifFalse: [editor defaultAcceptResponse]].
	^ editor
)
updateHolders = (

	theToggle:: heading: [headingDefinition]
					detailsExpanded: [details].
	theHolder content: (
		column: {
			row: {
				theToggle width: 0 elasticity: 1.
				columnSeparator}})
))
class TextMergeSubject onModel: model = MergeSubject onModel: model (|
	title
	manualMergeResult = merger automaticMergedOut.
	verificationBlock
|)
('as yet unclassified'
createPresenter = (

	^ TextMergePresenter onSubject: self
)
defaultResult = (

	merger anyChanged ifFalse: [
		^ #commonAncestorSource].
	merger rightChanged ifTrue: [
		^ #ourSource].
	merger leftChanged ifTrue: [
		^ #theirSource].
	^ #manualMerge
)
finalMerge = (

	currentSelection =  #manualMerge ifTrue: [
		storeManualMerge: manualMergeResult ifFail: [halt].
		^ manualMergeResult].
	currentSelection =  #ourSource ifTrue: [
		^ merger rightOut].
	currentSelection =  #theirSource ifTrue: [
		^ merger leftOut].
	currentSelection =  #commonAncestorSource ifTrue: [
		^ merger ancestorOut].
	error: 'unknown side'
)
isAddition = (

	^ merger isAddition
)
isConflict = (

	^ merger bothChanged
)
isDeletion = (

	^ merger isDeletion
)
isEquals = (

	^ merger anyChanged not
)
merger = (

	^ mergeModel
)
storeManualMerge: mergeResult ifFail: failBlock = (

	verificationBlock = nil ifFalse: [
		verificationBlock value: mergeResult value: failBlock].
	manualMergeResult:: mergeResult.
))'accessing'
blank: size color: color = (
	^(ColumnComposer definitions: {RowComposer definitions: {BlankFragment size: size}}) color: color
)
vblank: size color: color = (
	^(RowComposer definitions: {ColumnComposer definitions: {BlankFragment size: size}}) color: color
)'private'
presentMirrorsOf: mergeSubjects ifFail: failBlock = (

	| survivingElements |
	^ Array streamContents: [:stream |
		mergeSubjects do: [:each |
			each
				mirrorIfPresent: [:it | stream nextPut: it]
				ifRemoved: []
				ifFail: failBlock]]
))
class Presenters = ()
(
class CurrentLocalHistorianPresenter onSubject: subject = LocalHistorianPresenter onSubject: subject (|
|)
('as yet unclassified'
arrangeContent = (

	^ column: {
		heading.
		details
		}
)
heading = (

	^ super heading
))
class HistorianRelationPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
definition = (

	^ column: {
		h4: (subject runActionOn: self).
		IncomingOutgoingPresenter onSubject: subject}
)
forwardOther = (

	^ link: 'Forward ', otherHistorianAndRepositoryName
		action: [
			refreshSCAfter: [subject forwardOtherHistorian]]
)
forwardToOther = (

	^ link: 'Forward to ', otherHistorianAndRepositoryName
		action: [
			refreshSCAfter: [subject forwardToOtherHistorian]]
)
inSynch = (

	^ (label: 'In sync with ', otherHistorianAndRepositoryName) color: Color gray
)
merge = (

	"Allow merging only into image historian"
	subject historianIsImageHistorian ifTrue: [
		^ link: 'Merge from ', otherHistorianAndRepositoryName
		action: [
			sendUp repositoryEnterSubject:
				subject mergeFromOtherHistorianSubject]].
	subject otherHistorianIsImageHistorian ifTrue: [
		^ link: 'Merge into ', otherHistorianAndRepositoryName
		action: [
			sendUp repositoryEnterSubject:
				subject mergeIntoOtherHistorianSubject]].
	^ (label: 'Out of sync') color: Color gray
)
otherHistorianAndRepositoryName = (

	^ subject otherHistorianAndRepositoryName
))
class ImageBasedChangePresenter onSubject: subject = BasePresenter onSubject: subject (|
commitFragmentHolder
definitionHolder
|)
('as yet unclassified'
beforeCommitFragment = (

	^ h2: (row: {
			smallBlank.
			label: 'Modified in Image' asText allBold.
			filler.
			link: 'revert' action: [
				refreshSCAfter: [subject revertImage]].
			smallBlank.
			link: 'commit'
				action: [commitFragmentHolder content: commitFragment]}).
)
cleanDefinition = (

	^ column: {
		h2:: row: {smallBlank. label: 'No Changes in Image' asText allBold. filler}.
		unversionedClassesPresenter}
)
commitFragment = (

	^ column: {
		h2: (row: {
			label: ('Commit to ', subject historianName) asText allBold}).
		TextEditorFragment new
			text: 'Enter Commit Message ...';
			acceptResponse: [:editor |
				editor defaultAcceptResponse.
				refreshSCAfter: [subject commit: editor text asString]];
			cancelResponse: [:editor |
				editor defaultCancelResponse.
				commitFragmentHolder content: beforeCommitFragment]}
)
definition = (

	definitionHolder:: holder: [definitionHolderContents].
	^ definitionHolder
)
definitionHolderContents = (

	^ column: {
		subject hasChanges
			ifTrue: [dirtyDefinition]
			ifFalse: [cleanDefinition]}
)
dirtyDefinition = (

	commitFragmentHolder:: holder: beforeCommitFragment.
	^ column: {
		commitFragmentHolder.
		unversionedClassesPresenter.
		hackStoreMergeHeader.
		column: (subject changedDiffSubjects collect: [:each | each presenter])}
)
hackStoreMergeHeader = (

	"As long as we have not implemented stores and store diffs, use this to show the header that would usually be displayed by the StoreMergePresenter"
	^row: {
	BlankFragment size: 13.
		(h2: (label: 'Historian' asText allBold)) width: 0 elasticity: 1.
		BlankFragment size: 12.
		(h2: (label: 'Image' asText allBold)) width: 0 elasticity: 1.
		BlankFragment size: 12}
)
linkForLog: showLog = (

	^ showLog
		ifTrue: [link: 'Log' action: [
					changesOrLogHolder content: subject logSubject presenter.
					changesOrLogLinkHolder contents: (linkForLog: showLog not)]]
		ifFalse: [link: 'Changes' action: [
					changesOrLogHolder content: changesPresenter.
					changesOrLogLinkHolder contents: (linkForLog: showLog not)]]
)
refreshImageBasedChangePresenter = (

	definitionHolder content: definitionHolderContents.
)
unversionedClassesPresenter = (

	^ UnversionedClassesPresenter onSubject: subject.
))
class IncomingOutgoingPresenter onSubject: subject = BasePresenter onSubject: subject (|
	cachedPresenters
|)
('as yet unclassified'
definition = (

	^ column: presenters
)
ifNotEmptyStreamPresentersFor: subjects labeled: label to: stream = (

	^ subjects isEmpty ifFalse: [
		stream nextPut: (column: {
			h4: (label: label).
			listPresentersOf: subjects inIncrementsOf: 25})]
)
isEmpty = (

	^ presenters isEmpty
)
presenters = (

	^Array streamContents: [:stream |
		self
			ifNotEmptyStreamPresentersFor: subject incomingVersionSubjects
			labeled: 'Coming in from ', subject otherHistorianAndRepositoryName
			to: stream.
		self
			ifNotEmptyStreamPresentersFor: subject outgoingVersionSubjects
			labeled: 'Going out to ', subject otherHistorianAndRepositoryName
			to: stream]
))
class LocalHistorianPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
(
class ChooseShareDestinationPresenter onSubject: subject = BasePresenter onSubject: subject ()
('as yet unclassified'
definition = (

	^link: 'share' action: [showMenu]
)
shareActionFor: action = (

	^ [ refreshSCAfter: [action value]]
)
shareMenu = (

	| menu |
	menu:: Menu forVisual: visual.
	subject shareNamesAndActions do:
		[:each |
		menu add: 
			(MenuItem 
				label: each first
				action: (shareActionFor: each second))].
	^menu
)
showMenu = (

	openMenu: shareMenu
)
viewerDefinition = (

	^link: 'share' action: [showMenu]
))
class EditableClonePresenter onSubject: s = EditableLinePresenter onSubject: s (|
|)
('as yet unclassified'
definitionText = (

	^ 'enter name'
)
respondToAccept = (

	sendUp refreshSCAfter: [
		cloneAs: editor text asString ifFail: [
			"We could show a error message somehow"
			^ self].
		leaveEditState]
)
viewerDefinition = (

	^ (link: 'clone' asText action: [enterEditState])
))'as yet unclassified'
actionCloneHistorian = (

	^ EditableClonePresenter onSubject: subject
)
actionDeleteHistorian = (

	^
		imageButton: {
			HopscotchImages default cancel16px.
			HopscotchImages default cancel16pxOver.
			HopscotchImages default cancel16pxDown}
		action: [
			refreshSCAfter: [subject deleteHistorianIfFail: [unexpected]]]
)
actionLoadHistorian = (

	^ subject isImageHistorian
		ifTrue: [
			nothing]
		ifFalse: [
			link: 'load'
				action: [
					refreshSCAfter: [subject loadIntoImage]]]
)
actionShareHistorian = (

	^ subject trackedHistorianAccessor isTracking
		ifTrue: [nothing]
		ifFalse: [ChooseShareDestinationPresenter onSubject: subject]
)
arrangeContent = (

	"Can be arranged differently in subclass"
	^ self
		heading: heading
		details: details
)
cloneAs: forkName ifFail: failBlock = (

	^ subject cloneAs: forkName ifFail: failBlock.
)
definition = (

	| resultHolder |
	resultHolder:: holder: (label: 'synching ...').
	forkAndRemember: [
		resultHolder content: arrangeContent].
	^ resultHolder
)
details = (

	^ column: {
		infoTrackedHistorian.
		column: (subject historianRelationSubjects collect: [:each |
					each presenter])}
)
heading = (

	^ h3: (
		row: {
			smallBlank.
			label: subject name.
			filler.
			row: links})
)
infoTrackedHistorian = (

	^ subject trackedHistorianAccessor errorAccessingTrackingHistorian
		ifTrue: [(label: 'Cannot access tracked historian') color: Color red]
		ifFalse: [nothing]
)
links = (

	^ {actionLoadHistorian.
		smallBlank.
		actionCloneHistorian.
		smallBlank.
		actionShareHistorian.
		smallBlank.
		actionDeleteHistorian.}
))
class LocalRepositoryPresenter onSubject: subject = BasePresenter onSubject: subject (|
deferredContent = holder: nothing.
changesNotification
messagesContainer
inspectionHolder
statusOrLogHolder
statusOrLogLinkHolder
|)
('as yet unclassified'
actualDefinition = (

	messagesContainer:: OrderedCollection new.
	statusOrLogLinkHolder:: holder: (linkForLog: true).
	statusOrLogHolder:: holder: repositoryStatusPresenter.
	
	^column: {
		h1:: row: {
			presentTitle.
			filler.
			statusOrLogLinkHolder}.
		statusOrLogHolder
	}
)
definition = (
	^deferredContent
)
linkForLog: showLog = (

	^ showLog
		ifTrue: [link: 'Log' action: [
					statusOrLogHolder content: subject logSubject presenter.
					statusOrLogLinkHolder content: (linkForLog: showLog not)]]
		ifFalse: [link: 'Status' action: [
					statusOrLogHolder content: repositoryStatusPresenter.
					statusOrLogLinkHolder content: (linkForLog: showLog not)]]
)
noticeImminentExposure = (
	refreshSCAfter: []
)
presentAge = (
	"subject isRecent ifTrue: [
		^(link: '[active]' action: [confirm: 'New version published to server within the last week.' ifConfirmed:[]]) tinyFont color: Color gray
		].
	subject isOld ifTrue: [
		^(link: '[dormant]' action: [confirm: 'Latest published version is more than 30 days old.' ifConfirmed:[]]) tinyFont color: Color gray
		]."
	^label: ''
)
presentLocalHistorians = (

	| localHistorianSubjects |
	localHistorianSubjects:: subject localHistorianSubjects.
	^ column: {
		h2:( row: {
			label: 'Current Local Historian' asText allBold.
			filler}).
		CurrentLocalHistorianPresenter onSubject: (localHistorianSubjects detect: [:each | each isImageHistorian]).
		h2:( row: {
			label: 'Other Local Historians' asText allBold.
			filler}).
		list: ((localHistorianSubjects reject: [:each | each isImageHistorian]) collect: [:each | each presenter])}
)
presentModifiedInImage = (

	^ subject modifiedInImageSubject presenter
)
presentRemoteRepositories = (

	^ column: {
		h2:( row: {
			label: 'Remote Repositories' asText allBold.
			filler}).
		list: (subject remoteRepositorySubjects collect: [:each |
			each presenter])}
)
presentTitle = (

	| prefix repositoryName |
	prefix:: 'Repository [', subject repositoryType, ']: '.
	repositoryName:: ('...', (subject repositoryName last: 16)).
	^ row: {
		label:  prefix asText. 
		label: repositoryName asText allBold
	}
)
refreshSCAfter: block = (

	deferredContent content: (label: 'performing action...') tinyFont.
	[showWaitCursorWhile: [
		block value.
		shell desktop scheduleUIAction: [deferredContent content: actualDefinition].
	]
	]forkAt: 30 named: 'Refreshing: ', subject title
)
repositoryEnterSubject: newSubject = (

	statusOrLogHolder content: newSubject presenter.
	statusOrLogLinkHolder content: nothing.
)
repositoryStatusPresenter = (

	^ column: {
		presentModifiedInImage.
		presentLocalHistorians.
		presentRemoteRepositories}
))
class LogPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
definition = (

	^ listPresentersOf: subject versions  inIncrementsOf: 25
))
class MergeHistorianPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
definition = (

	| unequalMergeSubjects |
	unequalMergeSubjects:: subject mergeSubjects reject: [:each | each isEquals].
	^ column: {
		h1: (row: {
			label: 'Merge ', subject mergeSourceName, ' into ', subject mergeDestinationName.
			filler.
			link: 'Commit Merge' action: [
				refreshSCAfter: [
					subject mergeIfFail: [halt]]]}).
		column: (unequalMergeSubjects	collect: [:each | each presenter])}
))
class RemoteHistorianPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
definition = (

	^ h4: (
			row: {
				smallBlank.
				label: subject name.
				filler.
				row: links})
)
links = (

	^ {
		subject isTracked
			ifTrue: [(label: 'is tracked') color: Color gray]
			ifFalse: [link: 'track' action: [
					refreshSCAfter: [subject trackAs: subject name]]]}
))
class RemoteRepositoryPresenter onSubject: subject = BasePresenter onSubject: subject (|
	|)
('as yet unclassified'
deferredHistorianPresenters = (
"
	| historianPresentersHolder |
	historianPresentersHolder:: holder: ((label: 'synching ...') color: Color gray).
	forkAndRemember: [historianPresentersHolder content: (column: historianPresenters)].
	^ historianPresentersHolder"
	"There is some problem with forking. See deferredActionTrackedHistorian"
	^ initially: (label: 'synching ...') deferred: [column: historianPresenters]
)
definition = (

	^ heading: (h3: (label: subject name))
	details: deferredHistorianPresenters
)
historianPresenters = (

	^ subject historianSubjects collect: [:each | each presenter]
))
class SourceControlPresenter onSubject: subject = BasePresenter onSubject: subject (|
"helpHolder
status
deferredContent
inspectionHolder
modifiedList
updatedList"
addHolder
reposHolder
|)
('as yet unclassified'
createLocalHgRepoAt: relPath <String> = (

	| path hg uiusername repository |

	#BOGUS. "This logic belongs somewhere else!"

	path:: ((FileDirectory on: SmalltalkImage current imagePath) / relPath) pathName.

	hg:: ExternalLauncher for: 'hg'.
	hg otherUnixLocations: {'/opt/local/bin'. '/usr/local/bin'}.
	hg otherWindowsLocations: {'c:\cygwin\bin'}.

	"hg init path"
	hg 
		runWith: {'init'. path} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].

	uiusername:: UIManager default
			request: 'Please provide your Mercurial username'
			initialAnswer: 'Full Name <email@company.com>'.

	"setup hgrc"
	(FileStream forceNewFileNamed: ((FileDirectory on: path) / '.hg' / 'hgrc') pathName) nextPutAll: 
'[ui]
username=',uiusername,'
[extensions]
bookmarks=
[newspeak]
current_historian=main
'; flush; close.

	""
	(FileStream forceNewFileNamed: ((FileDirectory on: path) / '.hgignore') pathName)
		flush; close. 

	hg 
		runWith: {'--cwd'. path. 'bookmark'. 'main'} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].

	hg 
		runWith: {'--cwd'. path. 'add'. '.hgignore'} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].
	
	hg 
		runWith: {'--cwd'. path. 'commit'. '-m'. 'Initial commit.'} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].

	repository:: vcs hg Backend new LocalRepository onRepositoryId: path.

	subject model add: repository.
	self refresh.
)
definition = (

	^column: {
		majorHeadingBlock: (row: {
			label: 'MemoryHole Repositories' asText allBold.
			filler.
			addButtonWithAction: [addHolder content: presentAddRepositories].
		}).
		mediumBlank.
		addHolder:: holder: nothing.
		reposHolder:: holder: [presentRepositories].
	}
)
openLocalHgRepoAt: path = (

	| repository |

	repository:: vcs hg Backend new LocalRepository onRepositoryId:
		((FileDirectory on: SmalltalkImage current imagePath) / path) pathName.

	subject model add: repository.
	self refresh.
)
openRemoteHgRepoAt: url <String> = (

	| path hg uiusername username password repository |

	assert: [url startsWith: 'https://'] message: 'Convient support for https only at the moment.  Setup ssh yourself.'.

	path:: url copyFrom: (url lastIndexOf: $/)+1 to: url size.
	path:: ((FileDirectory on: SmalltalkImage current imagePath) / path) pathName.

	hg:: ExternalLauncher for: 'hg'.
	hg otherUnixLocations: {'/opt/local/bin'. '/usr/local/bin'}.
	hg otherWindowsLocations: {'c:\cygwin\bin'}.

	"hg init path"
	hg 
		runWith: {'init'. path} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].

	uiusername:: UIManager default
			request: 'Please provide your Mercurial username'
			initialAnswer: 'Full Name <email@company.com>'.

	username:: UIManager default
			request: 'Please provide your BitBucket, etc username'
			initialAnswer: 'wsmith'.

	password:: UIManager default
			request: 'Please provide your BitBucket, etc password'
			initialAnswer: 'downwithbigbrother'.

	"setup hgrc"
	(FileStream forceNewFileNamed: ((FileDirectory on: path) / '.hg' / 'hgrc') pathName) nextPutAll: 
'[paths]
default=',url,'
[ui]
username=',uiusername,'
[extensions]
bookmarks=
[auth]
bb1.schemes=https
bb1.prefex=',url,'
bb1.password=',password,'
bb1.username=',username,'
[hostfingerprints]
bitbucket.org=81:2b:08:90:dc:d3:71:ee:e0:7c:b4:75:ce:9b:6c:48:94:56:a1:fe
[newspeak]
current_historian=main
[newspeak_tracking_historian]
main=main
[newspeak_tracking_repository]
main=',url,'
'; flush; close.

	"hg --cwd path pull -B"
	hg 
		runWith: {'--cwd'. path. 'pull'. '-B'. 'main'} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].
	
	hg 
		runWith: {'--cwd'. path. 'update'.} 
		ifSuccess: [:stdout :stderr | ] 
		ifFailure: [:stdout :stderr | self error: stderr contents].

	repository:: vcs hg Backend new LocalRepository onRepositoryId: path.

	subject model add: repository.
	self refresh.
)
presentAddRepositories = (
	^column: {
		row: {
			label: 'Clone and open remote Mercurial repository at '.
			TextEditorFragment new
				text: 'https://bitbucket.org/username/repository';
				acceptResponse: [:editor | 
					editor defaultAcceptResponse.
					openRemoteHgRepoAt: editor text asString.
					addHolder content: nothing].
		}.
		row: {
			label: 'Open local Mercurial repository at '.
			TextEditorFragment new
				text: 'path/relativeTo/imageDirectory';
				acceptResponse: [:editor | 
					editor defaultAcceptResponse.
					openLocalHgRepoAt: editor text asString.
					addHolder content: nothing].
		}.
		row: {
			label: 'Create new local Mercurial repository at '.
			TextEditorFragment new
				text: 'path/relativeTo/imageDirectory';
				acceptResponse: [:editor | 
					editor defaultAcceptResponse.
					createLocalHgRepoAt: editor text asString.
					addHolder content: nothing].
		}.
		"row: {
			label: 'Open Git Repository at '.
			TextEditorFragment new
				text: 'relative/path';
				acceptResponse: [:editor | 
					editor defaultAcceptResponse.
					openGitRepoAt: editor text asString].
		}."
	}
)
presentDocumentation = (
	^{
		row: {
			filler.
			(link: 'close help' action: [respondToCloseHelp]) tinyFont.
		}.
		textDisplay: 'Source Control provides an overview of what changes you have made and what others have made available. TBD'.
	}
)
presentHelp = (
	^(link: '[?]' action: [respondToHelp]) tinyFont
)
presentRepositories = (
	^list: (subject modifiedLocalRepositorySubjects collect: [:ea <LocalRepositorySubject> |		
		row: {
			smallBlank.
			link: ea title action: [enterSubject: ea].
			filler.
			removeButtonWithAction: [confirm: 'Remove Repository' ifConfirmed: [subject removeRepository: ea model. self refresh]].
			smallBlank.
		}
	])
)
respondToCloseHelp = (
	helpHolder setPresenters: {}
)
respondToHelp = (
	helpHolder setPresenters: presentDocumentation
))
class TextMergePresenter onSubject: subject = MergePresenter onSubject: subject (|
theToggle
theHolder
|)
('as yet unclassified'
chooseSide: side = (

	subject chooseSide: side.
	updateHolders.
	theToggle collapse
)
definition = (

	subject isEquals
		ifTrue: [^ nothing].
	theHolder:: holder: nil. 
	updateHolders.
	subject isMerge ifTrue: [
		"Don't show our changes by default"
		subject currentSelection = #ourSource ifTrue: [
			theToggle collapse]].
	^ theHolder
)
details = (

	^ column: {
		textDiffPresenterFor: subject merger.
		ifMerging: [manualMergeEditor]}
)
manualMergeEditor = (

	^
		heading: [
			row: {
				(label: 'Manual merge') color: (colorIndicatingSelectionStatusForSide: #manualMerge).
				smallBlank.
				linkToSelectSide: #manualMerge}]
		details: [mergeEditor]
		initiallyExpanded: subject currentSelection = #manualMerge.
)
mergeEditor  = (

	| editor |

	editor:: TextEditorFragment new
		text: subject manualMergeResult;
		acceptResponse: [ | failed |
			failed:: false.
			subject
				storeManualMerge: editor textBeingAccepted
				ifFail: [:msg :pos |
					failed:: true.
					editor showMessage: msg].
			failed ifFalse: [editor defaultAcceptResponse]].
	^ editor
)
updateHolders = (

	theToggle:: heading: [headingDefinition]
					detailsExpanded: [details].
	theHolder content: (
		column: {
			row: {
				theToggle width: 0 elasticity: 1.
				columnSeparator}})
))
class UnversionedClassesPresenter onSubject: subject <ImageBasedChangeSubject> = BasePresenter onSubject: subject ("Allows adding unversioned classes to the current image based change"|
	private unversionedImageMirrors = subject unversionedImageMirrors.|)
('as yet unclassified'
definition = (

	^ unversionedImageMirrors isEmpty
		ifTrue: [nothing]
		ifFalse: [
			heading: header
			details: [column: (unversionedImageMirrors collect: [:each | mirrorEntry: each])]]
)
header = (

	^ h3: ( row: {
		label: 'Unversioned Classes'.
		largeBlank.
		link:  'Add All' action: [
			unversionedImageMirrors do: [:each | subject addMirror: each actualMirror].
			refreshImageBasedChangePresenter].
		filler})
)
mirrorEntry: mirror = (

	^ row: {
		addButtonWithAction: [
			subject addMirror: mirror actualMirror.
			refreshImageBasedChangePresenter].
		mediumBlank.
		label: mirror name}
)
refreshImageBasedChangePresenter = (

	sendUp refreshImageBasedChangePresenter
))
class VersionPresenter onSubject: subject = BasePresenter onSubject: subject (|
|)
('as yet unclassified'
definition = (

	| toggle |
	toggle:: 
		heading: (row: {
			link: subject message action: [toggle toggle].
			mediumBlank.
			(label: '[', subject author, ']') color: Color gray.
			mediumBlank.
			subject isParentOfImage
				ifTrue: [
					row: {
						label: '(current)' asText allBold.
						mediumBlank}]
				ifFalse: [nothing].
			link: 'load' action: [loadIntoImage]})
		details: [
			| unequalDiffSubjects |
			column: {
				label: subject internalId asString.
				column: (subject unequaldiffsFromPrevious collect: [:each | 
					each presenter])}].
	^ toggle
)
loadIntoImage = (

	refreshSCAfter: [subject loadIntoImage]
)))
class SourceControlSubject onModel: model = Subject onModel: model (|
title = 'MemoryHole'.
	mergingUI = MergingUI new.
	
	
|)
(
class LocalRepositorySubject onModel: model = Subject onModel: model (|

|model refresh)
(
class HistorianSubject onModel: model = Subject onModel: model (|
|)
('as yet unclassified'
name = (

	^ model name
))
class ImageBasedChangeSubject onModel: model = Subject onModel: model (|
	cachedMergeSubjects
	cachedVersion
	newlyAddedMirrors = Set new.
|)
('as yet unclassified'
addMirror: mirror = (

	newlyAddedMirrors add: mirror.
	clearCaches
)
buildVersion = (

	| v 	nilsAndMirrors |
	v:: historian repository createNewVersion.
	
	"Determines the classes in the image that correspond to the classes in the historian. I'm not sure how this can be extended to properly support renames, without having to check all classes in the image for possible correspondence. We could try to use renaming information provided by the external system."
	nilsAndMirrors:: historian version mirrors collect: [:each |
		logger
			log: 'Loading mirror corresponding to ', each name
			around: [
				sourceMirrors
					mirrorForClassInImageCorrespondingTo: each
					ifPresent: [:it | it]
					ifAbsent: [nil]]].
	v mirrors: newlyAddedMirrors, (nilsAndMirrors reject: [:each | nil = each]).
	v parents: {historian version}.
	^ v
)
changedDiffSubjects = (

	^ mergeSubjects reject: [:each | each mergeModel isEquals]
)
clearCaches = (

	cachedVersion:: nil.
	cachedMergeSubjects:: nil.
)
commit: message = (

	version
		mirrors: (mergingUI presentMirrorsOf: mergeSubjects ifFail: [logger error: 'unexpected']);
		message: message.
	historian commit: version.
)
createPresenter = (
	^ ImageBasedChangePresenter onSubject: self
)
hasChanges = (

	^ version diffsFromFirstParent anySatisfy: [:each |
		each isEquals not]
)
historian = (

	^ model
)
historianName = (

	^ historian name
)
mergeSubjects= (

	nil = cachedMergeSubjects ifTrue: [
		cachedMergeSubjects:: version diffsFromFirstParent collect: [:each |
			diffSubjectOn: each]].
	^ cachedMergeSubjects
)
revertImage = (

	historian loadIntoImage
)
unversionedImageMirrors = (

	^ (sourceMirrors imageMirrorsNotCorrespondingTo: version mirrors, newlyAddedMirrors) 
		sort: [:a :b | a name < b name]
)
version = (

	nil = cachedVersion ifTrue: [
		cachedVersion:: buildVersion].
	^ cachedVersion
))
class LocalHistorianSubject onModel: model = HistorianSubject onModel: model (|

	public trackedHistorianAccessor = TrackedHistorianAccessor new.
|)
(
class HistorianRelationSubject onModel: oh = Subject onModel: oh (
"Allows interacting with other historians"|

|)
('as yet unclassified'
canForwardOtherHistorian = (

	^ otherHistorian canForwardTo: historian
)
canForwardToOtherHistorian = (

	^ historian canForwardTo: otherHistorian
)
canMerge = (

	^ historian canMergeWith: otherHistorian
)
createPresenter = (

	^ HistorianRelationPresenter onSubject: self
)
forwardOtherHistorian = (

	otherHistorian setTo: historian version ifFail: [logger warn: 'Could not forward historian'].
	loadIfImageHistorian: otherHistorian
)
forwardToOtherHistorian = (

	historian setTo: otherHistorian version ifFail: [logger error: 'Could not forward historian'].
	loadIfImageHistorian: historian
)
historianIsImageHistorian = (

	^ historian = imageHistorian
)
incomingVersionSubjects = (

	| versions |
	versions:: historian versionsIncomingFrom: otherHistorian.
	^ versions collect: [:each | VersionSubject onModel: each]
)
mergeFromOtherHistorianSubject = (

	^ MergeHistoriansSubject merging: otherHistorian into: historian
)
mergeIntoOtherHistorianSubject = (

	^ MergeHistoriansSubject merging: historian into: otherHistorian
)
otherHistorian = (

	^ model
)
otherHistorianAndRepositoryName = (

	^ otherHistorian repository = repository
		ifTrue: ['local ', otherHistorian name]
		ifFalse: [otherHistorian name, ' on ', otherHistorian repository name]
)
otherHistorianIsImageHistorian = (

	^ otherHistorian = imageHistorian
)
outgoingVersionSubjects = (

	| versions |
	versions:: otherHistorian versionsIncomingFrom: historian.
	^ versions collect: [:each | VersionSubject onModel: each]
)
runActionOn: receiver = (

	canMerge ifTrue: [
		^ receiver merge].
	canForwardToOtherHistorian ifTrue: [
		^ receiver forwardToOther].
	canForwardOtherHistorian ifTrue: [
		^ receiver forwardOther].
	^ receiver inSynch
))
class IncomingOutgoingSubject onModel: otherHistorian = Subject onModel: otherHistorian (|

|)
('as yet unclassified'
createPresenter = (

	^ IncomingOutgoingPresenter onSubject: self
)
incomingVersionSubjects = (

	| versions |
	versions:: historian versionsIncomingFrom: otherHistorian.
	^ versions collect: [:each | VersionSubject onModel: each]
)
otherHistorian = (

	^ model
)
otherHistorianName = (

	^ otherHistorian name
)
outgoingVersionSubjects = (

	| versions |
	versions:: otherHistorian versionsIncomingFrom: historian.
	^ versions collect: [:each | VersionSubject onModel: each]
))
class TrackedHistorianAccessor = (
"Accessing a tracked historian can be slow. Funnel all access to it through this accessor to make it possibly slow commands explicit."|
	private cachedTrackingState
	private cachedTrackedHistorian
|)
('as yet unclassified'
computeTrackedHistorian = (

	cachedTrackedHistorian:: historian
		trackedHistorianifPresent: [:tr |
			cachedTrackingState:: #tracked.
			tr]
		ifAbsent: [cachedTrackingState:: #untracked.]
		ifError: [cachedTrackingState:: #error]
)
errorAccessingTrackingHistorian = (

	^ trackingState = #error
)
isTracking = (

	^ trackingState = #tracked
)
trackedHistorian = (

	nil = cachedTrackedHistorian ifTrue: [computeTrackedHistorian].
	^ cachedTrackedHistorian
)
trackingState = (

	nil = cachedTrackingState ifTrue: [computeTrackedHistorian].
	^ cachedTrackingState
))'as yet unclassified'
cloneAs: cloneName ifFail: failBlock = (

	^ model cloneAs: cloneName ifFail: failBlock
)
createPresenter = (

	^ LocalHistorianPresenter onSubject: self
)
deleteHistorianIfFail: failBlock = (

	model deleteIfFail: failBlock
)
historian = (

	^ model
)
historianRelationSubjects = (

	^ Array streamContents: [:stream |
		trackedHistorianAccessor isTracking ifTrue: [stream nextPut: (HistorianRelationSubject onModel: trackedHistorianAccessor trackedHistorian)].
		imageHistorian = historian ifFalse: [
			stream nextPut: (HistorianRelationSubject onModel: imageHistorian)]]
)
isImageHistorian = (

	^ model = imageHistorian
)
loadIntoImage = (

	model loadIntoImage
)
shareNamesAndActionOf: remoteRepository = (

	"We could put this into shareNamesAndActions if we had closures"
	^ {remoteRepository name.
		[model shareTo: remoteRepository]}
)
shareNamesAndActions = (

	^ remoteRepositories collect: [:each |
		shareNamesAndActionOf: each]
))
class LogSubject onModel: model = Subject onModel: model (|
|)
('as yet unclassified'
createPresenter = (

	^ LogPresenter onSubject: self
)
versions = (

	^ model logStream contents collect: [:each |
		VersionSubject onModel: each]
))
class MergeHistoriansSubject onModel: model = Subject onModel: model (|
cachedMergeSubjects

version = newVersion.
|)
('as yet unclassified'
createPresenter = (

	^ MergeHistorianPresenter onSubject: self
)
destinationHistorian = (

	^ model second
)
mergeDestinationName = (

	^ destinationHistorian name
)
mergeIfFail: failBlock = (

	version
		mirrors: (mergingUI presentMirrorsOf: mergeSubjects ifFail: failBlock);
		message: 'Merged from ', sourceHistorian name.
	destinationHistorian commit: version.
	"While we usually do not load the version created by a commit (as not all changes may have been committed), we do so in this case to bring external changes into the image"
	loadIfImageHistorian: destinationHistorian
)
mergeSourceName = (

	^ sourceHistorian name
)
mergeSubjects = (

	cachedMergeSubjects = nil ifTrue: [ | diffs |
		diffs:: destinationHistorian version diffsFrom: sourceHistorian version.
		cachedMergeSubjects:: diffs collect: [:each | mergeSubjectOn: each]].
	^ cachedMergeSubjects
)
newVersion = (

	| v |
	v:: repository createNewVersion.
	v parents: {sourceHistorian version. destinationHistorian version}.
	^ v
)
sourceHistorian = (

	^ model first
)) : ('as yet unclassified'
merging: sourceHistorian into: destinationHistorian = (

	^ MergeHistoriansSubject
		onModel: {sourceHistorian. destinationHistorian}
))
class RemoteHistorianSubject onModel: model = HistorianSubject onModel: model (|
|)
('as yet unclassified'
createPresenter = (

	^ RemoteHistorianPresenter onSubject: self
)
isTracked = (

	^ model isTracked
)
trackAs: name = (

	model trackAs: name
))
class RemoteRepositorySubject onModel: model = Subject onModel: model (|
|)
('as yet unclassified'
createPresenter = (

	^ RemoteRepositoryPresenter onSubject: self
)
historianSubjects = (

	^ model historians collect: [:each |
		RemoteHistorianSubject onModel: each]
)
name = (

	^ model name
))
class VersionSubject onModel: model = Subject onModel: model (|
|)
('as yet unclassified'
author = (

	^ model author
)
createPresenter = (

	^ VersionPresenter onSubject: self
)
internalId = (

	^ model internalId
)
isParentOfImage = (

	^ model isParentOfImage
)
loadIntoImage = (

	model loadIntoImage
)
message = (

	^ model message
)
unequaldiffsFromPrevious = (

	| diffsFromPrevious |
	diffsFromPrevious:: model diffsFromFirstParent collect: [:each | diffSubjectOn: each].
	^ diffsFromPrevious reject: [:each | each isEquals]
))'as yet unclassified'
= other = (
	^class = other class and: [model = other model]
)
createPresenter = (

	^ LocalRepositoryPresenter onSubject: self
)
hash = (
	^model hash
)
imageHistorian = (

	^ model imageHistorian
)
loadIfImageHistorian: historian = (

	"Before this, we had a historian check whether it is the image historian on setTo:ifFail:. It turns out, that there are cases where it's desirable to change a historian's version without changing the code in the image, for example when doing partial commits.
	The new strategy is to have callers of setTo: distinguish the two cases. Ideally we wouldn't distinguish 'commit' and 'setTo'. Then we could offer a 'updatingImageSet:to:ifFail:"
	imageHistorian = historian ifTrue: [
		imageHistorian loadIntoImage]
)
localHistorianSubjects = (

	^ model historians collect: [:each | LocalHistorianSubject onModel: each].
)
logSubject = (

	^ LogSubject onModel: repository
)
modifiedInImageSubject = (

	^ ImageBasedChangeSubject
		onModel: model imageHistorian.
)
remoteRepositories = (

	^ model remoteRepositories
)
remoteRepositorySubjects = (

	^ remoteRepositories collect: [:each | RemoteRepositorySubject onModel: each].
)
repository = (

	^ model
)
repositoryName = (

	^ model repositoryId
)
repositoryType = (

	^ model repositoryType
)
title = (
	^'[',repositoryType,'] ',repositoryName
))'as yet unclassified'
= other = (
	^self class = other class and: [self model = other model]
)
createPresenter = (

	^ SourceControlPresenter onSubject: self
)
diffSubjectOn: diff = (

	"TODO: dispatch on the kind of diff"
	^ mergingUI ClassMirrorMergeSubject diffSubjectOn: diff
)
hash = (
	^model hash
)
mergeSubjectOn: diff = (

	"TODO: dispatch on the kind of diff"
	^ mergingUI ClassMirrorMergeSubject mergeSubjectOn: diff
)
modifiedLocalRepositorySubjects = (

	^ model collect: [:each | LocalRepositorySubject onModel: each]
)
removeRepository: r = (
	model remove: r.
)
shutdown = (

	"If our model is simply some repositories we don't really own VCS and thus shouldn't be allowed to shut it down, should we?"
	[vcs shutdown] ifError:[]
)
sourceControlSubject = (

	^ self
))'accessing'
columnSeparator = (

	^ BlankFragment size: 12
)
halfColumnSeparator = (

	^ BlankFragment size: 6
)'as yet unclassified'
forkAndRemember: b= (
	vcs core forkAndRemember: b
)
mainSubject = (
	^SourceControlSubject onModel: theModel
))