public void OpenSourceFile(List <CodeRecord> recs) { if (recs.Count == 0) { return; } var filename = recs [0].SourceFile; var origfile = filename; var fbname = System.IO.Path.GetFileName(filename); if (openFiles.Contains(filename)) { return; } if (fsmap.SourceMap.ContainsKey(filename)) { filename = fsmap.SourceMap[filename]; } while (!File.Exists(filename)) { var fc = new FileChooserDialog("Locate source file " + origfile, this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Select", ResponseType.Apply); fc.Filter = new Gtk.FileFilter() { Name = fbname }; fc.Filter.AddPattern(fbname); fc.Response += (o, args) => { Console.Error.WriteLine(fc.Filename); fc.Hide(); }; fc.Run(); if (fc.Filename != null) { filename = System.IO.Path.Combine(fc.Filename, fbname); } else { return; } } fsmap.AddMapping(origfile, filename); openFiles.Add(origfile); SourceLanguage language = sourceManager.GetLanguage("c-sharp"); var buf = new SourceBuffer(language); TextTag visitedOnce = new TextTag("visited_once") { Background = VisitedOnceBG }; TextTag visitedMore = new TextTag("visited_more") { Background = VisitedMoreBG }; buf.TagTable.Add(visitedOnce); buf.TagTable.Add(visitedMore); buf.HighlightSyntax = true; buf.Text = System.IO.File.ReadAllText(filename); var page = new SourcePage(); var sv = new SourceView(buf); // sv.ScrollToIter (buf.GetIterAtLineOffset (22, 0), 1.1, false, 0.0, 0.0); sv.HighlightCurrentLine = true; sv.Editable = false; sv.ShowLineNumbers = true; var fp = System.IO.Path.GetFullPath(filename); page.Window.Add(sv); page.SetHeadingText(fp); page.SetSubHeadingText(""); var fname = System.IO.Path.GetFileName(filename); var tab = CloserTabLabel.InsertTabPage(notebook1, page, fname); tab.CloseKeyData = filename; page.ShowAll(); int total_lines = 0; int covered_lines = 0; buf.Text = File.ReadAllText(filename); foreach (var rec in recs) { RenderCoverage(buf, rec); total_lines += rec.GetLines().Length; covered_lines += rec.GetHits(); } double cov = (1.0 * covered_lines) / total_lines; page.SetCoverage(cov); notebook1.Page = notebook1.NPages - 1; sourceviews [filename] = sv; }
public void OpenSourceFile (List<CodeRecord> recs) { if (recs.Count == 0) return; var filename = recs [0].SourceFile; var origfile = filename; var fbname = System.IO.Path.GetFileName(filename); if (openFiles.Contains (filename)) return; if ( fsmap.SourceMap.ContainsKey( filename ) ){ filename = fsmap.SourceMap[filename]; } while (!File.Exists(filename)) { var fc = new FileChooserDialog("Locate source file " + origfile, this, FileChooserAction.SelectFolder, "Cancel", ResponseType.Cancel, "Select", ResponseType.Apply); fc.Filter = new Gtk.FileFilter(){ Name = fbname }; fc.Filter.AddPattern( fbname ); fc.Response += (o, args) => { Console.Error.WriteLine( fc.Filename ); fc.Hide(); }; fc.Run(); if ( fc.Filename != null ){ filename = System.IO.Path.Combine( fc.Filename, fbname ); } else { return; } } fsmap.AddMapping( origfile, filename ); openFiles.Add (origfile); SourceLanguage language = sourceManager.GetLanguage ("c-sharp"); var buf = new SourceBuffer (language); TextTag visitedOnce = new TextTag ("visited_once") { Background = VisitedOnceBG }; TextTag visitedMore = new TextTag ("visited_more") { Background = VisitedMoreBG }; buf.TagTable.Add (visitedOnce); buf.TagTable.Add (visitedMore); buf.HighlightSyntax = true; buf.Text = System.IO.File.ReadAllText (filename); var page = new SourcePage (); var sv = new SourceView (buf); // sv.ScrollToIter (buf.GetIterAtLineOffset (22, 0), 1.1, false, 0.0, 0.0); sv.HighlightCurrentLine = true; sv.Editable = false; sv.ShowLineNumbers = true; var fp = System.IO.Path.GetFullPath (filename); page.Window.Add (sv); page.SetHeadingText (fp); page.SetSubHeadingText (""); var fname = System.IO.Path.GetFileName (filename); var tab = CloserTabLabel.InsertTabPage (notebook1, page, fname); tab.CloseKeyData = filename; page.ShowAll (); int total_lines = 0; int covered_lines = 0; buf.Text = File.ReadAllText (filename); foreach (var rec in recs) { RenderCoverage (buf, rec); total_lines += rec.GetLines().Length; covered_lines += rec.GetHits(); } double cov = (1.0 * covered_lines) / total_lines; page.SetCoverage (cov); notebook1.Page = notebook1.NPages - 1; sourceviews [filename] = sv; }