Class: Breakpoints

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

Overview

ae-breakpoints.rb - Arcadia Ruby ide

by Antonio Galeone <[email protected]>

Instance Attribute Summary

Attributes inherited from ArcadiaExt

#arcadia

Instance Method Summary collapse

Methods inherited from ArcadiaExt

#conf, #conf_array, #exec, #float_frame, #frame, #frame_def_visible?, #frame_visible?, #initialize, #maximize, #maximized?, #resize

Constructor Details

This class inherits a constructor from ArcadiaExt

Instance Method Details

#breakpoint_add(_file, _line, _code, _active = true) ⇒ Object



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
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 278

def breakpoint_add(_file,_line, _code, _active=true)
  _file_node = file2node_name(_file) 
  _line_node = line2node_name(_file_node, _line)
  (_active)?_check_value=1 : _check_value=0
  if !@tree_break.exist?(_file_node)
    @tree_break.insert('end', 'root' ,_file_node, {
      'open'=>true,
      'anchor'=>'w',
      'text' =>  _file,
      'deltax'=>-1,
      'window' => new_check_button(_file_node, _check_value)
    }.update(Arcadia.style('treeitem')))
  elsif _active
    _check = @tree_break.itemcget(_file_node, 'window')
    _check.cget('variable').value=1
  end
  
  if !@tree_break.exist?(_line_node)
    @tree_break.insert('end', _file_node ,_line_node, {
      'open'=>true,
      'anchor'=>'w',
      'text' =>  "line: #{_line} --> #{_code}",
      'deltax'=>-1,
      'window' => new_check_button(_line_node, _check_value)
    }.update(Arcadia.style('treeitem')))
    @tree_break.reorder(_file_node,@tree_break.nodes(_file_node).sort)
  elsif _active
    _check = @tree_break.itemcget(_line_node, 'window')
    _check.cget('variable').value=1 
  end
end

#breakpoint_del(_file, _line, _delete = false) ⇒ Object



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
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 310

def breakpoint_del(_file,_line, _delete=false)
  _file_node = file2node_name(_file) 
  _line_node = line2node_name(_file_node, _line)
  if @tree_break.exist?(_line_node)
    begin
      if _delete
        _sc = @tree_break.cget('selectcommand')
        @tree_break.configure('selectcommand'=>nil)
        @tree_break.delete(_line_node)
      else
        _check = @tree_break.itemcget(_line_node, 'window')
        _check.cget('variable').value=0 
      end
      _bro = @tree_break.nodes(_file_node)
      if _bro.nil? || _bro.length == 0 
        if _delete
          @tree_break.delete(_file_node) 
        else
          _check = @tree_break.itemcget(_file_node, 'window')
          _check.cget('variable').value=0 
        end
      elsif _bro.length > 0 && !_delete
        is_checked = false
        _bro.each{|n|
          _check = @tree_break.itemcget(n, 'window')
          v = _check.cget('variable').value
          is_checked = is_checked || v.to_i==1
        }
        if !is_checked
          _check = @tree_break.itemcget(_file_node, 'window')
          _check.cget('variable').value=0 
        end
      end
    ensure
      @tree_break.configure('selectcommand'=>_sc) if _delete
    end

  end
end

#breakpoint_list_freeObject



363
364
365
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 363

def breakpoint_list_free
  @tree_break.delete(@tree_break.nodes('root'))
end

#breakpoint_select(_file, _line) ⇒ Object



350
351
352
353
354
355
356
357
358
359
360
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 350

def breakpoint_select(_file, _line)
  _file_node = file2node_name(_file) 
  _line_node = line2node_name(_file_node, _line)
  @tree_break.selection_clear
  #p "line node = #{_line_node}"
  if @tree_break.exist?(_line_node)
    @tree_break.open_tree(_file_node, false)
    @tree_break.selection_add(_line_node)
    @tree_break.see(_line_node)
  end
end

#build_popupObject



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
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 120

def build_popup
  _pop_up = TkMenu.new(
    :parent=>@tree_break,
    :tearoff=>0,
    :title => 'Menu'
  )
  _pop_up.configure(Arcadia.style('menu'))
  _title_item = _pop_up.insert('end',
    :command,
    :label=>'...',
    :state=>'disabled',
    :background=>Arcadia.conf('titlelabel.background'),
    :hidemargin => true
  )

  _pop_up.insert('end',
    :command,
    :label=>'Clear breakpoint',
    :hidemargin => false,
    :command=> proc{raise_clear_selected}
  )

  _pop_up.insert('end',
    :command,
    :label=>'Delete breakpoint',
    :hidemargin => false,
    :command=> proc{raise_clear_selected(true)}
  )

  _pop_up.insert('end',
    :command,
    :label=>'Goto breakpoint',
    :hidemargin => false,
    :command=> proc{goto_select_item}
  )


  @tree_break.textbind_append("Button-3",
    proc{|*x|
      _x = TkWinfo.pointerx(@tree_break)
      _y = TkWinfo.pointery(@tree_break)
      _selected = @tree_break.selection_get[0]
      _file, _line = get_tree_selection(@tree_break)
      _label = _file
      if _line
        _label << " line: #{_line}"
      end
      _pop_up.entryconfigure(0,'label'=>_label)

      _pop_up.popup(_x,_y)
    })
end

#build_uiObject



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
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 53

def build_ui
#    do_select_item = proc{|_self|
#      if _self.selection_get[0].length >0
#      	_selected = ""
#      	_self.selection_get[0].each{|_block|
#       	 _selected = _selected + _block.to_s + "\s" 
#      	}
#      	_selected = _selected.strip
#      else
#        _selected = _self.selection_get[0]
#      end
#      _node_name, _line = _selected.split('_')
#      if _node_name && _line
#        _file = _self.itemcget(_node_name, 'text')
#        if _file
# 	        Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file, 'row'=>_line))
#        end
#      end
#    }

  @tree_break = Tk::BWidget::Tree.new(self.frame.hinner_frame, Arcadia.style('treepanel')){
    #showlines true
    deltay 18
    padx 25
    #selectcommand proc{ do_select_item.call(self) } 
  }.place('relwidth' => 1,'relheight' => '1')
  
  build_popup
  
  @ui_builded = true
end

#ensure_build_uiObject



47
48
49
50
51
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 47

def ensure_build_ui
  if !@ui_builded
    build_ui
  end
end

#file2node_name(_file) ⇒ Object



217
218
219
220
221
222
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 217

def file2node_name(_file)
  _file = File.expand_path(_file)
  #_file = File.basename(_file)
  _s = ""
  _file.gsub("_",_s).gsub("/",_s).gsub(".",_s).gsub(":",_s).gsub("\\",_s).gsub("-",_s)
end

#get_tree_selection(_tree) ⇒ Object



173
174
175
176
177
178
179
180
181
182
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 173

def get_tree_selection(_tree)
  _ret = Array.new
  _selected = _tree.selection_get[0]
  if _selected
    _node_name, _line = _selected.split('_')
    _ret << _tree.itemcget(_node_name, 'text')
    _ret << _line if _line
  end
  _ret
end

#goto_select_itemObject



93
94
95
96
97
98
99
100
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 93

def goto_select_item
  _file, _line = get_tree_selection(@tree_break)
  if _file && _line
    Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file, 'row'=>_line))
  elsif _file
    Arcadia.process_event(OpenBufferEvent.new(self,'file'=>_file, 'row'=>0))
  end
end

#line2node_name(_parent, _line) ⇒ Object



274
275
276
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 274

def line2node_name(_parent, _line)
  "#{_parent}_#{_line.to_s}"
end

#load_persistent_breakpointsObject



33
34
35
36
37
38
39
40
41
42
43
44
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 33

def load_persistent_breakpoints
  b = Arcadia.persistent('breakpoints')
  if b
    _files_list =b.split("|")
    _files_list.each do |value| 
      _file,_line,_active = value.split('@@@')
      if _file && _line && _active
        Arcadia.process_event(SetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line, 'active'=>_active.to_i))
      end
    end
  end
end

#new_check_button(_node_name, _value = 1) ⇒ Object



224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
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-breakpoints/ae-breakpoints.rb', line 224

def new_check_button(_node_name, _value=1)
  _command = proc {|_checkbutton|
    _file_node_name, _line = _node_name.split('_')
    _file = @tree_break.itemcget(_file_node_name, 'text')
    if _checkbutton.cget('variable').value.to_i==0
      if _file && _line
        Arcadia.process_event(UnsetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line))
      elsif _file
        sons = @tree_break.nodes(_node_name)
        if sons
           sons.each{|son|
              _nil, _l = son.split('_')
              Arcadia.process_event(UnsetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_l)) if _l
           }
        end
      end
    else
      if _file && _line
        Arcadia.process_event(SetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line, 'active'=>1))
      elsif _file
        sons = @tree_break.nodes(_node_name)
        if sons
           sons.each{|son|
              _nil, _l = son.split('_')
              Arcadia.process_event(SetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_l, 'active'=>1)) if _l
           }
        end
      end
      
    end
  } 
  TkCheckButton.new(@tree_break, Arcadia.style('checkbox')){
    #text _label
    indicatoron  true
    padx 0
    pady 0
    variable TkVariable.new(_value)
    background   Arcadia.style('treepanel')['background']
    borderwidth 0
    command proc{_command.call(self)}
    relief 'flat'
  }
#    _item_on_img = TkPhotoImage.new('dat' => ON_GIF)
#    @item_off_img = TkPhotoImage.new('dat' => OFF_GIF)
#    @b_item_onoff = TkButton.new(@tree_break, Arcadia.style('button')){
#        image  _item_on_img
#        anchor 'nw'
#    }.bind("1",proc{   })
end

#on_after_build(_event) ⇒ Object



18
19
20
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 18

def on_after_build(_event)
  load_persistent_breakpoints
end

#on_before_build(_event) ⇒ Object



7
8
9
10
11
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 7

def on_before_build(_event)
  @ui_builded = false
  @breakpoints =Array.new
  Arcadia.attach_listener(self, DebugEvent)
end

#on_build(_event) ⇒ Object



13
14
15
16
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 13

def on_build(_event)
   build_ui 
#    load_persistent_breakpoints
end

#on_debug(_event) ⇒ Object



185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 185

def on_debug(_event)
  case _event
    when SetBreakpointEvent
      ensure_build_ui
      @breakpoints.delete_if{|b| (b[:file]==_event.file && b[:line]==_event.row)}
      @breakpoints << {:file=>_event.file,:line=>_event.row, :active=>_event.active}
      self.breakpoint_add(File.expand_path(_event.file), _event.row, _event.line_code, _event.active==1)
    when UnsetBreakpointEvent
      if @ui_builded
        if _event.delete
          @breakpoints.delete_if{|b| (b[:file]==_event.file && b[:line]==_event.row)}
        else
          @breakpoints.collect! {|b| 
            if b[:file]==_event.file && b[:line]==_event.row
              b[:active]=0
            end
            b
          } 
        end
        self.breakpoint_del(File.expand_path(_event.file), _event.row, _event.delete)
        #self.breakpoint_del(File.expand_path(_event.file), _event.row, _event.sender != self)
      end
  end
end

#on_debug_step_info(_event) ⇒ Object



210
211
212
213
214
215
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 210

def on_debug_step_info(_event)
  #Arcadia.console(self, :msg=> "ae-breakpoints -> DebugStepInfoEvent")
  if @ui_builded
    self.breakpoint_select(_event.file, _event.row)
  end
end

#on_finalize(_event) ⇒ Object



22
23
24
25
26
27
28
29
30
31
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 22

def on_finalize(_event)
  _breakpoints = '';
  @breakpoints.each{|point|
    if point[:file] != nil
      _breakpoints=_breakpoints+'|' if _breakpoints.strip.length > 0
      _breakpoints=_breakpoints + "#{point[:file]}@@@#{point[:line]}@@@#{point[:active]}"
    end
  }
  Arcadia.persistent('breakpoints', _breakpoints)
end

#raise_clear_selected(_delete = false) ⇒ Object



104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 104

def raise_clear_selected(_delete=false)
  _file, _line = get_tree_selection(@tree_break)
  if _file && _line
     Arcadia.process_event(UnsetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_line, 'delete'=>_delete))
  elsif _file
     _node_name = file2node_name(_file)
     sons = @tree_break.nodes(_node_name)
     if sons
       sons.each{|son|
         _nil, _l = son.split('_')
         Arcadia.process_event(UnsetBreakpointEvent.new(self, 'file'=>_file, 'row'=>_l, 'delete'=>_delete)) if _l
       }
    end
  end
end

#unbuild_uiObject



86
87
88
89
90
91
# File 'ext/ae-breakpoints/ae-breakpoints.rb', line 86

def unbuild_ui
  if @ui_builded
   
    @ui_builded = false
  end
end