Skip to content

Commit 03d3b45

Browse files
Merge pull request #99 from SyncfusionExamples/WPF-955409-Need_to_update_history_manager_sample
WPF-955409-Need to fix the custom actions issue in the History manager sample
2 parents 1b189da + 97ebd38 commit 03d3b45

File tree

1 file changed

+103
-6
lines changed

1 file changed

+103
-6
lines changed

Samples/HistoryManager/HistoryManagerStackView/Sample/ViewModel/HistoryManagerVM.cs

Lines changed: 103 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -268,6 +268,8 @@ public bool IsGroupAction
268268
}
269269

270270
public UndoRedoState State { get; set; }
271+
public bool FillColorChanged { get; set; }
272+
271273

272274
protected override void OnPropertyChanged(string name)
273275
{
@@ -297,7 +299,23 @@ protected override void OnPropertyChanged(string name)
297299
this.HistoryManager.LogData(this, data);
298300
}
299301

302+
303+
if (node.FillColor != (SolidColorBrush)new BrushConverter().ConvertFromString("White"))
304+
{
305+
FillColorChanged = true;
306+
}
300307
node.FillColor = selectedFillBrush;
308+
if (FillColorChanged)
309+
{
310+
HistoryEntry historyEntry = new HistoryEntry();
311+
historyEntry.Mode = EntryMode.External;
312+
historyEntry.Action = HistoryAction.CustomAction;
313+
historyEntry.GroupId = Guid.NewGuid();
314+
historyEntry.UndoElements.Add(selectedFillBrush);
315+
HistoryManager.UndoStack.Push(historyEntry);
316+
OnHistoryChanged(obj);
317+
FillColorChanged = false;
318+
}
301319
}
302320

303321
if (canLogData && !isGroupAction)
@@ -362,13 +380,52 @@ private void UpdateFormatingProperties(bool updateFontFamily = false, bool updat
362380
}
363381

364382
if (updateFontFamily)
365-
annotation.FontFamily = selectedFontFamily;
383+
{
384+
if (annotation.FontFamily == null || !annotation.FontFamily.Equals(selectedFontFamily))
385+
{
386+
annotation.FontFamily = selectedFontFamily;
387+
HistoryEntry historyEntry = new HistoryEntry();
388+
historyEntry.Mode = EntryMode.External;
389+
historyEntry.Action = HistoryAction.CustomAction;
390+
historyEntry.GroupId = Guid.NewGuid();
391+
historyEntry.UndoElements.Add(annotation.FontFamily);
392+
HistoryManager.UndoStack.Push(historyEntry);
393+
OnHistoryChanged(obj);
394+
}
395+
396+
}
366397

367398
if (updateFontSize)
368-
annotation.FontSize = selectedFontSize;
399+
{
400+
if (!annotation.FontSize.Equals(selectedFontSize))
401+
{
402+
annotation.FontSize = selectedFontSize;
403+
HistoryEntry historyEntry = new HistoryEntry();
404+
historyEntry.Mode = EntryMode.External;
405+
historyEntry.Action = HistoryAction.CustomAction;
406+
historyEntry.GroupId = Guid.NewGuid();
407+
historyEntry.UndoElements.Add(annotation.FontSize);
408+
HistoryManager.UndoStack.Push(historyEntry);
409+
OnHistoryChanged(obj);
410+
}
411+
}
369412

370413
if (updateFontColor)
371-
annotation.Foreground = selectedFontBrush;
414+
{
415+
416+
if (annotation.Foreground == null || !annotation.Foreground.Equals(selectedFontBrush))
417+
{
418+
annotation.Foreground = selectedFontBrush;
419+
HistoryEntry historyEntry = new HistoryEntry();
420+
historyEntry.Mode = EntryMode.External;
421+
historyEntry.Action = HistoryAction.CustomAction;
422+
historyEntry.GroupId = Guid.NewGuid();
423+
historyEntry.UndoElements.Add(annotation.Foreground);
424+
HistoryManager.UndoStack.Push(historyEntry);
425+
OnHistoryChanged(obj);
426+
;
427+
}
428+
}
372429
}
373430
}
374431
}
@@ -386,13 +443,52 @@ private void UpdateFormatingProperties(bool updateFontFamily = false, bool updat
386443
}
387444

388445
if (updateFontFamily)
389-
annotation.FontFamily = selectedFontFamily;
446+
{
447+
if (annotation.FontFamily == null || !annotation.FontFamily.Equals(selectedFontFamily))
448+
{
449+
annotation.FontFamily = selectedFontFamily;
450+
HistoryEntry historyEntry = new HistoryEntry();
451+
historyEntry.Mode = EntryMode.External;
452+
historyEntry.Action = HistoryAction.CustomAction;
453+
historyEntry.GroupId = Guid.NewGuid();
454+
historyEntry.UndoElements.Add(annotation.FontFamily);
455+
HistoryManager.UndoStack.Push(historyEntry);
456+
OnHistoryChanged(obj);
457+
}
458+
}
390459

391460
if (updateFontSize)
392-
annotation.FontSize = selectedFontSize;
461+
{
462+
if (!annotation.FontSize.Equals(selectedFontSize))
463+
{
464+
annotation.FontSize = selectedFontSize;
465+
466+
HistoryEntry historyEntry = new HistoryEntry();
467+
historyEntry.GroupId = Guid.NewGuid();
468+
historyEntry.Mode = EntryMode.External;
469+
historyEntry.Action = HistoryAction.CustomAction;
470+
historyEntry.UndoElements.Add(annotation.FontSize);
471+
HistoryManager.UndoStack.Push(historyEntry);
472+
OnHistoryChanged(obj);
473+
}
474+
475+
476+
}
393477

394478
if (updateFontColor)
395-
annotation.Foreground = selectedFontBrush;
479+
{
480+
if (annotation.Foreground == null || !annotation.Foreground.Equals(selectedFontBrush))
481+
{
482+
annotation.Foreground = selectedFontBrush;
483+
HistoryEntry historyEntry = new HistoryEntry();
484+
historyEntry.Mode = EntryMode.External;
485+
historyEntry.Action = HistoryAction.CustomAction;
486+
historyEntry.GroupId = Guid.NewGuid();
487+
historyEntry.UndoElements.Add(annotation.Foreground);
488+
HistoryManager.UndoStack.Push(historyEntry);
489+
OnHistoryChanged(obj);
490+
}
491+
}
396492
}
397493
}
398494
}
@@ -402,6 +498,7 @@ private void UpdateFormatingProperties(bool updateFontFamily = false, bool updat
402498
}
403499

404500
private bool canLogData = true;
501+
private object obj;
405502
private void OnItemSelected(object obj)
406503
{
407504
canLogData = false;

0 commit comments

Comments
 (0)