3
// This program is free software: you can redistribute it and/or modify
4
// it under the terms of the GNU General Public License as published by
5
// the Free Software Foundation, either version 3 of the License, or
6
// (at your option) any later version.
8
// This program is distributed in the hope that it will be useful,
9
// but WITHOUT ANY WARRANTY; without even the implied warranty of
10
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11
// GNU General Public License for more details.
13
// You should have received a copy of the GNU General Public License
14
// along with this program. If not, see <http://www.gnu.org/licenses/>.
21
using System.Collections;
22
using System.Collections.Generic;
29
namespace Do.FilesAndFolders
32
public class NewFolderAction : AbstractAction
35
public override string Name {
36
get { return Catalog.GetString ("New Folder"); }
39
public override string Description {
40
get { return Catalog.GetString ("Creates an new, empty folder."); }
43
public override string Icon {
44
get { return "folder-new"; }
47
public override IEnumerable<Type> SupportedItemTypes {
48
get { yield return typeof (ITextItem); }
51
public override IEnumerable<Type> SupportedModifierItemTypes {
52
get { yield return typeof (IFileItem); }
55
public override bool SupportsItem (IItem item)
57
string path = (item as ITextItem).Text.Replace ("~", Paths.UserHome);
58
return !File.Exists (path) && !Directory.Exists (path);
61
public override bool SupportsModifierItemForItems (IEnumerable<IItem> items, IItem modItem)
63
return Directory.Exists ((modItem as IFileItem).Path);
66
public override bool ModifierItemsOptional {
70
public override IEnumerable<IItem> Perform (IEnumerable<IItem> items, IEnumerable<IItem> modItems)
72
ITextItem text = items.First () as ITextItem;
73
IFileItem parent = modItems.Any ()
74
? modItems.First () as IFileItem
75
: UniverseFactory.NewFileItem (Plugin.ImportantFolders.Desktop);
76
string dir = Path.Combine (parent.Path, text.Text);
78
Directory.CreateDirectory (dir);
79
yield return UniverseFactory.NewFileItem (dir);