Class: PopupFormGenerator
- Inherits:
-
Object
- Object
- PopupFormGenerator
- Defined in:
- lib/vimamsa/search_replace.rb
Overview
PopupFormGenerator.new().run
Instance Method Summary collapse
-
#initialize(params = nil) ⇒ PopupFormGenerator
constructor
A new instance of PopupFormGenerator.
- #run ⇒ Object
- #submit ⇒ Object
Constructor Details
#initialize(params = nil) ⇒ PopupFormGenerator
Returns a new instance of PopupFormGenerator.
182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 |
# File 'lib/vimamsa/search_replace.rb', line 182 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 = Gtk::Button.new(:label => elem[:label]) hbox.pack_start(, :expand => false, :fill => false, :padding => 0) .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 |, 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) = Gtk::Button.new(:label => "Cancel") .signal_connect "clicked" do @window.destroy end hbox.pack_start(, :expand => false, :fill => false, :padding => 0) return end |
Instance Method Details
#run ⇒ Object
254 255 256 257 258 259 260 261 |
# File 'lib/vimamsa/search_replace.rb', line 254 def run if !@window.visible? @window.show_all else @window.destroy end @window end |
#submit ⇒ Object
173 174 175 176 177 178 179 180 |
# File 'lib/vimamsa/search_replace.rb', line 173 def submit() ret = {} for id, entry in @vals ret[id] = entry.text end @callback.call(ret) @window.destroy end |