@@ -3,20 +3,24 @@ open Eio_trace
33let ( ==> ) signal callback =
44 ignore (signal ~callback : GtkSignal. id)
55
6+ let (let * ) = Result. bind
7+
68let ui_xml = {|
79< ui>
810 < popup name= 'PopupMenu '>
11+ < menuitem action= 'export- image' />
912 < menuitem action= 'viewport- set- start' />
1013 < menuitem action= 'viewport- set- duration' />
1114 < / popup>
1215< / ui>
1316| }
1417
1518let create ~title tracefile =
19+ let last_export = ref None in
1620 let actions = GAction. action_group ~name: " main" () in
1721 let ui = GAction. ui_manager () in
1822 ui#insert_action_group actions 0 ;
19- let _id : GAction.ui_id = ui#add_ui_from_string ui_xml; in
23+ let _id : GAction.ui_id = ui#add_ui_from_string ui_xml in
2024
2125 let window = GWindow. window () in
2226 window#add_accel_group ui#get_accel_group;
@@ -112,6 +116,50 @@ let create ~title tracefile =
112116 )
113117 in
114118
119+ let alert message =
120+ let dialog = GWindow. message_dialog ~title: " Error" ~buttons: GWindow.Buttons. ok ~message () in
121+ dialog#show () ;
122+ match dialog#run () with
123+ | `DELETE_EVENT | `OK -> dialog#destroy ()
124+ in
125+
126+ let save_image () =
127+ let dialog = GWindow. file_chooser_dialog ~title: " Export image" ~action: `SAVE ~parent: window () in
128+ begin match ! last_export with
129+ | None ->
130+ let dir = Filename. dirname tracefile in
131+ ignore (dialog#set_current_folder dir : bool );
132+ dialog#set_current_name ((Filename. basename tracefile |> Filename. remove_extension) ^ " .svg" )
133+ | Some path ->
134+ ignore (dialog#set_filename path : bool )
135+ end ;
136+ dialog#add_select_button_stock `SAVE `OK ;
137+ dialog#set_default_response `OK ;
138+ dialog#add_button_stock `CANCEL `CANCEL ;
139+ dialog#connect#response ==> (function
140+ | `DELETE_EVENT | `CANCEL ->
141+ dialog#destroy ()
142+ | `OK ->
143+ match
144+ match dialog#get_filenames with
145+ | [path] ->
146+ let * fmt = Save. format_of_string (Filename. extension path) in
147+ last_export := Some path;
148+ Save. export_image v fmt path
149+ | _ -> Error " Must select one path"
150+ with
151+ | Ok () -> dialog#destroy ()
152+ | Error msg -> alert msg
153+ );
154+ dialog#show () ;
155+ in
156+
157+ GAction. add_action " export-image" actions
158+ ~label: " Export image as..."
159+ ~accel: " <control>e"
160+ ~stock: `SAVE_AS
161+ ~callback: (fun _a -> save_image () );
162+
115163 GAction. add_action " viewport-set-start" actions
116164 ~label: " Set start time..."
117165 ~callback: (fun _a -> show_start () );
@@ -134,7 +182,8 @@ let create ~title tracefile =
134182 true
135183 ) else false
136184 ) else (
137- if keyval = GdkKeysyms. _s then (
185+ if GdkEvent.Key. state ev <> [] then false
186+ else if keyval = GdkKeysyms. _s then (
138187 show_start () ;
139188 true
140189 ) else if keyval = GdkKeysyms. _d then (
0 commit comments