Class: VimMate::TagsWindow

Inherits:
Object
  • Object
show all
Defined in:
lib/vim_mate/tags_window.rb

Constant Summary collapse

NAME =

treestore columns Column for the tag name

0
LINE =

Column for the line it is in

1
PATH =
2
NODE =

path_node_connection columns

0
METHODS =
1
CLASSES =
2

Instance Method Summary collapse

Constructor Details

#initialize(vim_window = FalseClass) ⇒ TagsWindow

Returns a new instance of TagsWindow.



60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
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
# File 'lib/vim_mate/tags_window.rb', line 60

def initialize(vim_window = FalseClass)
  @vim_window = vim_window
  @tags_treestore = Gtk::TreeStore.new(String,String,String)
  
  # Tree View
  @tags_tree_view = Gtk::TreeView.new(@tags_treestore)
  @tags_tree_view.selection.mode = Gtk::SELECTION_SINGLE
  @tags_tree_view.headers_visible = Config[:file_headers_visible]
  @tags_tree_view.hover_selection = Config[:file_hover_selection]    
  
  tags_renderer = Gtk::CellRendererText.new
  col = Gtk::TreeViewColumn.new("Identifier", tags_renderer, :text => NAME)
  @tags_tree_view.append_column(col)
  col = Gtk::TreeViewColumn.new("Line", tags_renderer, :text => LINE)
  @tags_tree_view.append_column(col)

  # Double-click, Enter, Space: Signal to open the file
  @tags_tree_view.signal_connect("row-activated") do |view, path, column|
    iter = @tags_treestore.get_iter(path)
    @vim_window.open_and_jump_to_line iter[PATH], iter[LINE].to_i
  end

  Signal.on_file_opened do |path|
    sleep 0.5
    do_refresh_tags
  end

  #@tags_text_buffer = Gtk::TextBuffer.new()
  #gtk_text_view = Gtk::TextView.new(@tags_text_buffer)
  #gtk_text_view.editable = false
  #gtk_text_view.cursor_visible = false

  # Set the default size for the file list
 
  Signal.on_file_modified do |path|
    paths = @vim_window.get_all_buffer_paths
    if paths.include?(path)
      do_refresh_tags
    end
  end

  #Signal.on_file_deleted do |path|
  #  #do_refresh_tags
  #end
  
  #Signal.on_file_created do |path|
  #  #do_refresh_tags
  #end
end

Instance Method Details

#add_parent_rows(paths) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/vim_mate/tags_window.rb', line 40

def add_parent_rows(paths)
  #add some parents
  @path_node_connection = Hash.new(false)
  paths.each do |path|
    node = @tags_treestore.append(nil)
    node[0] = path.split('/').last
    node[1] = ''
    node[2] = ''
    methods = @tags_treestore.append(node)
    methods[0] = 'Methods'
    methods[1] = ''
    methods[2] = ''
    classes = @tags_treestore.append(node)
    classes[0] = 'Classes'
    classes[1] = ''
    classes[2] = ''
    @path_node_connection[path] = [node, methods, classes]
  end
end

#do_refresh_tags(paths = nil) ⇒ Object

TODO: refresh upon switch to this tab: switch-page: self, page, page_num Emitted when the user or a function changes the current page.

* self: the object which received the signal.
* page: the new current Gtk::NotebookPage
* page_num: the index of the page


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
# File 'lib/vim_mate/tags_window.rb', line 124

def do_refresh_tags(paths=nil)
  if not paths
    paths = @vim_window.get_all_buffer_paths
  end

  @tags_treestore.clear
  add_parent_rows(paths)
    
  paths.each do |path|
    #TODO make me dependent/configurable on file type/suffix
    tags = `ctags --sort=1 -ex #{path}`
    last_class = nil

    whats_a_tag = %r[^(\w+)\s+(\w+\s?\w+)\s+(\d+)\s+(\S+)]
    tags.each_line do |tag|
      if elems = whats_a_tag.match(tag)
        id, type, line, file = elems[1..-1]
        case type
        when 'function'
          new_row = @tags_treestore.append(@path_node_connection[path][METHODS])
          new_row.set_value(NAME, id)
          new_row.set_value(LINE, line)
          new_row.set_value(PATH, file)
        when 'class'
          new_row = @tags_treestore.append(@path_node_connection[path][CLASSES])
          new_row.set_value(NAME, id)
          new_row.set_value(LINE, line)
          new_row.set_value(PATH, file)
          last_class = new_row
        when /^(singleton )?method|member$/
          new_row = @tags_treestore.append(last_class)
          new_row.set_value(NAME, id)
          new_row.set_value(LINE, line)
          new_row.set_value(PATH, file)
        end
      end
    end
  end

  @tags_tree_view.expand_all
end

#gtk_windowObject

The “window” for this object



111
112
113
# File 'lib/vim_mate/tags_window.rb', line 111

def gtk_window
  @tags_tree_view
end