Use ccache
[ttodo.git] / elist.cc
blob11ca2ead752b467c3d1ec38c7d8b6069f40fce5b
1 // elist.cc
2 //
4 #include "elist.h"
5 #include <stdio.h>
7 //----------------------------------------------------------------------
9 /// Constructs a list displaying \p rctdl
10 CTodoList::CTodoList (void)
11 : CListbox ()
13 SetList (NULL);
16 /// Sets the list to display.
17 void CTodoList::SetList (pctodolist_t pl)
19 m_pTodos = pl;
20 if (m_pTodos)
21 SetListSize (pl->size());
24 /// Sets internal variables when the document is updated.
25 void CTodoList::OnUpdate (void)
27 CListbox::OnUpdate();
28 SetList (&Document()->List());
29 SetSelection (Document()->Selection());
32 /// Draws list item \p ii at \p pos onto \p gc.
33 void CTodoList::OnDrawItem (CGC& gc, rcpos_t pos, uint32_t ii)
35 CListbox::OnDrawItem (gc, pos, ii);
36 if (!m_pTodos)
37 return;
38 const CTodoEntry& e ((*m_pTodos)[ii]);
39 char progBuf [5];
40 gc.Char (pos, "+ "[!e.HasSublist()]);
41 snprintf (progBuf, 5, "%3u%%", e.Progress());
42 gc.Text (pos[0] + 1, pos[1], e.Progress() ? progBuf : " ");
43 static const EColor c_PriorityColors [2][CTodoEntry::priority_Last] = {
44 { lightred, yellow, green, cyan, lightblue },
45 { lightred, yellow, lightgreen, lightcyan, lightblue }
47 gc.FgColor (c_PriorityColors [ii == Selection()][e.Priority()]);
48 gc.Text (pos[0] + 6, pos[1], e.Text());
51 /// Causes the current entry to be edited.
52 inline void CTodoList::EditEntry (void)
54 SetFlag (flag_OffersFocus);
57 /// Processes keystroke \p key.
58 void CTodoList::OnKey (wchar_t key)
60 CListbox::OnKey (key);
62 if (Document()->Selection() != Selection())
63 Document()->SetSelection (Selection());
65 if (key == 'q')
66 Close();
67 else if (key == kv_Left || key == 'h')
68 Document()->LeaveCurrentEntry();
69 else if (key == 'R')
70 Document()->LoadData();
71 else if (key == 'o')
72 Document()->ToggleCompleteVisible();
73 else if (key == 'S') {
74 Document()->SaveData();
75 Commit();
76 } else if (key == 'n') {
77 Document()->SetSelection (Document()->ListSize() - 1);
78 Document()->AppendEntry();
79 EditEntry();
82 if (Document()->Selection() >= Document()->ListSize())
83 return;
85 if (key == kv_Space) // Toggle complete flag
86 Document()->MarkEntryComplete();
87 else if (key == kv_Delete || key == 'D')
88 Document()->RemoveCurrentEntry();
89 else if (key == 'e')
90 EditEntry();
91 else if (key >= '1' && key <= '5')
92 Document()->SetCurrentEntryPriority (CTodoEntry::EPriority (key - '1'));
93 else if (key == kv_Right || key == 'l' || key == kv_Enter)
94 Document()->EnterCurrentEntry();
95 else if (key == kv_Insert || key == 'i') {
96 Document()->AppendEntry();
97 EditEntry();