public void DisplaySource( string sourceFilePath, string text, int lineNumber = 0, int column = 0, Action preprocess = null, bool displayPath = true) { var existing = Find(sourceFilePath); if (existing != null) { Visibility = Visibility.Visible; tabControl.SelectedItem = existing; var textViewer = existing.Content as TextViewerControl; if (textViewer != null) { textViewer.SetPathDisplay(displayPath); if (textViewer.Text != text) { textViewer.SetText(text); } textViewer.DisplaySource(lineNumber, column); } return; } var textViewerControl = new TextViewerControl(); textViewerControl.DisplaySource(sourceFilePath, text, lineNumber, column, preprocess); var tab = new SourceFileTab() { FilePath = sourceFilePath, Text = text }; var tabItem = new TabItem() { Tag = tab, Content = textViewerControl }; var header = new SourceFileTabHeader(tab); tabItem.Header = header; header.CloseRequested += t => { var tabItem = Tabs.FirstOrDefault(tabItem => tabItem.Tag == t); if (tabItem != null) { Tabs.Remove(tabItem); } }; tabItem.HeaderTemplate = (DataTemplate)Application.Current.Resources["SourceFileTabHeaderTemplate"]; textViewerControl.SetPathDisplay(displayPath); Tabs.Add(tabItem); tabControl.SelectedItem = tabItem; }
public SourceFileTabHeader(SourceFileTab sourceFileTab) { this.tab = sourceFileTab; Close = new Command(InvokeClose); Header = Path.GetFileName(tab.FilePath); }