7 //----------------------------------------------------------------------
9 /// Constructs a list displaying \p rctdl
10 CTodoList::CTodoList (void)
16 /// Sets the list to display.
17 void CTodoList::SetList (pctodolist_t pl
)
21 SetListSize (pl
->size());
24 /// Sets internal variables when the document is updated.
25 void CTodoList::OnUpdate (void)
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
);
38 const CTodoEntry
& e ((*m_pTodos
)[ii
]);
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());
67 else if (key
== kv_Left
|| key
== 'h')
68 Document()->LeaveCurrentEntry();
70 Document()->LoadData();
72 Document()->ToggleCompleteVisible();
73 else if (key
== 'S') {
74 Document()->SaveData();
76 } else if (key
== 'n') {
77 Document()->SetSelection (Document()->ListSize() - 1);
78 Document()->AppendEntry();
82 if (Document()->Selection() >= Document()->ListSize())
85 if (key
== kv_Space
) // Toggle complete flag
86 Document()->MarkEntryComplete();
87 else if (key
== kv_Delete
|| key
== 'D')
88 Document()->RemoveCurrentEntry();
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();