finally implemented sortinggit diff
This commit is contained in:
parent
6ffc144936
commit
2da88f92f6
4 changed files with 174 additions and 9 deletions
|
@ -108,6 +108,11 @@ namespace Buypeeb {
|
||||||
this.builder = builder;
|
this.builder = builder;
|
||||||
builder.Autoconnect(this);
|
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.selectionViewBox = (Box)builder.GetObject("SelectionViewBox");
|
||||||
this.endingLabel = (Label)builder.GetObject("LabelSelectedEnding");
|
this.endingLabel = (Label)builder.GetObject("LabelSelectedEnding");
|
||||||
this.searchEntry = (SearchEntry)builder.GetObject("FilterSearchEntry");
|
this.searchEntry = (SearchEntry)builder.GetObject("FilterSearchEntry");
|
||||||
|
@ -335,6 +340,7 @@ namespace Buypeeb {
|
||||||
var l = (Label)this.builder.GetObject($"LabelSelected{row.Key}");
|
var l = (Label)this.builder.GetObject($"LabelSelected{row.Key}");
|
||||||
l.Text = row.Value;
|
l.Text = row.Value;
|
||||||
}
|
}
|
||||||
|
this.UpdateSelectionEndTime();
|
||||||
|
|
||||||
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
|
var noteBuffer = (TextBuffer)this.builder.GetObject("TextBufferSelectedNotes");
|
||||||
noteBuffer.Clear();
|
noteBuffer.Clear();
|
||||||
|
@ -413,11 +419,56 @@ namespace Buypeeb {
|
||||||
return (accepted == ResponseType.Ok, response);
|
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() {
|
private void RenderList() {
|
||||||
this.items.Clear();
|
this.items.Clear();
|
||||||
foreach (var item in this.settings.watchlist.Values) {
|
var values = this.settings.watchlist.Values;
|
||||||
items.AppendValues(item);
|
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;
|
var m = (TreeModelFilter)this.itemTreeView.Model;
|
||||||
m.Refilter();
|
m.Refilter();
|
||||||
}
|
}
|
||||||
|
@ -650,11 +701,22 @@ namespace Buypeeb {
|
||||||
ToggleButton s = (ToggleButton)sender;
|
ToggleButton s = (ToggleButton)sender;
|
||||||
this.selectedItem.favourite = s.Active;
|
this.selectedItem.favourite = s.Active;
|
||||||
|
|
||||||
// i don't know why this is necessary
|
if (this.settings.displayFavouritesAtTopOfList) {
|
||||||
var pathAndIter = this.GetRow(this.selectedItem.id);
|
var id = this.selectedItem.id;
|
||||||
if (pathAndIter.path != null) {
|
// re-render the list, to ensure the favourites get pushed to the top
|
||||||
this.items.EmitRowChanged(pathAndIter.path, pathAndIter.iter);
|
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) {
|
private void ButtonSelectedNotesClearClicked(object sender, EventArgs args) {
|
||||||
|
@ -677,6 +739,10 @@ namespace Buypeeb {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void SortMenuClosed(object sender, EventArgs args) {
|
||||||
|
this.RenderList();
|
||||||
|
}
|
||||||
|
|
||||||
// timers
|
// timers
|
||||||
|
|
||||||
private bool UpdateSelectionEndTime() {
|
private bool UpdateSelectionEndTime() {
|
||||||
|
|
|
@ -9,6 +9,7 @@ namespace Buypeeb {
|
||||||
public int updateIntervalCritical { get; set; } = 60;
|
public int updateIntervalCritical { get; set; } = 60;
|
||||||
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
public int favouriteUpdateIntervalCritical { get; set; } = 30;
|
||||||
public bool displaySecondsInList { get; set; } = true;
|
public bool displaySecondsInList { get; set; } = true;
|
||||||
|
public bool displayFavouritesAtTopOfList { get; set; } = true;
|
||||||
|
|
||||||
public Dictionary<string, YahooAuctionsItem> watchlist {
|
public Dictionary<string, YahooAuctionsItem> watchlist {
|
||||||
get; set;
|
get; set;
|
||||||
|
|
|
@ -31,7 +31,7 @@ namespace Buypeeb {
|
||||||
[Ignore]
|
[Ignore]
|
||||||
public string id { get; set; }
|
public string id { get; set; }
|
||||||
public string name { get; set; }
|
public string name { get; set; }
|
||||||
private int price = 0;
|
public int price = 0;
|
||||||
public int winPrice;
|
public int winPrice;
|
||||||
public string originalName { get; set; }
|
public string originalName { get; set; }
|
||||||
public string notes { get; set; }
|
public string notes { get; set; }
|
||||||
|
|
102
ui/main.glade
102
ui/main.glade
|
@ -2,6 +2,87 @@
|
||||||
<!-- 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="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="GtkTextBuffer" id="TextBufferSelectedNotes"/>
|
||||||
<object class="GtkPopover" id="popover1">
|
<object class="GtkPopover" id="popover1">
|
||||||
<property name="can_focus">False</property>
|
<property name="can_focus">False</property>
|
||||||
|
@ -432,7 +513,7 @@
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</child>
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkMenuButton">
|
<object class="GtkMenuButton" id="MenuButtonFilter">
|
||||||
<property name="visible">True</property>
|
<property name="visible">True</property>
|
||||||
<property name="can_focus">True</property>
|
<property name="can_focus">True</property>
|
||||||
<property name="focus_on_click">False</property>
|
<property name="focus_on_click">False</property>
|
||||||
|
@ -448,6 +529,24 @@
|
||||||
<property name="position">1</property>
|
<property name="position">1</property>
|
||||||
</packing>
|
</packing>
|
||||||
</child>
|
</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>
|
</object>
|
||||||
<packing>
|
<packing>
|
||||||
<property name="expand">False</property>
|
<property name="expand">False</property>
|
||||||
|
@ -491,7 +590,6 @@
|
||||||
<property name="fixed_width">100</property>
|
<property name="fixed_width">100</property>
|
||||||
<property name="title" translatable="yes">Name</property>
|
<property name="title" translatable="yes">Name</property>
|
||||||
<property name="expand">True</property>
|
<property name="expand">True</property>
|
||||||
<property name="clickable">True</property>
|
|
||||||
<child>
|
<child>
|
||||||
<object class="GtkCellRendererText"/>
|
<object class="GtkCellRendererText"/>
|
||||||
</child>
|
</child>
|
||||||
|
|
Loading…
Reference in a new issue