Class: Redwood::InboxMode

Inherits:
ThreadIndexMode show all
Defined in:
lib/sup/modes/inbox_mode.rb

Constant Summary

Constants inherited from ThreadIndexMode

ThreadIndexMode::DATE_WIDTH, ThreadIndexMode::LOAD_MORE_THREAD_NUM, ThreadIndexMode::MIN_FROM_WIDTH

Instance Attribute Summary

Attributes inherited from LineCursorMode

#curpos

Attributes inherited from ScrollMode

#botline, #leftcol, #topline

Attributes inherited from Mode

#buffer

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from ThreadIndexMode

#[], #actually_toggle_archived, #actually_toggle_deleted, #actually_toggle_spammed, #actually_toggle_starred, #apply_to_tagged, #cancel_search, #cleanup, #contains_thread?, #edit_labels, #edit_message, #flush_index, #forward, #handle_added_update, #handle_deleted_update, #handle_killed_update, #handle_labeled_update, #handle_location_deleted_update, #handle_simple_update, #handle_single_message_deleted_update, #handle_single_message_labeled_update, #handle_spammed_update, #handle_undeleted_update, #handle_unkilled_update, #handle_updated_update, #join_threads, #jump_to_next_new, #kill, #launch_another_thread, #launch_next_thread_after, #launch_prev_thread_before, #lines, #load_all_threads, #load_n_threads, #load_n_threads_background, #load_threads, #multi_edit_labels, #multi_join_threads, #multi_kill, #multi_read_and_archive, #multi_select, #multi_toggle_archived, #multi_toggle_deleted, #multi_toggle_new, #multi_toggle_spam, #multi_toggle_starred, #multi_toggle_tagged, #read_and_archive, #reload, #reply, #reply_all, #resize, #select, #tag_matching, #toggle_archived, #toggle_deleted, #toggle_new, #toggle_spam, #toggle_starred, #toggle_tagged, #toggle_tagged_all, #undo, #unsaved?, #update

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, load_all_modes, make_name, #name, #pipe_to_process, register_keymap, #resize, #resolve_input, #save_to_file, #unsaved?

Constructor Details

#initializeInboxMode

Returns a new instance of InboxMode.



12
13
14
15
16
# File 'lib/sup/modes/inbox_mode.rb', line 12

def initialize
  super [:inbox, :sent, :draft], { :label => :inbox, :skip_killed => true }
  raise "can't have more than one!" if defined? @@instance
  @@instance = self
end

Class Method Details

.instanceObject

label-list-mode wants to be able to raise us if the user selects the “inbox” label, so we need to keep our singletonness around



29
# File 'lib/sup/modes/inbox_mode.rb', line 29

def self.instance; @@instance; end

Instance Method Details

#archiveObject



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sup/modes/inbox_mode.rb', line 32

def archive
  return unless cursor_thread
  thread = cursor_thread # to make sure lambda only knows about 'old' cursor_thread

  UndoManager.register "archiving thread" do
    thread.apply_label :inbox
    add_or_unhide thread.first
    Index.save_thread thread
  end

  cursor_thread.remove_label :inbox
  hide_thread cursor_thread
  regen_text
  Index.save_thread thread
end

#handle_archived_update(sender, m) ⇒ Object



70
71
72
73
74
# File 'lib/sup/modes/inbox_mode.rb', line 70

def handle_archived_update sender, m
  t = thread_containing(m) or return
  hide_thread t
  regen_text
end

#handle_idle_update(sender, idle_since) ⇒ Object



76
77
78
# File 'lib/sup/modes/inbox_mode.rb', line 76

def handle_idle_update sender, idle_since
  flush_index
end

#handle_unarchived_update(sender, m) ⇒ Object



66
67
68
# File 'lib/sup/modes/inbox_mode.rb', line 66

def handle_unarchived_update sender, m
  add_or_unhide m
end

#is_relevant?(m) ⇒ Boolean

Returns:

  • (Boolean)


18
# File 'lib/sup/modes/inbox_mode.rb', line 18

def is_relevant? m; (m.labels & [:spam, :deleted, :killed, :inbox]) == Set.new([:inbox]) end

#killable?Boolean

Returns:

  • (Boolean)


30
# File 'lib/sup/modes/inbox_mode.rb', line 30

def killable?; false; end

#multi_archive(threads) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/sup/modes/inbox_mode.rb', line 48

def multi_archive threads
  UndoManager.register "archiving #{threads.size.pluralize 'thread'}" do
    threads.map do |t|
      t.apply_label :inbox
      add_or_unhide t.first
      Index.save_thread t
    end
    regen_text
  end

  threads.each do |t|
    t.remove_label :inbox
    hide_thread t
  end
  regen_text
  threads.each { |t| Index.save_thread t }
end

#refine_searchObject



20
21
22
23
24
25
# File 'lib/sup/modes/inbox_mode.rb', line 20

def refine_search
  text = BufferManager.ask :search, "refine inbox with query: "
  return unless text && text !~ /^\s*$/
  text = "label:inbox -label:spam -label:deleted " + text
  SearchResultsMode.spawn_from_query text
end

#statusObject



80
81
82
# File 'lib/sup/modes/inbox_mode.rb', line 80

def status
  super + "    #{Index.size} messages in index"
end