gtkvalagenie

How to fix two clicks in dialog


I've created a dialog to ask the user if he really want to proceed creating another file (text buffer). However, there is something with my approach that requires me to click twice at the button yes or at the button no.

What am I doing wrong?

The code for the specific function is:

def createnew ()
    var Hello=new MessageDialog (null, Gtk.DialogFlags.MODAL,
            Gtk.MessageType.INFO, Gtk.ButtonsType.YES_NO, "Hello world!")
    Hello.format_secondary_text ("This will delete the contets. Are you sure?")
    Hello.run ()

    case Hello.run()
        when ResponseType.YES
            _view.buffer.set_text("")
            Hello.destroy ()
        when ResponseType.NO
            Hello.destroy ()

The function is working fine otherwise.


Solution

  • You are calling Hello.run () twice. The fist time, you discard the result and the second time you use it for the case block.