From 8533781affde6f12922422cb5ff1f947432d6779 Mon Sep 17 00:00:00 2001 From: lyeeedar Date: Tue, 7 Jan 2020 16:40:47 +0000 Subject: [PATCH] Fix a bug with visibleif and threading meaning that updates didnt get processed. Stop the duplicate popups prompting to reload a document. You now only get prompted the next time you view that document. Graph item positions are now saved relative to the first root item. --- StructuredXmlEditor/Data/DataItem.cs | 7 +++++- StructuredXmlEditor/Data/Document.cs | 1 + StructuredXmlEditor/Data/Workspace.cs | 23 ++++++++++++------- .../Definition/GraphCollectionDefinition.cs | 6 +++-- .../Definition/GraphStructDefinition.cs | 6 +++-- StructuredXmlEditor/MainWindow.xaml.cs | 8 +++++++ 6 files changed, 38 insertions(+), 13 deletions(-) diff --git a/StructuredXmlEditor/Data/DataItem.cs b/StructuredXmlEditor/Data/DataItem.cs index 33b9e78..24cedb1 100644 --- a/StructuredXmlEditor/Data/DataItem.cs +++ b/StructuredXmlEditor/Data/DataItem.cs @@ -162,7 +162,7 @@ public bool IsVisibleFromBindings { if (VisibleIfStatements.Count == 0) return true; - UpdateVisibleIfBinding(); + //UpdateVisibleIfBinding(); foreach (var group in VisibleIfStatements) { @@ -567,6 +567,11 @@ public void UpdateVisibleIfBinding() if (Definition.VisibleIf != null) { + if (Definition.VisibleIf.Contains('(')) + { + throw new Exception("VisibleIf doesnt support brackets yet"); + } + // decompose into or groups var orgroups = Definition.VisibleIf.Split(new string[] { "||" }, StringSplitOptions.RemoveEmptyEntries); foreach (var orgroup in orgroups) diff --git a/StructuredXmlEditor/Data/Document.cs b/StructuredXmlEditor/Data/Document.cs index e4a15ff..7b0075e 100644 --- a/StructuredXmlEditor/Data/Document.cs +++ b/StructuredXmlEditor/Data/Document.cs @@ -21,6 +21,7 @@ public class Document : NotifyPropertyChanged public UndoRedoManager UndoRedo { get; set; } = new UndoRedoManager(); public Workspace Workspace { get; set; } public bool IsBackup { get; set; } + public bool NeedsReload { get; set; } //----------------------------------------------------------------------- public List MultieditDocs { get; set; } diff --git a/StructuredXmlEditor/Data/Workspace.cs b/StructuredXmlEditor/Data/Workspace.cs index 6387001..b7e4371 100644 --- a/StructuredXmlEditor/Data/Workspace.cs +++ b/StructuredXmlEditor/Data/Workspace.cs @@ -37,6 +37,20 @@ public Document Current set { m_current = value; + + if (m_current != null && m_current.NeedsReload) + { + m_current.NeedsReload = false; + + string response = Message.Show("This document changed on disk, do you want to reload it? Clicking Yes will discard any local changes.", "Document Changed On Disk", "Yes", "No"); + + if (response == "Yes") + { + m_current.Close(true); + Current = Open(m_current.Path); + } + } + RaisePropertyChangedEvent(); } } @@ -258,14 +272,7 @@ public void SetupFileChangeHandlers() var open = Documents.FirstOrDefault(e => e.Path == path); if (open != null) { - Current = open; - string response = Message.Show("This document changed on disk, do you want to reload it? Clicking Yes will discard any local changes.", "Document Changed On Disk", "Yes", "No"); - - if (response == "Yes") - { - open.Close(true); - Open(path); - } + open.NeedsReload = true; } ProjectViewTool.Instance.Add(path); diff --git a/StructuredXmlEditor/Definition/GraphCollectionDefinition.cs b/StructuredXmlEditor/Definition/GraphCollectionDefinition.cs index 9a528f9..17d8f3f 100644 --- a/StructuredXmlEditor/Definition/GraphCollectionDefinition.cs +++ b/StructuredXmlEditor/Definition/GraphCollectionDefinition.cs @@ -164,8 +164,10 @@ public override void DoSaveData(XElement parent, DataItem item) XElement root = new XElement(Name); - root.Add(new XAttribute(MetaNS + "X", ci.X)); - root.Add(new XAttribute(MetaNS + "Y", ci.Y)); + var relativeToNode = item.DataModel.RootItems.First(e => e.Definition is GraphNodeDefinition) as GraphNodeItem; + + root.Add(new XAttribute(MetaNS + "X", ci.X - relativeToNode.X)); + root.Add(new XAttribute(MetaNS + "Y", ci.Y - relativeToNode.Y)); if (ci.Comment != null) root.Add(new XAttribute(MetaNS + "Comment", ci.Comment)); if (ci.LinkParents.Count > 1 || ci.DataModel.FlattenData) diff --git a/StructuredXmlEditor/Definition/GraphStructDefinition.cs b/StructuredXmlEditor/Definition/GraphStructDefinition.cs index 2621483..da48798 100644 --- a/StructuredXmlEditor/Definition/GraphStructDefinition.cs +++ b/StructuredXmlEditor/Definition/GraphStructDefinition.cs @@ -226,8 +226,10 @@ public override void DoSaveData(XElement parent, DataItem item) var el = new XElement(name); parent.Add(el); - el.Add(new XAttribute(MetaNS + "X", si.X)); - el.Add(new XAttribute(MetaNS + "Y", si.Y)); + var relativeToNode = item.DataModel.RootItems.First(e => e.Definition is GraphNodeDefinition) as GraphNodeItem; + + el.Add(new XAttribute(MetaNS + "X", si.X - relativeToNode.X)); + el.Add(new XAttribute(MetaNS + "Y", si.Y - relativeToNode.Y)); if (si.Comment != null) el.Add(new XAttribute(MetaNS + "Comment", si.Comment)); if (string.IsNullOrWhiteSpace(ChildAsGUID) && (si.LinkParents.Count > 1 || si.DataModel.FlattenData)) diff --git a/StructuredXmlEditor/MainWindow.xaml.cs b/StructuredXmlEditor/MainWindow.xaml.cs index 426ef9d..1af1066 100644 --- a/StructuredXmlEditor/MainWindow.xaml.cs +++ b/StructuredXmlEditor/MainWindow.xaml.cs @@ -55,6 +55,14 @@ public MainWindow() VersionInfo.CheckForUpdates(Workspace); })); }; + + Activated += (e, args) => + { + if (Workspace != null) + { + Workspace.Current = Workspace.Current; + } + }; } protected override void OnPreviewKeyDown(KeyEventArgs e)