3
// Copyright (C) 2009 GNOME Do
5
// This program is free software: you can redistribute it and/or modify
6
// it under the terms of the GNU General Public License as published by
7
// the Free Software Foundation, either version 3 of the License, or
8
// (at your option) any later version.
10
// This program is distributed in the hope that it will be useful,
11
// but WITHOUT ANY WARRANTY; without even the implied warranty of
12
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
// GNU General Public License for more details.
15
// You should have received a copy of the GNU General Public License
16
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections.Generic;
27
namespace RememberTheMilk
30
/// Class to provide the "Add Tag(s)" action
32
public class RTMAddTags : Act
34
public override string Name {
35
get { return AddinManager.CurrentLocalizer.GetString ("Add Tag(s)"); }
38
public override string Description {
39
get { return AddinManager.CurrentLocalizer.GetString ("Add one or more tags to a task."); }
42
public override string Icon {
43
get { return "tag-add.png@" + GetType ().Assembly.FullName; }
46
public override IEnumerable<Type> SupportedItemTypes {
48
yield return typeof (RTMTaskItem);
49
yield return typeof (RTMTaskAttributeItem);
53
public override IEnumerable<Type> SupportedModifierItemTypes {
55
yield return typeof (ITextItem);
56
yield return typeof (RTMTagItem);
60
public override bool SupportsItem (Item item) {
61
if (item is RTMTaskItem)
63
else if (item is RTMTaskAttributeItem)
64
return (item as RTMTaskAttributeItem).Description == "Tags";
69
public override IEnumerable<Item> Perform (IEnumerable<Item> items, IEnumerable<Item> modifierItems)
71
RTMTaskItem task = null;
72
List<string> temp_tags = new List<string> ();
76
if (items.First () is RTMTaskItem)
77
task = (items.First () as RTMTaskItem);
78
else if (items.First () is RTMTaskAttributeItem)
79
task = (items.First () as RTMTaskAttributeItem).Parent;
82
if (modifierItems.Any () && task != null) {
83
foreach (Item item in modifierItems) {
85
if (!String.IsNullOrEmpty(s))
89
Services.Application.RunOnThread (() => {
90
RTM.AddTags ((items.First () as RTMTaskItem).ListId, (items.First () as RTMTaskItem).TaskSeriesId,
91
(items.First () as RTMTaskItem).Id, String.Join (",", temp_tags.ToArray ()));
97
protected string GetText (Item item)
99
if (item is ITextItem)
100
return (item as ITextItem).Text;
101
if (item is RTMTagItem)
102
return (item as RTMTagItem).Name;
103
throw new Exception ("Inappropriate Item type.");
b'\\ No newline at end of file'