Forum: Ruby-Gnome 2 Need help opening and saving a file with FileChooser

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
703cd1224835ae3acb7a4d2724001bd5?d=identicon&s=25 David Torres (verbena1)
on 2007-03-26 06:12
I have a question about using ruby and ruby-gtk2.  I have a simple gui
and am using SourceView as my text buffer and have added a menu to open
and save files.  My question is how in the world to I open a file and
display it within my buffer?

so far my open method is:

callback_open = Proc.new {
      p "Open is called."
      dialog = FileChooserDialog.new("Open File",nil,
                                     FileChooser::ACTION_OPEN,nil,
                                     [Stock::CANCEL,Dialog::RESPONSE_CANCEL],
                                     [Stock::OPEN,Dialog::RESPONSE_ACCEPT])
      if dialog.run == Dialog::RESPONSE_ACCEPT
        @filename = #{dialog.filename}
        file = File.open(@filename)

}

after the file variable line I have tried different things to actually
add the text to the buffer but none seem to work.  I checked the API but
I'm not sure if their is a TextBuffer method that I can use to read in
the file line by line or if I just call File.open and pass the filename
and rad it line by line.  When
I try to do that it outputs the text in the console not in my buffer.

Any help would be appreciated.

David Torres
0b039467c8c19aaef7d8f2a1b717435a?d=identicon&s=25 Mac Tuitui (Guest)
on 2007-03-26 06:47
(Received via mailing list)
I believe something along a call to the following open_file will do the
trick.


def read_file
  File.open(@filename){|f| ret = f.readlines.join }
end

def open_file
  text = read_file
  @buffer.text= text
end

view = Gtk::TextView.new
@buffer = view.buffer


There is a simple texteditor on the home page (section samples). It may
help.

Alexis

On 3/26/07, David Torres <ruby-forum-incoming@andreas-s.net> wrote:
>                                      FileChooser::ACTION_OPEN,nil,
> I'm not sure if their is a TextBuffer method that I can use to read in
>
> -------------------------------------------------------------------------
> Take Surveys. Earn Cash. Influence the Future of IT
> Join SourceForge.net's Techsay panel and you'll get the chance to share your
> opinions on IT & business topics through brief surveys-and earn cash
> http://www.techsay.com/default.php?page=join.php&p...
> _______________________________________________
> ruby-gnome2-devel-en mailing list
> ruby-gnome2-devel-en@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/ruby-...
>

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share
your
opinions on IT & business topics through brief surveys-and earn cash
http://www.techsay.com/default.php?page=join.php&p...
This topic is locked and can not be replied to.