Get and save player

This commit is contained in:
2020-03-02 19:40:46 +01:00
parent df5a9d3976
commit 3e72acf71a
6 changed files with 96 additions and 33 deletions

View File

@@ -100,7 +100,7 @@ namespace EstusShots.Gtk.Controls
}
}
private void TreeViewOnRowActivated(object o, RowActivatedArgs args)
private void TreeViewOnRowActivated(object o, RowActivatedArgs args)
{
if (!(o is TreeView tree)) return;
var selection = tree.Selection;
@@ -128,19 +128,35 @@ namespace EstusShots.Gtk.Controls
foreach (var dataColumn in Columns)
{
// Offset by one, because the first column in the data store is fixed to the key value of the row
var index = Columns.IndexOf(dataColumn) + 1;
var column = new TreeViewColumn(
dataColumn.Title,
new CellRendererText(),
"text", index)
{
Resizable = true,
Reorderable = true
};
TreeView.AppendColumn(column);
var valueIndex = Columns.IndexOf(dataColumn) + 1;
var cell = GetRenderer(dataColumn);
var attr = GetAttribute(dataColumn);
dataColumn.PackStart(cell, true);
dataColumn.AddAttribute(cell, attr, 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

View File

@@ -1,16 +1,20 @@
using System;
using Gtk;
namespace EstusShots.Gtk.Controls
{
public class DataColumn
public class DataColumn : TreeViewColumn
{
public DataColumn()
{
Resizable = true;
Reorderable = true;
}
public DataColumn(string propertyName)
{
PropertyName = propertyName;
Title = propertyName;
}
/// <summary>
@@ -18,11 +22,6 @@ namespace EstusShots.Gtk.Controls
/// </summary>
public string PropertyName { get; }
/// <summary>
/// The column header.
/// </summary>
public string Title { get; set; }
/// <summary>
/// Applies the given transformation on each item in the column.
/// This changes only the display of the value.