Class: RuDebug::Page::CodeFile

Inherits:
Object
  • Object
show all
Defined in:
lib/rudebug/page/code_file.rb

Instance Method Summary collapse

Constructor Details

#initialize(parent, name) ⇒ CodeFile

Returns a new instance of CodeFile.



2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/rudebug/page/code_file.rb', line 2

def initialize(parent, name)
  @parent = parent
  @name = name
  @glade_file = parent.glade_file

  @parent.files_combobox.prepend_text(name)
  update_combobox_sensitive()

  @glade = GladeXML.new(@glade_file, "code-container") do |handler|
    method(handler) rescue lambda { |*args| p [handler, *args] }
  end

  @code = @glade["code-container"]
  @code_viewport = @glade["code-viewport"]

  label = Gtk::Label.new(name)
  @parent.code_notebook.prepend_page(@code, label)

  @line_view = @glade["line-view"]
  @code_view = @glade["code-view"]
  @line_buf = @line_view.buffer
  @code_buf = @code_view.buffer

  @parent.create_default_tag(@line_buf)
  @parent.create_default_tag(@code_buf)

  @pos_marker = @code.render_icon(
    Gtk::Stock::GO_FORWARD, Gtk::IconSize::MENU, "foo")
  @last_marker_line = nil

  load_source_code()
end

Instance Method Details

#activateObject



35
36
37
# File 'lib/rudebug/page/code_file.rb', line 35

def activate()
  @parent.code_notebook.page = @parent.code_notebook.page_num(@code)
end

#load_source_codeObject



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rudebug/page/code_file.rb', line 43

def load_source_code()
  source = @parent.session.source_code(@name)
  Syntax.gtk_highlight(source, @code_buf)

  line_no = source.to_a.size
  lines = (1 .. line_no).map do |line|
    "%*d" % [line_no.to_s.size, line]
  end.join("\n")
  @line_buf.insert(@line_buf.end_iter, lines, "default")
  @line_count = line_no - 1
end

#on_code_view_button_release_eventObject Also known as: on_line_view_button_release_event



84
85
86
# File 'lib/rudebug/page/code_file.rb', line 84

def on_code_view_button_release_event()
  
end

#place_marker(line) ⇒ Object



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
# File 'lib/rudebug/page/code_file.rb', line 55

def place_marker(line)
  line -= 1

  if @last_marker_line then
    start_iter = @line_buf.get_iter_at_line(@last_marker_line)
    end_iter = @line_buf.get_iter_at_line(@last_marker_line)
    end_iter.forward_chars(2)
    @line_buf.delete(start_iter, end_iter)
  end

  iter = @line_buf.get_iter_at_line(line)
  @line_buf.insert(iter, " ")
  @line_buf.insert(iter, @pos_marker)
  @last_marker_line = line

  vadj = @code_viewport.vadjustment

  # Got to delay this until the source view actually is done loading...
  Thread.new do
    sleep 0.01 until vadj.upper > 1.0 if @line_count > 2

    vadj.value = [
      vadj.upper * (line / @line_count.to_f),
      vadj.upper - vadj.page_size
    ].min
  end
end

#update_combobox_sensitiveObject



39
40
41
# File 'lib/rudebug/page/code_file.rb', line 39

def update_combobox_sensitive()
  @parent.files_combobox.sensitive = @parent.files_combobox.model.size > 0
end