/// <summary> /// Create a new interface document. /// </summary> /// <param name="game">A game object used for graphical components.</param> /// <param name="directory">Path to the directory the interface resides in.</param> public EqInterfaceContent(Game game, string directory) : base() { m_interface = EqInterface.LoadInterface(game, directory); m_files = new EqFileCollection(); TextEditorSettings settings = TextEditorSettings.Default; settings.PropertyChanged += new System.ComponentModel.PropertyChangedEventHandler(TextEditorSettingsChanged); // create the text editor m_textEditor = new TextEditor(); m_textEditor.Foreground = new SolidColorBrush(settings.Color_XML_Text); m_textEditor.Background = new SolidColorBrush(settings.Color_XML_Background); m_textEditor.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; m_textEditor.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; m_textEditor.WordWrap = TextEditorSettings.Default.WordWrap; m_textEditor.ShowLineNumbers = TextEditorSettings.Default.ShowLineNumbers; m_textEditor.TextChanged += new EventHandler(TextEditor_TextChanged); m_textEditor.TextArea.TextEntered += new TextCompositionEventHandler(TextArea_TextEntered); // load syntax highlighting ruleset using (Stream stream = new MemoryStream(EQXResources.equi_xml)) { using (XmlReader reader = new XmlTextReader(stream)) { m_textEditor.SyntaxHighlighting = HighlightingLoader.Load(reader, HighlightingManager.Instance); } } // install the folding manager m_foldingManager = FoldingManager.Install(m_textEditor.TextArea); m_foldingStrategy = new XmlFoldingStrategy(); m_treeViewRoot = new TreeViewItem(); m_treeViewRoot.Header = m_interface.Directory.Name; m_treeViewRoot.Tag = this; foreach (EqFile file in m_interface.Files) { EqFileContent fileContent = new EqFileContent(file); m_treeViewRoot.Items.Add(fileContent.TreeViewRoot); } // embed the text editor Content = m_textEditor; }
void File_Open_Clicked(object sender, RoutedEventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Filter = "EQUI Xml File (*.xml)|*.xml"; if (fileDialog.ShowDialog() ?? false) { m_interface = EqInterface.LoadInterface(m_renderSurface.Game, fileDialog.FileName); TreeViewItem tvRoot = new TreeViewItem(); tvRoot.Header = m_interface.Directory.Name; tvRoot.Tag = m_interface; foreach (EqFile file in m_interface.Files) { TreeViewItem tvFile = new TreeViewItem(); tvFile.Header = file.Filename; tvFile.Tag = file; foreach (EqElement element in file.Elements) { TreeViewItem tvElement = new TreeViewItem(); tvElement.Tag = element; BitmapImage icon; if (ms_icons.TryGetValue(element.GetType().Name, out icon)) { StackPanel sp = new StackPanel(); sp.Orientation = Orientation.Horizontal; sp.Children.Add(new Image() { Source = icon, Width = 16, Height = 16 }); sp.Children.Add(new System.Windows.Controls.Label() { Padding = new Thickness(2), Content = element.Item }); tvElement.Header = sp; } else tvElement.Header = element.Item; tvFile.Items.Add(tvElement); } tvRoot.Items.Add(tvFile); } m_interfacesView.Items.Add(tvRoot); m_renderSurface.Game.Components.Add(m_interface); } }