This commit is contained in:
Bleak Grey 2020-06-01 03:54:20 +03:00
parent 5ca9db1839
commit 1806e9552c
3 changed files with 38 additions and 20 deletions

View File

@ -94,7 +94,10 @@ public class Tootle.API.Status : GLib.Object {
}
public Status.empty () {
Object (id: 0);
Object (
id: 0,
visibility: settings.default_post_visibility
);
}
public Status.from_account (API.Account account) {

View File

@ -71,6 +71,7 @@ public class Tootle.Dialogs.Compose : Window {
style_class: STYLE_CLASS_SUGGESTED_ACTION,
label: _("Post")
);
set_visibility (status.visibility);
}
public Compose.redraft (API.Status status) {
@ -79,22 +80,28 @@ public class Tootle.Dialogs.Compose : Window {
style_class: STYLE_CLASS_DESTRUCTIVE_ACTION,
label: _("Redraft")
);
set_visibility (status.visibility);
}
public Compose.reply (API.Status status) {
public Compose.reply (API.Status to) {
var template = new API.Status.empty ();
template.in_reply_to_id = status.in_reply_to_id;
template.in_reply_to_account_id = status.in_reply_to_account_id;
template.content = status.formal.get_reply_mentions ();
template.in_reply_to_id = to.id.to_string ();
template.in_reply_to_account_id = to.account.id.to_string ();
template.content = to.formal.get_reply_mentions ();
Object (
status: template,
style_class: STYLE_CLASS_SUGGESTED_ACTION,
label: _("Reply")
);
visibility_popover.selected = status.visibility;
set_visibility (to.visibility);
}
protected void validate () {
void set_visibility (API.Visibility v) {
visibility_popover.selected = v;
visibility_popover.invalidate ();
}
void validate () {
var remain = char_limit - content.buffer.get_char_count ();
if (cw_button.active)
remain -= (int)cw.buffer.length;
@ -105,12 +112,12 @@ public class Tootle.Dialogs.Compose : Window {
box.sensitive = true;
}
protected void on_error (int32 code, string reason) { //TODO: display errors
void on_error (int32 code, string reason) { //TODO: display errors
warning (reason);
validate ();
}
protected void on_post_button_clicked () {
void on_post_button_clicked () {
post_button.sensitive = false;
visibility_button.sensitive = false;
box.sensitive = false;
@ -124,7 +131,7 @@ public class Tootle.Dialogs.Compose : Window {
}
}
protected void publish () {
void publish () {
info ("Publishing new status...");
status.content = content.buffer.text;
status.spoiler_text = cw.text;

View File

@ -2,40 +2,39 @@ using Gtk;
public class Tootle.Widgets.VisibilityPopover: Popover {
protected RadioButton? group_owner;
protected MenuButton button;
protected int i = 0;
public API.Visibility selected { get; set; default = API.Visibility.PUBLIC; }
protected Box box;
RadioButton? group_owner;
MenuButton button;
construct {
var box = new Box (Orientation.VERTICAL, 8);
box.margin = 8;
box.show ();
add (box);
int i = 0;
foreach (API.Visibility item in API.Visibility.all ()){
var radio = new RadioButton.from_widget (group_owner);
radio.set_data ("i", (int) item);
if (group_owner == null)
group_owner = radio;
box.pack_start (radio, true, true, 0);
radio.toggled.connect (() => {
selected = item;
popdown ();
});
var label = new Label (@"<b>$(item.get_name())</b>\n$(item.get_desc())");
label.use_markup = true;
label.xalign = 0;
label.margin_start = 8;
radio.add (label);
i++;
}
box.show_all ();
}
@ -44,5 +43,14 @@ public class Tootle.Widgets.VisibilityPopover: Popover {
button.popover = this;
}
public void invalidate () {
unowned var group = group_owner.get_group ();
group.@foreach (w => {
int i = w.get_data ("i");
if (i == (int) selected)
w.active = true;
});
}
}