Implemented the menu bar with all the commands
[ttodo.git] / tddoc.h
blob18c29efcee53d28605575c040962b02ab23427dc
1 // Copyright (c) 2006 by Mike Sharov <msharov@users.sourceforge.net>
2 //
3 // tddoc.h
4 //
6 #ifndef TDDOC_H_31474BC008E2711A4DD60C960CFF3439
7 #define TDDOC_H_31474BC008E2711A4DD60C960CFF3439
9 #include "tde.h"
11 /// Global commands for this application.
12 enum {
13 cmd_List = cmd_User,
14 cmd_List_Enter,
15 cmd_List_Leave,
16 cmd_List_Copy,
17 cmd_List_Paste,
18 cmd_List_OldItems,
19 cmd_Item,
20 cmd_Item_New,
21 cmd_Item_Edit,
22 cmd_Item_Delete,
23 cmd_Item_Complete,
24 cmd_Item_Priority,
25 cmd_Item_Priority_Highest,
26 cmd_Item_Priority_High,
27 cmd_Item_Priority_Medium,
28 cmd_Item_Priority_Low,
29 cmd_Item_Priority_Lowest,
32 /// \class CTodoDocument tddoc.h tddoc.h
33 class CTodoDocument : public CDocument {
34 public:
35 typedef set<CTodoEntry> todoset_t;
36 typedef const todolist_t& rctodolist_t;
37 typedef const CTodoEntry& rcentry_t;
38 typedef CTodoEntry::id_t itemid_t;
39 typedef const string& rcfname_t;
40 /// Provides dependency links between todo items.
41 class DLL_LOCAL CDependency {
42 public:
43 typedef const CDependency& rcself_t;
44 public:
45 CDependency (itemid_t item = 0, itemid_t dep = 0) : m_ItemId (item), m_DepId (dep) { }
46 inline bool operator< (rcself_t v) const { return (m_ItemId < v.m_ItemId); }
47 inline bool operator== (rcself_t v) const { return (m_ItemId == v.m_ItemId); }
48 inline void read (istream& is) { is >> m_ItemId >> m_DepId; }
49 inline void write (ostream& os) const { os << m_ItemId << m_DepId; }
50 inline size_t stream_size (void) const { return (stream_size_of (m_ItemId) + stream_size_of (m_DepId)); }
51 public:
52 itemid_t m_ItemId; ///< Item id that has ...
53 itemid_t m_DepId; ///< ... this dependency.
55 enum {
56 f_CompleteVisible = CDocument::f_Last,
57 f_Last
59 public:
60 CTodoDocument (void);
61 virtual void read (istream& is);
62 virtual void write (ostream& os) const;
63 virtual size_t stream_size (void) const;
64 virtual void Open (rcfname_t filename);
65 virtual void Save (void);
66 void UpdateCurrentEntry (rcentry_t e);
67 rcentry_t CurrentEntry (void) const;
68 inline uint32_t Selection (void) const { return (m_Selection.back()); }
69 inline size_t ListSize (void) const { return (m_List.size()); }
70 inline rctodolist_t List (void) const { return (m_List); }
71 inline void SetSelection (uoff_t v) { m_Selection.back() = v; UpdateAllViews(); }
72 inline void ToggleCompleteVisible (void) { SetFlag (f_CompleteVisible, !Flag (f_CompleteVisible)); ReloadList(); }
73 inline size_t NestingDepth (void) const { return (m_Stack.size() - 1); }
74 void SetCurrentEntryPriority (CTodoEntry::EPriority p);
75 void RemoveCurrentEntry (void);
76 void AppendEntry (void);
77 void MarkEntryComplete (void);
78 void EnterCurrentEntry (void);
79 void LeaveCurrentEntry (void);
80 void PasteLinkToEntry (itemid_t id);
81 protected:
82 virtual void OnCommand (cmd_t c);
83 virtual void OnUpdateCommandUI (rcmd_t rc) const;
84 private:
85 typedef vector<CDependency> depmap_t;
86 typedef todolist_t::iterator iitem_t;
87 typedef todolist_t::const_iterator icitem_t;
88 typedef depmap_t::iterator idep_t;
89 typedef depmap_t::const_iterator icdep_t;
90 typedef pair<depmap_t::iterator, depmap_t::iterator> deprange_t;
91 typedef vector<itemid_t> itstack_t;
92 typedef vector<uint32_t> selstack_t;
93 private:
94 void VerifyData (void);
95 void DescendByCwd (void);
96 inline iitem_t FindItem (itemid_t id);
97 inline icitem_t FindItem (itemid_t id) const;
98 inline iitem_t FindCurrentItem (void);
99 inline deprange_t CurrentItemDeps (void);
100 bool ItemNameIsADirectory (rcfname_t name) const;
101 void UpdateEntryDirectoryFlag (iitem_t icuri) const;
102 void UpdateItemProgress (icdep_t first, icdep_t last);
103 void UpdateCompleteStatus (itemid_t dep);
104 inline itemid_t GetNextItemId (void) const;
105 void SetList (itemid_t lid);
106 void ReloadList (void);
107 inline itemid_t ItemId (void) const { return (m_Stack.back()); }
108 bool VisibleOrderLess (itemid_t i1, itemid_t i2) const;
109 void ResortVisibleList (void);
110 private:
111 todoset_t m_Todos; ///< List of all entries.
112 todolist_t m_List; ///< Currently selected list.
113 depmap_t m_Deps; ///< List of dependencies between todos.
114 itstack_t m_Stack; ///< The callstack of the currently active list.
115 selstack_t m_Selection; ///< Index of the selected entry.
118 STD_STREAMABLE (CTodoDocument::CDependency)
120 #endif