arcadia 0.2.0 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. data/README +132 -134
  2. data/bin/arcadia +13 -0
  3. data/conf/arcadia.conf +196 -3
  4. data/conf/arcadia.init.rb +27 -6
  5. data/conf/arcadia.res.rb +10 -0
  6. data/ext/ae-complete-code/ae-complete-code.rb +76 -82
  7. data/ext/ae-doc-code/ae-doc-code.rb +295 -291
  8. data/ext/ae-editor/ae-editor.conf +88 -67
  9. data/ext/ae-editor/ae-editor.rb +400 -202
  10. data/ext/ae-editor/langs/conf.lang +16 -5
  11. data/ext/ae-editor/langs/lang.lang.bind +1 -1
  12. data/ext/ae-editor/langs/rb.lang +77 -41
  13. data/ext/ae-editor/langs/rbw.lang.bind +1 -1
  14. data/ext/ae-event-log/ae-event-log.rb +46 -45
  15. data/ext/ae-file-history/ae-file-history.conf +1 -1
  16. data/ext/ae-file-history/ae-file-history.rb +373 -298
  17. data/ext/ae-output/ae-output.conf +2 -0
  18. data/ext/ae-output/ae-output.rb +200 -202
  19. data/ext/ae-rad/ae-rad-inspector.rb +64 -70
  20. data/ext/ae-rad/ae-rad-palette.rb +14 -14
  21. data/ext/ae-rad/ae-rad.conf +2 -0
  22. data/ext/ae-rad/lib/tk/al-tk.rb +2991 -2987
  23. data/ext/ae-rad/lib/tk/al-tkarcadia.rb +26 -26
  24. data/ext/ae-ruby-debug/ae-ruby-debug.conf +8 -8
  25. data/ext/ae-ruby-debug/ae-ruby-debug.rb +1566 -1465
  26. data/ext/ae-search-in-files/ae-search-in-files.rb +294 -284
  27. data/ext/ae-shell/ae-shell.rb +20 -11
  28. data/{base → lib}/a-commons.rb +291 -80
  29. data/{base → lib}/a-contracts.rb +40 -18
  30. data/{arcadia.rb → lib/a-core.rb} +238 -148
  31. data/{base → lib}/a-tkcommons.rb +81 -63
  32. metadata +64 -65
  33. data/ext/ae-action-dispatcher/ae-action-dispatcher.conf +0 -6
  34. data/ext/ae-action-dispatcher/ae-action-dispatcher.rb +0 -22
  35. data/ext/ae-inspector/ae-inspector.conf +0 -7
  36. data/ext/ae-inspector/ae-inspector.rb +0 -1519
  37. data/ext/ae-palette/ae-palette.conf +0 -7
  38. data/ext/ae-palette/ae-palette.rb +0 -265
@@ -1,15 +1,26 @@
1
- classes=key,value,operator,comment
1
+ classes=key,value,operator,comment,link
2
2
  re.key=(.*)\=
3
3
  re.value=\=(.*)
4
4
  re.operator=\=
5
5
  re.comment=#
6
+ re.link=>>>
6
7
  re_op.to_line_end=comment
7
8
  re_op.only_first=operator
8
9
 
9
- hightlight.comment.color.foreground=#007F00
10
- hightlight.key.color.foreground=#9c342c
10
+ #hightlight.comment.foreground=#007F00
11
+ #hightlight.key.foreground=#9c342c
12
+ #hightlight.key.style=bold
13
+ #hightlight.value.foreground=#69a0b6
14
+ #hightlight.value.style=bold
15
+ #hightlight.operator.foreground=red
16
+ #hightlight.operator.style=bold
17
+
18
+ hightlight.comment.foreground=>>>hightlight.11.foreground
19
+ hightlight.key.foreground=>>>hightlight.5.foreground
11
20
  hightlight.key.style=bold
12
- hightlight.value.color.foreground=#69a0b6
21
+ hightlight.value.foreground=>>>hightlight.6.foreground
13
22
  hightlight.value.style=bold
14
- hightlight.operator.color.foreground=red
23
+ hightlight.operator.foreground=>>>hightlight.14.foreground
15
24
  hightlight.operator.style=bold
25
+ hightlight.link.foreground=>>>hightlight.12.foreground
26
+ hightlight.link.style=bold
@@ -1 +1 @@
1
- bind=conf.lang
1
+ bind=conf
@@ -13,55 +13,91 @@ re.symbol=[^:](:)[A-Za-z0-9_]*
13
13
  re.comment=#
14
14
  re_op.to_line_end=comment
15
15
 
16
- # override global
17
- hightlight.sel.color.foreground=black
18
- hightlight.sel.color.background=#68f914
19
- hightlight.sel.borderwidth=1
20
- hightlight.sel.relief=raised
21
- hightlight.selected.color.background=yellow
22
- hightlight.tabs.color.foreground=black
23
- hightlight.tabs.color.background=#b1cfba
24
- hightlight.tabs.borderwidth=1
25
- hightlight.tabs.relief=raised
26
- hightlight.spaces.color.foreground=black
27
- hightlight.spaces.color.background=#d9f42b
28
- hightlight.spaces.borderwidth=1
29
- hightlight.spaces.relief=raised
30
- #+--------------------------------------------------
16
+ # override global classes
17
+ hightlight.sel.foreground=>>>hightlight.1.foreground
18
+ hightlight.sel.background=>>>hightlight.1.background
19
+ hightlight.sel.borderwidth=>>>hightlight.1.borderwidth
20
+ hightlight.sel.relief=>>>hightlight.1.relief
21
+ hightlight.selected.background=>>>hightlight.2.background
22
+ hightlight.tabs.foreground=>>>hightlight.3.foreground
23
+ hightlight.tabs.background=>>>hightlight.3.background
24
+ hightlight.tabs.borderwidth=>>>hightlight.3.borderwidth
25
+ hightlight.tabs.relief=>>>hightlight.3.relief
26
+ hightlight.spaces.foreground=>>>hightlight.4.foreground
27
+ hightlight.spaces.background=>>>hightlight.4.background
28
+ hightlight.spaces.borderwidth=>>>hightlight.4.borderwidth
29
+ hightlight.spaces.relief=>>>hightlight.4.relief
31
30
 
32
31
 
32
+ # override global
33
+ #hightlight.sel.color.foreground=black
34
+ #hightlight.sel.color.background=#68f914
35
+ #hightlight.sel.borderwidth=1
36
+ #hightlight.sel.relief=raised
37
+ #hightlight.selected.color.background=yellow
38
+ #hightlight.tabs.color.foreground=black
39
+ #hightlight.tabs.color.background=#b1cfba
40
+ #hightlight.tabs.borderwidth=1
41
+ #hightlight.tabs.relief=raised
42
+ #hightlight.spaces.color.foreground=black
43
+ #hightlight.spaces.color.background=#d9f42b
44
+ #hightlight.spaces.borderwidth=1
45
+ #hightlight.spaces.relief=raised
46
+ #+--------------------------------------------------
33
47
 
34
- hightlight.keyword.color.foreground=#00007F
48
+ # custom classes
49
+ hightlight.keyword.foreground=>>>hightlight.5.foreground
35
50
  hightlight.keyword.style=bold
36
- hightlight.method_name.color.foreground=#007F7F
51
+ hightlight.method_name.foreground=>>>hightlight.6.foreground
37
52
  hightlight.method_name.style=bold
38
- hightlight.class_name.color.foreground=#0000FF
53
+ hightlight.class_name.foreground=>>>hightlight.7.foreground
39
54
  hightlight.class_name.style=bold
40
- hightlight.module_name.color.foreground=#0000FF
55
+ hightlight.module_name.foreground=>>>hightlight.8.foreground
41
56
  hightlight.module_name.style=bold
42
- hightlight.instance_variable.color.foreground=#7F7F7F
43
- hightlight.global_variable.style=bold
44
- hightlight.global_variable.color.foreground=#db66ca
57
+ hightlight.instance_variable.foreground=>>>hightlight.9.foreground
45
58
  hightlight.instance_variable.style=bold
46
- hightlight.comment.color.foreground=#007F00
47
- hightlight.string.color.foreground=#7F007F
48
- hightlight.number.color.foreground=#007F7F
49
- #hightlight.capitalize.color.foreground=#0000FF
50
- hightlight.operator.color.foreground=#000000
59
+ hightlight.global_variable.foreground=>>>hightlight.10.foreground
60
+ hightlight.global_variable.style=bold
61
+ hightlight.comment.foreground=>>>hightlight.11.foreground
62
+ hightlight.string.foreground=>>>hightlight.12.foreground
63
+ hightlight.number.foreground=>>>hightlight.13.foreground
64
+ hightlight.operator.foreground=>>>hightlight.14.foreground
51
65
  hightlight.operator.style=bold
52
- hightlight.symbol.color.foreground=#bdc175
66
+ hightlight.symbol.foreground=>>>hightlight.15.foreground
53
67
  hightlight.symbol.style=bold
54
- hightlight.sel.color.foreground=black
55
- hightlight.sel.color.background=#68f914
56
- hightlight.sel.borderwidth=1
57
- hightlight.sel.relief=raised
68
+
69
+
70
+ #hightlight.keyword.color.foreground=#00007F
71
+ #hightlight.keyword.style=bold
72
+ #hightlight.method_name.color.foreground=#007F7F
73
+ #hightlight.method_name.style=bold
74
+ #hightlight.class_name.color.foreground=#0000FF
75
+ #hightlight.class_name.style=bold
76
+ #hightlight.module_name.color.foreground=#0000FF
77
+ #hightlight.module_name.style=bold
78
+ #hightlight.instance_variable.color.foreground=#7F7F7F
79
+ #hightlight.instance_variable.style=bold
80
+ #hightlight.global_variable.style=bold
81
+ #hightlight.global_variable.color.foreground=#db66ca
82
+ #hightlight.comment.color.foreground=#007F00
83
+ #hightlight.string.color.foreground=#7F007F
84
+ #hightlight.number.color.foreground=#007F7F
85
+ #hightlight.capitalize.color.foreground=#0000FF
86
+ #hightlight.operator.color.foreground=#000000
87
+ #hightlight.operator.style=bold
88
+ #hightlight.symbol.color.foreground=#bdc175
89
+ #hightlight.symbol.style=bold
90
+ #hightlight.sel.color.foreground=black
91
+ #hightlight.sel.color.background=#68f914
92
+ #hightlight.sel.borderwidth=1
93
+ #hightlight.sel.relief=raised
58
94
  #hightlight.goto.color.foreground=blue
59
- hightlight.selected.color.background=yellow
60
- hightlight.tabs.color.foreground=black
61
- hightlight.tabs.color.background=#b1cfba
62
- hightlight.tabs.borderwidth=1
63
- hightlight.tabs.relief=raised
64
- hightlight.spaces.color.foreground=black
65
- hightlight.spaces.color.background=#d9f42b
66
- hightlight.spaces.borderwidth=1
67
- hightlight.spaces.relief=raised
95
+ #hightlight.selected.color.background=yellow
96
+ #hightlight.tabs.color.foreground=black
97
+ #hightlight.tabs.color.background=#b1cfba
98
+ #hightlight.tabs.borderwidth=1
99
+ #hightlight.tabs.relief=raised
100
+ #hightlight.spaces.color.foreground=black
101
+ #hightlight.spaces.color.background=#d9f42b
102
+ #hightlight.spaces.borderwidth=1
103
+ #hightlight.spaces.relief=raised
@@ -1 +1 @@
1
- bind=rb.lang
1
+ bind=rb
@@ -1,45 +1,46 @@
1
- #
2
- # ae-event-log.rb - Arcadia Ruby ide
3
- # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
- #
5
-
6
-
7
- class EventLog < ArcadiaExt
8
-
9
- def on_before_build(_event)
10
- ArcadiaContractListener.new(self, ArcadiaContract, :do_event)
11
- end
12
-
13
- def do_event(_event)
14
- if _event.context.sender!=self
15
- message = event_message(_event)
16
- Arcadia.new_msg(self, message, 'CH1')
17
- end
18
- end
19
-
20
-
21
- def event_message(_event, _ind="")
22
- message = _ind
23
- if _event.is_action?
24
- message = message + 'ACTION::'
25
- end
26
- message = message +_event.signature+" :\n"
27
- if _event.context
28
- _event.context.instance_variables.sort.each do |key|
29
- _obj_value = _event.context.send(key.gsub('@',''))
30
- _value = _obj_value
31
- if _value == nil
32
- _value = 'nil'
33
- else !_value.instance_of?(String)
34
- _value = _value.to_s
35
- end
36
- message = message + _ind + "\s"*2 + key+' = '+_value+"\n"
37
- if _obj_value != nil && _obj_value.kind_of?(ArcadiaContract::ContractEvent)
38
- message = message + event_message(_obj_value, _ind+"\s"*4)
39
- end
40
- end
41
- end
42
- return message
43
- end
44
-
45
- end
1
+ #
2
+ # ae-event-log.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+
7
+ class EventLog < ArcadiaExt
8
+
9
+ def on_before_build(_event)
10
+ ArcadiaContractListener.new(self, ArcadiaContract, :do_event)
11
+ end
12
+
13
+ def do_event(_event)
14
+ if _event.context.sender!=self
15
+ message = event_message(_event)
16
+ Arcadia.console(self, 'msg'=>message, 'channel'=>'CH1')
17
+ #Arcadia.new_msg(self, message, 'CH1')
18
+ end
19
+ end
20
+
21
+
22
+ def event_message(_event, _ind="")
23
+ message = _ind
24
+ if _event.is_action?
25
+ message = message + 'ACTION::'
26
+ end
27
+ message = message +_event.signature+" :\n"
28
+ if _event.context
29
+ _event.context.instance_variables.sort.each do |key|
30
+ _obj_value = _event.context.send(key.gsub('@',''))
31
+ _value = _obj_value
32
+ if _value == nil
33
+ _value = 'nil'
34
+ else !_value.instance_of?(String)
35
+ _value = _value.to_s
36
+ end
37
+ message = message + _ind + "\s"*2 + key+' = '+_value+"\n"
38
+ if _obj_value != nil && _obj_value.kind_of?(ArcadiaContract::ContractEvent)
39
+ message = message + event_message(_obj_value, _ind+"\s"*4)
40
+ end
41
+ end
42
+ end
43
+ return message
44
+ end
45
+
46
+ end
@@ -3,7 +3,7 @@ labels=File history
3
3
  frames=0.0
4
4
  active=yes
5
5
  require=ext/ae-file-history/ae-file-history
6
- class=FileH
6
+ class=FilesHistrory
7
7
 
8
8
  file.name=arcadia.history
9
9
  length=34
@@ -1,298 +1,373 @@
1
- #
2
- # ae-file-history.rb - Arcadia Ruby ide
3
- # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
- #
5
-
6
-
7
- class TreeNode
8
- attr_reader :sons
9
- attr_reader :parent
10
- attr_reader :kind
11
- attr_reader :rif, :label, :helptext
12
- attr_writer :rif, :label, :helptext
13
- def initialize(parent=nil, kind='KClass')
14
- @sons = Array.new
15
- @parent = parent
16
- @kind = kind
17
- @label = ''
18
- if @parent !=nil
19
- @parent.sons << self
20
- end
21
- yield(self) if block_given?
22
- end
23
-
24
- def <=> (other)
25
- self.label.strip <=> other.label.strip
26
- end
27
-
28
- def path
29
- _path = @label
30
- if @parent != nil
31
- _path = @parent.path+_path
32
- end
33
- return _path
34
- end
35
-
36
- def dir(_path)
37
- node = nil
38
- parent = self
39
- sons.each{|_tree|
40
- if _path[0.._tree.label.length-1] == _tree.label
41
- res = _path[_tree.label.length.._path.length-1]
42
- if ["\\","/"].include?(res[0,1])
43
- parent = _tree
44
- node= _tree.dir(res)
45
- end
46
- end
47
- break if node != nil
48
- }
49
- if node == nil
50
- node = TreeNode.new(parent,'KDir') do |_node|
51
- _node.label=_path
52
- _node.rif= parent.path+_path
53
- end
54
- end
55
- return node
56
- end
57
- end
58
-
59
-
60
-
61
- class FileH < ArcadiaExt
62
- include Autils
63
- attr_reader :htree
64
-
65
- def on_build(_event)
66
- @h_stack = Array.new
67
- do_select_item = proc{|_self|
68
- if _self.selection_get[0].length >0
69
- _selected = ""
70
- _self.selection_get[0].each{|_block|
71
- _selected = _selected + _block.to_s + "\s"
72
- }
73
- _selected = _selected.strip
74
- else
75
- _selected = _self.selection_get[0]
76
- end
77
- _dir, _file = _selected.split('@@@')
78
- if _file
79
- _file = File.expand_path( _file , _dir )
80
- else
81
- _file = Tk.getOpenFile('initialdir'=>_dir)
82
- end
83
- if _file
84
- Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file))
85
- #EditorContract.instance.open_file(self,'file'=>_file)
86
- end
87
- }
88
- _background = conf('color.background')
89
- _foreground = conf('color.foreground')
90
- @font = conf('font')
91
- @font_b = conf('font.bold')
92
-
93
- @htree = Tk::BWidget::Tree.new(self.frame){
94
- relief 'flat'
95
- showlines false
96
- deltay 18
97
- background _background
98
- crossfill _foreground
99
- #dragenabled true
100
- selectcommand proc{ do_select_item.call(self) }
101
- place('relwidth' => 1,'relx' => 0,'x' => '0','y' => '0','relheight' => '1')
102
- }
103
- _scrollcommand = proc{|*args| @htree.yview(*args)}
104
- _scrollbar = TkScrollbar.new(self.frame){|s|
105
- width 8
106
- command _scrollcommand
107
- }.pack('side'=>'right', 'fill'=>'y')
108
- @htree.yscrollcommand proc{|first,last| _scrollbar.set(first,last)}
109
-
110
- self.build_tree
111
- end
112
-
113
- def on_after_build(_event)
114
- #ArcadiaContractListener.new(self, EditorContract, :do_editor_event)
115
- Arcadia.add_listener(self, OpenBufferEvent)
116
- end
117
-
118
- def history_file
119
- if !defined?(@arcadia_history_file)
120
- @arcadia_history_file = @arcadia.local_dir+'/'+conf('file.name')
121
- end
122
- return @arcadia_history_file
123
- end
124
-
125
- def on_after_open_buffer(_event)
126
- if _event.file
127
- self.add2history(_event.file)
128
- add_to_tree(_event.file)
129
- end
130
- end
131
-
132
- # def do_editor_event(_event)
133
- # case _event.signature
134
- # when EditorContract::FILE_AFTER_OPEN
135
- # if _event.context.file
136
- # self.add2history(_event.context.file)
137
- # add_to_tree(_event.context.file)
138
- # end
139
- # when EditorContract::FILE_AFTER_CLOSE
140
- # if _event.context.file
141
- # end
142
- # end
143
- # end
144
-
145
- def root
146
- if !defined?(@root)
147
- @root = TreeNode.new(nil, 'KRoot'){|_node|
148
- _node.rif= 'root'
149
- _node.label=''
150
- }
151
- end
152
- return @root
153
- end
154
-
155
- def build_tree
156
- file_dir = Hash.new
157
- nodes = Array.new
158
- if File.exist?(history_file)
159
- f = File::open(history_file,'r')
160
- f_open = $arcadia['pers']['editor.files.open'].split("|") if $arcadia['pers']['editor.files.open']
161
- begin
162
- _lines = f.readlines.collect!{| line | line.chomp+"\n" }.to_s
163
- _lines.sort.each{|_line|
164
- _file = _line.split(';')[0]
165
- if FileTest::exist?(_file)
166
- dir,fil =File.split(File.expand_path(_file))
167
- dir = dir.downcase if is_windows?
168
- fil = fil.downcase if is_windows?
169
- file_dir[dir] = Array.new if file_dir[dir] == nil
170
- file_dir[dir] << fil if !file_dir[dir].include?(fil)
171
- end
172
- }
173
- ensure
174
- f.close unless f.nil?
175
- end
176
- end
177
-
178
- file_dir.keys.sort.each{|_dir|
179
- node = root.dir(_dir)
180
- file_dir[_dir].each{|file|
181
- TreeNode.new(node, 'KFile'){|_node|
182
- _node.rif= _dir+'@@@'+file
183
- _node.label=file
184
- }
185
- }
186
- }
187
-
188
- @image_kdir = TkPhotoImage.new('dat' => BOOK_GIF)
189
- @image_kfile_rb = TkPhotoImage.new('dat' => RUBY_DOCUMENT_GIF)
190
- @image_kfile = TkPhotoImage.new('dat' => DOCUMENT_GIF)
191
-
192
- build_tree_from_node(root)
193
- end
194
-
195
- def add_to_tree(_file)
196
- _d, _f = File.split(File.expand_path(_file))
197
- _d = _d.downcase if is_windows?
198
- _f = _f.downcase if is_windows?
199
- _foreground = conf('color.foreground')
200
- node = root.dir(_d)
201
- if !@htree.exist?(node.rif)
202
- @htree.insert('end', node.parent.rif ,node.rif, {
203
- 'text' => node.rif ,
204
- 'helptext' => node.rif,
205
- 'deltax'=>-1,
206
- 'fill' => _foreground,
207
- 'font'=>@font,
208
- 'image'=> image('KDir')
209
- }
210
- )
211
- end
212
- _file_node_rif = _d+'@@@'+_f
213
- if !@htree.exist?(_file_node_rif)
214
- @htree.insert('end', node.rif ,_file_node_rif, {
215
- 'text' => _f ,
216
- 'helptext' => _f,
217
- 'deltax'=>-1,
218
- 'fill' => _foreground,
219
- 'font'=>@font_b,
220
- 'image'=> image('KFile',_f)
221
- }
222
- )
223
- end
224
-
225
- end
226
-
227
- def image(_kind, _label='.rb')
228
- if _kind == 'KDir'
229
- return @image_kdir
230
- elsif _kind == 'KFile' && _label.include?('.rb')
231
- return @image_kfile_rb
232
- else
233
- return @image_kfile
234
- end
235
- end
236
-
237
- def build_tree_from_node(_node)
238
- _foreground = conf('color.foreground')
239
- _sorted_sons = _node.sons.sort
240
- for inode in 0.._sorted_sons.length - 1
241
- _son = _sorted_sons[inode]
242
- @htree.insert('end', _son.parent.rif ,_son.rif, {
243
- 'text' => _son.label ,
244
- 'fill' => _foreground,
245
- 'helptext' => _son.helptext,
246
- 'deltax'=>-1,
247
- 'font'=>@font,
248
- 'image'=> image(_son.kind, _son.label)
249
- }
250
- )
251
- build_tree_from_node(_son)
252
- end
253
- end
254
-
255
-
256
- def add2history(_filename, _text_index='1.0')
257
- if _filename
258
- _filename = _filename.sub(Dir::pwd+'/',"")
259
- _filename = File.expand_path(_filename)
260
- _filename_index = _filename+";"+_text_index
261
-
262
- if File.exist?(history_file)
263
- f = File::open(history_file,'r')
264
- begin
265
- _lines = f.readlines.collect!{| line | line.chomp}
266
- ensure
267
- f.close unless f.nil?
268
- end
269
- f = File.new(history_file, "w")
270
- begin
271
- if f
272
- _l= conf('length').to_i
273
- f.syswrite(_filename_index+"\n")
274
- _lines[0.._l-2].each{|_line|
275
- _lfile = _line.split(';')
276
- if _lfile
277
- f.syswrite(_line+"\n") if (_lfile[0] != _filename)&&(_line.length > 0)
278
- end
279
- }
280
- end
281
- ensure
282
- f.close unless f.nil?
283
- end
284
- else
285
- dir,fil =File.split(File.expand_path(history_file))
286
- if !File.exist?(dir)
287
- Dir.mkdir(dir)
288
- end
289
- f = File.new(history_file, "w+")
290
- begin
291
- f.syswrite(_filename+"\n") if f
292
- ensure
293
- f.close unless f.nil?
294
- end
295
- end
296
- end
297
- end
298
- end
1
+ #
2
+ # ae-file-history.rb - Arcadia Ruby ide
3
+ # by Antonio Galeone <antonio-galeone@rubyforge.org>
4
+ #
5
+
6
+
7
+ class TreeNode
8
+ attr_reader :sons
9
+ attr_reader :parent
10
+ attr_reader :kind
11
+ attr_reader :rif, :label, :helptext
12
+ attr_writer :rif, :label, :helptext
13
+ def initialize(parent=nil, kind='KClass')
14
+ @sons = Array.new
15
+ @parent = parent
16
+ @kind = kind
17
+ @label = ''
18
+ if @parent !=nil
19
+ @parent.sons << self
20
+ end
21
+ yield(self) if block_given?
22
+ end
23
+
24
+ def <=> (other)
25
+ self.label.strip <=> other.label.strip
26
+ end
27
+
28
+ def path
29
+ _path = @label
30
+ if @parent != nil
31
+ _path = @parent.path+_path
32
+ end
33
+ return _path
34
+ end
35
+
36
+ def dir(_path)
37
+ node = nil
38
+ parent = self
39
+ sons.each{|_tree|
40
+ if _path[0.._tree.label.length-1] == _tree.label
41
+ res = _path[_tree.label.length.._path.length-1]
42
+ if ["\\","/"].include?(res[0,1])
43
+ parent = _tree
44
+ node= _tree.dir(res)
45
+ end
46
+ end
47
+ break if node != nil
48
+ }
49
+ if node == nil
50
+ node = TreeNode.new(parent,'KDir') do |_node|
51
+ _node.label=_path
52
+ _node.rif= parent.path+_path
53
+ end
54
+ end
55
+ return node
56
+ end
57
+ end
58
+
59
+
60
+
61
+ class FilesHistrory < ArcadiaExt
62
+ include Autils
63
+ attr_reader :htree
64
+
65
+ def sync_on
66
+ @sync = true
67
+ select_file_without_event(@last_file) if @last_file
68
+
69
+ #Arcadia.attach_listener(self, BufferRaisedEvent)
70
+ end
71
+
72
+ def sync_off
73
+ @sync = false
74
+ #Arcadia.detach_listener(self, BufferRaisedEvent)
75
+ end
76
+
77
+ def on_before_build(_event)
78
+ Arcadia.attach_listener(self, BufferRaisedEvent)
79
+ end
80
+
81
+ def on_build(_event)
82
+ @h_stack = Array.new
83
+ @cb_sync = TkCheckButton.new(self.frame.hinner_frame, Arcadia.style('checkbox')){
84
+ text 'Sync'
85
+ justify 'left'
86
+ variable 1
87
+ #command do_check
88
+ place('x' => 0,'y' => 0,'height' => 22)
89
+ }
90
+
91
+ do_check = proc {
92
+ if @cb_sync.cget('onvalue')==@cb_sync.cget('variable').value.to_i
93
+ sync_on
94
+ else
95
+ sync_off
96
+ end
97
+ }
98
+ @sync = false
99
+ @cb_sync.command(do_check)
100
+
101
+ do_select_item = proc{|_self|
102
+ if _self.selection_get[0].length >0
103
+ _selected = ""
104
+ _self.selection_get[0].each{|_block|
105
+ _selected = _selected + _block.to_s + "\s"
106
+ }
107
+ _selected = _selected.strip
108
+ else
109
+ _selected = _self.selection_get[0]
110
+ end
111
+ _dir, _file = _selected.split('@@@')
112
+ if _file
113
+ _file = File.expand_path( _file , _dir )
114
+ else
115
+ _file = Tk.getOpenFile('initialdir'=>_dir)
116
+ end
117
+ if _file
118
+ Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file))
119
+ #EditorContract.instance.open_file(self,'file'=>_file)
120
+ end
121
+ }
122
+ # _background = conf('color.background')
123
+ # _foreground = conf('color.foreground')
124
+ @font = Arcadia.conf('treeitem.font')
125
+ @font_b = "#{Arcadia.conf('treeitem.font')} bold"
126
+
127
+ @htree = Tk::BWidget::Tree.new(self.frame.hinner_frame, Arcadia.style('treepanel')){
128
+ #relief 'flat'
129
+ showlines false
130
+ deltay 18
131
+ #background _background
132
+ #crossfill _foreground
133
+ #dragenabled true
134
+ selectcommand proc{ do_select_item.call(self) }
135
+ place('relwidth' => 1,'relheight' => '1', 'x' => '0','y' => '22', 'height' => -22)
136
+ }
137
+ _scrollcommand = proc{|*args| @htree.yview(*args)}
138
+ _scrollbar = TkScrollbar.new(self.frame.hinner_frame, Arcadia.style('scrollbar')){|s|
139
+ width 8
140
+ command _scrollcommand
141
+ }.pack('side'=>'right', 'fill'=>'y')
142
+ @htree.yscrollcommand proc{|first,last| _scrollbar.set(first,last)}
143
+
144
+ self.build_tree
145
+ end
146
+
147
+ def on_after_build(_event)
148
+ #ArcadiaContractListener.new(self, EditorContract, :do_editor_event)
149
+ Arcadia.attach_listener(self, OpenBufferEvent)
150
+ end
151
+
152
+ def history_file
153
+ if !defined?(@arcadia_history_file)
154
+ @arcadia_history_file = @arcadia.local_dir+'/'+conf('file.name')
155
+ end
156
+ return @arcadia_history_file
157
+ end
158
+
159
+ def on_after_open_buffer(_event)
160
+ #Arcadia.new_error_msg(self, "on_after_open_buffer _event.file=#{_event.file}")
161
+
162
+ if _event.file
163
+ self.add2history(_event.file)
164
+ add_to_tree(_event.file)
165
+ end
166
+ end
167
+
168
+ def select_file_without_event(_file)
169
+ _d, _f = File.split(File.expand_path(_file))
170
+ _d = _d.downcase if is_windows?
171
+ _f = _f.downcase if is_windows?
172
+ _file_node_rif = _d+'@@@'+_f
173
+ if @htree.exist?(_file_node_rif)
174
+ _proc = @htree.selectcommand
175
+ @htree.selectcommand(proc{nil})
176
+ begin
177
+ parent = root.dir(_d)
178
+ @htree.selection_clear
179
+ @htree.selection_add(_file_node_rif)
180
+ #@htree.close_tree('root')
181
+ while !parent.nil? && parent.rif != 'root'
182
+ @htree.open_tree(parent.rif, false)
183
+ parent = parent.parent
184
+ end
185
+ @htree.see(_file_node_rif)
186
+ ensure
187
+ @htree.selectcommand(_proc)
188
+ end
189
+ end
190
+ end
191
+
192
+ def on_buffer_raised(_event)
193
+ return if _event.file.nil?
194
+ @last_file = _event.file
195
+ if @sync
196
+ select_file_without_event(_event.file)
197
+ end
198
+ end
199
+
200
+ # def do_editor_event(_event)
201
+ # case _event.signature
202
+ # when EditorContract::FILE_AFTER_OPEN
203
+ # if _event.context.file
204
+ # self.add2history(_event.context.file)
205
+ # add_to_tree(_event.context.file)
206
+ # end
207
+ # when EditorContract::FILE_AFTER_CLOSE
208
+ # if _event.context.file
209
+ # end
210
+ # end
211
+ # end
212
+
213
+ def root
214
+ if !defined?(@root)
215
+ @root = TreeNode.new(nil, 'KRoot'){|_node|
216
+ _node.rif= 'root'
217
+ _node.label=''
218
+ }
219
+ end
220
+ return @root
221
+ end
222
+
223
+ def build_tree
224
+ file_dir = Hash.new
225
+ nodes = Array.new
226
+ if File.exist?(history_file)
227
+ f = File::open(history_file,'r')
228
+ f_open = $arcadia['pers']['editor.files.open'].split("|") if $arcadia['pers']['editor.files.open']
229
+ begin
230
+ _lines = f.readlines.collect!{| line | line.chomp+"\n" }.to_s
231
+ _lines.sort.each{|_line|
232
+ _file = _line.split(';')[0]
233
+ if FileTest::exist?(_file)
234
+ dir,fil =File.split(File.expand_path(_file))
235
+ dir = dir.downcase if is_windows?
236
+ fil = fil.downcase if is_windows?
237
+ file_dir[dir] = Array.new if file_dir[dir] == nil
238
+ file_dir[dir] << fil if !file_dir[dir].include?(fil)
239
+ end
240
+ }
241
+ ensure
242
+ f.close unless f.nil?
243
+ end
244
+ end
245
+
246
+ file_dir.keys.sort.each{|_dir|
247
+ node = root.dir(_dir)
248
+ file_dir[_dir].each{|file|
249
+ TreeNode.new(node, 'KFile'){|_node|
250
+ _node.rif= _dir+'@@@'+file
251
+ _node.label=file
252
+ }
253
+ }
254
+ }
255
+
256
+ @image_kdir = TkPhotoImage.new('dat' => BOOK_GIF)
257
+ @image_kfile_rb = TkPhotoImage.new('dat' => RUBY_DOCUMENT_GIF)
258
+ @image_kfile = TkPhotoImage.new('dat' => DOCUMENT_GIF)
259
+
260
+ build_tree_from_node(root)
261
+ end
262
+
263
+ def add_to_tree(_file)
264
+ _d, _f = File.split(File.expand_path(_file))
265
+ #Arcadia.new_error_msg(self, "add_to_tree _file=#{_file}")
266
+ #Arcadia.new_error_msg(self, "add_to_tree _d=#{_d}")
267
+ #Arcadia.new_error_msg(self, "add_to_tree _f=#{_f}")
268
+ _d = _d.downcase if is_windows?
269
+ _f = _f.downcase if is_windows?
270
+ #_foreground = conf('color.foreground')
271
+ node = root.dir(_d)
272
+ if !@htree.exist?(node.rif)
273
+ #Arcadia.new_error_msg(self, "add_to_tree node.parent.rif=#{node.parent.rif}")
274
+ #Arcadia.new_error_msg(self, "add_to_tree node.rif=#{node.rif}")
275
+ @htree.insert('end', node.parent.rif ,node.rif, {
276
+ 'text' => node.label,
277
+ 'helptext' => node.rif,
278
+ 'deltax'=>-1,
279
+ # 'fill' => _foreground,
280
+ # 'font'=>@font,
281
+ 'image'=> image('KDir')
282
+ }.update(Arcadia.style('treeitem'))
283
+ )
284
+ end
285
+ _file_node_rif = _d+'@@@'+_f
286
+ if !@htree.exist?(_file_node_rif)
287
+ @htree.insert('end', node.rif ,_file_node_rif, {
288
+ 'text' => _f ,
289
+ 'helptext' => _f,
290
+ 'deltax'=>-1,
291
+ #'fill' => _foreground,
292
+ #'font'=>@font_b,
293
+ 'image'=> image('KFile',_f)
294
+ }.update(Arcadia.style('treeitem'))
295
+ )
296
+ end
297
+
298
+ end
299
+
300
+ def image(_kind, _label='.rb')
301
+ if _kind == 'KDir'
302
+ return @image_kdir
303
+ elsif _kind == 'KFile' && _label.include?('.rb')
304
+ return @image_kfile_rb
305
+ else
306
+ return @image_kfile
307
+ end
308
+ end
309
+
310
+ def build_tree_from_node(_node)
311
+ #_foreground = conf('color.foreground')
312
+ _sorted_sons = _node.sons.sort
313
+ for inode in 0.._sorted_sons.length - 1
314
+ _son = _sorted_sons[inode]
315
+ @htree.insert('end', _son.parent.rif ,_son.rif, {
316
+ 'text' => _son.label ,
317
+ # 'fill' => _foreground,
318
+ 'helptext' => _son.helptext,
319
+ 'deltax'=>-1,
320
+ # 'font'=>@font,
321
+ 'image'=> image(_son.kind, _son.label)
322
+ }.update(Arcadia.style('treeitem'))
323
+ )
324
+ build_tree_from_node(_son)
325
+ end
326
+ end
327
+
328
+
329
+ def add2history(_filename, _text_index='1.0')
330
+ if _filename
331
+ _filename = _filename.sub(Dir::pwd+'/',"")
332
+ _filename = File.expand_path(_filename)
333
+ _filename_index = _filename+";"+_text_index
334
+ #Arcadia.new_error_msg(self, "add2history _filename=#{_filename}")
335
+ #Arcadia.new_error_msg(self, "add2history history_file=#{history_file}")
336
+
337
+ if File.exist?(history_file)
338
+ f = File::open(history_file,'r')
339
+ begin
340
+ _lines = f.readlines.collect!{| line | line.chomp}
341
+ ensure
342
+ f.close unless f.nil?
343
+ end
344
+ f = File.new(history_file, "w")
345
+ begin
346
+ if f
347
+ _l= conf('length').to_i
348
+ f.syswrite(_filename_index+"\n")
349
+ _lines[0.._l-2].each{|_line|
350
+ _lfile = _line.split(';')
351
+ if _lfile
352
+ f.syswrite(_line+"\n") if (_lfile[0] != _filename)&&(_line.length > 0)
353
+ end
354
+ }
355
+ end
356
+ ensure
357
+ f.close unless f.nil?
358
+ end
359
+ else
360
+ dir,fil =File.split(File.expand_path(history_file))
361
+ if !File.exist?(dir)
362
+ Dir.mkdir(dir)
363
+ end
364
+ f = File.new(history_file, "w+")
365
+ begin
366
+ f.syswrite(_filename+"\n") if f
367
+ ensure
368
+ f.close unless f.nil?
369
+ end
370
+ end
371
+ end
372
+ end
373
+ end