18,52 → 18,13 |
/// </summary> |
public partial class MainForm : Form |
{ |
|
public class word |
{ |
public Color colour; |
public List<string> words; |
|
public word(Color colourN, string wordsN) |
{ |
colour = colourN; |
words = new List<string>(); |
string[] tempWords = wordsN.Split(','); |
for (int i = 0; i < tempWords.Length; i++) |
words.Add(tempWords[i]); |
} |
|
} |
|
public class comment |
{ |
public Color colour; |
public string start; |
public string end; |
|
public comment(Color colourN, string startN, string endN) |
{ |
colour = colourN; |
start = startN; |
end = endN; |
} |
|
public comment(Color colourN, string startN) |
{ |
colour = colourN; |
start = startN; |
end = "\n"; |
} |
} |
|
public class rtfFile |
{ |
public string loc; |
public RichTextBox rtfBox; |
public bool saved; |
public bool isRtf; |
public int syntax; |
|
|
public rtfFile(string locN) |
{ |
loc = locN; |
73,15 → 34,7 |
|
public void save() |
{ |
if (loc.EndsWith(".rtf")) |
rtfBox.SaveFile(loc); |
else |
{ |
string str = rtfBox.Rtf; |
rtfBox.Rtf = rtfBox.Text; |
rtfBox.SaveFile(loc); |
rtfBox.Rtf = str; |
} |
rtfBox.SaveFile(loc); |
saved = true; |
} |
|
91,51 → 44,19 |
{ |
rtfBox.LoadFile(loc); |
saved = true; |
if (loc.EndsWith(".rtf")) |
isRtf = true; |
else |
isRtf = false; |
} |
catch (Exception ex) |
{ |
try |
{ |
System.IO.StreamReader reader = new System.IO.StreamReader(loc); |
rtfBox.Text = reader.ReadToEnd(); |
// MessageBox.Show("File not loaded as RTF: " + ex.Message, "Load Notice", MessageBoxButtons.OK, MessageBoxIcon.Warning); |
isRtf = false; |
} |
catch (Exception ex2) |
{ |
MessageBox.Show(ex2.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
return false; |
} |
MessageBox.Show(ex.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error); |
return false; |
} |
return true; |
} |
} |
|
public class syntax |
{ |
|
public string id; |
public List<word> words; |
public List<comment> comments; |
|
public syntax(string idN) |
{ |
id = idN; |
words = new List<MainForm.word>(); |
comments = new List<MainForm.comment>(); |
} |
|
} |
|
public List<rtfFile> files = new List<rtfFile>(); |
public int curFileID; |
|
public List<syntax> syntaxes = new List<syntax>(); |
|
public int selectionStart; |
public int selectionLength; |
|
173,7 → 94,6 |
public void initAll() |
{ |
initTreeView(); |
loadSyntaxes(); |
} |
|
public void initTreeView() |
187,42 → 107,6 |
treeView.Nodes.Add("Files", "Files"); |
} |
|
public void loadSyntaxes() |
{ |
System.IO.StreamReader reader = new System.IO.StreamReader("data/syntaxes.dat"); |
string r = reader.ReadToEnd(); |
string[] data = r.Split('\n'); |
string[] d, d2; |
|
for (int i = 0; i < data.Length; i++) |
{ |
data[i] = data[i].Replace("\r", ""); |
if (data[i].EndsWith(":")) |
{ |
syntaxes.Add(new syntax(data[i].Substring(0, data[i].Length - 1))); |
syntaxHighlightingToolStripMenuItem.Items.Add(data[i].Substring(0, data[i].Length - 1)); |
} |
else |
{ |
d = data[i].Split(' '); |
switch (d[0]) |
{ |
case ("word"): |
{ |
if (d.Length == 3) |
syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromName(d[1]), d[2])); |
else if (d.Length == 5) |
{ |
d2 = d[1].Split(','); |
syntaxes[syntaxes.Count - 1].words.Add(new word(Color.FromArgb(int.Parse(d2[0]), int.Parse(d2[1]), int.Parse(d2[2])), d[2])); |
} |
break; |
} |
} |
} |
} |
} |
|
void TreeViewNodeMouseClick(object sender, TreeNodeMouseClickEventArgs e) |
{ |
if (e.Node.Level == 0) |
289,10 → 173,6 |
tabControl.SelectedIndex = 1; |
editorView.Rtf = files[fileID].rtfBox.Rtf; |
curFileID = fileID; |
if (files[curFileID].isRtf) |
syntaxHighlightingToolStripMenuItem.Enabled = false; |
else |
syntaxHighlightingToolStripMenuItem.Enabled = true; |
} |
|
public void showFile(string filename) |
304,10 → 184,6 |
{ |
editorView.Rtf = files[i].rtfBox.Rtf; |
curFileID = i; |
if (files[curFileID].isRtf) |
syntaxHighlightingToolStripMenuItem.Enabled = false; |
else |
syntaxHighlightingToolStripMenuItem.Enabled = true; |
return; |
} |
} |
331,7 → 207,6 |
{ |
files.Add(new rtfFile("NewFile" + i.ToString() + ".rtf")); |
treeView.Nodes["Files"].Nodes.Add("NewFile" + i.ToString() + ".rtf", "NewFile" + i.ToString() + ".rtf"); |
files[files.Count - 1].isRtf = true; |
showFile(files.Count - 1); |
return; |
} |
585,68 → 460,5 |
{ |
saveAll(); |
} |
|
void TabControlSelectedIndexChanged(object sender, EventArgs e) |
{ |
if (tabControl.SelectedIndex == 1 && files.Count == 0) |
{ |
newFile(); |
} |
} |
|
void SyntaxHighlightingToolStripMenuItemSelectedIndexChanged(object sender, EventArgs e) |
{ |
|
// clear own highlighting |
files[curFileID].rtfBox.Rtf = editorView.Text; |
files[curFileID].syntax = -1; |
|
// sort out new stuff |
if (syntaxHighlightingToolStripMenuItem.SelectedIndex == 1) |
{ |
for (int i = 0; i < syntaxes.Count; i++) |
{ |
if (files[curFileID].loc.EndsWith(syntaxes[i].id)) |
{ |
files[curFileID].syntax = i; |
break; |
} |
} |
} |
else |
files[curFileID].syntax = syntaxHighlightingToolStripMenuItem.SelectedIndex - 2; |
|
applySyntax(curFileID); |
showFile(curFileID); |
|
} |
|
public void applySyntax(int fileID) |
{ |
if (files[fileID].isRtf) |
return; |
|
if (files[fileID].syntax == -1) |
files[fileID].rtfBox.Rtf = files[fileID].rtfBox.Text; |
else |
{ |
int pos; |
string[] data = files[fileID].rtfBox.Text.Split(new char[] { ' ', '\n' }); |
for (int i = 0; i < syntaxes[files[fileID].syntax].words.Count; i++) |
{ |
pos = 0; |
for (int j = 0; j < data.Length; j++) |
{ |
if (syntaxes[files[fileID].syntax].words[i].words.Contains(data[j])) |
{ |
files[fileID].rtfBox.Select(pos, data[j].Length); |
files[fileID].rtfBox.SelectionColor = syntaxes[files[fileID].syntax].words[i].colour; |
} |
pos += data[j].Length + 1; |
} |
} |
} |
|
} |
} |
} |