2
// DirectoryTemplate.cs
5
// Michael Hutchinson <mhutchinson@novell.com>
7
// Copyright (c) 2009 Novell, Inc. (http://www.novell.com)
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:
16
// The above copyright notice and this permission notice shall be included in
17
// all copies or substantial portions of the Software.
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
28
using System.Collections.Generic;
31
using MonoDevelop.Core;
32
using MonoDevelop.Projects;
34
namespace MonoDevelop.Ide.Templates
38
public class DirectoryTemplate : FileDescriptionTemplate
40
List<FileDescriptionTemplate> templates = new List<FileDescriptionTemplate> ();
43
public override string Name {
44
get { return dirName; }
47
public override void Load (System.Xml.XmlElement filenode)
49
dirName = filenode.GetAttribute ("name");
50
if (string.IsNullOrEmpty (dirName) || !FileService.IsValidFileName (dirName))
51
throw new InvalidOperationException ("Invalid name in directory template");
53
foreach (XmlNode node in filenode) {
54
if (!(node is XmlElement))
57
FileDescriptionTemplate t = FileDescriptionTemplate.CreateTemplate ((XmlElement)node);
59
throw new InvalidOperationException ("Invalid file template in directory template");
65
public override bool SupportsProject (Project project, string projectPath)
70
foreach (FileDescriptionTemplate t in templates)
71
if (!t.SupportsProject (project, projectPath))
76
public override bool IsValidName (string name, string language)
78
foreach (FileDescriptionTemplate t in templates)
79
if (!t.IsValidName (name, language))
84
public override void Show ()
86
foreach (FileDescriptionTemplate t in templates)
90
public override bool AddToProject (SolutionItem policyParent, Project project,
91
string language, string directory, string name)
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;
101
foreach (FileDescriptionTemplate t in templates)
102
addedSomething |= t.AddToProject (policyParent, project, language, directory, name);
104
return addedSomething;