Permalink
Browse files

Add TextInputDialog and TextAreaDialog

  • Loading branch information...
1 parent 905b6ba commit 6c032c993f201ed56d4d1c83701850e8366e88e7 @mneumann committed Sep 27, 2010
Showing with 45 additions and 0 deletions.
  1. +45 −0 lib/wee/dialog.rb
View
@@ -106,6 +106,51 @@ def cancel
end
end # class SingleSelectionDialog
+ class TextInputDialog < Wee::FormDialog
+ attr_accessor :text
+
+ def initialize(caption=nil, text="", size=50)
+ super(caption)
+ @text = text
+ @size = size
+ end
+
+ def state(s) super
+ s.add_ivar(self, :@text)
+ end
+
+ def render_body(r)
+ r.text_input.size(@size).callback_method(:set_text).value(@text || "")
+ end
+
+ def set_text(text)
+ @text = text.strip
+ end
+
+ def buttons
+ [['Ok', nil, :ok, :ok], ['Cancel', nil, :cancel, :cancel]]
+ end
+
+ def ok
+ answer @text
+ end
+
+ def cancel
+ answer nil
+ end
+ end # class TextInputDialog
+
+ class TextAreaDialog < TextInputDialog
+ def initialize(caption=nil, text="", cols=50, rows=5)
+ super(caption, text, cols)
+ @rows = rows
+ end
+
+ def render_body(r)
+ r.text_area.cols(@size).rows(@rows).callback_method(:set_text).with(@text || "")
+ end
+ end # class TextAreaDialog
+
#
# Extend class Component with shortcuts for the dialogs above
#

0 comments on commit 6c032c9

Please sign in to comment.