From 9de71dd181945acf58498508b27c435e5a5e5d24 Mon Sep 17 00:00:00 2001 From: msharov Date: Mon, 18 Sep 2006 01:18:10 +0000 Subject: [PATCH] Add directory flag to items (as priority) --- elist.cc | 19 +++++++------------ tddoc.cc | 44 +++++++++++++++++++++++++++++++++++++++++++- tddoc.h | 2 ++ tde.h | 5 +---- 4 files changed, 53 insertions(+), 17 deletions(-) diff --git a/elist.cc b/elist.cc index f311cd1..bb4e62e 100644 --- a/elist.cc +++ b/elist.cc @@ -42,8 +42,8 @@ void CTodoList::OnDrawItem (CGC& gc, rcpos_t pos, uint32_t ii) snprintf (progBuf, 5, "%3u%%", e.Progress()); gc.Text (pos[0] + 1, pos[1], e.Progress() ? progBuf : " "); static const EColor c_PriorityColors [2][CTodoEntry::priority_Last] = { - { lightred, yellow, green, cyan, lightblue }, - { lightred, yellow, lightgreen, lightcyan, lightblue } + { white, lightred, yellow, green, cyan, lightblue }, + { white, lightred, yellow, lightgreen, lightcyan, lightblue } }; gc.FgColor (c_PriorityColors [ii == Selection()][e.Priority()]); gc.Text (pos[0] + 6, pos[1], e.Text()); @@ -88,8 +88,7 @@ void CTodoList::OnKey (wchar_t key) if (!bReadOnly) { if (key == 'v' && m_CopiedId) pDoc->PasteLinkToEntry (m_CopiedId); - else if (key == 'n') { - pDoc->SetSelection (pDoc->ListSize() - 1); + else if (key == kv_Insert || key == 'n') { pDoc->AppendEntry(); EditEntry(); } @@ -105,20 +104,16 @@ void CTodoList::OnKey (wchar_t key) // Modification operations on the current entry. if (!bReadOnly) { - if (key == kv_Space) // Toggle complete flag - pDoc->MarkEntryComplete(); - else if (key == kv_Delete || key == 'D') + if (key == kv_Delete || key == 'D') pDoc->RemoveCurrentEntry(); + else if (key == kv_Space) // Toggle complete flag + pDoc->MarkEntryComplete(); else if (key == 'e') EditEntry(); else if (key == 'c') m_CopiedId = pDoc->CurrentEntry().Id(); else if (key >= '1' && key <= '5') - pDoc->SetCurrentEntryPriority (CTodoEntry::EPriority (key - '1')); - else if (key == kv_Insert || key == 'i') { - pDoc->AppendEntry(); - EditEntry(); - } + pDoc->SetCurrentEntryPriority (CTodoEntry::EPriority (key - '1' + 1)); } } diff --git a/tddoc.cc b/tddoc.cc index 9d8a7e5..d2fd2f2 100644 --- a/tddoc.cc +++ b/tddoc.cc @@ -88,6 +88,34 @@ inline CTodoDocument::itemid_t CTodoDocument::GetNextItemId (void) const return (m_Todos.back().Id() + 1); } +/// Returns true if the current item is a directory under the current item. +bool CTodoDocument::ItemNameIsADirectory (rcfname_t name) const +{ + // Build the full path name of the supposed directory. + string dir; + if (Filename()[0] != '/') { + char cwd [PATH_MAX]; + if (!getcwd (VectorBlock (cwd))) + throw libc_exception ("getcwd"); + dir = cwd; + } + dir += '/'; + dir += Filename(); + // Remove the trailing /.todo + dir.erase (dir.iat (dir.rfind ('/')), dir.end()); + // Add the current entry stack (skip the root entry which is empty) + for (itstack_t::const_iterator i = m_Stack.begin()+1; i < m_Stack.end(); ++i) { + icitem_t ii = FindItem (*i); + if (ii->Priority() != CTodoEntry::priority_Directory) + return (false); // The full path must be a directory + dir += '/'; + dir += ii->Text(); + } + dir += '/'; + dir += name; + return (access (dir, F_OK) == 0); +} + //--{ Serialization }--------------------------------------------------- /// Reads the object from stream \p is. @@ -256,11 +284,22 @@ void CTodoDocument::ResortVisibleList (void) //--{ Entry editing }--------------------------------------------------- +/// Verifies that the entry is or is not a directory as it says. +void CTodoDocument::UpdateEntryDirectoryFlag (iitem_t icuri) const +{ + if (ItemNameIsADirectory (icuri->Text())) + icuri->SetPriority (CTodoEntry::priority_Directory); + else if (icuri->Priority() == CTodoEntry::priority_Directory) + icuri->SetPriority (CTodoEntry::priority_Medium); +} + /// Sets the current entry to \p e void CTodoDocument::UpdateCurrentEntry (rcentry_t e) { iitem_t icuri (FindCurrentItem()); - m_List[Selection()] = *icuri = e; + *icuri = e; + UpdateEntryDirectoryFlag (icuri); + m_List[Selection()] = *icuri; SetFlag (f_Changed); ResortVisibleList(); } @@ -288,6 +327,7 @@ void CTodoDocument::AppendEntry (void) { CTodoEntry e (GetNextItemId()); assert (FindItem (e.Id()) == m_Todos.end()); + UpdateEntryDirectoryFlag (&e); // To the complete list m_Todos.insert (e); // And create link to the current entry. @@ -308,6 +348,8 @@ void CTodoDocument::MarkEntryComplete (void) void CTodoDocument::SetCurrentEntryPriority (CTodoEntry::EPriority p) { iitem_t icuri (FindCurrentItem()); + if (icuri->Priority() == CTodoEntry::priority_Directory) + return; icuri->SetPriority (p); SetFlag (f_Changed); ResortVisibleList(); diff --git a/tddoc.h b/tddoc.h index e3b8854..d4c4329 100644 --- a/tddoc.h +++ b/tddoc.h @@ -72,6 +72,8 @@ private: inline icitem_t FindItem (itemid_t id) const; inline iitem_t FindCurrentItem (void); inline deprange_t CurrentItemDeps (void); + bool ItemNameIsADirectory (rcfname_t name) const; + void UpdateEntryDirectoryFlag (iitem_t icuri) const; void UpdateItemProgress (icdep_t first, icdep_t last); void UpdateCompleteStatus (itemid_t dep); inline itemid_t GetNextItemId (void) const; diff --git a/tde.h b/tde.h index a1d2401..d1255e5 100644 --- a/tde.h +++ b/tde.h @@ -9,11 +9,8 @@ /// ToDo list entry. class CTodoEntry { public: - enum EState { - state_Completed, - state_Last - }; enum EPriority { + priority_Directory, priority_Highest, priority_High, priority_Medium, -- 2.11.4.GIT