lib/gtk4/builder.rb in gtk4-3.5.1 vs lib/gtk4/builder.rb in gtk4-4.0.0

- old
+ new

@@ -1,6 +1,6 @@ -# Copyright (C) 2015-2016 Ruby-GNOME2 Project Team +# Copyright (C) 2015-2022 Ruby-GNOME Project Team # # This library is free software; you can redistribute it and/or # modify it under the terms of the GNU Lesser General Public # License as published by the Free Software Foundation; either # version 2.1 of the License, or (at your option) any later version. @@ -12,72 +12,32 @@ # # You should have received a copy of the GNU Lesser General Public # License along with this library; if not, write to the Free Software # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA +require_relative "ruby-builder-scope" + module Gtk class Builder - class << self - def connect_signal(builder, - object, - signal_name, - handler_name, - connect_object, - flags, - &block) - handler_name = normalize_handler_name(handler_name) - if connect_object - handler = connect_object.method(handler_name) - else - handler = block.call(handler_name) - end - - unless handler - $stderr.puts("Undefined handler: #{handler_name}") if $DEBUG - return - end - - if flags.is_a?(Integer) - flags = GLib::ConnectFlags.new(flags) - end - - if flags.after? - signal_connect_method = :signal_connect_after - else - signal_connect_method = :signal_connect - end - - if handler.arity.zero? - object.__send__(signal_connect_method, signal_name) do - handler.call - end - else - object.__send__(signal_connect_method, signal_name, &handler) - end - end - - private - def normalize_handler_name(name) - name.gsub(/[-\s]+/, "_") - end - end - alias_method :initialize_raw, :initialize def initialize(options={}) - path = options[:path] || options[:file] - resource = options[:resource] - string = options[:string] + object = options[:object] + path = options[:path] || options[:file] + resource = options[:resource] + string = options[:string] + initialize_new + set_current_object(object) if object + set_scope(RubyBuilderScope.new) + if path path = path.to_path if path.respond_to?(:to_path) - initialize_new_from_file(path) + add_from_file(path) elsif resource - initialize_new_from_resource(resource) + add_from_resource(resource) elsif string - initialize_new_from_string(string, string.bytesize) - else - initialize_raw + add_from_string(string) end end alias_method :[], :get_object @@ -141,15 +101,8 @@ end def <<(target) add(target) self - end - - alias_method :connect_signals_raw, :connect_signals - def connect_signals(&block) - connect_signals_raw do |*args| - self.class.connect_signal(*args, &block) - end end end end