Class: DirProjects

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

Instance Attribute Summary collapse

Attributes inherited from ArcadiaExtPlus

#index

Attributes inherited from ArcadiaExt

#arcadia, #name

Instance Method Summary collapse

Methods inherited from ArcadiaExtPlus

#activate, #activate_main, #active?, #active_instance, #clean_instance, #clone, #deduplicate, #duplicate, #exist_name?, #frame, #initialize, #instance_index, #instances, instances, #main_instance, #main_instance?, #new_name, #on_destroy_instance

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_raised?, #frame_title, #frame_visible?, #hide_frame, #hinner_dialog, #hinner_splitted_dialog, #hinner_splitted_dialog_titled, #initialize, #maximize, #maximized?, #resize, #restore_default_conf

Constructor Details

This class inherits a constructor from ArcadiaExtPlus

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


895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 895

def add_node(_parent, _node, _kind)
  if @htree.exist?(_node)
    if ['project','directory'].include?(_kind) && @node_parent[_node]!=_parent && !_node.include?('phantom_')
      _phantom_node =  "phantom_#{_node}"
      j = 0
      while @htree.exist?(_phantom_node)
        _phantom_node= "phantom_#{j}_#{_node}"
        j = j +1
      end
      _name = File.basename(_node)
      selectable = _kind == 'project'
      _drawcross = 'auto'
        @htree.insert('end', _parent ,_phantom_node, {
          'text' =>  _name ,
          'helptext' => _node,
          'drawcross'=>_drawcross,
          'selectable'=>selectable,
          'deltax'=>-1,
          'image'=> image(_kind, _node)
        }.update(Arcadia.style('treeitem').update({'fill'=>Arcadia.conf('inactiveforeground')}))
      )
    end
  else
    @node_parent[_node] = _parent
#    _name = _node.split(File::SEPARATOR)[-1]
    _name = File.basename(_node)
    _drawcross = 'auto'
    if _kind == "project" || _kind == "directory"
      begin
        num = Dir.entries(_node).length-2
        if num > 0
          _drawcross = 'always'
        end
      rescue  Errno::EACCES
 return
      rescue  Errno::ENOENT
  return
      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
end

#add_project(_dir) ⇒ Object


964
965
966
967
968
969
970
971
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 964

def add_project(_dir)
  if _dir && _dir.length > 0 && _dir[-1..-1] == File::SEPARATOR
    _dir = _dir[0..-2]
  end
  @projects[_dir] = Project.new(_dir)
  add_node('root', _dir, "project")
  add_project_to_file(_dir) 
end

#add_project_to_file(_project) ⇒ Object


1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1040

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") if _line.strip[0..0] == '#' || File.exists?(_line)
       }
       f.syswrite(_project+"\n")
     ensure
       f.close unless f.nil?
     end
   end	
end

#add_temp_node(_parent, _node, _kind) ⇒ Object


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

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


1004
1005
1006
1007
1008
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1004

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

#del_project_from_file(_project) ⇒ Object


1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1060

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
         f.syswrite(_line+"\n")
       end
     }
   ensure
     f.close unless f.nil?
   end
end

#do_close_folder(_node, _close = false) ⇒ Object


248
249
250
251
252
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 248

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


658
659
660
661
662
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 658

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


842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 842

def do_delete(_node, _interactive = true)
  if File.exists?(node2file(_node)) 
    type = File.ftype(node2file(_node))
    if type == 'directory'
      _msg = Arcadia.text("ext.dir_projects.d.delete.msg", [_node, 'directory'])
    else
      _msg = Arcadia.text("ext.dir_projects.d.delete.msg", [_node, 'file'])
    end
    if !_interactive || type == 'file' || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => Arcadia.text("ext.dir_projects.d.delete.title"), '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 = Arcadia.text("ext.dir_projects.d.delete.msg2", [_node])
          entries.each{|en|
            _msg2 = "#{_msg2}\n#{en}"
          }
          if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => Arcadia.text("ext.dir_projects.d.delete.title"), '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
        _event = Arcadia.process_event(DeleteFileBufferEvent.new(self,'file'=>node2file(_node)))
        delete_node = _event && _event.flag == Event::FLAG_DEFAULT
        #File.delete(node2file(_node))
      end
      shure_delete_node(_node) if delete_node
    end
  end
end

#do_goto_parent_folderObject


578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 578

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


745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 745

def do_move(_source, _destination, _interactive = true)
  _msg = Arcadia.text('ext.dir_projects.d.move.msg', [_source, _destination])
  if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => Arcadia.text('ext.dir_projects.d.move.title'), '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


688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 688

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


664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 664

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

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

def do_new_project(_parent_folder_node=nil)
  active_instance.do_new_project if active_instance != self
  if _parent_folder_node.nil?
    #_parent_folder_node=Tk.chooseDirectory 'initialdir' =>  MonitorLastUsedDir.get_last_dir
    _parent_folder_node=Arcadia.select_dir_dialog(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


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

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 child && 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


648
649
650
651
652
653
654
655
656
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 648

def do_open_project(_proj_name=nil)
  active_instance.do_open_project if active_instance != self

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

#do_open_termObject


567
568
569
570
571
572
573
574
575
576
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 567

def do_open_term
  active_instance.do_open_term if active_instance != self
  _target = @htree.selected || MonitorLastUsedDir.get_last_dir
  if _target
    _target = File.dirname(_target) if File.ftype(_target) == 'file'
    TermEvent.new(self,'dir'=>_target, 'title'=>_target).go!
  else
    Arcadia.dialog(self, 'type'=>'ok','title' => Arcadia.text('ext.dir_projects.d.nosel.title'), 'msg' => Arcadia.text('ext.dir_projects.d.nosel.msg'), 'level'=>'info')
  end
end

#do_paste(_source, _destination, _interactive = true) ⇒ Object


812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 812

def do_paste(_source, _destination, _interactive = true)
  _msg = Arcadia.text("ext.dir_projects.d.paste.msg", [_source, _destination])
  if !_interactive || Arcadia.dialog(self,'type'=>'yes_no', 'level'=>'warning','title' => Arcadia.text("ext.dir_projects.d.paste.title"), 'msg'=>_msg)=='yes'
    if File.exists?(_source) 
      require "fileutils"
      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_paste(full_en, des_path, false)
          }
        end
      else
        new_file = File.join(_destination,source_basename)
        FileUtils.cp(_source, new_file)
      end
      if _interactive
        do_refresh(File.split(_source)[0])
        do_refresh(_destination)
      end
    end
  end
end

#do_refresh(_node) ⇒ Object


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

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


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

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_search_filesObject


558
559
560
561
562
563
564
565
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 558

def do_search_files
  active_instance.do_search_files if active_instance != self
  _target = @htree.selected || MonitorLastUsedDir.get_last_dir
  if _target
    _target = File.dirname(_target) if File.ftype(_target) == 'file'
    Arcadia.process_event(SearchInFilesEvent.new(self,'dir'=>_target))
  end
end

#do_select_item2Object


202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 202

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


240
241
242
243
244
245
246
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 240

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

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


1153
1154
1155
1156
1157
1158
1159
1160
1161
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1153

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
end

#is_project?(_node) ⇒ Boolean

Returns:

  • (Boolean)

808
809
810
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 808

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

#key_press(_keysym) ⇒ Object


220
221
222
223
224
225
226
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 220

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

#load_projectsObject


1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1025

def load_projects
  f = File::open(projects_file,'r')
  begin
    _lines = f.readlines.collect!{| line | line.chomp}
    _lines = sort_files_name(_lines)
  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


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

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


232
233
234
235
236
237
238
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 232

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

#on_after_build(_event) ⇒ Object


228
229
230
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 228

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


1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1135

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


1127
1128
1129
1130
1131
1132
1133
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1127

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
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
# 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'=>0)
#    TkWinfo.parent(@button_box).configure(:background => Arcadia.conf('panel.background'))
  
#    @button_box.add(Arcadia.style('toolbarbutton').update({
#      'name'=>'new_proj',
#      'anchor' => 'center',
#      'command'=>proc{self.do_new_project},
#      'helptext'=>Arcadia.text('ext.dir_projects.button.new.hint'),
#      'image'=> Arcadia.image_res(NEW_GIF)})
#    )



#    @button_box.add(Arcadia.style('toolbarbutton').update({
#      'name'=>'open_proj',
#      'anchor' => 'center',
#      'command'=>proc{self.do_open_project},
#      'helptext'=>Arcadia.text('ext.dir_projects.button.open.hint'),
#      'image'=> Arcadia.image_res(OPEN_PROJECT_GIF)})
#    )



#    @button_box.add(Arcadia.style('toolbarbutton').update({
#      'name'=>'parent_folder',
#      'anchor' => 'center',
#      'command'=>proc{self.do_goto_parent_folder},
#      'helptext'=>Arcadia.text('ext.dir_projects.button.up.hint'),
#      'image'=> Arcadia.image_res(PARENTFOLDER_GIF)})
#    )


  
#    @button_box.add(Arcadia.style('toolbarbutton').update({
#      'name'=>'search_in_files',
#      'anchor' => 'center',
#      'command'=>proc{self.do_search_files},
#      'helptext'=>Arcadia.text('ext.dir_projects.button.search.hint'),
#      'image'=> Arcadia.image_res(SEARCH_FILES_GIF)})
#    )



#    @button_box.add(Arcadia.style('toolbarbutton').update({
#      'name'=>'terminal',
#      'anchor' => 'center',
#      'command'=>proc{self.do_open_term},
#      'helptext'=>Arcadia.text('ext.dir_projects.button.term.hint'),
#      'image'=> Arcadia.image_res(TERMINAL_GIF)})
#    )

  
  
  #--- button_box
  
  
  @panel = self.frame.root.add_panel(self.frame.name, "sync");
#    @cb_sync = TkCheckButton.new(@panel, Arcadia.style('checkbox').update('background'=>@panel.background)){
  
  @cb_sync = Arcadia.wf.titlecontextcheckbutton(@panel){
    variable TkVariable.new
    image Arcadia.image_res(SYNC_GIF)
    pack
  }
  
  @cb_sync.hint=Arcadia.text('ext.dir_projects.button.link.hint')

#    Tk::BWidget::DynamicHelp::add(@cb_sync, 
#      'text'=>Arcadia.text('ext.dir_projects.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)
  @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
  }

  self.frame.root.add_button(self.frame.name, Arcadia.text('ext.dir_projects.button.up.hint'), proc{self.do_goto_parent_folder}, ARROW_UP_GIF)
#    self.frame.root.add_sep(self.frame.name,1)
#    self.frame.root.add_button(self.frame.name, Arcadia.text('ext.dir_projects.button.term.hint'), proc{self.do_open_term}, TERMINAL_GIF)
#    self.frame.root.add_sep(self.frame.name,1)
#    self.frame.root.add_button(self.frame.name, Arcadia.text('ext.dir_projects.button.search.hint'), proc{self.do_search_files}, SEARCH_FILES_GIF)
#    self.frame.root.add_sep(self.frame.name,1)
#    self.frame.root.add_button(self.frame.name, Arcadia.text('ext.dir_projects.button.open.hint'), proc{Tk.callback_break;self.do_open_project}, OPEN_PROJECT_GIF)
#    self.frame.root.add_sep(self.frame.name,1)
#    self.frame.root.add_button(self.frame.name, Arcadia.text('ext.dir_projects.button.new.hint'), proc{self.do_new_project}, NEW_GIF)
  
  
  do_open_folder_cmd = proc{|_node| do_open_folder(_node)}
  do_close_folder_cmd = proc{|_node| do_close_folder(_node)}
  @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
    crosscloseimage  Arcadia.image_res(PLUS_GIF)
    crossopenimage  Arcadia.image_res(MINUS_GIF)
  }
#    @htree.extend(TkScrollableWidget).show(0,24)
  @htree.extend(TkScrollableWidget).show(0,0)
  self.pop_up_menu_tree
  @image_kdir = Arcadia.image_res(ICON_FOLDER_OPEN_GIF)
  @image_kdir_closed = Arcadia.image_res(FOLDER_GIF)
 self.load_projects
  @htree.areabind_append('KeyPress',proc{|k| 
      key_press(k)
  },"%K")

  do_double_click = proc{
      _selected = @htree.selected
      if _selected &&  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

#on_clear_cache_instance(_event) ⇒ Object


1147
1148
1149
1150
1151
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1147

def on_clear_cache_instance(_event)
  if File.exist?(@arcadia_projects_file)
    File.delete(@arcadia_projects_file)
  end
end

#pop_up_menu_treeObject


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
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
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
526
527
528
529
530
531
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
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 315

def pop_up_menu_tree
  #@pop_up_tree = TkMenu.new(
  @pop_up_tree = Arcadia.wf.menu(
    :parent=>@htree,
    :tearoff=>0,
    :title => Arcadia.text('ext.dir_projects.menu.title')
  )
  #@pop_up_tree.extend(TkAutoPostMenu)
  #@pop_up_tree.configure(Arcadia.style('menu'))
  #----- new submenu
  #sub_new = TkMenu.new(
  sub_new = Arcadia.wf.menu(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => Arcadia.text('ext.dir_projects.menu.new')
  )
  #sub_new.extend(TkAutoPostMenu)
  #sub_new.configure(Arcadia.style('menu'))
  sub_new.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.new_dir_proj'),
    :hidemargin => false,
    :command=> proc{do_new_project}
  )

  sub_new.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.new_folder'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_new_folder(_selected)
      end
    }
  )

  sub_new.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.new_file'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_new_file(_selected)
      end
    }
  )

  @pop_up_tree.insert('end',
    :cascade,
    :label=>Arcadia.text('ext.dir_projects.menu.new'),
    :menu=>sub_new,
    :hidemargin => false
  )
  #-----------------
  #----- refactor submenu
  #sub_ref = TkMenu.new(
  sub_ref = Arcadia.wf.menu(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => Arcadia.text('ext.dir_projects.menu.refactor')
  )
  #sub_ref.extend(TkAutoPostMenu)
  #sub_ref.configure(Arcadia.style('menu'))
  sub_ref.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.refactor.rename'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        do_rename(_selected)
      end
    }
  )
  sub_ref.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.refactor.move'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        _idir = File.split(_selected)[0]
        #_dir=Tk.chooseDirectory('initialdir'=>_idir,'mustexist'=>true) 
        _dir=Arcadia.select_dir_dialog(_idir, true)
        do_move(_selected, _dir) if _dir && File.exists?(_dir)
      end
    }
  )
  @pop_up_tree.insert('end',
    :cascade,
    :label=>Arcadia.text('ext.dir_projects.menu.refactor'),
    :menu=>sub_ref,
    :hidemargin => false
  )
  
  #-----------------
  #----- search submenu
  #sub_ref_search = TkMenu.new(
  sub_ref_search = Arcadia.wf.menu(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => Arcadia.text('ext.dir_projects.menu.search')
  )
  #sub_ref_search.extend(TkAutoPostMenu)
  #sub_ref_search.configure(Arcadia.style('menu'))
  sub_ref_search.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.search.find'),
    :hidemargin => false,
    :command=> proc{ do_search_files }
  )
  
  sub_ref_search.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.search.act'),
    :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=>Arcadia.text('ext.dir_projects.menu.search'),
    :menu=>sub_ref_search,
    :hidemargin => false
  )

  #-----------------
  #----- runners submenu
  @sub_ref_runners = Arcadia.wf.menu(
    :parent=>@pop_up_tree,
    :tearoff=>0,
    :title => Arcadia.text('ext.dir_projects.menu.runners')
  )
  
  @pop_up_tree.insert('end',
    :cascade,
    :label=>Arcadia.text('ext.dir_projects.menu.runners'),
    :menu=>@sub_ref_runners,
    :hidemargin => false
  )
  
  #-----------------

  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.term'),
    :hidemargin => false,
    :command=> proc{do_open_term}
  )
  
  #-----------------
  
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.open'),
    :hidemargin => false,
    :command=> proc{do_open_project}
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.close'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        #p _selected
        do_close_project(_selected)
      end
    }
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.refresh'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      do_refresh(_selected)
    }
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.copy'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if _selected
        @copy_source = _selected
      end
    }
  )
  
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.paste'),
    :hidemargin => false,
    :command=> proc{
      _selected = @htree.selected
      if @copy_source && _selected && @copy_source != _selected && File.ftype(node2file(_selected)) == "directory"
        do_paste(@copy_source, _selected)
      end
    }
  )
  @pop_up_tree.insert('end',
    :command,
    :label=>Arcadia.text('ext.dir_projects.menu.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)
      
      selected = @htree.selected
      if selected && @htree.exist?(selected)
        if File.ftype(selected) == 'file'
          file = selected
          dir = nil
        else
          file = nil
          dir = selected
        end
        Arcadia.instance.refresh_runners_on_menu(@sub_ref_runners, file, dir)
      end
      
    },
  "%x %y")
end

#project_of_node(_node) ⇒ Object


887
888
889
890
891
892
893
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 887

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


1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1082

def projects_file
   if !defined?(@arcadia_projects_file)
   		@arcadia_projects_file = @arcadia.local_dir+'/'+conf('file.name')
   		@arcadia_projects_file = "#{@arcadia_projects_file}#{instance_index}" if instance_index > 0 
   		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


1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1103

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


973
974
975
976
977
978
979
980
981
982
983
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 973

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


985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 985

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
  @htree.call_after_next_show_h_scroll(proc{Tk.update;@htree.see(_node)})
end

#sort_files_name(_files = nil) ⇒ Object


1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
# File 'ext/ae-dir-projects/ae-dir-projects.rb', line 1010

def sort_files_name(_files=nil)
  return if _files.nil?
  sorted = []
  names = []
  files_hash = {}
  _files.each{|file|
    name = File.split(file)[1]
    names << name
    files_hash[name]=file
  }
  names.sort!
  names.each{|n| sorted << files_hash[n]}
  sorted
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