private void openFile(string file) { try { EditorPage page = new EditorPage(); page.load(file); page.Editor.Lexing.SetKeywords(3, String.Join(" ", cfg.keyWords)); List <string> list; list = page.Editor.AutoComplete.List; list.AddRange(cfg.arduinoLibs.Select(x => x.name).ToArray()); foreach (ArduinoLibrary l in cfg.arduinoLibs) { list.AddRange(l.keyWords); } list.Sort(); list = list.Distinct().ToList(); list.Sort(); page.Editor.AutoComplete.List = list; page.Show(dockPanel1, DockState.Document); mruManager.Add(file); } catch { mruManager.Remove(file); } }
private void replaceToolStripMenuItem_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { page.Editor.FindReplace.ShowReplace(); } }
private void pasteToolStripMenuItem_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { page.Editor.Clipboard.Paste(); } }
private void redoToolStripMenuItem_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { page.Editor.UndoRedo.Redo(); } }
private void printToolStripButton_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { page.Editor.Printing.PrintPreview(); } }
private void saveToolStripMenuItem_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { page.save(); mruManager.Add(page.fileName); } }
private void cobFunctions_SelectedIndexChanged(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null && cobFunctions.SelectedIndex >= 0) { FunctionListItem f = (FunctionListItem)cobFunctions.SelectedItem; page.Editor.GoTo.Position(f.pos); } }
private void cobFunctions_Click(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { cobFunctions.Items.Clear(); List <FunctionListItem> functions = EditorPage.parseFunctions(page.Editor.Text); cobFunctions.Items.AddRange(functions.ToArray()); } }
private void dockPanel1_ActiveDocumentChanged(object sender, EventArgs e) { EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { cobFunctions.SelectedIndex = -1; cobFunctions.SelectedText = ""; cobFunctions.Items.Clear(); List <FunctionListItem> functions = EditorPage.parseFunctions(page.Editor.Text); cobFunctions.Items.AddRange(functions.ToArray()); } }
private void createNewEditor() { EditorPage page = new EditorPage(); page.Editor.Lexing.SetKeywords(3, String.Join(" ", cfg.keyWords)); List <string> list; list = page.Editor.AutoComplete.List; list.AddRange(cfg.keyWords.ToArray()); list.Sort(); page.Editor.AutoComplete.List = list; page.Text = "new File"; page.Show(dockPanel1, DockState.Document); }
// we want to capture F1 presses on the mainform to load the help page protected override bool ProcessCmdKey(ref Message msg, Keys keyData) { if (keyData == Keys.F1) { char[] badChars = new char[] { ' ', '\t', '\\', '/', '\n', '\r', '(', ')', '{', '}' }; EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null && page.IsActivated) { string selection = page.Editor.Selection.Text; // check if a word is selected if (selection == string.Empty) { // nothing selected so try to find beginning and end of current word int pos = page.Editor.NativeInterface.GetCurrentPos(); int start = pos; if (badChars.Contains(page.Editor.NativeInterface.GetCharAt(start))) { start--; } while (!badChars.Contains(page.Editor.NativeInterface.GetCharAt(start))) { start--; } int stop = page.Editor.NativeInterface.WordEndPosition(pos, true); selection = page.Editor.Text.Substring(start, stop - start); selection = selection.Trim(badChars); } // replace dots by space for better googeling string search = selection.Replace(".", "%20"); hlp.loadReference(search); } return(true); } return(base.ProcessCmdKey(ref msg, keyData)); }
private void buildToolStripMenuItem_Click(object sender, EventArgs e) { if (bwCompiler.IsBusy) { return; } if (cobBoard.SelectedIndex < 0 || (cobCPU.Items.Count > 0 && cobCPU.SelectedIndex < 0)) { MessageBox.Show("Please select platform / processor", "Build Error", MessageBoxButtons.OK, MessageBoxIcon.Error); return; } EditorPage page = dockPanel1.ActiveDocument as EditorPage; if (page != null) { if (!page.save()) { setListBox1("Could not save " + page.fileName, Color.Red); } outputListBox.Items.Clear(); string filename = Path.GetFileNameWithoutExtension(page.fileName); if (!new DirectoryInfo(cfg.buildPath).Name.Equals(filename)) { cfg.buildPath += filename + "/"; } _text = page.Editor.Text; ArduinoBoard board = cfg.arduinoBoards.First(b => b.name.Equals(cobBoard.SelectedItem.ToString())); bwCompiler.RunWorkerAsync(board); } }
private void bwCompiler_DoWork(object sender, DoWorkEventArgs e) { e.Result = false; ArduinoBoard board = (ArduinoBoard)e.Argument; string archive_name = Configuration.GetValidFileName(board.name + board.cpu).Replace(" ", "") + ".a"; System.Console.WriteLine("Archive Name: " + archive_name); List <ArduinoLibrary> usedLibs = new List <ArduinoLibrary>(); Regex myRegex = new Regex(@"#include [<""](\S+)[>""]", RegexOptions.None); foreach (Match myMatch in myRegex.Matches(_text)) { if (myMatch.Success) { string incName = myMatch.Groups[myMatch.Groups.Count - 1].ToString(); if (incName.Contains("/") || incName.Contains("\\")) { continue; } string libName = Path.GetFileNameWithoutExtension(incName); System.Console.WriteLine("searching for: " + libName); try { ArduinoLibrary f = cfg.arduinoLibs.First(l => l.name.Equals(libName)); System.Console.WriteLine("Found by name: " + f.name); usedLibs.Add(f); } catch { bool found = false; foreach (ArduinoLibrary l in cfg.arduinoLibs) { int idx = l.cppFiles.FindIndex(x => Path.GetFileNameWithoutExtension(x).Equals(libName)); if (idx != -1) { System.Console.WriteLine("Found by Include: " + l.name); usedLibs.Add(l); found = true; break; } } if (!found) { setListBox1("Library: " + libName + " not found, assuming system library", Color.Blue); } } } } foreach (ArduinoLibrary l in usedLibs) { setListBox1(l.name + ": " + l.path, Color.Green); } List <FunctionListItem> functions = EditorPage.parseFunctions(_text);; if (!Directory.Exists(cfg.buildPath)) { Directory.CreateDirectory(cfg.buildPath); } string[] lines = _text.Split(new string[] { "\r\n", "\n" }, StringSplitOptions.None); int lineCnt = 0; bool incomment = false; StringBuilder temp = new StringBuilder(); EditorPage page = (EditorPage)dockPanel1.ActiveDocument; temp.AppendLine("#line 1 \"" + Path.GetFileName(page.fileName) + "\""); foreach (string line in lines) { lineCnt++; string test = line.Trim(); if (test.Length < 2) { temp.AppendLine(); continue; } if (!incomment) { if (test[0] == '#' || test.StartsWith("//")) { temp.AppendLine(line); continue; } if (test.StartsWith("/*")) { temp.AppendLine(); incomment = true; continue; } break; } else { temp.AppendLine(); if (test.EndsWith("*/")) { incomment = false; } } } temp.AppendLine("#include \"Arduino.h\""); foreach (FunctionListItem func in functions) { temp.AppendLine(func.name + ";"); } temp.AppendLine("#line " + lineCnt.ToString()); // +" \"sketch.ino\"" for (int i = lineCnt - 1; i < lines.Length; i++) { temp.AppendLine(lines[i]); } File.WriteAllText(cfg.buildPath + "sketch.ino", _text); File.WriteAllText(cfg.buildPath + "sketch.cpp", temp.ToString()); string[] arduinoSrc = Directory.GetFiles(board.corePath, "*.cpp", SearchOption.AllDirectories); arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.corePath, "*.c", SearchOption.AllDirectories)).ToArray(); arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.variantPath, "*.cpp", SearchOption.TopDirectoryOnly)).ToArray(); arduinoSrc = arduinoSrc.Concat(Directory.GetFiles(board.variantPath, "*.c", SearchOption.TopDirectoryOnly)).ToArray(); string libInc = ""; foreach (ArduinoLibrary lib in usedLibs) { libInc += lib.getIncludePath(); } setListBox1("compiling sketch.cpp"); ProcessResult res = cfg.compile(cfg.buildPath + "sketch.cpp", board, libInc); if (res.returnCode == 0) { if (!File.Exists(cfg.buildPath + archive_name) || rebuildAll) { System.Console.WriteLine("Rebuilding Archive: " + cfg.buildPath + archive_name); foreach (string file in arduinoSrc) { string baseFile = Path.GetFileName(file); setListBox1("compiling: " + baseFile); res = cfg.compile(file, board); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } } foreach (ArduinoLibrary l in usedLibs) { foreach (string file in l.cppFiles) { setListBox1("compiling: " + file); res = cfg.compile(file, board, libInc); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } } } foreach (string file in arduinoSrc) { string baseFile = Path.GetFileName(file); setListBox1("linking " + baseFile + ".o"); res = cfg.linkArchive(baseFile, archive_name, board); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } } foreach (ArduinoLibrary l in usedLibs) { foreach (string file in l.cppFiles) { string baseFile = Path.GetFileName(file); setListBox1("linking " + baseFile + ".o"); res = cfg.linkArchive(baseFile, archive_name, board); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } } } } setListBox1("linking sketch.cpp.o"); res = cfg.combine("sketch.cpp", archive_name, board); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } /* * setListBox1("Creating EEPROM file"); * res = cfg.createEEProm("sketch.cpp", board); * if (res.returnCode != 0) * { * setListBox1("Error: " + res.error, Color.Red); * return; * }*/ setListBox1("Creating HEX file"); res = cfg.createHEX("sketch.cpp", board); if (res.returnCode != 0) { setListBox1("Error: " + res.error, Color.Red); return; } string size = cfg.getSize("sketch.cpp", board); if (size == String.Empty) { setListBox1("Error: " + res.error, Color.Red); return; } setListBox1(size); rebuildAll = false; setListBox1("success", Color.Green); e.Result = true; } else { setListBox1("Error: " + res.error, Color.Red); return; } }