Class: OneInputAction
- Inherits:
-
Object
- Object
- OneInputAction
- Defined in:
- lib/vimamsa/gui_dialog.rb
Instance Method Summary collapse
-
#initialize(main_window, title, field_label, button_title, callback, opt = {}) ⇒ OneInputAction
constructor
A new instance of OneInputAction.
- #run ⇒ Object
Constructor Details
#initialize(main_window, title, field_label, button_title, callback, opt = {}) ⇒ OneInputAction
Returns a new instance of OneInputAction.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/vimamsa/gui_dialog.rb', line 40 def initialize(main_window, title, field_label, , callback, opt = {}) @window = Gtk::Window.new() # @window.screen = main_window.screen # @window.title = title @window.title = "" frame = Gtk::Frame.new() # frame.margin = 20 @window.set_child(frame) infolabel = Gtk::Label.new infolabel.markup = title vbox = Gtk::Box.new(:vertical, 8) vbox.margin = 10 frame.set_child(vbox) hbox = Gtk::Box.new(:horizontal, 8) # @window.add(hbox) vbox.pack_end(infolabel, :expand => false, :fill => false, :padding => 0) vbox.pack_end(hbox, :expand => false, :fill => false, :padding => 0) = Gtk::Button.new(:label => ) = Gtk::Button.new(:label => "Cancel") label = Gtk::Label.new(field_label) @entry1 = Gtk::Entry.new if opt[:hide] @entry1.visibility = false end .signal_connect "clicked" do callback.call(@entry1.text) @window.destroy end .signal_connect "clicked" do @window.destroy end press = Gtk::EventControllerKey.new press.set_propagation_phase(Gtk::PropagationPhase::CAPTURE) @window.add_controller(press) press.signal_connect "key-pressed" do |gesture, keyval, keycode, y| if keyval == Gdk::Keyval::KEY_Return callback.call(@entry1.text) @window.destroy true elsif keyval == Gdk::Keyval::KEY_Escape @window.destroy true else false end end hbox.pack_end(label, :expand => false, :fill => false, :padding => 0) hbox.pack_end(@entry1, :expand => false, :fill => false, :padding => 0) hbox.pack_end(, :expand => false, :fill => false, :padding => 0) hbox.pack_end(, :expand => false, :fill => false, :padding => 0) return end |
Instance Method Details
#run ⇒ Object
105 106 107 108 109 110 111 112 |
# File 'lib/vimamsa/gui_dialog.rb', line 105 def run if !@window.visible? @window.show else @window.destroy end @window end |