~cszikszoy/do-plugins/pastebin

« back to all changes in this revision

Viewing changes to File/src/FileCopyToAction.cs

  • Committer: David Siegel
  • Date: 2008-06-02 19:48:18 UTC
  • Revision ID: dave@x-20080602194818-i7rtmvlbq2461ey3
Added repo.py

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* FileItemActions.cs
 
2
 *
 
3
 * GNOME Do is the legal property of its developers. Please refer to the
 
4
 * COPYRIGHT file distributed with this
 
5
 * source distribution.
 
6
 *
 
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.
 
11
 *
 
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.
 
16
 *
 
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/>.
 
19
 */
 
20
 
 
21
using System;
 
22
using System.IO;
 
23
using System.Collections.Generic;
 
24
 
 
25
using Do.Universe;
 
26
 
 
27
namespace FilePlugin {
 
28
        class CopyToAction : IAction {
 
29
 
 
30
                public string Name { get { return "Copy to..."; } } 
 
31
                public string Description { get { return "Copies a file or folder to another location."; } } 
 
32
                public string Icon { get { return "gtk-copy"; } } 
 
33
 
 
34
                public Type [] SupportedItemTypes {
 
35
                        get {
 
36
                                return new Type [] {
 
37
                                        typeof (FileItem),
 
38
                                };
 
39
                        }
 
40
                }
 
41
 
 
42
                public Type [] SupportedModifierItemTypes {
 
43
                        get {
 
44
                                return new Type [] {
 
45
                                        typeof (IFileItem),
 
46
                                };
 
47
                        }
 
48
                }
 
49
 
 
50
                public bool ModifierItemsOptional {
 
51
                        get { return false; }
 
52
                }
 
53
 
 
54
                public bool SupportsItem (IItem item)
 
55
                {
 
56
                        return true;
 
57
                }
 
58
 
 
59
                public bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
 
60
                {
 
61
                        return FileItem.IsDirectory (modItem as IFileItem);
 
62
                }
 
63
 
 
64
                public IItem [] DynamicModifierItemsForItem (IItem item)
 
65
                {
 
66
                        return null;
 
67
                }
 
68
 
 
69
                public IItem [] Perform (IItem [] items, IItem [] modItems)
 
70
                {
 
71
                        IFileItem dest;
 
72
                        List<string> seenPaths;
 
73
 
 
74
                        dest = modItems [0] as IFileItem;
 
75
                        seenPaths = new List<string> ();
 
76
                        foreach (FileItem src in items) {
 
77
                                if (seenPaths.Contains (src.Path)) continue;
 
78
                                try {
 
79
                                        File.Copy (FileItem.EscapedPath (src), 
 
80
                                                   FileItem.EscapedPath (dest) + "/" + src.Name);
 
81
                                        //System.Diagnostics.Process.Start ("cp",
 
82
                                        //              string.Format ("-r {0} {1}",
 
83
                                        //                      FileItem.EscapedPath (src), FileItem.EscapedPath (dest)));
 
84
 
 
85
                                        seenPaths.Add (src.Path);
 
86
                                        src.Path = Path.Combine (dest.Path, Path.GetFileName (src.Path));
 
87
                                } catch (Exception e) {
 
88
                                        Console.Error.WriteLine ("CopyToAction could not copy "+
 
89
                                                        src.Path + " to " + dest.Path + ": " + e.Message);
 
90
                                }
 
91
                        }
 
92
                        return null;
 
93
                }
 
94
        }
 
95
}
 
 
b'\\ No newline at end of file'