Class: Rfd::BookmarkWindow
Instance Attribute Summary
Attributes inherited from SubWindow
#controller, #window
Instance Method Summary
collapse
Methods inherited from SubWindow
#close, #create_window, #draw_border, #height, #left, #max_height, #max_width, #refresh, #reposition_if_needed, #top, #width
Constructor Details
Returns a new instance of BookmarkWindow.
5
6
7
8
9
10
11
|
# File 'lib/rfd/bookmark_window.rb', line 5
def initialize(controller)
super(controller)
@cursor = 0
@scroll = 0
@filter = FilterInput.new { apply_filter }
@filtered_items = nil
end
|
Instance Method Details
#all_items ⇒ Object
13
14
15
|
# File 'lib/rfd/bookmark_window.rb', line 13
def all_items
Bookmark.bookmarks
end
|
#current_bookmarked? ⇒ Boolean
21
22
23
|
# File 'lib/rfd/bookmark_window.rb', line 21
def current_bookmarked?
Bookmark.include?(controller.current_dir.path)
end
|
#current_item ⇒ Object
29
30
31
|
# File 'lib/rfd/bookmark_window.rb', line 29
def current_item
display_items[@cursor]
end
|
#display_items ⇒ Object
17
18
19
|
# File 'lib/rfd/bookmark_window.rb', line 17
def display_items
@filtered_items || all_items
end
|
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
84
85
86
87
88
|
# File 'lib/rfd/bookmark_window.rb', line 58
def handle_input(c)
case c
when 27 controller.close_sub_window
true
when 64, ?@ controller.close_sub_window
controller.instance_variable_set(:@sub_window, NavigationWindow.new(controller))
controller.instance_variable_get(:@sub_window).render
true
when 2 toggle_bookmark
true
when 10, 13 select_item
true
when 14 move_cursor_down
true
when 16 move_cursor_up
true
else
if @filter.handle_input(c)
render
true
else
false
end
end
end
|
#render ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
|
# File 'lib/rfd/bookmark_window.rb', line 33
def render
reposition_if_needed
@window.clear
draw_border('Bookmarks (@:tree ^B:add/remove ESC:close)')
@filter.render(@window, 1, max_width)
visible_items.each_with_index do |path, i|
actual_index = @scroll + i
@window.setpos(2 + i, 1)
display_path = path.sub(File.expand_path('~'), '~')
if actual_index == @cursor
@window.attron(Curses::A_REVERSE) { @window.addstr(display_path[0, max_width].ljust(max_width)) }
else
@window.addstr(display_path[0, max_width].ljust(max_width))
end
end
@window.refresh
end
|
#visible_items ⇒ Object
25
26
27
|
# File 'lib/rfd/bookmark_window.rb', line 25
def visible_items
display_items[@scroll, max_height - 1] || []
end
|