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 104 105 106 107 108 |
# File 'lib/vimamsa/gui_dialog.rb', line 40 def initialize(main_window, title, field_label, , callback, opt = {}) @window = Gtk::Window.new() @window.set_transient_for($vmag.window) if $vmag&.window @window.modal = true # @window.screen = main_window.screen @window.title = "" # @window.width_request = 800 # @window.hexpand = false frame = Gtk::Frame.new() # frame.margin = 20 @window.set_child(frame) infolabel = Gtk::Label.new infolabel.markup = title infolabel.wrap = true infolabel.max_width_chars = 80 vbox = Gtk::Box.new(:vertical, 8) vbox.margin = 10 frame.set_child(vbox) hbox = Gtk::Box.new(:horizontal, 8) vbox.append(infolabel) vbox.append(hbox) = 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.append(label) hbox.append(@entry1) hbox.append() hbox.append() return end |
Instance Method Details
#run ⇒ Object
110 111 112 113 114 115 116 117 |
# File 'lib/vimamsa/gui_dialog.rb', line 110 def run if !@window.visible? @window.show else @window.destroy end @window end |