Class: FilesHistrory

Inherits:
ArcadiaExt show all
Defined in:
ext/ae-file-history/ae-file-history.rb

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#add_to_conf_property, #array_conf, #conf, #conf_array, #conf_default, #del_from_conf_property, #destroy_frame, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_title, #frame_visible?, #hide_frame, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Attribute Details

#htreeObject (readonly)

Returns the value of attribute htree.



77
78
79
# File 'ext/ae-file-history/ae-file-history.rb', line 77

def htree
  @htree
end

Instance Method Details

#add2history(_filename, _text_index = '1.0') ⇒ Object



782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
# File 'ext/ae-file-history/ae-file-history.rb', line 782

def add2history(_filename, _text_index='1.0')
  #return if !@h_stack[_filename].nil?
  if _filename && File.exist?(_filename)
    _filename = _filename.sub(Dir::pwd+'/',"")
    _filename = File.expand_path(_filename)
    _filename_index = _filename+";"+_text_index
    if File.exist?(history_file)
      f = File.new(history_file, "w")
      begin
        if f
          max= conf('length').to_i
          i = 1
          f.syswrite(_filename_index+"\n")
          @history_lines.each{|_line|
            _lfile = _line.split(';')
            if _lfile
              if (_lfile[0] != _filename) && (_line.length > 0) 
                f.syswrite(_line+"\n")
                i+=1 
              end
            end
            break if i >= max
          }
        end
      ensure
        f.close unless f.nil?
      end
    else
      create_history_file(_filename+"\n")
    end
    refresh_history_lines
  end
end

#add_to_list(_file) ⇒ Object



486
487
488
489
490
# File 'ext/ae-file-history/ae-file-history.rb', line 486

def add_to_list(_file)
  if !@last_list_lines.include?(_file)
    build_list
  end
end

#add_to_tree(_file) ⇒ Object



621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
# File 'ext/ae-file-history/ae-file-history.rb', line 621

def add_to_tree(_file)
_d, _f = File.split(File.expand_path(_file))
return if _f.nil?
#Arcadia.new_error_msg(self, "add_to_tree _file=#{_file}")
#Arcadia.new_error_msg(self, "add_to_tree _d=#{_d}")
#Arcadia.new_error_msg(self, "add_to_tree _f=#{_f}")
_d = _d.downcase if Arcadia.is_windows?
_f = _f.downcase if Arcadia.is_windows?
  #_foreground = conf('color.foreground')
node = root.dir(_d)

node_stack = Array.new
node_stack << node
_parent = node.parent
while _parent.rif != 'root'
  node_stack << _parent
  _parent = _parent.parent
end
node_stack.reverse!

node_stack.each{|_node|
    if !@htree.exist?(_node.rif)
      @htree.insert('end', _node.parent.rif ,_node.rif, {
          'text' =>  _node.label,
          'helptext' => _node.rif,
          'deltax'=>-1,
          'image'=> image('KDir')
        }.update(Arcadia.style('treeitem'))
      )
    end
}
#    if [email protected]?(node.rif)
#      @htree.insert('end', node.parent.rif ,node.rif, {
#          'text' =>  node.label,
#          'helptext' => node.rif,
#          'deltax'=>-1,
#          'image'=> image('KDir')
#        }.update(Arcadia.style('treeitem'))
#      )
#    end


  _file_node_rif = _d+'@@@'+_f
  if !@htree.exist?(_file_node_rif)
    @htree.insert('end', node.rif ,_file_node_rif, {
        'text' =>  _f ,
        'helptext' => _f,
        'deltax'=>-1,
        #'fill' => _foreground,
        #'font'=>@font_b,
        'image'=> image('KFile',_f)
      }.update(Arcadia.style('treeitem'))
    )
  end
  
end

#append_to_list(_file, _i = 0) ⇒ Object



504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
# File 'ext/ae-file-history/ae-file-history.rb', line 504

def append_to_list(_file, _i=0)
  dir,fil =File.split(File.expand_path(_file))
  dir = dir.downcase if Arcadia.is_windows?
  fil = fil.downcase if Arcadia.is_windows?
  tag_name = "tag_#{_i}"
  @hlist.tag_remove(tag_name,'1.0', 'end')
  @hlist.tag_delete(tag_name)

  @hlist.tag_bind(tag_name,"Enter",  
    proc{
      Tk::BWidget::DynamicHelp::add(@hlist, 'text'=>_file)
      @hlist.configure('cursor'=> 'hand2')
      @hlist.tag_configure(tag_name, 'underline'=>true)
    }  
  )
  @hlist.tag_bind(tag_name,"Leave",
    proc{
      Tk::BWidget::DynamicHelp::delete(@hlist)
      @hlist.configure('cursor'=> nil)
      @hlist.tag_configure(tag_name, 'underline'=>false) 
    }
  )
  TkTextImage.new(@hlist, 'end', 'image'=> Arcadia.file_icon(_file))
  @hlist.insert("end", " ")
  @hlist.insert("end", "#{File.basename(_file)}\n", tag_name)
  @hlist.tag_bind(tag_name,"ButtonPress-1", proc{OpenBufferTransientEvent.new(self,'file'=>_file).go!})
end

#build_listObject



492
493
494
495
496
497
498
499
500
501
502
# File 'ext/ae-file-history/ae-file-history.rb', line 492

def build_list
  @hlist.delete('1.0','end')
  @last_list_lines.clear
  @history_lines.each_with_index{|line,i|
    file, index = line.split(';')
    if file && FileTest::exist?(file)
      append_to_list(file, i)
      @last_list_lines << file
    end
  }
end

#build_treeObject



532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
# File 'ext/ae-file-history/ae-file-history.rb', line 532

def build_tree
  file_dir = Hash.new
  nodes = Array.new
  _lines = @history_lines
  _lines.sort.each{|_line|
    _file, _index = _line.split(';')
    if _file && FileTest::exist?(_file)
      @h_stack[File.expand_path(_file)]=_index
      dir,fil =File.split(File.expand_path(_file))
      dir = dir.downcase if Arcadia.is_windows?
      fil = fil.downcase if Arcadia.is_windows?
      file_dir[dir] = Array.new if file_dir[dir] == nil
      file_dir[dir] << fil if !file_dir[dir].include?(fil)
    end
  }

  file_dir.keys.sort.each{|_dir|
  				node = root.dir(_dir)
		file_dir[_dir].each{|file|
		  TreeNode.new(node, 'KFile'){|_node|
            _node.rif= _dir+'@@@'+file
            _node.label=file
		  }
		}
  }

  @image_kdir = Arcadia.image_res(ICON_FOLDER_OPEN_GIF)
  build_tree_from_node(root)
end

#build_tree_from_node(_node) ⇒ Object



690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
# File 'ext/ae-file-history/ae-file-history.rb', line 690

def build_tree_from_node(_node)
  #_foreground = conf('color.foreground')
  _sorted_sons = _node.sons.sort
  for inode in 0.._sorted_sons.length - 1
    _son = _sorted_sons[inode]
    @htree.insert('end', _son.parent.rif ,_son.rif, {
      'text' =>  _son.label ,
   #   'fill' => _foreground,
      'helptext' => _son.helptext,
      'deltax'=>-1,
    #  'font'=>@font,
      'image'=> image(_son.kind, _son.label)
    }.update(Arcadia.style('treeitem'))
    )
    build_tree_from_node(_son)
  end
end

#create_history_file(_content = nil) ⇒ Object



769
770
771
772
773
774
775
776
777
778
779
780
# File 'ext/ae-file-history/ae-file-history.rb', line 769

def create_history_file(_content=nil)
  dir,fil =File.split(File.expand_path(history_file))
  if !File.exist?(dir)
    Dir.mkdir(dir)
  end
  f = File.new(history_file, "w+")
  begin
    f.syswrite(_content) if f && _content
  ensure
    f.close unless f.nil?
  end
end

#file2node(_file) ⇒ Object



370
371
372
373
374
375
376
# File 'ext/ae-file-history/ae-file-history.rb', line 370

def file2node(_file)
  if _file.include?("\s") && _file[0..0]!='{'
    return "{#{_file}}"
  else
    return _file
  end
end

#history_fileObject



325
326
327
328
329
330
# File 'ext/ae-file-history/ae-file-history.rb', line 325

def history_file
   if !defined?(@arcadia_history_file)
   		@arcadia_history_file = @arcadia.local_dir+'/'+conf('file.name')
   end
   return @arcadia_history_file
end

#image(_kind, _label = '.rb') ⇒ Object



678
679
680
681
682
683
684
685
686
687
688
# File 'ext/ae-file-history/ae-file-history.rb', line 678

def image(_kind, _label='.rb')
    if _kind == 'KDir'
      return @image_kdir
    elsif _kind == 'KFile'
      return Arcadia.file_icon(_label)
#      elsif _kind == 'KFile' && _label.include?('.rb')
#        return @image_kfile_rb
#      else
#        return @image_kfile
    end
end

#load_persistent_bookmarksObject



751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
# File 'ext/ae-file-history/ae-file-history.rb', line 751

def load_persistent_bookmarks
  b = Arcadia.persistent('bookmarks')
  if b
    bm_list =b.split("|")
    bm_list.each do |bm| 
      file,from_line,to_line = bm.split('@@@')
      if file && from_line && to_line
        SetBookmarkEvent.new(self, 
          'file'=>file, 
          'from_row'=>from_line.to_i, 
          'to_row'=>to_line.to_i,
          'persistent'=>true).go!
      end
    end
  end
end

#node2file(_node) ⇒ Object



362
363
364
365
366
367
368
# File 'ext/ae-file-history/ae-file-history.rb', line 362

def node2file(_node)
  if _node[0..0]=='{' && _node[-1..-1]=='}'
    return _node[1..-2]
  else
    return _node
  end
end

#on_after_build(_event) ⇒ Object



318
319
320
321
322
323
# File 'ext/ae-file-history/ae-file-history.rb', line 318

def on_after_build(_event)
   Arcadia.attach_listener(self, OpenBufferEvent)
   #Arcadia.attach_listener(self, BufferRaisedEvent)
   self.frame.show
   Arcadia.attach_listener(self, BufferClosedEvent)
end

#on_after_open_buffer(_event) ⇒ Object



346
347
348
349
350
351
352
353
# File 'ext/ae-file-history/ae-file-history.rb', line 346

def on_after_open_buffer(_event)
  if _event.file && File.exist?(_event.file)
    add2history(_event.file)
    add_to_tree(_event.file)
    add_to_list(_event.file)
    #build_list
  end
end

#on_before_build(_event) ⇒ Object



88
89
90
91
92
# File 'ext/ae-file-history/ae-file-history.rb', line 88

def on_before_build(_event)
  @bookmarks =Array.new
  Arcadia.attach_listener(self, BufferRaisedEvent)
  Arcadia.attach_listener(self, BookmarkEvent)
end

#on_before_open_buffer(_event) ⇒ Object



332
333
334
335
336
337
338
339
340
341
342
343
# File 'ext/ae-file-history/ae-file-history.rb', line 332

def on_before_open_buffer(_event)
  if _event.file && _event.row.nil? && File.exist?(_event.file)  
    if @h_stack[_event.file]
      r,c = @h_stack[_event.file].split('.')
      _event.last_row=r.to_i
      _event.last_col=c.to_i
      if _event.select_index.nil?
        _event.select_index=false
      end
    end
  end
end

#on_bookmark(_event) ⇒ Object



219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
# File 'ext/ae-file-history/ae-file-history.rb', line 219

def on_bookmark(_event)
   return if _event.file.nil?
   case _event
     when ToggleBookmarkEvent
       self.frame.show_anyway
       # set or unset ?
       to_set = true
       to_del_detail = nil
       @bookmarks.each{|detail|
         if detail[:file] == _event.file && (_event.from_row.to_i >= detail[:from_line].to_i - _event.range) && (_event.to_row.to_i <= detail[:to_line].to_i + _event.range)  
           to_set = false
           to_del_detail = detail
         end
         break if !to_set 
       }
       if to_set
         SetBookmarkEvent.new(self,
           'file'=>_event.file, 
           'from_row'=>_event.from_row, 
           'to_row'=>_event.to_row,
           'range'=>_event.range,
           'persistent'=>_event.persistent,
           'id'=>_event.id).go!
       else
         UnsetBookmarkEvent.new(self,
           'file'=>_event.file, 
           'from_row'=>to_del_detail[:from_line], 
           'to_row'=>to_del_detail[:to_line],
           'range'=>_event.range,
           'persistent'=>_event.persistent,
           'id'=>_event.id).go!
       end    
     when SetBookmarkEvent
       @bookmarks_frame.pack('before'=>@history_frame,'side' =>'top','anchor'=>'nw', 'fill'=>'x', :padx=>0, :pady=>0)     if @bookmarks.empty? 
       if _event.persistent
         bookmark = {:file=>_event.file}
         caption = File.basename(_event.file)
       else
         bookmark = {:file=>"__TMP__#{_event.id}"}
         caption = _event.id
       end
       caption = "#{caption} [#{_event.from_row}, #{_event.to_row}]"
       bookmark[:from_line] = _event.from_row
       bookmark[:to_line] = _event.to_row
       bookmark[:persistent] = _event.persistent
       bookmark[:widget] = Tk::BWidget::Button.new(@bookmarks_frame, Arcadia.style('toolbarbutton')){
         image Arcadia.image_res(BOOKMARK_GIF)
         compound 'left'
         anchor "w"
         command proc{OpenBufferTransientEvent.new(self,'file'=>_event.file, 'row'=> _event.from_row).go!}
         #width 20
         #height 20
         helptext  _event.content
         text caption
       }.pack('side' =>'top','anchor'=>'nw', 'fill'=>'x', :padx=>0, :pady=>0)    

       Tk::BWidget::Button.new(bookmark[:widget], Arcadia.style('toolbarbutton')){
         image  TkPhotoImage.new('dat' => CLOSE_GIF)
         command proc{UnsetBookmarkEvent.new(self,
           'file'=>_event.file, 
           'from_row'=>_event.from_row,
           'to_row'=>_event.to_row).go!}
         #width 20
         height 16
       }.pack('side' =>'right','anchor'=>'e', 'fill'=>'y', :padx=>0, :pady=>0)    
       
       @bookmarks << bookmark
     when UnsetBookmarkEvent
       @bookmarks.delete_if{|b| 
         if (b[:file]==_event.file && b[:from_line]==_event.from_row)
           b[:widget].destroy
           true
         else
           false
         end
       }
       @bookmarks_frame.unpack if @bookmarks.empty? 
 end

end

#on_buffer_closed(_event) ⇒ Object



355
356
357
358
359
360
# File 'ext/ae-file-history/ae-file-history.rb', line 355

def on_buffer_closed(_event)
  if _event.file && File.exist?(_event.file)
    @h_stack_changed = @h_stack_changed || @h_stack[_event.file] != "#{_event.row}.0"
    @h_stack[_event.file]="#{_event.row}.0"
  end
end

#on_buffer_raised(_event) ⇒ Object



436
437
438
439
440
441
442
# File 'ext/ae-file-history/ae-file-history.rb', line 436

def on_buffer_raised(_event)
  return if _event.file.nil?
  @last_file = _event.file
  if @sync
    select_file_without_event(_event.file)
  end
end

#on_build(_event) ⇒ Object



94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
# File 'ext/ae-file-history/ae-file-history.rb', line 94

def on_build(_event)
   @h_stack = Hash.new
   @h_stack_changed = false
   @bookmarks_frame = TkFrame.new(self.frame.hinner_frame)    
   @history_frame = TkFrame.new(self.frame.hinner_frame).pack('fill'=>'both', :padx=>0, :pady=>0, :expand => 'yes')    
   @panel = self.frame.root.add_panel(self.frame.name, "sync");
   @cb_sync = TkCheckButton.new(@panel, Arcadia.style('checkbox').update('background'=>@panel.background)){
     text  'Sync'
     justify  'left'
     indicatoron 0
     offrelief 'flat'
     image Arcadia.image_res(SYNC_GIF)
     pack
   }

   Tk::BWidget::DynamicHelp::add(@cb_sync, 
     'text'=>Arcadia.text('ext.file_history.button.link.hint'))

   do_check = proc {
     if @cb_sync.cget('onvalue')==@cb_sync.cget('variable').value.to_i
       sync_on
     else
       sync_off
     end
   }
   @sync = false
   @cb_sync.command(do_check)
   
   @list_label=Arcadia.text("ext.file_history.button.show_as_list.hint")
   @tree_label=Arcadia.text("ext.file_history.button.show_as_tree.hint")
   @is_tree = conf("view") == "tree"
   if @is_tree 
     image = LIST_VIEW_GIF
     label = @list_label
   else
     image = TREE_VIEW_GIF
     label = @tree_label
   end
   
   @btoggle_list_tree = frame.root.add_button(self.name, label, proc{toggle_list_tree}, image)
   
   do_select_item = proc{|_self|
     _selected = @htree.selected
     _dir, _file = _selected.sub("%%%",":").split('@@@')
     if _file
       _file = File.expand_path( _file  , _dir ) 
#	    else
#	      _file = Tk.getOpenFile('initialdir'=>_dir)
    end
    if _file && _file.strip.length > 0 
      Arcadia.process_event(OpenBufferTransientEvent.new(self,'file'=>_file))
     end
   }
   
   do_open_folder = proc{|_node|
     children = @htree.nodes(_node)
     if children.length == 1 
       @htree.open_tree(children[0],false)
     end
   }    

   @font =  Arcadia.conf('treeitem.font')
   @font_b = "#{Arcadia.conf('treeitem.font')} bold"
   @font_italic = "#{Arcadia.conf('treeitem.font')} italic"
   
  @htree = BWidgetTreePatched.new(@history_frame, Arcadia.style('treepanel')){
     showlines false
     deltay 18
     crosscloseimage  Arcadia.image_res(PLUS_GIF)
     crossopenimage  Arcadia.image_res(MINUS_GIF)
     opencmd proc{|node| do_open_folder.call(node)} 
     selectcommand proc{ do_select_item.call(self) } 
#      place('relwidth' => 1,'relheight' => '1', 'x' => '0','y' => '22', 'height' => -22)
   }
   @htree.extend(TkScrollableWidget)

   do_double_click = proc{
       #_selected = @htree.selection_get[0]
       _selected = @htree.selected
       _dir, _file = _selected.sub("%%%",":").split('@@@')
       if _dir && _file.nil? && File.ftype(node2file(_dir)) == 'directory'
        _file = Tk.getOpenFile('initialdir'=>node2file(_dir))
     	    if _file && _file.strip.length > 0 
     	       Arcadia.process_event(OpenBufferTransientEvent.new(self,'file'=>_file))
          end
#          if !_selected.nil? && @htree.open?(node2file(_selected))
#            @htree.close_tree(node2file(_selected))
#          elsif !_selected.nil?
#            @htree.open_tree(node2file(_selected),false) 
#            do_open_folder.call(_selected)
#          end
       end
   }
   
   @htree.textbind_append('Double-1',do_double_click)
    
   @history_lines = []
   @last_list_lines = []
   refresh_history_lines
  
   build_tree
   pop_up_menu_tree
   
   @hlist = TkText.new(@history_frame, Arcadia.style('text')){|j|
     wrap 'none'
     font @font_italic
     cursor nil
   }
   @hlist.bind_append('KeyPress'){|e| Tk.callback_break }
   @hlist.bind_append('KeyRelease'){|e| Tk.callback_break }
   @hlist.extend(TkScrollableWidget)
   @hlist.tag_configure("file_selected", 'foreground' => Arcadia.conf('hightlight.link.foreground'))
  build_list
  if @is_tree 
    @htree.show
  else
    @hlist.show
  end
end

#on_finalize(_event) ⇒ Object



708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
# File 'ext/ae-file-history/ae-file-history.rb', line 708

def on_finalize(_event)
  bookmarks = '';
  @bookmarks.each{|bm|
    if bm[:file] != nil && bm[:persistent]
      bookmarks="#{bookmarks}|" if bookmarks.strip.length > 0
      bookmarks="#{bookmarks}#{bm[:file]}@@@#{bm[:from_line]}@@@#{bm[:to_line]}"
    end
  }
  Arcadia.persistent('bookmarks', bookmarks)
  if @is_tree
    conf('view','tree') 
  else
    conf('view','list') 
  end
  return if !@h_stack_changed 
  if File.exist?(history_file)
    f = File::open(history_file,'r')
    begin
      _lines = f.readlines.collect!{| line | line.chomp}
    ensure
      f.close unless f.nil?
    end
    f = File.new(history_file, "w")
    begin
      if f
        _lines[0..-1].each{|_line|
          _lfile = _line.split(';')
          if _lfile
            if @h_stack[_lfile[0]]
              rif = "#{_lfile[0]};#{@h_stack[_lfile[0]]}"
            else
              rif = _line
            end
            f.syswrite(rif+"\n")
          end
        }
      end
    ensure
      f.close unless f.nil?
    end
  end
end

#on_initialize(_event) ⇒ Object



214
215
216
# File 'ext/ae-file-history/ae-file-history.rb', line 214

def on_initialize(_event)
  load_persistent_bookmarks
end

#pop_up_menu_treeObject



562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
# File 'ext/ae-file-history/ae-file-history.rb', line 562

def pop_up_menu_tree
  @pop_up_tree = TkMenu.new(
    :parent=>@htree,
    :tearoff=>0,
    :title => 'Menu tree'
  )
  @pop_up_tree.extend(TkAutoPostMenu)
  @pop_up_tree.configure(Arcadia.style('menu'))
  #----- search submenu
  sub_ref_search = TkMenu.new(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => 'Ref'
  )
  sub_ref_search.extend(TkAutoPostMenu)
  sub_ref_search.configure(Arcadia.style('menu'))
  sub_ref_search.insert('end',
    :command,
    :label=>Arcadia.text('ext.file_history.menu.find_in_files'),
    :hidemargin => false,
    :command=> proc{
      _target = @htree.selected
      _dir, _file = _target.sub("%%%",":").split('@@@')
      if _dir
        Arcadia.process_event(SearchInFilesEvent.new(self,'dir'=>_dir))
      end
    }
  )
  
  sub_ref_search.insert('end',
    :command,
    :label=>Arcadia.text('ext.file_history.menu.act_in_files'),
    :hidemargin => false,
    :command=> proc{
      _target = @htree.selected
      _dir, _file = _target.sub("%%%",":").split('@@@')
      if _dir
        Arcadia.process_event(AckInFilesEvent.new(self,'dir'=>_dir))
      end
    }
  )
  @pop_up_tree.insert('end',
    :cascade,
    :label=>Arcadia.text('ext.file_history.menu.search_from_here'),
    :menu=>sub_ref_search,
    :hidemargin => false
  )
  
  
  @htree.areabind_append("Button-3",
    proc{|x,y|
      _x = TkWinfo.pointerx(@htree)
      _y = TkWinfo.pointery(@htree)
      @pop_up_tree.popup(_x,_y)
    },
  "%x %y")
end

#read_historyObject



467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'ext/ae-file-history/ae-file-history.rb', line 467

def read_history
  to_ret = []
  if File.exist?(history_file)
    f = File::open(history_file,'r')
    begin 
      to_ret = f.readlines.collect!{| line | line.chomp }
    ensure
      f.close unless f.nil?
    end
  else
    create_history_file
  end
  to_ret
end

#refresh_history_linesObject



482
483
484
# File 'ext/ae-file-history/ae-file-history.rb', line 482

def refresh_history_lines
  @history_lines = read_history
end

#rootObject

def do_editor_event(_event)

 case _event.signature 
 		when EditorContract::FILE_AFTER_OPEN
 		  if _event.context.file
		      self.add2history(_event.context.file)
		      add_to_tree(_event.context.file)
 			  end
 		when EditorContract::FILE_AFTER_CLOSE
 		  if _event.context.file 
 		end
 end

end



457
458
459
460
461
462
463
464
465
# File 'ext/ae-file-history/ae-file-history.rb', line 457

def root
  if !defined?(@root)
    @root = TreeNode.new(nil, 'KRoot'){|_node|
      _node.rif= 'root'
      _node.label=''
    }
  end
  return @root
end

#select_file_without_event(_file) ⇒ Object

def selected

  if @htree.selection_get[0]
    if @htree.selection_get[0].length >0
     	_selected = ""
      if String.method_defined?(:lines)
    	   selection_lines = @htree.selection_get[0].lines
      else
    	   selection_lines = @htree.selection_get[0].split("\n")
      end
      selection_lines.each{|_block|
        _selected = _selected + _block.to_s + "\s" 
      }
      _selected = _selected.strip
    else
      _selected = @htree.selection_get[0]
    end
  end
  return _selected
end


399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
# File 'ext/ae-file-history/ae-file-history.rb', line 399

def select_file_without_event(_file)
  _d, _f = File.split(File.expand_path(_file))
  _d = _d.downcase if Arcadia.is_windows?
  _f = _f.downcase if Arcadia.is_windows?
  _file_node_rif = _d+'@@@'+_f
  if @htree.exist?(_file_node_rif)
    _proc = @htree.cget('selectcommand')
    @htree.configure('selectcommand'=>nil)
    #_proc = @htree.selectcommand
    #@htree.selectcommand(proc{nil})
    begin
      parent = root.dir(_d)
      @htree.selection_clear
      @htree.selection_add(_file_node_rif)
      #@htree.close_tree('root')
      while !parent.nil? && parent.rif != 'root'
        @htree.open_tree(parent.rif, false)
        parent = parent.parent
      end
      @htree.see(_file_node_rif)
    ensure
      #@htree.selectcommand(_proc)
      @htree.configure('selectcommand'=>_proc)
    end
    @htree.call_after_next_show_h_scroll(proc{Tk.update;@htree.see(_file_node_rif)})
  end

  @hlist.tag_remove("file_selected",'1.0', 'end')
  @history_lines.each_with_index{|line, i|
    if line.include?(File.expand_path(_file))
      index = "#{i+1}.0"
      @hlist.tag_add("file_selected",index, "#{index} lineend")
      @hlist.see(index)
    end
  }
end

#sync_offObject



84
85
86
# File 'ext/ae-file-history/ae-file-history.rb', line 84

def sync_off
  @sync = false
end

#sync_onObject



79
80
81
82
# File 'ext/ae-file-history/ae-file-history.rb', line 79

def sync_on
  @sync = true
  select_file_without_event(@last_file) if @last_file
end

#toggle_list_treeObject



300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
# File 'ext/ae-file-history/ae-file-history.rb', line 300

def toggle_list_tree
   Tk::BWidget::DynamicHelp::delete(@btoggle_list_tree)
  if @is_tree
    @htree.hide
    @hlist.show
    label = @tree_label
    image = Arcadia.image_res(TREE_VIEW_GIF)
  else
    @hlist.hide
    @htree.show
    label = @list_label
    image = Arcadia.image_res(LIST_VIEW_GIF)
  end
   @btoggle_list_tree.configure(:image=> image)
   Tk::BWidget::DynamicHelp::add(@btoggle_list_tree, 'text'=>label)
   @is_tree = !@is_tree
end