27
27
namespace Do.Files {
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 FileItem);
65
public IItem[] DynamicModifierItemsForItem (IItem item)
70
public IItem[] Perform (IItem[] items, IItem[] modItems)
73
List<string> seenPaths;
75
dest = modItems[0] as FileItem;
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),
83
FileItem.EscapedPath (dest)));
84
seenPaths.Add (src.Path);
85
src.Path = Path.Combine (dest.Path,
86
Path.GetFileName (src.Path));
87
} catch (Exception e) {
88
Console.Error.WriteLine ("CopyToAction could not copy "+
89
src.Path + " to " + dest.Path + ": " + e.Message);
96
class MoveToAction : IAction {
98
public string Name { get { return "Move to..."; } }
99
public string Description { get { return "Moves a file or folder to another location."; } }
100
public string Icon { get { return "forward"; } }
102
public Type[] SupportedItemTypes {
110
public Type[] SupportedModifierItemTypes {
118
public bool ModifierItemsOptional {
119
get { return false; }
122
public bool SupportsItem (IItem item)
127
public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
129
return items.Length == 1 ||
130
FileItem.IsDirectory (modItem as FileItem);
133
public IItem[] DynamicModifierItemsForItem (IItem item)
138
public IItem[] Perform (IItem[] items, IItem[] modItems)
141
List<string> seenPaths;
143
dest = modItems[0] as FileItem;
144
seenPaths = new List<string> ();
145
foreach (FileItem src in items) {
146
if (seenPaths.Contains (src.Path)) continue;
148
System.Diagnostics.Process.Start ("mv",
149
string.Format ("{0} {1}",
150
FileItem.EscapedPath (src),
151
FileItem.EscapedPath (dest)));
152
seenPaths.Add (src.Path);
154
if (FileItem.IsDirectory (dest)) {
155
src.Path = Path.Combine (dest.Path,
156
Path.GetFileName (src.Path));
158
src.Path = dest.Path;
160
} catch (Exception e) {
161
Console.Error.WriteLine ("MoveToAction could not move "+
162
src.Path + " to " + dest.Path + ": " + e.Message);
169
// class MoveToTrashAction : AbstractAction {
171
// public override string Name { get { return "Move to Trash"; } }
172
// public override string Description { get { return "Moves a file or folder to the trash."; } }
173
// public override string Icon { get { return "user-trash-full"; } }
178
// home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
179
// return "~/.Trash".Replace ("~", home);
183
// public override Type[] SupportedItemTypes {
185
// return new Type[] {
186
// typeof (FileItem),
191
// public override IItem[] Perform (IItem[] items, IItem[] modItems)
193
// List<string> seenPaths;
195
// seenPaths = new List<string> ();
196
// foreach (FileItem src in items) {
197
// if (seenPaths.Contains (src.Path)) continue;
199
// System.Diagnostics.Process.Start ("mv",
200
// string.Format ("{0} {1}",
201
// FileItem.EscapedPath (src), Trash));
202
// seenPaths.Add (src.Path);
203
// src.Path = Path.Combine (Trash,
204
// Path.GetFileName (src.Path));
205
// } catch (Exception e) {
206
// Console.Error.WriteLine ("MoveToTrashAction could not move "+
207
// src.Path + " to the trash: " + e.Message);
214
// class DeleteAction : AbstractAction {
216
// public override string Name { get { return "Delete File"; } }
217
// public override string Description { get { return "Deletes a file or folder."; } }
218
// public override string Icon { get { return "gtk-delete"; } }
220
// public override Type[] SupportedItemTypes {
222
// return new Type[] {
223
// typeof (FileItem),
228
// public override IItem[] Perform (IItem[] items, IItem[] modItems)
230
// foreach (FileItem src in items) {
232
// System.Diagnostics.Process.Start ("rm",
233
// string.Format ("-rf {0}", FileItem.EscapedPath (src)));
234
// } catch (Exception e) {
235
// Console.Error.WriteLine ("DeleteFileAction could not delete "+
236
// src.Path + ": " + e.Message);
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);