@@ -1407,58 +1407,113 @@ let createProfile parent =
1407
1407
1408
1408
(* Directory selection *)
1409
1409
let directorySelection = GPack. vbox ~border_width: 12 ~spacing: 6 () in
1410
+ let dirhb = GPack. hbox ~packing: (directorySelection#pack ~expand: false ) () in
1411
+ adjustSize
1412
+ (GMisc. label ~xalign: 0. ~line_wrap: false ~justify: `LEFT
1413
+ ~text: " Please select the two "
1414
+ ~packing: (dirhb#pack ~expand: false ) () );
1415
+ let dirKindCombo =
1416
+ GEdit. combo_box_text
1417
+ ~strings: [" directories" ; " files" ]
1418
+ ~active: 0 ~packing: (dirhb#pack ~expand: false ) () in
1419
+ let dirKind =
1420
+ GtkReact. text_combo dirKindCombo
1421
+ >> fun i -> List. nth [`Dir ; `File ] i
1422
+ in
1410
1423
adjustSize
1411
1424
(GMisc. label ~xalign: 0. ~line_wrap: true ~justify: `LEFT
1412
- ~text: " Please select the two directories that you want to synchronize."
1413
- ~packing: (directorySelection#pack ~expand: false ) () );
1425
+ ~text: " that you want to synchronize."
1426
+ ~packing: (dirhb#pack ~expand: false ) () );
1427
+ (* Not sure what's going on here, but when setting the focus on an element,
1428
+ it's actually the next element that gets the focus by default. We want
1429
+ the focus to be on the first directory selector. Setting the focus on the
1430
+ combo here achieves exactly that... *)
1431
+ ignore ((fst dirKindCombo)#misc#connect#map ~callback: (fst dirKindCombo)#misc#grab_focus);
1414
1432
let secondDirLabel1 =
1415
1433
GMisc. label ~xalign: 0. ~line_wrap: true ~justify: `LEFT
1416
- ~text: " The second directory is relative to your home \
1417
- directory on the remote machine."
1434
+ ~text: " "
1418
1435
~packing: (directorySelection#pack ~expand: false ) ()
1419
1436
in
1420
1437
adjustSize secondDirLabel1;
1421
1438
GtkReact. show secondDirLabel1 ((React. lift2 (|| ) isLocal isSocket) >> not );
1439
+ GtkReact. label secondDirLabel1 (dirKind >> function
1440
+ | `Dir -> " The second directory is relative to your home \
1441
+ directory on the remote machine."
1442
+ | `File -> " The second file is relative to your home \
1443
+ directory on the remote machine." );
1422
1444
let secondDirLabel2 =
1423
1445
GMisc. label ~xalign: 0. ~line_wrap: true ~justify: `LEFT
1424
- ~text: " The second directory is relative to \
1425
- the working directory of the Unison server \
1426
- running on the remote machine."
1446
+ ~text: " "
1427
1447
~packing: (directorySelection#pack ~expand: false ) ()
1428
1448
in
1429
1449
adjustSize secondDirLabel2;
1430
1450
GtkReact. show secondDirLabel2 isSocket;
1451
+ GtkReact. label secondDirLabel2 (dirKind >> function
1452
+ | `Dir -> " The second directory is relative to \
1453
+ the working directory of the Unison server \
1454
+ running on the remote machine."
1455
+ | `File -> " The second file is relative to \
1456
+ the working directory of the Unison server \
1457
+ running on the remote machine." );
1431
1458
let tbl =
1432
1459
let al =
1433
1460
GBin. alignment ~packing: (directorySelection#pack ~expand: false ) () in
1434
1461
al#set_left_padding 12 ;
1435
1462
GPack. table ~rows: 2 ~columns: 2 ~col_spacings: 12 ~row_spacings: 6
1436
1463
~packing: (al#add) () in
1437
- (* XXX Should focus on this button when becomes visible... *)
1438
1464
let firstDirButton =
1439
1465
GFile. chooser_button ~action: `SELECT_FOLDER ~title: " First Directory"
1440
1466
~packing: (tbl#attach ~left: 1 ~top: 0 ~expand: `X ) ()
1441
1467
in
1442
- isLocal > | (fun b -> firstDirButton#set_title
1443
- (if b then " First Directory" else " Local Directory" ));
1468
+ React. lift2
1469
+ (fun local dirkind ->
1470
+ firstDirButton#set_action (
1471
+ match dirkind with
1472
+ | `Dir -> `SELECT_FOLDER
1473
+ | `File -> `OPEN
1474
+ );
1475
+ firstDirButton#set_title (
1476
+ match local, dirkind with
1477
+ | true , `Dir -> " First Directory"
1478
+ | false , `Dir -> " Local Directory"
1479
+ | true , `File -> " First File"
1480
+ | false , `File -> " Local File"
1481
+ )
1482
+ ) isLocal dirKind |> ignore;
1483
+
1444
1484
GtkReact. label_underlined
1445
1485
(GMisc. label ~xalign: 0.
1446
1486
~mnemonic_widget: firstDirButton
1447
1487
~packing: (tbl#attach ~left: 0 ~top: 0 ~expand: `NONE ) () )
1448
- (isLocal >> fun b ->
1449
- if b then " _First directory:" else " _Local directory:" );
1488
+ (React. lift2 (fun local dirkind ->
1489
+ match local, dirkind with
1490
+ | true , `Dir -> " _First directory:"
1491
+ | false , `Dir -> " _Local directory:"
1492
+ | true , `File -> " _First file:"
1493
+ | false , `File -> " _Local file:"
1494
+ ) isLocal dirKind);
1450
1495
let noneToEmpty o = match o with None -> " " | Some s -> s in
1451
1496
let firstDir = GtkReact. file_chooser firstDirButton >> noneToEmpty in
1497
+
1452
1498
let secondDirButton =
1453
1499
GFile. chooser_button ~action: `SELECT_FOLDER ~title: " Second Directory"
1454
1500
~packing: (tbl#attach ~left: 1 ~top: 1 ~expand: `X ) () in
1501
+ dirKind > | (function
1502
+ | `Dir -> secondDirButton#set_action `SELECT_FOLDER ;
1503
+ secondDirButton#set_title " Second Directory"
1504
+ | `File -> secondDirButton#set_action `OPEN ;
1505
+ secondDirButton#set_title " Second File"
1506
+ );
1507
+
1455
1508
let secondDirLabel =
1456
1509
GMisc. label ~xalign: 0.
1457
1510
~text: " Se_cond directory:"
1458
1511
~use_underline: true ~mnemonic_widget: secondDirButton
1459
1512
~packing: (tbl#attach ~left: 0 ~top: 1 ~expand: `NONE ) () in
1460
1513
GtkReact. show secondDirButton isLocal;
1461
1514
GtkReact. show secondDirLabel isLocal;
1515
+ GtkReact. label_underlined secondDirLabel
1516
+ (dirKind >> function `Dir -> " Se_cond directory:" | `File -> " Se_cond file:" );
1462
1517
let remoteDirEdit =
1463
1518
GEdit. entry ~packing: (tbl#attach ~left: 1 ~top: 1 ~expand: `X ) ()
1464
1519
in
@@ -1470,19 +1525,13 @@ let createProfile parent =
1470
1525
in
1471
1526
GtkReact. show remoteDirEdit (isLocal >> not );
1472
1527
GtkReact. show remoteDirLabel (isLocal >> not );
1528
+ GtkReact. label_underlined remoteDirLabel
1529
+ (dirKind >> function `Dir -> " _Remote directory:" | `File -> " _Remote file:" );
1473
1530
let secondDir =
1474
1531
React. lift3 (fun b l r -> if b then l else r) isLocal
1475
1532
(GtkReact. file_chooser secondDirButton >> noneToEmpty)
1476
1533
(GtkReact. entry remoteDirEdit)
1477
1534
in
1478
- let dirExplanationLabel =
1479
- GMisc. label ~xalign: 0. ~line_wrap: true ~justify: `LEFT
1480
- ~text: " Note: To synchronize a single file with another file, you \
1481
- currently have to create the profile manually or specify the \
1482
- files on the command line."
1483
- ~packing: (directorySelection#pack ~expand: false ) ()
1484
- in
1485
- dirExplanationLabel#set_max_width_chars 80 ;
1486
1535
ignore
1487
1536
(assistant#append_page
1488
1537
~title: " Directory Selection"
0 commit comments