~ubuntu-branches/ubuntu/oneiric/monodevelop/oneiric-updates

« back to all changes in this revision

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

  • Committer: Bazaar Package Importer
  • Author(s): Jo Shields
  • Date: 2009-02-18 08:40:51 UTC
  • mfrom: (1.2.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20090218084051-gh8m6ukvokbwj7cf
Tags: 1.9.2+dfsg-1ubuntu1
* Merge from Debian Experimental (LP: #330519), remaining Ubuntu changes:
  + debian/control:
    - Update for Gnome# 2.24
    - Add libmono-cairo1.0-cil to build-deps to fool pkg-config check

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
//
2
 
// CombineEntryDescriptor.cs
3
 
//
4
 
// Author:
5
 
//   Lluis Sanchez Gual
6
 
//
7
 
// Copyright (C) 2005 Novell, Inc (http://www.novell.com)
8
 
//
9
 
// Permission is hereby granted, free of charge, to any person obtaining
10
 
// a copy of this software and associated documentation files (the
11
 
// "Software"), to deal in the Software without restriction, including
12
 
// without limitation the rights to use, copy, modify, merge, publish,
13
 
// distribute, sublicense, and/or sell copies of the Software, and to
14
 
// permit persons to whom the Software is furnished to do so, subject to
15
 
// the following conditions:
16
 
// 
17
 
// The above copyright notice and this permission notice shall be
18
 
// included in all copies or substantial portions of the Software.
19
 
// 
20
 
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
21
 
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
22
 
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
23
 
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
24
 
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
25
 
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
26
 
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
27
 
//
28
 
 
29
 
using System;
30
 
using System.IO;
31
 
using System.Xml;
32
 
using System.Collections;
33
 
using System.Collections.Specialized;
34
 
using System.Diagnostics;
35
 
using System.Reflection;
36
 
using MonoDevelop.Projects;
37
 
using MonoDevelop.Core;
38
 
using MonoDevelop.Core.Gui;
39
 
using MonoDevelop.Core.ProgressMonitoring;
40
 
 
41
 
namespace MonoDevelop.Ide.Templates
42
 
{
43
 
        /// <summary>
44
 
        /// This class is used inside the combine templates for projects.
45
 
        /// </summary>
46
 
        internal class CombineEntryDescriptor: ICombineEntryDescriptor
47
 
        {
48
 
                string name;
49
 
//              string relativePath;
50
 
                string typeName;
51
 
                XmlElement template;
52
 
                
53
 
                protected CombineEntryDescriptor (XmlElement element)
54
 
                {
55
 
                        name = element.GetAttribute ("name");
56
 
//                      relativePath = element.GetAttribute ("directory");
57
 
                        typeName = element.GetAttribute ("type");
58
 
                        template = element;
59
 
                }
60
 
                
61
 
                public string CreateEntry (ProjectCreateInformation projectCreateInformation, string defaultLanguage)
62
 
                {
63
 
                        Type type = Type.GetType (typeName);
64
 
                        
65
 
                        if (type == null) {
66
 
                                Services.MessageService.ShowError (GettextCatalog.GetString ("Can't create project with type : {0}", typeName));
67
 
                                return String.Empty;
68
 
                        }
69
 
                        
70
 
                        CombineEntry entry = (CombineEntry) Activator.CreateInstance (type);
71
 
                        entry.InitializeFromTemplate (template);
72
 
                        
73
 
                        string newProjectName = StringParserService.Parse (name, new string[,] { 
74
 
                                {"ProjectName", projectCreateInformation.ProjectName}
75
 
                        });
76
 
                        
77
 
                        entry.Name = newProjectName;
78
 
                        
79
 
                        IFileFormat[] fileFormats = Services.ProjectService.FileFormats.GetFileFormatsForObject (entry);
80
 
                        if (fileFormats.Length == 0)
81
 
                                throw new InvalidOperationException ("Can't find a file format for the type: " + type);
82
 
 
83
 
                        string fileName = fileFormats[0].GetValidFormatName (entry, Path.Combine (projectCreateInformation.ProjectBasePath, newProjectName));
84
 
                        
85
 
                        using (IProgressMonitor monitor = new NullProgressMonitor ()) {
86
 
                                if (File.Exists (fileName)) {
87
 
                                        if (Services.MessageService.AskQuestion (GettextCatalog.GetString (
88
 
                                                "Project file {0} already exists. Do you want to overwrite\nthe existing file?", fileName),
89
 
                                                GettextCatalog.GetString ("File already exists"))) {
90
 
                                                entry.Save (fileName, monitor);
91
 
                                        }
92
 
                                } else {
93
 
                                        entry.Save (fileName, monitor);
94
 
                                }
95
 
                        }
96
 
                        
97
 
                        return fileName;
98
 
                }
99
 
                
100
 
                public static CombineEntryDescriptor CreateDescriptor (XmlElement element)
101
 
                {
102
 
                        return new CombineEntryDescriptor (element);
103
 
                }
104
 
        }
105
 
}