diff --git a/MainWindow.cs b/MainWindow.cs index ec062af..36f3fd5 100755 --- a/MainWindow.cs +++ b/MainWindow.cs @@ -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 { "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 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() { diff --git a/Settings.cs b/Settings.cs index def2f87..18f6808 100644 --- a/Settings.cs +++ b/Settings.cs @@ -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 watchlist { get; set; diff --git a/YahooAuctionsItem.cs b/YahooAuctionsItem.cs index 4601dc0..effeb20 100644 --- a/YahooAuctionsItem.cs +++ b/YahooAuctionsItem.cs @@ -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; } diff --git a/ui/main.glade b/ui/main.glade index b53ce11..ae3234e 100644 --- a/ui/main.glade +++ b/ui/main.glade @@ -2,6 +2,87 @@ + + True + False + edit-find + + + True + False + view-sort-ascending + + + True + False + True + + + True + False + + + + True + False + Name, Ascending + True + True + True + SortMenu + + + + + True + False + Name, Descending + True + True + SortMenu + + + + + True + False + Price, low to high + True + True + SortMenu + + + + + True + False + Price, high to low + True + True + SortMenu + + + + + True + False + Ending soonest + True + True + SortMenu + + + + + True + False + Ending latest + True + True + SortMenu + + + False @@ -432,7 +513,7 @@ - + True True False @@ -448,6 +529,24 @@ 1 + + + True + True + False + True + menu1 + False + + + + + + False + True + 2 + + False @@ -491,7 +590,6 @@ 100 Name True - True