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/>.
28
public class AppendTextAction : IAction {
30
public string Name { get { return Catalog.GetString ("Append to..."); } }
31
public string Description { get { return Catalog.GetString ("Appends text to a selected file."); } }
32
public string Icon { get { return "text-editor"; } }
34
public Type[] SupportedItemTypes {
36
return new Type[] { typeof (ITextItem) };
40
public Type[] SupportedModifierItemTypes {
42
return new Type[] { typeof (FileItem), typeof(ITextItem) };
46
public bool ModifierItemsOptional {
51
public bool SupportsItem (IItem item)
56
public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
58
if (modItem is FileItem) {
59
string mime = (modItem as FileItem).MimeType;
60
return mime == "x-directory/normal" || mime.StartsWith ("text/");
62
return modItem is ITextItem;
65
public IItem[] DynamicModifierItemsForItem (IItem item)
70
public IItem[] Perform (IItem[] items, IItem[] modItems)
72
if (modItems [0] is FileItem) {
73
string text = (items [0] as ITextItem).Text;
74
string mime = (modItems [0] as FileItem).MimeType;
75
string file = (modItems [0] as FileItem).Path;
77
if (mime == "x-directory/normal") return null;
79
using (StreamWriter w = File.AppendText (file)) {
87
string text = (items [0] as ITextItem).Text;
88
string text2 = (modItems [0] as ITextItem).Text;
89
return new IItem[] { new TextItem (text + text2) };