blob: bfb46c7055d08e68f8fbc020b031a7b6c32719f4 (
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
|
// 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.ToList ();
foreach (var mapping in Commands.LayoutListHandler.NameMapping)
if (existingLayouts.Contains (mapping.Key))
existingLayouts.Add (mapping.Value);
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;
}
}
}
|