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/>.
23
using System.Collections.Generic;
29
class CopyToAction : IAction {
31
public string Name { get { return "Copy to..."; } }
32
public string Description { get { return "Copies a file or folder to another location."; } }
33
public string Icon { get { return "gtk-copy"; } }
35
public Type [] SupportedItemTypes {
43
public Type [] SupportedModifierItemTypes {
51
public bool ModifierItemsOptional {
55
public bool SupportsItem (IItem item)
60
public bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
62
return FileItem.IsDirectory (modItem as IFileItem);
65
public IItem [] DynamicModifierItemsForItem (IItem item)
70
public IItem [] Perform (IItem [] items, IItem [] modItems)
73
List<string> seenPaths;
75
dest = modItems [0] as IFileItem;
76
seenPaths = new List<string> ();
77
foreach (FileItem src in items) {
78
if (seenPaths.Contains (src.Path)) continue;
80
System.Diagnostics.Process.Start ("cp",
81
string.Format ("-r {0} {1}",
82
FileItem.EscapedPath (src), FileItem.EscapedPath (dest)));
84
seenPaths.Add (src.Path);
85
src.Path = Path.Combine (dest.Path, Path.GetFileName (src.Path));
86
} catch (Exception e) {
87
Console.Error.WriteLine ("CopyToAction could not copy "+
88
src.Path + " to " + dest.Path + ": " + e.Message);
95
class MoveToAction : IAction {
97
public string Name { get { return "Move to..."; } }
98
public string Description { get { return "Moves a file or folder to another location."; } }
99
public string Icon { get { return "forward"; } }
101
public Type [] SupportedItemTypes {
109
public Type [] SupportedModifierItemTypes {
117
public bool ModifierItemsOptional {
118
get { return false; }
121
public bool SupportsItem (IItem item)
126
public bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
128
return items.Length == 1 ||
129
FileItem.IsDirectory (modItem as IFileItem);
132
public IItem [] DynamicModifierItemsForItem (IItem item)
137
public IItem [] Perform (IItem [] items, IItem [] modItems)
140
List<string> seenPaths;
142
dest = modItems [0] as IFileItem;
143
seenPaths = new List<string> ();
144
foreach (FileItem src in items) {
145
if (seenPaths.Contains (src.Path)) continue;
147
System.Diagnostics.Process.Start ("mv",
148
string.Format ("{0} {1}",
149
FileItem.EscapedPath (src), FileItem.EscapedPath (dest)));
150
seenPaths.Add (src.Path);
152
if (FileItem.IsDirectory (dest)) {
153
src.Path = Path.Combine (dest.Path,
154
Path.GetFileName (src.Path));
156
src.Path = dest.Path;
158
} catch (Exception e) {
159
Console.Error.WriteLine ("MoveToAction could not move "+
160
src.Path + " to " + dest.Path + ": " + e.Message);
167
class MoveToTrashAction : AbstractAction {
169
public override string Name { get { return "Move to Trash"; } }
170
public override string Description { get { return "Moves a file or folder to the trash."; } }
171
public override string Icon { get { return "user-trash-full"; } }
175
return Paths.Combine (
176
Paths.ReadXdgUserDir ("XDG_DATA_HOME", ".local/share"),
181
public override Type [] SupportedItemTypes {
189
public override IItem [] Perform (IItem [] items, IItem [] modItems)
191
List<string> seenPaths;
193
seenPaths = new List<string> ();
194
foreach (FileItem src in items) {
195
if (seenPaths.Contains (src.Path)) continue;
197
System.Diagnostics.Process.Start ("mv",
198
string.Format ("{0} {1}", FileItem.EscapedPath (src), Trash));
199
seenPaths.Add (src.Path);
200
src.Path = Path.Combine (Trash, Path.GetFileName (src.Path));
201
} catch (Exception e) {
202
Console.Error.WriteLine ("MoveToTrashAction could not move "+
203
src.Path + " to the trash: " + e.Message);
210
abstract class DeleteAction : AbstractAction {
212
public override string Name { get { return "Delete File"; } }
213
public override string Description { get { return "Deletes a file or folder."; } }
214
public override string Icon { get { return "gtk-delete"; } }
216
public override Type [] SupportedItemTypes {
224
public override IItem [] Perform (IItem [] items, IItem [] modItems)
226
foreach (IFileItem src in items) {
228
System.Diagnostics.Process.Start ("rm",
229
string.Format ("-rf {0}", FileItem.EscapedPath (src)));
230
} catch (Exception e) {
231
Console.Error.WriteLine ("DeleteFileAction could not delete "+
232
src.Path + ": " + e.Message);