Refactor click handlers
This commit is contained in:
parent
4862438e15
commit
d2fe580e0f
|
@ -1,7 +1,7 @@
|
|||
public class Tootle.Desktop {
|
||||
|
||||
// Open URI in the user's default application associated with it
|
||||
public static void open_uri (string uri) {
|
||||
public static bool open_uri (string uri) {
|
||||
try {
|
||||
Gtk.show_uri (null, uri, Gdk.CURRENT_TIME);
|
||||
}
|
||||
|
@ -9,6 +9,7 @@ public class Tootle.Desktop {
|
|||
warning ("Can't open %s: %s", uri, e.message);
|
||||
app.error (_("Error"), e.message);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// Copy a string to the clipboard
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
using Gtk;
|
||||
using Gdk;
|
||||
|
||||
public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
||||
|
||||
|
@ -35,8 +36,7 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
primary_stack.transition_type = Gtk.StackTransitionType.SLIDE_LEFT_RIGHT;
|
||||
primary_stack.show ();
|
||||
primary_stack.add_named (secondary_stack, "0");
|
||||
primary_stack.hexpand = true;
|
||||
primary_stack.vexpand = true;
|
||||
primary_stack.hexpand = primary_stack.vexpand = true;
|
||||
|
||||
spinner = new Spinner ();
|
||||
spinner.active = true;
|
||||
|
@ -89,7 +89,7 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
overlay.add_overlay (toast);
|
||||
overlay.set_size_request (450, 600);
|
||||
add (overlay);
|
||||
|
||||
|
||||
restore_state ();
|
||||
show_all ();
|
||||
}
|
||||
|
@ -106,13 +106,13 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
network.started.connect (() => spinner.show ());
|
||||
network.finished.connect (() => spinner.hide ());
|
||||
accounts.updated (accounts.saved_accounts);
|
||||
button_press_event.connect ((event) => {
|
||||
if (event.button == 8) {
|
||||
back ();
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
button_press_event.connect (on_button_press);
|
||||
}
|
||||
|
||||
private bool on_button_press (EventButton ev) {
|
||||
if (ev.button == 8)
|
||||
return back ();
|
||||
return false;
|
||||
}
|
||||
|
||||
private void add_header_view (AbstractView view, string[] accelerators, int32 num) {
|
||||
|
@ -130,7 +130,7 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
return int.parse (primary_stack.get_visible_child_name ());
|
||||
}
|
||||
|
||||
public void open_view (AbstractView widget) {
|
||||
public bool open_view (AbstractView widget) {
|
||||
var i = get_visible_id ();
|
||||
i++;
|
||||
widget.stack_pos = i;
|
||||
|
@ -138,17 +138,19 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
primary_stack.add_named (widget, i.to_string ());
|
||||
primary_stack.set_visible_child_name (i.to_string ());
|
||||
update_header ();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void back () {
|
||||
public bool back () {
|
||||
var i = get_visible_id ();
|
||||
if (i == 0)
|
||||
return;
|
||||
return false;
|
||||
|
||||
var child = primary_stack.get_child_by_name (i.to_string ());
|
||||
primary_stack.set_visible_child_name ((i-1).to_string ());
|
||||
child.destroy ();
|
||||
update_header ();
|
||||
return true;
|
||||
}
|
||||
|
||||
public void reopen_view (int view_id) {
|
||||
|
@ -160,7 +162,7 @@ public class Tootle.MainWindow: Gtk.Window, ISavedWindow {
|
|||
}
|
||||
|
||||
public override bool delete_event (Gdk.EventAny event) {
|
||||
this.destroy.connect (() => {
|
||||
destroy.connect (() => {
|
||||
if (!settings.always_online || accounts.is_empty ())
|
||||
app.remove_window (window_dummy);
|
||||
window = null;
|
||||
|
|
|
@ -10,18 +10,18 @@ public class Tootle.StatusView : AbstractView {
|
|||
root_status = status;
|
||||
request_context ();
|
||||
}
|
||||
|
||||
|
||||
private void prepend (Status status, bool is_root = false){
|
||||
var separator = new Gtk.Separator (Gtk.Orientation.HORIZONTAL);
|
||||
separator.show ();
|
||||
|
||||
|
||||
var widget = new StatusWidget (status);
|
||||
widget.avatar.button_press_event.connect (widget.open_account);
|
||||
widget.avatar.button_press_event.connect (widget.on_avatar_clicked);
|
||||
if (!is_root)
|
||||
widget.button_press_event.connect (widget.open);
|
||||
else
|
||||
widget.highlight ();
|
||||
|
||||
|
||||
if (!last_was_a_root) {
|
||||
widget.separator = separator;
|
||||
view.pack_start (separator, false, false, 0);
|
||||
|
@ -36,7 +36,7 @@ public class Tootle.StatusView : AbstractView {
|
|||
network.queue (msg, (sess, mess) => {
|
||||
try{
|
||||
var root = network.parse (mess);
|
||||
|
||||
|
||||
var ancestors = root.get_array_member ("ancestors");
|
||||
ancestors.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
|
@ -45,9 +45,9 @@ public class Tootle.StatusView : AbstractView {
|
|||
prepend (status);
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
prepend (root_status, true);
|
||||
|
||||
|
||||
var descendants = root.get_array_member ("descendants");
|
||||
descendants.foreach_element ((array, i, node) => {
|
||||
var object = node.get_object ();
|
||||
|
|
|
@ -59,7 +59,7 @@ public class Tootle.TimelineView : AbstractView {
|
|||
widget.separator = separator;
|
||||
widget.button_press_event.connect (widget.open);
|
||||
if (!is_status_owned (status))
|
||||
widget.avatar.button_press_event.connect (widget.open_account);
|
||||
widget.avatar.button_press_event.connect (widget.on_avatar_clicked);
|
||||
view.pack_start (separator, false, false, 0);
|
||||
view.pack_start (widget, false, false, 0);
|
||||
|
||||
|
|
|
@ -1,3 +1,5 @@
|
|||
using Gdk;
|
||||
|
||||
public class Tootle.AccountWidget : StatusWidget {
|
||||
|
||||
public AccountWidget (Account account) {
|
||||
|
@ -6,28 +8,30 @@ public class Tootle.AccountWidget : StatusWidget {
|
|||
status.url = account.url;
|
||||
status.content = "<a href=\"%s\">@%s</a>".printf (account.url, account.acct);
|
||||
status.created_at = account.created_at;
|
||||
|
||||
|
||||
base (status);
|
||||
|
||||
|
||||
counters.visible = false;
|
||||
title_acct.visible = false;
|
||||
content_label.margin_bottom = 12;
|
||||
button_press_event.connect (ev => {
|
||||
open_account (ev);
|
||||
return true;
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
protected override bool on_clicked (EventButton ev) {
|
||||
if (ev.button == 1)
|
||||
return on_avatar_clicked (ev);
|
||||
return false;
|
||||
}
|
||||
|
||||
public override bool open_menu (uint button, uint32 time) {
|
||||
var menu = new Gtk.Menu ();
|
||||
|
||||
|
||||
var item_open_link = new Gtk.MenuItem.with_label (_("Open in Browser"));
|
||||
item_open_link.activate.connect (() => Desktop.open_uri (status.url));
|
||||
var item_copy_link = new Gtk.MenuItem.with_label (_("Copy Link"));
|
||||
item_copy_link.activate.connect (() => Desktop.copy (status.url));
|
||||
menu.add (item_open_link);
|
||||
menu.add (item_copy_link);
|
||||
|
||||
|
||||
menu.show_all ();
|
||||
menu.popup_at_pointer ();
|
||||
return true;
|
||||
|
|
|
@ -67,8 +67,8 @@ public class Tootle.Widgets.ImageAttachment : Gtk.DrawingArea {
|
|||
});
|
||||
}
|
||||
catch (Error e) {
|
||||
error (e.message);
|
||||
app.error (_("File read error"), _("Can't read file %s: %s").printf (uri, e.message));
|
||||
app.error (_("File read error"), _("Can't read file %s: %s").printf (uri, e.message));
|
||||
warning (e.message);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -151,8 +151,7 @@ public class Tootle.Widgets.ImageAttachment : Gtk.DrawingArea {
|
|||
case 3:
|
||||
return open_menu (ev.button, ev.time);
|
||||
case 1:
|
||||
Desktop.open_uri (attachment.url);
|
||||
return true;
|
||||
return Desktop.open_uri (attachment.url);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -54,7 +54,7 @@ public class Tootle.NotificationWidget : Grid {
|
|||
status_widget = new StatusWidget (notification.status, true);
|
||||
status_widget.is_notification = true;
|
||||
status_widget.button_press_event.connect (status_widget.open);
|
||||
status_widget.avatar.button_press_event.connect (status_widget.open_account);
|
||||
status_widget.avatar.button_press_event.connect (status_widget.on_avatar_clicked);
|
||||
attach (status_widget, 1, 3, 3, 1);
|
||||
}
|
||||
|
||||
|
|
|
@ -67,8 +67,7 @@ public class Tootle.RichLabel : Gtk.Label {
|
|||
return true;
|
||||
}
|
||||
|
||||
Desktop.open_uri (url);
|
||||
return true;
|
||||
return Desktop.open_uri (url);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -247,33 +247,28 @@ public class Tootle.StatusWidget : Gtk.EventBox {
|
|||
return null;
|
||||
}
|
||||
|
||||
public bool open_account (EventButton ev) {
|
||||
if (ev.button == 8)
|
||||
return false;
|
||||
|
||||
var view = new AccountView (status.get_formal ().account);
|
||||
window.open_view (view);
|
||||
return true;
|
||||
public bool on_avatar_clicked (EventButton ev) {
|
||||
if (ev.button == 1) {
|
||||
var view = new AccountView (status.get_formal ().account);
|
||||
return window.open_view (view);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public bool open (EventButton ev) {
|
||||
if (ev.button == 8)
|
||||
return false;
|
||||
|
||||
var formal = status.get_formal ();
|
||||
var view = new StatusView (formal);
|
||||
window.open_view (view);
|
||||
return true;
|
||||
if (ev.button == 1) {
|
||||
var formal = status.get_formal ();
|
||||
var view = new StatusView (formal);
|
||||
return window.open_view (view);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
private bool on_clicked (EventButton ev) {
|
||||
if (ev.button == 8)
|
||||
return false;
|
||||
|
||||
protected virtual bool on_clicked (EventButton ev) {
|
||||
if (ev.button == 3)
|
||||
return open_menu (ev.button, ev.time);
|
||||
else
|
||||
return false;
|
||||
return false;
|
||||
|
||||
}
|
||||
|
||||
public virtual bool open_menu (uint button, uint32 time) {
|
||||
|
|
Loading…
Reference in New Issue