mirror of
https://github.com/paparazzi/paparazzi.git
synced 2026-05-24 22:05:58 +08:00
Better handling of window title
This commit is contained in:
@@ -30,7 +30,19 @@ let if_none = fun f ->
|
||||
| None ->
|
||||
f ()
|
||||
|
||||
let save_fp = fun () ->
|
||||
let set_window_title = fun geomap ->
|
||||
let title_suffix =
|
||||
match !current_fp with
|
||||
None -> ""
|
||||
| Some (_fp, xml_file) -> sprintf " (%s)" (Filename.basename xml_file) in
|
||||
match GWindow.toplevel geomap#canvas with
|
||||
Some w ->
|
||||
w#set_title (sprintf "Flight Plan Editor%s" title_suffix)
|
||||
| None -> ()
|
||||
|
||||
|
||||
|
||||
let save_fp = fun geomap ->
|
||||
match !current_fp with
|
||||
None -> () (* Nothing to save *)
|
||||
| Some (fp, filename) ->
|
||||
@@ -40,9 +52,12 @@ let save_fp = fun () ->
|
||||
let f = open_out file in
|
||||
fprintf f "<!DOCTYPE flight_plan SYSTEM \"flight_plan.dtd\">\n\n";
|
||||
fprintf f "%s\n" (ExtXml.to_string_fmt fp#xml);
|
||||
close_out f
|
||||
close_out f;
|
||||
current_fp := Some (fp, file);
|
||||
set_window_title geomap
|
||||
|
||||
|
||||
let close_fp = fun () ->
|
||||
let close_fp = fun geomap ->
|
||||
match !current_fp with
|
||||
None -> () (* Nothing to close *)
|
||||
| Some (fp, _filename) ->
|
||||
@@ -50,11 +65,11 @@ let close_fp = fun () ->
|
||||
fp#destroy ();
|
||||
current_fp := None in
|
||||
match GToolbox.question_box ~title:"Closing flight plan" ~buttons:["Close"; "Save&Close"; "Cancel"] "Do you want to save/close ?" with
|
||||
2 -> save_fp (); close ()
|
||||
2 -> save_fp geomap; close ()
|
||||
| 1 -> close ()
|
||||
| _ -> ()
|
||||
|
||||
let load_xml_fp = fun geomap editor_frame accel_group ?(xml_file=Env.flight_plans_path) xml ->
|
||||
let load_xml_fp = fun geomap editor_frame _accel_group ?(xml_file=Env.flight_plans_path) xml ->
|
||||
Map2d.set_georef_if_none geomap (MapFP.georef_of_xml xml);
|
||||
let fp = new MapFP.flight_plan ~editable:true ~show_moved:false geomap "red" Env.flight_plan_dtd xml in
|
||||
editor_frame#add fp#window;
|
||||
@@ -63,7 +78,7 @@ let load_xml_fp = fun geomap editor_frame accel_group ?(xml_file=Env.flight_plan
|
||||
(** Add waypoints as geo references *)
|
||||
List.iter
|
||||
(fun w ->
|
||||
let (i, w) = fp#index w in
|
||||
let (_i, w) = fp#index w in
|
||||
geomap#add_info_georef (sprintf "%s" w#name) (w :> < pos : Latlong.geographic >))
|
||||
fp#waypoints;
|
||||
|
||||
@@ -121,15 +136,13 @@ let loading_error = fun xml_file e ->
|
||||
GToolbox.message_box "Error" m
|
||||
|
||||
|
||||
|
||||
let load_xml_file = fun geomap editor_frame accel_group xml_file ->
|
||||
try
|
||||
let xml = Xml.parse_file xml_file in
|
||||
ignore (load_xml_fp geomap editor_frame accel_group ~xml_file xml);
|
||||
geomap#fit_to_window ();
|
||||
match GWindow.toplevel geomap#canvas with
|
||||
Some w ->
|
||||
w#set_title (sprintf "%s (%s)" w#title (Filename.basename xml_file))
|
||||
| None -> ()
|
||||
set_window_title geomap
|
||||
with
|
||||
Dtd.Prove_error(e) -> loading_error xml_file (Dtd.prove_error e)
|
||||
| Dtd.Check_error(e) -> loading_error xml_file (Dtd.check_error e)
|
||||
@@ -194,7 +207,7 @@ let calibrate_map = fun (geomap:MapCanvas.widget) editor_frame accel_group () ->
|
||||
let cal = GButton.button ~stock:`OK ~packing:h#add () in
|
||||
let destroy = fun () ->
|
||||
dialog#destroy ();
|
||||
close_fp ();
|
||||
close_fp geomap;
|
||||
pix#destroy () in
|
||||
ignore(cancel#connect#clicked ~callback:destroy);
|
||||
ignore(cal#connect#clicked ~callback:(fun _ ->
|
||||
|
||||
@@ -3,5 +3,6 @@ val calibrate_map : MapCanvas.widget -> GBin.frame -> Gtk.accel_group -> unit ->
|
||||
val new_fp : MapCanvas.widget -> GBin.frame -> Gtk.accel_group -> unit -> unit
|
||||
val load_fp : MapCanvas.widget -> GBin.frame -> Gtk.accel_group -> unit -> unit
|
||||
val load_xml_file : MapCanvas.widget -> GBin.frame -> Gtk.accel_group -> string -> unit
|
||||
val save_fp : unit -> unit
|
||||
val close_fp : unit -> unit
|
||||
val save_fp : MapCanvas.widget -> unit
|
||||
val close_fp : MapCanvas.widget -> unit
|
||||
val set_window_title : MapCanvas.widget -> unit
|
||||
|
||||
@@ -226,7 +226,7 @@ let fill_ortho = fun (geomap:G.widget) ->
|
||||
|
||||
|
||||
(******* Mouse motion handling **********************************************)
|
||||
let motion_notify = fun (geomap:G.widget) ev -> false
|
||||
let motion_notify = fun (geomap:G.widget) _ev -> false
|
||||
|
||||
(******* Mouse wheel handling ***********************************************)
|
||||
let any_event = fun (geomap:G.widget) ev -> false
|
||||
@@ -394,8 +394,8 @@ let create_geomap = fun window switch_fullscreen editor_frame ->
|
||||
let fp_menu_fact = new GMenu.factory ~accel_group fp_menu in
|
||||
ignore (fp_menu_fact#add_item "New flight plan" ~key:GdkKeysyms._N ~callback:(EditFP.new_fp geomap editor_frame accel_group));
|
||||
ignore (fp_menu_fact#add_item "Open flight plan" ~key:GdkKeysyms._O ~callback:(EditFP.load_fp geomap editor_frame accel_group));
|
||||
ignore (fp_menu_fact#add_item "Save flight plan" ~key:GdkKeysyms._S ~callback:(EditFP.save_fp));
|
||||
ignore (fp_menu_fact#add_item "Close flight plan" ~key:GdkKeysyms._W ~callback:(EditFP.close_fp))
|
||||
ignore (fp_menu_fact#add_item "Save flight plan" ~key:GdkKeysyms._S ~callback:(fun () -> EditFP.save_fp geomap));
|
||||
ignore (fp_menu_fact#add_item "Close flight plan" ~key:GdkKeysyms._W ~callback:(fun () -> EditFP.close_fp geomap))
|
||||
end;
|
||||
|
||||
(** Help pushed to the right *)
|
||||
@@ -549,8 +549,7 @@ let () =
|
||||
match !wid with
|
||||
None ->
|
||||
let icon = GdkPixbuf.from_file Env.icon_file in
|
||||
let title = if !edit then "Flight Plan Editor" else "GCS" in
|
||||
let window = GWindow.window ~icon ~title ~border_width:1 ~width ~height ~allow_shrink:true () in
|
||||
let window = GWindow.window ~icon ~title:"GCS" ~border_width:1 ~width ~height ~allow_shrink:true () in
|
||||
if !maximize then
|
||||
window#maximize ();
|
||||
if !fullscreen then
|
||||
@@ -693,5 +692,8 @@ let () =
|
||||
else
|
||||
GToolbox.message_box "Error" (sprintf "Error: '%s' file does not exist\n%!" !file_to_edit);
|
||||
|
||||
if !edit then
|
||||
EditFP.set_window_title geomap;
|
||||
|
||||
(** Threaded main loop (map tiles loaded concurently) *)
|
||||
GtkThread.main ()
|
||||
|
||||
Reference in New Issue
Block a user