Maj terminée. Pour consulter la release notes associée voici le lien :
https://about.gitlab.com/releases/2021/07/07/critical-security-release-gitlab-14-0-4-released/

Commit 964d077e authored by Sylvain Dailler's avatar Sylvain Dailler
Browse files

Added the modifiable label in source_view_table and a ref to a boolean

which holds the changed state of the source file.
To be improved.
parent 4a274c43
...@@ -255,21 +255,40 @@ let exit_function_unsafe () = ...@@ -255,21 +255,40 @@ let exit_function_unsafe () =
send_request Exit_req; send_request Exit_req;
GMain.quit () GMain.quit ()
(* Contains a quadruplets (tab page, source_view, file_has_been_modified, label_of_tab) *)
let source_view_table : (int * GSourceView2.source_view * bool ref * GMisc.label) Hstr.t =
Hstr.create 14
let save_sources () =
Hstr.iter
(fun k (_n, (s: GSourceView2.source_view), b, _l) ->
if !b then
let text_to_save = s#source_buffer#get_text () in
send_request (Save_file_req (k, text_to_save))
)
source_view_table
(* True if some files need saving *)
let files_need_saving () =
Hstr.fold (fun _k (_, _, b, _) acc -> !b || acc) source_view_table false
(* Ask if the user wants to save session before exit *) (* Ask if the user wants to save session before exit *)
let exit_function_safe () = let exit_function_safe () =
if not !session_needs_saving then exit_function_unsafe () else if not !session_needs_saving && not (files_need_saving ()) then
let answer = exit_function_unsafe ()
GToolbox.question_box else
~title:"Why3 saving session" let answer =
~buttons:["Yes"; "No"; "Cancel"] GToolbox.question_box
"Do you want to save the session?" ~title:"Why3 saving session and files"
in ~buttons:["Yes"; "No"; "Cancel"]
begin "Do you want to save the session and unsaved files?"
match answer with in
| 1 -> send_request Save_req; quit_on_saved := true begin
| 2 -> exit_function_unsafe () match answer with
| _ -> () | 1 -> save_sources(); send_request Save_req; quit_on_saved := true
end | 2 -> exit_function_unsafe ()
| _ -> ()
end
let (_ : GtkSignal.id) = main_window#connect#destroy let (_ : GtkSignal.id) = main_window#connect#destroy
~callback:exit_function_safe ~callback:exit_function_safe
...@@ -527,18 +546,28 @@ let task_view = ...@@ -527,18 +546,28 @@ let task_view =
~packing:scrolled_task_view#add ~packing:scrolled_task_view#add
() ()
let source_view_table : (int * GSourceView2.source_view) Hstr.t = (* Update name of the tab when the label changes so that it has a * as prefix *)
Hstr.create 14 let update_label_change (label: GMisc.label) =
let s = label#text in
if not (Strings.has_prefix "*" s) then
label#set_text ("*" ^ s)
(* Update name of the tab when the label is saved. Removes * prefix *)
let update_label_saved (label: GMisc.label) =
let s = label#text in
if (Strings.has_prefix "*" s) then
label#set_text (String.sub s 1 (String.length s - 1))
let create_source_view = let create_source_view =
let n = ref 1 in let n = ref 1 in
let create_source_view f content = let create_source_view f content =
if not (Hstr.mem source_view_table f) then if not (Hstr.mem source_view_table f) then
begin begin
let label = GMisc.label ~text:f () in
let source_page, scrolled_source_view = let source_page, scrolled_source_view =
let label = GMisc.label ~text:f () in
!n, GPack.vbox ~homogeneous:false ~packing: !n, GPack.vbox ~homogeneous:false ~packing:
(fun w -> ignore(notebook#append_page ~tab_label:label#coerce w)) () in (fun w -> ignore(notebook#append_page ~tab_label:label#coerce w)) ()
in
let scrolled_source_view = let scrolled_source_view =
GBin.scrolled_window GBin.scrolled_window
~hpolicy: `AUTOMATIC ~vpolicy: `AUTOMATIC ~hpolicy: `AUTOMATIC ~vpolicy: `AUTOMATIC
...@@ -554,9 +583,21 @@ let create_source_view = ...@@ -554,9 +583,21 @@ let create_source_view =
~editable:true ~editable:true
~packing:scrolled_source_view#add ~packing:scrolled_source_view#add
() in () in
Hstr.add source_view_table f (source_page, source_view); let has_changed = ref false in
Hstr.add source_view_table f (source_page, source_view, has_changed, label);
n := !n + 1; n := !n + 1;
source_view#source_buffer#set_text content; source_view#source_buffer#set_text content;
(* At initialization, file has not changed. When it changes, changes the
name of the tab and update has_changed boolean. *)
let (_: GtkSignal.id) = source_view#source_buffer#connect#changed
~callback:(fun () ->
try
let _source_page, _source_view, has_changed, label =
Hstr.find source_view_table f in
update_label_change label;
has_changed := true;
()
with Not_found -> () ) in
Gconfig.add_modifiable_mono_font_view source_view#misc; Gconfig.add_modifiable_mono_font_view source_view#misc;
source_view#source_buffer#set_language why_lang; source_view#source_buffer#set_language why_lang;
Gconfig.set_fonts () Gconfig.set_fonts ()
...@@ -983,14 +1024,6 @@ let (_ : GMenu.menu_item) = ...@@ -983,14 +1024,6 @@ let (_ : GMenu.menu_item) =
exp_factory#add_item ~key:GdkKeysyms._D exp_factory#add_item ~key:GdkKeysyms._D
~callback:detached_copy "Detached copy" ~callback:detached_copy "Detached copy"
let save_sources () =
Hstr.iter
(fun k (_n, (s: GSourceView2.source_view)) ->
let text_to_save = s#source_buffer#get_text () in
send_request (Save_file_req (k, text_to_save))
)
source_view_table
(* TODO replace this with menu items *) (* TODO replace this with menu items *)
let (_ : GMenu.menu_item) = let (_ : GMenu.menu_item) =
exp_factory#add_item ~key:GdkKeysyms._X "Save files" exp_factory#add_item ~key:GdkKeysyms._X "Save files"
...@@ -1060,7 +1093,17 @@ let treat_message_notification msg = match msg with ...@@ -1060,7 +1093,17 @@ let treat_message_notification msg = match msg with
| Task_Monitor (t, s, r) -> update_monitor t s r | Task_Monitor (t, s, r) -> update_monitor t s r
| Open_File_Error s -> print_message "%s" s | Open_File_Error s -> print_message "%s" s
| Parse_Or_Type_Error s -> print_message "%s" s | Parse_Or_Type_Error s -> print_message "%s" s
| File_Saved s -> print_message "%s was saved" s | File_Saved f ->
begin
try
let (_source_page, _source_view, b, l) = Hstr.find source_view_table f in
b := false;
update_label_saved l;
print_message "%s was saved" f
with
| Not_found ->
print_message "Please report: %s was not found in ide but was saved in session" f
end
| Error s -> | Error s ->
if Debug.test_flag debug then if Debug.test_flag debug then
print_message "%s" s print_message "%s" s
...@@ -1164,8 +1207,10 @@ let treat_notification n = ...@@ -1164,8 +1207,10 @@ let treat_notification n =
| File_contents (file_name, content) -> | File_contents (file_name, content) ->
begin begin
try try
let (_, sc_view) = Hstr.find source_view_table file_name in let (_, sc_view, b, l) = Hstr.find source_view_table file_name in
sc_view#source_buffer#set_text content sc_view#source_buffer#set_text content;
update_label_saved l;
b := false;
with with
| Not_found -> create_source_view file_name content | Not_found -> create_source_view file_name content
end end
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment