Skip to content

Commit

Permalink
Enable manual path entry in new profile assistant
Browse files Browse the repository at this point in the history
GTK file chooser allows selecting either files or directories but not
both. File choosers in the new profile assistant are configured for
selecting directories, with the expectation that this covers the vast
majority of usages. This patch adds text entry fields for users who wish
to manually enter the paths. As a side effect, this enables specifying a
single file as a sync root.
  • Loading branch information
tleedjarv committed Feb 6, 2025
1 parent a769e71 commit 6f17aba
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions src/uigtk3.ml
Original file line number Diff line number Diff line change
Expand Up @@ -1407,10 +1407,19 @@ let createProfile parent =

(* Directory selection *)
let directorySelection = GPack.vbox ~border_width:12 ~spacing:6 () in
let dirhb = GPack.hbox ~packing:(directorySelection#pack ~expand:false) () in
adjustSize
(GMisc.label ~xalign:0. ~line_wrap:true ~justify:`LEFT
~text:"Please select the two directories that you want to synchronize."
~packing:(directorySelection#pack ~expand:false) ());
~packing:(dirhb#pack ~expand:false) ());
let manualEntryB =
GButton.toggle_button ~label:"I want to enter the paths manually"
~packing:(dirhb#pack ~expand:false ~from:`END) () in
(* Not sure what's going on here, but when setting the focus on an element,
it's actually the next element that gets the focus by default. We want
the focus to be on the first directory selector. Setting the focus on the
button here achieves exactly that... *)
ignore (manualEntryB#misc#connect#map ~callback:manualEntryB#misc#grab_focus);
let secondDirLabel1 =
GMisc.label ~xalign:0. ~line_wrap:true ~justify:`LEFT
~text:"The second directory is relative to your home \
Expand All @@ -1434,11 +1443,25 @@ let createProfile parent =
al#set_left_padding 12;
GPack.table ~rows:2 ~columns:2 ~col_spacings:12 ~row_spacings:6
~packing:(al#add) () in
(*XXX Should focus on this button when becomes visible... *)

let noneToEmpty o = match o with None -> "" | Some s -> s in
let connectButtonAndEntry btn entry =
ignore (btn#connect#selection_changed ~callback:(fun () ->
if not entry#is_focus then entry#set_text (noneToEmpty btn#filename)));
ignore (entry#connect#changed ~callback:(fun () ->
if entry#is_focus then ignore (btn#set_filename entry#text)))
in

let firstDirHbox =
GPack.hbox ~homogeneous:true ~packing:(tbl#attach ~left:1 ~top:0 ~expand:`X) () in
let firstFileEntry = GEdit.entry ~packing:(firstDirHbox#pack ~expand:false) () in
let firstDirButton =
GFile.chooser_button ~action:`SELECT_FOLDER ~title:"First Directory"
~packing:(tbl#attach ~left:1 ~top:0 ~expand:`X) ()
~packing:firstDirHbox#add ()
in
connectButtonAndEntry firstDirButton firstFileEntry;
GtkReact.show firstFileEntry (GtkReact.toggle_button manualEntryB);

isLocal >| (fun b -> firstDirButton#set_title
(if b then "First Directory" else "Local Directory"));
GtkReact.label_underlined
Expand All @@ -1447,11 +1470,18 @@ let createProfile parent =
~packing:(tbl#attach ~left:0 ~top:0 ~expand:`NONE) ())
(isLocal >> fun b ->
if b then "_First directory:" else "_Local directory:");
let noneToEmpty o = match o with None -> "" | Some s -> s in
let firstDir = GtkReact.file_chooser firstDirButton >> noneToEmpty in

let secondDirHbox =
GPack.hbox ~homogeneous:true ~packing:(tbl#attach ~left:1 ~top:1 ~expand:`X) () in
let secondFileEntry = GEdit.entry ~packing:(secondDirHbox#pack ~expand:false) () in
let secondDirButton =
GFile.chooser_button ~action:`SELECT_FOLDER ~title:"Second Directory"
~packing:(tbl#attach ~left:1 ~top:1 ~expand:`X) () in
~packing:secondDirHbox#add () in
connectButtonAndEntry secondDirButton secondFileEntry;
GtkReact.show secondFileEntry
(React.lift2 (&&) isLocal (GtkReact.toggle_button manualEntryB));

let secondDirLabel =
GMisc.label ~xalign:0.
~text:"Se_cond directory:"
Expand All @@ -1478,8 +1508,7 @@ let createProfile parent =
let dirExplanationLabel =
GMisc.label ~xalign:0. ~line_wrap:true ~justify:`LEFT
~text:"Note: To synchronize a single file with another file, you \
currently have to create the profile manually or specify the \
files on the command line."
have to enter the paths manually."
~packing:(directorySelection#pack ~expand:false) ()
in
dirExplanationLabel#set_max_width_chars 80;
Expand Down

0 comments on commit 6f17aba

Please sign in to comment.