Subversion Repositories LassyPad

Compare Revisions

Ignore whitespace Rev 8 → Rev 9

/LassyPad/bin/Debug/LassyPad.exe
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/LassyPad/bin/Debug/LassyPad.pdb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/LassyPad/obj/x86/Debug/LassyPad.exe
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/LassyPad/obj/x86/Debug/LassyPad.csproj.GenerateResource.Cache
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/LassyPad/obj/x86/Debug/LassyPad.pdb
Cannot display: file marked as a binary type.
svn:mime-type = application/octet-stream
/LassyPad/MainForm.Designer.cs
66,6 → 66,7
this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editorToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.wordWrapToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.syntaxHighlightingToolStripMenuItem = new System.Windows.Forms.ToolStripComboBox();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.saveFileDialog1 = new System.Windows.Forms.SaveFileDialog();
this.tabControl = new System.Windows.Forms.TabControl();
356,7 → 357,8
// editorToolStripMenuItem
//
this.editorToolStripMenuItem.DropDownItems.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.wordWrapToolStripMenuItem});
this.wordWrapToolStripMenuItem,
this.syntaxHighlightingToolStripMenuItem});
this.editorToolStripMenuItem.Name = "editorToolStripMenuItem";
this.editorToolStripMenuItem.Size = new System.Drawing.Size(47, 20);
this.editorToolStripMenuItem.Text = "Editor";
366,10 → 368,21
this.wordWrapToolStripMenuItem.Checked = true;
this.wordWrapToolStripMenuItem.CheckState = System.Windows.Forms.CheckState.Checked;
this.wordWrapToolStripMenuItem.Name = "wordWrapToolStripMenuItem";
this.wordWrapToolStripMenuItem.Size = new System.Drawing.Size(140, 22);
this.wordWrapToolStripMenuItem.Size = new System.Drawing.Size(237, 22);
this.wordWrapToolStripMenuItem.Text = "Word Wrap";
this.wordWrapToolStripMenuItem.Click += new System.EventHandler(this.WordWrapToolStripMenuItemClick);
//
// syntaxHighlightingToolStripMenuItem
//
this.syntaxHighlightingToolStripMenuItem.Enabled = false;
this.syntaxHighlightingToolStripMenuItem.Items.AddRange(new object[] {
"None",
"Auto-Detect"});
this.syntaxHighlightingToolStripMenuItem.Name = "syntaxHighlightingToolStripMenuItem";
this.syntaxHighlightingToolStripMenuItem.Size = new System.Drawing.Size(177, 21);
this.syntaxHighlightingToolStripMenuItem.Text = "Syntax Highlighting";
this.syntaxHighlightingToolStripMenuItem.SelectedIndexChanged += new System.EventHandler(this.SyntaxHighlightingToolStripMenuItemSelectedIndexChanged);
//
// openFileDialog1
//
this.openFileDialog1.FileName = "openFileDialog1";
389,6 → 402,7
this.tabControl.SelectedIndex = 0;
this.tabControl.Size = new System.Drawing.Size(502, 330);
this.tabControl.TabIndex = 0;
this.tabControl.SelectedIndexChanged += new System.EventHandler(this.TabControlSelectedIndexChanged);
//
// welcomeTab
//
423,6 → 437,7
//
// editorView
//
this.editorView.AcceptsTab = true;
this.editorView.BorderStyle = System.Windows.Forms.BorderStyle.None;
this.editorView.ContextMenuStrip = this.editorMenuStrip;
this.editorView.DetectUrls = false;
532,8 → 547,8
//
// toolStripContainer1.TopToolStripPanel
//
this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.formatBar);
this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.fileBar);
this.toolStripContainer1.TopToolStripPanel.Controls.Add(this.formatBar);
//
// MainForm
//
566,6 → 581,7
this.ResumeLayout(false);
this.PerformLayout();
}
private System.Windows.Forms.ToolStripComboBox syntaxHighlightingToolStripMenuItem;
private System.Windows.Forms.ToolStripButton toolStripButton9;
private System.Windows.Forms.ToolStripButton textColourF;
private System.Windows.Forms.ColorDialog colorDialog1;
/LassyPad/MainForm.cs
18,13 → 18,52
/// </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;
34,7 → 73,15
public void save()
{
rtfBox.SaveFile(loc);
if (loc.EndsWith(".rtf"))
rtfBox.SaveFile(loc);
else
{
string str = rtfBox.Rtf;
rtfBox.Rtf = rtfBox.Text;
rtfBox.SaveFile(loc);
rtfBox.Rtf = str;
}
saved = true;
}
44,19 → 91,51
{
rtfBox.LoadFile(loc);
saved = true;
if (loc.EndsWith(".rtf"))
isRtf = true;
else
isRtf = false;
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "Load Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
return false;
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;
}
}
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;
94,6 → 173,7
public void initAll()
{
initTreeView();
loadSyntaxes();
}
public void initTreeView()
107,6 → 187,42
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)
173,6 → 289,10
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)
184,6 → 304,10
{
editorView.Rtf = files[i].rtfBox.Rtf;
curFileID = i;
if (files[curFileID].isRtf)
syntaxHighlightingToolStripMenuItem.Enabled = false;
else
syntaxHighlightingToolStripMenuItem.Enabled = true;
return;
}
}
207,6 → 331,7
{
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;
}
460,5 → 585,68
{
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;
}
}
}
}
}
}