shoes / shoes3

a tiny graphical app kit for ruby
http://walkabout.mvmanila.com
Other
179 stars 19 forks source link

Save or copy text in edit_box or line to an external file #425

Closed JDsnyke closed 5 years ago

JDsnyke commented 5 years ago

Using Shoes 3.3.7

How do I go about grabbing the text typed in an Edit_box and saving it to a file on a button click?

This is what i used. It created the file but it just stays empty...

Shoes.app do
  Stack do
    flow do
      new_box = edit_box "placeholdertext"
    end

    flow do
      button "Save" do
        note_save = ask_save_file
        File.open("#{note_save}", "a") do |copy|
          copy.para "#{new_box.text}"
        end
      end
    end
  end
end

Edit : setting code to,

copy.write(new_box.text)

Still creates a file with empty content

I'm pretty new to all this. Any help is appreciated 😊

ccoupe commented 5 years ago

Hi @JDsnyke You have copy.para "#{new_box.text}" copy is File object which doesn't have a para method. You probably want copy.write "#{new_box.text}\n" You may want a class variable @new_box = edit_box "placeholdertext" because new_box may not be in scope.

JDsnyke commented 5 years ago

@ccoupe

Works like a charm. Thanks!