From df048ede967f06e2b7bea23c0de2141b4ad925ba Mon Sep 17 00:00:00 2001 From: Damian Suess Date: Fri, 21 Jul 2023 13:05:14 -0400 Subject: [PATCH] Avalonia v11 - Updated `IControl` to `Control` and `Items` (_readonly_) to `ItemsSource` --- .editorconfig | 7 ++++++- Directory.Build.props | 4 ++-- ILSpy.Core/ContextMenuEntry.cs | 16 ++++++++-------- ILSpy.Core/Controls/CustomDialog.xaml.cs | 2 +- .../Controls/ResourceObjectTable.xaml.cs | 4 ++-- ILSpy.Core/DebugSteps.xaml.cs | 6 +++--- ILSpy.Core/ISmartTextOutput.cs | 2 +- ILSpy.Core/MainWindow.xaml.cs | 18 ++++++++++++------ ILSpy.Core/OpenListDialog.xaml.cs | 2 +- .../Options/DisplaySettingsPanel.xaml.cs | 4 ++-- ILSpy.Core/Options/OptionsDialog.xaml.cs | 11 ++++++----- ILSpy.Core/Search/SearchPane.xaml.cs | 3 +-- ILSpy.Core/TextView/AvaloniaEditTextOutput.cs | 6 +++--- ILSpy.Core/TextView/UIElementGenerator.cs | 2 +- ILSpy/Program.cs | 3 ++- SharpTreeView/ExtensionMethods.cs | 2 +- SharpTreeView/SharpTreeNodeView.cs | 2 +- SharpTreeView/SharpTreeView.cs | 16 ++++++++-------- 18 files changed, 61 insertions(+), 49 deletions(-) diff --git a/.editorconfig b/.editorconfig index 667dc85..b0f7703 100644 --- a/.editorconfig +++ b/.editorconfig @@ -12,10 +12,15 @@ indent_style = space indent_size = 4 trim_trailing_whitespace = true -[*.{cs,vb}] +[*.{cs,csx}] tab_width = 4 indent_size = 4 end_of_line = crlf indent_style = tab +charset = utf-8-bom trim_trailing_whitespace = true insert_final_newline = true + +## Suppressions for ILSpy coding style +# dotnet_diagnostic.IDE2003.severity = error +dotnet_style_allow_statement_immediately_after_block_experimental = false:warning diff --git a/Directory.Build.props b/Directory.Build.props index 9825edd..5531e93 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -5,8 +5,8 @@ - 0.10.13 - 0.10.12.2 + 11.0.0 + 11.0.0 diff --git a/ILSpy.Core/ContextMenuEntry.cs b/ILSpy.Core/ContextMenuEntry.cs index 403bd8e..a6be14a 100644 --- a/ILSpy.Core/ContextMenuEntry.cs +++ b/ILSpy.Core/ContextMenuEntry.cs @@ -183,8 +183,8 @@ void treeView_ContextMenuOpening(object sender, CancelEventArgs e) } ContextMenu menu = (ContextMenu)sender; - if (ShowContextMenu(context, out IEnumerable items)) - menu.Items = items; + if (ShowContextMenu(context, out IEnumerable items)) + menu.ItemsSource = items; else // hide the context menu. e.Cancel = true; @@ -194,8 +194,8 @@ void textView_ContextMenuOpening(object sender, CancelEventArgs e) { TextViewContext context = TextViewContext.Create(textView: textView); ContextMenu menu = (ContextMenu)sender; - if (ShowContextMenu(context, out IEnumerable items)) - menu.Items = items; + if (ShowContextMenu(context, out IEnumerable items)) + menu.ItemsSource = items; else // hide the context menu. e.Cancel = true; @@ -205,16 +205,16 @@ void listBox_ContextMenuOpening(object sender, CancelEventArgs e) { TextViewContext context = TextViewContext.Create(listBox: listBox); ContextMenu menu = (ContextMenu)sender; - if (ShowContextMenu(context, out IEnumerable items)) - menu.Items = items; + if (ShowContextMenu(context, out IEnumerable items)) + menu.ItemsSource = items; else // hide the context menu. e.Cancel = true; } - bool ShowContextMenu(TextViewContext context, out IEnumerable menuItems) + bool ShowContextMenu(TextViewContext context, out IEnumerable menuItems) { - List items = new List(); + List items = new List(); foreach (var category in entries.OrderBy(c => c.Metadata.Order).GroupBy(c => c.Metadata.Category)) { bool needSeparatorForCategory = items.Count > 0; foreach (var entryPair in category) { diff --git a/ILSpy.Core/Controls/CustomDialog.xaml.cs b/ILSpy.Core/Controls/CustomDialog.xaml.cs index 393c332..c8d23fb 100644 --- a/ILSpy.Core/Controls/CustomDialog.xaml.cs +++ b/ILSpy.Core/Controls/CustomDialog.xaml.cs @@ -57,7 +57,7 @@ public CustomDialog(string caption, string message, int acceptButton = -1, int c this.WindowStartupLocation = WindowStartupLocation.CenterOwner; this.Width = buttonLabels.Length * (100+ 10); - buttons.Items = buttonLabels; + buttons.ItemsSource = buttonLabels; label.Text = message; diff --git a/ILSpy.Core/Controls/ResourceObjectTable.xaml.cs b/ILSpy.Core/Controls/ResourceObjectTable.xaml.cs index cfade13..fd680b9 100644 --- a/ILSpy.Core/Controls/ResourceObjectTable.xaml.cs +++ b/ILSpy.Core/Controls/ResourceObjectTable.xaml.cs @@ -42,7 +42,7 @@ public partial class ResourceObjectTable : UserControl, IRoutedCommandBindable public ResourceObjectTable(IEnumerable resources, ContentPresenter contentPresenter) { InitializeComponent(); - resourceListView.Items = resources; + resourceListView.ItemsSource = resources; } private void InitializeComponent() @@ -75,4 +75,4 @@ void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs args) args.CanExecute = true; } } -} \ No newline at end of file +} diff --git a/ILSpy.Core/DebugSteps.xaml.cs b/ILSpy.Core/DebugSteps.xaml.cs index 5a75367..364815f 100644 --- a/ILSpy.Core/DebugSteps.xaml.cs +++ b/ILSpy.Core/DebugSteps.xaml.cs @@ -68,7 +68,7 @@ private void WritingOptions_PropertyChanged(object sender, System.ComponentModel private void SelectionChanged(object sender, SelectionChangedEventArgs e) { Dispatcher.UIThread.InvokeAsync(() => { - tree.Items = null; + tree.ItemsSource = null; lastSelectedStep = int.MaxValue; }); } @@ -94,7 +94,7 @@ private void ILAstStepperUpdated(object sender, EventArgs e) #if DEBUG if (language == null) return; Dispatcher.UIThread.InvokeAsync(() => { - tree.Items = language.Stepper.Steps; + tree.ItemsSource = language.Stepper.Steps; lastSelectedStep = int.MaxValue; }); #endif @@ -164,4 +164,4 @@ private void tree_KeyDown(object sender, KeyEventArgs e) } } } -} \ No newline at end of file +} diff --git a/ILSpy.Core/ISmartTextOutput.cs b/ILSpy.Core/ISmartTextOutput.cs index 9e4399e..b4c168e 100644 --- a/ILSpy.Core/ISmartTextOutput.cs +++ b/ILSpy.Core/ISmartTextOutput.cs @@ -36,7 +36,7 @@ public interface ISmartTextOutput : ITextOutput /// /// Inserts an interactive UI element at the current position in the text output. /// - void AddUIElement(Func element); + void AddUIElement(Func element); void BeginSpan(HighlightingColor highlightingColor); void EndSpan(); diff --git a/ILSpy.Core/MainWindow.xaml.cs b/ILSpy.Core/MainWindow.xaml.cs index 9103072..645de6c 100644 --- a/ILSpy.Core/MainWindow.xaml.cs +++ b/ILSpy.Core/MainWindow.xaml.cs @@ -82,7 +82,7 @@ public partial class MainWindow : PlatformDependentWindow, IRoutedCommandBindabl internal ItemsControl toolBar; internal ComboBox languageComboBox; internal ComboBox languageVersionComboBox; - internal IControl statusBar; + internal Control statusBar; internal TextBlock StatusLabel; internal Grid mainGrid; internal ColumnDefinition leftColumn; @@ -199,7 +199,7 @@ private void InitializeComponent() } var themesDropDown = this.Find("Themes"); - themesDropDown.Items = themeNames; + themesDropDown.ItemsSource = themeNames; themesDropDown.SelectionChanged += (sender, e) => { Styles[0] = themes[themesDropDown.SelectedIndex]; @@ -355,7 +355,8 @@ void InitToolbar() } } } - toolBar.Items = toolbarItems; + + toolBar.ItemsSource = toolbarItems; } Button MakeToolbarItem(Lazy command) @@ -370,6 +371,7 @@ Button MakeToolbarItem(Lazy command) Source = Images.LoadImage(command.Value, command.Metadata.ToolbarIcon) } }; + ToolTip.SetTip(toolbarButton, Properties.Resources.ResourceManager.GetString(command.Metadata.ToolTip)); return toolbarButton; } @@ -392,6 +394,7 @@ void InitMainMenu() } else if (topLevelMenuItems.Count > 0) { topLevelMenuItems.Add(new Separator()); } + foreach (var entry in category) { MenuItem menuItem = new MenuItem(); menuItem.Command = CommandWrapper.Unwrap(entry.Value); @@ -409,9 +412,11 @@ void InitMainMenu() topLevelMenuItems.Add(menuItem); } } - topLevelMenuItem.Items = topLevelMenuItems; + + topLevelMenuItem.ItemsSource = topLevelMenuItems; } - mainMenu.Items = mainMenuItems; + + mainMenu.ItemsSource = mainMenuItems; } void InitNativeMenu() @@ -450,7 +455,8 @@ void InitNativeMenu() } } } - mainMenu.Items = mainMenuItems; + + mainMenu.ItemsSource = mainMenuItems; } internal static string GetResourceString(string key) diff --git a/ILSpy.Core/OpenListDialog.xaml.cs b/ILSpy.Core/OpenListDialog.xaml.cs index ab4c379..75b572e 100644 --- a/ILSpy.Core/OpenListDialog.xaml.cs +++ b/ILSpy.Core/OpenListDialog.xaml.cs @@ -78,7 +78,7 @@ private void InitializeComponent() private void listView_Loaded(object sender, EventArgs e) { - listView.Items = manager.AssemblyLists; + listView.ItemsSource = manager.AssemblyLists; CreateDefaultAssemblyLists(); } diff --git a/ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs b/ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs index 5540c78..42ff154 100644 --- a/ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs +++ b/ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs @@ -53,7 +53,7 @@ public DisplaySettingsPanel() Dispatcher.UIThread.InvokeAsync( (Action)( async () => { - fontSelector.Items = task.Result; + fontSelector.ItemsSource = task.Result; if (continuation.Exception != null) { foreach (var ex in continuation.Exception.InnerExceptions) { await MessageBox.Show(ex.ToString()); @@ -206,4 +206,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste throw new NotImplementedException(); } } -} \ No newline at end of file +} diff --git a/ILSpy.Core/Options/OptionsDialog.xaml.cs b/ILSpy.Core/Options/OptionsDialog.xaml.cs index 4daeae6..233f320 100644 --- a/ILSpy.Core/Options/OptionsDialog.xaml.cs +++ b/ILSpy.Core/Options/OptionsDialog.xaml.cs @@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpy.Options public partial class OptionsDialog : DialogWindow { - readonly Lazy[] optionPages; + readonly Lazy[] optionPages; internal TabControl tabControl; @@ -50,7 +50,7 @@ public OptionsDialog() // ExportProvider instance. // FIXME: Ideally, the export provider should be disposed when it's no longer needed. var ep = App.ExportProviderFactory.CreateExportProvider(); - this.optionPages = ep.GetExports("OptionPages").ToArray(); + this.optionPages = ep.GetExports("OptionPages").ToArray(); ILSpySettings settings = ILSpySettings.Load(); var tabItems = new List(); foreach (var optionPage in optionPages.OrderBy(p => p.Metadata.Order)) { @@ -63,7 +63,8 @@ public OptionsDialog() if (page != null) page.Load(settings); } - tabControl.Items = tabItems; + + tabControl.ItemsSource = tabItems; } private void InitializeComponent() @@ -110,7 +111,7 @@ public interface IOptionPage [AttributeUsage(AttributeTargets.Class, AllowMultiple=false)] public class ExportOptionPageAttribute : ExportAttribute { - public ExportOptionPageAttribute() : base("OptionPages", typeof(IControl)) + public ExportOptionPageAttribute() : base("OptionPages", typeof(Control)) { } public string Title { get; set; } @@ -130,4 +131,4 @@ public override async void Execute(object parameter) } } } -} \ No newline at end of file +} diff --git a/ILSpy.Core/Search/SearchPane.xaml.cs b/ILSpy.Core/Search/SearchPane.xaml.cs index 55b476b..944c6a6 100644 --- a/ILSpy.Core/Search/SearchPane.xaml.cs +++ b/ILSpy.Core/Search/SearchPane.xaml.cs @@ -66,7 +66,7 @@ public partial class SearchPane : UserControl, IPane public SearchPane() { InitializeComponent(); - searchModeComboBox.Items = new []{ + searchModeComboBox.ItemsSource = new []{ new { Image = Images.Library, Name = "Types and Members" }, new { Image = Images.Class, Name = "Type" }, new { Image = Images.Property, Name = "Member" }, @@ -78,7 +78,6 @@ public SearchPane() new { Image = Images.Library, Name = "Metadata Token" } }; - ContextMenuProvider.Add(listBox); MainWindow.Instance.CurrentAssemblyListChanged += MainWindow_Instance_CurrentAssemblyListChanged; MainWindow.Instance.SessionSettings.FilterSettings.PropertyChanged += FilterSettings_PropertyChanged; diff --git a/ILSpy.Core/TextView/AvaloniaEditTextOutput.cs b/ILSpy.Core/TextView/AvaloniaEditTextOutput.cs index 931783b..cd7c66e 100644 --- a/ILSpy.Core/TextView/AvaloniaEditTextOutput.cs +++ b/ILSpy.Core/TextView/AvaloniaEditTextOutput.cs @@ -98,7 +98,7 @@ public sealed class AvaloniaEditTextOutput : ISmartTextOutput internal bool EnableHyperlinks { get; set; } /// Embedded UIElements, see . - internal readonly List>> UIElements = new List>>(); + internal readonly List>> UIElements = new List>>(); public RichTextModel HighlightingModel { get; } = new RichTextModel(); @@ -298,12 +298,12 @@ public void MarkFoldEnd() this.Foldings.Add(f); } - public void AddUIElement(Func element) + public void AddUIElement(Func element) { if (element != null) { if (this.UIElements.Count > 0 && this.UIElements.Last().Key == this.TextLength) throw new InvalidOperationException("Only one UIElement is allowed for each position in the document"); - this.UIElements.Add(new KeyValuePair>(this.TextLength, new Lazy(element))); + this.UIElements.Add(new KeyValuePair>(this.TextLength, new Lazy(element))); } } diff --git a/ILSpy.Core/TextView/UIElementGenerator.cs b/ILSpy.Core/TextView/UIElementGenerator.cs index e309ea9..c1a9c0e 100644 --- a/ILSpy.Core/TextView/UIElementGenerator.cs +++ b/ILSpy.Core/TextView/UIElementGenerator.cs @@ -24,7 +24,7 @@ namespace ICSharpCode.ILSpy.TextView { - using Pair = KeyValuePair>; + using Pair = KeyValuePair>; /// /// Embeds UIElements in the text output. diff --git a/ILSpy/Program.cs b/ILSpy/Program.cs index dc85f03..1ee0928 100644 --- a/ILSpy/Program.cs +++ b/ILSpy/Program.cs @@ -93,10 +93,11 @@ public void Log(LogEventLevel level, string area, object source, string messageT object GetHierachy(object source) { - if (source is IControl visual) + if (source is Control visual) { List hierachy = new List(); hierachy.Add(visual.ToString()); + ////while ((visual = visual.Parent) != null) while ((visual = visual.Parent) != null) { hierachy.Insert(0, visual.ToString()); diff --git a/SharpTreeView/ExtensionMethods.cs b/SharpTreeView/ExtensionMethods.cs index 657e73a..d59dc8b 100644 --- a/SharpTreeView/ExtensionMethods.cs +++ b/SharpTreeView/ExtensionMethods.cs @@ -12,7 +12,7 @@ namespace ICSharpCode.TreeView { static class ExtensionMethods { - public static T FindAncestor(this IVisual d) where T : class + public static T FindAncestor(this Visual d) where T : class { return d.GetVisualAncestors().OfType().FirstOrDefault(); } diff --git a/SharpTreeView/SharpTreeNodeView.cs b/SharpTreeView/SharpTreeNodeView.cs index e613756..bdffb52 100644 --- a/SharpTreeView/SharpTreeNodeView.cs +++ b/SharpTreeView/SharpTreeNodeView.cs @@ -32,6 +32,7 @@ public IBrush TextBackground if (!expanded.HasValue) { return null; } + return expanded.Value ? owner.Node?.ExpandedIcon : owner.Node?.Icon; }); @@ -40,7 +41,6 @@ public object Icon get { return GetValue(IconProperty); } } - public SharpTreeNode Node { get { return DataContext as SharpTreeNode; } diff --git a/SharpTreeView/SharpTreeView.cs b/SharpTreeView/SharpTreeView.cs index 723da52..48824bb 100644 --- a/SharpTreeView/SharpTreeView.cs +++ b/SharpTreeView/SharpTreeView.cs @@ -155,7 +155,7 @@ void Reload() } flattener = new TreeFlattener(Root, ShowRoot); flattener.CollectionChanged += flattener_CollectionChanged; - this.Items = flattener; + this.ItemsSource = flattener; } } @@ -228,7 +228,7 @@ protected override void OnContainersRecycled(ItemContainerEventArgs e) } } - internal IControl ContainerFromItem(object item) + internal Control ContainerFromItem(object item) { int index = IndexOf(Items, item); if (index != -1) { @@ -274,7 +274,7 @@ protected override void OnKeyDown(KeyEventArgs e) SharpTreeViewItem container = e.Source as SharpTreeViewItem; switch (e.Key) { case Key.Left: - if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { + if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1) { if (container.Node.IsExpanded) { container.Node.IsExpanded = false; } else if (container.Node.Parent != null) { @@ -285,7 +285,7 @@ protected override void OnKeyDown(KeyEventArgs e) break; case Key.Right: // TODO: focus on first child - if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { + if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1) { if (!container.Node.IsExpanded && container.Node.ShowExpander) { container.Node.IsExpanded = true; } else if (container.Node.Children.Count > 0) { @@ -303,19 +303,19 @@ protected override void OnKeyDown(KeyEventArgs e) } break; case Key.Add: - if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { + if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1) { container.Node.IsExpanded = true; e.Handled = true; } break; case Key.Subtract: - if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { + if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1) { container.Node.IsExpanded = false; e.Handled = true; } break; case Key.Multiply: - if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1) { + if (container != null && ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1) { container.Node.IsExpanded = true; ExpandRecursively(container.Node); e.Handled = true; @@ -348,7 +348,7 @@ protected override void OnKeyDown(KeyEventArgs e) protected override void OnTextInput(TextInputEventArgs e) { - if (!string.IsNullOrEmpty(e.Text) && IsTextSearchEnabled && (e.Source == this || ItemContainerGenerator.IndexFromContainer(e.Source as IControl) != -1)) { + if (!string.IsNullOrEmpty(e.Text) && IsTextSearchEnabled && (e.Source == this || ItemContainerGenerator.IndexFromContainer(e.Source as Control) != -1)) { var instance = SharpTreeViewTextSearch.GetInstance(this); if (instance != null) { instance.Search(e.Text);