Skip to content

Commit d10e536

Browse files
authored
Merge pull request #8 from WCKYWCKF/pr8
优化预览页面的UI,修复一些BUG
2 parents 67fded2 + 38097e9 commit d10e536

File tree

4 files changed

+58
-20
lines changed

4 files changed

+58
-20
lines changed

WCKYWCKF.Model2ViewModel.Editor/ViewModels/MainWindowViewModel.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
using Avalonia.Controls.Notifications;
1515
using DynamicData;
1616
using DynamicData.Binding;
17+
using FuzzySharp;
1718
using Irihi.Mantra.Markdown.Plugin.AvaloniaHybrid.MarkdigPlugins;
1819
using Markdig;
1920
using Markdig.Syntax;
@@ -149,6 +150,9 @@ public partial class TF : ObservableObject;
149150
private readonly SourceCache<M2VMReplaceGenerationInfo, string> _replaceGenerationInfos = new(y => y.GetKey());
150151
private readonly ReadOnlyObservableCollection<MetadataTDGItemViewModel> _selection;
151152

153+
[BindableDerivedList]
154+
private readonly ReadOnlyObservableCollection<ViewModelCodeFile> _filterPreviewGeneratedCodeFiles;
155+
152156
static MainWindowViewModel()
153157
{
154158
MDPipeline = new MarkdownPipelineBuilder()
@@ -335,6 +339,16 @@ y is FilterAccessibility.None ||
335339
PreviewGeneratedCodeFiles = [];
336340
SummaryGeneratedBorderMdDocument = new MarkdownDocument();
337341
RootTypePartialCodeBorderMdDocument = new MarkdownDocument();
342+
343+
this.WhenAnyValue(x => x.PreviewGeneratedCodeFiles)
344+
.Select(x =>
345+
x is null ? Array.Empty<ViewModelCodeFile>().AsObservableChangeSet() : x.AsObservableChangeSet())
346+
.Switch()
347+
.AutoRefreshOnObservable(_ => this.WhenAnyValue(x => x.PreviewGeneratedCodeFilesFilterByFileName))
348+
.Sort(SortExpressionComparer<ViewModelCodeFile>.Descending(x =>
349+
Fuzz.WeightedRatio(PreviewGeneratedCodeFilesFilterByFileName ?? "", x.FileName)))
350+
.Bind(out _filterPreviewGeneratedCodeFiles)
351+
.Subscribe();
338352
return;
339353

340354
void TryAdd<T>(List<T> target, T newItem)
@@ -380,6 +394,7 @@ void TryAdd<T>(List<T> target, T newItem)
380394
[Reactive] public partial string? LoadingMessage { get; set; }
381395

382396
[Reactive] public partial IReadOnlyList<ViewModelCodeFile>? PreviewGeneratedCodeFiles { get; set; }
397+
[Reactive] public partial string? PreviewGeneratedCodeFilesFilterByFileName { get; set; }
383398

384399
[ReactiveCommand(CanExecute = nameof(_metadataIsNotEmpty))]
385400
[RequiresDynamicCode(

WCKYWCKF.Model2ViewModel.Editor/Views/MainWindow.axaml.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ protected override void OnDetachedFromLogicalTree(LogicalTreeAttachmentEventArgs
9494

9595
private void OpenEditMemberBuildTypeDialog(OpenEditMemberBuildTypeDialogEvent e)
9696
{
97-
OverlayDialogOptions _overlayDialogOptions = new OverlayDialogOptions
97+
var _overlayDialogOptions = new OverlayDialogOptions
9898
{
9999
Title = "编辑成员构建类型",
100100
CanResize = false,
@@ -166,7 +166,7 @@ private async void MenuItem_OnClick(object? sender, RoutedEventArgs e)
166166
{
167167
if (ViewModel is null) return;
168168
await ViewModel.PreviewGeneratedCodeCommand.Execute();
169-
OverlayDialogOptions _overlayDialogOptions = new OverlayDialogOptions
169+
var _overlayDialogOptions = new OverlayDialogOptions
170170
{
171171
Title = "正在预览将会构建的代码",
172172
CanResize = false,

WCKYWCKF.Model2ViewModel.Editor/Views/PreviewGeneratedCodeDialog.axaml

Lines changed: 40 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,40 +13,63 @@
1313
x:Class="WCKYWCKF.Model2ViewModel.Editor.Views.PreviewGeneratedCodeDialog"
1414
x:DataType="vm:MainWindowViewModel">
1515
<Grid
16-
RowDefinitions="65*,35*"
16+
RowDefinitions="30*,35*,35*"
1717
ColumnDefinitions="35*,65*">
1818
<mantra:MarkdownView
1919
Grid.Row="0"
2020
Grid.Column="0"
2121
Margin="5"
2222
Document="{Binding SummaryGeneratedBorderMdDocument}" />
23-
<mantra:MarkdownView
23+
<ursa:LoadingContainer
2424
Grid.Row="1"
2525
Grid.Column="0"
26-
Grid.ColumnSpan="2"
2726
Margin="5"
28-
Document="{Binding RootTypePartialCodeBorderMdDocument}" />
27+
LoadingMessage="{Binding LoadingMessage}"
28+
IsLoading="{Binding LoadingMessage,Converter={x:Static ObjectConverters.IsNotNull}}"
29+
HorizontalContentAlignment="Stretch"
30+
VerticalContentAlignment="Stretch">
31+
<DockPanel>
32+
<TextBox
33+
DockPanel.Dock="Top"
34+
Classes="clearButton"
35+
Margin="0,5,0,5"
36+
Text="{Binding PreviewGeneratedCodeFilesFilterByFileName}" />
37+
<ListBox
38+
Name="ListBox"
39+
DockPanel.Dock="Bottom"
40+
SelectionMode="AlwaysSelected"
41+
ItemsSource="{Binding FilterPreviewGeneratedCodeFiles}">
42+
<ListBox.ItemTemplate>
43+
<DataTemplate>
44+
<TextBlock Text="{Binding FileName}" />
45+
</DataTemplate>
46+
</ListBox.ItemTemplate>
47+
</ListBox>
48+
</DockPanel>
49+
</ursa:LoadingContainer>
2950
<ursa:LoadingContainer
3051
Grid.Row="0"
52+
Grid.RowSpan="2"
3153
Grid.Column="1"
3254
Margin="5"
3355
LoadingMessage="{Binding LoadingMessage}"
3456
IsLoading="{Binding LoadingMessage,Converter={x:Static ObjectConverters.IsNotNull}}"
3557
HorizontalContentAlignment="Stretch"
3658
VerticalContentAlignment="Stretch">
37-
<TabControl
38-
ItemsSource="{Binding PreviewGeneratedCodeFiles}">
39-
<TabControl.ItemTemplate>
40-
<DataTemplate>
41-
<Label Content="{Binding FileName}" />
42-
</DataTemplate>
43-
</TabControl.ItemTemplate>
44-
<TabControl.ContentTemplate>
45-
<DataTemplate DataType="vm:ViewModelCodeFile">
46-
<mantra:MarkdownView Document="{Binding CodeMdDocument}" />
47-
</DataTemplate>
48-
</TabControl.ContentTemplate>
49-
</TabControl>
59+
<mantra:MarkdownView Document="{Binding #ListBox.((vm:ViewModelCodeFile)SelectedItem).CodeMdDocument}" />
60+
</ursa:LoadingContainer>
61+
<ursa:LoadingContainer
62+
Grid.Row="2"
63+
Grid.Column="0"
64+
Grid.ColumnSpan="2"
65+
Margin="5"
66+
LoadingMessage="{Binding LoadingMessage}"
67+
IsLoading="{Binding LoadingMessage,Converter={x:Static ObjectConverters.IsNotNull}}"
68+
HorizontalContentAlignment="Stretch"
69+
VerticalContentAlignment="Stretch">
70+
<mantra:MarkdownView
71+
Margin="5"
72+
Document="{Binding RootTypePartialCodeBorderMdDocument}" />
5073
</ursa:LoadingContainer>
5174
</Grid>
5275
</UserControl>

WCKYWCKF.Model2ViewModel.Share/SourceInfo/M2VMGenerationInfo.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ public List<ViewModelBuildInfo> CreateViewModelBuildInfos(out HashSet<M2VMConver
190190
{
191191
GlobalSourceFQType = m2VmTypeInfo.GlobalTypeFullName,
192192
ViewModelName = $"{m2VmTypeInfo.Name}SGVM",
193-
Namespace = m2VmTypeInfo.NameSpace,
193+
Namespace = NameSpace,
194194
Properties = properties
195195
});
196196
}

0 commit comments

Comments
 (0)