1 (* Copyright (C) 2004, HELM Team.
3 * This file is part of HELM, an Hypertextual, Electronic
4 * Library of Mathematics, developed at the Computer Science
5 * Department, University of Bologna, Italy.
7 * HELM is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
12 * HELM is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with HELM; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
22 * For details, see the HELM World-Wide-Web page,
23 * http://helm.cs.unibo.it/
26 let toggle_visibility ~(win: GWindow.window) ~(check: GMenu.check_menu_item) =
27 ignore (check#connect#toggled (fun _ ->
28 if check#active then win#show () else win#misc#hide ()));
29 ignore (win#event#connect#delete (fun _ ->
31 check#set_active false;
34 let toggle_win ?(check: GMenu.check_menu_item option) (win: GWindow.window) () =
35 if win#is_active then win#misc#hide () else win#show ();
38 | Some check -> check#set_active (not check#active)
40 let add_key_binding key callback (evbox: GBin.event_box) =
41 ignore (evbox#event#connect#key_press (function
42 | key' when GdkEvent.Key.keyval key' = key ->
47 class stringListModel (tree_view: GTree.view) =
48 let column_list = new GTree.column_list in
49 let text_column = column_list#add Gobject.Data.string in
50 let list_store = GTree.list_store column_list in
54 let renderer = (GTree.cell_renderer_text [], ["text", text_column]) in
55 let view_column = GTree.view_column ~renderer () in
56 tree_view#set_model (Some (list_store :> GTree.model));
57 ignore (tree_view#append_column view_column)
59 method list_store = list_store
61 method easy_append s =
62 let tree_iter = list_store#append () in
63 list_store#set ~row:tree_iter ~column:text_column s
65 method easy_insert pos s =
66 let tree_iter = list_store#insert pos in
67 list_store#set ~row:tree_iter ~column:text_column s
69 method easy_selection () =
72 let iter = list_store#get_iter tree_path in
73 list_store#get ~row:iter ~column:text_column)
74 tree_view#selection#get_selected_rows
80 String.sub s (String.length s - 4) 4 = ".var"
81 with Invalid_argument _ -> false
83 let non p x = not (p x)
87 method newUriDialog: unit -> MatitaGeneratedGui.uriChoiceDialog
88 method newConfirmationDialog :
89 title:string -> msg:string -> unit ->
90 MatitaGeneratedGui.confirmationDialog
93 let interactive_user_uri_choice
94 ~(gui:#gui) ~(selection_mode:Gtk.Tags.selection_mode) ?(title = "")
95 ?(msg = "") ?(nonvars_button=false) uris
97 let nonvars_uris = lazy (List.filter (non is_var_uri) uris) in
98 if (selection_mode <> `SINGLE) &&
99 (Helm_registry.get_bool "matita.auto_disambiguation")
101 Lazy.force nonvars_uris
103 let dialog = gui#newUriDialog () in
104 dialog#uriChoiceTreeView#selection#set_mode selection_mode;
105 let model = new stringListModel dialog#uriChoiceTreeView in
106 let choices = ref None in
107 let nonvars = ref false in
108 dialog#uriChoiceDialog#set_title title;
109 dialog#uriChoiceLabel#set_text msg;
110 List.iter model#easy_append uris;
111 dialog#uriChoiceConstantsButton#misc#set_sensitive nonvars_button;
114 dialog#uriChoiceDialog#destroy ();
117 ignore (dialog#uriChoiceConstantsButton#connect#clicked (fun _ ->
118 return (Some (Lazy.force nonvars_uris))));
119 ignore (dialog#uriChoiceAutoButton#connect#clicked (fun _ ->
120 Helm_registry.set_bool "matita.auto_disambiguation" true;
121 return (Some (Lazy.force nonvars_uris))));
122 ignore (dialog#uriChoiceSelectedButton#connect#clicked (fun _ ->
123 match model#easy_selection () with
125 | uris -> return (Some uris)));
126 ignore (dialog#uriChoiceAbortButton#connect#clicked (fun _ -> return None));
127 ignore (dialog#uriChoiceDialog#event#connect#delete (fun _ -> true));
128 dialog#uriChoiceDialog#show ();
131 | None -> raise MatitaTypes.No_choice
135 let interactive_interp_choice ~(gui:#gui) choices =
136 (* TODO Zack implement interactive_interp_choice *)
138 "'interactive_interp_choice' not implemented: returning 1st interpretation";
141 let ask_confirmation ~(gui:#gui) ?(title = "") ?(msg = "") () =
142 let dialog = gui#newConfirmationDialog ~title ~msg () in
143 let result = ref None in
146 dialog#confirmationDialog#destroy ();
149 ignore (dialog#confirmationDialogOkButton#connect#clicked (return true));
150 ignore (dialog#confirmationDialogCancelButton#connect#clicked (return false));
151 ignore (dialog#confirmationDialog#event#connect#delete (fun _ -> true));
152 dialog#confirmationDialog#show ();
154 (match !result with None -> assert false | Some r -> r)