Skip to content

Commit 44a7262

Browse files
authored
Implement spinbutton to allow faster pagination (#312)
* Implement spinbutton to allow faster pagination * Update changelog
1 parent 58b2834 commit 44a7262

File tree

3 files changed

+35
-8
lines changed

3 files changed

+35
-8
lines changed

data/com.github.alecaddd.sequeler.appdata.xml.in.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
<ul>
4444
<li>You can now duplicate connections.</li>
4545
<li>Sorting columns now works as expected by actually running the ORDER BY query.</li>
46+
<li>Quickly jump to a specific result page with the handy dandy pagination popover.</li>
4647
<li>Show Comment Column inside table structure view.</li>
4748
</ul>
4849
</description>

debian/changelog

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ com.github.alecaddd.sequeler (0.7.5) xenial; urgency=medium
22

33
* You can now duplicate connections.
44
* Sorting columns now works as expected by actually running the ORDER BY query.
5+
* Quickly jump to a specific result page with the handy dandy pagination popover.
56
* Show Comment Column inside table structure view.
67

78
-- Alessandro Castellani <[email protected]> Thu, 04 Apr 2020 11:00:00 -0700

src/Layouts/Views/Content.vala

Lines changed: 33 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,10 @@ public class Sequeler.Layouts.Views.Content : Gtk.Grid {
2929
public Gtk.Label result_message;
3030
private Gtk.Spinner spinner;
3131

32+
private Gtk.Button pages_button;
33+
private Gtk.SpinButton pages_entry;
3234
private Sequeler.Partials.HeaderBarButton page_prev_btn;
3335
private Sequeler.Partials.HeaderBarButton page_next_btn;
34-
private Gtk.Label pages_label;
3536
private int tot_pages { get; set; default = 0; }
3637
private int current_page { get; set; default = 1; }
3738
private bool reloading { get; set; default = false; }
@@ -115,6 +116,7 @@ public class Sequeler.Layouts.Views.Content : Gtk.Grid {
115116

116117
public Gtk.Grid build_pagination () {
117118
var page_grid = new Gtk.Grid ();
119+
page_grid.valign = Gtk.Align.CENTER;
118120

119121
page_prev_btn = new Sequeler.Partials.HeaderBarButton ("go-previous-symbolic", _("Previous Page"));
120122
page_prev_btn.clicked.connect (go_prev_page);
@@ -126,12 +128,32 @@ public class Sequeler.Layouts.Views.Content : Gtk.Grid {
126128
page_next_btn.halign = Gtk.Align.END;
127129
page_next_btn.sensitive = false;
128130

129-
pages_label = new Gtk.Label (_("%d Pages").printf (tot_pages));
130-
pages_label.margin = 7;
131+
pages_button = new Gtk.Button.with_label (_("%d Pages").printf (tot_pages));
132+
pages_button.can_focus = false;
133+
pages_button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
134+
pages_button.set_tooltip_text (_("Jump to page…"));
135+
136+
pages_entry = new Gtk.SpinButton.with_range (0, 0, 1);
137+
pages_entry.margin = 3;
138+
pages_entry.value_changed.connect (() => {
139+
if (pages_entry.get_value_as_int () > tot_pages) {
140+
return;
141+
}
142+
current_page = pages_entry.get_value_as_int ();
143+
reload_results ();
144+
});
145+
146+
var pages_popover = new Gtk.Popover (pages_button);
147+
pages_popover.add (pages_entry);
148+
149+
pages_button.clicked.connect (() => {
150+
pages_popover.popup ();
151+
pages_popover.show_all ();
152+
});
131153

132154
page_grid.attach (page_prev_btn, 0, 0, 1, 1);
133155
page_grid.attach (new Gtk.Separator (Gtk.Orientation.VERTICAL), 1, 0, 1, 1);
134-
page_grid.attach (pages_label, 2, 0, 1, 1);
156+
page_grid.attach (pages_button, 2, 0, 1, 1);
135157
page_grid.attach (new Gtk.Separator (Gtk.Orientation.VERTICAL), 3, 0, 1, 1);
136158
page_grid.attach (page_next_btn, 4, 0, 1, 1);
137159

@@ -140,22 +162,25 @@ public class Sequeler.Layouts.Views.Content : Gtk.Grid {
140162

141163
private void update_pagination () {
142164
if (table_count <= settings.limit_results) {
143-
pages_label.set_text (_("1 Page"));
165+
pages_button.label = _("1 Page");
166+
pages_entry.set_range (1, 1);
144167
return;
145168
}
146169

147170
tot_pages = (int) Math.ceilf (((float) table_count) / settings.limit_results);
148-
pages_label.set_text (_("%d of %d Pages").printf (current_page, tot_pages));
171+
pages_button.label = _("%d of %d Pages").printf (current_page, tot_pages);
149172

150173
page_prev_btn.sensitive = (current_page > 1);
151174
page_next_btn.sensitive = (current_page < tot_pages);
175+
pages_entry.set_range (1, tot_pages);
152176
}
153177

154178
public Gtk.Label build_results_msg () {
155179
result_message = new Gtk.Label (_("No Results Available"));
156180
result_message.halign = Gtk.Align.START;
157-
result_message.margin = 7;
158-
result_message.margin_top = 6;
181+
result_message.margin_top = result_message.margin_bottom = 3;
182+
result_message.margin_start = result_message.margin_end = 9;
183+
result_message.ellipsize = Pango.EllipsizeMode.END;
159184
result_message.hexpand = true;
160185
result_message.wrap = true;
161186

0 commit comments

Comments
 (0)