Skip to content

Commit 4dd86fd

Browse files
author
Lains
committed
* - Make list & grid sort automatically
1 parent 2be85d6 commit 4dd86fd

File tree

3 files changed

+8
-9
lines changed

3 files changed

+8
-9
lines changed

data/ui/main_window.ui

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
<lookup name="notes">listview</lookup>
1313
</binding>
1414
<property name="sorter">
15-
<object class="NotejotNoteSorter"/>
15+
<object class="NotejotNoteSorter" id="sorter"/>
1616
</property>
1717
</object>
1818
</property>

src/MainWindow.vala

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@ namespace Notejot {
5252
public unowned Gtk.Overlay list_scroller;
5353
[GtkChild]
5454
public unowned Gtk.Overlay glist_scroller;
55+
[GtkChild]
56+
public unowned Gtk.Sorter sorter;
5557

5658
// Custom
5759
public MainWindow? mw {get; set;}
@@ -173,6 +175,7 @@ namespace Notejot {
173175
[GtkCallback]
174176
public void on_note_update_requested (Note note) {
175177
view_model.update_note (note);
178+
sorter.changed (Gtk.SorterChange.DIFFERENT);
176179
}
177180

178181
[GtkCallback]

src/Utils/NoteSorter.vala

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,14 +21,10 @@ class Notejot.NoteSorter : Gtk.Sorter {
2121
var note1 = item1 as Note;
2222
var note2 = item2 as Note;
2323

24-
if (note1 == null || note2 == null)
25-
return EQUAL;
26-
27-
if (note1.pinned || note2.pinned) {
28-
return LARGER;
29-
} else {
30-
return Gtk.Ordering.from_cmpfunc (note1.subtitle.collate (note2.subtitle));
31-
}
24+
var comp = (int) note2.pinned - (int) note1.pinned;
25+
if (comp == 0)
26+
comp = Gtk.Ordering.from_cmpfunc (note2.subtitle.collate(note1.subtitle));
27+
return comp;
3228
}
3329

3430
protected override Gtk.SorterOrder get_order () {

0 commit comments

Comments
 (0)