Class: TkInspect::ClassBrowser::RootComponent

Inherits:
TkComponent::Base
  • Object
show all
Defined in:
lib/tk_inspect/class_browser/root_component.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#class_browserObject

Returns the value of attribute class_browser.



6
7
8
# File 'lib/tk_inspect/class_browser/root_component.rb', line 6

def class_browser
  @class_browser
end

Instance Method Details

#browse_by_changed(e) ⇒ Object



75
76
77
78
79
80
81
82
83
# File 'lib/tk_inspect/class_browser/root_component.rb', line 75

def browse_by_changed(e)
  @class_browser.browsing_method = e.sender.value
  @class_browser_comp.data_source = @class_browser.class_data_source
  @class_browser.select_class_path([])
  @class_browser_comp.selected_path = []
  @module_method_browser_component.selected_path = []
  @class_browser_comp.regenerate
  @module_method_browser_component.regenerate
end

#class_selected(e) ⇒ Object



47
48
49
50
51
# File 'lib/tk_inspect/class_browser/root_component.rb', line 47

def class_selected(e)
  @class_browser.select_class_path(e.data_object.selected_path)
  @module_method_browser_component.selected_path = []
  @module_method_browser_component.regenerate
end

#filter_changed(e) ⇒ Object



65
66
67
68
69
70
71
72
73
# File 'lib/tk_inspect/class_browser/root_component.rb', line 65

def filter_changed(e)
  return if class_browser.class_data_source.class_filter == e.sender.s_value
  class_browser.class_data_source.class_filter = e.sender.s_value
  @class_browser.select_class_path([])
  @class_browser_comp.selected_path = []
  @module_method_browser_component.selected_path = []
  @class_browser_comp.regenerate
  @module_method_browser_component.regenerate
end

#module_method_selected(e) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'lib/tk_inspect/class_browser/root_component.rb', line 53

def module_method_selected(e)
  path = e.data_object.selected_path || []
  module_name = path[0]
  method_name = path[1]
  code, line, file = @class_browser.code_for_method(method_name)
  @code.method_name = method_name
  @code.code = code
  @code.method_line = line
  @code.filename = file
  @code.update
end

#render(p, parent_component) ⇒ Object



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
34
35
36
37
38
39
40
41
# File 'lib/tk_inspect/class_browser/root_component.rb', line 8

def render(p, parent_component)
  p.vframe(sticky: 'nsew', x_flex: 1, y_flex: 1) do |vf|
    vf.hframe(padding: "12", sticky: 'nsew', x_flex: 1, y_flex: 0) do |hf|
      hf.hframe(sticky: 'nw') do |f|
        f.label(text: "Browse by: ")
        f.radio_set(value: "hierarchy", on_change: :browse_by_changed) do |rs|
          rs.radio_button(text: "Class hierarchy", value: 'hierarchy')
          rs.radio_button(text: "Namespaces", value: 'namespaces')
        end
      end
      hf.hframe(sticky: 'ne', x_flex: 1) do |f|
        f.label(text: "Filter")
        f.entry(value: class_browser.class_data_source.class_filter, on_change: :filter_changed)
      end
    end
    vf.vpaned(sticky: 'nsew', x_flex: 1, y_flex: 1) do |vp|
      @class_browser_comp = vp.insert_component(TkComponent::BrowserComponent, self,
                                                data_source: class_browser.class_data_source,
                                                selected_path: class_browser.selected_class_path,
                                                paned: true,
                                                sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
        bc.on_event'PathChanged', ->(e) { class_selected(e) }
      end
      @module_method_browser_component = vp.insert_component(TkComponent::RBrowserComponent, self,
                                                             data_source: class_browser.module_method_data_source,
                                                             paned: true,
                                                             max_columns: 2,
                                                             sticky: 'nsew', x_flex: 1, y_flex: 1) do |bc|
        bc.on_event'PathChanged', ->(e) { module_method_selected(e) }
      end
      @code = vp.insert_component(CodeComponent, self, sticky: 'nsew', x_flex: 1, y_flex: 1)
    end
  end
end

#show_current_selectionObject



43
44
45
# File 'lib/tk_inspect/class_browser/root_component.rb', line 43

def show_current_selection
  @class_browser_comp.show_current_selection
end