Implement spoiler warnings in PostDialog
This commit is contained in:
parent
a8bfbaa685
commit
1d597e61dd
|
@ -7,12 +7,16 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
protected Gtk.TextView text;
|
||||
private Gtk.ScrolledWindow scroll;
|
||||
private Gtk.Label counter;
|
||||
private ImageToggleButton spoiler;
|
||||
private Gtk.MenuButton visibility;
|
||||
private Gtk.Button attach;
|
||||
private Gtk.Button cancel;
|
||||
private Gtk.Button publish;
|
||||
private AttachmentBox attachments;
|
||||
|
||||
private Gtk.Revealer spoiler_revealer;
|
||||
private Gtk.Entry spoiler_text;
|
||||
|
||||
protected Status? in_reply_to;
|
||||
protected StatusVisibility visibility_opt = StatusVisibility.PUBLIC;
|
||||
|
||||
|
@ -25,8 +29,8 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
transient_for: Tootle.window
|
||||
);
|
||||
in_reply_to = status;
|
||||
if (status != null)
|
||||
visibility_opt = status.visibility;
|
||||
if (in_reply_to != null)
|
||||
visibility_opt = in_reply_to.visibility;
|
||||
|
||||
var actions = get_action_area ().get_parent () as Gtk.Box;
|
||||
var content = get_content_area ();
|
||||
|
@ -38,6 +42,7 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
visibility.get_style_context ().remove_class ("image-button");
|
||||
visibility.can_default = false;
|
||||
visibility.set_focus_on_click (false);
|
||||
|
||||
attach = new Gtk.Button.from_icon_name ("mail-attachment-symbolic");
|
||||
attach.tooltip_text = _("Add Media");
|
||||
attach.valign = Gtk.Align.CENTER;
|
||||
|
@ -47,6 +52,14 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
attach.set_focus_on_click (false);
|
||||
attach.clicked.connect (() => attachments.select ());
|
||||
|
||||
spoiler = new ImageToggleButton ("image-red-eye-symbolic");
|
||||
spoiler.tooltip_text = _("Spoiler warning");
|
||||
spoiler.set_action ();
|
||||
spoiler.toggled.connect (() => {
|
||||
spoiler_revealer.reveal_child = spoiler.active;
|
||||
validate ();
|
||||
});
|
||||
|
||||
cancel = add_button(_("Cancel"), 5) as Gtk.Button;
|
||||
cancel.clicked.connect(() => this.destroy ());
|
||||
publish = add_button(_("Toot!"), 5) as Gtk.Button;
|
||||
|
@ -55,14 +68,23 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
publish_post ();
|
||||
});
|
||||
|
||||
spoiler_text = new Gtk.Entry ();
|
||||
spoiler_text.margin_start = 6;
|
||||
spoiler_text.margin_end = 6;
|
||||
spoiler_text.placeholder_text = _("Write your warning here");
|
||||
|
||||
spoiler_revealer = new Gtk.Revealer ();
|
||||
spoiler_revealer.add (spoiler_text);
|
||||
|
||||
text = new Gtk.TextView ();
|
||||
text.get_style_context ().add_class ("toot-text");
|
||||
text.wrap_mode = Gtk.WrapMode.WORD;
|
||||
text.buffer.changed.connect (update_counter);
|
||||
text.accepts_tab = false;
|
||||
text.buffer.changed.connect (validate);
|
||||
|
||||
scroll = new Gtk.ScrolledWindow (null, null);
|
||||
scroll.hscrollbar_policy = Gtk.PolicyType.NEVER;
|
||||
scroll.min_content_height = 150;
|
||||
scroll.min_content_height = 120;
|
||||
scroll.margin_start = 6;
|
||||
scroll.margin_end = 6;
|
||||
scroll.add (text);
|
||||
|
@ -72,14 +94,23 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
counter = new Gtk.Label ("500");
|
||||
|
||||
actions.pack_start (counter, false, false, 6);
|
||||
actions.pack_end (spoiler, false, false, 6);
|
||||
actions.pack_end (visibility, false, false, 0);
|
||||
actions.pack_end (attach, false, false, 6);
|
||||
content.pack_start (spoiler_revealer, false, false, 6);
|
||||
content.pack_start (scroll, false, false, 6);
|
||||
content.pack_start (attachments, false, false, 6);
|
||||
content.set_size_request (350, 150);
|
||||
content.set_size_request (350, 120);
|
||||
|
||||
if (in_reply_to != null) {
|
||||
spoiler.active = in_reply_to.sensitive;
|
||||
var status_spoiler_text = in_reply_to.spoiler_text != null ? in_reply_to.spoiler_text : "";
|
||||
spoiler_text.set_text (status_spoiler_text);
|
||||
}
|
||||
|
||||
show_all ();
|
||||
attachments.hide ();
|
||||
text.grab_focus ();
|
||||
}
|
||||
|
||||
private Gtk.MenuButton get_visibility_btn () {
|
||||
|
@ -115,12 +146,12 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
return button;
|
||||
}
|
||||
|
||||
private void update_counter () {
|
||||
private void validate () {
|
||||
var len = text.buffer.text.length;
|
||||
var remain = 500 - len;
|
||||
publish.sensitive = (remain >= 0);
|
||||
|
||||
counter.label = remain.to_string ();
|
||||
publish.sensitive = remain >= 0;
|
||||
}
|
||||
|
||||
public static void open (string? text = null, Status? reply_to = null) {
|
||||
|
@ -148,6 +179,11 @@ public class Tootle.PostDialog : Gtk.Dialog {
|
|||
if (in_reply_to != null)
|
||||
pars += "&in_reply_to_id=%s".printf (in_reply_to.id.to_string ());
|
||||
|
||||
if (spoiler.active) {
|
||||
pars += "&sensitive=true";
|
||||
pars += "&spoiler_text=" + Soup.URI.encode (spoiler_text.buffer.text, null);
|
||||
}
|
||||
|
||||
var url = "%s/api/v1/statuses%s".printf (Tootle.settings.instance_url, pars);
|
||||
var msg = new Soup.Message("POST", url);
|
||||
Tootle.network.queue(msg, (sess, mess) => {
|
||||
|
|
|
@ -57,8 +57,10 @@ public class Tootle.TimelineView : AbstractView {
|
|||
view.pack_start(separator, false, false, 0);
|
||||
view.pack_start(widget, false, false, 0);
|
||||
|
||||
if (first)
|
||||
if (first) {
|
||||
view.reorder_child (widget, 0);
|
||||
view.reorder_child (separator, 0);
|
||||
}
|
||||
}
|
||||
|
||||
public override void clear () {
|
||||
|
|
|
@ -5,7 +5,8 @@ public class Tootle.ImageToggleButton : Gtk.ToggleButton {
|
|||
public Gtk.Image icon;
|
||||
public Gtk.IconSize size;
|
||||
|
||||
public ImageToggleButton (string icon_name, Gtk.IconSize icon_size = Gtk.IconSize.SMALL_TOOLBAR) {
|
||||
public ImageToggleButton (string icon_name, Gtk.IconSize icon_size = Gtk.IconSize.BUTTON) {
|
||||
valign = Gtk.Align.CENTER;
|
||||
size = icon_size;
|
||||
icon = new Gtk.Image.from_icon_name (icon_name, icon_size);
|
||||
add (icon);
|
||||
|
|
Loading…
Reference in New Issue