From 1a1bdd3f6641507d2e8347ca0b727ecd4fb67db6 Mon Sep 17 00:00:00 2001 From: Peter Villadsen Date: Sat, 1 Feb 2020 17:32:00 -0800 Subject: [PATCH] Fixed problem with scroll wheel impacting both the xquery window and the source window. --- tools/Explorer/Model.cs | 16 +++++------ tools/Explorer/Views/QueryEditor.cs | 6 ++-- tools/Explorer/Views/SourceEditor.cs | 38 ++++++++++++------------- tools/Explorer/Views/XppSourceEditor.cs | 3 ++ 4 files changed, 32 insertions(+), 31 deletions(-) diff --git a/tools/Explorer/Model.cs b/tools/Explorer/Model.cs index adb6b24..17cdc0f 100644 --- a/tools/Explorer/Model.cs +++ b/tools/Explorer/Model.cs @@ -314,13 +314,10 @@ namespace XppReasoningWpf private void QueryDirectoryChanged(object sender, FileSystemEventArgs e) { - // In this simple solution, we reread all the files in the directory - IList queries = new List(); - if (e.ChangeType == WatcherChangeTypes.Deleted) { // Check if we have one in the model and delete if so. - var entry = this.Queries.Where(q => q.Path == e.Name).FirstOrDefault(); + var entry = this.Queries.Where(q => q.Path == e.FullPath).FirstOrDefault(); if (entry != null) { App.Current.Dispatcher.Invoke(() => @@ -336,20 +333,21 @@ namespace XppReasoningWpf } else if (e.ChangeType == WatcherChangeTypes.Renamed) { - var entry = this.Queries.Where(q => q.Path == e.Name).FirstOrDefault(); + var renamedArgs = e as RenamedEventArgs; + var entry = this.Queries.Where(q => q.Path == renamedArgs.OldFullPath).FirstOrDefault(); if (entry != null) { - entry.Path = e.Name; + entry.Path = renamedArgs.FullPath; } } else if (e.ChangeType == WatcherChangeTypes.Changed) { // This event may happen when the file is created, or at any time after than // when an existing file is actually changed. - var entry = this.Queries.Where(q => q.Path == e.Name).FirstOrDefault(); + var entry = this.Queries.Where(q => q.Path == e.FullPath).FirstOrDefault(); if (entry == null) { - entry = new QueryEntry() { Path = e.Name, Description = this.GetDescription(e.FullPath) }; + entry = new QueryEntry() { Path = e.FullPath, Description = this.GetDescription(e.FullPath) }; App.Current.Dispatcher.Invoke(() => { this.Queries.Add(entry); @@ -361,6 +359,8 @@ namespace XppReasoningWpf entry.Description = GetDescription(e.FullPath); } } + + this.OnPropertyChanged("Queries"); } public Model() diff --git a/tools/Explorer/Views/QueryEditor.cs b/tools/Explorer/Views/QueryEditor.cs index c32a841..f46a270 100644 --- a/tools/Explorer/Views/QueryEditor.cs +++ b/tools/Explorer/Views/QueryEditor.cs @@ -13,7 +13,6 @@ namespace XppReasoningWpf public class QueryEditor : SourceEditor { private static readonly Snippets snippets = new Snippets(); - //public Session Session { get; } public QueryEditor(ViewModels.ViewModel viewModel) :this() @@ -54,7 +53,7 @@ namespace XppReasoningWpf ICSharpCode.AvalonEdit.Search.SearchPanel.Install(this.TextArea); this.IsReadOnly = false; - this.PreviewMouseWheel += QueryEditor_PreviewMouseWheel; + // this.PreviewMouseWheel += QueryEditorMouseWheelHandler; // Adding to the context menu... var contextMenuItems = (this.ContextMenu.ItemsSource as Control[]).ToList(); @@ -62,7 +61,6 @@ namespace XppReasoningWpf var templatesMenuItem = new MenuItem { Header = "Snippets" - // Command = ApplicationCommands.Copy, }; contextMenuItems.Add(templatesMenuItem); @@ -84,7 +82,7 @@ namespace XppReasoningWpf this.ContextMenu.ItemsSource = contextMenuItems; } - private void QueryEditor_PreviewMouseWheel(object sender, MouseWheelEventArgs e) + protected override void MouseWheelHandler(object sender, MouseWheelEventArgs e) { if (Keyboard.IsKeyDown(Key.LeftCtrl)) { diff --git a/tools/Explorer/Views/SourceEditor.cs b/tools/Explorer/Views/SourceEditor.cs index ff084ba..53a5303 100644 --- a/tools/Explorer/Views/SourceEditor.cs +++ b/tools/Explorer/Views/SourceEditor.cs @@ -130,24 +130,6 @@ namespace XppReasoningWpf } } - private void SourceEditor_MouseWheel(object sender, MouseWheelEventArgs e) - { - if (Keyboard.IsKeyDown(Key.LeftCtrl)) - { - if (e.Delta > 0) - { - if (Properties.Settings.Default.SourceFontSize < 48) - Properties.Settings.Default.SourceFontSize += 1; - - } - else - { - if (Properties.Settings.Default.SourceFontSize < 48) - Properties.Settings.Default.SourceFontSize -= 1; - } - } - } - public SourceEditor() { this.TextArea.Caret.PositionChanged += (object sender, EventArgs a) => @@ -159,7 +141,7 @@ namespace XppReasoningWpf // Install the search panel that appears in the upper left corner. ICSharpCode.AvalonEdit.Search.SearchPanel.Install(this.TextArea); - this.PreviewMouseWheel += SourceEditor_MouseWheel; + this.PreviewMouseWheel += MouseWheelHandler; this.IsReadOnly = true; var fontFamilyBinding = new Binding("SourceFont") @@ -247,5 +229,23 @@ namespace XppReasoningWpf } }; } + + protected virtual void MouseWheelHandler(object sender, MouseWheelEventArgs e) + { + if (Keyboard.IsKeyDown(Key.LeftCtrl)) + { + if (e.Delta > 0) + { + if (Properties.Settings.Default.SourceFontSize < 48) + Properties.Settings.Default.SourceFontSize += 1; + + } + else + { + if (Properties.Settings.Default.SourceFontSize < 48) + Properties.Settings.Default.SourceFontSize -= 1; + } + } + } } } diff --git a/tools/Explorer/Views/XppSourceEditor.cs b/tools/Explorer/Views/XppSourceEditor.cs index 6563e78..03d7859 100644 --- a/tools/Explorer/Views/XppSourceEditor.cs +++ b/tools/Explorer/Views/XppSourceEditor.cs @@ -7,6 +7,7 @@ namespace XppReasoningWpf { using ICSharpCode.AvalonEdit.Folding; using System.Windows.Data; + using System.Windows.Input; class XppSourceEditor : SourceEditor { @@ -31,5 +32,7 @@ namespace XppReasoningWpf xppFoldingStrategy.UpdateFoldings(xppFoldingManager, this.Document); }; } + + } }