Factor common code out of xboard and gnushogi engines.
[kaya/ydirson.git] / lib / action_provider.rb
blobd681cbefed30100c3dfb63d2a8b53a4e5b9a8292
1 # Copyright (c) 2009 Paolo Capriotti <p.capriotti@gmail.com>
2
3 # This program is free software; you can redistribute it and/or modify
4 # it under the terms of the GNU General Public License as published by
5 # the Free Software Foundation; either version 2 of the License, or
6 # (at your option) any later version.
8 Action = Struct.new(:id, :opts, :action)
10 module ActionProvider
11   def action(id, opts = {}, &action)
12     @action_data ||= []
13     @action_data << Action.new(id, opts, action)
14   end
15   
16   def xml_file
17     rel('ui.rc')
18   end
19   
20   def each_action(&blk)
21     @action_data.each(&blk)
22   end
23 end
25 class ActionProviderClient < KDE::XMLGUIClient
26   include ActionHandler
27   
28   def initialize(parent, provider)
29     super(parent)
30     @parent = parent
31     
32     setXMLFile(provider.xml_file)
33     provider.each_action do |action|
34       regular_action(action.id, action.opts) do
35         action.action[@parent]
36       end
37     end
38   end
39   
40   def action_parent
41     @parent
42   end
43 end