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

NewLayoutDialog.cs « MonoDevelop.Ide.Gui.Dialogs « MonoDevelop.Ide « core « src « main - github.com/mono/monodevelop.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 938bd2991c00825236c881bda261faa578c4b613 (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
// NewLayoutDialog.cs
//
// Authors: Gustavo Giráldez  <gustavo.giraldez@gmx.net>

using System;
using Gtk;
using MonoDevelop.Ide.Gui;
using System.Linq;
using System.Collections.Generic;
using MonoDevelop.Core;

namespace MonoDevelop.Ide.Gui.Dialogs
{
	internal partial class NewLayoutDialog : Gtk.Dialog
	{
		IList<string> existingLayouts;

		public NewLayoutDialog ()
		{
			Build ();
			
			existingLayouts = IdeApp.Workbench.Layouts;
			
			layoutName.Changed += OnNameChanged;
			OnNameChanged (layoutName, EventArgs.Empty);

			newButton.GrabDefault ();
		}
		
		public string LayoutName {
			get { return layoutName.Text; }
		}

		void OnNameChanged (object obj, EventArgs args)
		{
			var txt = LayoutName;
			
			if (string.IsNullOrEmpty (txt)) {
				validationMessage.Text = GettextCatalog.GetString ("Enter a name for the new layout");
			} else if (!char.IsLetterOrDigit (txt[0])) {
				validationMessage.Text = GettextCatalog.GetString ("Name must start with a letter or number");
			} else if (txt.Any (ch => !char.IsLetterOrDigit (ch) && ch != ' ')) {
				validationMessage.Text = GettextCatalog.GetString ("Name must contain only letters, numbers and spaces");
			} else if (existingLayouts.Contains (layoutName.Text)) {
				validationMessage.Text = GettextCatalog.GetString ("There is already a layout with that name");
			} else {
				validationMessage.Text = GettextCatalog.GetString ("Layout name is valid");
				newButton.Sensitive = true;
				return;
			}
			
			newButton.Sensitive = false;
		}
	}
}