|
@@ -355,6 +355,7 @@ namespace InABox.DynamicGrid
|
|
|
private readonly Button Export;
|
|
|
private readonly Label ExportSpacer;
|
|
|
private readonly Button DuplicateBtn;
|
|
|
+ private readonly Button SwitchViewBtn;
|
|
|
|
|
|
private readonly GridRowSizingOptions gridRowResizingOptions = new() { CanIncludeHiddenColumns = false, AutoFitMode = AutoFitMode.SmartFit };
|
|
|
private readonly Button Help;
|
|
@@ -428,6 +429,8 @@ namespace InABox.DynamicGrid
|
|
|
protected virtual FontStyle? GetCellFontStyle(CoreRow row, String columnname) => null;
|
|
|
protected virtual FontWeight? GetCellFontWeight(CoreRow row, String columnname) => null;
|
|
|
|
|
|
+ protected DynamicGridSettings Settings { get; set; }
|
|
|
+
|
|
|
public DynamicGrid() : base()
|
|
|
{
|
|
|
IsReady = false;
|
|
@@ -579,6 +582,10 @@ namespace InABox.DynamicGrid
|
|
|
Edit.Margin = new Thickness(0, 2, 2, 0);
|
|
|
Edit.Click += Edit_Click;
|
|
|
|
|
|
+ SwitchViewBtn = CreateButton(Wpf.Resources.alter.AsBitmapImage());
|
|
|
+ SwitchViewBtn.Margin = new Thickness(0, 2, 2, 0);
|
|
|
+ SwitchViewBtn.Click += SwitchView_Click;
|
|
|
+
|
|
|
EditSpacer = new Label { Width = 5 };
|
|
|
|
|
|
Print = CreateButton(Wpf.Resources.print.AsBitmapImage(Color.White));
|
|
@@ -618,6 +625,7 @@ namespace InABox.DynamicGrid
|
|
|
LeftButtonStack.Children.Add(Help);
|
|
|
LeftButtonStack.Children.Add(Add);
|
|
|
LeftButtonStack.Children.Add(Edit);
|
|
|
+ LeftButtonStack.Children.Add(SwitchViewBtn);
|
|
|
//Stack.Children.Add(MultiEdit);
|
|
|
LeftButtonStack.Children.Add(EditSpacer);
|
|
|
|
|
@@ -691,11 +699,13 @@ namespace InABox.DynamicGrid
|
|
|
? Visibility.Collapsed
|
|
|
: Visibility.Visible;
|
|
|
};
|
|
|
+
|
|
|
+ Settings = LoadSettings();
|
|
|
|
|
|
Init();
|
|
|
Reconfigure();
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
protected virtual void BeforeSelection(CancelEventArgs cancel)
|
|
|
{
|
|
|
OnBeforeSelection?.Invoke(cancel);
|
|
@@ -780,7 +790,9 @@ namespace InABox.DynamicGrid
|
|
|
? Visibility.Visible
|
|
|
: Visibility.Collapsed;
|
|
|
|
|
|
- var allowEditing = HasOption(DynamicGridOption.DirectEdit);
|
|
|
+ SwitchViewBtn.Visibility = HasOption(DynamicGridOption.DirectEdit) ? Visibility.Visible : Visibility.Collapsed;
|
|
|
+ var allowEditing = IsDirectEditMode();
|
|
|
+
|
|
|
if (DataGrid.AllowEditing != allowEditing)
|
|
|
{
|
|
|
DataGrid.NavigationMode = allowEditing ? NavigationMode.Cell : NavigationMode.Row;
|
|
@@ -828,6 +840,33 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
}
|
|
|
|
|
|
+ protected virtual DynamicGridSettings LoadSettings()
|
|
|
+ {
|
|
|
+ return new DynamicGridSettings();
|
|
|
+ }
|
|
|
+ protected virtual void SaveSettings(DynamicGridSettings settings)
|
|
|
+ {
|
|
|
+ }
|
|
|
+
|
|
|
+ public bool IsDirectEditMode(IEnumerable<DynamicGridOption>? options = null)
|
|
|
+ {
|
|
|
+ return HasOption(DynamicGridOption.DirectEdit, options)
|
|
|
+ && (Settings.ViewMode == DynamicGridSettings.DynamicGridViewMode.DirectEdit
|
|
|
+ || Settings.ViewMode == DynamicGridSettings.DynamicGridViewMode.Default);
|
|
|
+ }
|
|
|
+
|
|
|
+ private void SwitchView_Click(object sender, RoutedEventArgs e)
|
|
|
+ {
|
|
|
+ Settings.ViewMode = Settings.ViewMode switch
|
|
|
+ {
|
|
|
+ DynamicGridSettings.DynamicGridViewMode.Default => DynamicGridSettings.DynamicGridViewMode.Normal,
|
|
|
+ DynamicGridSettings.DynamicGridViewMode.Normal => DynamicGridSettings.DynamicGridViewMode.DirectEdit,
|
|
|
+ DynamicGridSettings.DynamicGridViewMode.DirectEdit or _ => DynamicGridSettings.DynamicGridViewMode.Normal
|
|
|
+ };
|
|
|
+ SaveSettings(Settings);
|
|
|
+ Reconfigure();
|
|
|
+ }
|
|
|
+
|
|
|
protected override DynamicGridRowStyleSelector<T> GetRowStyleSelector()
|
|
|
{
|
|
|
return new DynamicGridRowStyleSelector<T, DynamicGridRowStyle>();
|
|
@@ -857,7 +896,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
private void DataGrid_CurrentCellActivated(object? sender, CurrentCellActivatedEventArgs e)
|
|
|
{
|
|
|
- if (!HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (!IsDirectEditMode())
|
|
|
return;
|
|
|
if ((DataGrid.SelectionController.CurrentCellManager.CurrentCell?.IsEditing != true) && e.ActivationTrigger == ActivationTrigger.Keyboard)
|
|
|
DataGrid.SelectionController.CurrentCellManager.BeginEdit();
|
|
@@ -872,7 +911,7 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
else if (e.Key == Key.Tab)
|
|
|
{
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (IsDirectEditMode())
|
|
|
{
|
|
|
DataGrid.SelectionController.CurrentCellManager.EndEdit();
|
|
|
DataGrid.MoveFocus(new TraversalRequest(FocusNavigationDirection.Right));
|
|
@@ -1423,7 +1462,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
protected virtual void DoDoubleClick(object sender)
|
|
|
{
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (IsDirectEditMode())
|
|
|
return;
|
|
|
|
|
|
SelectItems(SelectedRows);
|
|
@@ -1462,7 +1501,7 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
var result = new DynamicGridColumns();
|
|
|
|
|
|
- var cols = HasOption(DynamicGridOption.DirectEdit)
|
|
|
+ var cols = IsDirectEditMode()
|
|
|
? new Columns<T>().Default(ColumnType.IncludeForeignKeys, ColumnType.ExcludeID)
|
|
|
: new Columns<T>().Default(ColumnType.IncludeLinked, ColumnType.ExcludeID);
|
|
|
result.AddRange(MasterColumns.Where(x => cols.Items.Any(c => c.Property.Equals(x.ColumnName)))
|
|
@@ -1864,7 +1903,7 @@ namespace InABox.DynamicGrid
|
|
|
}
|
|
|
else if (prop.PropertyType == typeof(bool))
|
|
|
{
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (IsDirectEditMode())
|
|
|
{
|
|
|
var checkcol = new GridCheckBoxColumn
|
|
|
{
|
|
@@ -1937,7 +1976,7 @@ namespace InABox.DynamicGrid
|
|
|
binding.Bindings.Add(new Binding(displaycol));
|
|
|
binding.Converter = new PopupConverter(lookupcolumns, pEditor.Type);
|
|
|
result.SetBinding(Label.ContentProperty, binding);
|
|
|
- result.Background = new SolidColorBrush(Colors.LightYellow);
|
|
|
+ //result.Background = new SolidColorBrush(Colors.WhiteSmoke);
|
|
|
return result;
|
|
|
}
|
|
|
);
|
|
@@ -1946,7 +1985,7 @@ namespace InABox.DynamicGrid
|
|
|
() =>
|
|
|
{
|
|
|
var result = new DockPanel();
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (IsDirectEditMode())
|
|
|
{
|
|
|
var button = new Button();
|
|
|
button.Content = "..";
|
|
@@ -2003,7 +2042,7 @@ namespace InABox.DynamicGrid
|
|
|
binding.Converter = new PopupConverter(lookupcolumns, pEditor.Type);
|
|
|
label.SetBinding(Label.ContentProperty, binding);
|
|
|
label.SetValue(DockPanel.DockProperty, Dock.Left);
|
|
|
- label.Background = new SolidColorBrush(Colors.LightYellow);
|
|
|
+ //label.Background = new SolidColorBrush(Colors.LightYellow);
|
|
|
result.Children.Add(label);
|
|
|
return result;
|
|
|
}
|
|
@@ -2054,7 +2093,7 @@ namespace InABox.DynamicGrid
|
|
|
newcol = textcol;
|
|
|
if (prop.PropertyType == typeof(string[]))
|
|
|
newcol.DisplayBinding = new Binding { Path = new PropertyPath(scolname), Converter = new StringArrayConverter() };
|
|
|
- textcol.AllowEditing = HasOption(DynamicGridOption.DirectEdit);
|
|
|
+ textcol.AllowEditing = IsDirectEditMode();
|
|
|
textcol.UpdateTrigger = UpdateSourceTrigger.PropertyChanged;
|
|
|
}
|
|
|
|
|
@@ -2093,7 +2132,7 @@ namespace InABox.DynamicGrid
|
|
|
newcol.HeaderStyle = headstyle;
|
|
|
|
|
|
var cellstyle = new Style();
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (IsDirectEditMode())
|
|
|
{
|
|
|
if (prop.Editor is null || !prop.Editor.Editable.IsDirectEditable())
|
|
|
{
|
|
@@ -2464,7 +2503,7 @@ namespace InABox.DynamicGrid
|
|
|
if (!result.Columns.Contains(colname))
|
|
|
{
|
|
|
result.Columns.Add(colname, column.DataType);
|
|
|
- if (!HasOption(DynamicGridOption.DirectEdit))
|
|
|
+ if (!IsDirectEditMode())
|
|
|
defaults.Add(column.DataType.GetDefault());
|
|
|
}
|
|
|
}
|
|
@@ -2780,7 +2819,7 @@ namespace InABox.DynamicGrid
|
|
|
{
|
|
|
//CoreRow row = (SelectedRow > -1) && (SelectedRow < Data.Rows.Count) ? Data.Rows[this.SelectedRow] : null;
|
|
|
|
|
|
- if (HasOption(DynamicGridOption.DirectEdit) && !OpenEditorOnDirectEdit)
|
|
|
+ if (IsDirectEditMode() && !OpenEditorOnDirectEdit)
|
|
|
{
|
|
|
if (!CanCreateItems())
|
|
|
return;
|
|
@@ -2882,7 +2921,7 @@ namespace InABox.DynamicGrid
|
|
|
|
|
|
editor.OnEditorValueChanged += (s, n, v) => EditorValueChanged(editor, items, n, v);
|
|
|
|
|
|
- editor.OnAfterEditorValueChanged += (g, n) => AfterEditorValueChanged(g, items, n);
|
|
|
+ editor.OnAfterEditorValueChanged += (g, args) => AfterEditorValueChanged(g, items, args);
|
|
|
|
|
|
editor.OnReconfigureEditors = g => DoReconfigureEditors(g, items);
|
|
|
|
|
@@ -2946,14 +2985,14 @@ namespace InABox.DynamicGrid
|
|
|
return editor.ShowDialog() == true;
|
|
|
}
|
|
|
|
|
|
- private Dictionary<String, object?> AfterEditorValueChanged(DynamicEditorGrid grid, T[] items, String columnnname)
|
|
|
+ private Dictionary<String, object?> AfterEditorValueChanged(DynamicEditorGrid grid, T[] items, AfterEditorValueChangedArgs args)
|
|
|
{
|
|
|
- var changes = new Dictionary<String, object?>();
|
|
|
- OnAfterEditorValueChanged(grid, items, columnnname, changes);
|
|
|
+ var changes = new Dictionary<string, object?>();
|
|
|
+ OnAfterEditorValueChanged(grid, items, args, changes);
|
|
|
return changes;
|
|
|
}
|
|
|
|
|
|
- protected virtual void OnAfterEditorValueChanged(DynamicEditorGrid grid, T[] items, String columnname, Dictionary<String, object?> changes)
|
|
|
+ protected virtual void OnAfterEditorValueChanged(DynamicEditorGrid grid, T[] items, AfterEditorValueChangedArgs args, Dictionary<String, object?> changes)
|
|
|
{
|
|
|
}
|
|
|
|
|
@@ -3637,7 +3676,7 @@ namespace InABox.DynamicGrid
|
|
|
private void SelectColumnsClick(object sender, RoutedEventArgs e)
|
|
|
{
|
|
|
var editor = new DynamicGridColumnsEditor(typeof(T));
|
|
|
- editor.DirectEdit = HasOption(DynamicGridOption.DirectEdit);
|
|
|
+ editor.DirectEdit = IsDirectEditMode();
|
|
|
|
|
|
editor.Columns.AddRange(VisibleColumns);
|
|
|
|