CPF/CPF.ReoGrid/Actions/RemoveRowsAction.cs
2024-06-24 10:15:59 +08:00

121 lines
3.3 KiB
C#

using System;
using System.Collections.Generic;
using System.Diagnostics;
using CPF.ReoGrid.Common;
using CPF.ReoGrid.Outline;
namespace CPF.ReoGrid.Actions
{
public class RemoveRowsAction : WorksheetReusableAction
{
public RemoveRowsAction(int row, int rows) : base(new RangePosition(row, 0, rows, -1))
{
}
public override void Do()
{
bool flag = base.Range.Rows == -1;
if (flag)
{
Logger.Log("remove rows", "attempt to remove all columns but grid must have one column, operation aborted.");
}
else
{
this.backupHeights = new int[base.Range.Rows];
for (int i = base.Range.Row; i <= base.Range.EndRow; i++)
{
this.backupHeights[i - base.Range.Row] = (int)base.Worksheet.RetrieveRowHeader(i).InnerHeight;
}
base.Range = base.Worksheet.FixRange(base.Range);
this.backupData = base.Worksheet.GetPartialGrid(base.Range);
Debug.Assert(this.backupData != null);
base.Worksheet.DeleteRows(base.Range.Row, base.Range.Rows, this);
}
}
public override void Undo()
{
bool flag = base.Range.Rows == -1;
if (flag)
{
Logger.Log("remove rows", "attempt to undo removing all rows from the worksheet must it must be have at least one row, operation aborted.");
}
else
{
base.Worksheet.InsertRows(base.Range.Row, base.Range.Rows);
bool flag2 = this.backupData == null;
if (flag2)
{
Logger.Log("remove rows", "no backup data");
Debug.Assert(false, "why no backup data here?");
}
base.Worksheet.SetPartialGrid(base.Range, this.backupData);
bool flag3 = this.changedOutlines != null;
if (flag3)
{
foreach (KeyValuePair<IReoGridOutline, BackupRangeInfo> keyValuePair in this.changedOutlines)
{
keyValuePair.Key.Start = keyValuePair.Value.start;
keyValuePair.Key.Count = keyValuePair.Value.count;
}
}
bool flag4 = this.deletedOutlines != null;
if (flag4)
{
foreach (IReoGridOutline reoGridOutline in this.deletedOutlines)
{
base.Worksheet.GroupRows(reoGridOutline.Start, reoGridOutline.Count);
}
}
bool flag5 = this.deletedNamedRanges != null;
if (flag5)
{
foreach (NamedRange namedRange in this.deletedNamedRanges)
{
base.Worksheet.AddNamedRange(namedRange);
}
}
bool flag6 = this.deletedHighlightRanges != null;
if (flag6)
{
foreach (HighlightRange range in this.deletedHighlightRanges)
{
base.Worksheet.AddHighlightRange(range);
}
}
bool flag7 = this.changedOutlines != null && this.changedOutlines.Count > 0;
if (flag7)
{
base.Worksheet.UpdateViewportController();
}
}
}
public override string GetName()
{
return "Remove Rows";
}
public override WorksheetReusableAction Clone(RangePosition range)
{
return new RemoveRowsAction(range.Row, range.Rows);
}
private PartialGrid backupData = null;
private int[] backupHeights;
internal List<NamedRange> deletedNamedRanges;
internal List<HighlightRange> deletedHighlightRanges;
internal Dictionary<NamedRange, BackupRangeInfo> changedNamedRange;
internal Dictionary<HighlightRange, BackupRangeInfo> changedHighlightRanges;
internal List<IReoGridOutline> deletedOutlines;
internal Dictionary<IReoGridOutline, BackupRangeInfo> changedOutlines;
}
}