class OneInputAction

Public Class Methods

new(main_window, title, field_label, button_title, callback) click to toggle source
# File lib/vimamsa/search_replace.rb, line 266
def initialize(main_window, title, field_label, button_title, callback)
  @window = Gtk::Window.new(:toplevel)
  # @window.screen = main_window.screen
  # @window.title = title
  @window.title = ""

  frame = Gtk::Frame.new()
  frame.margin = 8
  @window.add(frame)

  infolabel = Gtk::Label.new
  infolabel.markup = title

  vbox = Gtk::Box.new(:vertical, 8)
  vbox.margin = 8
  frame.add(vbox)

  hbox = Gtk::Box.new(:horizontal, 8)
  # @window.add(hbox)
  vbox.pack_start(infolabel, :expand => false, :fill => false, :padding => 0)
  vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0)

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

  label = Gtk::Label.new(field_label)

  @entry1 = Gtk::Entry.new

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

  cancel_button.signal_connect "clicked" do
    @window.destroy
  end

  @entry1.signal_connect("key_press_event") do |widget, event|
    if event.keyval == Gdk::Keyval::KEY_Return
      callback.call(@entry1.text)
      @window.destroy
      true
    elsif event.keyval == Gdk::Keyval::KEY_Escape
      @window.destroy
      true
    else
      false
    end
  end

  hbox.pack_start(label, :expand => false, :fill => false, :padding => 0)
  hbox.pack_start(@entry1, :expand => false, :fill => false, :padding => 0)
  hbox.pack_start(button, :expand => false, :fill => false, :padding => 0)
  hbox.pack_start(cancel_button, :expand => false, :fill => false, :padding => 0)
  return
end

Public Instance Methods

run() click to toggle source
# File lib/vimamsa/search_replace.rb, line 324
def run
  if !@window.visible?
    @window.show_all
  else
    @window.destroy
  end
  @window
end