finally implemented sortinggit diff

This commit is contained in:
Lynne Megido 2020-09-06 14:39:30 +10:00
parent 6ffc144936
commit 2da88f92f6
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
4 changed files with 174 additions and 9 deletions

View file

@ -108,6 +108,11 @@ namespace Buypeeb {
this.builder = builder;
builder.Autoconnect(this);
var menuButtonFilter = (MenuButton)builder.GetObject("MenuButtonFilter");
var menuButtonSort = (MenuButton)builder.GetObject("MenuButtonSort");
menuButtonFilter.Child = (Image)builder.GetObject("ImageFilter");
menuButtonSort.Child = (Image)builder.GetObject("ImageSort");
this.selectionViewBox = (Box)builder.GetObject("SelectionViewBox");
this.endingLabel = (Label)builder.GetObject("LabelSelectedEnding");
this.searchEntry = (SearchEntry)builder.GetObject("FilterSearchEntry");
@ -335,6 +340,7 @@ namespace Buypeeb {
var l = (Label)this.builder.GetObject($"LabelSelected{row.Key}");
l.Text = row.Value;
}
this.UpdateSelectionEndTime();
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
noteBuffer.Clear();
@ -413,11 +419,56 @@ namespace Buypeeb {
return (accepted == ResponseType.Ok, response);
}
private string GetSortType() {
foreach (var name in new List<string> { "NameDescending", "NameAscending", "PriceDescending", "PriceAscending", "EndingDescending", "EndingAscending" }) {
var radio = (RadioMenuItem)this.builder.GetObject($"Sort{name}");
if (radio.Active) {
return name;
}
}
return "NameAscending";
}
private void RenderList() {
this.items.Clear();
foreach (var item in this.settings.watchlist.Values) {
items.AppendValues(item);
var values = this.settings.watchlist.Values;
IOrderedEnumerable<YahooAuctionsItem> sorted;
var type = this.GetSortType();
if (type == "NameDescending") {
sorted = values.OrderByDescending(item => item.name);
}
else if (type == "NameAscending") {
sorted = values.OrderBy(item => item.name);
}
else if (type == "PriceDescending") {
sorted = values.OrderByDescending(item => item.price);
}
else if (type == "PriceAscending") {
sorted = values.OrderBy(item => item.price);
}
else if (type == "EndingDescending") {
sorted = values.OrderByDescending(item => item.endDate);
}
else {
sorted = values.OrderBy(item => item.endDate);
}
if (settings.displayFavouritesAtTopOfList) {
foreach (var item in sorted.Where(item => item.favourite)) {
items.AppendValues(item);
}
foreach (var item in sorted.Where(item => !item.favourite)) {
items.AppendValues(item);
}
}
else {
foreach (var item in sorted) {
items.AppendValues(item);
}
}
var m = (TreeModelFilter)this.itemTreeView.Model;
m.Refilter();
}
@ -650,11 +701,22 @@ namespace Buypeeb {
ToggleButton s = (ToggleButton)sender;
this.selectedItem.favourite = s.Active;
// i don't know why this is necessary
var pathAndIter = this.GetRow(this.selectedItem.id);
if (pathAndIter.path != null) {
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
if (this.settings.displayFavouritesAtTopOfList) {
var id = this.selectedItem.id;
// re-render the list, to ensure the favourites get pushed to the top
this.RenderList();
// attempt to reselect the item we were just looking at
var pathAndIter = this.GetRow(id);
this.itemTreeView.Selection.SelectPath(pathAndIter.path);
}
else {
// i don't know why this is necessary
var pathAndIter = this.GetRow(this.selectedItem.id);
if (pathAndIter.path != null) {
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
}
}
}
private void ButtonSelectedNotesClearClicked(object sender, EventArgs args) {
@ -677,6 +739,10 @@ namespace Buypeeb {
}
}
private void SortMenuClosed(object sender, EventArgs args) {
this.RenderList();
}
// timers
private bool UpdateSelectionEndTime() {

View file

@ -9,6 +9,7 @@ namespace Buypeeb {
public int updateIntervalCritical { get; set; } = 60;
public int favouriteUpdateIntervalCritical { get; set; } = 30;
public bool displaySecondsInList { get; set; } = true;
public bool displayFavouritesAtTopOfList { get; set; } = true;
public Dictionary<string, YahooAuctionsItem> watchlist {
get; set;

View file

@ -31,7 +31,7 @@ namespace Buypeeb {
[Ignore]
public string id { get; set; }
public string name { get; set; }
private int price = 0;
public int price = 0;
public int winPrice;
public string originalName { get; set; }
public string notes { get; set; }

View file

@ -2,6 +2,87 @@
<!-- Generated with glade 3.36.0 -->
<interface>
<requires lib="gtk+" version="3.22"/>
<object class="GtkImage" id="ImageFilter">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">edit-find</property>
</object>
<object class="GtkImage" id="ImageSort">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="icon_name">view-sort-ascending</property>
</object>
<object class="GtkRadioMenuItem" id="SortMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="draw_as_radio">True</property>
</object>
<object class="GtkMenu" id="menu1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<signal name="selection-done" handler="SortMenuClosed" swapped="no"/>
<child>
<object class="GtkRadioMenuItem" id="SortNameAscending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Name, Ascending</property>
<property name="use_underline">True</property>
<property name="active">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="SortNameDescending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Name, Descending</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="SortPriceAscending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Price, low to high</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="SortPriceDescending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Price, high to low</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="SortEndingAscending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Ending soonest</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
<child>
<object class="GtkRadioMenuItem" id="SortEndingDescending">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label" translatable="yes">Ending latest</property>
<property name="use_underline">True</property>
<property name="draw_as_radio">True</property>
<property name="group">SortMenu</property>
</object>
</child>
</object>
<object class="GtkTextBuffer" id="TextBufferSelectedNotes"/>
<object class="GtkPopover" id="popover1">
<property name="can_focus">False</property>
@ -432,7 +513,7 @@
</packing>
</child>
<child>
<object class="GtkMenuButton">
<object class="GtkMenuButton" id="MenuButtonFilter">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
@ -448,6 +529,24 @@
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkMenuButton" id="MenuButtonSort">
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="focus_on_click">False</property>
<property name="receives_default">True</property>
<property name="popup">menu1</property>
<property name="use_popover">False</property>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
@ -491,7 +590,6 @@
<property name="fixed_width">100</property>
<property name="title" translatable="yes">Name</property>
<property name="expand">True</property>
<property name="clickable">True</property>
<child>
<object class="GtkCellRendererText"/>
</child>