Welcome to mirror list, hosted at ThFree Co, Russian Federation.

TemplateWizard.cs « MonoDevelop.Ide.Templates « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 709c800ad6b04f5bc9c38faca31101f74722cb41 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// TemplateWizard.cs
//
// Author:
//       Matt Ward <matt.ward@xamarin.com>
//
// Copyright (c) 2014 Xamarin Inc. (http://xamarin.com)
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//

using System;
using System.Collections.Generic;
using System.Linq;
using MonoDevelop.Core;
using MonoDevelop.Core.StringParsing;
using MonoDevelop.Ide.Projects;
using MonoDevelop.Projects;

namespace MonoDevelop.Ide.Templates
{
	public abstract class TemplateWizard
	{
		public abstract string Id { get; }

		public abstract WizardPage GetPage (int pageNumber);

		public virtual void ConfigureWizard ()
		{
		}

		public virtual int TotalPages {
			get { return 1; }
		}

		public event EventHandler TotalPagesChanged;

		protected void OnTotalPagesChanged ()
		{
			TotalPagesChanged?.Invoke (this, EventArgs.Empty);
		}

		ProjectCreateParameters parameters;

		public ProjectCreateParameters Parameters {
			get {
				if (parameters == null) {
					parameters = new ProjectCreateParameters ();
				}
				return parameters;
			}
			set { parameters = value; }
		}

		List<string> supportedParameters;

		internal void UpdateParameters (SolutionTemplate template)
		{
			Parameters ["TemplateId"] = template.Id;
			Parameters ["TemplateName"] = template.Name;
			UpdateSupportedParameters (template.SupportedParameters);
			UpdateDefaultParameters (template.DefaultParameters);
		}

		void UpdateSupportedParameters (string parameters)
		{
			supportedParameters = new List<string> ();
			if (!string.IsNullOrEmpty (parameters)) {
				foreach (string part in parameters.Split (new [] {',', ';'}, StringSplitOptions.RemoveEmptyEntries)) {
					supportedParameters.Add (part.Trim ());
				}
			}
		}

		public bool IsSupportedParameter (string name)
		{
			return supportedParameters.Contains (name);
		}

		void UpdateDefaultParameters (string parameters)
		{
			if (String.IsNullOrEmpty (parameters)) {
				return;
			}

			foreach (TemplateParameter parameter in GetValidParameters (parameters)) {
				Parameters [parameter.Name] = parameter.Value;
			}
		}

		static IEnumerable<TemplateParameter> GetValidParameters (string parameters)
		{
			return TemplateParameter.CreateParameters (parameters)
				.Where (parameter => parameter.IsValid);
		}

		public virtual void ItemsCreated (IEnumerable<IWorkspaceFileObject> items)
		{
			if (!(items.FirstOrDefault () is Solution solution))
				return;

			CreateMultiProjectStartUp (solution);
		}

		/// <summary>
		/// Adds MultiStartupConfiguration when there are 
		/// more than one project and one of them is a Backend project
		/// </summary>
		/// <param name="solution">Solution.</param>
		void CreateMultiProjectStartUp (Solution solution)
		{
			if (Parameters.GetBoolValue ("CreateBackEndProject") != true || Parameters.GetBoolValue ("IncludeBackEndProject") != true)
				return;

			var config = new MultiItemSolutionRunConfiguration ("multiprojId", GettextCatalog.GetString ("Multiple Projects"));
			foreach (var proj in solution.GetAllProjects ()) {
				if (!proj.SupportsExecute ())
					continue;
				var startupItem = new StartupItem (proj, null);
				config.Items.Add (startupItem);
			}

			solution.MultiStartupRunConfigurations.Add (config);
			solution.StartupConfiguration = config;

			solution.SaveAsync (new ProgressMonitor ()).Ignore ();
		}

		public virtual IEnumerable<ProjectConfigurationControl> GetFinalPageControls ()
		{
			return Enumerable.Empty <ProjectConfigurationControl> ();
		}
	}
}