Class: OneInputAction

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

Instance Method Summary collapse

Constructor Details

#initialize(main_window, title, field_label, button_title, callback) ⇒ OneInputAction

Returns a new instance of OneInputAction.



266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
# 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

Instance Method Details

#runObject



324
325
326
327
328
329
330
331
# File 'lib/vimamsa/search_replace.rb', line 324

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