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 =
100

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

#cleanup, #draw

Methods inherited from ScrollMode

#at_bottom?, #at_top?, #cancel_search!, #col_jump, #col_left, #col_right, #continue_search_in_buffer, #draw, #ensure_mode_validity, #half_page_down, #half_page_up, #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_goto_pos, #search_in_buffer, #search_start_line

Methods inherited from Mode

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

Constructor Details

#initialize(mode = :regular) ⇒ ContactListMode

Returns a new instance of ContactListMode.



30
31
32
33
34
35
36
# File 'lib/sup/modes/contact_list_mode.rb', line 30

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

Instance Method Details

#[](i) ⇒ Object



46
# File 'lib/sup/modes/contact_list_mode.rb', line 46

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

#aliasObject



39
40
41
42
43
# File 'lib/sup/modes/contact_list_mode.rb', line 39

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

#apply_to_taggedObject



60
# File 'lib/sup/modes/contact_list_mode.rb', line 60

def apply_to_tagged; @tags.apply_to_tagged; end

#linesObject



45
# File 'lib/sup/modes/contact_list_mode.rb', line 45

def lines; @text.length; end

#loadObject



108
109
110
111
112
113
114
115
116
117
# File 'lib/sup/modes/contact_list_mode.rb', line 108

def load
  @num ||= (buffer.content_height * 2)
  @user_contacts = ContactManager.contacts_with_aliases
  @user_contacts += (HookManager.run("extra-contact-addresses") || []).map { |addr| Person.from_address addr }
  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



100
101
102
103
104
105
106
# File 'lib/sup/modes/contact_list_mode.rb', line 100

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



62
63
64
65
66
67
# File 'lib/sup/modes/contact_list_mode.rb', line 62

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

#multi_search(people) ⇒ Object



83
84
85
86
87
# File 'lib/sup/modes/contact_list_mode.rb', line 83

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



69
70
71
72
73
74
75
76
# File 'lib/sup/modes/contact_list_mode.rb', line 69

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

#multi_toggle_tagged(threads) ⇒ Object



55
56
57
58
# File 'lib/sup/modes/contact_list_mode.rb', line 55

def multi_toggle_tagged threads
  @tags.drop_all_tags
  update
end

#reloadObject



94
95
96
97
98
# File 'lib/sup/modes/contact_list_mode.rb', line 94

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

#searchObject



89
90
91
92
# File 'lib/sup/modes/contact_list_mode.rb', line 89

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

#selectObject



78
79
80
81
# File 'lib/sup/modes/contact_list_mode.rb', line 78

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

#toggle_taggedObject



48
49
50
51
52
53
# File 'lib/sup/modes/contact_list_mode.rb', line 48

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