Skip to content

Commit c941bad

Browse files
committed
fix: replace CommandRecorder with HistoryManager in curve-related view models
1 parent 8b3a34b commit c941bad

File tree

3 files changed

+12
-22
lines changed

3 files changed

+12
-22
lines changed

src/Beutl/ViewModels/Tools/ColorGradingTabViewModel.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
using System.Text.Json.Nodes;
2+
using Beutl.Editor;
23
using Beutl.Engine;
34
using Beutl.Graphics.Effects;
45
using Beutl.Media;
@@ -130,8 +131,8 @@ public void Visit(IPropertyEditorContext context)
130131
if (serviceType == typeof(EditViewModel))
131132
return _editViewModel;
132133

133-
if (serviceType == typeof(CommandRecorder))
134-
return _editViewModel.CommandRecorder;
134+
if (serviceType == typeof(HistoryManager))
135+
return _editViewModel.HistoryManager;
135136

136137
if (serviceType == typeof(Element))
137138
return _currentElement;

src/Beutl/ViewModels/Tools/CurvePresenterViewModel.cs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using System.Collections.ObjectModel;
22
using System.Collections.Specialized;
3+
using Beutl.Editor;
34
using Beutl.Engine;
45
using Beutl.Graphics;
56
using Beutl.Graphics.Effects;
@@ -10,17 +11,16 @@ public sealed class CurvePresenterViewModel : IDisposable
1011
{
1112
private readonly Curves _effect;
1213
private readonly IProperty<CurveMap> _property;
13-
private readonly CommandRecorder _commandRecorder;
14-
private CurveMap? _oldValue;
14+
private readonly HistoryManager _history;
1515
private bool _isUpdating;
1616

1717
public CurvePresenterViewModel(string header, Curves effect, IProperty<CurveMap> property,
18-
CommandRecorder commandRecorder)
18+
HistoryManager history)
1919
{
2020
Header = header;
2121
_effect = effect;
2222
_property = property;
23-
_commandRecorder = commandRecorder;
23+
_history = history;
2424

2525
Points = new ObservableCollection<CurveControlPoint>(_property.CurrentValue.Points);
2626
Points.CollectionChanged += OnCollectionChanged;
@@ -33,23 +33,11 @@ public CurvePresenterViewModel(string header, Curves effect, IProperty<CurveMap>
3333

3434
public void BeginEdit()
3535
{
36-
_oldValue = _property.CurrentValue;
3736
}
3837

3938
public void EndEdit()
4039
{
41-
if (_oldValue == null) return;
42-
43-
CurveMap newValue = _property.CurrentValue;
44-
CurveMap oldValue = _oldValue;
45-
_oldValue = null;
46-
47-
if (oldValue != newValue)
48-
{
49-
RecordableCommands.Edit(_property, newValue, oldValue)
50-
.WithStoables([_effect])
51-
.DoAndRecord(_commandRecorder);
52-
}
40+
_history.Commit(CommandNames.EditProperty);
5341
}
5442

5543
// Viewからの変更を反映

src/Beutl/ViewModels/Tools/CurvesTabViewModel.cs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
using Beutl.ProjectSystem;
88
using Beutl.Services.PrimitiveImpls;
99
using Avalonia.Media.Imaging;
10+
using Beutl.Editor;
1011
using Reactive.Bindings;
1112
using Reactive.Bindings.Extensions;
1213

@@ -276,8 +277,8 @@ public void WriteToJson(JsonObject json)
276277
if (serviceType == typeof(EditViewModel))
277278
return _editViewModel;
278279

279-
if (serviceType == typeof(CommandRecorder))
280-
return _editViewModel.CommandRecorder;
280+
if (serviceType == typeof(HistoryManager))
281+
return _editViewModel.HistoryManager;
281282

282283
if (serviceType == typeof(Element))
283284
return _currentElement;
@@ -362,7 +363,7 @@ private void SetEditors(Curves? effect)
362363

363364
private CurvePresenterViewModel CreateCurve(IProperty<CurveMap> property)
364365
{
365-
var vm = new CurvePresenterViewModel(property.Name, _currentEffect!, property, _editViewModel.CommandRecorder);
366+
var vm = new CurvePresenterViewModel(property.Name, _currentEffect!, property, _editViewModel.HistoryManager);
366367
_editorContexts.Add(vm);
367368
return vm;
368369
}

0 commit comments

Comments
 (0)