Class: StandardLocator
- Inherits:
-
Object
- Object
- StandardLocator
- 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
-
#treeviewer ⇒ Object
Returns the value of attribute treeviewer.
Instance Method Summary collapse
- #goto_path(fs_path) ⇒ Object
- #handle_keypress(widget, event) ⇒ Object
-
#initialize(treeviewer) ⇒ StandardLocator
constructor
A new instance of StandardLocator.
- #select_related_paths(widget, event, &block) ⇒ Object
- #viewer_root ⇒ Object
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
#treeviewer ⇒ Object
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( , 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? ( , 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 |
#select_related_paths(widget, event, &block) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/hilfer/standard_locator.rb', line 31 def ( , event, &block ) items = [] paths_to_select = [] .selection.selected_each do |model, path, iter| item = model.get_value( iter, 0 ) puts "item: #{item.path}" if [:debug] new_path = yield( item ) puts "new_path #{new_path}" if [:debug] paths_to_select << viewer_root + new_path end treeviewer.select_fs_paths( paths_to_select, true ) end |
#viewer_root ⇒ Object
23 24 25 |
# File 'lib/hilfer/standard_locator.rb', line 23 def viewer_root treeviewer.root_item.path end |