Base data editing page in GTK client.

This commit is contained in:
2020-03-05 21:06:58 +01:00
parent d8035452d8
commit 118c15f6c9
13 changed files with 620 additions and 229 deletions

View File

@@ -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