Class: Redwood::ContactListMode

Inherits:
LineCursorMode show all
Includes:
CanAliasContacts
Defined in:
lib/sup/modes/contact-list-mode.rb

Constant Summary collapse

LOAD_MORE_CONTACTS_NUM =
10

Constants inherited from ScrollMode

ScrollMode::COL_JUMP

Instance Attribute Summary

Attributes inherited from LineCursorMode

#curpos

Attributes inherited from ScrollMode

#botline, #leftcol, #status, #topline

Attributes inherited from Mode

#buffer

Instance Method Summary collapse

Methods included from CanAliasContacts

#alias_contact

Methods inherited from LineCursorMode

#draw

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #in_search?, #jump_to_col, #jump_to_end, #jump_to_left, #jump_to_line, #jump_to_start, #line_down, #line_up, #page_down, #page_up, #resize, #rightcol, #search_goto_line, #search_in_buffer, #search_start_line

Methods inherited from Mode

#blur, #cancel_search!, #cleanup, #draw, #focus, #handle_input, #help_text, #in_search?, #killable?, load_all_modes, make_name, #name, register_keymap, #resize, #resolve_input, #save_to_file, #status

Constructor Details

#initialize(mode = :regular) ⇒ ContactListMode

Returns a new instance of ContactListMode.



26
27
28
29
30
31
32
# File 'lib/sup/modes/contact-list-mode.rb', line 26

def initialize mode=:regular
  @mode = mode
  @tags = Tagger.new self
  @num = nil
  @text = []
  super()
end

Instance Method Details

#[](i) ⇒ Object



42
# File 'lib/sup/modes/contact-list-mode.rb', line 42

def [] i; @text[i]; end

#aliasObject



35
36
37
38
39
# File 'lib/sup/modes/contact-list-mode.rb', line 35

def alias
  p = @contacts[curpos] or return
  alias_contact p
  update
end

#apply_to_taggedObject



56
# File 'lib/sup/modes/contact-list-mode.rb', line 56

def apply_to_tagged; @tags.apply_to_tagged; end

#linesObject



41
# File 'lib/sup/modes/contact-list-mode.rb', line 41

def lines; @text.length; end

#loadObject



104
105
106
107
108
109
110
111
112
# File 'lib/sup/modes/contact-list-mode.rb', line 104

def load
  @num ||= buffer.content_height
  @user_contacts = ContactManager.contacts
  num = [@num - @user_contacts.length, 0].max
  BufferManager.say("Loading #{num} contacts from index...") do
    recentc = Index.load_contacts AccountManager.user_emails, :num => num
    @contacts = (@user_contacts + recentc).sort_by { |p| p.sort_by_me }.uniq
  end
end

#load_in_backgroundObject



96
97
98
99
100
101
102
# File 'lib/sup/modes/contact-list-mode.rb', line 96

def load_in_background
  Redwood::reporting_thread("contact manager load in bg") do
    load
    update
    BufferManager.draw_screen
  end
end

#load_more(num = LOAD_MORE_CONTACTS_NUM) ⇒ Object



58
59
60
61
62
63
# File 'lib/sup/modes/contact-list-mode.rb', line 58

def load_more num=LOAD_MORE_CONTACTS_NUM
  @num += num
  load
  update
  BufferManager.flash "Added #{num.pluralize 'contact'}."
end

#multi_search(people) ⇒ Object



79
80
81
82
83
# File 'lib/sup/modes/contact-list-mode.rb', line 79

def multi_search people
  mode = PersonSearchResultsMode.new people
  BufferManager.spawn "search for #{people.map { |p| p.name }.join(', ')}", mode
  mode.load_threads :num => mode.buffer.content_height
end

#multi_select(people) ⇒ Object



65
66
67
68
69
70
71
72
# File 'lib/sup/modes/contact-list-mode.rb', line 65

def multi_select people
  case @mode
  when :regular
    mode = ComposeMode.new :to => people
    BufferManager.spawn "new message", mode
    mode.edit_message
  end
end

#multi_toggle_tagged(threads) ⇒ Object



51
52
53
54
# File 'lib/sup/modes/contact-list-mode.rb', line 51

def multi_toggle_tagged threads
  @tags.drop_all_tags
  update
end

#reloadObject



90
91
92
93
94
# File 'lib/sup/modes/contact-list-mode.rb', line 90

def reload
  @tags.drop_all_tags
  @num = nil
  load
end

#searchObject



85
86
87
88
# File 'lib/sup/modes/contact-list-mode.rb', line 85

def search
  p = @contacts[curpos] or return
  multi_search [p]
end

#selectObject



74
75
76
77
# File 'lib/sup/modes/contact-list-mode.rb', line 74

def select
  p = @contacts[curpos] or return
  multi_select [p]
end

#toggle_taggedObject



44
45
46
47
48
49
# File 'lib/sup/modes/contact-list-mode.rb', line 44

def toggle_tagged
  p = @contacts[curpos] or return
  @tags.toggle_tag_for p
  update_text_for_line curpos
  cursor_down
end