7 //----------------------------------------------------------------------
9 const CTodoList::SCommandKey
CTodoList::c_CmdKeys
[] = {
10 { 'q', cmd_File_Quit
},
11 { 'S', cmd_File_Save
},
12 { 'l', cmd_List_Enter
},
13 { kv_Enter
, cmd_List_Enter
},
14 { kv_Right
, cmd_List_Enter
},
15 { kv_Left
, cmd_List_Leave
},
16 { 'h', cmd_List_Leave
},
17 { 'o', cmd_List_OldItems
},
18 { 'c', cmd_List_Copy
},
19 { 'v', cmd_List_Paste
},
20 { kv_Insert
, cmd_Item_New
},
21 { 'n', cmd_Item_New
},
22 { kv_Delete
, cmd_Item_Delete
},
23 { 'D', cmd_Item_Delete
},
24 { kv_Space
, cmd_Item_Complete
},
25 { 'e', cmd_Item_Edit
},
26 { '1', cmd_Item_Priority_Highest
},
27 { '2', cmd_Item_Priority_High
},
28 { '3', cmd_Item_Priority_Medium
},
29 { '4', cmd_Item_Priority_Low
},
30 { '5', cmd_Item_Priority_Lowest
}
33 /// Constructs a list displaying \p rctdl
34 CTodoList::CTodoList (void)
41 /// Sets the list to display.
42 void CTodoList::SetList (pctodolist_t pl
)
44 SetCommandKeys (VectorBlock (c_CmdKeys
));
47 SetListSize (pl
->size());
50 /// Sets internal variables when the document is updated.
51 void CTodoList::OnUpdate (void)
54 SetList (&Document()->List());
55 SetSelection (Document()->Selection());
58 /// Draws list item \p ii at \p pos onto \p gc.
59 void CTodoList::OnDrawItem (CGC
& gc
, rcpos_t pos
, uint32_t ii
)
61 CListbox::OnDrawItem (gc
, pos
, ii
);
64 const CTodoEntry
& e ((*m_pTodos
)[ii
]);
66 gc
.Char (pos
, "+ "[!e
.HasSublist()]);
67 snprintf (progBuf
, 5, "%3u%%", e
.Progress());
68 gc
.Text (pos
[0] + 1, pos
[1], e
.Progress() ? progBuf
: " ");
69 static const EColor c_PriorityColors
[2][CTodoEntry::priority_Last
] = {
70 { white
, lightred
, yellow
, green
, cyan
, lightblue
},
71 { white
, lightred
, yellow
, lightgreen
, lightcyan
, lightblue
}
73 gc
.FgColor (c_PriorityColors
[ii
== Selection()][e
.Priority()]);
74 gc
.Text (pos
[0] + 6, pos
[1], e
.Text());
77 /// Causes the current entry to be edited.
78 inline void CTodoList::EditEntry (void)
80 SetFlag (f_OffersFocus
);
83 /// Processes keystroke \p key.
84 void CTodoList::OnKey (wchar_t key
)
86 CListbox::OnKey (key
);
87 pdoc_t pDoc
= Document();
88 if (pDoc
->Selection() != Selection())
89 pDoc
->SetSelection (Selection());
92 /// Executes command \p c.
93 void CTodoList::OnCommand (cmd_t c
)
95 CListbox::OnCommand (c
);
96 pdoc_t pDoc
= Document();
98 case cmd_Item_New
: pDoc
->AppendEntry();
99 case cmd_Item_Edit
: EditEntry(); break;
100 case cmd_List_Copy
: m_CopiedId
= pDoc
->CurrentEntry().Id(); break;
101 case cmd_List_Paste
: pDoc
->PasteLinkToEntry (m_CopiedId
); break;
105 void CTodoList::OnUpdateCommandUI (rcmd_t rc
) const
107 CListbox::OnUpdateCommandUI (rc
);
108 pcdoc_t pDoc
= Document();
109 const bool bHaveSelection (pDoc
->Selection() < pDoc
->ListSize());
110 const bool bReadOnly (Flag (f_ReadOnly
));
113 case cmd_Item_New
: break;
114 case cmd_Item_Edit
: bActive
= bHaveSelection
&& !bReadOnly
; break;
115 case cmd_List_Copy
: bActive
= bHaveSelection
; break;
116 case cmd_List_Paste
: bActive
= !bReadOnly
&& m_CopiedId
; break;
118 bActive
= !(rc
.flags
& SCmd::cf_Grayed
);
121 rc
.SetFlag (SCmd::cf_Grayed
, !bActive
);