Class: StandardLocator

Inherits:
Object
  • Object
show all
Defined in:
lib/hilfer/standard_locator.rb

Overview

This handles various keypresses that jump to specific locations in a project. If a specific file isn’t selected, the jump will go to the directory. Otherwise it will go to a specific file.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(treeviewer) ⇒ StandardLocator

Returns a new instance of StandardLocator.



12
13
14
15
16
17
18
19
20
21
# File 'lib/hilfer/standard_locator.rb', line 12

def initialize( treeviewer )
  @treeviewer = treeviewer

  @controller_re =       %r|^(.*?)/app/controllers/(.*?)/?(.*?)_controller.rb$|
  @view_re =             %r|^(.*?)/app/views/(.*?)/?([^/.]*?\..*?)?$|
  @model_re =            %r|^(.*?)/app/models/(.*?/?)([^/.]*?).rb$|
  @unit_test_re =        %r|^(.*?)/test/unit/(.*?/?)(.*?)_test.rb$|
  @functional_test_re =  %r|^(.*?)/test/functional/(.*?/?)(.*?)_controller_test.rb$|
  @fixture_re =          %r|^(.*?)/test/fixtures/(.*?/?)(.*?).yml$|
end

Instance Attribute Details

#treeviewerObject

Returns the value of attribute treeviewer.



10
11
12
# File 'lib/hilfer/standard_locator.rb', line 10

def treeviewer
  @treeviewer
end

Instance Method Details

#goto_path(fs_path) ⇒ Object



27
28
29
# File 'lib/hilfer/standard_locator.rb', line 27

def goto_path( fs_path )
  treeviewer.select_fs_path( viewer_root + fs_path, true )
end

#handle_keypress(widget, event) ⇒ Object



46
47
48
49
50
51
52
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 'lib/hilfer/standard_locator.rb', line 46

def handle_keypress( widget, event )
  retval = true
  case
  # Shift-Ctrl-T - go to test, or test dir
  when event.hardware_keycode == 28 && event.state.control_mask?  && event.state.shift_mask?
    select_related_paths( widget, event ) do |item|
      case
        when md = @model_re.match( item.path )
          '/test/unit/' + $2 + $3 + '_test.rb'
        when md = @view_re.match( item.path )
          '/test/functional/' + $2 + '_controller_test.rb'
        when md = @controller_re.match( item.path )
          '/test/functional/' + $2 + $3 + '_controller_test.rb'
        when md = @fixture_re.match( item.path )
          '/test/unit/' + $2 + $3.singularize + '_test.rb'
        else
          rp = Pathname.new( viewer_root )
          if ( rp + 'test' ).exist?
            '/test'
          elsif (rp + 'spec').exist?
            '/spec'
          end
      end
    end

  # Shift-Ctrl-B - go to lib dir
  when event.hardware_keycode == 56 && event.state.control_mask? && event.state.shift_mask?
    goto_path '/lib'

  # Shift-Ctrl-O - go to config
  when event.hardware_keycode == 32 && event.state.control_mask?  && event.state.shift_mask?
    goto_path '/config'

  else
    retval = false
  end
  retval
end


31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/hilfer/standard_locator.rb', line 31

def select_related_paths( widget, event, &block )
  items = []
  paths_to_select = []
  widget.selection.selected_each do
    |model, path, iter|
    item = model.get_value( iter, 0 )
    puts "item: #{item.path}" if $options[:debug]
    new_path = yield( item )
    puts "new_path #{new_path}" if $options[:debug]
    paths_to_select << viewer_root + new_path
  end

  treeviewer.select_fs_paths( paths_to_select, true )
end

#viewer_rootObject



23
24
25
# File 'lib/hilfer/standard_locator.rb', line 23

def viewer_root
  treeviewer.root_item.path
end