Add generic TreeView class
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
using System;
|
||||
using System.Net;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Net.Http;
|
||||
using System.Text;
|
||||
using System.Text.Json;
|
||||
using EstusShots.Client;
|
||||
using EstusShots.Gtk.DataStores;
|
||||
using EstusShots.Gtk.Controls;
|
||||
using EstusShots.Shared.Models;
|
||||
using Gtk;
|
||||
using Application = Gtk.Application;
|
||||
@@ -24,7 +25,7 @@ namespace EstusShots.Gtk
|
||||
[UI] private readonly Button _newSeasonButton = null;
|
||||
[UI] private readonly Label _infoLabel = null;
|
||||
|
||||
private SeasonsDataStore SeasonsView { get; set; }
|
||||
private BindableListView<Season> SeasonsView { get; set; }
|
||||
|
||||
public MainWindow() : this(new Builder("MainWindow.glade")) { }
|
||||
|
||||
@@ -37,17 +38,34 @@ namespace EstusShots.Gtk
|
||||
_loadButton.Clicked += LoadButtonClicked;
|
||||
_newSeasonButton.Clicked += NewSeasonButtonOnClicked;
|
||||
|
||||
SeasonsView = new SeasonsDataStore(_seasonsView);
|
||||
var seasonsColumns = new List<DataColumn>
|
||||
{
|
||||
new DataColumn(nameof(Season.DisplayName)){Title = "Name"}
|
||||
};
|
||||
SeasonsView = new BindableListView<Season>(seasonsColumns, nameof(Season.SeasonId) ,_seasonsView);
|
||||
SeasonsView.OnSelectionChanged += SeasonsViewOnOnSelectionChanged;
|
||||
|
||||
Info("Application Started");
|
||||
}
|
||||
|
||||
private void SeasonsViewOnOnSelectionChanged(object sender, SelectionChangedEventArgs e)
|
||||
{
|
||||
if (!(e.Selection is Season season)) return;
|
||||
Info($"Season '{season.DisplayName}' selected");
|
||||
}
|
||||
|
||||
private void NewSeasonButtonOnClicked(object sender, EventArgs e)
|
||||
{
|
||||
if (!SeasonsView.Items.Any())
|
||||
{
|
||||
Info("Cannot add Season (Not Loaded)");
|
||||
return;
|
||||
}
|
||||
var nextNum = SeasonsView.Items.Max(x => x.Number) + 1 ;
|
||||
var season = new Season
|
||||
{
|
||||
Game = "Test Game",
|
||||
Number = 1,
|
||||
Number = nextNum,
|
||||
Start = DateTime.Now
|
||||
};
|
||||
var content = new StringContent(JsonSerializer.Serialize(season), Encoding.UTF8, "application/json");
|
||||
@@ -61,7 +79,8 @@ namespace EstusShots.Gtk
|
||||
_infoLabel.Text = $"Error while creating Season: {response.ReasonPhrase}";
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
ReloadSeasons();
|
||||
Info($"Created new Season");
|
||||
}
|
||||
catch (Exception ex)
|
||||
@@ -70,23 +89,19 @@ namespace EstusShots.Gtk
|
||||
Console.WriteLine(ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
private void SeasonsViewOnShown(object sender, EventArgs e)
|
||||
{
|
||||
Info("Loading Data");
|
||||
// var seasons = Client.GetSeasons().Result;
|
||||
// SeasonsView.Data = seasons;
|
||||
// SeasonsView.DataBind();
|
||||
// Info("Data Loaded");
|
||||
}
|
||||
|
||||
private void LoadButtonClicked(object sender, EventArgs a)
|
||||
{
|
||||
var seasons = Client.GetSeasons().Result;
|
||||
SeasonsView.Data = seasons;
|
||||
SeasonsView.DataBind();
|
||||
ReloadSeasons();
|
||||
Info("List Refreshed");
|
||||
}
|
||||
|
||||
private void ReloadSeasons()
|
||||
{
|
||||
var seasons = Client.GetSeasons().Result;
|
||||
SeasonsView.Items = seasons;
|
||||
SeasonsView.DataBind();
|
||||
}
|
||||
|
||||
private void Window_DeleteEvent(object sender, DeleteEventArgs a)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user