Class: AgEditorOutline

Inherits:
Object
  • Object
show all
Defined in:
ext/ae-editor/ae-editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(_editor, _frame, _bar, _lang = nil) ⇒ AgEditorOutline

Returns a new instance of AgEditorOutline.



855
856
857
858
859
860
861
# File 'ext/ae-editor/ae-editor.rb', line 855

def initialize(_editor, _frame, _bar, _lang=nil)
  @editor = _editor
  @frame = _frame
  @bar = _bar
  @lang = _lang
  initialize_tree(_frame)
end

Instance Attribute Details

#last_openedObject (readonly)

Returns the value of attribute last_opened.



854
855
856
# File 'ext/ae-editor/ae-editor.rb', line 854

def last_opened
  @last_opened
end

#last_rowObject (readonly)

Returns the value of attribute last_row.



851
852
853
# File 'ext/ae-editor/ae-editor.rb', line 851

def last_row
  @last_row
end

#ssObject (readonly)

Returns the value of attribute ss.



853
854
855
# File 'ext/ae-editor/ae-editor.rb', line 853

def ss
  @ss
end

#tree_expObject (readonly)

Returns the value of attribute tree_exp.



852
853
854
# File 'ext/ae-editor/ae-editor.rb', line 852

def tree_exp
  @tree_exp
end

Instance Method Details

#build_tree(_sel = nil) ⇒ Object



1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
# File 'ext/ae-editor/ae-editor.rb', line 1013

def build_tree(_sel=nil)
  #Arcadia.console(self,"msg"=>"build for #{@file}")
  if _sel
    _label_sel = @tree_exp.itemcget(_sel,'text')
  end
  
  #clear tree
  begin
    @tree_exp.delete(@tree_exp.nodes('root'))
  rescue Exception
    # workaround on windows
    @tree_exp.delete(@tree_exp.nodes('root'))
  end
  
  
  _txt = @editor.text.get('1.0','end')
  if @editor.has_ctags?
    if @editor.file && !@editor.modified?
      @ss = CtagsSourceStructure.new(@editor.file, @editor.ctags_string)
    else
      tmp_file = @editor.create_temp_file
      begin
        @ss = CtagsSourceStructure.new(tmp_file, @editor.ctags_string, @lang)
      ensure 
        File.delete(tmp_file)
      end
    end
  else
    @ss = RubySourceStructure.new(_txt)
  end
  @selected = nil
  build_tree_from_node(@ss.root, _label_sel)
  if @selected
    @tree_exp.selection_add(@selected.rif)
    @tree_exp.open_tree(@selected.parent.rif) if @selected.parent.rif != 'root'
    @tree_exp.see(@selected.rif)
  end
end

#build_tree_from_node(_node, _label_match = nil) ⇒ Object



981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
# File 'ext/ae-editor/ae-editor.rb', line 981

def build_tree_from_node(_node, _label_match=nil)
  @image_class = Arcadia.image_res(TREE_NODE_CLASS_GIF)
  @image_module =  Arcadia.image_res(TREE_NODE_MODULE_GIF)
  @image_method =  Arcadia.image_res(TREE_NODE_METHOD_GIF)
  @image_singleton_method =  Arcadia.image_res(TREE_NODE_SINGLETON_METHOD_GIF)
  
  _sorted_sons = _node.sons.sort 
  for inode in 0.._sorted_sons.length - 1
    _son = _sorted_sons[inode]
    if _son.kind == 'class'
        _image = @image_class
    elsif _son.kind == 'module'
        _image = @image_module
    elsif _son.kind == 'method' || _son.kind == 'procedure'
        _image = @image_method
    elsif _son.kind == 'singleton method'
        _image = @image_singleton_method
    end
    @tree_exp.insert('end', _son.parent.rif ,_son.rif, {
      'text' =>  _son.label ,
      'helptext' => _son.helptext,
      #'font'=>$arcadia['conf']['editor.explorer_panel.tree.font'],
      'image'=> _image
    }.update(Arcadia.style('treeitem'))
    )
    if (_label_match) && (_label_match.strip == _son.label.strip)
      @selected = _son
    end
    build_tree_from_node(_son, _label_match) # recursion -- if there are no sons it will do nothing
  end
end

#destroyObject



963
964
965
966
967
968
# File 'ext/ae-editor/ae-editor.rb', line 963

def destroy
  #@tree_scroll_wrapper.destroy
  @tree_exp.hide
  @tree_exp.destroy
  Tk.update
end

#hideObject



976
977
978
979
# File 'ext/ae-editor/ae-editor.rb', line 976

def hide
  @tree_exp.hide
  #@tree_scroll_wrapper.hide
end

#initialize_tree(_frame) ⇒ Object



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
949
950
951
952
953
954
955
956
957
958
959
960
961
# File 'ext/ae-editor/ae-editor.rb', line 916

def initialize_tree(_frame)
  _tree_goto = proc{|_self|
    sync_val = @bar.sync
    @bar.sync=false
    begin
      #_line = _self.selection_get[0]
      _line = _self.selected
      _index =_line.to_s+'.0'
      _hinner_text = @tree_exp.itemcget(_line,'text').strip
      _editor_line = @editor.text.get(_index, _index+ '  lineend')
      if !_editor_line.include?(_hinner_text)
        Arcadia.console(self, 'msg'=>"#{Arcadia.text('ext.editor.outline.rebuild_tree')} \n")
        if @tree_thread && @tree_thread.alive?
          @tree_thread.exit # kill the old tree
        end
        @tree_thread = Thread.new{
          build_tree(_line)
          Tk.update
        }
        _line = _self.selected
        _index =_line.to_s+'.0'
      end
      @editor.text.set_focus
      @editor.text.see(_index)
      @editor.text.tag_remove('selected','1.0','end')
      @editor.text.tag_add('selected',_line.to_s+'.0',(_line+1).to_s+'.0')
    ensure
      @bar.sync = sync_val
    end
  }
  do_open_command = proc{|no|
    @last_opened = no
  }
  @tree_exp = BWidgetTreePatched.new(_frame, Arcadia.style('treepanel')){
    showlines false
    deltay 18
    dragenabled true
    selectcommand proc{ _tree_goto.call(self) } 
    opencmd do_open_command 
    crosscloseimage  Arcadia.image_res(ARROWRIGHT_GIF)      
    crossopenimage  Arcadia.image_res(ARROWDOWN_GIF)
  }
  @tree_exp.extend(TkScrollableWidget)
  self.show
  pop_up_menu_tree
end

#pop_up_menu_treeObject



1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
# File 'ext/ae-editor/ae-editor.rb', line 1052

def pop_up_menu_tree
  @pop_up_tree = TkMenu.new(
    :parent=>@tree_exp,
    :tearoff=>0,
    :title => 'Menu tree'
  )
  @pop_up_tree.extend(TkAutoPostMenu)
  @pop_up_tree.configure(Arcadia.style('menu'))
  #Arcadia.instance.main_menu.update_style(@pop_up_tree)
  @pop_up_tree.insert('end',
    :command,
    :label=> Arcadia.text('ext.editor.outline.menu.rebuild'),
    :hidemargin => false,
    :command=> proc{build_tree}
  )
  @tree_exp.areabind_append("Button-3",
    proc{|x,y|
      _x = TkWinfo.pointerx(@tree_exp)
      _y = TkWinfo.pointery(@tree_exp)
      @pop_up_tree.popup(_x,_y)
    },
  "%x %y")
end

#select_without_event(_line) ⇒ Object



907
908
909
910
911
912
913
914
# File 'ext/ae-editor/ae-editor.rb', line 907

def select_without_event(_line)
  if @ss
    _node=@ss.(@ss.root, _line)
    if _node && @tree_exp.exist?(_node.rif) && _node.rif!='root'
      shure_select_node(_node)
    end
  end
end

#showObject



970
971
972
973
974
# File 'ext/ae-editor/ae-editor.rb', line 970

def show
  #@tree_scroll_wrapper.show(0,26)
  @tree_exp.show(0,0)
  Tk.update
end

#shure_select_line(_line, _close_if_opened = true) ⇒ Object



898
899
900
901
902
903
904
905
# File 'ext/ae-editor/ae-editor.rb', line 898

def shure_select_line(_line, _close_if_opened = true)
  if @ss && _line
    node = @ss.(@ss.root, _line)
  else
    node = SourceStructure.root
  end
  shure_select_node(node, _close_if_opened)
end

#shure_select_node(_node, _close_if_opened = true) ⇒ Object

I think this is “if synced expand out the outline for the current selection”



871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
# File 'ext/ae-editor/ae-editor.rb', line 871

def shure_select_node(_node, _close_if_opened = true)
  return if @selecting_node
  #return if @tree_exp.exist?(_node.rif)
  @selecting_node = true
  _proc = @tree_exp.selectcommand
  @tree_exp.selectcommand(nil)
  begin
    @tree_exp.selection_clear
    @tree_exp.selection_add(_node.rif)
    @opened = false
    to_open = @last_open_node
    parent = _node.parent
    while !parent.nil? && parent.rif != 'root'
      @tree_exp.open_tree(parent.rif, false)
      @opened = to_open==parent.rif || @opened
      @last_open_node=parent.rif
      parent = parent.parent
    end
    @tree_exp.close_tree(to_open) if _close_if_opened && to_open && !@opened
    @tree_exp.see(_node.rif)
  ensure
    @tree_exp.selectcommand(_proc)
    @selecting_node = false
  end
  @tree_exp.call_after_next_show_h_scroll(proc{Tk.update;@tree_exp.see(_node.rif)})    
end

#update_row(_row = 0) ⇒ Object



863
864
865
866
867
868
# File 'ext/ae-editor/ae-editor.rb', line 863

def update_row(_row=0)
  @last_row=_row
  if @bar.is_sync_on?
    select_without_event(_row)
  end
end