Base data editing page in GTK client.
This commit is contained in:
@@ -83,7 +83,7 @@ namespace EstusShots.Gtk.Controls
|
||||
throw new TypeLoadException(
|
||||
$"Property '{column.PropertyName}' does not exist on Type '{item.GetType()}'");
|
||||
var val = prop.GetValue(item);
|
||||
if (column.Format != null) val = column.Format(val);
|
||||
if (column.DisplayConverter != null) val = column.DisplayConverter(val);
|
||||
row.Add(val);
|
||||
}
|
||||
|
||||
@@ -129,34 +129,11 @@ namespace EstusShots.Gtk.Controls
|
||||
{
|
||||
// Offset by one, because the first column in the data store is fixed to the key value of the row
|
||||
var valueIndex = Columns.IndexOf(dataColumn) + 1;
|
||||
var cell = GetRenderer(dataColumn);
|
||||
var attr = GetAttribute(dataColumn);
|
||||
dataColumn.PackStart(cell, true);
|
||||
dataColumn.AddAttribute(cell, attr, valueIndex);
|
||||
dataColumn.AddAttribute(dataColumn.Cell, dataColumn.ValueAttribute, valueIndex);
|
||||
TreeView.AppendColumn(dataColumn);
|
||||
}
|
||||
}
|
||||
|
||||
private CellRenderer GetRenderer(DataColumn column)
|
||||
{
|
||||
var property = typeof(T).GetProperty(column.PropertyName);
|
||||
return property?.PropertyType.Name switch
|
||||
{
|
||||
nameof(Boolean) => new CellRendererToggle(),
|
||||
_ => new CellRendererText()
|
||||
};
|
||||
}
|
||||
|
||||
private string GetAttribute(DataColumn column)
|
||||
{
|
||||
var property = typeof(T).GetProperty(column.PropertyName);
|
||||
return property?.PropertyType.Name switch
|
||||
{
|
||||
nameof(Boolean) => "active",
|
||||
_ => "text"
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
private void InitListStore()
|
||||
{
|
||||
var types = Columns
|
||||
|
||||
@@ -3,19 +3,18 @@ using Gtk;
|
||||
|
||||
namespace EstusShots.Gtk.Controls
|
||||
{
|
||||
public class DataColumn : TreeViewColumn
|
||||
public abstract class DataColumn : TreeViewColumn
|
||||
{
|
||||
public DataColumn()
|
||||
protected DataColumn(string propertyName)
|
||||
{
|
||||
PropertyName = propertyName;
|
||||
Title = propertyName;
|
||||
|
||||
Resizable = true;
|
||||
Reorderable = true;
|
||||
}
|
||||
|
||||
public DataColumn(string propertyName) : this()
|
||||
{
|
||||
PropertyName = propertyName;
|
||||
Title = propertyName;
|
||||
}
|
||||
public abstract string ValueAttribute { get; }
|
||||
|
||||
/// <summary>
|
||||
/// The name of the property in the data source, that should be show nin the view
|
||||
@@ -26,6 +25,64 @@ namespace EstusShots.Gtk.Controls
|
||||
/// Applies the given transformation on each item in the column.
|
||||
/// This changes only the display of the value.
|
||||
/// </summary>
|
||||
public Func<object, string> Format { get; set; }
|
||||
public abstract Func<object, string> DisplayConverter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cell renderer for rows in the column
|
||||
/// </summary>
|
||||
public abstract CellRenderer Cell { get; set; }
|
||||
}
|
||||
|
||||
public class DataColumnText : DataColumn
|
||||
{
|
||||
public DataColumnText(string propertyName) : base(propertyName)
|
||||
{
|
||||
ValueAttribute = "text";
|
||||
Cell = new CellRendererText();
|
||||
PackStart(Cell, true);
|
||||
}
|
||||
|
||||
|
||||
public override string ValueAttribute { get; }
|
||||
|
||||
public override Func<object, string> DisplayConverter { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// Cell renderer for rows in the column
|
||||
/// </summary>
|
||||
public sealed override CellRenderer Cell { get; set; }
|
||||
}
|
||||
|
||||
public class DataColumnBool : DataColumn
|
||||
{
|
||||
public DataColumnBool(string propertyName) : base(propertyName)
|
||||
{
|
||||
ValueAttribute = "active";
|
||||
Cell = new CellRendererToggle();
|
||||
PackStart(Cell, true);
|
||||
}
|
||||
|
||||
public override string ValueAttribute { get; }
|
||||
public override Func<object, string> DisplayConverter { get; set; }
|
||||
public sealed override CellRenderer Cell { get; set; }
|
||||
}
|
||||
|
||||
public class DataColumnDouble : DataColumn
|
||||
{
|
||||
public DataColumnDouble(string propertyName) : base(propertyName)
|
||||
{
|
||||
ValueAttribute = "text";
|
||||
Cell = new CellRendererSpin();
|
||||
PackStart(Cell, true);
|
||||
}
|
||||
|
||||
public int Digits
|
||||
{
|
||||
set => SetAttributes(Cell, "digits", value);
|
||||
}
|
||||
|
||||
public override string ValueAttribute { get; }
|
||||
public override Func<object, string> DisplayConverter { get; set; }
|
||||
public sealed override CellRenderer Cell { get; set; }
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user