diff options
Diffstat (limited to 'ext/tk/lib/tk/menu.rb')
-rw-r--r-- | ext/tk/lib/tk/menu.rb | 70 |
1 files changed, 69 insertions, 1 deletions
diff --git a/ext/tk/lib/tk/menu.rb b/ext/tk/lib/tk/menu.rb index be8ec2ddee..ddddc8e53e 100644 --- a/ext/tk/lib/tk/menu.rb +++ b/ext/tk/lib/tk/menu.rb @@ -43,6 +43,7 @@ module TkMenuEntryConfig end class TkMenu<TkWindow + include Wm include TkMenuEntryConfig extend TkMenuSpec @@ -115,6 +116,36 @@ class TkMenu<TkWindow def add_separator(keys=nil) add('separator', keys) end + + def clone_menu(*args) + if args[0].kind_of?(TkWindow) + parent = args.shift + else + parent = self + end + + if args[0].kind_of?(String) || args[0].kind_of?(Symbol) # menu type + type = args.shift + else + type = None # 'normal' + end + + if args[0].kind_of?(Hash) + keys = _symbolkey2str(args.shift) + else + keys = {} + end + + parent = keys.delete('parent') if keys.has_key?('parent') + type = keys.delete('type') if keys.has_key?('type') + + if keys.empty? + TkMenuClone.new(self, parent, type) + else + TkMenuClone.new(self, parent, type, keys) + end + end + def index(idx) ret = tk_send_without_enc('index', _get_eval_enc_str(idx)) (ret == 'none')? nil: number(ret) @@ -352,6 +383,7 @@ end class TkMenuClone<TkMenu +=begin def initialize(parent, type=None) widgetname = nil if parent.kind_of? Hash @@ -367,8 +399,44 @@ class TkMenuClone<TkMenu install_win(@parent.path, widgetname) tk_call_without_enc(@parent.path, 'clone', @path, type) end -end +=end + def initialize(src_menu, *args) + widgetname = nil + + if args[0].kind_of?(TkWindow) # parent window + parent = args.shift + else + parent = src_menu + end + + if args[0].kind_of?(String) || args[0].kind_of?(Symbol) # menu type + type = args.shift + else + type = None # 'normal' + end + + if args[0].kind_of?(Hash) + keys = _symbolkey2str(args.shift) + parent = keys.delete('parent') if keys.has_key?('parent') + widgetname = keys.delete('widgetname') + type = keys.delete('type') if keys.has_key?('type') + else + keys = nil + end + @src_menu = src_menu + @parent = parent + @type = type + install_win(@parent.path, widgetname) + tk_call_without_enc(@src_menu.path, 'clone', @path, @type) + configure(keys) if keys && !keys.empty? + end + + def source_menu + @src_menu + end +end +TkCloneMenu = TkMenuClone module TkSystemMenu def initialize(parent, keys=nil) |