Skip to content

Commit

Permalink
Avalonia v11 - Updated IControl to Control and Items (_readonly…
Browse files Browse the repository at this point in the history
…_) to `ItemsSource`
  • Loading branch information
DamianSuess committed Jul 21, 2023
1 parent a3904e4 commit df048ed
Show file tree
Hide file tree
Showing 18 changed files with 61 additions and 49 deletions.
7 changes: 6 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
</PropertyGroup>

<PropertyGroup>
<AvaloniaVersion>0.10.13</AvaloniaVersion>
<AvaloniaEditVersion>0.10.12.2</AvaloniaEditVersion>
<AvaloniaVersion>11.0.0</AvaloniaVersion>
<AvaloniaEditVersion>11.0.0</AvaloniaEditVersion>
</PropertyGroup>

</Project>
16 changes: 8 additions & 8 deletions ILSpy.Core/ContextMenuEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,8 @@ void treeView_ContextMenuOpening(object sender, CancelEventArgs e)
}

ContextMenu menu = (ContextMenu)sender;
if (ShowContextMenu(context, out IEnumerable<IControl> items))
menu.Items = items;
if (ShowContextMenu(context, out IEnumerable<Control> items))
menu.ItemsSource = items;
else
// hide the context menu.
e.Cancel = true;
Expand All @@ -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<IControl> items))
menu.Items = items;
if (ShowContextMenu(context, out IEnumerable<Control> items))
menu.ItemsSource = items;
else
// hide the context menu.
e.Cancel = true;
Expand All @@ -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<IControl> items))
menu.Items = items;
if (ShowContextMenu(context, out IEnumerable<Control> items))
menu.ItemsSource = items;
else
// hide the context menu.
e.Cancel = true;
}

bool ShowContextMenu(TextViewContext context, out IEnumerable<IControl> menuItems)
bool ShowContextMenu(TextViewContext context, out IEnumerable<Control> menuItems)
{
List<IControl> items = new List<IControl>();
List<Control> items = new List<Control>();
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) {
Expand Down
2 changes: 1 addition & 1 deletion ILSpy.Core/Controls/CustomDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions ILSpy.Core/Controls/ResourceObjectTable.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -75,4 +75,4 @@ void CanExecuteCopy(object sender, CanExecuteRoutedEventArgs args)
args.CanExecute = true;
}
}
}
}
6 changes: 3 additions & 3 deletions ILSpy.Core/DebugSteps.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
Expand All @@ -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
Expand Down Expand Up @@ -164,4 +164,4 @@ private void tree_KeyDown(object sender, KeyEventArgs e)
}
}
}
}
}
2 changes: 1 addition & 1 deletion ILSpy.Core/ISmartTextOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public interface ISmartTextOutput : ITextOutput
/// <summary>
/// Inserts an interactive UI element at the current position in the text output.
/// </summary>
void AddUIElement(Func<IControl> element);
void AddUIElement(Func<Control> element);

void BeginSpan(HighlightingColor highlightingColor);
void EndSpan();
Expand Down
18 changes: 12 additions & 6 deletions ILSpy.Core/MainWindow.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -199,7 +199,7 @@ private void InitializeComponent()
}

var themesDropDown = this.Find<ComboBox>("Themes");
themesDropDown.Items = themeNames;
themesDropDown.ItemsSource = themeNames;
themesDropDown.SelectionChanged += (sender, e) =>
{
Styles[0] = themes[themesDropDown.SelectedIndex];
Expand Down Expand Up @@ -355,7 +355,8 @@ void InitToolbar()
}
}
}
toolBar.Items = toolbarItems;

toolBar.ItemsSource = toolbarItems;
}

Button MakeToolbarItem(Lazy<ICommand, IToolbarCommandMetadata> command)
Expand All @@ -370,6 +371,7 @@ Button MakeToolbarItem(Lazy<ICommand, IToolbarCommandMetadata> command)
Source = Images.LoadImage(command.Value, command.Metadata.ToolbarIcon)
}
};

ToolTip.SetTip(toolbarButton, Properties.Resources.ResourceManager.GetString(command.Metadata.ToolTip));
return toolbarButton;
}
Expand All @@ -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);
Expand All @@ -409,9 +412,11 @@ void InitMainMenu()
topLevelMenuItems.Add(menuItem);
}
}
topLevelMenuItem.Items = topLevelMenuItems;

topLevelMenuItem.ItemsSource = topLevelMenuItems;
}
mainMenu.Items = mainMenuItems;

mainMenu.ItemsSource = mainMenuItems;
}

void InitNativeMenu()
Expand Down Expand Up @@ -450,7 +455,8 @@ void InitNativeMenu()
}
}
}
mainMenu.Items = mainMenuItems;

mainMenu.ItemsSource = mainMenuItems;
}

internal static string GetResourceString(string key)
Expand Down
2 changes: 1 addition & 1 deletion ILSpy.Core/OpenListDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ private void InitializeComponent()

private void listView_Loaded(object sender, EventArgs e)
{
listView.Items = manager.AssemblyLists;
listView.ItemsSource = manager.AssemblyLists;
CreateDefaultAssemblyLists();
}

Expand Down
4 changes: 2 additions & 2 deletions ILSpy.Core/Options/DisplaySettingsPanel.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -206,4 +206,4 @@ public object ConvertBack(object value, Type targetType, object parameter, Syste
throw new NotImplementedException();
}
}
}
}
11 changes: 6 additions & 5 deletions ILSpy.Core/Options/OptionsDialog.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ namespace ICSharpCode.ILSpy.Options
public partial class OptionsDialog : DialogWindow
{

readonly Lazy<IControl, IOptionsMetadata>[] optionPages;
readonly Lazy<Control, IOptionsMetadata>[] optionPages;

internal TabControl tabControl;

Expand All @@ -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<IControl, IOptionsMetadata>("OptionPages").ToArray();
this.optionPages = ep.GetExports<Control, IOptionsMetadata>("OptionPages").ToArray();
ILSpySettings settings = ILSpySettings.Load();
var tabItems = new List<TabItem>();
foreach (var optionPage in optionPages.OrderBy(p => p.Metadata.Order)) {
Expand All @@ -63,7 +63,8 @@ public OptionsDialog()
if (page != null)
page.Load(settings);
}
tabControl.Items = tabItems;

tabControl.ItemsSource = tabItems;
}

private void InitializeComponent()
Expand Down Expand Up @@ -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; }
Expand All @@ -130,4 +131,4 @@ public override async void Execute(object parameter)
}
}
}
}
}
3 changes: 1 addition & 2 deletions ILSpy.Core/Search/SearchPane.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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" },
Expand All @@ -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;
Expand Down
6 changes: 3 additions & 3 deletions ILSpy.Core/TextView/AvaloniaEditTextOutput.cs
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public sealed class AvaloniaEditTextOutput : ISmartTextOutput
internal bool EnableHyperlinks { get; set; }

/// <summary>Embedded UIElements, see <see cref="UIElementGenerator"/>.</summary>
internal readonly List<KeyValuePair<int, Lazy<IControl>>> UIElements = new List<KeyValuePair<int, Lazy<IControl>>>();
internal readonly List<KeyValuePair<int, Lazy<Control>>> UIElements = new List<KeyValuePair<int, Lazy<Control>>>();

public RichTextModel HighlightingModel { get; } = new RichTextModel();

Expand Down Expand Up @@ -298,12 +298,12 @@ public void MarkFoldEnd()
this.Foldings.Add(f);
}

public void AddUIElement(Func<IControl> element)
public void AddUIElement(Func<Control> 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<int, Lazy<IControl>>(this.TextLength, new Lazy<IControl>(element)));
this.UIElements.Add(new KeyValuePair<int, Lazy<Control>>(this.TextLength, new Lazy<Control>(element)));
}
}

Expand Down
2 changes: 1 addition & 1 deletion ILSpy.Core/TextView/UIElementGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

namespace ICSharpCode.ILSpy.TextView
{
using Pair = KeyValuePair<int, Lazy<IControl>>;
using Pair = KeyValuePair<int, Lazy<Control>>;

/// <summary>
/// Embeds UIElements in the text output.
Expand Down
3 changes: 2 additions & 1 deletion ILSpy/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<string> hierachy = new List<string>();
hierachy.Add(visual.ToString());
////while ((visual = visual.Parent) != null)
while ((visual = visual.Parent) != null)
{
hierachy.Insert(0, visual.ToString());
Expand Down
2 changes: 1 addition & 1 deletion SharpTreeView/ExtensionMethods.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ namespace ICSharpCode.TreeView
{
static class ExtensionMethods
{
public static T FindAncestor<T>(this IVisual d) where T : class
public static T FindAncestor<T>(this Visual d) where T : class
{
return d.GetVisualAncestors().OfType<T>().FirstOrDefault();
}
Expand Down
2 changes: 1 addition & 1 deletion SharpTreeView/SharpTreeNodeView.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ public IBrush TextBackground
if (!expanded.HasValue) {
return null;
}
return expanded.Value ? owner.Node?.ExpandedIcon : owner.Node?.Icon;
});

Expand All @@ -40,7 +41,6 @@ public object Icon
get { return GetValue(IconProperty); }
}


public SharpTreeNode Node
{
get { return DataContext as SharpTreeNode; }
Expand Down
Loading

0 comments on commit df048ed

Please sign in to comment.