0

I've created a 'confirm exit' dialog box to prompt the user when exiting. I've successfully connected it to an 'exit' menu command, but I also want to connect it to the window-close (X) button. How can I do this? I've had some experience with Java Swing, and to accomplish this task you had to add a window listener to the frame that would call this prompt. Is there something similar I must do here?

Daniel Brady
  • 934
  • 3
  • 11
  • 27

1 Answers1

1

Do it like this:

require 'fox16'
include Fox

class MyApp < FXMainWindow
  def initialize(app)
    @app = app
    super(app, "Test", :height => 150, :width => 350, :opts=> DECOR_ALL)
    self.connect(SEL_CLOSE, method(:on_close))
  end

  def create
    super
    show(PLACEMENT_SCREEN)
  end

  def on_close(sender, sel, event)
    q = FXMessageBox.question(@app, MBOX_YES_NO, "Sure?", "You sure?")
    if q == MBOX_CLICKED_YES
      getApp().exit(0)
    end
  end
end

FXApp.new do |app|
  MyApp.new(app)
  app.create
  app.run
end
James Hibbard
  • 16,490
  • 14
  • 62
  • 74
  • A safer way to exit would be "getApp().exit(0)". I was using FXRegistry and if I exited with just "exit" it was never writing to disk. This solved it. – Swaathi Kakarla Jun 25 '15 at 02:26