private ViewerNode(XSDocument doc, XmlNode originalNode, ViewerNode parent, int occurrenceIndex = -1) { _document = doc; // ChildNodes = new List<ViewerNode>(); Attributes = new List <ViewerNode>(); NodeType = NodeType.Unknown; _originalNode = originalNode; _parent = parent; OccurrenceIndex = occurrenceIndex; Build(); }
private void createTaskPanes(XSDocument Doc) { _tabCtrl.Content = null; if (Doc != null) { Editor = new EditorFrame(Doc, Data); _tabCtrl.Content = Editor; if (Doc.Filename != null && Doc.Filename.ToLower().EndsWith(".xsd")) { tabXsd.Visibility = Visibility.Visible; } else { tabXsd.Visibility = Visibility.Collapsed; } } }
public ViewerNode(XSDocument doc) : this(doc, doc.XmlDoc.DocumentElement, null) { }
public void OpenFile(string filePath) { if (!allowToClose()) { return; } if (!NEW.Equals(filePath) && !filePath.StartsWith(NAMEDPIPE) && !CLIPBOARD.Equals(filePath) && !FileHelper.FileExists(filePath)) { MessageBox.Show(this, string.Format("The file '{0}' does not exist", filePath), "File does not exist", MessageBoxButton.OK, MessageBoxImage.Exclamation); return; } try { _watcher.EnableRaisingEvents = false; Mouse.OverrideCursor = Cursors.Wait; XSDocument doc; if (filePath.StartsWith(NAMEDPIPE)) { string pipeName = filePath.Substring(NAMEDPIPE.Length); string clip = NamedPipeHelper.Read(pipeName); if (clip.Length > MAX_FILESIZE_IN_BYTES) { if (!openTooLargeFiles()) { return; } } doc = new XSDocument(clip); } else if (CLIPBOARD.Equals(filePath)) { Debug.Assert(Clipboard.ContainsText(), "Already checked"); string clip = Clipboard.GetText(); if (clip.Length > MAX_FILESIZE_IN_BYTES) { if (!openTooLargeFiles()) { return; } } doc = new XSDocument(clip); } else if (NEW.Equals(filePath)) { doc = new XSDocument(@"<?xml version=""1.0"" encoding=""utf-8"" ?>"); } else { if (new FileInfo(filePath).Length > MAX_FILESIZE_IN_BYTES) { if (!openTooLargeFiles()) { return; } } //open file, even if it is locked by another process using (FileStream fileStream = new FileStream(filePath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite)) using (StreamReader streamReader = new StreamReader(fileStream)) { string xml = streamReader.ReadToEnd(); doc = new XSDocument(xml, null, filePath); } XSConfiguration.Instance.Config.AddRecentlyUsedFile(filePath); if (XSConfiguration.Instance.Config.WatchCurrentFileForChanges) { _watcher.Dispose(); _watcher = new FileSystemWatcher { Path = Path.GetDirectoryName(filePath), NotifyFilter = NotifyFilters.LastAccess | NotifyFilters.LastWrite, Filter = Path.GetFileName(filePath), IncludeSubdirectories = false }; _watcher.Changed += OnChanged; _watcher.EnableRaisingEvents = true; } } createTaskPanes(doc); setFilename(); _ribbongroupExternalTools.IsEnabled = true; //http://stackoverflow.com/questions/3109080/focus-on-textbox-when-usercontrol-change-visibility Dispatcher.BeginInvoke((Action) delegate { Keyboard.Focus(Editor.XmlEditor); bool success = Editor.XmlEditor.Focus(); // Debug.Assert(success); }, DispatcherPriority.Render); } catch (Exception e) { Mouse.OverrideCursor = null; MessageBox.Show(this, string.Format("Cannot open file '{1}': {0}", e.Message, filePath), "Error", MessageBoxButton.OK, MessageBoxImage.Error); } finally { Mouse.OverrideCursor = null; } }