From 3aa5318dd41ff7b45c783feaec7facec688ebc0e Mon Sep 17 00:00:00 2001 From: Chris Lovett Date: Thu, 12 Oct 2023 19:10:10 -0700 Subject: [PATCH] move to .NET 4.8 Add a Copy XPath command --- docs/dev/index.md | 2 +- docs/help/menus.md | 1 + src/Application/Application.csproj | 4 +- src/Application/FormMain.Designer.cs | 28 +- src/Application/FormMain.cs | 12 +- src/Application/FormMain.resx | 403 +++++++++++++----------- src/Application/app.manifest | 2 +- src/Model/XmlHelpers.cs | 20 +- src/UnitTests/window.cs | 2 +- src/Updates/Updates.xml | 6 + src/WpfApp/App.config | 2 +- src/WpfApp/packages.config | 10 +- src/XmlNotepad/XmlTreeView.cs | 26 +- src/XmlNotepad/XmlTreeViewFindTarget.cs | 60 +--- 14 files changed, 315 insertions(+), 263 deletions(-) diff --git a/docs/dev/index.md b/docs/dev/index.md index 61690f0a..8cb39f58 100644 --- a/docs/dev/index.md +++ b/docs/dev/index.md @@ -2,7 +2,7 @@ You can build and test XML Notepad using [Visual Studio 2022](https://visualstudio.microsoft.com/downloads/). It uses .NET frameworks, so be sure to install the ".NET desktop development" feature when using the Visual Studio Installer. -XML Notepad targets .NET Framework version 4.7.2 which is the default target for VS 2022. +XML Notepad targets .NET Framework version 4.8. ### Coding Guidelines diff --git a/docs/help/menus.md b/docs/help/menus.md index a6a6ed40..df231cc1 100644 --- a/docs/help/menus.md +++ b/docs/help/menus.md @@ -24,6 +24,7 @@ The edit menu contains the following commands: - **Redo** Reverses the last undo operation. - **Cut** Copy the selected node to the clipboard (and its children) and remove that node from the tree. See [Clipboard support](clipboard.md). - **Copy** Copy the selected node to the clipboard (and its children). +- **Copy XPath** Copy the XPath expression that locates the selected node. - **Paste** Parse the XML in the clipboard and create new nodes in the tree under the selected node. - **Delete** Delete the selected node. - **Insert** Insert a new node of the same type (element, attribute, processing instruction, comment, etc) as the currently selected node. This makes it easy to build a list of nodes that have the same type. diff --git a/src/Application/Application.csproj b/src/Application/Application.csproj index 23a4723b..fd2c4c16 100644 --- a/src/Application/Application.csproj +++ b/src/Application/Application.csproj @@ -288,9 +288,9 @@ - + False - Microsoft .NET Framework 4.7.2 %28x86 and x64%29 + Microsoft .NET Framework 4.8 %28x86 and x64%29 true diff --git a/src/Application/FormMain.Designer.cs b/src/Application/FormMain.Designer.cs index 9d6a16a3..582098c9 100644 --- a/src/Application/FormMain.Designer.cs +++ b/src/Application/FormMain.Designer.cs @@ -247,6 +247,7 @@ private void InitializeComponent() this.openToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.reloadToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.openSettingsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.openXmlDiffStylesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.toolStripMenuItem1 = new System.Windows.Forms.ToolStripSeparator(); this.saveToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); this.saveAsToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); @@ -368,7 +369,8 @@ private void InitializeComponent() this._dynamicHelpViewer = new XmlNotepad.XsltControl(); this.statusStrip1 = new System.Windows.Forms.StatusStrip(); this.toolStripStatusLabel1 = new System.Windows.Forms.ToolStripStatusLabel(); - this.openXmlDiffStylesToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.copyXPathToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem(); + this.ctxMenuItemCopyXPath = new System.Windows.Forms.ToolStripMenuItem(); this.contextMenu1.SuspendLayout(); this.menuStrip1.SuspendLayout(); this.toolStrip1.SuspendLayout(); @@ -389,6 +391,7 @@ private void InitializeComponent() this.contextMenu1.Items.AddRange(new System.Windows.Forms.ToolStripItem[] { this.ctxcutToolStripMenuItem, this.ctxMenuItemCopy, + this.ctxMenuItemCopyXPath, this.ctxMenuItemPaste, this.toolStripMenuItem13, this.deleteToolStripMenuItem1, @@ -748,6 +751,12 @@ private void InitializeComponent() this.openSettingsToolStripMenuItem.Name = "openSettingsToolStripMenuItem"; this.openSettingsToolStripMenuItem.Click += new System.EventHandler(this.openSettingsToolStripMenuItem_Click); // + // openXmlDiffStylesToolStripMenuItem + // + this.openXmlDiffStylesToolStripMenuItem.Name = "openXmlDiffStylesToolStripMenuItem"; + resources.ApplyResources(this.openXmlDiffStylesToolStripMenuItem, "openXmlDiffStylesToolStripMenuItem"); + this.openXmlDiffStylesToolStripMenuItem.Click += new System.EventHandler(this.openXmlDiffStylesToolStripMenuItem_Click); + // // toolStripMenuItem1 // this.toolStripMenuItem1.Name = "toolStripMenuItem1"; @@ -800,6 +809,7 @@ private void InitializeComponent() this.toolStripMenuItem4, this.cutToolStripMenuItem, this.copyToolStripMenuItem, + this.copyXPathToolStripMenuItem, this.pasteToolStripMenuItem, this.toolStripMenuItem5, this.deleteToolStripMenuItem, @@ -1583,11 +1593,17 @@ private void InitializeComponent() this.toolStripStatusLabel1.Name = "toolStripStatusLabel1"; resources.ApplyResources(this.toolStripStatusLabel1, "toolStripStatusLabel1"); // - // openXmlDiffStylesToolStripMenuItem + // copyXPathToolStripMenuItem // - this.openXmlDiffStylesToolStripMenuItem.Name = "openXmlDiffStylesToolStripMenuItem"; - resources.ApplyResources(this.openXmlDiffStylesToolStripMenuItem, "openXmlDiffStylesToolStripMenuItem"); - this.openXmlDiffStylesToolStripMenuItem.Click += new System.EventHandler(this.openXmlDiffStylesToolStripMenuItem_Click); + this.copyXPathToolStripMenuItem.Name = "copyXPathToolStripMenuItem"; + resources.ApplyResources(this.copyXPathToolStripMenuItem, "copyXPathToolStripMenuItem"); + this.copyXPathToolStripMenuItem.Click += new System.EventHandler(this.copyXPathToolStripMenuItem_Click); + // + // ctxMenuItemCopyXPath + // + this.ctxMenuItemCopyXPath.Name = "ctxMenuItemCopyXPath"; + resources.ApplyResources(this.ctxMenuItemCopyXPath, "ctxMenuItemCopyXPath"); + this.ctxMenuItemCopyXPath.Click += new System.EventHandler(this.ctxMenuItemCopyXPath_Click); // // FormMain // @@ -1623,5 +1639,7 @@ private void InitializeComponent() private ToolStripMenuItem gCCollectToolStripMenuItem; private ToolStripMenuItem goToLineToolStripMenuItem; private ToolStripMenuItem openXmlDiffStylesToolStripMenuItem; + private ToolStripMenuItem copyXPathToolStripMenuItem; + private ToolStripMenuItem ctxMenuItemCopyXPath; } } \ No newline at end of file diff --git a/src/Application/FormMain.cs b/src/Application/FormMain.cs index ede19110..d311afca 100644 --- a/src/Application/FormMain.cs +++ b/src/Application/FormMain.cs @@ -1647,7 +1647,7 @@ protected virtual void UpdateMenuState() this.toolStripButtonCut.Enabled = this.cutToolStripMenuItem.Enabled = this.ctxcutToolStripMenuItem.Enabled = hasXmlNode; this.toolStripButtonDelete.Enabled = this.deleteToolStripMenuItem.Enabled = hasSelection; - this.toolStripButtonCopy.Enabled = this.copyToolStripMenuItem.Enabled = this.ctxMenuItemCopy.Enabled = hasXmlNode; + this.toolStripButtonCopy.Enabled = this.copyToolStripMenuItem.Enabled = this.ctxMenuItemCopy.Enabled = this.copyXPathToolStripMenuItem.Enabled = this.ctxMenuItemCopyXPath.Enabled = hasXmlNode; this.duplicateToolStripMenuItem.Enabled = hasXmlNode; this.changeToAttributeContextMenuItem.Enabled = this.changeToAttributeToolStripMenuItem1.Enabled = hasSelection; @@ -2223,6 +2223,16 @@ private void toolStripButtonCopy_Click(object sender, EventArgs e) this.xmlTreeView1.Copy(); } + private void copyXPathToolStripMenuItem_Click(object sender, EventArgs e) + { + this.xmlTreeView1.CopyXPath(); + } + + private void ctxMenuItemCopyXPath_Click(object sender, EventArgs e) + { + this.xmlTreeView1.CopyXPath(); + } + private void toolStripButtonPaste_Click(object sender, EventArgs e) { SelectTreeView(); diff --git a/src/Application/FormMain.resx b/src/Application/FormMain.resx index db1583db..bcbaf83d 100644 --- a/src/Application/FormMain.resx +++ b/src/Application/FormMain.resx @@ -134,21 +134,6 @@ 231, 17 - - 561, 17 - - - True - - - 192, 402 - - - contextMenu1 - - - System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -196,6 +181,12 @@ Copy the selected node onto the clipboard + + 191, 22 + + + Copy &XPath + iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8 @@ -285,6 +276,87 @@ C&hange To + + 188, 6 + + + F12 + + + 191, 22 + + + &Goto Definition + + + 188, 6 + + + 191, 22 + + + &Element + + + 191, 22 + + + &Attribute + + + 191, 22 + + + &Text + + + 191, 22 + + + Co&mment + + + 191, 22 + + + C&DATA + + + 191, 22 + + + Pr&ocessing Instruction + + + 188, 6 + + + 191, 22 + + + Expa&nd + + + 191, 22 + + + Collap&se + + + 561, 17 + + + True + + + 192, 446 + + + contextMenu1 + + + System.Windows.Forms.ContextMenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + 191, 22 @@ -330,27 +402,6 @@ Change the selected node into an XML processing instruction - - 188, 6 - - - F12 - - - 191, 22 - - - &Goto Definition - - - 188, 6 - - - 191, 22 - - - &Element - ctxElementBeforeToolStripMenuItem @@ -381,12 +432,6 @@ &Child - - 191, 22 - - - &Attribute - ctxAttributeBeforeToolStripMenuItem @@ -417,12 +462,6 @@ &Child - - 191, 22 - - - &Text - ctxTextBeforeToolStripMenuItem @@ -450,12 +489,6 @@ &Child - - 191, 22 - - - Co&mment - ctxCommentBeforeToolStripMenuItem @@ -483,12 +516,6 @@ &Child - - 191, 22 - - - C&DATA - ctxCdataBeforeToolStripMenuItem @@ -516,12 +543,6 @@ &Child - - 191, 22 - - - Pr&ocessing Instruction - ctxPIBeforeToolStripMenuItem @@ -549,24 +570,42 @@ &Child - - 188, 6 + + 0, 0 + + + 0, 0 - - 191, 22 + + True - - E&xpand + + 736, 24 - - 191, 22 + + 7 - - Collap&se + + menuStrip1 + + + menuStrip1 + + + System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + $this + + + 6 + + + 37, 20 + + + &File - - 0, 0 - newToolStripMenuItem @@ -588,7 +627,7 @@ Ctrl+N - 191, 22 + 188, 22 &New @@ -622,7 +661,7 @@ Ctrl+O - 191, 22 + 188, 22 &Open @@ -634,7 +673,7 @@ reloadToolStripMenuItem - 191, 22 + 188, 22 &Reload @@ -658,7 +697,7 @@ Open &XmlDiff Styles... - 188, 6 + 185, 6 saveToolStripMenuItem @@ -686,7 +725,7 @@ Ctrl+S - 191, 22 + 188, 22 &Save @@ -701,7 +740,7 @@ False - 191, 22 + 188, 22 Save &As... @@ -713,7 +752,7 @@ exportErrorsToolStripMenuItem - 191, 22 + 188, 22 &Export Errors... @@ -722,7 +761,7 @@ Save the errors in the Error List to an XML file. - 188, 6 + 185, 6 recentFilesToolStripMenuItem @@ -731,7 +770,7 @@ False - 191, 22 + 188, 22 Recent &Files @@ -740,13 +779,13 @@ This menu provides quick access to the last 10 XML documents you've edited. - 188, 6 + 185, 6 exitToolStripMenuItem - 191, 22 + 188, 22 E&xit @@ -754,96 +793,12 @@ Close XML notepad. - - 37, 20 - - - &File - 39, 20 &Edit - - F12 - - - 44, 20 - - - &View - - - insertToolStripMenuItem - - - 48, 20 - - - &Insert - - - windowToolStripMenuItem - - - 63, 20 - - - &Window - - - helpToolStripMenuItem - - - 44, 20 - - - &Help - - - toolStripMenuItemUpdate - - - 108, 20 - - - Update Available - - - Click here to read message about software updates. - - - 0, 0 - - - 561, 17 - - - True - - - 736, 24 - - - 7 - - - menuStrip1 - - - menuStrip1 - - - System.Windows.Forms.MenuStrip, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - - $this - - - 6 - undoToolStripMenuItem @@ -1064,7 +1019,7 @@ 212, 22 - D&uplicate + Dup&licate Clone the selected node (and its children) and insert the clone as the next sibling. @@ -1271,7 +1226,7 @@ 212, 22 - &Replace... + Repl&ace... Replace text in the current document @@ -1294,6 +1249,15 @@ GC.Collect + + F12 + + + 44, 20 + + + &View + expandAllToolStripMenuItem @@ -1417,6 +1381,15 @@ Compare the current document with another document on disk and display the differences. + + insertToolStripMenuItem + + + 48, 20 + + + &Insert + 191, 22 @@ -1624,6 +1597,15 @@ &Child + + windowToolStripMenuItem + + + 63, 20 + + + &Window + newWindowToolStripMenuItem @@ -1636,6 +1618,15 @@ Launch another instance of XML notepad + + helpToolStripMenuItem + + + 44, 20 + + + &Help + contentsToolStripMenuItem @@ -1669,6 +1660,18 @@ &About XML Notepad + + toolStripMenuItemUpdate + + + 108, 20 + + + Update Available + + + Click here to read message about software updates. + 0, 24 @@ -2077,7 +2080,7 @@ xmlTreeView1 - XmlNotepad.XmlTreeView, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.XmlTreeView, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabPageTreeView @@ -2104,7 +2107,7 @@ tabPageTreeView - XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabControlViews @@ -2119,7 +2122,7 @@ xsltViewer - XmlNotepad.XsltViewer, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.XsltViewer, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabPageHtmlView @@ -2146,7 +2149,7 @@ tabPageHtmlView - XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabControlViews @@ -2173,7 +2176,7 @@ tabControlViews - XmlNotepad.NoBorderTabControl, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.NoBorderTabControl, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 $this @@ -2200,7 +2203,7 @@ xmlTreeView1 - XmlNotepad.XmlTreeView, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.XmlTreeView, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabPageTreeView @@ -2233,7 +2236,7 @@ xsltViewer - XmlNotepad.XsltViewer, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.XsltViewer, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 tabPageHtmlView @@ -2260,7 +2263,7 @@ resizer - XmlNotepad.PaneResizer, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.PaneResizer, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 $this @@ -2284,7 +2287,7 @@ tabPageTaskList - XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 0, 0 @@ -2302,7 +2305,7 @@ tabPageDynamicHelp - XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.NoBorderTabPage, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 taskList @@ -2329,7 +2332,7 @@ _taskList - XmlNotepad.TaskList, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.TaskList, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 dynamicHelpViewer @@ -2350,7 +2353,7 @@ _dynamicHelpViewer - XmlNotepad.XsltControl, Microsoft.XmlNotepad, Version=2.9.0.6, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 + XmlNotepad.XsltControl, Microsoft.XmlNotepad, Version=2.9.0.7, Culture=neutral, PublicKeyToken=d2e0d325f5b08396 688, 17 @@ -2382,6 +2385,12 @@ 0, 17 + + 212, 22 + + + Copy &XPath + True @@ -3897,6 +3906,12 @@ System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + openXmlDiffStylesToolStripMenuItem + + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + toolStripMenuItem1 @@ -4545,10 +4560,16 @@ System.Windows.Forms.ToolStripStatusLabel, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - - openXmlDiffStylesToolStripMenuItem + + copyXPathToolStripMenuItem - + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + ctxMenuItemCopyXPath + + System.Windows.Forms.ToolStripMenuItem, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 diff --git a/src/Application/app.manifest b/src/Application/app.manifest index 8f50d880..fb2d72c3 100644 --- a/src/Application/app.manifest +++ b/src/Application/app.manifest @@ -12,7 +12,7 @@ + and .NET Framework 4.8 supports. --> diff --git a/src/Model/XmlHelpers.cs b/src/Model/XmlHelpers.cs index 4fcfc7a8..190e34f2 100644 --- a/src/Model/XmlHelpers.cs +++ b/src/Model/XmlHelpers.cs @@ -1,4 +1,5 @@ -using System.Xml; +using Microsoft.Xml; +using System.Xml; namespace XmlNotepad { @@ -137,6 +138,7 @@ public static XmlNamespaceManager GetNamespaceScope(XmlNode context) XmlNameTable nt = owner.NameTable; XmlNamespaceManager nsmgr = new XmlNamespaceManager(nt); XmlNode parent = context; + while (parent != null) { if (parent is XmlElement) @@ -157,11 +159,25 @@ public static XmlNamespaceManager GetNamespaceScope(XmlNode context) } } } - parent = parent.ParentNode; + if (parent.NodeType == XmlNodeType.Attribute) + { + parent = ((XmlAttribute)parent).OwnerElement; + } + else + { + parent = parent.ParentNode; + } } return nsmgr; } + public static string GetXPathLocation(XmlNode context, XmlNamespaceManager scope) + { + string path = null; + XPathGenerator gen = new XPathGenerator(); + return gen.GetXPath(context, scope); + } + public static bool MissingNamespace(XmlName name) { return !string.IsNullOrEmpty(name.Prefix) && string.IsNullOrEmpty(name.NamespaceUri) && diff --git a/src/UnitTests/window.cs b/src/UnitTests/window.cs index dbd722f7..929e63d8 100644 --- a/src/UnitTests/window.cs +++ b/src/UnitTests/window.cs @@ -340,7 +340,7 @@ void ReloadMenuItems(string name) { string itemName = e.Current.Name; // Debug.WriteLine(itemName); - _menuItems[itemName] = new AutomationWrapper(e); + _menuItems[itemName] = new AutomationWrapper(e); } } // and the toolbar buttons diff --git a/src/Updates/Updates.xml b/src/Updates/Updates.xml index 27a6ed9e..b367585f 100644 --- a/src/Updates/Updates.xml +++ b/src/Updates/Updates.xml @@ -10,6 +10,9 @@ 1.00:00:00 + + Move to .NET Framework version 4.8. + Add some bootstrapping help creating an empty document by providing intellisense from loaded schemas to show possible root elements and when an element is selected from the @@ -20,6 +23,9 @@ Delete the file to reset back to the original styles. The files lives in %LOCALAPPDATA%\Microsoft\Xml Notepad\XmlDiffStyles.css. + + Add a Copy XPath command that gives you the XPath location of the selected element. + Fix Schema dialog row copy so it gives you a valid xsi:schemaLocation value. diff --git a/src/WpfApp/App.config b/src/WpfApp/App.config index 359541cf..ca9f6a32 100644 --- a/src/WpfApp/App.config +++ b/src/WpfApp/App.config @@ -1,6 +1,6 @@  - + diff --git a/src/WpfApp/packages.config b/src/WpfApp/packages.config index 565c0c40..77c9f2f6 100644 --- a/src/WpfApp/packages.config +++ b/src/WpfApp/packages.config @@ -1,8 +1,8 @@  - - - - - + + + + + \ No newline at end of file diff --git a/src/XmlNotepad/XmlTreeView.cs b/src/XmlNotepad/XmlTreeView.cs index 7abae30f..4bda787f 100644 --- a/src/XmlNotepad/XmlTreeView.cs +++ b/src/XmlNotepad/XmlTreeView.cs @@ -4,6 +4,7 @@ using System.ComponentModel; using System.Diagnostics; using System.Drawing; +using System.IO; using System.Linq; using System.Security.Cryptography; using System.Windows.Forms; @@ -791,6 +792,11 @@ public void OnLoaded() this._nodeTextView.OnLoaded(); } + private void OnClipboardChanged() + { + if (ClipboardChanged != null) ClipboardChanged(this, EventArgs.Empty); + } + public void Cut() { this.Commit(); @@ -798,7 +804,7 @@ public void Cut() if (selection != null) { this.UndoManager.Push(new CutCommand(this, selection)); - if (ClipboardChanged != null) ClipboardChanged(this, EventArgs.Empty); + OnClipboardChanged(); } } @@ -809,7 +815,23 @@ public void Copy() if (selection != null) { TreeData.SetData(selection); - if (ClipboardChanged != null) ClipboardChanged(this, EventArgs.Empty); + OnClipboardChanged(); + } + } + + public void CopyXPath() + { + XmlTreeNode selection = (XmlTreeNode)this._myTreeView.SelectedNode; + if (selection != null && selection.Node != null) + { + var xnode = selection.Node; + var nsmgr = XmlHelpers.GetNamespaceScope(xnode); + string path = XmlHelpers.GetXPathLocation(xnode, nsmgr); + if (!string.IsNullOrEmpty(path)) + { + Clipboard.SetText(path); + OnClipboardChanged(); + } } } diff --git a/src/XmlNotepad/XmlTreeViewFindTarget.cs b/src/XmlNotepad/XmlTreeViewFindTarget.cs index 96847e4e..e5369df9 100644 --- a/src/XmlNotepad/XmlTreeViewFindTarget.cs +++ b/src/XmlNotepad/XmlTreeViewFindTarget.cs @@ -45,9 +45,12 @@ public XmlTreeViewFindTarget(XmlTreeView view) void FindNodes() { - XmlDocument doc = this._view.Model.Document; - if (this._doc != doc) + if (this._doc == null) + { + this._doc = doc; + } + else if (this._doc != doc) { this._doc = doc; this._nsmgr = new XmlNamespaceManager(doc.NameTable); @@ -588,57 +591,12 @@ public XmlNamespaceManager Namespaces private string GetLocation() { string path = null; - this._doc = this._view.Model.Document; - this._nsmgr = new XmlNamespaceManager(_doc.NameTable); XmlTreeNode node = this._view.SelectedNode as XmlTreeNode; - if (node != null) + if (node != null && node.Node != null) { - XmlNode xnode = node.Node; - if (xnode != null) - { - XmlNode nsctx = xnode; - if (nsctx.NodeType != XmlNodeType.Element) - { - if (nsctx.NodeType == XmlNodeType.Attribute) - { - nsctx = ((XmlAttribute)nsctx).OwnerElement; - } - else - { - nsctx = nsctx.ParentNode; - } - } - if (nsctx == null || nsctx == this._doc) - nsctx = this._doc.DocumentElement; - - foreach (XmlAttribute a in nsctx.SelectNodes("namespace::*")) - { - string prefix = (a.Prefix == "xmlns") ? a.LocalName : ""; - if (!string.IsNullOrEmpty(prefix)) - { - string ns = a.Value; - if (_nsmgr.LookupPrefix(ns) == null) - { - _nsmgr.AddNamespace(prefix, ns); - } - } - } - foreach (XmlElement child in nsctx.SelectNodes("//*[namespace-uri(.) != '']")) - { - string uri = child.NamespaceURI; - if (_nsmgr.LookupPrefix(uri) == null) - { - string prefix = child.Prefix; - if (!string.IsNullOrEmpty(prefix)) - { - _nsmgr.AddNamespace(prefix, uri); - } - } - } - - XPathGenerator gen = new XPathGenerator(); - path = gen.GetXPath(xnode, _nsmgr); - } + var xnode = node.Node; + this._nsmgr = XmlHelpers.GetNamespaceScope(xnode); + path = XmlHelpers.GetXPathLocation(xnode, _nsmgr); } return path; }