-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfile_diag.rb
41 lines (34 loc) · 1.05 KB
/
file_diag.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
#!/usr/bin/ruby -w
# -*- coding: utf-8 -*-
=begin
* Name: rplac open file dialog
* Description: open file dialog class
* Author: Murilo de Lima
* Date: 2009-11-20
* License:
rplac 0.1, Copyright (C) 2009 Joel Uchoa, Murilo de Lima
rplac comes with ABSOLUTELY NO WARRANTY; for detais see `gpl-2.0.txt'.
This is free software, and you are welcome to redistribute it
under certain conditions; see `gpl-2.0.txt' for details.
=end
require 'gtk2'
class OpenFileDialog
def initialize
@diag = Gtk::FileChooserDialog.new
@bt_cancel = @diag.add_button(Gtk::Stock::CANCEL, Gtk::Dialog::RESPONSE_CANCEL)
@bt_cancel.signal_connect('clicked') { @diag.destroy }
@bt_open = @diag.add_button(Gtk::Stock::OPEN, Gtk::Dialog::RESPONSE_ACCEPT)
@bt_open.signal_connect('clicked') do
# testing: open normal file, open directory, open nothing
fname = @diag.filename
if fname && !File.directory?(fname)
@callback.call(fname)
@diag.destroy
end
end
end
def show(&callback)
@diag.show
@callback = callback
end
end