Class: OneInputAction

Inherits:
Object
  • Object
show all
Defined in:
lib/vimamsa/gui_dialog.rb

Instance Method Summary collapse

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
# File 'lib/vimamsa/gui_dialog.rb', line 40

def initialize(main_window, title, field_label, button_title, callback, opt = {})
  @window = Gtk::Window.new()
  # @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)

  button = Gtk::Button.new(:label => button_title)
  cancel_button = Gtk::Button.new(:label => "Cancel")

  label = Gtk::Label.new(field_label)

  @entry1 = Gtk::Entry.new

  if opt[:hide]
    @entry1.visibility = false
  end

  button.signal_connect "clicked" do
    callback.call(@entry1.text)
    @window.destroy
  end

  cancel_button.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(button)
  hbox.append(cancel_button)
  return
end

Instance Method Details

#runObject



108
109
110
111
112
113
114
115
# File 'lib/vimamsa/gui_dialog.rb', line 108

def run
  if !@window.visible?
    @window.show
  else
    @window.destroy
  end
  @window
end