much nicer way of rendering the list view, with easier updates and such
This commit is contained in:
parent
341a13e523
commit
e52cc5d7d8
3 changed files with 94 additions and 49 deletions
|
@ -6,7 +6,7 @@ namespace Buypeeb {
|
||||||
public string url { get; set; }
|
public string url { get; set; }
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
public int price;
|
public int price = 0;
|
||||||
public int win_price;
|
public int win_price;
|
||||||
public string original_name;
|
public string original_name;
|
||||||
public bool favourite { get; set; } = false;
|
public bool favourite { get; set; } = false;
|
||||||
|
|
|
@ -37,6 +37,7 @@ namespace Buypeeb {
|
||||||
|
|
||||||
private ListStore items;
|
private ListStore items;
|
||||||
private Settings settings;
|
private Settings settings;
|
||||||
|
private TreeView itemTreeView;
|
||||||
|
|
||||||
static SemaphoreSlim tasklimit = new SemaphoreSlim(4);
|
static SemaphoreSlim tasklimit = new SemaphoreSlim(4);
|
||||||
|
|
||||||
|
@ -48,12 +49,23 @@ namespace Buypeeb {
|
||||||
this.Title = "Buypeeb";
|
this.Title = "Buypeeb";
|
||||||
|
|
||||||
builder.Autoconnect(this);
|
builder.Autoconnect(this);
|
||||||
this.items = (ListStore)builder.GetObject("ListItems");
|
|
||||||
|
// bind treeview columns to watchlist instead of needing to manually sync its liststore
|
||||||
|
this.itemTreeView = (TreeView)builder.GetObject("TreeViewItems");
|
||||||
|
this.items = new ListStore(typeof(Listing));
|
||||||
this.RenderList();
|
this.RenderList();
|
||||||
|
|
||||||
|
this.itemTreeView.Model = this.items;
|
||||||
|
//TODO: make this less verbose
|
||||||
|
this.itemTreeView.Columns[ItemColumns.Name].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.Name].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnName));
|
||||||
|
this.itemTreeView.Columns[ItemColumns.PriceYen].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.PriceYen].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnPriceYen));
|
||||||
|
this.itemTreeView.Columns[ItemColumns.PriceAUD].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.PriceAUD].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnPriceAUD));
|
||||||
|
this.itemTreeView.Columns[ItemColumns.Ending].SetCellDataFunc(this.itemTreeView.Columns[ItemColumns.Ending].Cells[0], new Gtk.TreeCellDataFunc(this.RenderColumnEnding));
|
||||||
|
|
||||||
foreach (object[] row in this.items) {
|
foreach (object[] row in this.items) {
|
||||||
Console.WriteLine(row[ItemColumns.Name]);
|
Console.WriteLine(row[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
DeleteEvent += Window_Shutdown;
|
DeleteEvent += Window_Shutdown;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -73,8 +85,20 @@ namespace Buypeeb {
|
||||||
item.ready = true;
|
item.ready = true;
|
||||||
Console.WriteLine($"{id} updated.");
|
Console.WriteLine($"{id} updated.");
|
||||||
Gtk.Application.Invoke(delegate {
|
Gtk.Application.Invoke(delegate {
|
||||||
// this.RenderListItem(id);\
|
//TODO: surely there's a better way to do this
|
||||||
this.RenderList();
|
TreeIter iter;
|
||||||
|
this.itemTreeView.Model.GetIterFirst(out iter);
|
||||||
|
|
||||||
|
for (int i = 0; i < this.itemTreeView.Model.IterNChildren(); i++) {
|
||||||
|
var x = (Listing)this.itemTreeView.Model.GetValue(iter, 0);
|
||||||
|
if (x.id == id) {
|
||||||
|
this.items.EmitRowChanged(this.itemTreeView.Model.GetPath(iter), iter);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
this.itemTreeView.Model.IterNext(ref iter);
|
||||||
|
}
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -114,9 +138,8 @@ namespace Buypeeb {
|
||||||
|
|
||||||
private void RenderList() {
|
private void RenderList() {
|
||||||
this.items.Clear();
|
this.items.Clear();
|
||||||
foreach (KeyValuePair<string, Listing> entry in settings.watchlist) {
|
foreach (var item in this.settings.watchlist) {
|
||||||
string[] values = new[] { entry.Value.name, entry.Value.PriceJPY(), entry.Value.PriceAUD(), "whenever", entry.Value.id };
|
items.AppendValues(item.Value);
|
||||||
this.items.AppendValues(values);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -188,5 +211,27 @@ namespace Buypeeb {
|
||||||
Console.WriteLine("ButtonSelectedRenameClicked");
|
Console.WriteLine("ButtonSelectedRenameClicked");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// column renderers
|
||||||
|
|
||||||
|
private void RenderColumnName(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
|
Listing item = (Listing)model.GetValue(iter, 0);
|
||||||
|
(cell as Gtk.CellRendererText).Text = item.name ?? "Loading...";
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderColumnPriceYen(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
|
Listing item = (Listing)model.GetValue(iter, 0);
|
||||||
|
(cell as Gtk.CellRendererText).Text = item.PriceJPY();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderColumnPriceAUD(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
|
Listing item = (Listing)model.GetValue(iter, 0);
|
||||||
|
(cell as Gtk.CellRendererText).Text = item.PriceAUD();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void RenderColumnEnding(Gtk.TreeViewColumn column, Gtk.CellRenderer cell, Gtk.ITreeModel model, Gtk.TreeIter iter) {
|
||||||
|
Listing item = (Listing)model.GetValue(iter, 0);
|
||||||
|
(cell as Gtk.CellRendererText).Text = "whatever";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -287,7 +287,7 @@
|
||||||
<property name="shadow_type">in</property>
|
<property name="shadow_type">in</property>
|
||||||
<property name="min_content_width">200</property>
|
<property name="min_content_width">200</property>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkTreeView">
|
<object class="GtkTreeView" id="TreeViewItems">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="model">ListItems</property>
|
<property name="model">ListItems</property>
|
||||||
|
|
Loading…
Reference in a new issue