tags:

views:

249

answers:

2

When the window closes, the user is asked to save the file that they edited. They should also have an option to cancel quitting the application.

In WPF I can set the CancelEventArgs.Cancel property to true to do this. Is there an equivalent/workaround in Gtk#?

A: 

Found this python example (link) from a quick google search:

# When the window is requested to be closed, we need to check if they have 
# unsaved work. We use this callback to prompt the user to save their work 
# before they exit the application. From the "delete-event" signal, we can 
# choose to effectively cancel the close based on the value we return.
def on_window_delete_event(self, widget, event, data=None):

    if self.check_for_save(): self.on_save_menu_item_activate(None, None)
    return False # Propogate event

Hopefully this helps.

Steven
Setting DeleteEventArgs.RetVal to false prevents the application from exiting but the window still disappears and calling ShowAll does not show it again.
+2  A: 

You need to set the DeleteEventArgs.RetVal to true, not false. From the relevant Mono documentation:

To keep a Gtk.Window from closing, set Gtk.DeleteEventHandler's Gtk.DeleteEventArgs.RetVal to true.

Vinay Sajip