Class: SearchOutput

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

Instance Method Summary collapse

Constructor Details

#initialize(_ext) ⇒ SearchOutput

Returns a new instance of SearchOutput.



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
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 82

def initialize(_ext)
  @sequence = 0
  @ext = _ext
  left_frame = TkFrame.new(@ext.frame).place('x' => '0','y' => '0','relheight' => '1','width' => '25')
  #right_frame = TkFrame.new(@ext.frame).place('x' => '25','y' => '0','relwidth' => '1', 'relheight' => '1', 'width' => '-25')
  @results = {}
  _open_file = proc do |tree, sel|
    n_parent, n = sel.split('@@@')
    Arcadia.process_event(OpenBufferEvent.new(self,'file'=>@results[n_parent][n][0], 'row'=>@results[n_parent][n][1]))  if n && @results[n_parent][n]
    #EditorContract.instance.open_file(self, 'file'=>@results[n_parent][n][0], 'line'=>@results[n_parent][n][1]) if n && @results[n_parent][n]
  end

  @tree = Tk::BWidget::Tree.new(@ext.frame){
    background '#FFFFFF'
    relief 'flat'
    showlines true
    linesfill '#e7de8f'
    selectcommand _open_file 
    deltay 15
  }.place('x' => '25','y' => '0','relwidth' => '1', 'relheight' => '1', 'width' => '-40', 'height'=>'-15')
  #---- y scrollbar
  _yscrollcommand = proc{|*args| @tree.yview(*args)}
  _yscrollbar = TkScrollbar.new(@ext.frame){|s|
    #width 8
    command _yscrollcommand
  }.pack('side'=>'right', 'fill'=>'y')
  @tree.yscrollcommand proc{|first,last| _yscrollbar.set(first,last)}
  #---- x scrollbar
  _xscrollcommand = proc{|*args| @tree.xview(*args)}
  _xscrollbar = TkScrollbar.new(@ext.frame){|s|
    #width 8
    orient 'horizontal'
    command _xscrollcommand
  }.pack('side'=>'bottom', 'fill'=>'x')
  @tree.xscrollcommand proc{|first,last| _xscrollbar.set(first,last)}
  
  _proc_clear = proc{clear_tree}
  
  @button_u = Tk::BWidget::Button.new(left_frame){
    image  TkPhotoImage.new('dat' => CLEAR_GIF)
    helptext 'Clear'
    foreground 'blue'
    command _proc_clear
    relief 'groove'
    pack('side' =>'top', 'anchor'=>'n',:padx=>0, :pady=>0)
  }
  
  @found_color='#3f941b'
  @not_found_color= 'red'
  @item_color='#6fc875'
end

Instance Method Details

#add_result(_node, _file, _line = '', _line_text = '') ⇒ Object



163
164
165
166
167
168
169
170
171
172
173
174
175
176
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 163

def add_result(_node, _file, _line='', _line_text='')
  @count = @count+1
  @tree.itemconfigure(_node, 'fill'=>@found_color, 'text'=>@text_result+' { '+@count.to_s+' found }')
  _text = _file+':'+_line+' : '+_line_text
  _node_name = new_node_name
  @tree.insert('end', _node ,_node+'@@@'+_node_name, {
    'fill'=>@item_color,
    'anchor'=>'w',
    'font' => @ext.conf('font'),
    'text' =>  _text.strip
  })
  @results[_node][_node_name]=[_file,_line]
  Tk.update
end

#clear_treeObject



134
135
136
137
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 134

def clear_tree
  @tree.delete(@tree.nodes('root'))
  @results.clear
end

#new_node_nameObject



139
140
141
142
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 139

def new_node_name
  @sequence = @sequence + 1
  return 'n'+@sequence.to_s
end

#new_result(_text, _length = 0) ⇒ Object



144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
# File 'ext/ae-search-in-files/ae-search-in-files.rb', line 144

def new_result(_text, _length=0)
  @results.each_key{|key| @tree.close_tree(key)}
  _r_node = new_node_name
  @text_result = _text
  #_text = _text + ' { '+_length.to_s+' found }'
  #_length > 0 ? _color='#3f941b':_color = 'red'
  @tree.insert('end', 'root' ,_r_node, {
    'fill'=>@not_found_color,
    'open'=>true,
    'anchor'=>'w',
    'font' => @ext.conf('font.bold'),
    'text' =>  _text
  })
  Tk.update
  @results[_r_node]={}
  @count = 0
  return _r_node
end