3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
7
* This program is free software: you can redistribute it and/or modify
8
* it under the terms of the GNU General Public License as published by
9
* the Free Software Foundation, either version 3 of the License, or
10
* (at your option) any later version.
12
* This program is distributed in the hope that it will be useful,
13
* but WITHOUT ANY WARRANTY; without even the implied warranty of
14
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
* GNU General Public License for more details.
17
* You should have received a copy of the GNU General Public License
18
* along with this program. If not, see <http://www.gnu.org/licenses/>.
26
namespace GnomeDoAppendText {
27
public class AppendTextAction : IAction {
29
public string Name { get { return "Append to..."; } }
30
public string Description { get { return "Appends text to a selected file."; } }
31
public string Icon { get { return "text-editor"; } }
33
public Type[] SupportedItemTypes {
35
return new Type[] { typeof (ITextItem) };
39
public Type[] SupportedModifierItemTypes {
41
return new Type[] { typeof (FileItem), typeof(ITextItem) };
45
public bool ModifierItemsOptional {
50
public bool SupportsItem (IItem item)
55
public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
57
if (modItem is FileItem) {
58
string mime = (modItem as FileItem).MimeType;
59
return mime == "x-directory/normal" || mime.StartsWith ("text/");
61
return modItem is ITextItem;
64
public IItem[] DynamicModifierItemsForItem (IItem item)
69
public IItem[] Perform (IItem[] items, IItem[] modItems)
71
if (modItems [0] is FileItem) {
72
string text = (items [0] as ITextItem).Text;
73
string mime = (modItems [0] as FileItem).MimeType;
74
string file = (modItems [0] as FileItem).Path;
76
if (mime == "x-directory/normal") return null;
78
using (StreamWriter w = File.AppendText (file)) {
86
string text = (items [0] as ITextItem).Text;
87
string text2 = (modItems [0] as ITextItem).Text;
88
return new IItem[] { new TextItem (text + text2) };