Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

autoconnect callbacks on layout

  • Loading branch information...
commit 234007ca70afed8a6f864bc0738c98a328c2412b 1 parent 6445f5b
andrea@VEGETA authored
View
8 lib/extensions/gtk/widgets/gtk_layout.rb
@@ -2,6 +2,7 @@
module Gtk
class Layout
+ include Freightrain::LayoutWidget
def elements=(enumerable)
delta = enumerable.length - @elements.length
@@ -24,8 +25,6 @@ def elements=(enumerable)
end
self.height = @elements.length * @height_factor
(0...@elements.length).each do |index|
- p "i am nil! " if @elements[index] == nil
- p "value is nil" if enumerable[index] == nil
@elements[index].value = enumerable[index]
end
end
@@ -35,15 +34,14 @@ def elements()
end
def bind(options)
- if options[:property] == :elements
+ if options[:property].to_s == "elements"
@elements = []
@viewmodel = (options[:element].to_s + "_element_view_model").to_sym
- @signals = options[:signals]
+ @signals ||= {}
options[:force] = true
selected_callback = @signals[:selected]
@signals[:selected] = lambda do |value|
elements.each do |item|
- p item.object_id
item.set_selection(item.value == value)
end
selected_callback.call(value) if selected_callback
View
1  lib/freightrain/auto_requirer.rb
@@ -15,7 +15,6 @@ def self.auto_require!
end
require_all viewmodels_folder
if File.directory?(services_folder) && !Dir.entries(services_folder).empty?
- p Dir.entries(services_folder)
require_all services_folder
end
if File.directory?(domain_folder) && !Dir.entries(domain_folder).empty?
View
2  lib/freightrain/elements/freight_element_view_model.rb
@@ -11,8 +11,6 @@ def self.container_options
def value=(val)
@value = val
- p val.name if val
- p "nil value" if !val
@view.update
end
View
12 lib/freightrain/elements/layout_widget.rb
@@ -0,0 +1,12 @@
+
+module Freightrain
+ module LayoutWidget
+
+ def add_signal_callback(signal, proc)
+ p signal
+ @signals ||= {}
+ @signals[signal] = proc
+ end
+
+ end
+end
View
11 lib/freightrain/freight_view.rb
@@ -26,10 +26,21 @@ def initialize()
@widgets = []
@builder = Toolkit::InterfaceBuilder.new
load_from_file(self.class.name, @builder)
+ hook_to_layout_widgets()
load_bindings_from_file(@widgets)
create_signals
end
+ def hook_to_layout_widgets
+ @widgets.select{ |widget| widget.is_a? LayoutWidget }.each do |widget|
+ method_prefix = widget.name + "_on_"
+ self.methods.select { |method_name| method_name =~ /#{method_prefix}/}.each do |method_name|
+ signal_name = method_name.sub(method_prefix, "")
+ widget.add_signal_callback(signal_name.to_sym, method(method_name))
+ end
+ end
+ end
+
end
end
View
1  lib/freightrain/ioc/container.rb
@@ -7,7 +7,6 @@ def configure_container!(registry = Needle::Registry.new)
ContainerHookable.classes.each do |klass|
klass.subclasses.each do |subclass|
- p subclass.name.to_convention_sym
@registry.register(
subclass.name.to_convention_sym, subclass.container_options) { subclass.new }
end
Please sign in to comment.
Something went wrong with that request. Please try again.