~do-plugins/do-plugins/future

« back to all changes in this revision

Viewing changes to File/src/Do.FilesAndFolders/NewFolderAction.cs

  • Committer: David Siegel
  • Date: 2008-12-23 22:55:20 UTC
  • Revision ID: david@david-desktop-20081223225520-fqdedh21xtm635wl
Update File plugin (had to replace files, merge was very difficult).

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// NewFolderAction.cs
 
2
//
 
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.
 
7
//
 
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.
 
12
//
 
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/>.
 
15
//
 
16
 
 
17
using System;
 
18
using System.IO;
 
19
using System.Linq;
 
20
using System.Text;
 
21
using System.Collections;
 
22
using System.Collections.Generic;
 
23
 
 
24
using Mono.Unix;
 
25
 
 
26
using Do.Universe;
 
27
using Do.Platform;
 
28
 
 
29
namespace Do.FilesAndFolders
 
30
{
 
31
        
 
32
        public class NewFolderAction : AbstractAction
 
33
        {
 
34
 
 
35
                public override string Name {
 
36
                        get { return Catalog.GetString ("New Folder"); }
 
37
                }
 
38
                
 
39
                public override string Description {
 
40
                        get { return Catalog.GetString ("Creates an new, empty folder."); }
 
41
                }
 
42
                
 
43
                public override string Icon {
 
44
                        get { return "folder-new"; }
 
45
                }
 
46
                
 
47
                public override IEnumerable<Type> SupportedItemTypes {
 
48
                        get { yield return typeof (ITextItem); }
 
49
                }
 
50
 
 
51
                public override IEnumerable<Type> SupportedModifierItemTypes {
 
52
                        get { yield return typeof (IFileItem); }
 
53
                }
 
54
                
 
55
                public override bool SupportsItem (IItem item)
 
56
                {
 
57
                        string path = (item as ITextItem).Text.Replace ("~", Paths.UserHome);
 
58
                        return !File.Exists (path) && !Directory.Exists (path);
 
59
                }
 
60
 
 
61
                public override bool SupportsModifierItemForItems (IEnumerable<IItem> items, IItem modItem)
 
62
                {
 
63
                        return Directory.Exists ((modItem as IFileItem).Path);
 
64
                }
 
65
                
 
66
                public override bool ModifierItemsOptional {
 
67
                        get { return true; }
 
68
                }
 
69
 
 
70
                public override IEnumerable<IItem> Perform (IEnumerable<IItem> items, IEnumerable<IItem> modItems)
 
71
                {
 
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);
 
77
 
 
78
                        Directory.CreateDirectory (dir);
 
79
                        yield return UniverseFactory.NewFileItem (dir);
 
80
                }
 
81
        }
 
82
}
 
83