1. Technology
Send to a Friend via Email
You can opt-out at any time. Please refer to our privacy policy for contact information.

Are You Sure You Want to Exit? and Other Dialog Methods

By

5 of 5

Loading and Saving Files
Are You Sure You Want to Exit? and Other Dialog Methods

The two methods ask_load_file and ask_save_file provide an easy interface for selecting filenames to load from and save to. The following example creates a simple text editor with these dialogs, two buttons and an edit_box.

Shoes.app :width => 300 do
  flow do
    button "Load", :width => '50%' do
      file = ask_open_file
      @edit.text = File.read(file)
    end

    button "Save", :width => '50%' do
      file = ask_save_file
      File.open(file, "w+") do|f|
        f.write @edit.text
      end
    end
  end

  @edit = edit_box :width => '100%',
    :height => 500
end
  1. About.com
  2. Technology
  3. Ruby
  4. Graphical User Interfaces
  5. Shoes
  6. Loading and Saving Files

©2014 About.com. All rights reserved.