Skip to content

Commit

Permalink
Switched to dropdown and listbox combination in order to replace slow…
Browse files Browse the repository at this point in the history
… treeview, fixes #28
  • Loading branch information
bcssov committed Apr 18, 2020
1 parent b24564c commit 0b71c72
Show file tree
Hide file tree
Showing 4 changed files with 49 additions and 37 deletions.
3 changes: 2 additions & 1 deletion src/IronyModManager/Controls/TextEditor.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 04-15-2020
//
// Last Modified By : Mario
// Last Modified On : 04-15-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="TextEditor.cs" company="Mario">
// Mario
Expand All @@ -29,6 +29,7 @@ namespace IronyModManager.Controls
/// </summary>
/// <seealso cref="Avalonia.Styling.IStyleable" />
/// <seealso cref="AvaloniaEdit.TextEditor" />
[ExcludeFromCoverage("Should be tested in functional testing.")]
public class TextEditor : AvaloniaEdit.TextEditor, IStyleable
{
#region Fields
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
// Created : 03-18-2020
//
// Last Modified By : Mario
// Last Modified On : 04-17-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="MainConflictSolverViewModel.cs" company="Mario">
// Mario
Expand Down Expand Up @@ -209,6 +209,12 @@ public MainConflictSolverControlViewModel(IModService modService, ILocalizationM
/// <value>The selected mod collection.</value>
public virtual IModCollection SelectedModCollection { get; set; }

/// <summary>
/// Gets or sets the selected parent conflict.
/// </summary>
/// <value>The selected parent conflict.</value>
public virtual IHierarchicalDefinitions SelectedParentConflict { get; set; }

#endregion Properties

#region Methods
Expand Down
41 changes: 27 additions & 14 deletions src/IronyModManager/Views/MainConflictSolverControlView.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,25 +4,38 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
MinWidth="800" MinHeight="450"
xmlns:converter="clr-namespace:IronyModManager.Converters;assembly=IronyModManager"
x:Class="IronyModManager.Views.MainConflictSolverControlView">
<UserControl.Resources>
<converter:MathConverter x:Key="MathConverter" />
</UserControl.Resources>
<Panel HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
<Grid RowDefinitions="4*,8*,1.1*" ColumnDefinitions="3*,7*">
<Panel Grid.Column="0" Grid.Row="0" Grid.RowSpan="3">
<Grid ColumnDefinitions="*" RowDefinitions="1*,20*">
<TextBlock Text="{Binding ConflictedObjects}" Grid.Column="0"
Grid.Row="0" HorizontalAlignment="Center" Margin="10"></TextBlock>
<TreeView Items="{Binding HierarchalConflicts}" Grid.Column="0" Grid.Row="1"
SelectedItem="{Binding SelectedConflict}"
x:Name="conflicts" ScrollViewer.HorizontalScrollBarVisibility="Visible">
<TreeView.DataTemplates>
<TreeDataTemplate ItemsSource="{Binding Children}">
<TextBlock Text="{Binding Name}"></TextBlock>
</TreeDataTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}"></TextBlock>
</DataTemplate>
</TreeView.DataTemplates>
</TreeView>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding ConflictedObjects}" Grid.Column="0"
Grid.Row="0" HorizontalAlignment="Center" Margin="10"></TextBlock>
<ComboBox Items="{Binding HierarchalConflicts}" SelectedItem="{Binding SelectedParentConflict}"
HorizontalAlignment="Stretch" MinHeight="30">
<ComboBox.ItemTemplate>
<DataTemplate>
<ComboBoxItem Content="{Binding Name}"></ComboBoxItem>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
<ListBox Items="{Binding SelectedParentConflict.Children}" SelectedItem="SelectedConflict"
ScrollViewer.HorizontalScrollBarVisibility="Disabled" SelectionMode="Single" x:Name="conflictList"
Height="{Binding $parent[Window].Height,
Converter={StaticResource MathConverter}
ConverterParameter=x-50}">
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" TextWrapping="Wrap"></TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
</Panel>
<Panel Grid.Row="0" Grid.Column="1">
Expand Down
34 changes: 13 additions & 21 deletions src/IronyModManager/Views/MainConflictSolverControlView.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,16 @@
// Created : 03-18-2020
//
// Last Modified By : Mario
// Last Modified On : 04-07-2020
// Last Modified On : 04-18-2020
// ***********************************************************************
// <copyright file="MainConflictSolverControlView.xaml.cs" company="Mario">
// Mario
// </copyright>
// <summary></summary>
// ***********************************************************************
using System;
using System.Linq;
using System;
using System.Reactive.Disposables;
using System.Reactive.Linq;
using Avalonia.Controls;
using Avalonia.Markup.Xaml;
using IronyModManager.Common.Views;
Expand Down Expand Up @@ -52,30 +51,23 @@ public MainConflictSolverControlView()
/// <param name="disposables">The disposables.</param>
protected override void OnActivated(CompositeDisposable disposables)
{
base.OnActivated(disposables);
var conflicts = this.FindControl<TreeView>("conflicts");
this.WhenAnyValue(v => v.ViewModel.SelectedConflict).Where(p => p != null).Subscribe(s =>
var conflictList = this.FindControl<ListBox>("conflictList");
conflictList.SelectionChanged += (sender, args) =>
{
int idx = 0;
bool matchFound = false;
foreach (var item in ViewModel.HierarchalConflicts)
if (conflictList?.SelectedIndex > -1 && ViewModel.SelectedParentConflict != null)
{
if (item.Children.Contains(ViewModel.SelectedConflict))
{
matchFound = true;
break;
}
idx++;
ViewModel.SelectedConflict = ViewModel.SelectedParentConflict.Children.ElementAt(conflictList.SelectedIndex);
}
if (idx > (ViewModel.HierarchalConflicts.Count() - 1))
else
{
idx = ViewModel.HierarchalConflicts.Count() - 1;
}
if (matchFound && conflicts.Presenter.Panel.Children[idx] is TreeViewItem tvItem && !tvItem.IsExpanded)
{
tvItem.IsExpanded = true;
ViewModel.SelectedConflict = null;
}
};
this.WhenAnyValue(v => v.ViewModel.SelectedParentConflict).Subscribe(s =>
{
conflictList.SelectedIndex = 0;
}).DisposeWith(disposables);
base.OnActivated(disposables);
}

/// <summary>
Expand Down

0 comments on commit 0b71c72

Please sign in to comment.