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

FinalProjectConfigurationPage.cs « MonoDevelop.Ide.Projects « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: c903c47c920eeb7c62c1796c0364dbccf04ae003 (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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
//
// FinalProjectConfigurationPage.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 MonoDevelop.Core.StringParsing;
using MonoDevelop.Ide.Templates;
using ProjectCreateParameters = MonoDevelop.Projects.ProjectCreateParameters;
using SolutionFolder = MonoDevelop.Projects.SolutionFolder;

namespace MonoDevelop.Ide.Projects
{
	class FinalProjectConfigurationPage
	{
		static readonly string WorkplaceTemplateId = "MonoDevelop.Workspace";

		NewProjectConfiguration config;
		SolutionTemplate template;
		bool valid;
		bool projectNameIsReadOnly;
		bool? createProjectDirectoryInsideSolutionDirectory;
		bool createProjectDirectoryInsideSolutionDirectoryEnabled = true;
		bool? createGitIgnoreFile;
		bool gitIgnoreEnabled = true;

		public FinalProjectConfigurationPage (NewProjectConfiguration config)
		{
			this.config = config;
		}

		public SolutionFolder ParentFolder { get; set; }

		public ProjectCreateParameters Parameters {
			get { return config.Parameters; }
		}

		public string ProjectFileExtension {
			get { return template.ProjectFileExtension; }
		}

		public SolutionTemplate Template {
			get { return template; }
			set {
				template = value;
				HasProjects = template.HasProjects;
				config.Parameters.Clear ();
				config.Parameters ["CreateSolution"] = (ParentFolder == null).ToString ();
			}
		}

		public bool IsWorkspace {
			get { return template.Id == WorkplaceTemplateId; }
		}

		public bool HasProjects {
			get { return !config.IsNewSolutionWithoutProjects; }
			private set {
				config.IsNewSolutionWithoutProjects = !value;
				CheckIsValid ();
			}
		}

		public string Location {
			get { return config.Location; }
			set {
				config.Location = value;
				CheckIsValid ();
			}
		}

		public string ProjectName {
			get { return config.ProjectName; }
			set {
				config.ProjectName = value;
				Parameters ["UserDefinedProjectName"] = value;
				CheckIsValid ();
			}
		}

		public string SolutionName {
			get {
				if (ParentFolder != null) {
					return ParentFolder.Name;
				}
				return config.SolutionName;
			}
			set {
				config.SolutionName = value;
				CheckIsValid ();
			}
		}

		public string ProjectFileName {
			get { return config.ProjectName + ProjectFileExtension; }
		}

		public string SolutionFileName {
			get { return config.SolutionName + GetSolutionFileExtension (); }
		}

		string GetSolutionFileExtension ()
		{
			if (IsWorkspace) {
				return ".mdw";
			}
			return ".sln";
		}

		public string GetValidProjectName ()
		{
			return config.GetValidProjectName ();
		}

		public string GetValidSolutionName ()
		{
			if (ParentFolder != null) {
				return ParentFolder.Name;
			}
			return config.GetValidSolutionName ();
		}

		public bool CreateGitIgnoreFile {
			get {
				if (createGitIgnoreFile.HasValue) {
					return createGitIgnoreFile.Value;
				}
				return config.CreateGitIgnoreFile;
			}
			set { config.CreateGitIgnoreFile = value; }
		}

		public bool UseGit {
			get { return config.UseGit; }
			set { config.UseGit = value; }
		}

		public bool CreateProjectDirectoryInsideSolutionDirectory {
			get {
				if (createProjectDirectoryInsideSolutionDirectory.HasValue) {
					return createProjectDirectoryInsideSolutionDirectory.Value;
				}
				return config.CreateProjectDirectoryInsideSolutionDirectory;
			}
			set { config.CreateProjectDirectoryInsideSolutionDirectory = value; }
		}

		public bool IsProjectNameEnabled {
			get { return HasProjects && !projectNameIsReadOnly; }
		}

		public bool IsSolutionNameEnabled {
			get { return config.CreateSolution; }
		}

		public bool IsCreateProjectDirectoryInsideSolutionDirectoryEnabled {
			get { return HasProjects && IsNewSolution && createProjectDirectoryInsideSolutionDirectoryEnabled; }
		}

		public bool IsGitIgnoreEnabled {
			get { return config.UseGit && IsUseGitEnabled && gitIgnoreEnabled; }
		}

		public bool IsUseGitEnabled { get; set; }

		public bool IsNewSolution {
			get { return config.CreateSolution; }
		}

		public string DefaultPreviewSolutionName {
			get {
				if (IsWorkspace) {
					return "Workspace";
				}
				return "Solution";
			}
		}

		public string DefaultPreviewSolutionFileName {
			get {
				if (IsWorkspace) {
					return "Workspace.mdw";
				}
				return "Solution.sln";
			}
		}

		public string DefaultPreviewProjectName {
			get { return "Project"; }
		}

		public string DefaultPreviewProjectFileName {
			get { return "Project" + ProjectFileExtension; }
		}

		void CheckIsValid ()
		{
			IsValid = (!IsProjectNameEnabled || !String.IsNullOrEmpty (config.ProjectName)) &&
				(!IsSolutionNameEnabled || !String.IsNullOrEmpty (config.SolutionName)) &&
				!String.IsNullOrEmpty (config.Location);
		}

		public bool IsValid {
			get { return valid; }
			set {
				if (valid != value) {
					valid = value;
					OnIsValidChanged ();
				}
			}
		}

		public event EventHandler IsValidChanged;

		void OnIsValidChanged ()
		{
			if (IsValidChanged != null) {
				IsValidChanged (this, new EventArgs ());
			}
		}

		public void UpdateFromParameters ()
		{
			ProjectName = Parameters ["ProjectName"];
			projectNameIsReadOnly = Parameters.GetBoolValue ("IsProjectNameReadOnly", false);

			createProjectDirectoryInsideSolutionDirectory = GetParameterValue ("CreateProjectDirectoryInsideSolutionDirectory");
			createProjectDirectoryInsideSolutionDirectoryEnabled = Parameters. GetBoolValue ("IsCreateProjectDirectoryInsideSolutionDirectoryEnabled", true);

			createGitIgnoreFile = GetParameterValue ("CreateGitIgnoreFile");
			gitIgnoreEnabled = Parameters.GetBoolValue ("IsGitIgnoreEnabled", true);
		}

		bool? GetParameterValue (string name)
		{
			string value = Parameters [name];
			if (!string.IsNullOrEmpty (value)) {
				return Parameters.GetBoolValue (name);
			}
			return null;
		}
	}
}