Need help opening and saving a file with FileChooser


#1

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 T.


#2

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 T. removed_email_address@domain.invalid 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=sourceforge&CID=DEVDEV


ruby-gnome2-devel-en mailing list
removed_email_address@domain.invalid
https://lists.sourceforge.net/lists/listinfo/ruby-gnome2-devel-en


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=sourceforge&CID=DEVDEV