Add reply button

This commit is contained in:
bleakgrey 2018-04-24 17:50:38 +03:00
parent 541cd26ac3
commit 28456b2aa0
3 changed files with 25 additions and 11 deletions

View File

@ -54,7 +54,7 @@ public enum Tootle.NotificationType {
case MENTION:
return "user-available-symbolic";
case REBLOG:
return "edit-undo-symbolic";
return "go-up-symbolic";
case FAVORITE:
return "help-about-symbolic";
case FOLLOW:

View File

@ -4,12 +4,13 @@ using Tootle;
public class Tootle.PostDialog : Gtk.Dialog {
private static PostDialog dialog;
private Gtk.TextView text;
protected Gtk.TextView text;
private Gtk.Label counter;
private Gtk.MenuButton visibility;
private Gtk.Button publish;
private StatusVisibility visibility_opt;
protected int64? in_reply_to_id;
public PostDialog (Gtk.Window? parent) {
Object (
@ -106,9 +107,19 @@ public class Tootle.PostDialog : Gtk.Dialog {
}
}
public static void open_reply (Gtk.Window? parent, Status status){
if(dialog == null){
open (parent);
dialog.in_reply_to_id = status.id;
dialog.text.buffer.text = "@%s ".printf (status.account.username);
}
}
public void publish_post(){
var text_escaped = text.buffer.text.replace (" ", "%20");
var pars = "?status=" + text_escaped;
if (in_reply_to_id != null)
pars += "&in_reply_to_id=" + in_reply_to_id.to_string ();
pars += "&visibility=" + visibility_opt.to_string ();
var msg = new Soup.Message("POST", Settings.instance.instance_url + "/api/v1/statuses" + pars);

View File

@ -17,6 +17,7 @@ public class Tootle.StatusWidget : Gtk.Grid {
Gtk.Label favorites;
Gtk.ToggleButton reblog;
Gtk.ToggleButton favorite;
Gtk.ToggleButton reply;
Gtk.Button? spoiler_button;
construct {
@ -46,16 +47,21 @@ public class Tootle.StatusWidget : Gtk.Grid {
reblogs = new Gtk.Label ("0");
favorites = new Gtk.Label ("0");
reblog = get_action_button ();
reblog = get_action_button ("go-up-symbolic");
reblog.toggled.connect (() => {
if (reblog.sensitive)
toggle_reblog ();
});
favorite = get_action_button (false);
favorite = get_action_button ("help-about-symbolic");
favorite.toggled.connect (() => {
if (favorite.sensitive)
toggle_fav ();
});
reply = get_action_button ("edit-undo-symbolic");
reply.toggled.connect (() => {
reply.set_active (false);
PostDialog.open_reply (Tootle.window, this.status);
});
counters = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6); //TODO: currently useless
counters.margin_top = 6;
@ -63,6 +69,7 @@ public class Tootle.StatusWidget : Gtk.Grid {
counters.add (reblogs);
counters.add (favorite);
counters.add (favorites);
counters.add (reply);
counters.show_all ();
attach (avatar, 1, 1, 1, 4);
@ -77,7 +84,7 @@ public class Tootle.StatusWidget : Gtk.Grid {
get_style_context ().add_class ("status");
if (status.reblog != null){
var image = new Gtk.Image.from_icon_name("edit-undo-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
var image = new Gtk.Image.from_icon_name("go-up-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
image.halign = Gtk.Align.END;
image.margin_end = 8;
image.show ();
@ -138,12 +145,8 @@ public class Tootle.StatusWidget : Gtk.Grid {
CacheManager.instance.load_avatar (avatar_url, this.avatar, this.avatar_size);
}
private Gtk.ToggleButton get_action_button (bool reblog = true){
var path = "edit-undo-symbolic";
if (!reblog)
path = "help-about-symbolic";
var icon = new Gtk.Image.from_icon_name (path, Gtk.IconSize.SMALL_TOOLBAR);
private Gtk.ToggleButton get_action_button (string icon_path){
var icon = new Gtk.Image.from_icon_name (icon_path, Gtk.IconSize.SMALL_TOOLBAR);
var button = new Gtk.ToggleButton ();
button.can_default = false;
button.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);