Skip to content

Commit 0dc4d02

Browse files
committed
fix: update DataContext binding for TableEditorControl and enhance command execution logic
1 parent 5f42a28 commit 0dc4d02

5 files changed

Lines changed: 5 additions & 26 deletions

File tree

src/SharpFM/App.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
<Application.Styles>
88
<FluentTheme />
9+
<StyleInclude Source="avares://Avalonia.Controls.DataGrid/Themes/Fluent.xaml" />
910
<StyleInclude Source="avares://AvaloniaEdit/Themes/Fluent/AvaloniaEdit.xaml" />
1011

1112
<!-- Fluent 2 Design System Tokens and Styles -->

src/SharpFM/MainWindow.axaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -182,7 +182,7 @@
182182
Document="{Binding SelectedClip.ScriptDocument}" />
183183
<!-- Table editor for table/field clips -->
184184
<Border IsVisible="{Binding SelectedClip.IsTableClip, FallbackValue=False}">
185-
<schema:TableEditorControl x:Name="tableEditorControl" />
185+
<schema:TableEditorControl DataContext="{Binding SelectedClip.TableEditor}" />
186186
</Border>
187187
<!-- Fallback XML editor for other clips -->
188188
<AvaloniaEdit:TextEditor

src/SharpFM/MainWindow.axaml.cs

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
using System;
2-
using System.ComponentModel;
32
using Avalonia.Controls;
43
using AvaloniaEdit;
54
using AvaloniaEdit.TextMate;
6-
using SharpFM.Schema.Editor;
75
using SharpFM.Scripting;
86
using TextMateSharp.Grammars;
97

@@ -16,7 +14,6 @@ public partial class MainWindow : Window
1614
private TextMate.Installation? _xmlTextMateInstallation;
1715
private TextMate.Installation? _scriptTextMateInstallation;
1816
private Window? _xmlWindow;
19-
private TableEditorControl? _tableEditor;
2017

2118
public MainWindow()
2219
{
@@ -34,18 +31,6 @@ public MainWindow()
3431
_scriptController = new ScriptEditorController(scriptEditor);
3532
}
3633

37-
// Table editor — wire DataContext when selection changes
38-
_tableEditor = this.FindControl<TableEditorControl>("tableEditorControl");
39-
40-
// Listen for SelectedClip changes to update table editor DataContext
41-
DataContextChanged += (_, _) =>
42-
{
43-
if (DataContext is SharpFM.ViewModels.MainWindowViewModel mainVm)
44-
{
45-
mainVm.PropertyChanged += OnMainVmPropertyChanged;
46-
}
47-
};
48-
4934
// "View XML" menu item
5035
var viewXmlItem = this.FindControl<MenuItem>("viewXmlMenuItem");
5136
if (viewXmlItem != null)
@@ -54,16 +39,6 @@ public MainWindow()
5439
}
5540
}
5641

57-
private void OnMainVmPropertyChanged(object? sender, PropertyChangedEventArgs e)
58-
{
59-
if (e.PropertyName != "SelectedClip" || _tableEditor == null) return;
60-
61-
var mainVm = sender as SharpFM.ViewModels.MainWindowViewModel;
62-
var clip = mainVm?.SelectedClip;
63-
64-
_tableEditor.DataContext = clip?.IsTableClip == true ? clip.TableEditor : null;
65-
}
66-
6742
private void ShowXmlWindow()
6843
{
6944
var vm = (DataContext as SharpFM.ViewModels.MainWindowViewModel)?.SelectedClip;

src/SharpFM/Schema/Editor/TableEditorControl.axaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
xmlns:editor="using:SharpFM.Schema.Editor"
66
xmlns:model="using:SharpFM.Schema.Model"
77
x:Class="SharpFM.Schema.Editor.TableEditorControl"
8+
x:DataType="editor:TableEditorViewModel"
89
x:CompileBindings="False"
910
mc:Ignorable="d"
1011
d:DesignWidth="600" d:DesignHeight="400">

src/SharpFM/Schema/Editor/TableEditorViewModel.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,8 @@ public FmField? SelectedField
2727
{
2828
_selectedField = value;
2929
NotifyPropertyChanged();
30+
(RemoveFieldCommand as RelayCommand)?.RaiseCanExecuteChanged();
31+
(EditCalculationCommand as RelayCommand)?.RaiseCanExecuteChanged();
3032
}
3133
}
3234

0 commit comments

Comments
 (0)