Changed file format to include dependency table.
[ttodo.git] / elist.cc
blob795458b53fd10394b778c62117104528484c16ed
1 // elist.cc
2 //
4 #include "elist.h"
6 //----------------------------------------------------------------------
8 /// Constructs a list displaying \p rctdl
9 CTodoList::CTodoList (void)
10 : CListbox ()
12 SetList (NULL);
15 /// Sets the list to display.
16 void CTodoList::SetList (pctodolist_t pl)
18 m_pTodos = pl;
19 if (m_pTodos)
20 SetListSize (pl->size());
23 /// Sets internal variables when the document is updated.
24 void CTodoList::OnUpdate (void)
26 CListbox::OnUpdate();
27 SetList (&Document()->List());
28 SetSelection (Document()->Selection());
31 /// Draws list item \p ii at \p pos onto \p gc.
32 void CTodoList::OnDrawItem (CGC& gc, rcpos_t pos, uint32_t ii)
34 CListbox::OnDrawItem (gc, pos, ii);
35 if (!m_pTodos)
36 return;
37 string line;
38 const CTodoEntry& e ((*m_pTodos)[ii]);
39 line.format ("%c%3u%% %s", "+ "[!e.SublistId()], e.Progress(), e.Text().c_str());
40 gc.Text (pos, line);
43 /// Causes the current entry to be edited.
44 inline void CTodoList::EditEntry (void)
46 SetFlag (flag_OffersFocus);
49 /// Processes keystroke \p key.
50 void CTodoList::OnKey (wchar_t key)
52 CListbox::OnKey (key);
54 if (Document()->Selection() != Selection())
55 Document()->SetSelection (Selection());
57 if (key == 'q')
58 Close();
59 else if (key == 'S') {
60 Document()->SaveData();
61 Commit();
62 } else if (key == 'R')
63 Document()->LoadData();
64 else if (key == 'n') {
65 Document()->SetSelection (Document()->ListSize() - 1);
66 Document()->AppendEntry();
67 EditEntry();
70 if (Document()->Selection() >= Document()->ListSize())
71 return;
73 if (key == kv_Space) // Toggle complete flag
74 Document()->MarkEntryComplete();
75 else if (key == kv_Delete || key == 'D')
76 Document()->RemoveCurrentEntry();
77 else if (key == kv_Enter || key == 'e')
78 EditEntry();
79 else if (key == kv_Insert || key == 'i') {
80 Document()->AppendEntry();
81 EditEntry();