|
@@ -65,17 +65,16 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
bool IDynamicGridUIComponentParent<T>.IsRefreshing => bRefreshing;
|
|
|
|
|
|
private readonly Label ClipboardSpacer;
|
|
|
-
|
|
|
private readonly Button Copy;
|
|
|
|
|
|
private readonly Label Count;
|
|
|
|
|
|
- private readonly Button Cut;
|
|
|
private readonly Border Disabler;
|
|
|
|
|
|
+ private readonly DynamicActionColumn? drag;
|
|
|
+
|
|
|
private readonly Button Delete;
|
|
|
private readonly DockPanel Docker;
|
|
|
- private readonly DynamicRowMovementColumn? down;
|
|
|
private readonly Button Edit;
|
|
|
private readonly Label EditSpacer;
|
|
|
private readonly Button Export;
|
|
@@ -91,17 +90,12 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
private DoubleAnimation LoadingFader = new DoubleAnimation(1d, 0.2d, new Duration(TimeSpan.FromSeconds(2))) { AutoReverse = true };
|
|
|
|
|
|
- //private readonly Button MultiEdit;
|
|
|
- private readonly Button Paste;
|
|
|
-
|
|
|
private readonly Button Print;
|
|
|
private readonly Label PrintSpacer;
|
|
|
|
|
|
private readonly StackPanel LeftButtonStack;
|
|
|
private readonly StackPanel RightButtonStack;
|
|
|
|
|
|
- private readonly DynamicRowMovementColumn? up;
|
|
|
-
|
|
|
protected DynamicGridRowStyleSelector<T> RowStyleSelector;
|
|
|
|
|
|
#region Events
|
|
@@ -205,12 +199,10 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
HiddenColumns = new HiddenColumnsList();
|
|
|
|
|
|
- if (ShowSequenceButtons)
|
|
|
+ drag = new DynamicImageColumn(InABox.Wpf.Resources.drag.AsBitmapImage()) { Position = DynamicActionColumnPosition.Start };
|
|
|
+ ActionColumns.Add(drag);
|
|
|
+ if (typeof(T).IsAssignableTo(typeof(ISequenceable)))
|
|
|
{
|
|
|
- up = new DynamicRowMovementColumn(DynamicRowMovement.Up, SwapRows);
|
|
|
- ActionColumns.Add(up);
|
|
|
- down = new DynamicRowMovementColumn(DynamicRowMovement.Down, SwapRows);
|
|
|
- ActionColumns.Add(down);
|
|
|
HiddenColumns.Add(x => (x as ISequenceable)!.Sequence);
|
|
|
}
|
|
|
|
|
@@ -261,18 +253,10 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
PrintSpacer = new Label { Width = 5 };
|
|
|
|
|
|
- Cut = CreateButton(Wpf.Resources.cut.AsBitmapImage(Color.White));
|
|
|
- Cut.Margin = new Thickness(0, 2, 2, 0);
|
|
|
- Cut.Click += Cut_Click;
|
|
|
-
|
|
|
- Copy = CreateButton(Wpf.Resources.copy.AsBitmapImage(Color.White));
|
|
|
+ Copy = CreateButton(Wpf.Resources.duplicate.AsBitmapImage(Color.White), tooltip: "Duplicate Rows");
|
|
|
Copy.Margin = new Thickness(0, 2, 2, 0);
|
|
|
Copy.Click += Copy_Click;
|
|
|
|
|
|
- Paste = CreateButton(Wpf.Resources.paste.AsBitmapImage(Color.White));
|
|
|
- Paste.Margin = new Thickness(0, 2, 2, 0);
|
|
|
- Paste.Click += Paste_Click;
|
|
|
-
|
|
|
ClipboardSpacer = new Label { Width = 5 };
|
|
|
|
|
|
Export = CreateButton(Wpf.Resources.doc_xls.AsBitmapImage(Color.White), "Export");
|
|
@@ -300,9 +284,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
LeftButtonStack.Children.Add(Print);
|
|
|
LeftButtonStack.Children.Add(PrintSpacer);
|
|
|
|
|
|
- LeftButtonStack.Children.Add(Cut);
|
|
|
LeftButtonStack.Children.Add(Copy);
|
|
|
- LeftButtonStack.Children.Add(Paste);
|
|
|
LeftButtonStack.Children.Add(ClipboardSpacer);
|
|
|
|
|
|
LeftButtonStack.Children.Add(Export);
|
|
@@ -390,12 +372,12 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
bool IDynamicGridUIComponentParent<T>.CanFilter()
|
|
|
{
|
|
|
- return !ShowSequenceButtons || !Options.EditRows;
|
|
|
+ return !Options.ReorderRows || !Options.EditRows;
|
|
|
}
|
|
|
|
|
|
bool IDynamicGridUIComponentParent<T>.CanSort()
|
|
|
{
|
|
|
- return !ShowSequenceButtons || !Options.EditRows;
|
|
|
+ return !Options.ReorderRows || !Options.EditRows;
|
|
|
}
|
|
|
|
|
|
T IDynamicGrid<T>.LoadItem(CoreRow row) => LoadItem(row);
|
|
@@ -430,7 +412,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
void IDynamicGridUIComponentParent<T>.HandleKey(KeyEventArgs e)
|
|
|
{
|
|
|
- if (ShowSequenceButtons)
|
|
|
+ if (Options.ReorderRows)
|
|
|
{
|
|
|
if (e.Key == Key.X && (Keyboard.Modifiers & ModifierKeys.Control) == ModifierKeys.Control)
|
|
|
{
|
|
@@ -653,8 +635,6 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
private static bool IsSequenced => typeof(T).GetInterfaces().Any(x => x.Equals(typeof(ISequenceable)));
|
|
|
|
|
|
- protected virtual bool ShowSequenceButtons => IsSequenced;
|
|
|
-
|
|
|
public double RowHeight
|
|
|
{
|
|
|
get => UIComponent.RowHeight;
|
|
@@ -694,10 +674,8 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
Print.Visibility = Options.Print ? Visibility.Visible : Visibility.Collapsed;
|
|
|
PrintSpacer.Visibility = Options.Print ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
- Cut.Visibility = ShowSequenceButtons && Options.EditRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
- Copy.Visibility = ShowSequenceButtons && Options.EditRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
- Paste.Visibility = ShowSequenceButtons && Options.EditRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
- ClipboardSpacer.Visibility = ShowSequenceButtons && Options.EditRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ Copy.Visibility = Options.ReorderRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ ClipboardSpacer.Visibility = Options.ReorderRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
Export.Visibility = Options.ExportData ? Visibility.Visible : Visibility.Collapsed;
|
|
|
Import.Visibility = Options.ImportData ? Visibility.Visible : Visibility.Collapsed;
|
|
@@ -715,14 +693,12 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
|
|
|
Delete.Visibility = Options.DeleteRows ? Visibility.Visible : Visibility.Collapsed;
|
|
|
|
|
|
- if (up != null && down != null)
|
|
|
+ if (drag is not null)
|
|
|
{
|
|
|
- var hasSequence = up.Position == DynamicActionColumnPosition.Start;
|
|
|
- var shouldHaveSequence = Options.EditRows;
|
|
|
- if(hasSequence != shouldHaveSequence)
|
|
|
+ var hasSequence = drag.Position == DynamicActionColumnPosition.Start;
|
|
|
+ if(hasSequence != Options.ReorderRows)
|
|
|
{
|
|
|
- up.Position = Options.EditRows ? DynamicActionColumnPosition.Start : DynamicActionColumnPosition.Hidden;
|
|
|
- down.Position = Options.EditRows ? DynamicActionColumnPosition.Start : DynamicActionColumnPosition.Hidden;
|
|
|
+ drag.Position = Options.ReorderRows ? DynamicActionColumnPosition.Start : DynamicActionColumnPosition.Hidden;
|
|
|
reloadColumns = true;
|
|
|
}
|
|
|
}
|
|
@@ -773,7 +749,7 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
public void Reconfigure(DynamicGridOptions options)
|
|
|
{
|
|
|
options.BeginUpdate().Clear();
|
|
|
- options.DragRows = IsSequenced;
|
|
|
+ options.ReorderRows = IsSequenced;
|
|
|
DoReconfigure(options);
|
|
|
OnReconfigureEvent(options);
|
|
|
options.EndUpdate();
|
|
@@ -2119,44 +2095,8 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
}
|
|
|
}
|
|
|
|
|
|
- private bool SwapRows(int row1, int row2)
|
|
|
- {
|
|
|
- CoreRow[] rows = Data.Rows.Where(x => x.Index.Equals(row1) || x.Index.Equals(row2)).ToArray();
|
|
|
- var items = LoadItems(rows);
|
|
|
- var first = (items.First() as ISequenceable)!;
|
|
|
- var last = (items.Last() as ISequenceable)!;
|
|
|
- var iBuf1 = first.Sequence;
|
|
|
- var iBuf2 = last.Sequence;
|
|
|
- first.Sequence = iBuf2;
|
|
|
- last.Sequence = iBuf1;
|
|
|
- SaveItems(items);
|
|
|
- return true;
|
|
|
- }
|
|
|
-
|
|
|
void IDynamicGridUIComponentParent<T>.MoveRows(InABox.Core.CoreRow[] rows, int index) => MoveRows(rows, index);
|
|
|
|
|
|
- protected virtual void MoveRows(CoreRow[] rows, int index)
|
|
|
- {
|
|
|
- var sequence = index < Data.Rows.Count
|
|
|
- ? Data.Rows[index].Get<ISequenceable, long>(x => x.Sequence)
|
|
|
- : Data.Rows[^1].Get<ISequenceable, long>(x => x.Sequence) + 1;
|
|
|
-
|
|
|
- var postRows = Data.Rows.Where(r => !rows.Contains(r) && r.Get<ISequenceable, long>(x => x.Sequence) >= sequence);
|
|
|
-
|
|
|
- var updates = rows.Concat(postRows).ToObjects<T>().ToArray();
|
|
|
- foreach (var update in updates)
|
|
|
- {
|
|
|
- ((ISequenceable)update).Sequence = sequence;
|
|
|
- sequence++;
|
|
|
- }
|
|
|
-
|
|
|
- if (updates.Length != 0)
|
|
|
- {
|
|
|
- SaveItems(updates);
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
#region ClipBuffer
|
|
|
|
|
|
private Tuple<ClipAction, CoreRow[]>? ClipBuffer;
|
|
@@ -2183,59 +2123,57 @@ public abstract class DynamicGrid<T> : DynamicGrid, IDynamicGridUIComponentParen
|
|
|
InvalidateGrid();
|
|
|
}
|
|
|
|
|
|
+ protected virtual bool BeforeCopy(IList<T> items)
|
|
|
+ {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
private void PasteFromClipBuffer()
|
|
|
{
|
|
|
if (ClipBuffer == null)
|
|
|
return;
|
|
|
+ var row = SelectedRows.FirstOrDefault();
|
|
|
+ MoveRows(ClipBuffer.Item2, row is not null ? (int)row.Index + 1 : Data.Rows.Count, isCopy: ClipBuffer.Item1 == ClipAction.Copy);
|
|
|
+ }
|
|
|
|
|
|
- if (!ShowSequenceButtons)
|
|
|
- return;
|
|
|
+ protected virtual void MoveRows(CoreRow[] rows, int index, bool isCopy = false)
|
|
|
+ {
|
|
|
+ if (!Options.ReorderRows || !IsSequenced) return;
|
|
|
|
|
|
- using (new WaitCursor())
|
|
|
+ var items = rows.ToArray<T>();
|
|
|
+ if (isCopy)
|
|
|
{
|
|
|
- var updates = ClipBuffer.Item2.Select(x => x.ToObject<T>()).ToList();
|
|
|
- if (BeforePaste(updates, ClipBuffer.Item1))
|
|
|
+ if (!BeforeCopy(items))
|
|
|
{
|
|
|
- var currow = SelectedRows.FirstOrDefault()
|
|
|
- ?? Data.Rows.LastOrDefault();
|
|
|
-
|
|
|
- var sequence = currow != null ? currow.Get<T, long>(c => ((ISequenceable)c).Sequence) : 0;
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- var postrows = Data.Rows.Where(r => !ClipBuffer.Item2.Contains(r) && r.Get<ISequenceable, long>(x => x.Sequence) >= sequence);
|
|
|
- updates.AddRange(LoadItems(postrows.ToArray()));
|
|
|
+ var sequence = index < Data.Rows.Count
|
|
|
+ ? Data.Rows[index].Get<ISequenceable, long>(x => x.Sequence)
|
|
|
+ : Data.Rows[^1].Get<ISequenceable, long>(x => x.Sequence) + 1;
|
|
|
|
|
|
- foreach (var update in updates)
|
|
|
- {
|
|
|
- sequence++;
|
|
|
- ((ISequenceable)update).Sequence = sequence;
|
|
|
- }
|
|
|
- }
|
|
|
+ var postRows = Data.Rows.Where(r => !rows.Contains(r) && r.Get<ISequenceable, long>(x => x.Sequence) >= sequence);
|
|
|
|
|
|
- if (updates.Count != 0)
|
|
|
- {
|
|
|
- SaveItems(updates);
|
|
|
- Refresh(false, true);
|
|
|
- }
|
|
|
+ var updates = items.Concat(postRows.ToObjects<T>()).ToArray();
|
|
|
+ foreach (var update in updates)
|
|
|
+ {
|
|
|
+ ((ISequenceable)update).Sequence = sequence;
|
|
|
+ sequence++;
|
|
|
}
|
|
|
- }
|
|
|
|
|
|
- protected virtual bool BeforePaste(IEnumerable<T> items, ClipAction action)
|
|
|
- {
|
|
|
- return true;
|
|
|
- }
|
|
|
- private void Cut_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- CutToClipBuffer();
|
|
|
+ if (updates.Length != 0)
|
|
|
+ {
|
|
|
+ SaveItems(updates);
|
|
|
+ Refresh(false, true);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
private void Copy_Click(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
- CopyToClipBuffer();
|
|
|
- }
|
|
|
-
|
|
|
- private void Paste_Click(object sender, RoutedEventArgs e)
|
|
|
- {
|
|
|
- PasteFromClipBuffer();
|
|
|
+ var rows = SelectedRows;
|
|
|
+ if (rows.Length == 0) return;
|
|
|
+ MoveRows(rows, rows[^1].Index + 1, isCopy: true);
|
|
|
}
|
|
|
|
|
|
#endregion
|