~raof/do-plugins/bansheeplugin

« back to all changes in this revision

Viewing changes to File/src/Do/Do.FilesAndFolders/CopyAction.cs

  • Committer: Alex Launi
  • Date: 2009-01-12 22:08:01 UTC
  • mfrom: (276.29.21 plugins-trunk)
  • Revision ID: alex.launi@gmail.com-20090112220801-te84p7e7av19gt1j
merge trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* FileItemActions.cs
 
1
/* CopyAction.cs
2
2
 *
3
3
 * GNOME Do is the legal property of its developers. Please refer to the
4
 
 * COPYRIGHT file distributed with this
5
 
 * source distribution.
 
4
 * COPYRIGHT file distributed with this source distribution.
6
5
 *
7
6
 * This program is free software: you can redistribute it and/or modify
8
7
 * it under the terms of the GNU General Public License as published by
22
21
using System.IO;
23
22
using System.Linq;
24
23
using System.Collections.Generic;
 
24
 
25
25
using Mono.Unix;
26
26
 
27
27
using Do.Universe;
 
28
using Do.Platform;
28
29
 
29
 
namespace FilePlugin
 
30
namespace Do.FilesAndFolders
30
31
{
31
32
        
32
 
        class CopyToAction : IAction {
 
33
        class CopyAction : AbstractFileAction
 
34
        {
33
35
 
34
 
                public string Name {
 
36
                public override string Name {
35
37
                        get { return Catalog.GetString ("Copy to..."); }
36
38
                }
37
39
                
38
 
                public string Description {
 
40
                public override string Description {
39
41
                        get { return Catalog.GetString ("Copies a file or folder to another location."); }
40
42
                }
41
43
                
42
 
                public string Icon { get { return "gtk-copy"; } } 
43
 
 
44
 
                public IEnumerable<Type> SupportedItemTypes {
45
 
                        get {
46
 
                                return new Type [] {
47
 
                                        typeof (FileItem),
48
 
                                };
49
 
                        }
50
 
                }
51
 
 
52
 
                public IEnumerable<Type> SupportedModifierItemTypes {
53
 
                        get {
54
 
                                return new Type [] {
55
 
                                        typeof (IFileItem),
56
 
                                };
57
 
                        }
58
 
                }
59
 
 
60
 
                public bool ModifierItemsOptional {
61
 
                        get { return false; }
62
 
                }
63
 
 
64
 
                public bool SupportsItem (IItem item)
65
 
                {
66
 
                        return true;
67
 
                }
68
 
 
69
 
                public bool SupportsModifierItemForItems (IEnumerable<IItem> items, IItem modItem)
70
 
                {
71
 
                        return FileItem.IsDirectory (modItem as IFileItem);
72
 
                }
73
 
 
74
 
                public IEnumerable<IItem> DynamicModifierItemsForItem (IItem item)
75
 
                {
76
 
                        return null;
77
 
                }
78
 
 
79
 
                public IEnumerable<IItem> Perform (IEnumerable<IItem> items, IEnumerable<IItem> modItems)
80
 
                {
81
 
                        IFileItem dest;
82
 
                        List<string> seenPaths;
83
 
 
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"; }
 
46
                }
 
47
 
 
48
                public override bool SupportsModifierItemForItems (IEnumerable<Item> items, Item modItem)
 
49
                {
 
50
                        return Directory.Exists (GetPath (modItem));
 
51
                }
 
52
 
 
53
                protected override IEnumerable<Item> Perform (string source, string destination)
 
54
                {
 
55
                        PerformOnThread (() => {
 
56
                                FileTransformation copy = new FileTransformation (CopyTransform);
88
57
                                try {
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));
93
 
                                                
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);
99
63
                                }
100
 
                        }
101
 
                        return null;
 
64
                        });
 
65
                        
 
66
                        yield break;
 
67
                }
 
68
 
 
69
                void CopyTransform (string source, string destination)
 
70
                {
 
71
                        if (Directory.Exists (source) && !Directory.Exists (destination))
 
72
                                Directory.CreateDirectory (destination);
 
73
                        else
 
74
                                File.Copy (source, destination, true);
102
75
                }
103
76
        }
104
77
}
 
 
b'\\ No newline at end of file'