Sha256: 2f223055d7957710518d72e61fd493de405fa7ea6d3343f01b7dd8e1ecbca6e1

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# Copyright (c) 2023 M.J.N. Corino, The Netherlands
#
# This software is released under the MIT license.
# 
# Some parts are
# Copyright 2004-2007, wxRuby development team
# released under the MIT-like wxRuby2 license

class Wx::AcceleratorTable
  # Allow new to be called as []
  class << self
    alias :[] :new
  end

  # Allow initialize to be called with a splat-like list of arguments,
  # and allow entries to be specified in terser form [mod, key, id]
  # rather than full AcceleratorEntry.new call.
  wx_init = self.instance_method(:initialize)
  wx_redefine_method(:initialize) do | *args |
    # Test for old-style arg passing in a single array
    if args.length == 1 and args.first.kind_of?(Array) and
       args.first.all? { | e | e.kind_of?(Wx::AcceleratorEntry) }
      args = args[0]
    end
    # Convert to array of AccEntries, to pass in as single array
    args = args.map do | entry |
      case entry 
      when Wx::AcceleratorEntry then entry
      when Array then Wx::AcceleratorEntry.new(*entry)
      else Kernel.raise ArgumentError,
                        "#{entry.inspect} is not a valid AcceleratorTable entry"
      end
    end
    wx_init.bind(self).call(args)
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
wxruby3-1.5.1 lib/wx/core/acceleratortable.rb
wxruby3-1.5.0 lib/wx/core/acceleratortable.rb
wxruby3-1.4.2 lib/wx/core/acceleratortable.rb
wxruby3-1.4.1 lib/wx/core/acceleratortable.rb
wxruby3-1.4.0 lib/wx/core/acceleratortable.rb