Class: Ektoplayer::Controllers::Playlist

Inherits:
Controller
  • Object
show all
Defined in:
lib/ektoplayer/controllers/playlist.rb

Instance Method Summary collapse

Constructor Details

#initialize(view, playlist, view_operations, operations) ⇒ Playlist

Returns a new instance of Playlist.



7
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
42
43
44
45
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
# File 'lib/ektoplayer/controllers/playlist.rb', line 7

def initialize(view, playlist, view_operations, operations)
   super(view)
   view.attach(playlist)

   register = view_operations.with_register('playlist.')
   %w(up down page_up page_down top bottom
      search_up search_down search_next search_prev toggle_selection).
      each { |op| register.(op, &@view.method(op)) }

   register.(:play) do
      operations.send(:'playlist.play', view.selected)
   end

   register.(:reload) do
      view.get_selection.each do |index|
         operations.send(:'playlist.reload', index)
      end
   end

   register.(:download_album) do
      view.get_selection.each do |index|
         operations.send(:'playlist.download_album', index)
      end
   end

   register.(:delete) do
      view.with_lock do
         old_cursor, selection = view.cursor, view.get_selection

         selection.each do 
            operations.send(:'playlist.delete', selection[0])
         end

         view.selected=(selection[0])
         view.force_cursorpos(old_cursor)
      end
   end

   register.(:goto_current) do
      view.with_lock do
         if index = playlist.current_playing
            view.selected=(index)
            view.center()
         end
      end
   end

   # TODO: mouse?
   view.mouse.on(65536) do view.up(5) end
   view.mouse.on(2097152) do view.down(5) end

   [ICurses::BUTTON1_CLICKED, ICurses::BUTTON2_CLICKED].
      each do |button|
      view.mouse.on(button) do |mevent|
         view.select_from_cursorpos(mevent.y)
      end
   end

   [ICurses::BUTTON1_DOUBLE_CLICKED, ICurses::BUTTON3_CLICKED].each do |btn|
      view.mouse.on(btn) do |mevent|
         view.select_from_cursorpos(mevent.y)
         view_operations.send('playlist.play')
      end
   end
end