Class: DirProjects

Inherits:
ArcadiaExt show all
Defined in:
ext/ae-dir-projects/ae-dir-projects.rb

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#conf, #conf_array, #conf_default, #exec, #float_frame, #frame, #frame_def_visible?, #frame_domain, #frame_domain_default, #frame_visible?, #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.



25
26
27
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 25

def htree
  @htree
end

Instance Method Details

#add_node(_parent, _node, _kind) ⇒ Object



740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 740

def add_node(_parent, _node, _kind)
  return if @htree.exist?(_node)
  @node_parent[_node] = _parent
#    _name = _node.split(File::SEPARATOR)[-1]
  _name = File.basename(_node)
  _drawcross = 'auto'
  if _kind == "project" || _kind == "directory"
    num = Dir.entries(_node).length-2
    if num > 0
      _drawcross = 'always'
    end
  end
  @htree.insert('end', _parent ,_node, {
    'text' =>  _name ,
    'helptext' => _node,
    'drawcross'=>_drawcross,
    'deltax'=>-1,
    'image'=> image(_kind, _node)
  }.update(Arcadia.style('treeitem'))
  )
  if _kind == "project" || _kind == "directory"
    if @opened_folder.include?(_node)
      do_open_folder(_node, true)
    end
  end
end

#add_project(_dir) ⇒ Object



781
782
783
784
785
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 781

def add_project(_dir)
  @projects[_dir] = Project.new(_dir)
  add_node('root', _dir, "project")
  add_project_to_file(_dir) 
end

#add_project_to_file(_project) ⇒ Object



838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 838

def add_project_to_file(_project)
   f = File::open(projects_file,'r')
   begin
     _lines = f.readlines.collect!{| line | line.chomp}
   ensure
     f.close unless f.nil?
   end
   if !_lines.include?(_project)
     f = File.new(projects_file, "w")
     begin
       _lines.each{|_line|
         f.syswrite(_line+"\n")
       }
       f.syswrite(_project+"\n")
     ensure
       f.close unless f.nil?
     end
   end	
end

#add_temp_node(_parent, _node, _kind) ⇒ Object



767
768
769
770
771
772
773
774
775
776
777
778
779
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 767

def add_temp_node(_parent, _node, _kind)
  return if @htree.exist?(_node)
  _name = _node.split(File::SEPARATOR)[-1]
  _drawcross = 'auto'
  @htree.insert('end', _parent ,_node, {
    'text' =>  _name ,
    'helptext' => _node,
    'drawcross'=>_drawcross,
    'deltax'=>-1,
    'image'=> image(_kind, _node)
  }.update(Arcadia.style('treeitem'))
  )
end

#del_project(_dir) ⇒ Object



817
818
819
820
821
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 817

def del_project(_dir)
    shure_delete_node(file2node(_dir))
    @projects.delete(_dir)
    del_project_from_file(_dir) 
end

#del_project_from_file(_project) ⇒ Object



858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 858

def del_project_from_file(_project)
 # p "del_project_from_file =>#{_project}"
 # p projects_file
   f = File::open(projects_file,'r')
   begin
     _lines = f.readlines.collect!{| line | line.chomp}
   ensure
     f.close unless f.nil?
   end
   f = File.new(projects_file, "w")
   begin
     _lines.each{|_line|
       if _line != _project
       p _line
         f.syswrite(_line+"\n")
       end
     }
   ensure
     f.close unless f.nil?
   end
end

#do_close_folder(_node, _close = false) ⇒ Object



207
208
209
210
211
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 207

def do_close_folder(_node, _close=false)
  @opened_folder.delete(_node)
  @current_opened_folder = nil
  @htree.close_tree(_node) if _close
end

#do_close_project(_proj_name) ⇒ Object



534
535
536
537
538
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 534

def do_close_project(_proj_name)
  if _proj_name && is_project?(_proj_name)
    del_project(_proj_name)
  end
end

#do_delete(_node, _interactive = true) ⇒ Object



688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 688

def do_delete(_node, _interactive = true)
  if File.exists?(node2file(_node)) 
    type = File.ftype(node2file(_node))
    if type == 'directory'
      _msg = "Delete #{_node} directory ?"
    else
      _msg = "Delete #{_node} file ?"
    end
    if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => 'Confirm delete', 'msg'=>_msg)=='yes'
      delete_node = true
      if type == 'directory'
        entries = Dir.entries(node2file(_node))
        entries.delete('.')
        entries.delete('..')
        #is_project = @htree.exist?(_node) && @htree.parent(_node)=='root'
        if entries.length > 0
          _msg2 = "#{_node} isn't empty. Shure to delete all sub entries ?"
          entries.each{|en|
            _msg2 = "#{_msg2}\n#{en}"
          }
          if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => 'Confirm deletion', 'msg'=>_msg2)=='yes'
            entries.each{|en|
              do_delete(File.join(node2file(_node),en),false)
            }
            Dir.delete(node2file(_node))
          else
            delete_node = false
          end
        else
          Dir.delete(node2file(_node))
        end
        if  is_project?(_node) && delete_node
          delete_node = false
          del_project(_node)
        end
      else
        Arcadia.process_event(CloseBufferEvent.new(self,'file'=>node2file(_node)))
        File.delete(node2file(_node))
      end
      shure_delete_node(_node) if delete_node
    end
  end
end

#do_goto_parent_folderObject



459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 459

def do_goto_parent_folder
  if @current_opened_folder && @current_opened_folder != @last_current_opened_folder 
    shure_select_node(@current_opened_folder)
    @last_current_opened_folder = @current_opened_folder
  else
    _selected = @htree.selected
    if _selected && @htree.exist?(_selected)
      _parent = @htree.parent(_selected)
      if _parent && _parent != 'root'
        shure_select_node(_parent)
      else
        do_close_folder(_selected,true)  
      end
    end 
  end 
end

#do_move(_source, _destination, _interactive = true) ⇒ 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
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 621

def do_move(_source, _destination, _interactive = true)
  _msg = "Move #{_source} to #{_destination}?"
  if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => 'Confirm move', 'msg'=>_msg)=='yes'
    if File.exists?(_source) 
      type = File.ftype(node2file(_source))
      source_basename = _source.split(File::SEPARATOR)[-1]
      if type == 'directory'
        des_path = File.join(_destination,source_basename)
        if File.exists?(des_path)  || Dir.mkdir(des_path)
          entries = Dir.entries(_source)
          entries.delete('.')
          entries.delete('..')
          entries.each{|en|
            full_en = File.join(_source,en)
            do_move(full_en, des_path, false)
          }
          Dir.delete(_source)
          if @projects[_source]
            del_project(_source)
          end
        end
      else
        new_file = File.join(_destination,source_basename)
        if File.rename(_source, new_file)
          # evento
          Arcadia.process_event(MoveBufferEvent.new(self,'old_file'=>_source,'new_file'=>new_file))
        end
      end
      if _interactive
        do_refresh(File.split(_source)[0])
        do_refresh(_destination)
      end
    end
  end
end

#do_new_file(_parent_folder_node) ⇒ Object



564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 564

def do_new_file(_parent_folder_node)
  if File.exists?(node2file(_parent_folder_node)) && File.ftype(node2file(_parent_folder_node)) == 'directory'
    tmp_node_name = "#{node2file(_parent_folder_node)}#{File::SEPARATOR}_new_file_"
    add_temp_node(_parent_folder_node,tmp_node_name,"file")
    @htree.open_tree(_parent_folder_node,false)
    _verify_cmd = proc{|_text|
      _ret = 0
      begin
        new_file_name = "#{node2file(_parent_folder_node)}#{File::SEPARATOR}#{_text}"
        if !File.exists?(new_file_name)
          File.new(new_file_name, "w").close
          add_node(_parent_folder_node,new_file_name,"file")
          #Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_node))
        end
        _ret = 1
      ensure
        @htree.delete(file2node(tmp_node_name))
      end
      _ret
    }
    @htree.edit(tmp_node_name, tmp_node_name.split(File::SEPARATOR)[-1], _verify_cmd, 1)
  end
end

#do_new_folder(_parent_folder_node) ⇒ Object



540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 540

def do_new_folder(_parent_folder_node)
  if File.exists?(node2file(_parent_folder_node)) && File.ftype(node2file(_parent_folder_node)) == 'directory'
    tmp_node_name = "#{node2file(_parent_folder_node)}#{File::SEPARATOR}_new_folder_"
    add_temp_node(_parent_folder_node,tmp_node_name,'directory')
    @htree.open_tree(_parent_folder_node,false)
    _verify_cmd = proc{|_text|
      _ret = 0
      begin
        new_dir_name = "#{node2file(_parent_folder_node)}#{File::SEPARATOR}#{_text}"
        if !File.exists?(new_dir_name)
          Dir.mkdir(new_dir_name)
          add_node(_parent_folder_node,new_dir_name,'directory')
        end
        _ret = 1
      ensure
        @htree.delete(file2node(tmp_node_name))
        shure_select_node(new_dir_name)
      end
      _ret
    }
    @htree.edit(tmp_node_name, tmp_node_name.split(File::SEPARATOR)[-1], _verify_cmd, 1)
  end
end

#do_new_project(_parent_folder_node = nil) ⇒ Object

def selected

  if @htree.selection_get[0]
    if @htree.selection_get[0].length >0
     	_selected = ""
      if @htree.selection_get[0].instance_of?(Array)
        selection_lines = @htree.selection_get[0]
      else
        if String.method_defined?(:lines)
      	   selection_lines = @htree.selection_get[0].lines
        else
      	   selection_lines = @htree.selection_get[0].split("\n")
        end
      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


500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 500

def do_new_project(_parent_folder_node=nil)
  if _parent_folder_node.nil?
    _parent_folder_node=Tk.chooseDirectory 'initialdir' =>  MonitorLastUsedDir.get_last_dir
  end
  if _parent_folder_node && File.exists?(node2file(_parent_folder_node)) && File.ftype(node2file(_parent_folder_node)) == 'directory'
    tmp_node_name = "#{node2file(_parent_folder_node)}#{File::SEPARATOR}_new_project_"
    tree_parent = _parent_folder_node
    add_temp_node('root',tmp_node_name,'project')
    _verify_cmd = proc{|_text|
      _ret = 0
      begin
        new_dir_name = "#{_parent_folder_node}#{File::SEPARATOR}#{_text}"
        if !File.exists?(new_dir_name)
          Dir.mkdir(new_dir_name)
          add_project(new_dir_name)
        end
        _ret = 1
      ensure
        @htree.delete(file2node(tmp_node_name))
      end
      _ret
    }
    @htree.edit(tmp_node_name, tmp_node_name.split(File::SEPARATOR)[-1], _verify_cmd, 1)
  end

end

#do_open_folder(_node, _open = false) ⇒ Object



213
214
215
216
217
218
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
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 213

def do_open_folder(_node, _open=false)
  #shure_select_node(_node) if self.selected.nil?
  proj  = @projects[_node]
  if proj && !proj.loaded
    n = load_tree_from_dir(_node)
    proj.loaded = true
  else
    proj = project_of_node(_node)
    if !proj.cache_dirs.include?(_node)
      load_tree_from_dir(_node)
      proj.cache_dirs << _node
    end
    if @num_childrens_of[_node] == 1
      child = @htree.nodes(_node)[0]
      if File.ftype(node2file(child)) == 'directory'
        @htree.open_tree(child,false) 
        @opened_folder << child if !@opened_folder.include?(child)
      end
#      elsif @num_childrens_of[_node] > 1
#        @htree.nodes(_node).each{|child|
#          if @opened_folder.include?(child)
#            load_tree_from_dir(child)
#            do_open_folder(child, true)
#          end
#        }
    end
  end
  @opened_folder << _node if !@opened_folder.include?(_node)
  @current_opened_folder = _node
  @htree.open_tree(_node,false)  if _open
end

#do_open_project(_proj_name = nil) ⇒ Object



527
528
529
530
531
532
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 527

def do_open_project(_proj_name=nil)
  if _proj_name.nil?
    _proj_name=Tk.chooseDirectory 'initialdir' =>  MonitorLastUsedDir.get_last_dir
    add_project(_proj_name) if _proj_name && File.exists?(_proj_name)
  end
end

#do_refresh(_node) ⇒ Object



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
619
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 588

def do_refresh(_node)
  if _node.nil?
    @projects.keys.each{|proj|
      if !File.exists?(proj)
        del_project(proj)
      else
        do_refresh(proj)
      end
    }
  elsif @htree.exist?(_node)
    opened = @opened_folder.include?(_node)
    @htree.close_tree(_node)
    nodes = @htree.nodes(_node)
    shure_delete_node(nodes) if nodes
    proj  = @projects[_node]
    if proj && proj.loaded
      proj.loaded = false
      proj.cache_dirs.clear
    else
      proj = project_of_node(_node)
      if proj
        proj.cache_dirs.delete(_node)
      end
    end
    do_open_folder(_node, opened) if opened
    nodes.each{|n|
      if File.exists?(n) && File.ftype(node2file(n)) == 'directory'
        do_refresh(n)
      end
    }
  end
end

#do_rename(_source) ⇒ Object



657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 657

def do_rename(_source)
  old_file_name = node2file(_source)
  if File.exists?(old_file_name) 
    source_dir = File.split(old_file_name)[0]
    _verify_cmd = proc{|_text|
      _ret = 0
      begin
        new_file_name = "#{source_dir}#{File::SEPARATOR}#{_text}"
        #p "new_file_name=#{new_file_name}"
        #p "old_file_name=#{old_file_name}"
        if !File.exists?(new_file_name)
          if File.rename(old_file_name, new_file_name)
            # evento
            Arcadia.process_event(MoveBufferEvent.new(self,'old_file'=>old_file_name,'new_file'=>new_file_name))
          end
        end
        _ret = 1
      ensure
        shure_delete_node(_source)
        do_refresh(source_dir)
      end
      _ret
    }
    @htree.edit(_source, _source.split(File::SEPARATOR)[-1], _verify_cmd, 1)
  end
end

#do_select_item2Object



161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 161

def do_select_item2
  proc{|_tree, _selected|
    if File.exist?(node2file(_selected))
      if File.ftype(node2file(_selected)) == 'file'
        _sync_val = @sync
        @sync = false
        begin
  	         Arcadia.process_event(OpenBufferTransientEvent.new(self,'file'=>node2file(_selected)))
  	     ensure
          @sync = _sync_val
  	     end
      end
    else
      shure_delete_node(_selected)
    end
  }
end

#file2node(_file) ⇒ Object



199
200
201
202
203
204
205
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 199

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

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



946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 946

def image(_kind, _label='.rb')
    if _kind == 'directory'
      return @image_kdir
    elsif _kind == 'project'
      return @image_kdir_closed
    elsif _kind == 'file'
      return Arcadia.file_icon(_label)
    end

#      elsif _kind == 'file' && _label.include?('.rb')
#        return @image_kfile_rb
#      else
#        return @image_kfile
#      end
end

#is_project?(_node) ⇒ Boolean

Returns:

  • (Boolean)


684
685
686
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 684

def is_project?(_node)
  @htree.exist?(_node) && @htree.parent(_node)=='root'
end

#key_press(_keysym) ⇒ Object



179
180
181
182
183
184
185
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 179

def key_press(_keysym)
     case _keysym
       when 'F5'
       _selected = @htree.selected
       do_refresh(_selected)
     end
end

#load_projectsObject



824
825
826
827
828
829
830
831
832
833
834
835
836
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 824

def load_projects
  f = File::open(projects_file,'r')
  begin
    _lines = f.readlines.collect!{| line | line.chomp}
  ensure
    f.close unless f.nil?
  end
  _lines.each{|_line|
    if _line.length > 0 && _line[0] != '#' && FileTest.directory?(_line)
      add_project(_line)
    end
  }
end

#load_tree_from_dir(_node, _reset = false) ⇒ Object



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
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 245

def load_tree_from_dir(_node, _reset = false)
  @htree.delete(@htree.nodes(_node)) if _reset
  if @htree.exist?(_node)
    childrens = Dir.entries(node2file(_node))
    childrens_dir = Array.new
    childrens_file = Array.new
    @num_childrens_of[_node] = childrens.length-2
    childrens.sort.each{|c|
      if c != '.' && c != '..'
        child = File.join(node2file(_node),c)
        fty = File.ftype(node2file(child))
        if fty == "file"
          childrens_file << child
          #add_node(_node, child, fty)
        elsif fty == "directory"
          childrens_dir << child
          #add_node(_node, child, fty)
        end
      end
    }
    childrens_dir.each{|child|
      add_node(_node, child, "directory")
    }
    childrens_file.each{|child|
      add_node(_node, child, "file")
    }
  end
end

#node2file(_node) ⇒ Object



191
192
193
194
195
196
197
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 191

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

#on_after_build(_event) ⇒ Object



187
188
189
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 187

def on_after_build(_event)
   self.frame.show
end

#on_before_build(_event) ⇒ Object



36
37
38
39
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 36

def on_before_build(_event)
  Arcadia.attach_listener(self, BufferRaisedEvent)
  Arcadia.attach_listener(self, SaveAsBufferEvent)
end

#on_before_save_as_buffer(_event) ⇒ Object



934
935
936
937
938
939
940
941
942
943
944
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 934

def on_before_save_as_buffer(_event)
  _selected = @htree.selected
  if _selected
    tpy =  File.ftype(node2file(_selected))
    if tpy == 'directory'
      Dir.chdir(_selected)
    elsif tpy == 'file'
      Dir.chdir(File.dirname(_selected))
    end      
  end
end

#on_buffer_raised(_event) ⇒ Object



926
927
928
929
930
931
932
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 926

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



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
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
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 41

def on_build(_event)
  @projects = Hash.new
  @node_parent = Hash.new
  @num_childrens_of = Hash.new
  @h_stack = Array.new
  @opened_folder = Array.new
  #--- button_box 
  @button_box = Tk::BWidget::ButtonBox.new(self.frame.hinner_frame){
    homogeneous true
    spacing 0
    padx 0
    pady 0
    background Arcadia.conf('panel.background')
  }.place('x'=>32,'height'=> 28)

  @button_box.add(Arcadia.style('toolbarbutton').update({
    'name'=>'new_proj',
    'anchor' => 'nw',
    'command'=>proc{self.do_new_project},
    'helptext'=>'New dir Project',
    'image'=> TkPhotoImage.new('dat' => NEW_GIF)})
  )

  @button_box.add(Arcadia.style('toolbarbutton').update({
    'name'=>'open_proj',
    'anchor' => 'nw',
    'command'=>proc{self.do_open_project},
    'helptext'=>'Open dir as Project',
    'image'=> TkPhotoImage.new('dat' => OPEN_GIF)})
  )

  @button_box.add(Arcadia.style('toolbarbutton').update({
    'name'=>'parent_folder',
    'anchor' => 'nw',
    'command'=>proc{self.do_goto_parent_folder},
    'helptext'=>'Go to parent folder',
    'image'=> TkPhotoImage.new('dat' => PARENTFOLDER_GIF)})
  )
  #--- button_box
  
  @cb_sync = TkCheckButton.new(self.frame.hinner_frame, Arcadia.style('checkbox')){
    text  'Sync'
    justify  'left'
    indicatoron 0
    offrelief 'raised'
    image TkPhotoImage.new('dat' => SYNCICON20_GIF)
    #pack('anchor'=>'n')
    place('x' => 0,'y' => 0,'height' => 26, 'width' => 26)
  }

  Tk::BWidget::DynamicHelp::add(@cb_sync, 
    'text'=>'Link open editors with content in the Navigator')

  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)
  @font =  Arcadia.conf('treeitem.font')
  @font_b = "#{Arcadia.conf('treeitem.font')} bold"
  @selecting_node = false    
  do_select_item = proc{|_tree, _selected|
    if File.exist?(node2file(_selected))
      if File.ftype(node2file(_selected)) == 'file'
        _sync_val = @sync
        @sync = false
        begin
	         Arcadia.process_event(OpenBufferTransientEvent.new(self,'file'=>node2file(_selected)))
	       ensure
          @sync = _sync_val
	       end
#        elsif !_selected.nil? && @htree.open?(node2file(_selected))
#          @htree.close_tree(node2file(_selected))
#        elsif !_selected.nil?
#          @htree.open_tree(node2file(_selected),false) 
      end
    else
      shure_delete_node(_selected)
    end
  }
  
  
  do_open_folder_cmd = proc{|_node| do_open_folder(_node)}
  do_close_folder_cmd = proc{|_node| do_close_folder(_node)}
  
#	  @htree = Tk::BWidget::Tree.new(self.frame.hinner_frame, Arcadia.style('treepanel')){
 @htree = BWidgetTreePatched.new(self.frame.hinner_frame, Arcadia.style('treepanel')){
    showlines false
    deltay 18
    opencmd do_open_folder_cmd
    closecmd do_close_folder_cmd
    selectcommand do_select_item
  }
  @htree.extend(TkScrollableWidget).show(0,26)
  self.pop_up_menu_tree
  @image_kdir = TkPhotoImage.new('dat' => ICON_FOLDER_OPEN_GIF)
  @image_kdir_closed = TkPhotoImage.new('dat' => FOLDER_GIF)
 self.load_projects
  @htree.areabind_append('KeyPress',proc{|k| 
      key_press(k)
  },"%K")

  do_double_click = proc{
      _selected = @htree.selected
      if File.ftype(node2file(_selected)) == 'directory'
        if !_selected.nil? && @htree.open?(node2file(_selected))
          @htree.close_tree(node2file(_selected))
        elsif !_selected.nil?
          @htree.open_tree(node2file(_selected),false) 
        end
      end
  }
  
  @htree.textbind_append('Double-1',do_double_click)
end

#pop_up_menu_treeObject



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
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
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
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 274

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'))
  #----- new submenu
  sub_new = TkMenu.new(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => 'New'
  )
  sub_new.extend(TkAutoPostMenu)
  sub_new.configure(Arcadia.style('menu'))
  sub_new.insert('end',
    :command,
    :label=>'New dir Project',
    :hidemargin => false,
    :command=> proc{do_new_project}
  )

  sub_new.insert('end',
    :command,
    :label=>'New folder',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_new_folder(_selected)
      end
    }
  )

  sub_new.insert('end',
    :command,
    :label=>'New file',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_new_file(_selected)
      end
    }
  )

  @pop_up_tree.insert('end',
    :cascade,
    :label=>'New',
    :menu=>sub_new,
    :hidemargin => false
  )
  #-----------------
  #----- refactor submenu
  sub_ref = TkMenu.new(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => 'Ref'
  )
  sub_ref.extend(TkAutoPostMenu)
  sub_ref.configure(Arcadia.style('menu'))
  sub_ref.insert('end',
    :command,
    :label=>'Rename',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_rename(_selected)
      end
    }
  )
  sub_ref.insert('end',
    :command,
    :label=>'Move',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        _idir = File.split(_selected)[0]
        _dir=Tk.chooseDirectory('initialdir'=>_idir,'mustexist'=>true) 
        do_move(_selected, _dir) if _dir && File.exists?(_dir)
      end
    }
  )
  @pop_up_tree.insert('end',
    :cascade,
    :label=>'Refactor',
    :menu=>sub_ref,
    :hidemargin => false
  )
  
  #-----------------
  #----- 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=>'Find in files...',
    :hidemargin => false,
    :command=> proc{
      _target = @htree.selected
      if _target
        _target = File.dirname(_target) if File.ftype(_target) == 'file'
        Arcadia.process_event(SearchInFilesEvent.new(self,'dir'=>_target))
      end
    }
  )
  
  sub_ref_search.insert('end',
    :command,
    :label=>'Act in files...',
    :hidemargin => false,
    :command=> proc{
      _target = @htree.selected
      if _target
        _target = File.dirname(_target) if File.ftype(_target) == 'file'
        Arcadia.process_event(AckInFilesEvent.new(self,'dir'=>_target))
      end
    }
  )
  @pop_up_tree.insert('end',
    :cascade,
    :label=>'Search from here',
    :menu=>sub_ref_search,
    :hidemargin => false
  )
  
  
  #-----------------
  
  @pop_up_tree.insert('end',
    :command,
    :label=>'Open dir as Project',
    :hidemargin => false,
    :command=> proc{do_open_project}
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>'Close Project',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        #p _selected
        do_close_project(_selected)
      end
    }
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>'Refresh',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      do_refresh(_selected)
    }
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>'Delete',
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_delete(_selected)
      end
    }
  )

  @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

#project_of_node(_node) ⇒ Object



732
733
734
735
736
737
738
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 732

def project_of_node(_node)
  project = _node
  while !@node_parent[project].nil? && @node_parent[project] != 'root'
    project = @node_parent[project]
  end
  return @projects[project]
end

#projects_fileObject



881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 881

def projects_file
   if !defined?(@arcadia_projects_file)
   		@arcadia_projects_file = @arcadia.local_dir+'/'+conf('file.name')
   		if !File.exist?(@arcadia_projects_file)
    			dir,fil =File.split(File.expand_path(@arcadia_projects_file))
    			if !File.exist?(dir)
    			  Dir.mkdir(dir)
    			end
       f = File.new(@arcadia_projects_file, "w+")
       begin
         f.syswrite("#Projects conf\n") if f
       ensure
         f.close unless f.nil?
       end
     end
   		
   end
   return @arcadia_projects_file
end

#select_file_without_event(_file) ⇒ Object



902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 902

def select_file_without_event(_file)
  _file_node_rif = File.expand_path(_file)
  steps = _file_node_rif.split(File::SEPARATOR)
  j = 0
  max = steps.length-1
  path = ''
  while j <  max
    if path.strip.length > 0 && path.strip != File::SEPARATOR
      path = path + File::SEPARATOR
    end
    if path.strip.length == 0 && _file_node_rif[0..0] == File::SEPARATOR
      path = File::SEPARATOR
    end
    path = path + steps[j]
    if @htree.exist?(path) 
      @htree.open_tree(path, false)
    end
    j=j+1
  end
  if @htree.exist?(_file_node_rif)
    shure_select_node(_file_node_rif)
  end
end

#shure_delete_node(_node) ⇒ Object



787
788
789
790
791
792
793
794
795
796
797
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 787

def shure_delete_node(_node)
  if _node.length>1 || @htree.exist?(_node)
    _sc = @htree.cget('selectcommand')
    begin
      @htree.configure('selectcommand'=>nil)
      @htree.delete(file2node(_node))
    ensure
      @htree.configure('selectcommand'=>_sc)
    end
  end
end

#shure_select_node(_node) ⇒ Object



799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 799

def shure_select_node(_node)
  return if @selecting_node
  @selecting_node = true
  #_proc = @htree.selectcommand
  #@htree.selectcommand(nil)
  _proc = @htree.cget('selectcommand')
  @htree.configure('selectcommand'=>nil)
  begin
    @htree.selection_clear
    @htree.selection_add(_node)
    @htree.see(_node)
  ensure
    #@htree.selectcommand(_proc)
    @htree.configure('selectcommand'=>_proc)
    @selecting_node = false
  end
end

#sync_offObject



32
33
34
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 32

def sync_off
  @sync = false
end

#sync_onObject



27
28
29
30
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 27

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