Class: AgEditorOutline
- Inherits:
-
Object
- Object
- AgEditorOutline
- Defined in:
- ext/ae-editor/ae-editor.rb
Instance Attribute Summary collapse
-
#last_row ⇒ Object
readonly
Returns the value of attribute last_row.
-
#tree_exp ⇒ Object
readonly
Returns the value of attribute tree_exp.
Instance Method Summary collapse
- #build_tree(_sel = nil) ⇒ Object
- #build_tree_from_node(_node, _label_match = nil) ⇒ Object
- #destroy ⇒ Object
- #hide ⇒ Object
-
#initialize(_editor, _frame, _bar) ⇒ AgEditorOutline
constructor
A new instance of AgEditorOutline.
- #initialize_tree(_frame) ⇒ Object
- #pop_up_menu_tree ⇒ Object
- #select_without_event(_line) ⇒ Object
- #show ⇒ Object
-
#shure_select_node(_node) ⇒ Object
I think this is “if synced expand out the outline for the current selection”.
- #update_row(_row = 0) ⇒ Object
Constructor Details
#initialize(_editor, _frame, _bar) ⇒ AgEditorOutline
Returns a new instance of AgEditorOutline.
675 676 677 678 679 680 |
# File 'ext/ae-editor/ae-editor.rb', line 675 def initialize(_editor, _frame, ) @editor = _editor @frame = _frame @bar = initialize_tree(_frame) end |
Instance Attribute Details
#last_row ⇒ Object (readonly)
Returns the value of attribute last_row.
673 674 675 |
# File 'ext/ae-editor/ae-editor.rb', line 673 def last_row @last_row end |
#tree_exp ⇒ Object (readonly)
Returns the value of attribute tree_exp.
674 675 676 |
# File 'ext/ae-editor/ae-editor.rb', line 674 def tree_exp @tree_exp end |
Instance Method Details
#build_tree(_sel = nil) ⇒ Object
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 841 842 |
# File 'ext/ae-editor/ae-editor.rb', line 815 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 #(re)build tree _txt = @editor.text.get('1.0','end') #@root = build_tree_from_source(_txt) @ss = SourceStructure.new(_txt) #@root = @ss.root @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) @tree_exp.see(@selected.rif) end end |
#build_tree_from_node(_node, _label_match = nil) ⇒ Object
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 |
# File 'ext/ae-editor/ae-editor.rb', line 783 def build_tree_from_node(_node, _label_match=nil) @image_kclass = TkPhotoImage.new('dat' => TREE_NODE_CLASS_GIF) @image_kmodule = TkPhotoImage.new('dat' => TREE_NODE_MODULE_GIF) @image_kdef = TkPhotoImage.new('dat' => TREE_NODE_DEF_GIF) @image_kdefclass = TkPhotoImage.new('dat' => TREE_NODE_DEFCLASS_GIF) _sorted_sons = _node.sons.sort for inode in 0.._sorted_sons.length - 1 _son = _sorted_sons[inode] if _son.kind == 'KClass' _image = @image_kclass elsif _son.kind == 'KModule' _image = @image_kmodule elsif _son.kind == 'KDef' _image = @image_kdef elsif _son.kind == 'KDefClass' _image = @image_kdefclass 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 |
#destroy ⇒ Object
769 770 771 772 |
# File 'ext/ae-editor/ae-editor.rb', line 769 def destroy @tree_scroll_wrapper.destroy @tree_exp.destroy end |
#hide ⇒ Object
779 780 781 |
# File 'ext/ae-editor/ae-editor.rb', line 779 def hide @tree_scroll_wrapper.hide end |
#initialize_tree(_frame) ⇒ Object
727 728 729 730 731 732 733 734 735 736 737 738 739 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 766 767 |
# File 'ext/ae-editor/ae-editor.rb', line 727 def initialize_tree(_frame) _tree_goto = proc{|_self| sync_val = @bar.sync @bar.sync=false begin _line = _self.selection_get[0] _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'=>"... 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.selection_get[0] _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 } @tree_exp = Tk::BWidget::Tree.new(_frame, Arcadia.style('treepanel')){ showlines false deltay 18 dragenabled true selectcommand proc{ _tree_goto.call(self) } } @tree_scroll_wrapper = TkScrollWidget.new(@tree_exp) self.show @tree_scroll_wrapper.show_v_scroll @tree_scroll_wrapper.show_h_scroll end |
#pop_up_menu_tree ⇒ Object
844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 |
# File 'ext/ae-editor/ae-editor.rb', line 844 def @pop_up_tree = TkMenu.new( :parent=>@tree_exp, :title => 'Menu tree' ) @pop_up_tree.configure(Arcadia.style('menu')) #Arcadia.instance.main_menu.update_style(@pop_up_tree) @pop_up_tree.insert('end', :command, :label=>'Rebuild', :hidemargin => false, :command=> proc{build_tree} ) @tree_exp.bind_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
718 719 720 721 722 723 724 725 |
# File 'ext/ae-editor/ae-editor.rb', line 718 def select_without_event(_line) if @ss _node=@ss.deep_node_by_line(@ss.root, _line) if _node && @tree_exp.exist?(_node.rif) && _node.rif!='root' shure_select_node(_node) end end end |
#show ⇒ Object
774 775 776 777 |
# File 'ext/ae-editor/ae-editor.rb', line 774 def show @tree_scroll_wrapper.show(0,26) Tk.update end |
#shure_select_node(_node) ⇒ Object
I think this is “if synced expand out the outline for the current selection”
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 |
# File 'ext/ae-editor/ae-editor.rb', line 690 def shure_select_node(_node) 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 to_open && !@opened @tree_exp.see(_node.rif) ensure @tree_exp.selectcommand(_proc) @selecting_node = false end end |
#update_row(_row = 0) ⇒ Object
682 683 684 685 686 687 |
# File 'ext/ae-editor/ae-editor.rb', line 682 def update_row(_row=0) @last_row=_row if @bar.is_sync_on? select_without_event(_row) end end |