~ubuntu-branches/ubuntu/hardy/do-plugins/hardy

« back to all changes in this revision

Viewing changes to File/CreateEmptyFileAction.cs

  • Committer: Bazaar Package Importer
  • Author(s): Christopher James Halse Rogers
  • Date: 2008-03-15 13:06:35 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20080315130635-jg1g6fbllv1sfjsx
Tags: 0.4.0-0ubuntu1
* New upstream release
* debian/watch:
  + Update for new Launchpad address
* debian/rules:
  + Don't build the Banshee plugin - it interferes with the normal running
    of Banshee
* debian/gnome-do-plugins.install:
  + Update for new plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* CreateEmptyFileAction.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.Collections;
 
23
using System.Collections.Generic;
 
24
using System.Text;
 
25
using System.IO;
 
26
 
 
27
using Do.Universe;
 
28
 
 
29
namespace GnomeDoFile {
 
30
        public class CreateEmptyFileAction : AbstractAction {
 
31
 
 
32
                public override string Name {
 
33
                        get {
 
34
                                return "Create empty file";
 
35
                        }
 
36
                }
 
37
                
 
38
                public override string Description {
 
39
                        get {
 
40
                                return "Creates an empty file";
 
41
                        }
 
42
                }
 
43
                
 
44
                public override string Icon {
 
45
                        get {
 
46
                                return "filenew";
 
47
                        }
 
48
                }
 
49
                
 
50
                public override Type[] SupportedItemTypes {
 
51
                        get {
 
52
                                return new Type[] {
 
53
                                        typeof(FileItem),
 
54
                                };
 
55
                        }
 
56
                }
 
57
 
 
58
                public override Type[] SupportedModifierItemTypes {
 
59
                        get {
 
60
                                return new Type[] { typeof(ITextItem) };
 
61
                        }
 
62
                }
 
63
                
 
64
                public override bool SupportsItem (IItem item)
 
65
                {
 
66
                        // Check for archive types
 
67
                        FileItem fi = item as FileItem;
 
68
                        return fi.MimeType == "x-directory/normal";
 
69
                }
 
70
 
 
71
                public override bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
 
72
                {
 
73
                        return true;
 
74
                }
 
75
 
 
76
                public override IItem[] Perform (IItem[] items, IItem[] modItems)
 
77
                {
 
78
                        FileItem parent = items [0] as FileItem;
 
79
 
 
80
                        // Don't create the file if the parent is not a dir
 
81
                        if (parent.MimeType != "x-directory/normal") {
 
82
                                return null;
 
83
                        }
 
84
 
 
85
                        ITextItem ti = modItems [0] as ITextItem;
 
86
 
 
87
                        // Create the filename for the new file
 
88
                        string filename = parent.Path + "/" + ti.Text;
 
89
 
 
90
                        try {
 
91
                                using (FileStream w = File.Open (filename, FileMode.CreateNew, FileAccess.Write)) {
 
92
                                        // Do nothing just create the file
 
93
                                        w.Close();
 
94
                                }
 
95
                        }
 
96
                        catch (Exception) {
 
97
                                return null;
 
98
                        }
 
99
 
 
100
                        // Return the new file, so new actions can be used on it
 
101
                        return new IItem[]{ new FileItem(filename) };
 
102
                }
 
103
        }
 
104
}
 
105