tasque r15 - in trunk: . src
- From: sharm svn gnome org
- To: svn-commits-list gnome org
- Subject: tasque r15 - in trunk: . src
- Date: Thu, 13 Mar 2008 15:30:46 +0000 (GMT)
Author: sharm
Date: Thu Mar 13 15:30:46 2008
New Revision: 15
URL: http://svn.gnome.org/viewvc/tasque?rev=15&view=rev
Log:
* src/TaskTreeView.cs: Support for parsing due date out of undated
tasks. Currently handles "today", "tomorrow", and anything
understood by DateTime.Parse. Favors future dates, but will obey a
year if one is specified.
* src/Preferences.cs: Added hidden preference for enabling due date
parsing, which defaults to true. Added support for preference
defaults. Changed a bunch of static strings to const strings in
support of this.
Modified:
trunk/ChangeLog
trunk/src/Preferences.cs
trunk/src/TaskTreeView.cs
Modified: trunk/src/Preferences.cs
==============================================================================
--- trunk/src/Preferences.cs (original)
+++ trunk/src/Preferences.cs Thu Mar 13 15:30:46 2008
@@ -43,19 +43,20 @@
private System.Xml.XmlDocument document;
private string location;
- public static string AuthTokenKey = "AuthToken";
- public static string CurrentBackend = "CurrentBackend";
- public static string InactivateTimeoutKey = "InactivateTimeout";
- public static string SelectedCategoryKey = "SelectedCategory";
+ public const string AuthTokenKey = "AuthToken";
+ public const string CurrentBackend = "CurrentBackend";
+ public const string InactivateTimeoutKey = "InactivateTimeout";
+ public const string SelectedCategoryKey = "SelectedCategory";
+ public const string ParseDateEnabledKey = "ParseDateEnabled";
/// <summary>
/// A list of category names to show in the TaskWindow when the "All"
/// category is selected.
/// </summary>
- public static string HideInAllCategory = "HideInAllCategory";
- public static string ShowCompletedTasksKey = "ShowCompletedTasks";
- public static string UserNameKey = "UserName";
- public static string UserIdKey = "UserID";
+ public const string HideInAllCategory = "HideInAllCategory";
+ public const string ShowCompletedTasksKey = "ShowCompletedTasks";
+ public const string UserNameKey = "UserName";
+ public const string UserIdKey = "UserID";
/// <summary>
/// This setting allows a user to specify how many completed tasks to
@@ -68,7 +69,7 @@
/// <returns>
/// A <see cref="System.String"/>
/// </returns>
- public static string CompletedTasksRange = "CompletedTasksRange";
+ public const string CompletedTasksRange = "CompletedTasksRange";
public delegate void SettingChangedHandler (Preferences preferences,
string settingKey);
@@ -82,15 +83,33 @@
string xPath = string.Format ("//{0}", settingKey.Trim ());
XmlNode node = document.SelectSingleNode (xPath);
if (node == null || node is XmlElement == false)
- return null;
+ return SetDefault (settingKey);
XmlElement element = node as XmlElement;
if( (element == null) || (element.InnerText.Length < 1) )
- return null;
+ return SetDefault (settingKey);
else
return element.InnerText;
}
+ private string SetDefault (string settingKey)
+ {
+ string val = GetDefault (settingKey);
+ if (val != null)
+ Set (settingKey, val);
+ return val;
+ }
+
+ private string GetDefault (string settingKey)
+ {
+ switch (settingKey) {
+ case ParseDateEnabledKey:
+ return true.ToString ();
+ default:
+ return null;
+ }
+ }
+
public void Set (string settingKey, string settingValue)
{
if (settingKey == null || settingKey.Trim () == string.Empty)
Modified: trunk/src/TaskTreeView.cs
==============================================================================
--- trunk/src/TaskTreeView.cs (original)
+++ trunk/src/TaskTreeView.cs Thu Mar 13 15:30:46 2008
@@ -3,6 +3,7 @@
using System;
using System.Collections.Generic;
+using System.Text.RegularExpressions;
using Gtk;
using Mono.Unix;
@@ -350,8 +351,10 @@
return;
}
- crc.Text = date.ToString(Catalog.GetString("M/d - ddd"));
-
+ if (date.Year == DateTime.Today.Year)
+ crc.Text = date.ToString(Catalog.GetString("M/d - ddd"));
+ else
+ crc.Text = date.ToString(Catalog.GetString("M/d/yy - ddd"));
//Utilities.GetPrettyPrintDate (task.DueDate, false);
}
@@ -541,7 +544,80 @@
if (task == null)
return;
- task.Name = args.NewText;
+ string newText = args.NewText;
+ if (Application.Preferences.GetBool (Preferences.ParseDateEnabledKey) &&
+ task.State == TaskState.Active &&
+ task.DueDate == DateTime.MinValue)
+ newText = ParseTaskText (newText, task);
+ task.Name = newText;
+ }
+
+ /// <summary>
+ /// Parse the task name in order to derive due date information.
+ /// </summary>
+ /// <param name="taskText">
+ /// A <see cref="System.String"/> representing the text entered
+ /// into the task name field.
+ /// </param>
+ /// <param name="task">
+ /// The <see cref="ITask"/> object to which due date information
+ /// should be added, if any is found.
+ /// </param>
+ /// <returns>
+ /// The taskText with the due date section of the string removed.
+ /// </returns>
+ string ParseTaskText (string taskText, ITask task)
+ {
+ // First, look for ways that the right side of the entered
+ // text can be directly parsed as a date
+ string[] words = taskText.Split (' ');
+ for (int i = 1; i < words.Length; i++) {
+ string possibleDate = string.Join (" ", words, i, words.Length - i);
+ DateTime result;
+ if (DateTime.TryParse (possibleDate, out result)) {
+ // Favor future dates, unless year was specifically mentioned
+ if (!possibleDate.Contains (result.Year.ToString ()))
+ while (result < DateTime.Today)
+ result = result.AddYears (1);
+
+ // Set task due date and return the task
+ // name with the date part removed.
+ task.DueDate = result;
+ return string.Join (" ", words, 0, i);
+ }
+ }
+
+ // Then try some more natural language parsing
+
+ // A regular expression to capture a task that is due today
+ string today = Catalog.GetString (@"^(?<task>.+)\s+today\W*$");
+ // A regular expression to capture a task that is due tomorrow
+ string tomorrow = Catalog.GetString (@"^(?<task>.+)\s+tomorrow\W*$");
+
+ // Additional regular expressions to consider using
+ //string abbrevDate = Catalog.GetString (@"^(?<task>.+)(on )?(the )?(?<day>\d{1,2})((th)|(nd)|(rd)|(st))\W*$");
+ //string nextDayName = Catalog.GetString (@"^(?<task>.+)(on )?next\s+(?<day>[a-z]+)\W*$");
+ //string dayName = Catalog.GetString (@"^(?<task>.+)\s+(on )?(?<day>[a-z]+)\W*$");
+
+ Match match = Regex.Match (taskText, today, RegexOptions.IgnoreCase);
+ if (match.Success) {
+ string trimmedTaskText = match.Groups ["task"].Value;
+ if (!string.IsNullOrEmpty (trimmedTaskText)) {
+ task.DueDate = DateTime.Now;
+ return trimmedTaskText;
+ }
+ }
+
+ match = Regex.Match (taskText, tomorrow, RegexOptions.IgnoreCase);
+ if (match.Success) {
+ string trimmedTaskText = match.Groups ["task"].Value;
+ if (!string.IsNullOrEmpty (trimmedTaskText)) {
+ task.DueDate = DateTime.Now.AddDays (1);
+ return trimmedTaskText;
+ }
+ }
+
+ return taskText;
}
/// <summary>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]