24
23
using System.Collections.Generic;
30
namespace Do.FilesAndFolders
32
class CopyToAction : IAction {
33
class CopyAction : AbstractFileAction
36
public override string Name {
35
37
get { return Catalog.GetString ("Copy to..."); }
38
public string Description {
40
public override string Description {
39
41
get { return Catalog.GetString ("Copies a file or folder to another location."); }
42
public string Icon { get { return "gtk-copy"; } }
44
public IEnumerable<Type> SupportedItemTypes {
52
public IEnumerable<Type> SupportedModifierItemTypes {
60
public bool ModifierItemsOptional {
64
public bool SupportsItem (IItem item)
69
public bool SupportsModifierItemForItems (IEnumerable<IItem> items, IItem modItem)
71
return FileItem.IsDirectory (modItem as IFileItem);
74
public IEnumerable<IItem> DynamicModifierItemsForItem (IItem item)
79
public IEnumerable<IItem> Perform (IEnumerable<IItem> items, IEnumerable<IItem> modItems)
82
List<string> seenPaths;
84
dest = modItems.First () as IFileItem;
85
seenPaths = new List<string> ();
86
foreach (FileItem src in items) {
87
if (seenPaths.Contains (src.Path)) continue;
44
public override string Icon {
45
get { return "gtk-copy"; }
48
public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
50
return Directory.Exists (GetPath (modItem));
53
protected override IEnumerable<Item> Perform (string source, string destination)
55
PerformOnThread (() => {
56
FileTransformation copy = new FileTransformation (CopyTransform);
89
//File.Copy doesn't work on directories, WHY!?
90
System.Diagnostics.Process.Start ("cp", "-a " +
91
FileItem.EscapedPath (src.Path) + " " +
92
FileItem.EscapedPath (dest.Path + "/" + src.Name));
94
seenPaths.Add (src.Path);
95
src.Path = Path.Combine (dest.Path, Path.GetFileName (src.Path));
58
Log.Info ("Copying {0} to {1}...", source, destination);
59
copy.Transform (source, destination);
96
60
} catch (Exception e) {
97
Console.Error.WriteLine ("CopyToAction could not copy "+
98
src.Path + " to " + dest.Path + ": " + e.Message);
61
Log.Error ("Could not copy {0} to {1}: {2}", source, destination, e.Message);
62
Log.Debug (e.StackTrace);
69
void CopyTransform (string source, string destination)
71
if (Directory.Exists (source) && !Directory.Exists (destination))
72
Directory.CreateDirectory (destination);
74
File.Copy (source, destination, true);
b'\\ No newline at end of file'