Sorry - laptop ran out of battery - was in a hurry
;Issues
;I do not set the ORDER of the TDL file in the same way as the TDL.exe - New tasks is inserted after the categories - however TDL.exe restores the correct order when next saving - and it only affects human reading of the .tdl in a text editor
;For categorical variables like "Category" and "Allocated To" I cannot get (YET) a dropdownlistcheckbox to enter multiple categories - currently you will be restricted to a single category
;Unicode is untested - but in theory it should work fine for files saved with 6.3.1 - however with files saved with 6.3.0 it may convert it back to ANSI (as the encoding flag was not set)
;Only works with the current active .tdl file - but can be very easily be changed to work with any .tdl file - even closed files or on computers where no AHK is installed
;Requires AHK_L
;Untested with different regional date settings - however I believe that the local date settings in TDL only affects the display and not the saving
;I am not suppressing the dialog box that asks you to reload the tasklist
;Does not recognise default values - though for colours and the like, when left blank it is automatically corrected by TDL
;Cannot handle RichText or encrypted files
;Shared files not locked properly when writing
settitlematchmode,2
#ifwinactive AbstractSpoon
Width2=140
X2=100
^N::
Gui, Destroy
StatusBarGetText, Filename , 1, AbstractSpoon
FileRead, xml, %Filename%
TDL:=loadXML(XML)
Categories:=TDLCategories(TDL, "Category")
TDLCategories(TDL, Category)
{
Categories=
for node in TDL.childNodes.Item(1).childNodes
{
NodeName:=node.nodename
If (NodeName=Category)
for attrib In node.attributes
Categories.=strlen(Categories)>0 ? "|" . attrib.value : attrib.value
}
return Categories
}
DateFormat=dd/MM/yyyy HH:mm:ss
WinGet, HWND, ID, AbstractSpoon
Gui, +ToolWindow -Caption
Gui +owner %HWND%
Gui, Add, Text, xm y+10, TDL Target
Gui, Add, Text, x%X2% yp , Content
;Gui, Add, Text, xm y+10 , Target TDL File
;Gui, Add, Edit, x%X2% yp vFilename w%Width2% r1,%Filename%
;msgbox %Filename%
Gui, Add, Text, xm y+10 , Title
Gui, Add, Edit, x%X2% yp vTitle w%Width2%, New Task
Gui, Add, Text, xm y+10 , Due Date
Gui, Add, DateTime, x%X2% yp vDueDate w%Width2%, %DateFormat%
;Gui, Add, Edit, x100 yp vDueDate
Gui, Add, Text, xm y+10 , Priority
Gui, Add, DropDownList, x%X2% yp w%Width2% vPriority Choose1, <None>|0 (Lowest)|1 (Very Low)|2 (Low) |3 ((Low-Med)|4 (Medium)|5 (Medium)|6 (Medium)|7 (Med-High)|8 (High)|9 (Very High)|10 (Highest)
Gui, Add, Text, xm y+10 , Risk
Gui, Add, DropDownList, x%X2% yp w%Width2% vRisk Choose1, <None>|0 (Lowest)|1 (Very Low)|2 (Low) |3 ((Low-Med)|4 (Medium)|5 (Medium)|6 (Medium)|7 (Med-High)|8 (High)|9 (Very High)|10 (Highest)
;Gui, Add, Edit, x%X2% yp vRisk w%Width2%
Gui, Add, Text, xm y+10 , Cost
Gui, Add, Edit, x%X2% yp vCost w%Width2%, 0.0
Gui, Add, Text, xm y+10 , Category
Gui, Add, ComboBox, x%X2% yp w%Width2% vCategory, %Categories%
Gui, Add, Button, xm y+10 gSave,Save
Gui, Add, Button, x+10 yp gCancel,Cancel
Gui Show
Return
#ifwinactive
Save:
Gui, Submit
FileRead, xml, %Filename%
TDL:=loadXML(XML)
NextID:=TDL.childNodes.Item(1).getAttribute("NEXTUNIQUEID")
MyNode:=TDL.createNode(1,"Task","")
;Save Plain text attribute
MyNode.setattribute("Title",Title)
;Save numbers entered - requires validation - though will not crash if text is entered!
MyNode.setattribute("Cost",Cost)
;Save categorical attribute with FIXED Categories
MyNode.setattribute("Risk",TDLCategory10(Risk))
MyNode.setattribute("Priority",TDLCategory10(Risk))
;Save categorical attribute with VARIABLE Categories - note that only 1 category can be chosen at the moment TDL allows multiple categories
If Category<>
{
MyNode.setattribute("NUMCATEGORY",1)
MyNode.setattribute("CATEGORY",Category)
CategoryIndex:=TDLGetCategoryIndex(Categories, Category)
If CategoryIndex<0
{
MaxIndex:=TDLGetCategoryMaxIndex(Categories, Category)
TDLAddCategory(TDL, "Category", "Category" . MaxIndex, Category)
}
}
;Save a Date
MyNode.setattribute("DueDate",TDLDate(Duedate))
MyNode.setattribute("DueDateString",TDLDateString(Duedate))
;Creation and modification dates are not user editable (well it can be - but I cannot see why you would want to)
TimeNow:=A_Now
MyNode.setattribute("CREATIONDATE",TDLDate(TimeNow))
MyNode.setattribute("CREATIONDATEString",TDLDateString(TimeNow))
MyNode.setattribute("CREATIONDATE",TDLDate(TimeNow))
MyNode.setattribute("CREATIONDATEString",TDLDateString(TimeNow))
MyNode.setattribute("LASTMOD",TDLDate(TimeNow))
MyNode.setattribute("LASTMODString",TDLDateString(TimeNow))
Mynode.setattribute("ID",NextID)
TDL.childNodes.Item(1).appendChild(myNode)
TDL.childNodes.Item(1).setAttribute("NEXTUNIQUEID",NextId+1)
TDL.save(FileName)
Gui, Destroy
;exitApp
return
Cancel:
Gui, Destroy
return
loadXML(ByRef data)
{
o := ComObjCreate("MSXML2.DOMDocument.6.0")
o.async := false
o.loadXML(data)
return o
}
TDLDate(TextDate)
{
EnvSub, TextDate, 19000101, seconds
var1:=TextDate/86400+2
return,%var1%
}
DUEDATESTRING="2011-10-15T11:00"
TDLDateString(TextDate)
{
FormatTime, TDLDateString , %TextDate%, yyyy-MM-ddTHH:mm
return,%TDLDateString%
}
TDLCategory10(TextCategory)
{
if (TextCategory="<None>")
return ""
return SubStr(TextCategory, 1 , InStr(TextCategory," ")-1)
}
TDLAddCategory(TDL, Category, NewCategory, NewCategoryValue)
{
Categories=
for node in TDL.childNodes.Item(1).childNodes
{
NodeName:=node.nodename
If (NodeName=Category)
node.setattribute(NewCategory,NewCategoryValue)
; for attrib In node.attributes
; Categories.=strlen(Categories)>0 ? "|" . attrib.value : attrib.value
}
return Categories
}
TDLGetCategoryIndex(Categories, Category)
{
CategoryIndex=-1
Loop, Parse, Categories, |
{
if (A_LoopField=Category)
CategoryIndex:=A_Index
}
Return CategoryIndex
}
TDLGetCategoryMaxIndex(Categories, Category)
{
MaxIndex:=0
Loop, Parse, Categories, |
MaxIndex:=A_Index
Return MaxIndex
}
|