ruby_mvc 0.0.1 → 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +14 -0
- data/lib/ruby_mvc.rb +3 -1
- data/lib/ruby_mvc/application.rb +52 -2
- data/lib/ruby_mvc/controllers.rb +28 -0
- data/lib/ruby_mvc/controllers/action.rb +93 -0
- data/lib/ruby_mvc/controllers/action_group.rb +70 -0
- data/lib/ruby_mvc/controllers/app_controller.rb +4 -2
- data/lib/ruby_mvc/controllers/rails_controller.rb +2 -0
- data/lib/ruby_mvc/models.rb +2 -0
- data/lib/ruby_mvc/models/ar_table_model.rb +133 -0
- data/lib/ruby_mvc/models/array_table_model.rb +81 -13
- data/lib/ruby_mvc/models/keyed_array_table_model.rb +1 -1
- data/lib/ruby_mvc/models/model.rb +129 -0
- data/lib/ruby_mvc/models/table_model.rb +107 -10
- data/lib/ruby_mvc/models/view_model_template.rb +140 -0
- data/lib/ruby_mvc/renderers.rb +1 -0
- data/lib/ruby_mvc/renderers/html4_table_model_renderer.rb +7 -6
- data/lib/ruby_mvc/renderers/hyperlink_cell_renderer.rb +47 -0
- data/lib/ruby_mvc/toolkit.rb +5 -1
- data/lib/ruby_mvc/toolkit/browser_history.rb +115 -0
- data/lib/ruby_mvc/toolkit/dialog.rb +12 -1
- data/lib/ruby_mvc/toolkit/frame.rb +3 -1
- data/lib/ruby_mvc/toolkit/grid_view.rb +46 -0
- data/lib/ruby_mvc/toolkit/messagebox.rb +32 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby.rb +5 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/app.rb +23 -2
- data/lib/ruby_mvc/toolkit/peers/wxruby/common.rb +11 -1
- data/lib/ruby_mvc/toolkit/peers/wxruby/dialog.rb +82 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/form_builder.rb +108 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/frame.rb +85 -1
- data/lib/ruby_mvc/toolkit/peers/wxruby/grid_model.rb +79 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/grid_view.rb +117 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/messagebox.rb +58 -0
- data/lib/ruby_mvc/toolkit/peers/wxruby/web_view.rb +40 -10
- data/lib/ruby_mvc/toolkit/property_change_notifier.rb +46 -0
- data/lib/ruby_mvc/toolkit/signal_handler.rb +149 -0
- data/lib/ruby_mvc/toolkit/web_view.rb +1 -1
- data/lib/ruby_mvc/toolkit/widget.rb +13 -6
- data/lib/ruby_mvc/views.rb +8 -59
- data/lib/ruby_mvc/views/{ar_type_list.rb → ar_form_view.rb} +10 -13
- data/lib/ruby_mvc/views/ar_support.rb +29 -0
- data/lib/ruby_mvc/views/ar_type_editor.rb +17 -28
- data/lib/ruby_mvc/views/ar_web_model_view.rb +59 -0
- data/lib/ruby_mvc/views/ar_web_type_list.rb +44 -0
- data/lib/ruby_mvc/views/browser_view.rb +185 -0
- data/lib/ruby_mvc/views/form_view.rb +111 -0
- data/lib/ruby_mvc/views/grid_table_view.rb +96 -0
- data/lib/ruby_mvc/views/table_view.rb +0 -39
- data/lib/ruby_mvc/views/view.rb +121 -0
- data/lib/ruby_mvc/views/web_content_table_view.rb +40 -0
- data/lib/ruby_mvc/views/{web_view.rb → web_content_view.rb} +17 -28
- data/lib/ruby_mvc/views/web_model_view.rb +67 -0
- data/ruby_mvc.gemspec +1 -1
- data/sample/browser_view.rb +57 -0
- data/sample/form.rb +59 -0
- data/sample/form2.rb +63 -0
- data/sample/grid_table_view.rb +68 -0
- data/sample/grid_view.rb +44 -0
- data/sample/grid_view2.rb +57 -0
- data/sample/test.html +1 -0
- data/sample/test2.html +33 -0
- data/sample/web_view.rb +4 -0
- data/test/unit/models/test_array_table_model.rb +19 -3
- data/test/unit/models/test_keyed_array_table_model.rb +3 -2
- data/test/unit/models/test_model.rb +88 -0
- metadata +39 -20
- data/lib/ruby_mvc/toolkit/notification.rb +0 -202
- data/lib/ruby_mvc/views/ar_model_editor.rb +0 -84
data/lib/ruby_mvc/renderers.rb
CHANGED
@@ -47,16 +47,17 @@ module RubyMVC
|
|
47
47
|
:valign => "top"
|
48
48
|
}.freeze
|
49
49
|
|
50
|
-
def self.render(model,
|
51
|
-
self.new.render(model,
|
50
|
+
def self.render(model, options = {})
|
51
|
+
self.new.render(model, options)
|
52
52
|
end
|
53
53
|
|
54
|
-
def render(model,
|
54
|
+
def render(model, options = {})
|
55
55
|
options = OPTIONS.merge(options)
|
56
56
|
tagz {
|
57
57
|
table_(options) {
|
58
|
-
|
59
|
-
model
|
58
|
+
labels = model.labels
|
59
|
+
build_header(model, labels, options)
|
60
|
+
model.each { |row| build_row(labels, row) }
|
60
61
|
}
|
61
62
|
}
|
62
63
|
end
|
@@ -81,7 +82,7 @@ module RubyMVC
|
|
81
82
|
tagz.concat r.render(self, row, col)
|
82
83
|
else
|
83
84
|
data = row[col[:key]]
|
84
|
-
style = TD_OPTIONS.merge(col[:style])
|
85
|
+
style = TD_OPTIONS.merge(col[:style] || {})
|
85
86
|
weight = style.delete(:weight)
|
86
87
|
td_(style) {
|
87
88
|
if weight == "bold"
|
@@ -0,0 +1,47 @@
|
|
1
|
+
#--
|
2
|
+
######################################################################
|
3
|
+
#
|
4
|
+
# Copyright 2011-2012 Andrew S. Townley
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and disribute this software for
|
7
|
+
# any purpose with or without fee is hereby granted, provided that
|
8
|
+
# the above copyright notices and this permission notice appear in
|
9
|
+
# all copies.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
|
12
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
13
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
14
|
+
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
|
15
|
+
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
20
|
+
# File: hyperlink_cell_renderer.rb
|
21
|
+
# Created: Mon 9 Jan 2012 17:47:19 GMT
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
require 'tagz'
|
27
|
+
|
28
|
+
module RubyMVC
|
29
|
+
module Renderers
|
30
|
+
|
31
|
+
class HyperlinkCellRenderer
|
32
|
+
include Tagz
|
33
|
+
|
34
|
+
def render(widget, row, col)
|
35
|
+
lk = col[:hl_label_key] || col[:key]
|
36
|
+
text = row[lk]
|
37
|
+
val = row[col[:key]]
|
38
|
+
tagz {
|
39
|
+
td_ {
|
40
|
+
a_ text, :href => "#{col[:href]}#{val}"
|
41
|
+
}
|
42
|
+
}
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
end
|
data/lib/ruby_mvc/toolkit.rb
CHANGED
@@ -23,9 +23,13 @@
|
|
23
23
|
#####################################################################
|
24
24
|
#++
|
25
25
|
|
26
|
-
require 'ruby_mvc/toolkit/
|
26
|
+
require 'ruby_mvc/toolkit/signal_handler'
|
27
|
+
require 'ruby_mvc/toolkit/property_change_notifier'
|
27
28
|
require 'ruby_mvc/toolkit/widget'
|
28
29
|
require 'ruby_mvc/toolkit/app'
|
29
30
|
require 'ruby_mvc/toolkit/dialog'
|
31
|
+
require 'ruby_mvc/toolkit/messagebox'
|
30
32
|
require 'ruby_mvc/toolkit/frame'
|
33
|
+
require 'ruby_mvc/toolkit/browser_history'
|
31
34
|
require 'ruby_mvc/toolkit/web_view'
|
35
|
+
require 'ruby_mvc/toolkit/grid_view'
|
@@ -0,0 +1,115 @@
|
|
1
|
+
#--
|
2
|
+
######################################################################
|
3
|
+
#
|
4
|
+
# Copyright 2008-2012 Andrew S. Townley
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and disribute this software for
|
7
|
+
# any purpose with or without fee is hereby granted, provided that
|
8
|
+
# the above copyright notices and this permission notice appear in
|
9
|
+
# all copies.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
|
12
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
13
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
14
|
+
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
|
15
|
+
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
20
|
+
# File: browser_history.rb
|
21
|
+
# Created: Sun Oct 19 17:08:26 IST 2008
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module RubyMVC
|
27
|
+
module Toolkit
|
28
|
+
|
29
|
+
# This class provides a mechanism for tracking browser
|
30
|
+
# history operations where the underlying peer controls
|
31
|
+
# don't do this well enough for our purposes (yes, I'm
|
32
|
+
# looking at you Wx::HtmlWindow...)
|
33
|
+
|
34
|
+
class BrowserHistory
|
35
|
+
def initialize(maxsize = 100)
|
36
|
+
@mutex = Mutex.new
|
37
|
+
@history = []
|
38
|
+
@maxsize = maxsize
|
39
|
+
@index = 0
|
40
|
+
end
|
41
|
+
|
42
|
+
def <<(entry)
|
43
|
+
@mutex.synchronize {
|
44
|
+
return if @history[-1] == entry
|
45
|
+
if @history.size >= @maxsize
|
46
|
+
@history.delete(0)
|
47
|
+
else
|
48
|
+
@history = @history[0..@index]
|
49
|
+
end
|
50
|
+
@history << entry if @history[-1] != entry
|
51
|
+
@index = @history.size - 1
|
52
|
+
# dump_history
|
53
|
+
}
|
54
|
+
end
|
55
|
+
|
56
|
+
def current
|
57
|
+
@mutex.synchronize { @history[@index] }
|
58
|
+
end
|
59
|
+
|
60
|
+
def has_prev?
|
61
|
+
@index > 0
|
62
|
+
end
|
63
|
+
|
64
|
+
def has_next?
|
65
|
+
@index < @history.size - 1
|
66
|
+
end
|
67
|
+
|
68
|
+
def prev
|
69
|
+
@mutex.synchronize {
|
70
|
+
if has_prev?
|
71
|
+
@index -= 1
|
72
|
+
end
|
73
|
+
# dump_history
|
74
|
+
}
|
75
|
+
current
|
76
|
+
end
|
77
|
+
|
78
|
+
def next
|
79
|
+
@mutex.synchronize {
|
80
|
+
if has_next?
|
81
|
+
@index += 1
|
82
|
+
end
|
83
|
+
# dump_history
|
84
|
+
}
|
85
|
+
current
|
86
|
+
end
|
87
|
+
|
88
|
+
def each(&block)
|
89
|
+
@mutex.synchronize {
|
90
|
+
@history.each(&block)
|
91
|
+
}
|
92
|
+
end
|
93
|
+
|
94
|
+
def reverse_each(&block)
|
95
|
+
@mutex.synchronize {
|
96
|
+
@history.reverse_each(&block)
|
97
|
+
}
|
98
|
+
end
|
99
|
+
|
100
|
+
private
|
101
|
+
def dump_history
|
102
|
+
puts "HISTORY ---"
|
103
|
+
@history.each_index do |index|
|
104
|
+
if @index == index
|
105
|
+
puts ">> #{@history[index]}"
|
106
|
+
else
|
107
|
+
puts " #{@history[index]} "
|
108
|
+
end
|
109
|
+
end
|
110
|
+
puts "---"
|
111
|
+
end
|
112
|
+
end
|
113
|
+
|
114
|
+
end
|
115
|
+
end
|
@@ -26,6 +26,17 @@
|
|
26
26
|
module RubyMVC
|
27
27
|
module Toolkit
|
28
28
|
|
29
|
-
class Dialog < Widget
|
29
|
+
class Dialog < Widget
|
30
|
+
def add(w)
|
31
|
+
# FIXME: this is a cheezy way to do this...
|
32
|
+
if w.is_a? RubyMVC::Views::FormView
|
33
|
+
peer.add_form(w)
|
34
|
+
elsif w.is_a? RubyMVC::Views::View
|
35
|
+
peer.add_view(w)
|
36
|
+
else
|
37
|
+
peer.add(w)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
30
41
|
end
|
31
42
|
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
#--
|
2
|
+
######################################################################
|
3
|
+
#
|
4
|
+
# Copyright 2011 Andrew S. Townley
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and disribute this software for
|
7
|
+
# any purpose with or without fee is hereby granted, provided that
|
8
|
+
# the above copyright notices and this permission notice appear in
|
9
|
+
# all copies.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
|
12
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
13
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
14
|
+
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
|
15
|
+
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
20
|
+
# File: grid_view.rb
|
21
|
+
# Created: Sat 31 Dec 2011 18:59:06 CET
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module RubyMVC
|
27
|
+
module Toolkit
|
28
|
+
|
29
|
+
class GridView < Widget
|
30
|
+
api_methods :model=, :editable=, :selected_rows
|
31
|
+
|
32
|
+
# This method is used to inform the listener that the
|
33
|
+
# specified row in the view was "activated" (normally, a
|
34
|
+
# double-click on the row). Arguments are the sender,
|
35
|
+
# the model, the row and the column activated.
|
36
|
+
|
37
|
+
signal "row-activated"
|
38
|
+
|
39
|
+
# This method is used to monitor changes in the selected
|
40
|
+
# rows of the grid. Arguments are the sender, the model
|
41
|
+
# and the row indexes selected.
|
42
|
+
|
43
|
+
signal "row-selection-changed"
|
44
|
+
end
|
45
|
+
end
|
46
|
+
end
|
@@ -0,0 +1,32 @@
|
|
1
|
+
#--
|
2
|
+
######################################################################
|
3
|
+
#
|
4
|
+
# Copyright 2011-2012 Andrew S. Townley
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and disribute this software for
|
7
|
+
# any purpose with or without fee is hereby granted, provided that
|
8
|
+
# the above copyright notices and this permission notice appear in
|
9
|
+
# all copies.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
|
12
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
13
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
14
|
+
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
|
15
|
+
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
20
|
+
# File: messagebox.rb
|
21
|
+
# Created: Mon 9 Jan 2012 11:39:56 GMT
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module RubyMVC
|
27
|
+
module Toolkit
|
28
|
+
|
29
|
+
class MessageBox < Widget
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
@@ -26,6 +26,11 @@
|
|
26
26
|
require 'wx'
|
27
27
|
|
28
28
|
require 'ruby_mvc/toolkit/peers/wxruby/common'
|
29
|
+
require 'ruby_mvc/toolkit/peers/wxruby/form_builder'
|
29
30
|
require 'ruby_mvc/toolkit/peers/wxruby/app'
|
31
|
+
require 'ruby_mvc/toolkit/peers/wxruby/dialog'
|
32
|
+
require 'ruby_mvc/toolkit/peers/wxruby/messagebox'
|
30
33
|
require 'ruby_mvc/toolkit/peers/wxruby/frame'
|
31
34
|
require 'ruby_mvc/toolkit/peers/wxruby/web_view'
|
35
|
+
require 'ruby_mvc/toolkit/peers/wxruby/grid_model'
|
36
|
+
require 'ruby_mvc/toolkit/peers/wxruby/grid_view'
|
@@ -29,13 +29,34 @@ module RubyMVC
|
|
29
29
|
class App < Wx::App
|
30
30
|
Toolkit::App.peer_class = self
|
31
31
|
|
32
|
-
def initialize(&block)
|
33
|
-
super
|
32
|
+
def initialize(options, &block)
|
33
|
+
super()
|
34
34
|
@block = block
|
35
|
+
@options = options
|
35
36
|
main_loop
|
36
37
|
end
|
37
38
|
|
38
39
|
def on_init
|
40
|
+
if icon = @options[:icon]
|
41
|
+
|
42
|
+
# FIXME: the following does what yu expect, but the issue is
|
43
|
+
# that we need to destroy it when the last application window
|
44
|
+
# is closed (meaning we also need to track windows for this
|
45
|
+
# too). tbicon.remove_icon should cause everything to shut
|
46
|
+
# down the way we expect. What a PITA!!!
|
47
|
+
#
|
48
|
+
# if Wx::PLATFORM == "WXMAC"
|
49
|
+
# # ensure we have a dock icon set
|
50
|
+
# tbicon = Wx::TaskBarIcon.new
|
51
|
+
# tbicon.set_icon(WxRuby.load_icon(icon), @options[:title])
|
52
|
+
# class << tbicon
|
53
|
+
# def create_popup_menu
|
54
|
+
# puts "popup menu"
|
55
|
+
# Wx::Menu.new
|
56
|
+
# end
|
57
|
+
# end
|
58
|
+
# end
|
59
|
+
end
|
39
60
|
@block.call
|
40
61
|
end
|
41
62
|
end
|
@@ -54,7 +54,17 @@ module RubyMVC
|
|
54
54
|
default_parent
|
55
55
|
end
|
56
56
|
end
|
57
|
-
|
57
|
+
|
58
|
+
def self.load_icon(path, size = nil)
|
59
|
+
img = Wx::Image.new(path)
|
60
|
+
if size
|
61
|
+
img = img.scale(size, size)
|
62
|
+
end
|
63
|
+
icon = Wx::Icon.new
|
64
|
+
icon.copy_from_bitmap(Wx::Bitmap.new(img))
|
65
|
+
icon
|
66
|
+
end
|
67
|
+
|
58
68
|
# This module has some common things that map between
|
59
69
|
# controls in the WxRuby universe
|
60
70
|
|
@@ -0,0 +1,82 @@
|
|
1
|
+
#--
|
2
|
+
######################################################################
|
3
|
+
#
|
4
|
+
# Copyright 2011 Andrew S. Townley
|
5
|
+
#
|
6
|
+
# Permission to use, copy, modify, and disribute this software for
|
7
|
+
# any purpose with or without fee is hereby granted, provided that
|
8
|
+
# the above copyright notices and this permission notice appear in
|
9
|
+
# all copies.
|
10
|
+
#
|
11
|
+
# THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL
|
12
|
+
# WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
|
13
|
+
# WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
|
14
|
+
# AUTHORS BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT OR
|
15
|
+
# CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
|
16
|
+
# LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
|
17
|
+
# NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN
|
18
|
+
# CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
19
|
+
#
|
20
|
+
# File: dialog.rb
|
21
|
+
# Created: Sun 11 Dec 2011 14:37:40 CST
|
22
|
+
#
|
23
|
+
#####################################################################
|
24
|
+
#++
|
25
|
+
|
26
|
+
module RubyMVC
|
27
|
+
module Toolkit
|
28
|
+
module WxRuby
|
29
|
+
class Dialog < Wx::Dialog
|
30
|
+
include Common
|
31
|
+
Toolkit::Dialog.peer_class = self
|
32
|
+
|
33
|
+
def initialize(options)
|
34
|
+
opts = {}
|
35
|
+
title = options[:title] || "Dialog"
|
36
|
+
winid = options[:id] || -1
|
37
|
+
opts[:size] = [ options[:width], options[:height] ]
|
38
|
+
if parent = options[:parent]
|
39
|
+
parent = parent.peer
|
40
|
+
end
|
41
|
+
if options[:modal].nil? || options[:modal]
|
42
|
+
@modal = true
|
43
|
+
else
|
44
|
+
@modal = false
|
45
|
+
end
|
46
|
+
super(parent, winid, title)
|
47
|
+
@buttons = create_separated_button_sizer(Wx::OK|Wx::CANCEL)
|
48
|
+
end
|
49
|
+
|
50
|
+
# This method is used to add a child to the existing
|
51
|
+
# frame.
|
52
|
+
|
53
|
+
def add(child, options = {})
|
54
|
+
child.peer.reparent(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
# This method is used to add a FormView to the main
|
58
|
+
# content part of the dialog
|
59
|
+
|
60
|
+
def add_form(form)
|
61
|
+
@wxform = FormBuilder.build(self, form)
|
62
|
+
@wxform.widget.add(@buttons, 0, Wx::ALIGN_RIGHT|Wx::ALL, 5)
|
63
|
+
self.sizer = @wxform.widget
|
64
|
+
self.sizer.fit(self)
|
65
|
+
end
|
66
|
+
|
67
|
+
def show
|
68
|
+
self.centre
|
69
|
+
if @modal
|
70
|
+
if Wx::ID_OK == self.show_modal()
|
71
|
+
@wxform.submit if @wxform
|
72
|
+
end
|
73
|
+
else
|
74
|
+
sel.show()
|
75
|
+
end
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
private
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|