Permalink
Browse files

Added table formatting for todo object; added prioritize command; add…

…ed 'do' command;
  • Loading branch information...
1 parent e6400ed commit e8007e9c68c66aedd91c3f5e9d098232e73469be @hartez committed Apr 26, 2011
Showing with 152 additions and 2 deletions.
  1. +39 −2 todo.cs
  2. +42 −0 todo.ps1xml
  3. BIN todo.psd1
  4. +71 −0 todo.psm1
View
@@ -11,6 +11,24 @@ public class ToDo
public String Text;
public List<String> Contexts = new List<String>();
public List<String> Projects = new List<String>();
+ private bool _done = false;
+
+ public bool Done
+ {
+ get{return _done;}
+ }
+
+ public void MarkDone()
+ {
+ _done = true;
+
+ if(IsPriority)
+ {
+ Priority = String.Empty;
+ }
+
+ Date = DateTime.Now;
+ }
public ToDo(String todo, int itemNumber)
{
@@ -36,7 +54,7 @@ public ToDo(String todo, int itemNumber)
todo = todo.Trim();
- Match everythingElse = Regex.Match(todo, @"(^\((?<priority>[A-Z])\) )?(?:(?<date>[0-9]{4}-[0-9]{2}-[0-9]{2}) )?(?<todo>.+)$");
+ Match everythingElse = Regex.Match(todo, @"(?:(?<done>[x]) )?(?:\((?<priority>[A-Z])\) )?(?:(?<date>[0-9]{4}-[0-9]{2}-[0-9]{2}) )?(?<todo>.+)$");
if(everythingElse != Match.Empty)
{
@@ -54,6 +72,11 @@ public ToDo(String todo, int itemNumber)
{
Text = everythingElse.Groups["todo"].Value;
}
+
+ if(everythingElse.Groups["done"].Success)
+ {
+ _done = true;
+ }
}
}
@@ -69,7 +92,9 @@ public String ToString(String numberFormat)
public override String ToString()
{
- return (!String.IsNullOrEmpty(Priority) ? "(" + Priority + ") " : String.Empty)
+ return
+ (_done ? "x " : String.Empty)
+ + (!String.IsNullOrEmpty(Priority) ? "(" + Priority + ") " : String.Empty)
+ (Date.HasValue ? Date.Value.ToString("yyyy-MM-dd") : String.Empty)
+ " " + Text
+ (Projects.Count() > 0 ? " " : String.Empty)
@@ -131,6 +156,18 @@ orderby todo.Priority
}
}
+ public void SetItemPriority(int item, string priority)
+ {
+ ToDo target = (from todo in this
+ where todo.ItemNumber == item
+ select todo).FirstOrDefault();
+
+ if(target != null)
+ {
+ target.Priority = priority;
+ }
+ }
+
private bool ReplaceItemText(int item, string oldText, string newText)
{
ToDo target = (from todo in this
View
@@ -0,0 +1,42 @@
+<?xml version="1.0" encoding="utf-8" ?>
+
+<Configuration>
+ <ViewDefinitions>
+ <View>
+ <Name>todo</Name>
+ <ViewSelectedBy>
+ <TypeName>ToDo</TypeName>
+ </ViewSelectedBy>
+ <TableControl>
+ <TableHeaders>
+ <TableColumnHeader>
+ <Label>Item</Label>
+ <Width>4</Width>
+ </TableColumnHeader>
+ <TableColumnHeader>
+ <Width>8</Width>
+ </TableColumnHeader>
+ <TableColumnHeader>
+ <Width>60</Width>
+ </TableColumnHeader>
+ </TableHeaders>
+ <TableRowEntries>
+ <TableRowEntry>
+ <TableColumnItems>
+ <TableColumnItem>
+ <PropertyName>ItemNumber</PropertyName>
+ </TableColumnItem>
+ <TableColumnItem>
+ <PropertyName>Priority</PropertyName>
+ </TableColumnItem>
+ <TableColumnItem>
+ <PropertyName>Text</PropertyName>
+ </TableColumnItem>
+ </TableColumnItems>
+ </TableRowEntry>
+ </TableRowEntries>
+ </TableControl>
+ </View>
+ </ViewDefinitions>
+</Configuration>
+
View
Binary file not shown.
View
@@ -96,6 +96,10 @@ param()
{
Append-ToDo $args[1] ([String]::Join(" ", $args[2..$args.Length]))
}
+ elseif($cmd -eq "do")
+ {
+ Set-ToDoDone $args[1..$args.Length]
+ }
Write-Host ""
}
@@ -128,6 +132,71 @@ param(
return ,$todos
}
+function Set-ToDoDone {
+ param([int[]] $items)
+
+ if($items)
+ {
+ $list = ParseToDoList
+
+ $items | % {
+ if($_ -le $list.Count)
+ {
+ if($list[$_ - 1].Done)
+ {
+ Write-Host "$_ is already marked done."
+ }
+ else
+ {
+ $list[$_ - 1].MarkDone()
+
+ if($TODOTXT_VERBOSE)
+ {
+ Write-Host ("$_ " + $list[$_ - 1].Text)
+ Write-Host "TODO: $_ marked as done."
+ }
+ }
+ }
+ else
+ {
+ Write-Host "No task $_."
+ }
+ }
+
+ Set-Content $todoLocation $list.ToOutput()
+ }
+}
+
+function Set-ToDoPriority {
+ param([int] $item,
+ [string] $priority)
+
+ if($priority -match "^[A-Z]{1}$")
+ {
+ $list = ParseToDoList
+
+ if($item -le $list.Count)
+ {
+ $currentPriority = $list.GetPriority($priority)
+
+ if($currentPriority.Count -gt 0)
+ {
+ ##TODO error - already an item with this priority
+ }
+ else
+ {
+ $list.SetItemPriority($item, $priority)
+ Set-Content $todoLocation $list.ToOutput()
+ #TODO check verbosity, output accordingly
+ }
+ }
+
+ ## TODO no such item message
+ }
+
+ ## TODO show an error message
+}
+
function Get-ToDo {
param(
[string[]] $search,
@@ -353,5 +422,7 @@ export-modulemember -function Get-Priority
export-modulemember -function Append-ToDo
export-modulemember -function Prepend-ToDo
export-modulemember -function Replace-ToDo
+export-modulemember -function Set-ToDoDone
+export-modulemember -function Set-ToDoPriority
export-modulemember -function ToDo
export-modulemember -function ParseToDoList

0 comments on commit e8007e9

Please sign in to comment.