-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAttributedTask.cs
165 lines (138 loc) · 4.19 KB
/
AttributedTask.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
// Permission is hereby granted, free of charge, to any person obtaining
// a copy of this software and associated documentation files (the
// "Software"), to deal in the Software without restriction, including
// without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to
// permit persons to whom the Software is furnished to do so, subject to
// the following conditions:
//
// The above copyright notice and this permission notice shall be
// included in all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
//
// Authors:
// Jan Rüegg <[email protected]>
// Gabriel Walch <[email protected]>
// Gerd Zellweger <[email protected]>
//
using System;
using System.Collections.Generic;
using Gtk;
namespace Tomboy.TaskManager {
/// <summary>
/// Class that represents the common functionality of TaskList and Task
/// </summary>
public abstract class AttributedTask {
protected TaskNoteUtilities utils;
public void Initialize (TextIter iter, AttributedTaskTag tag)
{
//this.Buffer = buffer;
this.Position = Buffer.CreateMark (null, iter, true);
this.Tag = tag;
Tag.AttributedTask = this;
utils = new TaskNoteUtilities (Buffer);
}
/// <summary>
/// The duedate of the corresponding task or tasklist
/// if DateTime.MinValue
/// </summary>
public Nullable<DateTime> DueDate {
get {
TextTagEnumerator dates = new TextTagEnumerator (Buffer, "duedate");
foreach (TextRange r in dates) {
if (r.Start.Compare (DescriptionStart) >= 0 && r.End.Compare (DescriptionEnd) <=0){
try{
return DateTime.Parse (r.Text);
} catch (FormatException ex) {
return null;
}
}
}
return null;
}
}
/// <summary>
/// True if this task's duedate lies in the past, false if the duedates time is in the future or not set.
/// </summary>
/// <returns>
/// A <see cref="boolean"/>;
/// </returns>
public bool IsOverdue ()
{
DateTime? date = DueDate;
if (DueDate != null)
return ((DateTime)date).CompareTo(DateTime.Now) <= 0;
return false;
}
/// <summary>
/// Whether or not this task has been completed
/// </summary>
public abstract bool Done {
get; set;
}
/// <summary>
/// Tag that is attached to this attributedtask (in the buffer)
/// </summary>
public AttributedTaskTag Tag {
get; set;
}
/// <summary>
/// Describes the shortcut to the buffer
/// </summary>
protected abstract NoteBuffer Buffer {
get;
}
protected TextMark Position;
public String Description ()
{
return Buffer.GetText (DescriptionStart, DescriptionEnd, false);
}
public TextIter Start {
get { return Buffer.GetIterAtMark (Position); }
}
protected abstract TextIter DescriptionStart {
get;
}
protected abstract TextIter DescriptionEnd {
get;
}
protected abstract TextIter End {
get;
}
public bool DueDateSet {
get
{
TextTagEnumerator dates = new TextTagEnumerator (Buffer, "duedate");
foreach (TextRange r in dates)
{
if (r.Start.Compare (DescriptionStart) >= 0 && r.End.Compare (DescriptionEnd) <=0)
return true;
}
return false;
}
}
private DateTag datetag;
private DateTag DateTag{
get {
if (datetag ==null)
datetag = (DateTag) Buffer.TagTable.Lookup ("duedate");
return datetag;
}
}
public virtual void AddDueDate (DateTime date){
TextIter pos = Buffer.GetIterAtMark (Buffer.InsertMark);
Buffer.InsertWithTags (
ref pos,
date.ToShortDateString (),
new TextTag[]{DateTag}
);
}
}
}