-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathTextEditorPopup.cs
75 lines (59 loc) · 2.38 KB
/
TextEditorPopup.cs
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
// Copyright 2009-2013 Matvei Stefarov <[email protected]>
using System;
using System.IO;
using System.Linq;
using System.Windows.Forms;
namespace fCraft.ConfigGUI {
public sealed partial class TextEditorPopup : Form {
public string OriginalText { get; private set; }
public string FileName { get; private set; }
public TextEditorPopup( string fileName, string defaultValue ) {
InitializeComponent();
FileName = fileName;
Text = "Editing " + FileName;
if ( File.Exists( fileName ) ) {
OriginalText = File.ReadAllText( fileName );
} else {
OriginalText = defaultValue;
}
tText.Text = OriginalText;
lWarning.Visible = ContainsLongLines();
}
private bool ContainsLongLines() {
return tText.Lines.Any( line => ( line.Length > 62 ) );
}
private void tRules_KeyDown( object sender, KeyEventArgs e ) {
lWarning.Visible = ContainsLongLines();
}
private void bOK_Click( object sender, EventArgs e ) {
File.WriteAllText( FileName, tText.Text );
Close();
}
private ColorPicker colorPicker;
private void bInsertColor_Click( object sender, EventArgs e ) {
if ( colorPicker == null )
colorPicker = new ColorPicker( "Insert color", 0 );
if ( colorPicker.ShowDialog() == DialogResult.OK ) {
string colorToInsert = Color.Parse( colorPicker.ColorIndex );
int selectionStart = tText.SelectionStart;
tText.Paste( colorToInsert );
tText.Select( selectionStart, 2 );
tText.Focus();
}
}
private KeywordPicker keywordPicker;
private void bInsertKeyword_Click( object sender, EventArgs e ) {
if ( keywordPicker == null )
keywordPicker = new KeywordPicker();
if ( keywordPicker.ShowDialog() == DialogResult.OK ) {
int selectionStart = tText.SelectionStart;
tText.Paste( keywordPicker.Result );
tText.Select( selectionStart, keywordPicker.Result.Length );
tText.Focus();
}
}
private void bReset_Click( object sender, EventArgs e ) {
tText.Text = OriginalText;
}
}
}