Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAddContextForm.cs
More file actions
Latest commit
90 lines (76 loc) · 3 KB
/
Copy pathAddContextForm.cs
File metadata and controls
90 lines (76 loc) · 3 KB
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
usingSystem;
usingSystem.Collections.Generic;
usingEto.Drawing;
usingEto.Forms;
namespacedevtime
{
publicclassAddContextForm:Dialog<bool>
{
publicstring?ContextName{get;privateset;}
privatereadonlyTextBox_textBox;
publicAddContextForm()
{
Title="Add project";
Icon=IconLoader.LoadIcon("add.png");
Resizable=false;
_textBox=newTextBox{MaxLength=255,Width=150};
varokButton=newButton{Text="OK",Width=70,Height=23};
okButton.Click+=(sender,e)=>OkClick();
varcancelButton=newButton{Text="Cancel",Width=70,Height=23};
cancelButton.Click+=(sender,e)=>Close(false);
DefaultButton=okButton;
AbortButton=cancelButton;
varbuttonLayout=newStackLayout
{
Orientation=Orientation.Horizontal,
Spacing=5,
Items={okButton,cancelButton}
};
Content=newStackLayout
{
Padding=newPadding(10,5),
Spacing=5,
HorizontalContentAlignment=HorizontalAlignment.Stretch,
Items=
{
newLabel{Text="Project name:"},
_textBox,
newStackLayout{HorizontalContentAlignment=HorizontalAlignment.Right,Items={buttonLayout}}
}
};
}
privatevoidOkClick()
{
stringtext=_textBox.Text.Trim();
if(string.IsNullOrWhiteSpace(text))
{
MessageBox.Show(this,"The project name cannot be empty.","devtime error",MessageBoxButtons.OK,MessageBoxType.Error);
return;
}
if(text.Length>255||!IsValidProjectName(text))
{
MessageBox.Show(this,"Invalid project name (must only contain a-z, A-Z, 0-9 and underscores, with the first character not being a digit, and max 255 characters).\nPlease try another name.","devtime error",MessageBoxButtons.OK,MessageBoxType.Error);
return;
}
List<string>contexts=DB.ListTables();
if(contexts.Contains(text))
{
MessageBox.Show(this,$"A project named '{text}' already exists.\nPlease try another name.","devtime error",MessageBoxButtons.OK,MessageBoxType.Error);
return;
}
ContextName=text;
Close(true);
}
privateboolIsValidProjectName(stringstr)
{
if(string.IsNullOrEmpty(str))returnfalse;
for(inti=0;i<str.Length;++i)
{
charc=str[i];
if(i==0&&char.IsDigit(c))returnfalse;
if(!char.IsLetterOrDigit(c)&&c!='_')returnfalse;
}
returntrue;
}
}
}