~bratsche/ubuntu/maverick/monodevelop/disable-appmenu

« back to all changes in this revision

Viewing changes to src/core/MonoDevelop.Ide/MonoDevelop.Ide.Templates/DirectoryTemplate.cs

  • Committer: Bazaar Package Importer
  • Author(s): Stefan Ebner
  • Date: 2009-03-17 17:55:55 UTC
  • mfrom: (1.1.13 sid)
  • Revision ID: james.westby@ubuntu.com-20090317175555-2w5qbmu0l5maq6fq
Tags: 1.9.3+dfsg-1ubuntu1
* FFe for Monodevelop 2 granted by motu-release team :)
* Merge from Debian Unstable , remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
// 
 
2
// DirectoryTemplate.cs
 
3
//  
 
4
// Author:
 
5
//       Michael Hutchinson <mhutchinson@novell.com>
 
6
// 
 
7
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
 
8
// 
 
9
// Permission is hereby granted, free of charge, to any person obtaining a copy
 
10
// of this software and associated documentation files (the "Software"), to deal
 
11
// in the Software without restriction, including without limitation the rights
 
12
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 
13
// copies of the Software, and to permit persons to whom the Software is
 
14
// furnished to do so, subject to the following conditions:
 
15
// 
 
16
// The above copyright notice and this permission notice shall be included in
 
17
// all copies or substantial portions of the Software.
 
18
// 
 
19
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 
20
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 
21
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 
22
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 
23
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 
24
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 
25
// THE SOFTWARE.
 
26
 
 
27
using System;
 
28
using System.Collections.Generic;
 
29
using System.Xml;
 
30
using System.IO;
 
31
using MonoDevelop.Core;
 
32
using MonoDevelop.Projects;
 
33
 
 
34
namespace MonoDevelop.Ide.Templates
 
35
{
 
36
        
 
37
        
 
38
        public class DirectoryTemplate : FileDescriptionTemplate
 
39
        {
 
40
                List<FileDescriptionTemplate> templates = new List<FileDescriptionTemplate> ();
 
41
                string dirName;
 
42
                
 
43
                public override string Name {
 
44
                        get { return dirName; } 
 
45
                }
 
46
                
 
47
                public override void Load (System.Xml.XmlElement filenode)
 
48
                {
 
49
                        dirName = filenode.GetAttribute ("name");
 
50
                        if (string.IsNullOrEmpty (dirName) || !FileService.IsValidFileName (dirName))
 
51
                                throw new InvalidOperationException ("Invalid name in directory template");
 
52
                        
 
53
                        foreach (XmlNode node in filenode) {
 
54
                                if (!(node is XmlElement))
 
55
                                        continue;
 
56
                                
 
57
                                FileDescriptionTemplate t = FileDescriptionTemplate.CreateTemplate ((XmlElement)node);
 
58
                                if (t == null)
 
59
                                        throw new InvalidOperationException ("Invalid file template in directory template");
 
60
                                
 
61
                                templates.Add (t);
 
62
                        }
 
63
                }
 
64
                
 
65
                public override bool SupportsProject (Project project, string projectPath)
 
66
                {
 
67
                        if (project == null)
 
68
                                return false;
 
69
                        
 
70
                        foreach (FileDescriptionTemplate t in templates)
 
71
                                if (!t.SupportsProject (project, projectPath))
 
72
                                        return false;
 
73
                        return true;
 
74
                }
 
75
                
 
76
                public override bool IsValidName (string name, string language)
 
77
                {
 
78
                        foreach (FileDescriptionTemplate t in templates)
 
79
                                if (!t.IsValidName (name, language))
 
80
                                        return false;
 
81
                        return true;
 
82
                }
 
83
                
 
84
                public override void Show ()
 
85
                {
 
86
                        foreach (FileDescriptionTemplate t in templates)
 
87
                                t.Show ();
 
88
                }
 
89
                        
 
90
                public override bool AddToProject (SolutionItem policyParent, Project project,
 
91
                                                   string language, string directory, string name)
 
92
                {
 
93
                        bool addedSomething = false;
 
94
                        directory = Path.Combine (directory, dirName);
 
95
                        if (templates.Count == 0) {
 
96
                                string relPath = FileService.AbsoluteToRelativePath (project.BaseDirectory, directory);
 
97
                                if (project.AddDirectory (relPath) != null)
 
98
                                        addedSomething = true;
 
99
                        }
 
100
                        
 
101
                        foreach (FileDescriptionTemplate t in templates)
 
102
                                addedSomething |= t.AddToProject (policyParent, project, language, directory, name);
 
103
                        
 
104
                        return addedSomething;
 
105
                }
 
106
        }
 
107
}