| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
open Preferences |
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
type pref_box = { |
| 18 |
label: string; |
| 19 |
box: GPack.box; |
| 20 |
apply: unit -> unit; |
| 21 |
} |
| 22 |
|
| 23 |
type pref_section = { |
| 24 |
label: string; |
| 25 |
icon: GtkStock.id option; |
| 26 |
sections: pref_box list; |
| 27 |
children: pref_section list; |
| 28 |
} |
| 29 |
|
| 30 |
type pref_widget = { widget: GObj.widget; apply: unit -> unit } |
| 31 |
|
| 32 |
let pref_section label ?icon ?(children = []) sections = |
| 33 |
{ label; icon; sections; children } |
| 34 |
|
| 35 |
let create_preferences_box pref_struct current_section = |
| 36 |
let main_box = GPack.hbox () in |
| 37 |
|
| 38 |
let columns = new GTree.column_list in |
| 39 |
let icon_col = columns#add GtkStock.conv |
| 40 |
and label_col = columns#add Gobject.Data.string |
| 41 |
and box_col = columns#add Gobject.Data.caml in |
| 42 |
columns#lock (); |
| 43 |
|
| 44 |
let pane = GPack.paned `HORIZONTAL ~packing:main_box#add () in |
| 45 |
|
| 46 |
|
| 47 |
let scroll = GBin.scrolled_window ~hpolicy:`NEVER ~packing:pane#pack1 () |
| 48 |
and tree = GTree.tree_store columns in |
| 49 |
let view = GTree.view ~model:tree ~headers_visible:false ~packing:scroll#add_with_viewport () in |
| 50 |
let selection = view#selection in |
| 51 |
selection#set_mode `SINGLE; |
| 52 |
|
| 53 |
let menu_box = GPack.vbox ~packing:pane#pack2 () in |
| 54 |
|
| 55 |
let renderer = (GTree.cell_renderer_pixbuf [], ["stock-id", icon_col]) in |
| 56 |
let col = GTree.view_column ~renderer () in |
| 57 |
let _ = view#append_column col in |
| 58 |
|
| 59 |
let renderer = (GTree.cell_renderer_text [], ["text", label_col]) in |
| 60 |
let col = GTree.view_column ~renderer () in |
| 61 |
let _ = view#append_column col in |
| 62 |
|
| 63 |
let make_section (main_box : #GPack.box) { label; box; apply } = |
| 64 |
let wf = GBin.frame ~label () in |
| 65 |
box#set_border_width 4; |
| 66 |
wf#add box#coerce; |
| 67 |
let widget = wf#coerce in |
| 68 |
main_box#pack ~expand:true ~padding:2 widget; |
| 69 |
{ widget; apply } |
| 70 |
in |
| 71 |
|
| 72 |
|
| 73 |
let rec make_tree ?parent { label; icon; sections; children } = |
| 74 |
|
| 75 |
let box = GPack.vbox ~packing:(menu_box#pack ~expand:true) ~show:false () in |
| 76 |
box#set_margin_left 4; |
| 77 |
let section_widgets = List.map (make_section box) sections in |
| 78 |
let box_widget = { |
| 79 |
widget = box#coerce; |
| 80 |
apply = fun () -> List.iter (fun { apply } -> apply ()) section_widgets; |
| 81 |
} in |
| 82 |
let new_iter = tree#append ?parent () in |
| 83 |
Option.iter (tree#set ~row:new_iter ~column:icon_col) icon; |
| 84 |
|
| 85 |
let label = if parent <> None then " " ^ label else label in |
| 86 |
tree#set ~row:new_iter ~column:label_col label; |
| 87 |
tree#set ~row:new_iter ~column:box_col box_widget; |
| 88 |
List.iter (make_tree ~parent:new_iter) children; |
| 89 |
in |
| 90 |
|
| 91 |
List.iter make_tree pref_struct; |
| 92 |
|
| 93 |
|
| 94 |
let current_widget : GObj.widget option ref = ref None in |
| 95 |
|
| 96 |
let select_path path = |
| 97 |
Option.iter (fun widget -> widget#misc#hide ()) !current_widget; |
| 98 |
current_section := Some (GTree.Path.get_indices path); |
| 99 |
let { widget } = tree#get ~row:(tree#get_iter path) ~column:box_col in |
| 100 |
widget#misc#show (); |
| 101 |
current_widget := Some widget; |
| 102 |
in |
| 103 |
|
| 104 |
let when_selected () = |
| 105 |
match selection#get_selected_rows with |
| 106 |
| row :: _ -> select_path row |
| 107 |
| _ -> () |
| 108 |
in |
| 109 |
|
| 110 |
|
| 111 |
let _ = selection#connect#changed ~callback:when_selected in |
| 112 |
|
| 113 |
view#expand_all (); |
| 114 |
Option.iter (fun path -> |
| 115 |
selection#select_path (GTree.Path.create (Array.to_list path)); |
| 116 |
) !current_section; |
| 117 |
|
| 118 |
{ |
| 119 |
widget = (main_box :> GObj.widget); |
| 120 |
apply = fun () -> |
| 121 |
let foreach _ iter = |
| 122 |
let { apply } = tree#get ~row:iter ~column:box_col in |
| 123 |
apply (); |
| 124 |
false |
| 125 |
in |
| 126 |
tree#foreach foreach; |
| 127 |
} |
| 128 |
|
| 129 |
let edit_preferences |
| 130 |
?(apply = fun () -> ()) |
| 131 |
?parent ?width ?height ?(current_section = ref None) |
| 132 |
title pref_struct = |
| 133 |
let dialog = GWindow.dialog |
| 134 |
~position:`CENTER |
| 135 |
~modal:true ~title |
| 136 |
~type_hint:`DIALOG |
| 137 |
?parent ?height ?width |
| 138 |
() |
| 139 |
in |
| 140 |
let preferences_box = create_preferences_box pref_struct current_section in |
| 141 |
|
| 142 |
dialog#vbox#pack ~expand:true preferences_box.widget#coerce; |
| 143 |
|
| 144 |
dialog#add_button_stock `APPLY `APPLY; |
| 145 |
dialog#add_button_stock `OK `OK; |
| 146 |
dialog#add_button_stock `CANCEL `CANCEL; |
| 147 |
|
| 148 |
let apply () = |
| 149 |
preferences_box.apply (); |
| 150 |
apply (); |
| 151 |
in |
| 152 |
|
| 153 |
let rec iter rep = |
| 154 |
try |
| 155 |
match dialog#run () with |
| 156 |
| `APPLY -> apply (); iter true |
| 157 |
| `OK -> apply (); dialog#destroy (); true |
| 158 |
| _ -> dialog#destroy (); rep |
| 159 |
with exc -> |
| 160 |
GToolbox.message_box ~title:"Error" |
| 161 |
(match exc with Failure str -> str | _ -> Printexc.to_string exc); |
| 162 |
iter rep |
| 163 |
in |
| 164 |
iter false |
| 165 |
|
| 166 |
|
| 167 |
|
| 168 |
type pref_ui_specific_info = |
| 169 |
| PBool of { pref: bool preference } |
| 170 |
| PInt of { min: int; max: int; pref: int preference } |
| 171 |
| PTextExpr of { initial: string; set: (string -> unit) } |
| 172 |
| PCombo of { values: string list; editable: bool; initial: string; set: (int -> string -> unit) } |
| 173 |
| PModifiers of { |
| 174 |
allowed_mods: Gdk.Tags.modifier list; |
| 175 |
registerer: ((Gdk.Tags.modifier list -> unit) -> unit) option; |
| 176 |
callback: (Gdk.Tags.modifier list -> unit) option; |
| 177 |
pref: string preference |
| 178 |
} |
| 179 |
|
| 180 |
type pref_ui_info = { |
| 181 |
text: string; |
| 182 |
tooltip: string option; |
| 183 |
specific: pref_ui_specific_info; |
| 184 |
} |
| 185 |
|
| 186 |
let string_of_modifier = function |
| 187 |
| `CONTROL -> "<ctrl>" |
| 188 |
| `SHIFT -> "<shift>" |
| 189 |
| `META -> select_arch "<meta>" "<cmd>" |
| 190 |
| `MOD1 -> "<alt>" |
| 191 |
| `MOD2 -> "<mod2>" |
| 192 |
| `MOD3 -> "<mod3>" |
| 193 |
| `MOD4 -> "<mod4>" |
| 194 |
| `MOD5 -> "<mod5>" |
| 195 |
| _ -> "" |
| 196 |
|
| 197 |
let all_modifiers = [`CONTROL; `SHIFT; `META; `MOD1; `MOD2; `MOD3; `MOD4; `MOD5] |
| 198 |
|
| 199 |
let rec find_index_opt elem ?(i = 0) = function |
| 200 |
| [] -> None |
| 201 |
| h :: _ when h = elem -> Some i |
| 202 |
| _ :: t -> find_index_opt elem ~i:(succ i) t |
| 203 |
|
| 204 |
let pbool text ?tooltip pref = { text; tooltip; specific = PBool { pref } } |
| 205 |
let pint text ?tooltip ?(min = 0) ?(max = 999_999_999) pref = |
| 206 |
{ text; tooltip; specific = PInt { min; max; pref } } |
| 207 |
let ptextexpr text ?tooltip initial set = { text; tooltip; specific = PTextExpr { initial; set } } |
| 208 |
let pstring text ?tooltip pref = ptextexpr text ?tooltip pref#get pref#set |
| 209 |
let pcombo text ?tooltip values ?(editable = false) initial set = |
| 210 |
{ text; tooltip; specific = PCombo { values; editable; initial; set } } |
| 211 |
let pstringcombo text ?tooltip values ?(editable = false) pref = |
| 212 |
pcombo text ?tooltip values ~editable pref#get (fun _ s -> pref#set s) |
| 213 |
let pmodifiers text ?tooltip allowed_mods ?registerer ?callback pref = |
| 214 |
{ text; tooltip; specific = PModifiers { allowed_mods; registerer; callback; pref } } |
| 215 |
|
| 216 |
let create_pref_box ?(in_grid = false) label pref_data = |
| 217 |
let box = GPack.vbox () in |
| 218 |
let apply_list = ref [] in |
| 219 |
let add_row = |
| 220 |
let create_label pref_data packing = |
| 221 |
if pref_data.text <> "" then |
| 222 |
let label = GMisc.label ~text:pref_data.text ~packing () in |
| 223 |
label#set_halign `START; |
| 224 |
Option.iter label#set_tooltip_text pref_data.tooltip; |
| 225 |
in |
| 226 |
if in_grid then |
| 227 |
let grid = GPack.grid ~col_spacings:4 ~packing:box#pack () in |
| 228 |
(fun pref_data index -> |
| 229 |
create_label pref_data (grid#attach ~left:0 ~top:index); |
| 230 |
((grid#attach ~left:1 ~top:index) : (GObj.widget -> unit))) |
| 231 |
else |
| 232 |
(fun pref_data _ -> |
| 233 |
let box = GPack.hbox ~packing:box#pack () in |
| 234 |
create_label pref_data box#pack; |
| 235 |
(box#pack : (GObj.widget -> unit))) |
| 236 |
in |
| 237 |
let add_param index pref_data = |
| 238 |
let setup_input ?(expand = false) input = |
| 239 |
if not in_grid && pref_data.text <> "" then |
| 240 |
input#set_margin_left 4; |
| 241 |
Option.iter input#set_tooltip_text pref_data.tooltip; |
| 242 |
input#set_hexpand expand; |
| 243 |
in |
| 244 |
match pref_data.specific with |
| 245 |
| PBool { pref } -> |
| 246 |
let input = GButton.check_button ~label:pref_data.text ~active:pref#get ~packing:box#pack () in |
| 247 |
apply_list := (fun () -> pref#set input#active) :: !apply_list; |
| 248 |
| PInt { min; max; pref } -> |
| 249 |
let packing = add_row pref_data index in |
| 250 |
let input = GEdit.spin_button |
| 251 |
~numeric:true ~update_policy:`IF_VALID ~digits:0 |
| 252 |
~packing () |
| 253 |
in |
| 254 |
setup_input input; |
| 255 |
let lower = float_of_int min and upper = float_of_int max in |
| 256 |
input#adjustment#set_bounds ~lower ~upper ~step_incr:1. (); |
| 257 |
input#set_value (float_of_int pref#get); |
| 258 |
apply_list := (fun () -> pref#set input#value_as_int) :: !apply_list; |
| 259 |
| PTextExpr { initial; set } -> |
| 260 |
let packing = add_row pref_data index in |
| 261 |
let input = GEdit.entry ~text:initial ~packing () in |
| 262 |
setup_input ~expand:true input; |
| 263 |
apply_list := (fun () -> set input#text) :: !apply_list; |
| 264 |
| PCombo { values; editable; initial; set } when editable -> |
| 265 |
let packing = add_row pref_data index in |
| 266 |
let input, _ = GEdit.combo_box_entry_text ~strings:values ~packing () in |
| 267 |
input#entry#set_editable true; |
| 268 |
input#entry#set_text initial; |
| 269 |
setup_input ~expand:true input; |
| 270 |
apply_list := (fun () -> set input#active input#entry#text) :: !apply_list; |
| 271 |
| PCombo { values; editable; initial; set } -> |
| 272 |
let packing = add_row pref_data index in |
| 273 |
let input, _ = GEdit.combo_box_text ~strings:values ?active:(find_index_opt initial values) ~packing () in |
| 274 |
setup_input input; |
| 275 |
let values = Array.of_list values in |
| 276 |
apply_list := (fun () -> set input#active values.(input#active)) :: !apply_list; |
| 277 |
| PModifiers { allowed_mods; registerer; callback; pref } -> |
| 278 |
let packing = add_row pref_data index in |
| 279 |
let hbox = GPack.hbox ~packing () in |
| 280 |
setup_input hbox; |
| 281 |
let filter_mods allowed = List.filter (fun modifier -> List.mem modifier allowed) in |
| 282 |
let value = ref (filter_mods allowed_mods (str_to_mod_list pref#get)) in |
| 283 |
let create_button modifier = |
| 284 |
let but = GButton.toggle_button |
| 285 |
~label:(string_of_modifier modifier) |
| 286 |
~active:(List.mem modifier !value) |
| 287 |
~packing:hbox#pack () in |
| 288 |
ignore (but#connect#toggled ~callback:(fun () -> |
| 289 |
if but#active then ( |
| 290 |
value := str_to_mod_list (mod_list_to_str (modifier :: !value)); |
| 291 |
) else value := List.filter ((<>) modifier) !value; |
| 292 |
Option.iter (fun callback -> callback !value) callback; |
| 293 |
)); |
| 294 |
apply_list := (fun () -> pref#set (mod_list_to_str !value)) :: !apply_list; |
| 295 |
in |
| 296 |
List.iter create_button allowed_mods; |
| 297 |
Option.iter (fun registerer -> |
| 298 |
registerer (fun allowed_mods -> |
| 299 |
List.iter hbox#remove hbox#children; |
| 300 |
value := filter_mods allowed_mods !value; |
| 301 |
List.iter create_button allowed_mods; |
| 302 |
); |
| 303 |
) registerer; |
| 304 |
in |
| 305 |
List.iteri add_param pref_data; |
| 306 |
{ label; box; apply = fun () -> List.iter (fun apply -> apply ()) !apply_list } |
| 307 |
|
| 308 |
class tag_button (box : Gtk.box Gtk.obj) = |
| 309 |
object (self) |
| 310 |
|
| 311 |
inherit GObj.widget box |
| 312 |
|
| 313 |
val fg_color = GButton.color_button () |
| 314 |
val fg_unset = GButton.toggle_button () |
| 315 |
val bg_color = GButton.color_button () |
| 316 |
val bg_unset = GButton.toggle_button () |
| 317 |
val bold = GButton.toggle_button () |
| 318 |
val italic = GButton.toggle_button () |
| 319 |
val underline = GButton.toggle_button () |
| 320 |
val strikethrough = GButton.toggle_button () |
| 321 |
|
| 322 |
method set_tag tag = |
| 323 |
let track c but set = match c with |
| 324 |
| None -> set#set_active true |
| 325 |
| Some c -> |
| 326 |
set#set_active false; |
| 327 |
but#set_color (Gdk.Color.color_parse c) |
| 328 |
in |
| 329 |
track tag.tag_bg_color bg_color bg_unset; |
| 330 |
track tag.tag_fg_color fg_color fg_unset; |
| 331 |
bold#set_active tag.tag_bold; |
| 332 |
italic#set_active tag.tag_italic; |
| 333 |
underline#set_active tag.tag_underline; |
| 334 |
strikethrough#set_active tag.tag_strikethrough; |
| 335 |
|
| 336 |
method tag = |
| 337 |
let get but set = |
| 338 |
if set#active then None |
| 339 |
else Some (Gdk.Color.color_to_string but#color) |
| 340 |
in |
| 341 |
{ |
| 342 |
tag_bg_color = get bg_color bg_unset; |
| 343 |
tag_fg_color = get fg_color fg_unset; |
| 344 |
tag_bold = bold#active; |
| 345 |
tag_italic = italic#active; |
| 346 |
tag_underline = underline#active; |
| 347 |
tag_strikethrough = strikethrough#active; |
| 348 |
} |
| 349 |
|
| 350 |
initializer |
| 351 |
let box = new GPack.box box in |
| 352 |
let set_stock button stock = |
| 353 |
let stock = GMisc.image ~stock ~icon_size:`BUTTON () in |
| 354 |
button#set_image stock#coerce |
| 355 |
in |
| 356 |
let bprops button ?stock tooltip = |
| 357 |
(button :> GButton.button_skel), stock, tooltip |
| 358 |
in |
| 359 |
List.iter (fun (button, stock, tooltip) -> |
| 360 |
Option.iter (set_stock button) stock; |
| 361 |
button#set_tooltip_text tooltip; |
| 362 |
box#pack button#coerce; |
| 363 |
) [ |
| 364 |
bprops fg_color "Foreground color"; |
| 365 |
bprops fg_unset ~stock:`CANCEL "Disable foreground color"; |
| 366 |
bprops bg_color "Background color"; |
| 367 |
bprops bg_unset ~stock:`CANCEL "Disable background color"; |
| 368 |
bprops bold ~stock:`BOLD "Bold"; |
| 369 |
bprops italic ~stock:`ITALIC "Italic"; |
| 370 |
bprops underline ~stock:`UNDERLINE "Underline"; |
| 371 |
bprops strikethrough ~stock:`STRIKETHROUGH "Strikethrough"; |
| 372 |
]; |
| 373 |
let cb but obj = obj#set_sensitive (not but#active) in |
| 374 |
let _ = fg_unset#connect#toggled ~callback:(fun () -> cb fg_unset fg_color#misc) in |
| 375 |
let _ = bg_unset#connect#toggled ~callback:(fun () -> cb bg_unset bg_color#misc) in |
| 376 |
() |
| 377 |
|
| 378 |
end |
| 379 |
|
| 380 |
let tag_button () = |
| 381 |
let box = GPack.hbox () in |
| 382 |
new tag_button (Gobject.unsafe_cast box#as_widget) |
| 383 |
|
| 384 |
let current_section = ref None |
| 385 |
|
| 386 |
let configure ?(apply = fun () -> ()) parent = |
| 387 |
let file_format = |
| 388 |
create_pref_box ~in_grid:true "File format" [ |
| 389 |
pcombo "File charset encoding:" ~editable:true |
| 390 |
("UTF-8" :: "LOCALE" :: match encoding#get with Emanual s -> [s] | _ -> []) |
| 391 |
(encoding#repr#raw_from encoding#get) |
| 392 |
(fun _ s -> encoding#set (encoding#repr#raw_into s)); |
| 393 |
let values = [`DEFAULT; `UNIX; `WINDOWS] in |
| 394 |
let labels = ["Default"; {|Linux (\n)|}; {|Windows (\r\n)|}] in |
| 395 |
pcombo "EOL character:" labels |
| 396 |
(List.nth labels (match find_index_opt line_ending#get values with Some i -> i | _ -> 0)) |
| 397 |
(fun i _ -> line_ending#set (List.nth values i)); |
| 398 |
] |
| 399 |
in |
| 400 |
let global_auto_reload = |
| 401 |
create_pref_box "Global auto reload" [ |
| 402 |
pbool "Enable" global_auto_reload; |
| 403 |
pint "Delay (ms):" global_auto_reload_delay; |
| 404 |
] |
| 405 |
in |
| 406 |
let auto_save = |
| 407 |
create_pref_box "Auto save" [ |
| 408 |
pbool "Enable" auto_save; |
| 409 |
pint "Delay (ms):" auto_save_delay; |
| 410 |
] |
| 411 |
in |
| 412 |
|
| 413 |
let project_management = |
| 414 |
create_pref_box "Project management" [ |
| 415 |
pstring "Default name for project file:" project_file_name; |
| 416 |
pcombo "Project file options are" |
| 417 |
(List.map read_project#repr#raw_from [Subst_args; Append_args; Ignore_args]) |
| 418 |
(read_project#repr#raw_from read_project#get) |
| 419 |
(fun _ s -> read_project#set (read_project#repr#raw_into s)); |
| 420 |
]; |
| 421 |
in |
| 422 |
|
| 423 |
let editor_appearance = |
| 424 |
create_pref_box "Editor appearance" [ |
| 425 |
pbool "Dynamic word wrap" dynamic_word_wrap; |
| 426 |
pbool "Show line number" show_line_number; |
| 427 |
pbool "Highlight current line" highlight_current_line; |
| 428 |
pbool "Show right margin" show_right_margin; |
| 429 |
pbool "Show spaces" show_spaces; |
| 430 |
pbool "Show progress bar" show_progress_bar; |
| 431 |
] |
| 432 |
in |
| 433 |
let editor_behavior = |
| 434 |
create_pref_box "Editor behavior" [ |
| 435 |
pbool "Auto indentation" auto_indent; |
| 436 |
pbool "Insert spaces instead of tabs" spaces_instead_of_tabs; |
| 437 |
pbool "Unicode binding completion" unicode_binding; |
| 438 |
pbool "Auto completion" auto_complete; |
| 439 |
pint "Delay (ms):" ~max:5000 auto_complete_delay; |
| 440 |
pbool "Emacs/PG keybindings (μPG mode)" microPG; |
| 441 |
] |
| 442 |
in |
| 443 |
|
| 444 |
let config_window = |
| 445 |
create_pref_box ~in_grid:true "Window" [ |
| 446 |
pint "Width at startup:" window_width; |
| 447 |
pint "Height at startup:" window_height; |
| 448 |
] |
| 449 |
in |
| 450 |
let config_document_tabs = |
| 451 |
create_pref_box "Document tabs" [ |
| 452 |
let positions = ["top"; "left"; "right"; "bottom"] in |
| 453 |
let labels = ["Top"; "Left"; "Right"; "Bottom"] in |
| 454 |
let initial = List.nth labels |
| 455 |
(match find_index_opt document_tabs_pos#get positions with Some i -> i | _ -> 0) in |
| 456 |
let setter i _ = document_tabs_pos#set (List.nth positions i) in |
| 457 |
pcombo "Position:" labels initial setter; |
| 458 |
] |
| 459 |
in |
| 460 |
let config_message_tabs = |
| 461 |
create_pref_box "Message tabs" [ |
| 462 |
pbool "Cap message length" message_tab_capped; |
| 463 |
pint "Length limit" message_tab_length; |
| 464 |
] |
| 465 |
in |
| 466 |
|
| 467 |
let config_font = |
| 468 |
let preview_text = "Goal (∃n : nat, n ≤ 0)∧(∀x,y,z, x∈y⋃z↔x∈y∨x∈z)." in |
| 469 |
if Coq_config.arch <> "Darwin" then begin |
| 470 |
let box = GPack.hbox () in |
| 471 |
let font_sel = GMisc.font_selection ~preview_text:preview_text () in |
| 472 |
let realized = ref false in |
| 473 |
box#pack ~expand:true font_sel#coerce; |
| 474 |
let _ = font_sel#misc#connect#realize |
| 475 |
~callback:(fun () -> font_sel#set_font_name text_font#get; realized := true;) in |
| 476 |
{ label = "Text font"; box; apply = (fun () -> if !realized then text_font#set font_sel#font_name;) } |
| 477 |
end else begin |
| 478 |
|
| 479 |
let box = GPack.vbox () in |
| 480 |
box#set_height_request 200; |
| 481 |
box#set_height_request 300; |
| 482 |
let font_sel = GEdit.entry ~text:text_font#get () in |
| 483 |
box#pack ~expand:false font_sel#coerce; |
| 484 |
let text = GMisc.label ~text:preview_text () in |
| 485 |
text#set_ypad 10; |
| 486 |
box#pack ~expand:false text#coerce; |
| 487 |
let set_font () = |
| 488 |
let fd = GPango.font_description_from_string font_sel#text in |
| 489 |
text_font#set fd#to_string; |
| 490 |
text#misc#modify_font_by_name fd#to_string; |
| 491 |
font_sel#set_text fd#to_string; |
| 492 |
in |
| 493 |
text#misc#modify_font_by_name text_font#get; |
| 494 |
let _ = font_sel#connect#activate ~callback:set_font in |
| 495 |
{ label = "Text font"; box; apply = set_font } |
| 496 |
end |
| 497 |
in |
| 498 |
|
| 499 |
let config_highlight = |
| 500 |
let source_param text ids elem_get pref = |
| 501 |
let id_to_name id = |
| 502 |
match elem_get id with |
| 503 |
| Some elem -> elem#name |
| 504 |
| None -> id |
| 505 |
in |
| 506 |
let names = List.map id_to_name ids in |
| 507 |
let ids = Array.of_list ids in |
| 508 |
pcombo text names (id_to_name pref#get) (fun i _ -> pref#set ids.(i)) |
| 509 |
in |
| 510 |
create_pref_box ~in_grid:true "Highlight configuration" [ |
| 511 |
source_param "Style scheme:" style_manager#style_scheme_ids |
| 512 |
style_manager#style_scheme source_style; |
| 513 |
source_param "Language:" |
| 514 |
(List.filter (CString.is_prefix "coq") lang_manager#language_ids) |
| 515 |
lang_manager#language source_language; |
| 516 |
] |
| 517 |
in |
| 518 |
let config_color = |
| 519 |
let box = GPack.vbox () in |
| 520 |
let grid = GPack.grid |
| 521 |
~row_spacings:5 |
| 522 |
~col_spacings:5 |
| 523 |
~border_width:4 |
| 524 |
~packing:(box#pack ~expand:true) () |
| 525 |
in |
| 526 |
let reset_button = GButton.button ~label:"Reset" ~packing:box#pack () in |
| 527 |
let apply_list = ref [] in |
| 528 |
let _ = |
| 529 |
GMisc.label ~text:"Background" ~packing:(grid#attach ~left:1 ~top: 0) (), |
| 530 |
GMisc.label ~text:"Foreground" ~packing:(grid#attach ~left:2 ~top: 0) () |
| 531 |
in |
| 532 |
let iter i (text, prefs) = |
| 533 |
let top = i + 1 in |
| 534 |
(GMisc.label ~text ~packing:(grid#attach ~left:0 ~top) ())#set_halign `START; |
| 535 |
List.iteri (fun i pref -> |
| 536 |
let button = GButton.color_button |
| 537 |
~color:(Gdk.Color.color_parse pref#get) |
| 538 |
~packing:(grid#attach ~left:(i + 1) ~top) () |
| 539 |
in |
| 540 |
apply_list := (fun () -> pref#set (Gdk.Color.color_to_string button#color)) :: !apply_list; |
| 541 |
let _ = reset_button#connect#clicked ~callback:(fun () -> |
| 542 |
pref#reset (); |
| 543 |
button#set_color (Gdk.Color.color_parse pref#get); |
| 544 |
) |
| 545 |
in |
| 546 |
()) prefs; |
| 547 |
in |
| 548 |
let () = Util.List.iteri iter [ |
| 549 |
"Processed text", [processed_color]; |
| 550 |
"Text being processed", [processing_color]; |
| 551 |
"Incompletely processed Qed", [incompletely_processed_color]; |
| 552 |
"Unjustified conclusions", [unjustified_conclusion_color]; |
| 553 |
"Breakpoints", [breakpoint_color]; |
| 554 |
"Debugger stopping point", [db_stopping_point_color]; |
| 555 |
"Errors", [error_color; error_fg_color]; |
| 556 |
] in |
| 557 |
let label = "Color configuration" in |
| 558 |
{ label; box; apply = fun () -> List.iter (fun apply -> apply ()) !apply_list } |
| 559 |
in |
| 560 |
|
| 561 |
let config_tags = |
| 562 |
let box = GPack.vbox () in |
| 563 |
let scroll = GBin.scrolled_window |
| 564 |
~hpolicy:`NEVER |
| 565 |
~vpolicy:`AUTOMATIC |
| 566 |
~packing:(box#pack ~expand:true) |
| 567 |
() |
| 568 |
in |
| 569 |
let grid = GPack.grid |
| 570 |
~row_spacings:5 |
| 571 |
~col_spacings:5 |
| 572 |
~border_width:2 |
| 573 |
~packing:scroll#add_with_viewport () |
| 574 |
in |
| 575 |
let i = ref 0 in |
| 576 |
let cb = ref [] in |
| 577 |
let iter text tag = |
| 578 |
(GMisc.label ~text ~packing:(grid#attach ~left:0 ~top:!i) ())#set_halign `START; |
| 579 |
let button = tag_button () in |
| 580 |
let callback () = tag#set button#tag in |
| 581 |
button#set_tag tag#get; |
| 582 |
grid#attach ~left:1 ~top:!i button#coerce; |
| 583 |
incr i; |
| 584 |
cb := callback :: !cb; |
| 585 |
in |
| 586 |
Util.String.Map.iter iter (list_tags ()); |
| 587 |
let label = "Tag configuration" in |
| 588 |
let callback () = List.iter (fun f -> f ()) !cb in |
| 589 |
{ label; box; apply = callback } |
| 590 |
in |
| 591 |
|
| 592 |
let modifiers_valid_callbacks = ref [] in |
| 593 |
let modifiers_reg callback = |
| 594 |
modifiers_valid_callbacks := callback :: !modifiers_valid_callbacks |
| 595 |
in |
| 596 |
let allowed_mods = str_to_mod_list modifiers_valid#get in |
| 597 |
let modifiers_valid = |
| 598 |
create_pref_box "Allowed modifiers" [ |
| 599 |
pmodifiers "" all_modifiers ~callback:(fun value -> |
| 600 |
List.iter (fun callback -> callback value) !modifiers_valid_callbacks; |
| 601 |
) modifiers_valid; |
| 602 |
] |
| 603 |
in |
| 604 |
let config_modifiers = |
| 605 |
create_pref_box ~in_grid:true "Modifiers for menu item shortcuts" [ |
| 606 |
pmodifiers "View:" allowed_mods ~registerer:modifiers_reg modifier_for_display; |
| 607 |
pmodifiers "Navigation:" allowed_mods ~registerer:modifiers_reg modifier_for_navigation; |
| 608 |
pmodifiers "Templates:" allowed_mods ~registerer:modifiers_reg modifier_for_templates; |
| 609 |
pmodifiers "Queries:" allowed_mods ~registerer:modifiers_reg modifier_for_queries; |
| 610 |
|
| 611 |
] |
| 612 |
in |
| 613 |
|
| 614 |
let cmd_editor = |
| 615 |
let predefined = ["gedit %s"; "kate %s"; "emacs %s"; "vi %s"; "notepad %s"; "notepad++ %s"] in |
| 616 |
pstringcombo ~tooltip:"(%s for file name)" "External editor:" ~editable:true |
| 617 |
((if List.mem cmd_editor#get predefined then [] else [cmd_editor#get]) @ predefined) |
| 618 |
cmd_editor |
| 619 |
in |
| 620 |
let cmd_browse = |
| 621 |
let predefined = [Coq_config.browser; "firefox %s &"; "seamonkey %s &"; "chromium %s &"] in |
| 622 |
pstringcombo ~tooltip:"(%s for url)" "Browser:" ~editable:true |
| 623 |
((if List.mem cmd_browse#get predefined then [] else [cmd_browse#get]) @ predefined) |
| 624 |
cmd_browse |
| 625 |
in |
| 626 |
let externals_cmds = |
| 627 |
create_pref_box ~in_grid:true "Commands for external programs" [ |
| 628 |
ptextexpr "coqidetop:" |
| 629 |
(match cmd_rocqtop#get with | None -> "AUTO" | Some x -> x) |
| 630 |
(fun s -> cmd_rocqtop#set (if s = "AUTO" then None else Some s)); |
| 631 |
pstring "coqc:" cmd_rocqc; |
| 632 |
pstring "make:" cmd_make; |
| 633 |
pstring "coqmakefile:" cmd_rocqmakefile; |
| 634 |
pstring "coqdoc:" cmd_rocqdoc; |
| 635 |
pstring "Print ps:" cmd_print; |
| 636 |
cmd_editor; |
| 637 |
cmd_browse; |
| 638 |
] |
| 639 |
in |
| 640 |
|
| 641 |
let misc = |
| 642 |
create_pref_box "Miscellaneous" [ |
| 643 |
pbool "Stop interpreting before the current point" stop_before; |
| 644 |
pbool "Reset coqtop on tab switch" reset_on_tab_switch; |
| 645 |
] |
| 646 |
in |
| 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 |
let cmds = [ |
| 680 |
pref_section "Files" ~icon:`FLOPPY [file_format; global_auto_reload; auto_save] ~children:[ |
| 681 |
pref_section "Project" ~icon:`PAGE_SETUP [project_management]; |
| 682 |
]; |
| 683 |
pref_section "Editor" ~icon:`EDIT [editor_appearance; editor_behavior]; |
| 684 |
pref_section "Appearance" ~icon:`ZOOM_FIT [config_window; config_document_tabs; config_message_tabs] ~children:[ |
| 685 |
pref_section "Font" ~icon:`SELECT_FONT [config_font]; |
| 686 |
pref_section "Colors" ~icon:`SELECT_COLOR [config_highlight; config_color]; |
| 687 |
pref_section "Tags" ~icon:`SELECT_COLOR [config_tags]; |
| 688 |
]; |
| 689 |
pref_section "Shortcuts" ~icon:`MEDIA_FORWARD [modifiers_valid; config_modifiers]; |
| 690 |
pref_section "Externals" ~icon:`EXECUTE [externals_cmds]; |
| 691 |
pref_section "Misc" ~icon:`PREFERENCES [misc]; |
| 692 |
] |
| 693 |
in |
| 694 |
|
| 695 |
if edit_preferences ~apply ~parent ~current_section ~width:600 ~height:400 "Preferences" cmds then |
| 696 |
save_pref () |