much nicer way of rendering the list view, with easier updates and such

This commit is contained in:
Lynne Megido 2020-09-03 16:02:56 +10:00
parent 341a13e523
commit e52cc5d7d8
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
3 changed files with 94 additions and 49 deletions

View file

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

View file

@ -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";
}
} }
} }

View file

@ -1,19 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.36.0 --> <!-- Generated with glade 3.36.0 -->
<interface> <interface>
<requires lib="gtk+" version="3.22" /> <requires lib="gtk+" version="3.22"/>
<object class="GtkListStore" id="ListItems"> <object class="GtkListStore" id="ListItems">
<columns> <columns>
<!-- column-name Name --> <!-- column-name Name -->
<column type="gchararray" /> <column type="gchararray"/>
<!-- column-name PriceYen --> <!-- column-name PriceYen -->
<column type="gchararray" /> <column type="gchararray"/>
<!-- column-name PriceAUD --> <!-- column-name PriceAUD -->
<column type="gchararray" /> <column type="gchararray"/>
<!-- column-name Ending --> <!-- column-name Ending -->
<column type="gchararray" /> <column type="gchararray"/>
<!-- column-name id --> <!-- column-name id -->
<column type="gchararray" /> <column type="gchararray"/>
</columns> </columns>
<data> <data>
<row> <row>
@ -55,8 +55,8 @@
<property name="label" translatable="yes">Add new</property> <property name="label" translatable="yes">Add new</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-add</property> <property name="stock_id">gtk-add</property>
<signal name="clicked" handler="ButtonAddClicked" swapped="no" /> <signal name="clicked" handler="ButtonAddClicked" swapped="no"/>
<accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK" /> <accelerator key="n" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -71,8 +71,8 @@
<property name="label" translatable="yes">Update all</property> <property name="label" translatable="yes">Update all</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-refresh</property> <property name="stock_id">gtk-refresh</property>
<signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no" /> <signal name="clicked" handler="ButtonUpdateAllClicked" swapped="no"/>
<accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK" /> <accelerator key="r" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -97,7 +97,7 @@
<property name="label" translatable="yes">Undo</property> <property name="label" translatable="yes">Undo</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-undo</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -112,7 +112,7 @@
<property name="label" translatable="yes">Redo</property> <property name="label" translatable="yes">Redo</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-redo</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -137,7 +137,7 @@
<property name="label" translatable="yes">Clear ended</property> <property name="label" translatable="yes">Clear ended</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-clear</property> <property name="stock_id">gtk-clear</property>
<signal name="clicked" handler="ButtonClearEndedClicked" swapped="no" /> <signal name="clicked" handler="ButtonClearEndedClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -152,7 +152,7 @@
<property name="label" translatable="yes">Clear all</property> <property name="label" translatable="yes">Clear all</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-delete</property> <property name="stock_id">gtk-delete</property>
<signal name="clicked" handler="ButtonClearAllClicked" swapped="no" /> <signal name="clicked" handler="ButtonClearAllClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -177,7 +177,7 @@
<property name="label" translatable="yes">Open</property> <property name="label" translatable="yes">Open</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-open</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -192,8 +192,8 @@
<property name="label" translatable="yes">Save</property> <property name="label" translatable="yes">Save</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-save</property> <property name="stock_id">gtk-save</property>
<signal name="clicked" handler="ButtonSaveClicked" swapped="no" /> <signal name="clicked" handler="ButtonSaveClicked" swapped="no"/>
<accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK" /> <accelerator key="s" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -208,7 +208,7 @@
<property name="label" translatable="yes">Export as...</property> <property name="label" translatable="yes">Export as...</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-save-as</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -233,7 +233,7 @@
<property name="label" translatable="yes">Help</property> <property name="label" translatable="yes">Help</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-help</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -248,7 +248,7 @@
<property name="label" translatable="yes">Settings</property> <property name="label" translatable="yes">Settings</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-preferences</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> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -263,8 +263,8 @@
<property name="label" translatable="yes">Quit</property> <property name="label" translatable="yes">Quit</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<property name="stock_id">gtk-quit</property> <property name="stock_id">gtk-quit</property>
<signal name="clicked" handler="ButtonQuitClicked" swapped="no" /> <signal name="clicked" handler="ButtonQuitClicked" swapped="no"/>
<accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK" /> <accelerator key="q" signal="clicked" modifiers="GDK_CONTROL_MASK"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -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>
@ -296,7 +296,7 @@
<property name="activate_on_single_click">True</property> <property name="activate_on_single_click">True</property>
<child internal-child="selection"> <child internal-child="selection">
<object class="GtkTreeSelection"> <object class="GtkTreeSelection">
<signal name="changed" handler="tveItemsSelectionChanged" swapped="no" /> <signal name="changed" handler="tveItemsSelectionChanged" swapped="no"/>
</object> </object>
</child> </child>
<child> <child>
@ -308,7 +308,7 @@
<property name="expand">True</property> <property name="expand">True</property>
<property name="clickable">True</property> <property name="clickable">True</property>
<child> <child>
<object class="GtkCellRendererText" /> <object class="GtkCellRendererText"/>
<attributes> <attributes>
<attribute name="text">0</attribute> <attribute name="text">0</attribute>
</attributes> </attributes>
@ -320,7 +320,7 @@
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="title" translatable="yes">Price (¥)</property> <property name="title" translatable="yes">Price (¥)</property>
<child> <child>
<object class="GtkCellRendererText" /> <object class="GtkCellRendererText"/>
<attributes> <attributes>
<attribute name="text">1</attribute> <attribute name="text">1</attribute>
</attributes> </attributes>
@ -332,7 +332,7 @@
<property name="resizable">True</property> <property name="resizable">True</property>
<property name="title" translatable="yes">Price (AUD)</property> <property name="title" translatable="yes">Price (AUD)</property>
<child> <child>
<object class="GtkCellRendererText" /> <object class="GtkCellRendererText"/>
<attributes> <attributes>
<attribute name="text">2</attribute> <attribute name="text">2</attribute>
</attributes> </attributes>
@ -345,7 +345,7 @@
<property name="title" translatable="yes">Ending at</property> <property name="title" translatable="yes">Ending at</property>
<property name="clickable">True</property> <property name="clickable">True</property>
<child> <child>
<object class="GtkCellRendererText" /> <object class="GtkCellRendererText"/>
<attributes> <attributes>
<attribute name="text">3</attribute> <attribute name="text">3</attribute>
</attributes> </attributes>
@ -385,8 +385,8 @@
<property name="max_width_chars">40</property> <property name="max_width_chars">40</property>
<property name="lines">3</property> <property name="lines">3</property>
<attributes> <attributes>
<attribute name="weight" value="bold" /> <attribute name="weight" value="bold"/>
<attribute name="scale" value="2" /> <attribute name="scale" value="2"/>
</attributes> </attributes>
</object> </object>
<packing> <packing>
@ -597,22 +597,22 @@
</packing> </packing>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
<child> <child>
<placeholder /> <placeholder/>
</child> </child>
</object> </object>
<packing> <packing>
@ -647,7 +647,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no" /> <signal name="clicked" handler="ButtonViewBuyeeClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -661,7 +661,7 @@
<property name="visible">True</property> <property name="visible">True</property>
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<signal name="clicked" handler="ButtonViewYahooClicked" swapped="no" /> <signal name="clicked" handler="ButtonViewYahooClicked" swapped="no"/>
</object> </object>
<packing> <packing>
<property name="expand">False</property> <property name="expand">False</property>
@ -682,7 +682,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Remove</property> <property name="tooltip_text" translatable="yes">Remove</property>
<signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no" /> <signal name="clicked" handler="ButtonSelectedRemoveClicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="image4"> <object class="GtkImage" id="image4">
<property name="visible">True</property> <property name="visible">True</property>
@ -704,7 +704,7 @@
<property name="can_focus">True</property> <property name="can_focus">True</property>
<property name="receives_default">True</property> <property name="receives_default">True</property>
<property name="tooltip_text" translatable="yes">Rename</property> <property name="tooltip_text" translatable="yes">Rename</property>
<signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no" /> <signal name="clicked" handler="ButtonSelectedRenameClicked" swapped="no"/>
<child> <child>
<object class="GtkImage" id="image1"> <object class="GtkImage" id="image1">
<property name="visible">True</property> <property name="visible">True</property>
@ -829,7 +829,7 @@
</object> </object>
</child> </child>
<child type="titlebar"> <child type="titlebar">
<placeholder /> <placeholder/>
</child> </child>
</object> </object>
</interface> </interface>