1
/* CreateEmptyFileAction.cs
3
* GNOME Do is the legal property of its developers. Please refer to the
4
* COPYRIGHT file distributed with this
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.
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.
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/>.
22
using System.Collections;
23
using System.Collections.Generic;
29
namespace GnomeDoFile {
30
public class CreateEmptyFileAction : AbstractAction {
32
public override string Name {
34
return "Create empty file";
38
public override string Description {
40
return "Creates an empty file";
44
public override string Icon {
50
public override Type[] SupportedItemTypes {
58
public override Type[] SupportedModifierItemTypes {
60
return new Type[] { typeof(ITextItem) };
64
public override bool SupportsItem (IItem item)
66
// Check for archive types
67
FileItem fi = item as FileItem;
68
return fi.MimeType == "x-directory/normal";
71
public override bool SupportsModifierItemForItems (IItem[] items, IItem modItem)
76
public override IItem[] Perform (IItem[] items, IItem[] modItems)
78
FileItem parent = items [0] as FileItem;
80
// Don't create the file if the parent is not a dir
81
if (parent.MimeType != "x-directory/normal") {
85
ITextItem ti = modItems [0] as ITextItem;
87
// Create the filename for the new file
88
string filename = parent.Path + "/" + ti.Text;
91
using (FileStream w = File.Open (filename, FileMode.CreateNew, FileAccess.Write)) {
92
// Do nothing just create the file
100
// Return the new file, so new actions can be used on it
101
return new IItem[]{ new FileItem(filename) };