arcadia 0.6.0 → 0.7.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.
@@ -1,5 +1,5 @@
1
1
  name=editor
2
- frames=0.1,0.0
2
+ frames=0.1,0.2
3
3
  frames.labels=Editor,Outline
4
4
  frames.names=editor,editor_outline
5
5
  active=yes
@@ -17,6 +17,8 @@ tab-replace-width-space=2
17
17
  ##tabs.side=bottom
18
18
  tabs.side=top
19
19
  complete-code=yes
20
+ close-last-if-not-modified=yes
21
+ max-file-open=3 #todo
20
22
  # editor
21
23
  #font=courier 11
22
24
  #font.bold=courier 11 bold
@@ -68,6 +68,11 @@ class SourceStructure
68
68
  end
69
69
  if (m[0].strip[0..4] == "class" && m.pre_match.strip.length==0)
70
70
  _kind = 'KClass'
71
+ if m.post_match.strip[0..1]=='<<'
72
+ hinner_class = true
73
+ else
74
+ hinner_class = false
75
+ end
71
76
  elsif (m[0].strip[0..4] == "class" && m.pre_match.strip.length>0)
72
77
  _row = _row +1
73
78
  _liv = _liv - 1
@@ -96,21 +101,13 @@ class SourceStructure
96
101
  # _row = _row +1
97
102
  end
98
103
 
99
- if _livs[_liv-1] && _livs[_liv-1].kind != 'KDef'
104
+ if _livs[_liv-1] && (_livs[_liv-1].kind != 'KDef' || (_livs[_liv-1].kind == 'KDef' && _kind == 'KClass' && hinner_class))
100
105
  TreeNode.new(_parent, _kind){|_node|
101
106
  _node.label = _label
102
107
  _node.helptext = _helptext
103
108
  _node.rif = _row.to_s
104
109
  _livs[_pliv + 1]=_node
105
110
  }
106
- # elsif _kind == 'KDef' && _parent == @root
107
- # TreeNode.new(_livs[_liv+1], _kind){|_node|
108
- # _node.label = _label
109
- # _node.helptext = _helptext
110
- # _node.rif = _row.to_s
111
- # _livs[_pliv+2]=_node
112
- # }
113
- # _liv = _liv + 2
114
111
  else
115
112
  TreeNode.new(_livs[_liv-3], _kind){|_node|
116
113
  _node.label = _label
@@ -216,27 +213,12 @@ class SafeCompleteCode
216
213
  @col = _col.to_i
217
214
  @ss = SourceStructure.new(_source)
218
215
  @filter=''
219
- #@candidates = Array.new
216
+ @words = Array.new
220
217
  process_source
221
218
  end
222
219
 
223
- # def dot_trip(_var_name)
224
- # ret = "_candidates << #{_var_name}.class.to_s.sub('#{self.class.to_s}::','')\n"
225
- # ret = ret + "#{_var_name}.class.instance_methods.each{|m|\n"
226
- # ret = ret + "meth = #{_var_name}.method(m)\n"
227
- # ret = ret + "_candidates << meth.owner.to_s.sub('#{self.class.to_s}::','')+'#'+m+'#'+meth.arity.to_s\n"
228
- # ret = ret + "}\n"
229
- # #ret = ret + "exit\n"
230
- # ret
231
- # end
232
-
233
220
  def dot_trip(_var_name)
234
221
  ret = "_class=#{_var_name}.class.name\n"
235
- # ret = ret +"if _class=='Class'\n"
236
- # ret = ret +" _methods=#{_var_name}.singleton_methods\n"
237
- # ret = ret +"else\n"
238
- # ret = ret +" _methods=#{_var_name}.class.instance_methods\n"
239
- # ret = ret +"end\n"
240
222
  ret = ret +" _methods=#{_var_name}.methods\n"
241
223
  ret = ret +"owner_on = Method.instance_methods.include?('owner')\n"
242
224
  ret = ret + "_methods.each{|m|\n"
@@ -306,6 +288,17 @@ class SafeCompleteCode
306
288
  @is_dot
307
289
  end
308
290
 
291
+ def refresh_words
292
+ @words.clear
293
+ _re = /[\s\t\n]#{@filter}[a-zA-Z0-9\-_]*/
294
+ m = _re.match(@source)
295
+ while m && (_txt=m.post_match)
296
+ can = m[0].strip
297
+ @words << can if can != @filter
298
+ m = _re.match(_txt)
299
+ end
300
+ end
301
+
309
302
  def process_source
310
303
  @modified_source = ""
311
304
  @modified_row = @row
@@ -329,7 +322,7 @@ class SafeCompleteCode
329
322
  end
330
323
  focus_segment = focus_segment+seg
331
324
  }
332
- @filter = focus_segment_array[-1].strip
325
+ @filter = focus_word(focus_segment_array[-1].strip)
333
326
  else
334
327
  focus_segment = ''
335
328
  @filter = focus_word(focus_line[0..@col-1].strip)
@@ -446,6 +439,10 @@ class SafeCompleteCode
446
439
  @modified_row = @modified_row+1+ss_len
447
440
  end
448
441
  end
442
+ if @filter.strip.length > 0
443
+ # refresh_words(source_array)
444
+ refresh_words
445
+ end
449
446
 
450
447
  # Arcadia.console(self, 'msg'=>@modified_source)
451
448
  # Arcadia.console(self, 'msg'=>"@modified_row=#{@modified_row}")
@@ -458,26 +455,22 @@ class SafeCompleteCode
458
455
 
459
456
  def focus_word(focus_segment)
460
457
  focus_world = ''
458
+ char = focus_segment[-1..-1]
459
+ while [")","]","}"].include?(char)
460
+ char=focus_segment[-2..-2]
461
+ focus_segment = focus_segment[0..-2]
462
+ end
461
463
  j = focus_segment.length - 1
462
- char = focus_segment[j..j]
463
- if char != ')'
464
- while !["\s","\t",";",",","(","[","{",">"].include?(char) && j >= 0
465
- focus_world = "#{char}#{focus_world}"
466
- j=j-1
467
- char = focus_segment[j..j]
468
- end
469
- else
470
- while !["\s","\t",";"].include?(char) && j >= 0
471
- focus_world = "#{char}#{focus_world}"
472
- j=j-1
473
- char = focus_segment[j..j]
474
- end
464
+ while !["\s","\t",";",",","(","[","{",">"].include?(char) && j >= 0
465
+ focus_world = "#{char}#{focus_world}"
466
+ j=j-1
467
+ char = focus_segment[j..j]
475
468
  end
476
469
  focus_world
477
470
  end
478
471
 
479
472
  def candidates(_show_error = false)
480
- temp_file = create_temp_file(@file)
473
+ temp_file = create_modified_temp_file(@file)
481
474
  begin
482
475
  _cmp_s = "|ruby '#{temp_file}'"
483
476
  _ret = nil
@@ -488,27 +481,22 @@ class SafeCompleteCode
488
481
  line
489
482
  }
490
483
  end
491
- # if _ret.length == 0 && _show_error
492
- # _cmp_s_d = _cmp_s+" 2>&1"
493
- # _error = nil
494
- # open(_cmp_s_d,"r") do
495
- # |f|
496
- # _error = f.readlines.collect!{| line | line.chomp}
497
- # end
498
- # if _error != nil && _error.length > 0
499
- # Arcadia.console(self, 'msg'=>_error.to_s, 'level'=>'error')
500
- # end
501
- # end
484
+ if @filter.strip.length > 0
485
+ @words.each{|w|
486
+ if !_ret.include?(w) # && w[0..@filter.length-1] == @filter
487
+ _ret << w
488
+ end
489
+ }
490
+ end
502
491
  _ret.sort
503
492
  rescue Exception => e
504
- # Arcadia.console(self, 'msg'=>e.to_s, 'level'=>'error')
493
+ #Arcadia.console(self, 'msg'=>e.to_s, 'level'=>'error')
505
494
  ensure
506
495
  File.delete(temp_file) if File.exist?(temp_file)
507
496
  end
508
497
  end
509
-
510
498
 
511
- def create_temp_file(_base_file=nil)
499
+ def create_modified_temp_file(_base_file=nil)
512
500
  if _base_file
513
501
  _file = _base_file+'~~'
514
502
  else
@@ -623,7 +611,7 @@ end
623
611
 
624
612
  class AgEditor
625
613
  include Configurable
626
- attr_reader :file
614
+ attr_accessor :file
627
615
  attr_reader :read_only
628
616
  attr_reader :page_frame
629
617
  attr_reader :text, :root
@@ -631,6 +619,7 @@ class AgEditor
631
619
  @controller = _controller
632
620
  @page_frame = _page_frame
633
621
  @set_mod = false
622
+ @modified_from_opening=false
634
623
  # @font = @controller.conf('font')
635
624
  # @font_bold = @controller.conf('font.bold')
636
625
  @font = Arcadia.conf('edit.font')
@@ -655,6 +644,10 @@ class AgEditor
655
644
  # @fm.is_left_hide?
656
645
  # end
657
646
  # end
647
+
648
+ def modified_from_opening?
649
+ @modified_from_opening
650
+ end
658
651
 
659
652
  def xy_insert
660
653
  _index_now = @text.index('insert')
@@ -727,38 +720,18 @@ class AgEditor
727
720
 
728
721
 
729
722
  def initialize_text(_frame)
730
- # @v_scroll = TkScrollbar.new(_frame,{
731
- # 'orient'=>'vertical'}.update(Arcadia.style('scrollbar'))
732
- # ).pack('side' => 'right', 'fill' => 'y')
733
- @text = TkScrollText.new(_frame, Arcadia.style('edit')){|j|
723
+ @text = TkScrollText.new(_frame, Arcadia.style('text')){|j|
734
724
  wrap 'none'
735
725
  undo true
736
- insertofftime 200
737
- insertontime 200
738
- highlightthickness 0
739
- insertwidth 3
726
+ # insertofftime 200
727
+ # insertontime 200
728
+ # highlightthickness 0
729
+ # insertwidth 3
740
730
  exportselection true
741
731
  autoseparators true
742
732
  padx 0
743
733
  tabs $arcadia['conf']['editor.tabs']
744
- # place(
745
- # 'x'=>0,
746
- # 'y'=>0,
747
- # 'width' => -15,
748
- # 'relheight'=>1,
749
- # 'relwidth'=>1,
750
- # 'bordermode'=>'outside'
751
- # )
752
734
  }
753
-
754
- # class << @text
755
- # def do_yscrollcommand(first,last)
756
- # super
757
- # do_line_update()
758
- # end
759
- # end
760
-
761
- # @text.configure('font', @font);
762
735
 
763
736
  #do_tag_configure_global('debug')
764
737
  @text.tag_configure('eval','foreground' => 'yellow', 'background' =>'red','borderwidth'=>1, 'relief'=>'raised')
@@ -770,7 +743,6 @@ class AgEditor
770
743
  @text.show_v_scroll
771
744
  @text.show_h_scroll
772
745
  @text_cursor = @text.cget('cursor')
773
-
774
746
  end
775
747
 
776
748
  def create_temp_file
@@ -874,7 +846,6 @@ class AgEditor
874
846
 
875
847
  def raise_complete_code(_candidates, _row, _col, _filter='')
876
848
  @raised_listbox_frame.destroy if @raised_listbox_frame != nil
877
- #@raised_listbox.destroy if @raised_listbox != nil
878
849
  _index_call = _row+'.'+_col
879
850
  _index_now = @text.index('insert')
880
851
  if _index_call == _index_now
@@ -882,227 +853,233 @@ class AgEditor
882
853
  if _target.strip == '('
883
854
  _target = @text.get('insert - 2 chars wordstart','insert')
884
855
  end
885
- if _target.strip.length > 0 && _target != '.'
886
- extra_len = _target.length.+@
887
- _begin_index = _index_now<<' - '<<extra_len.to_s<<' chars'
888
- @text.tag_add('sel', _begin_index, _index_now)
889
- else
890
- _begin_index = _index_now
891
- extra_len = 0
892
- end
893
- if _candidates.length >= 1
894
- _rx, _ry, _widht, heigth = @text.bbox(_begin_index);
895
- _x = _rx + TkWinfo.rootx(@text)
896
- _y = _ry + TkWinfo.rooty(@text) + @font_metrics[2][1]
897
- _xroot = _x - TkWinfo.rootx(Arcadia.instance.layout.root)
898
- _yroot = _y - TkWinfo.rooty(Arcadia.instance.layout.root)
899
-
900
- _max_height = TkWinfo.screenheight(Arcadia.instance.layout.root) - _y - 5
901
- self.complete_code_begin
902
-
903
- # @raised_listbox_frame = TkResizingTitledFrame.new(Arcadia.instance.layout.root)
904
- @raised_listbox_frame = TkFrame.new(Arcadia.instance.layout.root, {
905
- :padx=>"1",
906
- :pady=>"1",
907
- :background=> Arcadia.conf("foreground")
908
- })
909
-
910
- @raised_listbox = TkTextListBox.new(@raised_listbox_frame, {
911
- :takefocus=>true,
912
- :selectbackground=>Arcadia.conf('hightlight.1.background'),
913
- :selectforeground=>Arcadia.conf('hightlight.1.foreground')}.update(Arcadia.style('listbox'))
914
- )
915
- _char_height = @font_metrics[2][1]
916
- _width = 0
917
- _docs_entries = Hash.new
918
- _item_num = 0
919
- _update_list = proc{|_in|
920
- _in.strip!
921
- @raised_listbox.clear
922
- _length = 0
923
- _candidates.each{|value|
924
- _doc = value.strip
925
- _class, _key, _arity = _doc.split('#')
926
- if _key && _arity
927
- args = arity_to_str(_arity.to_i)
928
- if args.length > 0
929
- _key = "#{_key}(#{args})"
930
- end
931
- end
932
-
933
- if _key && _class && _key.strip.length > 0 && _class.strip.length > 0
934
- _item = "#{_key.strip} - #{_class.strip}"
935
- elsif _key && _key.strip.length > 0
936
- _item = "#{_key.strip}"
937
- else
938
- _key = "#{_doc.strip}"
939
- _item = "#{_doc.strip}"
940
- end
941
- if _in.nil? || _in.strip.length == 0 || _item[0.._in.length-1] == _in
942
- #|| _item[0.._in.length-1].downcase == _in
943
- _docs_entries[_item]= _doc
944
- # @raised_listbox.insert('end', _item)
945
- @raised_listbox.add(_item)
946
- _temp_length = _item.length
947
- _length = _temp_length if _temp_length > _length
948
- _item_num = _item_num+1
949
- _last_valid_key = _key
856
+ if _target.strip.length > 0 && _target != '.'
857
+ extra_len = _target.length.+@
858
+ _begin_index = _index_now<<' - '<<extra_len.to_s<<' chars'
859
+ @text.tag_add('sel', _begin_index, _index_now)
860
+ else
861
+ _begin_index = _index_now
862
+ extra_len = 0
863
+ end
864
+ if _candidates.length >= 1
865
+ _rx, _ry, _widht, heigth = @text.bbox(_begin_index);
866
+ _x = _rx + TkWinfo.rootx(@text)
867
+ _y = _ry + TkWinfo.rooty(@text) + @font_metrics[2][1]
868
+ _xroot = _x - TkWinfo.rootx(Arcadia.instance.layout.root)
869
+ _yroot = _y - TkWinfo.rooty(Arcadia.instance.layout.root)
870
+
871
+ _max_height = TkWinfo.screenheight(Arcadia.instance.layout.root) - _y - 5
872
+ self.complete_code_begin
873
+
874
+ # @raised_listbox_frame = TkResizingTitledFrame.new(Arcadia.instance.layout.root)
875
+ @raised_listbox_frame = TkFrame.new(Arcadia.instance.layout.root, {
876
+ :padx=>"1",
877
+ :pady=>"1",
878
+ :background=> Arcadia.conf("foreground")
879
+ })
880
+
881
+ @raised_listbox = TkTextListBox.new(@raised_listbox_frame, {
882
+ :takefocus=>true,
883
+ :selectbackground=>Arcadia.conf('hightlight.1.background'),
884
+ :selectforeground=>Arcadia.conf('hightlight.1.foreground')}.update(Arcadia.style('listbox'))
885
+ )
886
+ _char_height = @font_metrics[2][1]
887
+ _width = 0
888
+ _docs_entries = Hash.new
889
+ _item_num = 0
890
+ _update_list = proc{|_in|
891
+ _in.strip!
892
+ @raised_listbox.clear
893
+ _length = 0
894
+ _candidates.each{|value|
895
+ _doc = value.strip
896
+ _class, _key, _arity = _doc.split('#')
897
+ if _key && _arity
898
+ args = arity_to_str(_arity.to_i)
899
+ if args.length > 0
900
+ _key = "#{_key}(#{args})"
950
901
  end
951
- }
952
- _width = _length*8
953
- @raised_listbox.select(1)
954
- # p "_update_list end-->#{Time.new}"
955
-
956
- Tk.event_generate(@raised_listbox, "1") if TkWinfo.mapped?(@raised_listbox)
957
- }
958
-
959
- _insert_selected_value = proc{
960
- #_value = @raised_listbox.get('active').split('-')[0].strip
961
- if @raised_listbox.selected_line && @raised_listbox.selected_line.strip.length>0
962
- _value = @raised_listbox.selected_line.split('-')[0].strip
963
- @raised_listbox_frame.grab("release")
964
- @raised_listbox_frame.destroy
965
- #_menu.destroy
966
- @text.focus
967
- @text.delete(_begin_index,'insert')
968
- @text.insert('insert',_value.strip)
969
- complete_code_end
902
+ end
970
903
 
971
- _to_search = 'arg1'
972
- _argindex = @text.search(_to_search,_begin_index)
973
- if !(_argindex && _argindex.length>0)
974
- _to_search = '*'
975
- _argindex = @text.search(_to_search,_begin_index)
904
+ if _key && _class && _key.strip.length > 0 && _class.strip.length > 0
905
+ _item = "#{_key.strip} - #{_class.strip}"
906
+ elsif _key && _key.strip.length > 0
907
+ _item = "#{_key.strip}"
908
+ else
909
+ _key = "#{_doc.strip}"
910
+ _item = "#{_doc.strip}"
976
911
  end
977
- if _argindex && _argindex.length>0
978
- _argrow, _argcol = _argindex.split('.')
979
- if _argrow.to_i == _row.to_i
980
- _argindex_sel_end = _argrow.to_i.to_s+'.'+(_argcol.to_i+_to_search.length).to_i.to_s
981
- @text.tag_add('sel', _argindex,_argindex_sel_end)
982
- @text.set_insert(_argindex)
983
- end
912
+ if _in.nil? || _in.strip.length == 0 || _item[0.._in.length-1] == _in
913
+ #|| _item[0.._in.length-1].downcase == _in
914
+ _docs_entries[_item]= _doc
915
+ # @raised_listbox.insert('end', _item)
916
+ @raised_listbox.add(_item)
917
+ _temp_length = _item.length
918
+ _length = _temp_length if _temp_length > _length
919
+ _item_num = _item_num+1
920
+ _last_valid_key = _key
984
921
  end
922
+ }
923
+ _width = _length*8
924
+ @raised_listbox.select(1)
925
+ # p "_update_list end-->#{Time.new}"
926
+
927
+ Tk.event_generate(@raised_listbox, "1") if TkWinfo.mapped?(@raised_listbox)
928
+ }
929
+
930
+ _insert_selected_value = proc{
931
+ #_value = @raised_listbox.get('active').split('-')[0].strip
932
+ if @raised_listbox.selected_line && @raised_listbox.selected_line.strip.length>0
933
+ _value = @raised_listbox.selected_line.split('-')[0].strip
934
+ @raised_listbox_frame.grab("release")
935
+ @raised_listbox_frame.destroy
936
+ #_menu.destroy
937
+ @text.focus
938
+ @text.delete(_begin_index,'insert')
939
+
940
+ # workaround for @ char
941
+ _value = _value.strip
942
+ if _value[0..0] !=_target[0..0] && _value[1..1] == _target[0..0]
943
+ _value = _value[1..-1]
985
944
  end
945
+ @text.insert('insert',_value)
946
+ complete_code_end
986
947
 
987
- Tk.callback_break
988
- }
989
- _update_list.call(_filter)
990
- if _item_num == 0
991
- @raised_listbox_frame.destroy
992
- self.complete_code_end
993
- return
994
- elsif _item_num == 1
995
- _insert_selected_value.call
996
- return
948
+ _to_search = 'arg1'
949
+ _argindex = @text.search(_to_search,_begin_index)
950
+ if !(_argindex && _argindex.length>0)
951
+ _to_search = '*'
952
+ _argindex = @text.search(_to_search,_begin_index)
953
+ end
954
+ if _argindex && _argindex.length>0
955
+ _argrow, _argcol = _argindex.split('.')
956
+ if _argrow.to_i == _row.to_i
957
+ _argindex_sel_end = _argrow.to_i.to_s+'.'+(_argcol.to_i+_to_search.length).to_i.to_s
958
+ @text.tag_add('sel', _argindex,_argindex_sel_end)
959
+ @text.set_insert(_argindex)
960
+ end
961
+ end
997
962
  end
998
- _width = _width + 10
999
- #_height = (candidates.length+1)*_char_height
1000
- _height = 15*_char_height
1001
- _height = _max_height if _height > _max_height
1002
963
 
1003
- _buffer = @text.get(_begin_index, 'insert')
1004
- _buffer_ini_length = _buffer.length
1005
- @raised_listbox_frame.place('x'=>_xroot,'y'=>_yroot, 'width'=>_width, 'height'=>_height)
1006
- @raised_listbox.show(0,0,'inside')
1007
- @raised_listbox.show_v_scroll
1008
- @raised_listbox.focus
1009
- #@raised_listbox.activate(0)
1010
- @raised_listbox.select(1)
1011
- @raised_listbox_frame.grab("set")
1012
- # Tk.event_generate(@raised_listbox, "1")
1013
-
1014
-
1015
- @raised_listbox.bind_append("Double-ButtonPress-1",
1016
- proc{|x,y|
1017
- _index = @raised_listbox.index("@#{x},#{y}")
1018
- _line = _index.split('.')[0].to_i
1019
- @raised_listbox.select(_line)
1020
- _insert_selected_value.call
1021
- }, "%x %y")
1022
- @raised_listbox.bind_append('Shift-KeyPress'){|e|
1023
- # todo
1024
- case e.keysym
1025
- when 'parenleft'
1026
- @text.insert('insert','(')
1027
- _buffer = _buffer + '('
1028
- _item_num = 0
1029
- _update_list.call(_buffer)
1030
- if _item_num == 1
1031
- _insert_selected_value.call
1032
- end
1033
- Tk.callback_break
1034
- when 'A'..'Z','equal','greater'
1035
- if e.keysym == 'equal'
1036
- ch = '='
1037
- elsif e.keysym == 'greater'
1038
- ch = '>'
1039
- else
1040
- ch = e.keysym
1041
- end
1042
- @text.insert('insert',ch)
1043
- _buffer = _buffer + ch
1044
- _update_list.call(_buffer)
1045
- Tk.callback_break
964
+ Tk.callback_break
965
+ }
966
+ _update_list.call(_filter)
967
+ if _item_num == 0
968
+ @raised_listbox_frame.destroy
969
+ self.complete_code_end
970
+ return
971
+ elsif _item_num == 1
972
+ _insert_selected_value.call
973
+ return
974
+ end
975
+ _width = _width + 30
976
+ #_height = (candidates.length+1)*_char_height
977
+ _height = 15*_char_height
978
+ _height = _max_height if _height > _max_height
979
+
980
+ _buffer = @text.get(_begin_index, 'insert')
981
+ _buffer_ini_length = _buffer.length
982
+ @raised_listbox_frame.place('x'=>_xroot,'y'=>_yroot, 'width'=>_width, 'height'=>_height)
983
+ @raised_listbox.show(0,0,'inside')
984
+ @raised_listbox.show_v_scroll
985
+ @raised_listbox.focus
986
+ #@raised_listbox.activate(0)
987
+ @raised_listbox.select(1)
988
+ @raised_listbox_frame.grab("set")
989
+ # Tk.event_generate(@raised_listbox, "1")
990
+
991
+
992
+ @raised_listbox.bind_append("Double-ButtonPress-1",
993
+ proc{|x,y|
994
+ _index = @raised_listbox.index("@#{x},#{y}")
995
+ _line = _index.split('.')[0].to_i
996
+ @raised_listbox.select(_line)
997
+ _insert_selected_value.call
998
+ }, "%x %y")
999
+ @raised_listbox.bind_append('Shift-KeyPress'){|e|
1000
+ # todo
1001
+ case e.keysym
1002
+ when 'parenleft'
1003
+ @text.insert('insert','(')
1004
+ _buffer = _buffer + '('
1005
+ _item_num = 0
1006
+ _update_list.call(_buffer)
1007
+ if _item_num == 1
1008
+ _insert_selected_value.call
1009
+ end
1010
+ Tk.callback_break
1011
+ when 'A'..'Z','equal','greater'
1012
+ if e.keysym == 'equal'
1013
+ ch = '='
1014
+ elsif e.keysym == 'greater'
1015
+ ch = '>'
1046
1016
  else
1047
- if e.keysym.length > 1
1048
- p ">#{e.keysym}<"
1049
- Tk.callback_break
1050
- end
1051
- end
1052
- }
1053
- @raised_listbox.bind_append('KeyPress'){|e|
1054
- case e.keysym
1055
- when 'Escape'
1056
- @raised_listbox.grab("release")
1057
- @raised_listbox_frame.destroy
1058
- complete_code_end
1059
- @text.focus
1060
- #_menu.destroy
1017
+ ch = e.keysym
1018
+ end
1019
+ @text.insert('insert',ch)
1020
+ _buffer = _buffer + ch
1021
+ _update_list.call(_buffer)
1022
+ Tk.callback_break
1023
+ else
1024
+ if e.keysym.length > 1
1025
+ p ">#{e.keysym}<"
1061
1026
  Tk.callback_break
1027
+ end
1028
+ end
1029
+ }
1030
+ @raised_listbox.bind_append('KeyPress'){|e|
1031
+ case e.keysym
1032
+ when 'Escape'
1033
+ @raised_listbox.grab("release")
1034
+ @raised_listbox_frame.destroy
1035
+ complete_code_end
1036
+ @text.focus
1037
+ #_menu.destroy
1038
+ Tk.callback_break
1062
1039
  # when 'Return'
1063
1040
  # _insert_selected_value.call
1064
- when 'F1'
1065
- _key = @raised_listbox.selected_line.split('-')[0].strip
1066
- _x, _y = xy_insert
1067
- Arcadia.process_event(DocCodeEvent.new(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y))
1068
- #EditorContract.instance.doc_code(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y)
1069
- when 'a'..'z','less','space'
1070
- if e.keysym == 'less'
1071
- ch = '<'
1072
- elsif e.keysym == 'space'
1073
- ch = ''
1074
- else
1075
- ch = e.keysym
1076
- end
1077
- @text.insert('insert',ch)
1078
- _buffer = _buffer + ch
1079
- _update_list.call(_buffer)
1080
- Tk.callback_break
1081
- when 'BackSpace'
1082
- if _buffer.length > _buffer_ini_length
1083
- @text.delete("#{_begin_index} + #{_buffer.length-1} chars" ,'insert')
1084
- _buffer = _buffer[0..-2]
1085
- Tk.update
1086
- _update_list.call(_buffer)
1087
- Tk.callback_break
1088
- end
1089
- when 'Next', 'Prior'
1041
+ when 'F1'
1042
+ _key = @raised_listbox.selected_line.split('-')[0].strip
1043
+ _x, _y = xy_insert
1044
+ Arcadia.process_event(DocCodeEvent.new(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y))
1045
+ #EditorContract.instance.doc_code(self, 'doc_entry'=>_docs_entries[_key], 'xdoc'=>_x, 'ydoc'=>_y)
1046
+ when 'a'..'z','less','space'
1047
+ if e.keysym == 'less'
1048
+ ch = '<'
1049
+ elsif e.keysym == 'space'
1050
+ ch = ''
1090
1051
  else
1052
+ ch = e.keysym
1053
+ end
1054
+ @text.insert('insert',ch)
1055
+ _buffer = _buffer + ch
1056
+ _update_list.call(_buffer)
1057
+ Tk.callback_break
1058
+ when 'BackSpace'
1059
+ if _buffer.length > _buffer_ini_length
1060
+ @text.delete("#{_begin_index} + #{_buffer.length-1} chars" ,'insert')
1061
+ _buffer = _buffer[0..-2]
1062
+ Tk.update
1063
+ _update_list.call(_buffer)
1091
1064
  Tk.callback_break
1092
- end
1093
- }
1094
- @raised_listbox.bind_append('KeyRelease'){|e|
1095
- case e.keysym
1096
- when 'Return'
1097
- _insert_selected_value.call
1098
- end
1099
- }
1100
- elsif _candidates.length == 1 && _candidates[0].length>0
1101
- @text.delete(_begin_index,'insert');
1102
- @text.insert('insert',_candidates[0].split[0])
1103
- complete_code_end
1104
- end
1105
- end
1065
+ end
1066
+ when 'Next', 'Prior'
1067
+ else
1068
+ Tk.callback_break
1069
+ end
1070
+ }
1071
+ @raised_listbox.bind_append('KeyRelease'){|e|
1072
+ case e.keysym
1073
+ when 'Return'
1074
+ _insert_selected_value.call
1075
+ end
1076
+ }
1077
+ elsif _candidates.length == 1 && _candidates[0].length>0
1078
+ @text.delete(_begin_index,'insert');
1079
+ @text.insert('insert',_candidates[0].split[0])
1080
+ complete_code_end
1081
+ end
1082
+ end
1106
1083
  end
1107
1084
 
1108
1085
 
@@ -1120,7 +1097,14 @@ class AgEditor
1120
1097
  }
1121
1098
 
1122
1099
  @text.bind_append("KeyPress"){|e|
1123
- @do_complete = false
1100
+ if e.keysym == "Escape"
1101
+ if @n_complete_task == 0
1102
+ @do_complete = true
1103
+ complete_code
1104
+ end
1105
+ else
1106
+ @do_complete = false
1107
+ end
1124
1108
  }
1125
1109
 
1126
1110
  @text.bind_append("KeyRelease"){|e|
@@ -1158,6 +1142,14 @@ class AgEditor
1158
1142
  end
1159
1143
  end
1160
1144
  break
1145
+ when 'o'
1146
+ if @file
1147
+ _dir = File.dirname(@file)
1148
+ else
1149
+ _dir = Dir.pwd
1150
+ end
1151
+ Arcadia.process_event(OpenBufferEvent.new(self,'file'=>Tk.getOpenFile('initialdir'=>_dir)))
1152
+ break
1161
1153
  when 'c'
1162
1154
  @text.text_copy
1163
1155
  break
@@ -1769,7 +1761,7 @@ class AgEditor
1769
1761
 
1770
1762
  @pop_up.insert('end',
1771
1763
  :command,
1772
- :label=>'Data image',
1764
+ :label=>'Data image from file',
1773
1765
  :hidemargin => false,
1774
1766
  :command=> proc{
1775
1767
  file = Tk.getOpenFile
@@ -1795,7 +1787,6 @@ class AgEditor
1795
1787
  if _r.length>0
1796
1788
  _data=@text.get(_r[0][0],_r[0][1])
1797
1789
  if _data.length > 0
1798
-
1799
1790
  _b = TkButton.new(@text,
1800
1791
  'command'=>proc{_b.destroy},
1801
1792
  'image'=> TkPhotoImage.new('data' => _data),
@@ -1806,6 +1797,33 @@ class AgEditor
1806
1797
  }
1807
1798
  )
1808
1799
 
1800
+ @pop_up.insert('end',
1801
+ :command,
1802
+ :label=>'Data image to file',
1803
+ :hidemargin => false,
1804
+ :command=> proc{
1805
+ _r = @text.tag_ranges('sel')
1806
+ if _r.length>0
1807
+ _data=@text.get(_r[0][0],_r[0][1])
1808
+ if _data.length > 0
1809
+ file = Tk.getSaveFile("filetypes"=>[["Image", [".gif"]],["All Files", [".*"]]])
1810
+ if file
1811
+ require 'base64'
1812
+ decoded = Base64.decode64(_data)
1813
+ f = File.new(file, "w")
1814
+ begin
1815
+ if f
1816
+ f.syswrite(decoded)
1817
+ end
1818
+ ensure
1819
+ f.close unless f.nil?
1820
+ end
1821
+ end
1822
+ end
1823
+ end
1824
+ }
1825
+ )
1826
+
1809
1827
  @pop_up.insert('end', :separator)
1810
1828
 
1811
1829
  #---- debug menu
@@ -1860,6 +1878,40 @@ class AgEditor
1860
1878
  :command=> proc{@text.configure('wrap'=>'none');@text.show_h_scroll}
1861
1879
  )
1862
1880
 
1881
+ _sub_code.insert('end',
1882
+ :command,
1883
+ :label=>'Selection to uppercase',
1884
+ :hidemargin => false,
1885
+ :command=> proc{
1886
+ _r = @text.tag_ranges('sel')
1887
+ if _r.length>0
1888
+ _text=@text.get(_r[0][0],_r[0][1])
1889
+ if _text.length > 0
1890
+ @text.delete(_r[0][0],_r[0][1])
1891
+ @text.insert(_r[0][0],_text.upcase)
1892
+ end
1893
+ end
1894
+ }
1895
+ )
1896
+
1897
+ _sub_code.insert('end',
1898
+ :command,
1899
+ :label=>'Selection to downcase',
1900
+ :hidemargin => false,
1901
+ :command=> proc{
1902
+ _r = @text.tag_ranges('sel')
1903
+ if _r.length>0
1904
+ _text=@text.get(_r[0][0],_r[0][1])
1905
+ if _text.length > 0
1906
+ @text.delete(_r[0][0],_r[0][1])
1907
+ @text.insert(_r[0][0],_text.downcase)
1908
+ end
1909
+ end
1910
+ }
1911
+ )
1912
+
1913
+
1914
+
1863
1915
  _sub_code.insert('end',
1864
1916
  :command,
1865
1917
  :label=>'Show tabs',
@@ -2294,6 +2346,7 @@ class AgEditor
2294
2346
  def set_modify
2295
2347
  if !@set_mod
2296
2348
  @set_mod = true
2349
+ @modified_from_opening = true
2297
2350
  @controller.change_tab_set_modify(@page_frame)
2298
2351
  end
2299
2352
  end
@@ -2617,6 +2670,7 @@ class AgEditor
2617
2670
  end
2618
2671
 
2619
2672
  def check_modify
2673
+ return if @loading
2620
2674
  if modified?
2621
2675
  set_modify if !@set_mod
2622
2676
  else
@@ -2634,7 +2688,7 @@ class AgEditor
2634
2688
  'title' => '(Arcadia) Libs', 'parent' => @text,
2635
2689
  'message' => msg) == 'yes'
2636
2690
  @text.delete('1.0','end')
2637
- reset_highlight
2691
+ reset_highlight if @highlighting
2638
2692
  load_file(@file)
2639
2693
  else
2640
2694
  @file_last_access_time = ftime
@@ -2846,7 +2900,7 @@ class AgMultiEditor < ArcadiaExt
2846
2900
  :command=> proc{
2847
2901
  if @selected_tab_name_from_popup != nil
2848
2902
  _e = @tabs_editor[@selected_tab_name_from_popup]
2849
- self.close_editor(_e)
2903
+ self.close_editor(_e) if _e
2850
2904
  end
2851
2905
  }
2852
2906
  )
@@ -2981,6 +3035,19 @@ class AgMultiEditor < ArcadiaExt
2981
3035
  if _event.row
2982
3036
  _index = _event.row.to_s+'.0'
2983
3037
  end
3038
+ if _event.kind_of?(OpenBufferTransientEvent) && conf('close-last-if-not-modified')=="yes"
3039
+ if defined?(@last_transient_file) && !@last_transient_file.nil? && @last_transient_file != _event.file
3040
+ _e = @tabs_editor[tab_name(@last_transient_file)]
3041
+ if _e && !_e.modified_from_opening?
3042
+ close_editor(_e)
3043
+ end
3044
+ end
3045
+ if !editor_exist?(_event.file)
3046
+ @last_transient_file = _event.file
3047
+ else
3048
+ @last_transient_file = nil
3049
+ end
3050
+ end
2984
3051
  self.open_file(_event.file, _index)
2985
3052
  elsif _event.text
2986
3053
  if _event.title
@@ -3022,6 +3089,11 @@ class AgMultiEditor < ArcadiaExt
3022
3089
  if _event.line == nil
3023
3090
  @find.show_go_to_line_dialog
3024
3091
  end
3092
+ when MoveBufferEvent
3093
+ if _event.old_file && _event.new_file && editor_exist?(_event.old_file)
3094
+ #close_file(_event.old_file)
3095
+ change_file(_event.old_file, _event.new_file)
3096
+ end
3025
3097
  end
3026
3098
  end
3027
3099
 
@@ -3049,6 +3121,7 @@ class AgMultiEditor < ArcadiaExt
3049
3121
  _files=_files+'|' if _files.strip.length > 0
3050
3122
  _files=_files + editor.file
3051
3123
  end
3124
+ #p editor.text.dump_tag('0.1',editor.text.index('end'))
3052
3125
  close_editor(editor)
3053
3126
  }
3054
3127
  Arcadia.persistent('editor.files.open', _files)
@@ -3069,7 +3142,8 @@ class AgMultiEditor < ArcadiaExt
3069
3142
  end
3070
3143
 
3071
3144
  def close_raised
3072
- close_editor(@tabs_editor[@main_frame.enb.raise])
3145
+ _e = @tabs_editor[@main_frame.enb.raise]
3146
+ close_editor(_e) if _e
3073
3147
 
3074
3148
  #_page = @main_frame.enb.raise
3075
3149
  #_editor = @tabs_editor[_page]
@@ -3230,6 +3304,14 @@ class AgMultiEditor < ArcadiaExt
3230
3304
  @main_frame.enb.itemconfigure(page_name(_tab), 'text'=> _new_text)
3231
3305
  end
3232
3306
 
3307
+ def change_file(_old_file, _new_file)
3308
+ _tab_name=tab_file_name(_old_file)
3309
+ _tab = @main_frame.enb.get_frame(_tab_name)
3310
+ e = @tabs_editor[_tab_name]
3311
+ e.file =_new_file if e
3312
+ change_file_name(_tab, _new_file)
3313
+ end
3314
+
3233
3315
  def change_file_name(_tab, _new_file)
3234
3316
  _new_label = File.basename(_new_file)
3235
3317
  change_tab_title(_tab, _new_label)
@@ -3392,6 +3474,7 @@ class AgMultiEditor < ArcadiaExt
3392
3474
  ext = _e.file_extension(_title)
3393
3475
  ext='rb' if ext.nil?
3394
3476
  _e.init_editing(ext, w1)
3477
+ _e.text.set_focus
3395
3478
  #@tabs_file[_buffer_name]= nil
3396
3479
  @tabs_editor[_buffer_name]=_e
3397
3480
  end
@@ -3447,7 +3530,8 @@ class AgMultiEditor < ArcadiaExt
3447
3530
  end
3448
3531
 
3449
3532
  def close_file(_filename)
3450
- close_editor(@tabs_editor[tab_name(_filename)])
3533
+ _e = @tabs_editor[tab_name(_filename)]
3534
+ close_editor(_e) if _e
3451
3535
  end
3452
3536
 
3453
3537
  def save_file(_filename)