action to jump back to the top
This commit is contained in:
parent
0f8d45219a
commit
e29c5d3e8d
3 changed files with 22 additions and 4 deletions
|
@ -62,6 +62,10 @@ class Application(Gtk.Application):
|
|||
self.add_action(action)
|
||||
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.connect('activate', self.on_refresh)
|
||||
self.add_action(action)
|
||||
|
@ -196,6 +200,10 @@ class Application(Gtk.Application):
|
|||
timeline = self.stack.get_visible_child()
|
||||
timeline.emit('refresh')
|
||||
|
||||
def on_top(self, action, param):
|
||||
timeline = self.stack.get_visible_child()
|
||||
timeline.emit('top')
|
||||
|
||||
def on_preferences(self, action, param):
|
||||
pass
|
||||
|
||||
|
|
|
@ -2,6 +2,10 @@
|
|||
<interface>
|
||||
<menu id="app-menu">
|
||||
<section>
|
||||
<item>
|
||||
<attribute name="action">app.top</attribute>
|
||||
<attribute name="label" translatable="yes">To Top</attribute>
|
||||
</item>
|
||||
<item>
|
||||
<attribute name="action">app.refresh</attribute>
|
||||
<attribute name="label" translatable="yes">Refresh</attribute>
|
||||
|
|
|
@ -187,6 +187,7 @@ class Timeline(Gtk.Box):
|
|||
|
||||
__gsignals__ = {
|
||||
'refresh': (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
'top': (GObject.SIGNAL_RUN_FIRST, None, ()),
|
||||
'reply': (GObject.SIGNAL_RUN_FIRST, None, (int,str,))
|
||||
}
|
||||
|
||||
|
@ -197,21 +198,21 @@ class Timeline(Gtk.Box):
|
|||
self.max_id = 0
|
||||
self.min_id = 0
|
||||
|
||||
scroller = Gtk.ScrolledWindow(
|
||||
self.scroller = Gtk.ScrolledWindow(
|
||||
halign='fill',
|
||||
kinetic_scrolling=True
|
||||
)
|
||||
self.view = Gtk.ListBox(
|
||||
selection_mode=Gtk.SelectionMode.NONE
|
||||
)
|
||||
scroller.add(self.view)
|
||||
self.pack_start(scroller, True, True, 0)
|
||||
self.scroller.add(self.view)
|
||||
self.pack_start(self.scroller, True, True, 0)
|
||||
|
||||
self.stream = stream
|
||||
self.load_timeline()
|
||||
|
||||
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()
|
||||
|
||||
|
@ -274,12 +275,17 @@ class Timeline(Gtk.Box):
|
|||
self.show_all()
|
||||
|
||||
def do_refresh(self):
|
||||
self.do_top()
|
||||
rows = self.view.get_children()
|
||||
for item in rows:
|
||||
self.view.remove(item)
|
||||
self.load_timeline()
|
||||
self.show_all()
|
||||
|
||||
def do_top(self):
|
||||
vadjustment = self.scroller.get_vadjustment()
|
||||
vadjustment.set_value(0)
|
||||
|
||||
def on_edge_reached(self, widget, pos):
|
||||
if pos == Gtk.PositionType.BOTTOM:
|
||||
self.load_timeline(True)
|
||||
|
|
Loading…
Reference in a new issue