Sha256: b9ecd64805cdbb6d3912ec1eb1dabad3db74ef28eb35283793e88a0a342b4681

Contents?: true

Size: 1.67 KB

Versions: 29

Compression:

Stored size: 1.67 KB

Contents

# Copyright (C) 2015  Ruby-GNOME2 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.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# 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

module Gio
  module ActionMap
    alias_method :add_action_raw, :add_action
    def add_action(action)
      action = convert_to_action(action) unless action.is_a?(Action)
      add_action_raw(action)
      actions[action.name] = action
    end

    alias_method :remove_action_raw, :remove_action
    def remove_action(name)
      remove_action_raw(name)
      actions.delete(name)
    end

    def add_actions(actions)
      actions.each do |action|
        add_action(action)
      end
    end

    private
    def actions
      @acitions ||= {}
    end

    def convert_to_action(definition)
      name = definition[:name]
      parameter_type = definition[:parameter_type]
      callback = definition[:callback]

      action = SimpleAction.new(name, parameter_type)
      if callback
        action.signal_connect("activate") do |*args|
          callback.call(*args)
        end
      end
      action
    end
  end
end

Version data entries

29 entries across 29 versions & 1 rubygems

Version Path
gio2-3.0.9-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.9-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.9 lib/gio2/action-map.rb
gio2-3.0.8-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.8-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.8 lib/gio2/action-map.rb
gio2-3.0.7-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.7-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.7 lib/gio2/action-map.rb
gio2-3.0.6-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.6-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.6 lib/gio2/action-map.rb
gio2-3.0.5-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.5-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.5 lib/gio2/action-map.rb
gio2-3.0.4-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.4-x86-mingw32 lib/gio2/action-map.rb
gio2-3.0.4 lib/gio2/action-map.rb
gio2-3.0.3-x64-mingw32 lib/gio2/action-map.rb
gio2-3.0.3-x86-mingw32 lib/gio2/action-map.rb