class PopupFormGenerator
Public Class Methods
new(params = nil)
click to toggle source
# File lib/vimamsa/search_replace.rb, line 183 def initialize(params = nil) @window = Gtk::Window.new(:toplevel) # @window.screen = main_window.screen # @window.title = title # params = {} # params["inputs"] = {} # params["inputs"]["search"] = { :label => "Search", :type => :entry } # params["inputs"]["replace"] = { :label => "Replace", :type => :entry } # params["inputs"]["btn1"] = { :label => "Replace all", :type => :button } # params[:callback] = proc { |x| puts "====="; puts x.inspect; puts "=====" } @callback = params[:callback] @window.title = "" frame = Gtk::Frame.new() frame.margin = 8 @window.add(frame) # @window.title = params["title"] # @callback = params["callback"] infolabel = Gtk::Label.new # infolabel.markup = params["title"] vbox = Gtk::Box.new(:vertical, 8) vbox.margin = 8 frame.add(vbox) hbox = Gtk::Box.new(:horizontal, 8) # @window.add(hbox) @vals = {} for id, elem in params["inputs"] if elem[:type] == :button button = Gtk::Button.new(:label => elem[:label]) hbox.pack_start(button, :expand => false, :fill => false, :padding => 0) button.signal_connect "clicked" do submit end elsif elem[:type] == :entry label = Gtk::Label.new(elem[:label]) entry = Gtk::Entry.new hbox.pack_start(label, :expand => false, :fill => false, :padding => 0) hbox.pack_start(entry, :expand => false, :fill => false, :padding => 0) @vals[id] = entry entry.signal_connect("key_press_event") do |widget, event| if event.keyval == Gdk::Keyval::KEY_Return submit true elsif event.keyval == Gdk::Keyval::KEY_Escape @window.destroy true else false end end end end vbox.pack_start(hbox, :expand => false, :fill => false, :padding => 0) cancel_button = Gtk::Button.new(:label => "Cancel") cancel_button.signal_connect "clicked" do @window.destroy end 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 255 def run if !@window.visible? @window.show_all else @window.destroy end @window end
submit()
click to toggle source
# File lib/vimamsa/search_replace.rb, line 174 def submit() ret = {} for id, entry in @vals ret[id] = entry.text end @callback.call(ret) @window.destroy end