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 id { get; set; }
|
||||
public string name { get; set; }
|
||||
public int price;
|
||||
public int price = 0;
|
||||
public int win_price;
|
||||
public string original_name;
|
||||
public bool favourite { get; set; } = false;
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace Buypeeb {
|
|||
|
||||
private ListStore items;
|
||||
private Settings settings;
|
||||
private TreeView itemTreeView;
|
||||
|
||||
static SemaphoreSlim tasklimit = new SemaphoreSlim(4);
|
||||
|
||||
|
@ -48,12 +49,23 @@ namespace Buypeeb {
|
|||
this.Title = "Buypeeb";
|
||||
|
||||
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.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) {
|
||||
Console.WriteLine(row[ItemColumns.Name]);
|
||||
Console.WriteLine(row[0]);
|
||||
}
|
||||
|
||||
DeleteEvent += Window_Shutdown;
|
||||
}
|
||||
|
||||
|
@ -73,8 +85,20 @@ namespace Buypeeb {
|
|||
item.ready = true;
|
||||
Console.WriteLine($"{id} updated.");
|
||||
Gtk.Application.Invoke(delegate {
|
||||
// this.RenderListItem(id);\
|
||||
this.RenderList();
|
||||
//TODO: surely there's a better way to do this
|
||||
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() {
|
||||
this.items.Clear();
|
||||
foreach (KeyValuePair<string, Listing> entry in settings.watchlist) {
|
||||
string[] values = new[] { entry.Value.name, entry.Value.PriceJPY(), entry.Value.PriceAUD(), "whenever", entry.Value.id };
|
||||
this.items.AppendValues(values);
|
||||
foreach (var item in this.settings.watchlist) {
|
||||
items.AppendValues(item.Value);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -188,5 +211,27 @@ namespace Buypeeb {
|
|||
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";
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,19 +1,19 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!-- Generated with glade 3.36.0 -->
|
||||
<interface>
|
||||
<requires lib="gtk+" version="3.22" />
|
||||
<requires lib="gtk+" version="3.22"/>
|
||||
<object class="GtkListStore" id="ListItems">
|
||||
<columns>
|
||||
<!-- column-name Name -->
|
||||
<column type="gchararray" />
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name PriceYen -->
|
||||
<column type="gchararray" />
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name PriceAUD -->
|
||||
<column type="gchararray" />
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name Ending -->
|
||||
<column type="gchararray" />
|
||||
<column type="gchararray"/>
|
||||
<!-- column-name id -->
|
||||
<column type="gchararray" />
|
||||
<column type="gchararray"/>
|
||||
</columns>
|
||||
<data>
|
||||
<row>
|
||||
|
@ -55,8 +55,8 @@
|
|||
<property name="label" translatable="yes">Add new</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-add</property>
|
||||
<signal name="clicked" handler="ButtonAddClicked" swapped="no" />
|
||||
<accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<signal name="clicked" handler="ButtonAddClicked" swapped="no"/>
|
||||
<accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -71,8 +71,8 @@
|
|||
<property name="label" translatable="yes">Update all</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-refresh</property>
|
||||
<signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no" />
|
||||
<accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no"/>
|
||||
<accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -97,7 +97,7 @@
|
|||
<property name="label" translatable="yes">Undo</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-undo</property>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -112,7 +112,7 @@
|
|||
<property name="label" translatable="yes">Redo</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-redo</property>
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" />
|
||||
<accelerator key="z" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -137,7 +137,7 @@
|
|||
<property name="label" translatable="yes">Clear ended</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-clear</property>
|
||||
<signal name="clicked" handler="ButtonClearEndedClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonClearEndedClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -152,7 +152,7 @@
|
|||
<property name="label" translatable="yes">Clear all</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-delete</property>
|
||||
<signal name="clicked" handler="ButtonClearAllClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonClearAllClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -177,7 +177,7 @@
|
|||
<property name="label" translatable="yes">Open</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-open</property>
|
||||
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<accelerator key="o" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -192,8 +192,8 @@
|
|||
<property name="label" translatable="yes">Save</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-save</property>
|
||||
<signal name="clicked" handler="ButtonSaveClicked" swapped="no" />
|
||||
<accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<signal name="clicked" handler="ButtonSaveClicked" swapped="no"/>
|
||||
<accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -208,7 +208,7 @@
|
|||
<property name="label" translatable="yes">Export as...</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-save-as</property>
|
||||
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK" />
|
||||
<accelerator key="e" signal="clicked" modifiers="GDK_SHIFT_MASK | GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -233,7 +233,7 @@
|
|||
<property name="label" translatable="yes">Help</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-help</property>
|
||||
<accelerator key="slash" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<accelerator key="slash" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -248,7 +248,7 @@
|
|||
<property name="label" translatable="yes">Settings</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-preferences</property>
|
||||
<accelerator key="comma" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<accelerator key="comma" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -263,8 +263,8 @@
|
|||
<property name="label" translatable="yes">Quit</property>
|
||||
<property name="use_underline">True</property>
|
||||
<property name="stock_id">gtk-quit</property>
|
||||
<signal name="clicked" handler="ButtonQuitClicked" swapped="no" />
|
||||
<accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK" />
|
||||
<signal name="clicked" handler="ButtonQuitClicked" swapped="no"/>
|
||||
<accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -287,7 +287,7 @@
|
|||
<property name="shadow_type">in</property>
|
||||
<property name="min_content_width">200</property>
|
||||
<child>
|
||||
<object class="GtkTreeView">
|
||||
<object class="GtkTreeView" id="TreeViewItems">
|
||||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="model">ListItems</property>
|
||||
|
@ -296,7 +296,7 @@
|
|||
<property name="activate_on_single_click">True</property>
|
||||
<child internal-child="selection">
|
||||
<object class="GtkTreeSelection">
|
||||
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no" />
|
||||
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no"/>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
|
@ -308,7 +308,7 @@
|
|||
<property name="expand">True</property>
|
||||
<property name="clickable">True</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" />
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">0</attribute>
|
||||
</attributes>
|
||||
|
@ -320,7 +320,7 @@
|
|||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Price (¥)</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" />
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">1</attribute>
|
||||
</attributes>
|
||||
|
@ -332,7 +332,7 @@
|
|||
<property name="resizable">True</property>
|
||||
<property name="title" translatable="yes">Price (AUD)</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" />
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">2</attribute>
|
||||
</attributes>
|
||||
|
@ -345,7 +345,7 @@
|
|||
<property name="title" translatable="yes">Ending at</property>
|
||||
<property name="clickable">True</property>
|
||||
<child>
|
||||
<object class="GtkCellRendererText" />
|
||||
<object class="GtkCellRendererText"/>
|
||||
<attributes>
|
||||
<attribute name="text">3</attribute>
|
||||
</attributes>
|
||||
|
@ -385,8 +385,8 @@
|
|||
<property name="max_width_chars">40</property>
|
||||
<property name="lines">3</property>
|
||||
<attributes>
|
||||
<attribute name="weight" value="bold" />
|
||||
<attribute name="scale" value="2" />
|
||||
<attribute name="weight" value="bold"/>
|
||||
<attribute name="scale" value="2"/>
|
||||
</attributes>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -597,22 +597,22 @@
|
|||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
<child>
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
<packing>
|
||||
|
@ -647,7 +647,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -661,7 +661,7 @@
|
|||
<property name="visible">True</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<signal name="clicked" handler="ButtonViewYahooClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonViewYahooClicked" swapped="no"/>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="expand">False</property>
|
||||
|
@ -682,7 +682,7 @@
|
|||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Remove</property>
|
||||
<signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="image4">
|
||||
<property name="visible">True</property>
|
||||
|
@ -704,7 +704,7 @@
|
|||
<property name="can_focus">True</property>
|
||||
<property name="receives_default">True</property>
|
||||
<property name="tooltip_text" translatable="yes">Rename</property>
|
||||
<signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no" />
|
||||
<signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no"/>
|
||||
<child>
|
||||
<object class="GtkImage" id="image1">
|
||||
<property name="visible">True</property>
|
||||
|
@ -829,7 +829,7 @@
|
|||
</object>
|
||||
</child>
|
||||
<child type="titlebar">
|
||||
<placeholder />
|
||||
<placeholder/>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
|
|
Loading…
Reference in a new issue