From bb5763c3c0481080d7087475d3ef11c084c48adf Mon Sep 17 00:00:00 2001 From: fab <> Date: Sun, 6 May 2007 21:58:51 +0000 Subject: [PATCH] Fix for ruby-libglade-0.16, for Windows, BT2 and other distribs git-svn-id: file:///home/svn/framework3/trunk@4878 4d416f70-5f16-0410-b530-b9f4589650da --- lib/msf/ui/gtk2/app.rb | 51 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) diff --git a/lib/msf/ui/gtk2/app.rb b/lib/msf/ui/gtk2/app.rb index 5e79fed204..9bbb937cf6 100644 --- a/lib/msf/ui/gtk2/app.rb +++ b/lib/msf/ui/gtk2/app.rb @@ -2,10 +2,61 @@ module Msf module Ui module Gtk2 +## +# This class help us to wait the next release of ruby-libglade2 package +## +class GladeXML < GladeXML + def connect(source, target, signal, handler, data, after = false) + @handler_proc ||= Proc.new{} + handler = canonical_handler(handler) + if target + signal_proc = target.method(handler) + else + signal_proc = @handler_proc.call(handler) + end + + if after + sig_conn_proc = source.method(:signal_connect_after) + else + sig_conn_proc = source.method(:signal_connect) + end + + if signal_proc + guard_source_from_gc(source) + case signal_proc.arity + when 0 + sig_conn_proc.call(signal) {signal_proc.call} + else + sig_conn_proc.call(signal, &signal_proc) + end + elsif $DEBUG + puts "Undefined handler: #{handler}" + end + end + + def guard_source_from_gc(source) + return if source.nil? + @sources ||= {} + @sources[source.object_id] = source + + source.signal_connect("destroy") do |object| + @sources.delete(object.object_id) + end + + # To get the parent window of the source as a ruby object. + # Ruby/GTK keeps the Window objects on the memory to prevend from GC. + parent = source.parent + while parent + parent = parent.parent + end + end +end + ## # This class help us to retreive all glade widgets and place them in your user instance # like @windows, @widget, ... ## + class MyGlade include Msf::Ui::Gtk2::MyControls