Skip to content

Commit 77cd088

Browse files
authored
Merge pull request #1119 from tleedjarv/fix-1116
Enable manual path entry in the new profile assistant
2 parents fd53cfb + dae18b0 commit 77cd088

File tree

1 file changed

+69
-20
lines changed

1 file changed

+69
-20
lines changed

src/uigtk3.ml

+69-20
Original file line numberDiff line numberDiff line change
@@ -1407,58 +1407,113 @@ let createProfile parent =
14071407

14081408
(* Directory selection *)
14091409
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
14101423
adjustSize
14111424
(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);
14141432
let secondDirLabel1 =
14151433
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:""
14181435
~packing:(directorySelection#pack ~expand:false) ()
14191436
in
14201437
adjustSize secondDirLabel1;
14211438
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.");
14221444
let secondDirLabel2 =
14231445
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:""
14271447
~packing:(directorySelection#pack ~expand:false) ()
14281448
in
14291449
adjustSize secondDirLabel2;
14301450
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.");
14311458
let tbl =
14321459
let al =
14331460
GBin.alignment ~packing:(directorySelection#pack ~expand:false) () in
14341461
al#set_left_padding 12;
14351462
GPack.table ~rows:2 ~columns:2 ~col_spacings:12 ~row_spacings:6
14361463
~packing:(al#add) () in
1437-
(*XXX Should focus on this button when becomes visible... *)
14381464
let firstDirButton =
14391465
GFile.chooser_button ~action:`SELECT_FOLDER ~title:"First Directory"
14401466
~packing:(tbl#attach ~left:1 ~top:0 ~expand:`X) ()
14411467
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+
14441484
GtkReact.label_underlined
14451485
(GMisc.label ~xalign:0.
14461486
~mnemonic_widget:firstDirButton
14471487
~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);
14501495
let noneToEmpty o = match o with None -> "" | Some s -> s in
14511496
let firstDir = GtkReact.file_chooser firstDirButton >> noneToEmpty in
1497+
14521498
let secondDirButton =
14531499
GFile.chooser_button ~action:`SELECT_FOLDER ~title:"Second Directory"
14541500
~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+
14551508
let secondDirLabel =
14561509
GMisc.label ~xalign:0.
14571510
~text:"Se_cond directory:"
14581511
~use_underline:true ~mnemonic_widget:secondDirButton
14591512
~packing:(tbl#attach ~left:0 ~top:1 ~expand:`NONE) () in
14601513
GtkReact.show secondDirButton isLocal;
14611514
GtkReact.show secondDirLabel isLocal;
1515+
GtkReact.label_underlined secondDirLabel
1516+
(dirKind >> function `Dir -> "Se_cond directory:" | `File -> "Se_cond file:");
14621517
let remoteDirEdit =
14631518
GEdit.entry ~packing:(tbl#attach ~left:1 ~top:1 ~expand:`X) ()
14641519
in
@@ -1470,19 +1525,13 @@ let createProfile parent =
14701525
in
14711526
GtkReact.show remoteDirEdit (isLocal >> not);
14721527
GtkReact.show remoteDirLabel (isLocal >> not);
1528+
GtkReact.label_underlined remoteDirLabel
1529+
(dirKind >> function `Dir -> "_Remote directory:" | `File -> "_Remote file:");
14731530
let secondDir =
14741531
React.lift3 (fun b l r -> if b then l else r) isLocal
14751532
(GtkReact.file_chooser secondDirButton >> noneToEmpty)
14761533
(GtkReact.entry remoteDirEdit)
14771534
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;
14861535
ignore
14871536
(assistant#append_page
14881537
~title:"Directory Selection"

0 commit comments

Comments
 (0)