~ubuntu-branches/ubuntu/precise/gnome-do/precise-backports

« back to all changes in this revision

Viewing changes to Do.Addins/src/Do.Universe/FileItemActions.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-04-14 21:36:12 UTC
  • mfrom: (0.1.2 lenny) (1.1.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20080414213612-j6izjrqjsd4f4ulo
* Initial Debian package (closes: #474022)
* debian/patches/02_use_cli_for_wrapper:
  + Patch upstream's wrapper to call /usr/bin/cli rather than mono
* debian/patches/01_fix_libX11_linkage:
  + Link libdo against libX11; fix undefined symbol warnings.
* debian/patches/03_show_in_all_DEs:
  + Show the launcher in all desktop environments; it's useful in XFCE
  and KDE as well as GNOME.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
 
27
27
namespace Do.Files {
28
28
 
29
 
    class CopyToAction : IAction {
30
 
       
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"; } } 
34
 
 
35
 
                public Type[] SupportedItemTypes {
36
 
            get {
37
 
                return new Type[] {
38
 
                    typeof (FileItem),
39
 
                };
40
 
            }
41
 
        }
42
 
 
43
 
                public Type[] SupportedModifierItemTypes {
44
 
            get {
45
 
                return new Type[] {
46
 
                    typeof (FileItem),
47
 
                };
48
 
            }
49
 
        }
50
 
 
51
 
                public bool ModifierItemsOptional {
52
 
            get { return false; }
53
 
        }
54
 
 
55
 
                public bool SupportsItem (IItem item)
56
 
        {
57
 
            return true;
58
 
        }
59
 
 
60
 
                public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
61
 
        {
62
 
            return FileItem.IsDirectory (modItem as FileItem);
63
 
        }
64
 
 
65
 
                public IItem[] DynamicModifierItemsForItem (IItem item)
66
 
        {
67
 
            return null;
68
 
        }
69
 
 
70
 
                public IItem[] Perform (IItem[] items, IItem[] modItems)
71
 
        {
72
 
            FileItem dest;
73
 
            List<string> seenPaths;
74
 
 
75
 
            dest = modItems[0] as FileItem;
76
 
            seenPaths = new List<string> ();
77
 
            foreach (FileItem src in items) {
78
 
                if (seenPaths.Contains (src.Path)) continue;
79
 
                try {
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);
90
 
                }
91
 
            }
92
 
            return null;
93
 
        }
94
 
        }
95
 
 
96
 
    class MoveToAction : IAction {
97
 
       
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"; } } 
101
 
 
102
 
                public Type[] SupportedItemTypes {
103
 
            get {
104
 
                return new Type[] {
105
 
                    typeof (FileItem),
106
 
                };
107
 
            }
108
 
        }
109
 
 
110
 
                public Type[] SupportedModifierItemTypes {
111
 
            get {
112
 
                return new Type[] {
113
 
                    typeof (FileItem),
114
 
                };
115
 
            }
116
 
        }
117
 
 
118
 
                public bool ModifierItemsOptional {
119
 
            get { return false; }
120
 
        }
121
 
 
122
 
                public bool SupportsItem (IItem item)
123
 
        {
124
 
            return true;
125
 
        }
126
 
 
127
 
                public bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
128
 
        {
129
 
            return items.Length == 1 ||
130
 
                FileItem.IsDirectory (modItem as FileItem);
131
 
        }
132
 
 
133
 
                public IItem[] DynamicModifierItemsForItem (IItem item)
134
 
        {
135
 
            return null;
136
 
        }
137
 
 
138
 
                public IItem[] Perform (IItem[] items, IItem[] modItems)
139
 
        {
140
 
            FileItem dest;
141
 
            List<string> seenPaths;
142
 
 
143
 
            dest = modItems[0] as FileItem;
144
 
            seenPaths = new List<string> ();
145
 
            foreach (FileItem src in items) {
146
 
                if (seenPaths.Contains (src.Path)) continue;
147
 
                try {
148
 
                    System.Diagnostics.Process.Start ("mv",
149
 
                       string.Format ("{0} {1}",
150
 
                           FileItem.EscapedPath (src),
151
 
                           FileItem.EscapedPath (dest)));
152
 
                    seenPaths.Add (src.Path);
153
 
 
154
 
                    if (FileItem.IsDirectory (dest)) {
155
 
                        src.Path = Path.Combine (dest.Path,
156
 
                            Path.GetFileName (src.Path));
157
 
                    } else {
158
 
                        src.Path = dest.Path;
159
 
                    }
160
 
                } catch (Exception e) {
161
 
                    Console.Error.WriteLine ("MoveToAction could not move "+
162
 
                        src.Path + " to " + dest.Path + ": " + e.Message);
163
 
                }
164
 
            }
165
 
            return null;
166
 
        }
167
 
        }
168
 
 
169
 
    // class MoveToTrashAction : AbstractAction {
170
 
       
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"; } } 
174
 
 
175
 
    //     string Trash {
176
 
    //         get {
177
 
    //             string home;
178
 
    //             home = Environment.GetFolderPath (Environment.SpecialFolder.Personal);
179
 
    //             return "~/.Trash".Replace ("~", home);
180
 
    //         }
181
 
    //     }
182
 
 
183
 
    //          public override Type[] SupportedItemTypes {
184
 
    //         get {
185
 
    //             return new Type[] {
186
 
    //                 typeof (FileItem),
187
 
    //             };
188
 
    //         }
189
 
    //     }
190
 
 
191
 
    //          public override IItem[] Perform (IItem[] items, IItem[] modItems)
192
 
    //     {
193
 
    //         List<string> seenPaths;
194
 
 
195
 
    //         seenPaths = new List<string> ();
196
 
    //         foreach (FileItem src in items) {
197
 
    //             if (seenPaths.Contains (src.Path)) continue;
198
 
    //             try {
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);
208
 
    //             }
209
 
    //         }
210
 
    //         return null;
211
 
    //     }
212
 
    //  }
213
 
 
214
 
    // class DeleteAction : AbstractAction {
215
 
       
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"; } } 
219
 
 
220
 
    //          public override Type[] SupportedItemTypes {
221
 
    //         get {
222
 
    //             return new Type[] {
223
 
    //                 typeof (FileItem),
224
 
    //             };
225
 
    //         }
226
 
    //     }
227
 
 
228
 
    //          public override IItem[] Perform (IItem[] items, IItem[] modItems)
229
 
    //     {
230
 
    //         foreach (FileItem src in items) {
231
 
    //             try {
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);
237
 
    //             }
238
 
    //         }
239
 
    //         return null;
240
 
    //     }
241
 
    //  }
 
29
        class CopyToAction : IAction {
 
30
 
 
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"; } } 
 
34
 
 
35
                public Type [] SupportedItemTypes {
 
36
                        get {
 
37
                                return new Type [] {
 
38
                                        typeof (FileItem),
 
39
                                };
 
40
                        }
 
41
                }
 
42
 
 
43
                public Type [] SupportedModifierItemTypes {
 
44
                        get {
 
45
                                return new Type [] {
 
46
                                        typeof (IFileItem),
 
47
                                };
 
48
                        }
 
49
                }
 
50
 
 
51
                public bool ModifierItemsOptional {
 
52
                        get { return false; }
 
53
                }
 
54
 
 
55
                public bool SupportsItem (IItem item)
 
56
                {
 
57
                        return true;
 
58
                }
 
59
 
 
60
                public bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
 
61
                {
 
62
                        return FileItem.IsDirectory (modItem as IFileItem);
 
63
                }
 
64
 
 
65
                public IItem [] DynamicModifierItemsForItem (IItem item)
 
66
                {
 
67
                        return null;
 
68
                }
 
69
 
 
70
                public IItem [] Perform (IItem [] items, IItem [] modItems)
 
71
                {
 
72
                        IFileItem dest;
 
73
                        List<string> seenPaths;
 
74
 
 
75
                        dest = modItems [0] as IFileItem;
 
76
                        seenPaths = new List<string> ();
 
77
                        foreach (FileItem src in items) {
 
78
                                if (seenPaths.Contains (src.Path)) continue;
 
79
                                try {
 
80
                                        System.Diagnostics.Process.Start ("cp",
 
81
                                                        string.Format ("-r {0} {1}",
 
82
                                                                FileItem.EscapedPath (src), FileItem.EscapedPath (dest)));
 
83
 
 
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);
 
89
                                }
 
90
                        }
 
91
                        return null;
 
92
                }
 
93
        }
 
94
 
 
95
        class MoveToAction : IAction {
 
96
 
 
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"; } } 
 
100
 
 
101
                public Type [] SupportedItemTypes {
 
102
                        get {
 
103
                                return new Type [] {
 
104
                                        typeof (FileItem),
 
105
                                };
 
106
                        }
 
107
                }
 
108
 
 
109
                public Type [] SupportedModifierItemTypes {
 
110
                        get {
 
111
                                return new Type [] {
 
112
                                        typeof (IFileItem),
 
113
                                };
 
114
                        }
 
115
                }
 
116
 
 
117
                public bool ModifierItemsOptional {
 
118
                        get { return false; }
 
119
                }
 
120
 
 
121
                public bool SupportsItem (IItem item)
 
122
                {
 
123
                        return true;
 
124
                }
 
125
 
 
126
                public bool SupportsModifierItemForItems (IItem [] items, IItem modItem)
 
127
                {
 
128
                        return items.Length == 1 ||
 
129
                                FileItem.IsDirectory (modItem as IFileItem);
 
130
                }
 
131
 
 
132
                public IItem [] DynamicModifierItemsForItem (IItem item)
 
133
                {
 
134
                        return null;
 
135
                }
 
136
 
 
137
                public IItem [] Perform (IItem [] items, IItem [] modItems)
 
138
                {
 
139
                        IFileItem dest;
 
140
                        List<string> seenPaths;
 
141
 
 
142
                        dest = modItems [0] as IFileItem;
 
143
                        seenPaths = new List<string> ();
 
144
                        foreach (FileItem src in items) {
 
145
                                if (seenPaths.Contains (src.Path)) continue;
 
146
                                try {
 
147
                                        System.Diagnostics.Process.Start ("mv",
 
148
                                                        string.Format ("{0} {1}",
 
149
                                                                FileItem.EscapedPath (src), FileItem.EscapedPath (dest)));
 
150
                                        seenPaths.Add (src.Path);
 
151
 
 
152
                                        if (FileItem.IsDirectory (dest)) {
 
153
                                                src.Path = Path.Combine (dest.Path,
 
154
                                                                Path.GetFileName (src.Path));
 
155
                                        } else {
 
156
                                                src.Path = dest.Path;
 
157
                                        }
 
158
                                } catch (Exception e) {
 
159
                                        Console.Error.WriteLine ("MoveToAction could not move "+
 
160
                                                        src.Path + " to " + dest.Path + ": " + e.Message);
 
161
                                }
 
162
                        }
 
163
                        return null;
 
164
                }
 
165
        }
 
166
 
 
167
        class MoveToTrashAction : AbstractAction {
 
168
 
 
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"; } } 
 
172
 
 
173
                string Trash {
 
174
                        get { 
 
175
                                return Paths.Combine (
 
176
                                                Paths.ReadXdgUserDir ("XDG_DATA_HOME", ".local/share"),
 
177
                                                "Trash/files");
 
178
                        }
 
179
                }
 
180
 
 
181
                public override Type [] SupportedItemTypes {
 
182
                        get {
 
183
                                return new Type [] {
 
184
                                        typeof (FileItem),
 
185
                                };
 
186
                        }
 
187
                }
 
188
 
 
189
                public override IItem [] Perform (IItem [] items, IItem [] modItems)
 
190
                {
 
191
                        List<string> seenPaths;
 
192
 
 
193
                        seenPaths = new List<string> ();
 
194
                        foreach (FileItem src in items) {
 
195
                                if (seenPaths.Contains (src.Path)) continue;
 
196
                                try {
 
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);
 
204
                                }
 
205
                        }
 
206
                        return null;
 
207
                }
 
208
        }
 
209
 
 
210
        abstract class DeleteAction : AbstractAction {
 
211
 
 
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"; } } 
 
215
 
 
216
                public override Type [] SupportedItemTypes {
 
217
                        get {
 
218
                                return new Type [] {
 
219
                                        typeof (IFileItem),
 
220
                                };
 
221
                        }
 
222
                }
 
223
 
 
224
                public override IItem [] Perform (IItem [] items, IItem [] modItems)
 
225
                {
 
226
                        foreach (IFileItem src in items) {
 
227
                                try {
 
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);
 
233
                                }
 
234
                        }
 
235
                        return null;
 
236
                }
 
237
        }
242
238
}