arcadia 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,253 @@
1
+ #
2
+ # a-contracts.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+ # Catalog of all contracts used by exstension. This astraction guarantees
7
+ # the separation of ext
8
+ # contract must extend AeContract
9
+
10
+ require "base/a-ext"
11
+
12
+ #---------------- contracts ----------------------
13
+ class MainContract < ArcadiaContract
14
+ class TMainObj < TObj
15
+ attr_accessor :obj, :domain, :extension
16
+ end
17
+
18
+ EXTENSION_BEFORE_BUILD = "EXTENSION_BEFORE_BUILD"
19
+ EXTENSION_BUILD = "EXTENSION_BUILD"
20
+ EXTENSION_AFTER_BUILD = "EXTENSION_AFTER_BUILD"
21
+ EXTENSION_FINALIZE = "EXTENSION_FINALIZE"
22
+ CONTRACT_RETRIVE = "CONTRACT_RETRIVE"
23
+ RAISE_EXTENSION = "RAISE_EXTENSION"
24
+
25
+ def extension_before_build(_tobj)
26
+ raise_event(EXTENSION_BEFORE_BUILD, _tobj)
27
+ end
28
+
29
+ def extension_build(_tobj)
30
+ raise_event(EXTENSION_BUILD, _tobj)
31
+ end
32
+
33
+ def extension_after_build(_tobj)
34
+ raise_event(EXTENSION_AFTER_BUILD, _tobj)
35
+ end
36
+
37
+ def raise_extension(_tobj)
38
+ raise_action(RAISE_EXTENSION, _tobj)
39
+ end
40
+
41
+ end
42
+
43
+
44
+ class EditorContract < ArcadiaContract
45
+ class TEditorObj < TObj
46
+ attr_accessor :file, :line, :col, :title, :text
47
+ end
48
+ OPEN_FILE = "OPEN_FILE"
49
+ CLOSE_FILE = "CLOSE_FILE"
50
+ OPEN_TEXT = "OPEN_TEXT"
51
+
52
+ AFTER_CREATE = "AFTER_CREATE"
53
+ BREAKPOINT_AFTER_CREATE = "BREAKPOINT_AFTER_CREATE"
54
+ BREAKPOINT_AFTER_DELETE = "BREAKPOINT_AFTER_DELETE"
55
+ BREAKPOINTS_AFTER_CREATE = "BREAKPOINTS_AFTER_CREATE"
56
+ BREAKPOINTS_AFTER_DELETE = "BREAKPOINTS_AFTER_DELETE"
57
+ FILE_AFTER_OPEN = "FILE_AFTER_OPEN"
58
+ FILE_AFTER_CLOSE = "FILE_AFTER_CLOSE"
59
+ BUFFER_AFTER_RAISE = "BUFFER_AFTER_RAISE"
60
+
61
+ def open_file(_tobj)
62
+ raise_action(OPEN_FILE, _tobj)
63
+ end
64
+
65
+ def close_file(_tobj)
66
+ raise_action(CLOSE_FILE, _tobj)
67
+ end
68
+
69
+ def open_text(_tobj)
70
+ raise_action(OPEN_TEXT, _tobj)
71
+ end
72
+
73
+
74
+ def file_opened(_tobj=nil)
75
+ raise_event(FILE_AFTER_OPEN, _tobj)
76
+ end
77
+
78
+ def buffer_raised(_tobj=nil)
79
+ raise_event(BUFFER_AFTER_RAISE, _tobj)
80
+ end
81
+
82
+ def file_closed(_tobj=nil)
83
+ raise_event(FILE_AFTER_CLOSE, _tobj)
84
+ end
85
+
86
+ def breakpoint_created(_tobj=nil)
87
+ raise_event(BREAKPOINT_AFTER_CREATE, _tobj)
88
+ end
89
+
90
+ def breakpoint_deleted(_tobj=nil)
91
+ raise_event(BREAKPOINT_AFTER_DELETE, _tobj)
92
+ end
93
+ def breakpoints_created(_array_of_tobj=nil)
94
+ raise_event(BREAKPOINTS_AFTER_CREATE, _array_of_tobj)
95
+ end
96
+ def breakpoints_deleted(_array_of_tobj=nil)
97
+ raise_event(BREAKPOINTS_AFTER_DELETE, _array_of_tobj)
98
+ end
99
+ end
100
+
101
+ class MsgContract < ArcadiaContract
102
+ TYPE_SIMPLE = "TYPE_SIMPLE"
103
+ TYPE_DEBUG = "TYPE_DEBUG"
104
+ SObj = Struct.new("MsgState"
105
+ )
106
+ class TMsgObj < TObj
107
+ attr_accessor :type, :text
108
+ end
109
+
110
+ EVENT_EXT_MSG_OUT = "EVENT_EXT_MSG_OUT"
111
+ def out(_tobj)
112
+ raise_event(EVENT_EXT_MSG_OUT, _tobj)
113
+ end
114
+
115
+ def out_simple(_sender, _msg, _channel=nil)
116
+ _tobj = TMsgObj.new(_sender, 'channel'=>_channel)
117
+ _tobj.type = TYPE_SIMPLE
118
+ _tobj.text = _msg
119
+ self.out(_tobj)
120
+ end
121
+
122
+ def out_debug(_sender, _msg, _channel=nil)
123
+ _tobj = TMsgObj.new(_sender, 'channel'=>_channel)
124
+ _tobj.type = TYPE_DEBUG
125
+ _tobj.text = _msg
126
+ self.out(_tobj)
127
+ end
128
+ end
129
+
130
+ class ShellContract < ArcadiaContract
131
+ SObj = Struct.new("ShellState"
132
+ )
133
+ class TShellObj < TObj
134
+ attr_accessor :file
135
+ end
136
+
137
+ def run(_tobj)
138
+ end
139
+ def debug(_tobj)
140
+ end
141
+ end
142
+
143
+
144
+ class DebugContract < ArcadiaContract
145
+ SObj = Struct.new("DebugState"
146
+ )
147
+ class TDebugObj < TObj
148
+ attr_accessor :file, :line, :error_text, :error_class,:callers, :variables
149
+ end
150
+
151
+ DEBUG_BEGIN="DEBUG_BEGIN"
152
+ DEBUG_END="DEBUG_END"
153
+ DEBUG_STEP="DEBUG_STEP"
154
+
155
+ def debug_begin(_tobj=nil)
156
+ raise_event(DEBUG_BEGIN, _tobj)
157
+ end
158
+ def debug_end(_tobj=nil)
159
+ raise_event(DEBUG_END, _tobj)
160
+ end
161
+ def debug_step(_tobj=nil)
162
+ raise_event(DEBUG_STEP, _tobj)
163
+ end
164
+ end
165
+
166
+ class InspectorContract < ArcadiaContract
167
+ SObj = Struct.new("InspectorActionState"
168
+ )
169
+ class TInspectorObj < TObj
170
+ attr_accessor :wrapper, :requires, :property_family,:property_name,:property_value
171
+ end
172
+
173
+ SELECT_WRAPPER = "SELECT_WRAPPER"
174
+ #ACTIVATE_WRAPPER = "ACTIVATE_WRAPPER"
175
+ DELETE_WRAPPER = "DELETE_WRAPPER"
176
+ ADD_REQUIRE = "ADD_REQUIRE"
177
+ REGISTER_WRAPPER = "REGISTER_WRAPPER"
178
+ # UPDATE_PROPERTY = "UPDATE_PROPERTY"
179
+ DELETE_INSPECTOR = "DELETE_INSPECTOR"
180
+ RAISE_ACTIVE_OBJECT = "RAISE_ACTIVE_OBJECT"
181
+ RAISE_ACTIVE_TOPLEVEL = "RAISE_ACTIVE_TOPLEVEL"
182
+
183
+ def delete_wrapper(_tobj=nil)
184
+ raise_action(DELETE_WRAPPER, _tobj)
185
+ end
186
+
187
+ def raise_active_object(_tobj=nil)
188
+ raise_action(RAISE_ACTIVE_OBJECT, _tobj)
189
+ end
190
+
191
+ def raise_active_toplevel(_tobj=nil)
192
+ raise_action(RAISE_ACTIVE_OBJECT, _tobj)
193
+ end
194
+
195
+ def select(_tobj=nil)
196
+ raise_action(SELECT_WRAPPER, _tobj)
197
+ end
198
+
199
+ def add_require(_tobj=nil)
200
+ raise_action(ADD_REQUIRE, _tobj)
201
+ end
202
+
203
+ def register(_tobj=nil)
204
+ raise_action(REGISTER_WRAPPER, _tobj)
205
+ end
206
+
207
+ # def update_property(_tobj=nil)
208
+ # raise_action(UPDATE_PROPERTY, _tobj)
209
+ # end
210
+
211
+ def delete_inspector(_tobj=nil)
212
+ raise_action(DELETE_INSPECTOR, _tobj)
213
+ end
214
+
215
+ publish_action :raise_active_object
216
+ end
217
+
218
+ class PublishContract < ArcadiaContract
219
+ ADD_COMAND_ACTOR = "ADD_COMAND_ACTOR"
220
+ def add_command_actor(_tobj)
221
+ raise_action(ADD_COMAND_ACTOR, _tobj)
222
+ end
223
+ end
224
+
225
+
226
+
227
+ class WrapperContract < ArcadiaContract
228
+ class TWrapperObj < TObj
229
+ attr_accessor :wrapper, :property_name, :property_family, :property_old_value, :property_new_value
230
+ end
231
+ WRAPPER_AFTER_CREATE="WRAPPER_AFTER_CREATE"
232
+ PROPERTY_AFTER_UPDATE="PROPERTY_AFTER_UPDATE"
233
+ UPDATE_PROPERTY="UPDATE_PROPERTY"
234
+ def update_property(_tobj)
235
+ raise_action(UPDATE_PROPERTY, _tobj)
236
+ end
237
+ def property_updated(_tobj)
238
+ raise_event(PROPERTY_AFTER_UPDATE, _tobj)
239
+ end
240
+ def wrapper_created(_tobj)
241
+ raise_event(WRAPPER_AFTER_CREATE, _tobj)
242
+ end
243
+ end
244
+
245
+ class PaletteContract < ArcadiaContract
246
+ class TPaletteObj < TObj
247
+ attr_accessor :parent, :x, :y
248
+ end
249
+ MAKE_SELECTED_WRAPPER = "MAKE_SELECTED_WRAPPER"
250
+ def make_selected(_tobj)
251
+ raise_action(MAKE_SELECTED_WRAPPER, _tobj)
252
+ end
253
+ end
data/base/a-ext.rb ADDED
@@ -0,0 +1,360 @@
1
+ #
2
+ # a-ext.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+ require "observer"
7
+ require 'singleton'
8
+
9
+ class ArcadiaExt
10
+ attr_reader :arcadia
11
+
12
+ def initialize(_arcadia, _name=nil)
13
+ @arcadia = _arcadia
14
+ @name = _name
15
+ unless self.respond_to? :build
16
+ raise NoMethodError, "ArcadiaExt needs to respond to `:build'"
17
+ end
18
+ unless self.respond_to? :before_build
19
+ raise NoMethodError, "ArcadiaExt needs to respond to `:before_build'"
20
+ end
21
+ unless self.respond_to? :after_build
22
+ raise NoMethodError, "ArcadiaExt needs to respond to `:after_build'"
23
+ end
24
+ if self.respond_to? :arcadia_update
25
+ ObserverCallback.new(@arcadia.main_contract, self, :arcadia_update)
26
+ end
27
+ ObjectSpace.define_finalizer(self, self.method(:finalize).to_proc)
28
+ end
29
+
30
+ def before_build
31
+ #must be implemented in child
32
+ end
33
+
34
+ def build
35
+ #must be implemented in child
36
+ end
37
+
38
+ def after_build
39
+ #must be implemented in child
40
+ end
41
+
42
+ def frame
43
+ if @frame == nil
44
+ @frame = @arcadia.layout.register_panel(@arcadia['conf'][@name+'.frame'],@name, @arcadia['conf'][@name+'.label'])
45
+ end
46
+ return @frame
47
+ end
48
+
49
+ def frame_free
50
+ @arcadia.layout.unregister_panel(@arcadia['conf'][@name+'.frame'],@name)
51
+ @frame = nil
52
+ end
53
+
54
+ def conf(_property)
55
+ @arcadia['conf'][@name+'.'+_property]
56
+ end
57
+ # def arcadia_update(_sender, _event)
58
+ #must be implemented to activate
59
+ # end
60
+
61
+ def can_exit_query
62
+ return true
63
+ end
64
+
65
+ def finalize
66
+ #may be extendeded in child
67
+ end
68
+
69
+ def verbose
70
+ '??????'
71
+ end
72
+
73
+ end
74
+
75
+
76
+ class ObserverCallback
77
+ def initialize(_publisher, _subscriber, _method_update_to_call=:update)
78
+ @publisher = _publisher
79
+ @subscriber = _subscriber
80
+ @method=_method_update_to_call
81
+ @publisher.add_observer(self)
82
+ end
83
+ def update(*args)
84
+ @subscriber.send(@method,*args)
85
+ end
86
+ end
87
+
88
+ class ObserverCallbackContract < ObserverCallback
89
+ def initialize(_publisher, _subscriber, _method_update_to_call=:update, _channel=nil)
90
+ super(_publisher, _subscriber, _method_update_to_call)
91
+ @channel = _channel
92
+ @channel_conf = @subscriber.conf(@publisher.class.to_s+'.channel') if @subscriber.respond_to?(:conf)
93
+ end
94
+
95
+ def filter(_event)
96
+ @channel_conf != nil && @channel_conf != _event.channel
97
+ end
98
+
99
+ def update(_event, *args)
100
+ super(_event, *args) if !filter(_event)
101
+ end
102
+ end
103
+
104
+
105
+ class ObserverCallbackContractThread < ObserverCallbackContract
106
+ def update(*args)
107
+ Thread.new do
108
+ super(*args)
109
+ end
110
+ end
111
+
112
+ end
113
+
114
+
115
+ # The contract define the interface beetwhen extension
116
+ # in particulare define method than raise event to observers client
117
+ # and a way to retreive state from client
118
+
119
+ class ArcadiaContract
120
+ include Observable
121
+ include Singleton
122
+ class ContractEvent
123
+ attr_reader :contract
124
+ attr_reader :signature
125
+ attr_reader :context
126
+ attr_reader :channel
127
+ attr_reader :time
128
+ attr_writer :action
129
+
130
+ SIGNATURE = "NOT_DEFINED"
131
+ def initialize(_contract, _signature=SIGNATURE, _context=nil)
132
+ @contract = _contract
133
+ @signature = _signature
134
+ @context = _context
135
+ _context.channel != nil ?@channel=_context.channel: @channel='0'
136
+ @time = Time.new
137
+ @action = false
138
+ end
139
+
140
+ def handled(_by)
141
+ @contract.event_handled(TObj.new(_by))
142
+ end
143
+
144
+ def is_action?
145
+ @action
146
+ end
147
+ end
148
+
149
+ class TObj
150
+ attr_reader :sender
151
+ attr_accessor :channel
152
+ DEFAULT_CHANNEL='0'
153
+ def initialize(_sender, _args=nil)
154
+ @sender=_sender
155
+ @channel = DEFAULT_CHANNEL
156
+ if _args
157
+ _args.each do |key, value|
158
+ self.send(key+'=', value)
159
+ end
160
+ end
161
+
162
+ end
163
+
164
+ # properties.each do |prop|
165
+ # define_method(prop) {
166
+ # instance_variable_get("@#{prop}")
167
+ # }
168
+ # define_method("#{prop}=") do |value|
169
+ # instance_variable_set("@#{prop}", value)
170
+ # end
171
+ # end
172
+
173
+ # define_method(prop)
174
+ # attr_reader prop.to_sym # prop by itself also worked for me
175
+ # # code snip ? setter method
176
+ # end
177
+
178
+
179
+ # def TObj.property(*properties)
180
+ # properties.each { |property|
181
+ # class_eval(%Q[
182
+ # def #{property}
183
+ # @#{property}
184
+ # end
185
+ #
186
+ # def #{property}=(value)
187
+ # @#{property} = value
188
+ # end
189
+ # ])
190
+ # }
191
+ # end
192
+ end
193
+
194
+ class EventInfo
195
+ attr_reader :method
196
+ attr_reader :label
197
+ attr_reader :icon
198
+ def initialize(_method)
199
+ @method = @method
200
+ #TODO: load label and icon from config file
201
+ end
202
+ end
203
+
204
+ EVENT_HANDLED = "EVENT_HANDLED"
205
+ CONTRACT_CREATED = "CONTRACT_CREATED"
206
+
207
+ SObj = Struct.new("GenericState",
208
+ :caller
209
+ )
210
+ # TObj = Struct.new("GenericObj",
211
+ # :sender
212
+ # )
213
+
214
+ # def initialize(_sender=nil, _state_method=nil, _channel='0')
215
+ # @@instances = Array.new if !defined?(@@instances)
216
+ # #@@listeners_queue Array.new if !defined?(@@listeners_queue)
217
+ # @@instances << self
218
+ # @sender = _sender
219
+ # @state_method = _state_method
220
+ # @channel = _channel
221
+ # ObjectSpace.define_finalizer(self, self.class.method(:finalize).to_proc)
222
+ # #ArcadiaContract.source(self).raise_event(CONTRACT_CREATED, TObj.new(_sender))
223
+ # end
224
+
225
+ # def ArcadiaContract.instances
226
+ # @@instances
227
+ # end
228
+
229
+ # def ArcadiaContract.source(_sender=nil)
230
+ # if !defined?(@@source)
231
+ # (_sender==nil) ? @@source = ArcadiaContract.new : @@source = _sender
232
+ # end
233
+ # return @@source
234
+ # end
235
+
236
+ # def ArcadiaContract.finalize(id)
237
+ # raise_event(MainContract::EXTENSION_FINALIZE, id)
238
+ # end
239
+
240
+ # raise an event with event handled as context obj
241
+ def event_handled(_tobj)
242
+ raise_event(EVENT_HANDLED, _tobj)
243
+ end
244
+
245
+ def _event_forge(_event_signature, _tobj)
246
+ ContractEvent.new(self, _event_signature, _tobj)
247
+ end
248
+ private :_event_forge
249
+
250
+
251
+ def raise_event(_event_signature, _tobj, *args)
252
+ _raise_event(_event_forge(_event_signature, _tobj),*args)
253
+ end
254
+
255
+ def _raise_event(_event, *args)
256
+ changed
257
+ notify_observers(_event, *args)
258
+ if self.class != ArcadiaContract
259
+ self.class.superclass.instance._raise_event(_event, *args)
260
+ end
261
+ end
262
+ #protected :_raise_event
263
+
264
+ def raise_action(_event_signature, _tobj, *args)
265
+ _raise_action(_event_forge(_event_signature, _tobj),*args)
266
+ end
267
+
268
+ def _raise_action(_event, *args)
269
+ _event.action = true
270
+ _raise_event(_event, *args)
271
+ end
272
+ private :_raise_action
273
+
274
+
275
+
276
+ # def retrieve_state(*args)
277
+ # unless @sender.respond_to? @state_method
278
+ # raise NoMethodError, self.class.to_s+" needs to respond to "+@state_method.to_s
279
+ # end
280
+ # return @sender.send(@state_method, *args)
281
+ # end
282
+
283
+ def ArcadiaContract.publish_action(_method)
284
+ _info = EventInfo.new(_method)
285
+ @@actions = Array.new if !defined?(@@actions)
286
+ @@actions << _info
287
+ end
288
+
289
+ end
290
+
291
+ class ArcadiaContractListener
292
+ def initialize(_subscriber, _class, _method, _channel=nil)
293
+ # @arcadia = _arcadia
294
+ @subscriber = _subscriber
295
+ @class = _class
296
+ @method = _method
297
+ @channel = _channel
298
+ create_callback(_class.instance)
299
+ # _klass = _class
300
+ # while _klass.kind_of?(ArcadiaContract)
301
+ # create_callback(_klass.instance)
302
+ # _klass = _klass.superclass
303
+ # end
304
+
305
+ # ObserverCallback.new(_class.instance, self, :do_main_event)
306
+ # ObserverCallback.new(MainContract.instance, self, :do_main_event)
307
+ # @class.instances.each do |_contract|
308
+ # create_callback(_contract) if _contract.kind_of?(@class)
309
+ # end
310
+ end
311
+
312
+ # def do_main_event(_event)
313
+ # if _event.signature == MainContract::CONTRACT_RETRIVE && _event.context.contract.kind_of?(@class)
314
+ # create_callback(_event.context.contract)
315
+ ## elsif _event.signature == ArcadiaContract::CONTRACT_CREATED && _event.contract.kind_of?(@class)
316
+ ## create_callback(_event.contract)
317
+ # end
318
+ # end
319
+
320
+ def create_callback(_contract)
321
+ ObserverCallbackContract.new(_contract, @subscriber, @method, @channel)
322
+ #ObserverCallback.new(_contract, _subscriber, _method)
323
+ end
324
+
325
+ # def update(*args)
326
+ # @subscriber.send(@method,*args)
327
+ # end
328
+
329
+ # def info
330
+ # @contract.retrieve_state if @contract
331
+ # end
332
+
333
+ # def delegate_action(_action, _obj=nil)
334
+ # if @contract && @contract.respond_to? :do_action
335
+ # @contract.do_action
336
+ # end
337
+ # end
338
+ end
339
+
340
+ class ArcadiaContractListenerThread < ArcadiaContractListener
341
+
342
+ def create_callback(_contract)
343
+ #Thread.new do super(_contract, _subscriber, _method) end
344
+ ObserverCallbackContractThread.new(_contract)
345
+ end
346
+
347
+ end
348
+
349
+
350
+
351
+
352
+ #class AeContractListener
353
+ # def initialize(_arcadia)
354
+ #
355
+ # end
356
+ # def listen_on(_aeclip_name, _method_update_to_call=:update)
357
+ # end
358
+ # def update(_tobj)
359
+ # end
360
+ #end