Click here to Skip to main content
16,021,687 members
Articles / Desktop Programming / MFC

ToDoList 8.2 - An Effective and Flexible Way to Keep on Top of Your Tasks

Rate me:
Please Sign up or sign in to vote.
4.85/5 (2,420 votes)
17 Sep 2023Eclipse12 min read 71.7M   441.6K   3.6K   32.8K
A hierarchical task manager with native XML support for custom reporting

Downloads


3rd Party

Note: Please contact the respective authors directly with comments and questions

todolist2/CP_screenshot2.png

Latest Update (8.2 Feature Release)

  • Added 'Markdown' comments
  • Added highlighting of 'Circular Dependencies'
  • Added 'Calculations' to 'Custom Attributes'
  • Added 'Custom Date' attributes to 'Week Planner'
  • Added 'Custom Date' attributes to 'Calendar'
  • Added 'Drag and Drop' from 'Explorer' to 'Spreadsheet' comments
  • Added dedicated toolbar button for creating 'ToDoLIst UDTs'
  • Added 'Recurrence' options to 'Filter Bar'
  • Added '-mp' command line switch to use first decryption password as a 'Master Password'
  • Added toolbar button to 'Find Tasks' dialog to allow closing when docked
  • Added 'Calendar' preferences to show 'Week Number' in cell header
  • Added 'Straight Line Connections' option to 'Mind Map'
  • Added 'Completed Date' to 'Attribute Inheritance'
  • Improved layout of overlapping 'Calendar' tasks
  • Improved handling of 'Due Task Notification' hyperlinks
  • Improved 'Time Tracker' task selection
  • Improved 'Edit Dependency' task selection
  • Improved performance of 'flat' tasklists

Introduction

You know how it is - you start work on one project and halfway through, you find one or two side-projects crop up that have to be solved before you can continue on the original project.

This is one such project with the added twist that it too started its life as a side-project. Here's what happened:

<Cue wavy screen effect>

I can only imagine that the planets must have been in (mis-)alignment or something, because at one point a few months ago, I was suddenly fielding emails on four or five separate articles I had previously submitted to CodeProject, some asking for features and others for bug fixes.

Foolishly or otherwise, I largely agreed with all the points raised, and subsequently found myself with fourteen or fifteen separate issues to resolve.

The situation was also made worse because I was trying to use CodeProject to keep track of all the things I had agreed to do, meaning that I had to continuously trawl the comments section of each article to remind myself of what I was supposed to be working on.

It even got to the stage where I was worrying that I'd fail to deliver on something - silly I know, but there you are!

Keeping a list on paper was a definite step in the right direction, but since I do all my coding on the same machine, it seemed somewhat inelegant, and anyway, we all know what happens to crucial bits of paper left lying around on desks and such.

The next step was to hunt around on the web for a tool to meet the following requirements:

  • Simple interface
  • Support for hierarchical data
  • Numbered items/subitems
  • Open file format
  • Freeware

Simple, huh! not!

I will admit that I did not spend weeks searching, but I am still surprised at the general lack of software matching my needs.

On reflection, I think that the reason may be simple: people are so used to commercial software being 'feature-rich' that when they come to design software themselves, they (not unreasonably) think they too need to cram as much in as possible, often leading to software where a lot of essential functionality is hidden away in the menu bar.

So, surprise, surprise, I decided to write something myself.

However, it's fair to say that I did not originally intend to post it on CodeProject and am only really doing so because I had a heap of fun solving some very interesting problems and these are what I think make it worth it.

Using the Software

There's really very little I need to say here since every feature/function is explicitly visible in the interface.

Nevertheless, the following list of basic capabilities and omissions may go someway to answering any questions that arise:

  • Files are stored in XML format with .xml file extension.
  • Trying to load a non-tasklist file will generally fail (unless you read the code to see how to circumvent it).
  • The number of items/subitems is limited only by memory (although performance may be the deciding factor before you exhaust memory).
  • Marking a parent item as 'done' will also gray-out child items, but they are not disabled or automatically marked as 'done'.
  • An ellipsis (...) indicates that an item has sub-items.
  • All items can be expanded or collapsed (by double-clicking).
  • Top-level items and sub-items are created using different toolbar buttons.
  • There are task-specific context-menus.
  • The previously open tasklists are re-opened on startup.
  • The tasklist is automatically saved when closing the software or minimizing it to the system tray.
  • The priority of a task is shown as a grayscale box to the left of the item.

Points of Interest

Here's where we come to the side-projects I was talking about, the first two of which I intend to work up into follow-up articles.

They are:

  1. The 'ordered' tree control, which incorporates a non-client gutter for displaying the item numbers.

    The idea stemmed from research I did into alternative designs for a tree-list control, which did not solve it by creating a hybrid control incorporating a tree and a list.

    The hybrid control seems such an obvious solution that I suspect few people have stopped to question it, but it has still always struck me as looking far too much like hard work to be truly elegant ('square pegs' and 'round holes' spring to mind).

    One possible idea is to implement the 'list' portion entirely in the non-client area of the tree. I.e., shift the right hand client edge to the left and then render the list portion in the resulting non-client area.

    Whilst I've yet to get round to building a proof of concept, it was nevertheless this ongoing mental debate which prompted me to try to solve the requirement for numbered items and subitems by rendering the item/subitem numbers in the non-client area.

    Without going into too much detail (as this will subsequently be an article of its own), this is how I got it to work:

    • Handle TVM_INSERTITEM and TVM_DELETEITEM to know exactly when items are added and removed.
    • In these handlers recalculate the width of the gutter required to display the widest 'dotted' item/subitem number. (Note: this is not necessarily simply the deepest subitem.)
    • If the required gutter width changes, call SetWindowPos(NULL, 0, 0, 0, 0, SWP_FRAMECHANGED | SWP_NOMOVE | SWP_NOSIZE | SWP_NOZORDER) to force Windows to recalculate the non-client area of the control.
    • Handle WM_NCCALCSIZE when it does, and offset the left border by the required gutter width.
    • Handle WM_NCPAINT for painting the numbers.

    This is necessarily an over-simplification, but it captures the essence of the solution, and all that essentially remains is lots of fiddling about to ensure the non-client area gets redrawn at the the right times to stay synchronized with the client area.

  2. Embedding .RC control definition data directly in a .cpp file to break the dependency on binary resources (a.k.a. 'Runtime Dialogs').

    This is an idea that has been floating about for quite some time and which has only recently gelled into a workable solution.

    The problem, put simply, is that if you want to take advantage of the resource editor in Visual Studio (and who doesn't), then you very quickly find yourself stuck with having to load dialog templates from resources compiled into the binary file.

    This further means that if you want to make use of a dialog across multiple projects, then either you need to copy and paste the dialog template between project .RC files, or you need to build the dialog into a DLL from which it can be accessed.

    'Runtime Dialogs' (a snappy title I coined myself) is a solution that neatly sidesteps both the nuisance of copying dialog resources between resource files and the extra work (and maintenance) involved in packaging dialogs in DLLs.

    And it works like this:

    • First, you design your dialog template in the resource editor, create a CDialog derived class using class wizard, and wire up all the controls just as you normally would.
    • Next, you #include "runtimedlg.h" and change all instances of CDialog to CRuntimeDlg.
    • Then, you cut and paste the control definition section from the appropriate section in the .RC file and embed it directly in the dialog's .cpp file as a static string (with a bit of tweaking to handle double quotes and such like).
    • Finally, in the constructor of your dialog, you simply call CRuntimeDlg::AddRCControls(...) passing the control definitions as a string.
    • And CRuntimeDlg takes care of the rest including, if required, auto-sizing the dialog to suit the control layout.

    I'm certainly not suggesting that this is a 'win-win' solution for all situations but it certainly has merits in its closer coupling of dialog template to dialog code which makes sharing dialogs across multiple projects a breeze.

    P.S.: In case it's not clear here, I used CRuntimeDlg to create CToDoCtrl which encapsulates the ordered tree together with the priority, date and comments controls as a single simple-to-instantiate control.

    I'm also proposing to use them in the .NET port of my ProjectZip add-in for VC6.

  3. Embedding the XML file in a web page.

    This is possibly the most satisfying aspect of the whole project because it was completely unexpected.

    What I mean is that, until recently, my knowledge of DOM and XMLDOM was virtually non-existent, as it's only since I've become more interested in the presentation of AbstractSpoon that I've been forced to get to grips with the various implementations of DOM and XMLDOM out there.

    I'm pleased to say that the code on my site works under IE 6.0, Netscape 7.1, and Mozilla, although custom code was required to achieve this.

Generic MFC Classes that may prove Useful to You

The following table lists a wide range of utility classes written for this project. They can all be included in any MFC project provided you include any class dependencies too. Feel free to ask any questions relating to these specific classes and how to use them.

Class Name

Description

Class Dependencies
(apart from MFC)

CAboutDlg

Customizable "About...' dialog not requiring a dialog resource. Supports html encoded text

CRuntimeDlg, CRCCtrlParser

CAutoComboBox

Adds only unique items to the drop list and shuffles the list so that the last added item is at the top

CHoldRedraw

CAutoFlag

Encapsulates the setting and unsetting of a boolean variable thru the lifetime of the class instance

 

CColorButton

Non-ownerdraw button that displays the selected colour on the button face and displays the colour dialog when clicked

CEnColorDialog

CColorComboBox

Owner-draw combobox for displaying and selecting user defined colours

 

CDateHelper

Encapsulation of various rountines for calculating date spans and for formatting

 

CDeferWndMove

Encapsulation of the Win32 API

 

CDialogHelper

Re-implementation of the CDialog DDX/DDV rountines to avoid the MFC error messages when the user clears a number edit (for instance)

 

CDlgUnits

Encapsulates the MapDialogRect Win32 API

 

CDockManager

Class for managing the docking of one popup window to another.

*CSubclassWnd, CHoldRedraw, CAutoFlag

CDriveInfo

Encapsulates various rountines for querying about drives, files and disk space

 

CEnBitmap

Adds support to CBitmap for loading non-bmp files and resources.

 

CEnBitmapEx, CColorReplacer, CImageBlurrer, CImageColorizer, CImageContraster, CImageEmbosser, CImageFlipper, CImageGrayer, CImageLightener, CImageNegator, CImageResizer, CImageRotator, CImageSharpener, CImageShearer, CImageSysColorMapper, CImageTinter

Adds image manipulation funationality to CEnBitmap

CEnBitmap

CEnColorDialog

Adds saving and restoring of custom colours to CColorDialog

 

CEnCommandLineInfo

Adds functions for extracting and querying commandline switches

 

CEnEdit

Adds user-defined button capabilities to CEdit

CMaskEdit, CThemed, CDlgUnits

CEnToolBar

Adds support for using alternative resource or file images

 

CFileEdit

Adds buttons for browsing and displaying the file represented by the text in the edit control. Also shows the file's small icon.

CEnEdit, CFolderDialog, CMaskEdit, CDlgUnits, CThemed, CSysImageList

CHoldRedraw

Encapsulates WM_SETREDRAW

 

CHotKeyCtrlEx

Fixes a number of behavioural problems including the handling of certain keypresses

 

CHotTracker

Tracks the cursor movement over user-defined windows and posts event messages as necessary

*CSubclassWnd,

CLimitSingleInstance

Provides simple method to detect if another instance of an app is running

 

CMaskEdit

Adds simple character masking to CEdit

 

CNcGutter

Allows the UI of standard windows controls to be extended by supporting any number of columns to be added to the non-client area of the window. Favours tabular controls like lists, trees, etc

*CSubclassWnd, CHoldRedraw, CThemed, CDlgUnits

COrderedTreeCtrl

CTreeCtrl implementation of CNcGutter displaying a single column showing the hierarchical position of each tree item in '1.2.3.4' notation.

CHoldRedraw, CThemed

CPasswordDialog

Very simple password dialog not requiring a dialog resource

CRuntimeDlg, CRCCtrlParser

CPropertyPageHost

Simpler replacement for CPropertySheet allowing easier creation as a child window

 

CRCCtrlParser

Used by CRuntimeDlg for parsing dialog resource-like text

 

CRuntimeDlg

Adds support to CDialog for building dialogs at runtime ie. dialogs do not require a dialog resource

CRCCtrlParser

CShortcutManager

Class for handling application keyboard shortcuts.

*CSubclassWnd, CWinClasses

CSpellCheckDlg

Spellcheck dialog not requiring a dialog resource, which interfaces with ISpellCheck (interface to Open Office dictionaries)

CRuntimeDlg, CRCCtrlParser, ISpellCheck

CSysImageList

Encapsulates the Windows system image list (file/folder images)

 

CTabCtrlEx

Adds post rendering callback for the tabs without using owner-draw

 

CThemed

Encapsulates themed (XP) and non-themed (the rest) drawing of windows controls

 

CTimeEdit

Adds a button for specifying time units and provided routines for converting time to and from different time units

CEnEdit, CMaskEdit, CThemed, CDlgUnits

CToolbarHelper

Adds support for dialog toolbar tooltips, multiline tooltips and dropbuttons with menus

*CSubclassWnd, CEnBitmap, CEnBitmapEx

CTrayIcon

Encapsulates the Shell_NotifyIcon Win32 API. Also provides balloon tips and animation

*CSubclassWnd,

CUrlRichEditCtrl

Adds support for recognizing urls, clicking them and setting custom url callbacks

 

CWinClasses

Encapsulates the ::GetClassName Win32 functions

 

CXmlFile, CXmlItem

Non-Unicode class for reading and writing xml files

 

CXmlFileEx

Adds encryption capabilities to CXmlFile

CXmlFile, IEncryption

* CSubclassWnd was originally written by Paul DiLascia for MSJ magazine. The version I use has been heavily extended to suit my specific needs. The classes that depend on it here need this extended version.

Further Work

Whilst this tool was originally intended for my personal use only, it is now a 'community' project, so if you find it useful and want to make suggestions for enhancements or bug fixes, please post to our Google Group.

History

  • History now held here
  • 1.1-7.1 (removed by .dan.g.)
  • 1.0 (4 Nov 2003)

License

This article, along with any associated source code and files, is licensed under The Eclipse Public License 1.0


Written By
Software Developer Maptek
Australia Australia
.dan.g. is a naturalised Australian and has been developing commercial windows software since 1998.

Comments and Discussions

 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
.dan.g.10-Aug-22 15:04
professional.dan.g.10-Aug-22 15:04 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
Hugo González Castro10-Aug-22 15:20
professionalHugo González Castro10-Aug-22 15:20 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
.dan.g.17-Aug-22 22:14
professional.dan.g.17-Aug-22 22:14 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
Hugo González Castro18-Aug-22 3:34
professionalHugo González Castro18-Aug-22 3:34 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
Hugo González Castro24-Aug-22 2:20
professionalHugo González Castro24-Aug-22 2:20 
GeneralRe: How can I get the formatted text of the comments of a task? Pin
.dan.g.24-Aug-22 13:46
professional.dan.g.24-Aug-22 13:46 
QuestionBroken export to MyLifeOrganized (and code to fix it) Pin
Hugo González Castro6-Aug-22 13:01
professionalHugo González Castro6-Aug-22 13:01 
AnswerRe: Broken export to MyLifeOrganized (and code to fix it) Pin
Hugo González Castro9-Aug-22 12:50
professionalHugo González Castro9-Aug-22 12:50 
I have improved the export to MyLifeOrganized, now I export:

- Task colors
- Flag state
- Completion state
- Comments in plain text and in HTML format! RTF / rich text comments are also exported in HTML
- Link or multiple links
- Task dependency or multiple dependencies
- First level task exported in bold, like in ToDoList
- Folders and projects: These are not available in ToDoList, but I set a criteria for setting those in MyLifeOrganized
- Fixed importance scale
- Fixed dates


Here it is the final code (that might apply to ToDoList 8.1 only, later versions might include Dan's improvements):
C++
// MLOExporter.h: interface for the CMLOExporter class.
//
//////////////////////////////////////////////////////////////////////

bool SupportsHtmlComments() const { return true; }

C++
// MLOExporter.cpp: implementation of the CMLOExporter class.
//
//////////////////////////////////////////////////////////////////////

#include "stdafx.h"
#include "MLOImport.h"
#include "MLOExporter.h"

#include "..\shared\xmlfileex.h"
#include "..\shared\datehelper.h"
#include "..\shared\timehelper.h"
#include "..\shared\misc.h"

#include "..\3rdParty\T64Utils.h"

#ifdef _DEBUG
#undef THIS_FILE
static char THIS_FILE[]=__FILE__;
#define new DEBUG_NEW
#endif

//////////////////////////////////////////////////////////////////////
// Construction/Destruction
//////////////////////////////////////////////////////////////////////

CMLOExporter::CMLOExporter()
{
	m_icon.Load(IDI_MYLIFEORGANISED);
}

CMLOExporter::~CMLOExporter() 
{
}

void CMLOExporter::SetLocalizer(ITransText* /*pTT*/)
{
	//CLocalizer::Initialize(pTT);
}

IIMPORTEXPORT_RESULT CMLOExporter::Export(const ITaskList* pSrcTaskFile, LPCTSTR szDestFilePath, DWORD /*dwFlags*/, IPreferences* /*pPrefs*/, LPCTSTR /*szKey*/)
{
	const ITASKLISTBASE* pTasks = GetITLInterface<ITASKLISTBASE>(pSrcTaskFile, IID_TASKLISTBASE);

	if (pTasks == NULL)
	{
		ASSERT(0);
		return IIER_BADINTERFACE;
	}
	
	CXmlFile fileDest(_T("MyLifeOrganized-xml"));
	fileDest.SetXmlHeader(DEFAULT_UTF8_HEADER);
	fileDest.AddItem(_T("ver"), _T("1.2"));

	// export tasks
	CXmlItem* pXITasks = fileDest.AddItem(_T("TaskTree"));
	
	if (!ExportTask(pTasks, pSrcTaskFile->GetFirstTask(), pXITasks, TRUE))
		return IIER_SOMEFAILED;
	
	// export resource allocations
	ExportPlaces(pTasks, fileDest.Root());
	
	// save result
	if (!fileDest.Save(szDestFilePath, SFEF_UTF8WITHOUTBOM))
		return IIER_BADFILE;

	return IIER_SUCCESS;
}

IIMPORTEXPORT_RESULT CMLOExporter::Export(const IMultiTaskList* pSrcTaskFile, LPCTSTR szDestFilePath, DWORD /*dwFlags*/, IPreferences* /*pPrefs*/, LPCTSTR /*szKey*/)
{
	CXmlFile fileDest(_T("MyLifeOrganized-xml"));
	fileDest.SetXmlHeader(DEFAULT_UTF8_HEADER);
	fileDest.AddItem(_T("ver"), _T("1.2"));

	// export tasks
	CXmlItem* pXITasks = fileDest.AddItem(_T("TaskTree"));
	
	for (int nTaskList = 0; nTaskList < pSrcTaskFile->GetTaskListCount(); nTaskList++)
	{
		const ITASKLISTBASE* pTasks = GetITLInterface<ITASKLISTBASE>(pSrcTaskFile->GetTaskList(nTaskList), IID_TASKLISTBASE);
		
		if (pTasks == NULL)
		{
			ASSERT(0);
			return IIER_BADINTERFACE;
		}

		// export tasks
		if (!ExportTask(pTasks, pTasks->GetFirstTask(), pXITasks, TRUE))
			return IIER_SOMEFAILED;
			
		// export resource allocations
		ExportPlaces(pTasks, fileDest.Root());
	}
	
	// save result
	if (!fileDest.Save(szDestFilePath, SFEF_UTF8WITHOUTBOM))
		return IIER_BADFILE;

	return IIER_SUCCESS;
}

bool CMLOExporter::ExportTask(const ITASKLISTBASE* pSrcTaskFile, HTASKITEM hTask, 
							  CXmlItem* pXIDestParent, BOOL bAndSiblings)
{
	if (!hTask)
		return true;
	
	// create a new item corresponding to pXITask at the dest
	CXmlItem* pXIDestItem = pXIDestParent->AddItem(_T("TaskNode"));
	
	if (!pXIDestItem)
		return false;
	
	// copy across the appropriate attributes
	pXIDestItem->AddItem(_T("Caption"), pSrcTaskFile->GetTaskTitle(hTask));
	
	// priority
	int nPriority = pSrcTaskFile->GetTaskPriority(hTask, FALSE);
	int nImportance = max(nPriority, 0) * 20; // The scale of MyLifeOrganized is over 200, not over 100.
	
	pXIDestItem->AddItem(_T("Importance"), nImportance, XIT_ELEMENT);

	// ID and dependency
	CString strIDD;
	// IDD reference trick (we generate a unique ID based on the task name and ToDoList ID):
	unsigned long nIDD = pSrcTaskFile->GetTaskID(hTask);
	CString strTitle = pSrcTaskFile->GetTaskTitle(hTask);
	unsigned long nTaskNameCode = strTitle.GetLength();
	if (nTaskNameCode > 1)
		nTaskNameCode *= int(strTitle[1]);
	// <IDD>{00000000-0000-0000-0000-000000000000}</IDD>
	strIDD.Format(_T("{%08lu-0000-1111-0000-%012lu}"), nIDD, nTaskNameCode);
	pXIDestItem->AddItem(_T("IDD"), strIDD, XIT_ELEMENT);

	// Include Dependencies array in Notes:
	CString strNote;
	int nDependencies = pSrcTaskFile->GetTaskDependencyCount(hTask);
	if (nDependencies > 0)
	{
		// Dependency
		CXmlItem* pXIDestDependenciesItem = pXIDestItem->AddItem(_T("Dependency"), _T(""), XIT_ELEMENT);
		if (!pXIDestDependenciesItem)
			return false;

		CString strUID;
		CString strDependencyCount;
		for (int nDependency = 0; nDependency < nDependencies; ++nDependency)
		{
			LPCWSTR pStrDependency = pSrcTaskFile->GetTaskDependency(hTask, nDependency);

			// Add dependency to notes, as a reference to make sure it worked the IDD reference trick:
			strDependencyCount.Format(_T("%d"), nDependency + 1);
			strNote += _T("ToDoList Dependency (") + strDependencyCount + _T("): [ID " + CString(pStrDependency) + _T("] "));

			// Get the hTaskDependency from the pStrDependency
			unsigned long nID = _wtoi(pStrDependency);
			HTASKITEM hTaskDependency = pSrcTaskFile->FindTask(nID);
			if (hTaskDependency)
			{
				// IDD reference trick:
				unsigned long nUID = pSrcTaskFile->GetTaskID(hTaskDependency);
				CString strDependencyTitle = pSrcTaskFile->GetTaskTitle(hTaskDependency);
				unsigned long nTaskDependencyNameCode = strDependencyTitle.GetLength();
				if (nTaskDependencyNameCode > 1)
					nTaskDependencyNameCode *= int(strDependencyTitle[1]);
				strUID.Format(_T("{%08lu-0000-1111-0000-%012lu}"), nUID, nTaskDependencyNameCode);
				pXIDestDependenciesItem->AddItem(_T("UID"), strUID, XIT_ELEMENT);

				// Task title reference in notes:
				strNote += strDependencyTitle;
			}

			strNote += _T("\r\n\r\n");
		}
	}

	// dates
	time64_t tDate = T64Utils::T64_NULL;
	
	if (pSrcTaskFile->GetTaskCreationDate64(hTask, tDate))
		pXIDestItem->AddItem(_T("Created"), FormatDate(tDate), XIT_ELEMENT);
	
	if (pSrcTaskFile->GetTaskDoneDate64(hTask, tDate))
		pXIDestItem->AddItem(_T("CompletionDateTime"), FormatDate(tDate), XIT_ELEMENT);

	if (pSrcTaskFile->GetTaskDueDate64(hTask, false, tDate))
		pXIDestItem->AddItem(_T("DueDateTime"), FormatDate(tDate), XIT_ELEMENT);
	
	// time estimate
	TDC_UNITS nUnits;
	double dTimeEst = pSrcTaskFile->GetTaskTimeEstimate(hTask, nUnits, FALSE);
	
	if (dTimeEst > 0.0)
	{
		TH_UNITS nTHUnits = MapUnitsToTHUnits(nUnits);
		pXIDestItem->AddItem(_T("EstimateMax"), CTimeHelper().Convert(dTimeEst, nTHUnits, THU_DAYS), XIT_ELEMENT);
	}


	// links
	CString strLink;
	static const CString urlProtocol = _T("://");
	static const CString fileProtocol = _T("file://");

	// Include links array in Notes:
	int nLinks = pSrcTaskFile->GetTaskFileLinkCount(hTask);
	if (nLinks > 1)
	{
		CString strLinkCount;
		for (int nLinkCount = 0; nLinkCount < nLinks; ++nLinkCount)
		{
			strLink = pSrcTaskFile->GetTaskFileLink(hTask, nLinkCount);
			strLinkCount.Format(_T("%d"), nLinkCount+1);
			strNote += _T("ToDoList Link (") + strLinkCount + _T("): <");
			// Is it a local file link without an URL-protocol? Then add the fileProtocol...
			if (strLink.Find(urlProtocol) < 0)
				strNote += fileProtocol;
			strNote += CString(strLink) + _T(">\r\n\r\n");
		}
	}
	else
	{
		strLink = pSrcTaskFile->GetTaskFileLinkPath(hTask);
		// Include Link in Notes:
		if (!Misc::IsEmpty(strLink))
		{
			strNote += _T("ToDoList Link: <");
			// Is it a local file link without an URL-protocol? Then add the fileProtocol...
			if (strLink.Find(urlProtocol) < 0)
				strNote += fileProtocol;
			strNote += CString(strLink) + _T(">\r\n\r\n");
		}
	}

	// comments
	LPCTSTR szComments = pSrcTaskFile->GetTaskComments(hTask);

	// Formatted Comments:
	CString strHtmlComments = pSrcTaskFile->GetTaskAttribute(hTask, TDCA_HTMLCOMMENTS);
	CString strCommentsType;
	strHtmlComments.Trim();
	bool bHasFormattedComments = !strHtmlComments.IsEmpty();
	if (bHasFormattedComments)
	{
		// Remove parts of HTML that MyLifeOrganized cannot process/recognize (when generated from rich text):
		// Sample of what is actually generated from rich text:
		//      <div class=WordSection1>
		//      <p class=MsoNormal style='margin-top:0cm;margin-bottom:.0001pt;line-height:
		//      normal;text-autospace:none'><span lang=EN-GB style='font-size:8.0pt;font-family:
		//      "Arial","sans-serif"'>This is a test in bold, <span style='color:red;
		//      background:yellow'>colored</span>, Underlined.</span></p>
		//      <p class=MsoNormal style='margin-top:0cm;margin-bottom:.0001pt;line-height:
		//      normal;text-autospace:none'><span style='font-size:8.0pt;font-family:"Arial","sans-serif"'> </span></p>
		//      </div>
		//
		// TODO: Check COMMENTSTYPE instead to get bIsRTFContent. Doesn't compile: pSrcTaskFile->GetTaskAttribute(hTask, TDL_TASKCOMMENTSTYPE);
		bool bIsRTFContent = (strHtmlComments.Find(_T("<div class=WordSection1>")) >= 0);
		if (bIsRTFContent)
		{
			strHtmlComments.Replace(_T("<div class=WordSection1>"), _T(""));
			strHtmlComments.Replace(_T("</div>"), _T(""));
			strHtmlComments.Replace(_T(" style='font-size:8.0pt;font-family:"), _T(""));
			strHtmlComments.Replace(_T("\"Arial\",\"sans-serif\"'"), _T(""));
			strHtmlComments.Replace(_T(" lang=EN-GB"), _T(""));
			strHtmlComments.Replace(_T(" class=MsoNormal style='margin-top:0cm;margin-bottom:.0001pt;line-height:"), _T(""));
			strHtmlComments.Replace(_T("normal;text-autospace:none'"), _T(""));
			strHtmlComments.Replace(_T("<p\r\n>"), _T("<p>"));
			strHtmlComments.Replace(_T("<p\n>"), _T("<p>"));
			strHtmlComments.Replace(_T("<span\r\n>"), _T("<span>"));
			strHtmlComments.Replace(_T("<span\n>"), _T("<span>"));

			strCommentsType = _T("RTF"); // Type of comment in ToDoList
		}
		else
			strCommentsType = _T("HTML"); // Type of comment in ToDoList

		// Warn about the format issue in MyLifeOrganized:
		strNote += _T("ToDoList Comments (from ") + strCommentsType + _T("): *** To see format in notes, activate \"Use Markdown format in notes\" in the MyLifeOrganized options ***\r\n\r\n");
	}

	// Separation line:
	if ((!Misc::IsEmpty(strNote)) && (!Misc::IsEmpty(szComments)))
		strNote += _T("\r\n\r\n");

	// Original note:
	if (!Misc::IsEmpty(szComments))
	{
		if (!strHtmlComments.IsEmpty())
			strNote += _T("----- *** ToDoList Plain Text (HTML below) *** -----\r\n\r\n");

		strNote += szComments;
	}

	// Note in HTML:
	if (!strHtmlComments.IsEmpty())
		strNote += _T("\r\n\r\n\r\n----- *** ToDoList HTML (from ") + strCommentsType +  _T(") *** (MyLifeOrganized supports only basic HTML formatting and Markdown) -----\r\n\r\n") + strHtmlComments;

	// Notes must be added as elements now:
	if (!strNote.IsEmpty())
		pXIDestItem->AddItem(_T("Note"), strNote, XIT_ELEMENT);

	// Folders and projects: These are not available in ToDoList,
	// but we set a criteria for setting those in MyLifeOrganized:
	if ((pSrcTaskFile->GetFirstTask(hTask) != nullptr)) // If they have sub-tasks...
	{
		// We consider it a folder if it has no notes, otherwise it is a project:
		if (strNote.IsEmpty())
			pXIDestItem->AddItem(_T("HideInToDoThisTask"), -1, XIT_ELEMENT); // Folders are marked with: HideInToDoThisTask
		else
			pXIDestItem->AddItem(_T("IsProject"), -1, XIT_ELEMENT); // Projects are marked with: IsProject
	}

	// Flag:
	bool bTaskFlagged = pSrcTaskFile->IsTaskFlagged(hTask, false);
	if (bTaskFlagged)
		pXIDestItem->AddItem(_T("Flag"), _T("Red Flag"), XIT_ELEMENT);

	// CustomFormat
	CXmlItem* pXIDestCustomFormatItem = pXIDestItem->AddItem(_T("CustomFormat"), _T(""), XIT_ELEMENT);
	if (!pXIDestCustomFormatItem)
		return false;

	// Parent Task are in Bold in ToDoList, so we migrate them in bold too:
	bool bIsParentTask = pSrcTaskFile->IsTaskParent(hTask);
	if (bIsParentTask)
		pXIDestCustomFormatItem->AddItem(_T("Bold"), _T("1"), XIT_ELEMENT);

	// Task Color:
	unsigned long unTaskColor = pSrcTaskFile->GetTaskColor(hTask);
	CString strColor;
	strColor.Format(_T("%lu"), unTaskColor);
	pXIDestCustomFormatItem->AddItem(_T("FontColor"), strColor, XIT_ELEMENT);
	pXIDestCustomFormatItem->AddItem(_T("SideBarColor"), strColor, XIT_ELEMENT);


	// copy across first child
	if (!ExportTask(pSrcTaskFile, pSrcTaskFile->GetFirstTask(hTask), pXIDestItem, TRUE))
		return false;
	
	// handle sibling tasks WITHOUT RECURSION
	if (bAndSiblings)
	{
		HTASKITEM hSibling = pSrcTaskFile->GetNextTask(hTask);
		
		while (hSibling)
		{
			// FALSE == don't recurse on siblings
			if (!ExportTask(pSrcTaskFile, hSibling, pXIDestParent, FALSE))
				return false;

			hSibling = pSrcTaskFile->GetNextTask(hSibling);
		}
	}

	return true;
}

CString CMLOExporter::FormatDate(time64_t tDate)
{
	COleDateTime date = CDateHelper::GetDate(tDate);

	return CDateHelper::FormatDate(date, DHFD_ISO | DHFD_TIME, 'T');
}

void CMLOExporter::BuildPlacesMap(const ITASKLISTBASE* pSrcTaskFile, HTASKITEM hTask, 
								  CMapStringToString& mapPlaces, BOOL bAndSiblings)
{
	if (!hTask)
		return;
	
	int nCat = pSrcTaskFile->GetTaskCategoryCount(hTask);
	
	while (nCat--)
	{
		CString sCat = pSrcTaskFile->GetTaskCategory(hTask, nCat);
		CString sCatUpper(sCat);
		sCat.MakeUpper();
		
		mapPlaces[sCatUpper] = sCat;
	}
	
	// children
	BuildPlacesMap(pSrcTaskFile, pSrcTaskFile->GetFirstTask(hTask), mapPlaces, TRUE);
	
	// handle sibling tasks WITHOUT RECURSION
	if (bAndSiblings)
	{
		HTASKITEM hSibling = pSrcTaskFile->GetNextTask(hTask);
		
		while (hSibling)
		{
			// FALSE == don't recurse on siblings
			BuildPlacesMap(pSrcTaskFile, hSibling, mapPlaces, FALSE);
			hSibling = pSrcTaskFile->GetNextTask(hSibling);
		}
	}
}

void CMLOExporter::ExportPlaces(const ITASKLISTBASE* pSrcTaskFile, CXmlItem* pDestPrj)
{
	CMapStringToString mapPlaces;
	BuildPlacesMap(pSrcTaskFile, pSrcTaskFile->GetFirstTask(), mapPlaces, TRUE);
	
	if (mapPlaces.GetCount())
	{
		CXmlItem* pXIResources = pDestPrj->AddItem(_T("PlacesList"));
		CString sPlace, sPlaceUpper;
		
		POSITION pos = mapPlaces.GetStartPosition();
		
		while (pos)
		{
			mapPlaces.GetNextAssoc(pos, sPlaceUpper, sPlace);
			
			CXmlItem* pXIRes = pXIResources->AddItem(_T("TaskPlace"));
			
			if (pXIRes)
				pXIRes->AddItem(_T("Caption"), sPlace);
		}
	}
}

TH_UNITS CMLOExporter::MapUnitsToTHUnits(TDC_UNITS nUnits)
{
	switch (nUnits)
	{
	case TDCU_MINS:		return THU_MINS;
	case TDCU_HOURS:	return THU_HOURS;
	case TDCU_DAYS:		return THU_DAYS;
	case TDCU_WEEKDAYS:	return THU_WEEKDAYS;
	case TDCU_WEEKS:	return THU_WEEKS;
	case TDCU_MONTHS:	return THU_MONTHS;
	case TDCU_YEARS:	return THU_YEARS;
	}
	
	// all else
	ASSERT(0);
	return THU_NULL;
}

Hope it is useful for someone!

modified 10-Aug-22 17:41pm.

GeneralRe: Broken export to MyLifeOrganized (and code to fix it) Pin
.dan.g.4-Aug-24 16:56
professional.dan.g.4-Aug-24 16:56 
QuestionMLO Android app to display ToDoList? Pin
Hugo González Castro25-Jul-22 18:28
professionalHugo González Castro25-Jul-22 18:28 
AnswerRe: MLO Android app to display ToDoList? Pin
.dan.g.28-Jul-22 15:48
professional.dan.g.28-Jul-22 15:48 
GeneralRe: MLO Android app to display ToDoList? Pin
Hugo González Castro29-Jul-22 17:35
professionalHugo González Castro29-Jul-22 17:35 
GeneralRe: MLO Android app to display ToDoList? Pin
Hugo González Castro30-Jul-22 18:15
professionalHugo González Castro30-Jul-22 18:15 
GeneralRe: MLO Android app to display ToDoList? Pin
Hugo González Castro2-Aug-24 15:36
professionalHugo González Castro2-Aug-24 15:36 
GeneralRe: MLO Android app to display ToDoList? Pin
.dan.g.4-Aug-24 16:53
professional.dan.g.4-Aug-24 16:53 
QuestionHow about crowdfounding a good mobile app? Pin
Hugo González Castro25-Jul-22 13:30
professionalHugo González Castro25-Jul-22 13:30 
AnswerRe: How about crowdfounding a good mobile app? Pin
.dan.g.28-Jul-22 15:50
professional.dan.g.28-Jul-22 15:50 
GeneralRe: How about crowdfounding a good mobile app? Pin
Hugo González Castro29-Jul-22 17:48
professionalHugo González Castro29-Jul-22 17:48 
GeneralRe: How about crowdfounding a good mobile app? Pin
.dan.g.4-Aug-24 16:58
professional.dan.g.4-Aug-24 16:58 
GeneralCodeProject hasn't been updated for v8.1 Pin
iamstarbuck6-May-22 8:04
iamstarbuck6-May-22 8:04 
GeneralRe: CodeProject hasn't been updated for v8.1 Pin
.dan.g.6-May-22 23:36
professional.dan.g.6-May-22 23:36 
QuestionLinux Debian 11 Pin
Fabio D 202124-Feb-22 11:45
Fabio D 202124-Feb-22 11:45 
AnswerRe: Linux Debian 11 Pin
.dan.g.24-Feb-22 15:14
professional.dan.g.24-Feb-22 15:14 
GeneralRe: Linux Debian 11 Pin
Fabio D 202124-Feb-22 22:51
Fabio D 202124-Feb-22 22:51 
GeneralRe: Linux Debian 11 Pin
.dan.g.25-Feb-22 14:27
professional.dan.g.25-Feb-22 14:27 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.