action to jump back to the top

This commit is contained in:
Morgan McMillian 2020-12-22 17:02:31 -08:00
parent 0f8d45219a
commit e29c5d3e8d
3 changed files with 22 additions and 4 deletions

View file

@ -62,6 +62,10 @@ class Application(Gtk.Application):
self.add_action(action) self.add_action(action)
self.set_accels_for_action('app.newpost',["<Ctrl>n"]) self.set_accels_for_action('app.newpost',["<Ctrl>n"])
action = Gio.SimpleAction.new('top', None)
action.connect('activate', self.on_top)
self.add_action(action)
action = Gio.SimpleAction.new('refresh', None) action = Gio.SimpleAction.new('refresh', None)
action.connect('activate', self.on_refresh) action.connect('activate', self.on_refresh)
self.add_action(action) self.add_action(action)
@ -196,6 +200,10 @@ class Application(Gtk.Application):
timeline = self.stack.get_visible_child() timeline = self.stack.get_visible_child()
timeline.emit('refresh') timeline.emit('refresh')
def on_top(self, action, param):
timeline = self.stack.get_visible_child()
timeline.emit('top')
def on_preferences(self, action, param): def on_preferences(self, action, param):
pass pass

View file

@ -2,6 +2,10 @@
<interface> <interface>
<menu id="app-menu"> <menu id="app-menu">
<section> <section>
<item>
<attribute name="action">app.top</attribute>
<attribute name="label" translatable="yes">To Top</attribute>
</item>
<item> <item>
<attribute name="action">app.refresh</attribute> <attribute name="action">app.refresh</attribute>
<attribute name="label" translatable="yes">Refresh</attribute> <attribute name="label" translatable="yes">Refresh</attribute>

View file

@ -187,6 +187,7 @@ class Timeline(Gtk.Box):
__gsignals__ = { __gsignals__ = {
'refresh': (GObject.SIGNAL_RUN_FIRST, None, ()), 'refresh': (GObject.SIGNAL_RUN_FIRST, None, ()),
'top': (GObject.SIGNAL_RUN_FIRST, None, ()),
'reply': (GObject.SIGNAL_RUN_FIRST, None, (int,str,)) 'reply': (GObject.SIGNAL_RUN_FIRST, None, (int,str,))
} }
@ -197,21 +198,21 @@ class Timeline(Gtk.Box):
self.max_id = 0 self.max_id = 0
self.min_id = 0 self.min_id = 0
scroller = Gtk.ScrolledWindow( self.scroller = Gtk.ScrolledWindow(
halign='fill', halign='fill',
kinetic_scrolling=True kinetic_scrolling=True
) )
self.view = Gtk.ListBox( self.view = Gtk.ListBox(
selection_mode=Gtk.SelectionMode.NONE selection_mode=Gtk.SelectionMode.NONE
) )
scroller.add(self.view) self.scroller.add(self.view)
self.pack_start(scroller, True, True, 0) self.pack_start(self.scroller, True, True, 0)
self.stream = stream self.stream = stream
self.load_timeline() self.load_timeline()
self.view.connect('button-press-event', self.on_button_pressed) self.view.connect('button-press-event', self.on_button_pressed)
scroller.connect('edge-reached', self.on_edge_reached) self.scroller.connect('edge-reached', self.on_edge_reached)
action_group = Gio.SimpleActionGroup() action_group = Gio.SimpleActionGroup()
@ -274,12 +275,17 @@ class Timeline(Gtk.Box):
self.show_all() self.show_all()
def do_refresh(self): def do_refresh(self):
self.do_top()
rows = self.view.get_children() rows = self.view.get_children()
for item in rows: for item in rows:
self.view.remove(item) self.view.remove(item)
self.load_timeline() self.load_timeline()
self.show_all() self.show_all()
def do_top(self):
vadjustment = self.scroller.get_vadjustment()
vadjustment.set_value(0)
def on_edge_reached(self, widget, pos): def on_edge_reached(self, widget, pos):
if pos == Gtk.PositionType.BOTTOM: if pos == Gtk.PositionType.BOTTOM:
self.load_timeline(True) self.load_timeline(True)