Add toot visibility button
This commit is contained in:
parent
9eb35ac55f
commit
f6b37d9dd6
|
@ -26,6 +26,7 @@ executable(
|
|||
'src/CacheManager.vala',
|
||||
'src/API/Account.vala',
|
||||
'src/API/Status.vala',
|
||||
'src/API/StatusVisibility.vala',
|
||||
'src/Widgets/AlignedLabel.vala',
|
||||
'src/Widgets/AccountsButton.vala',
|
||||
'src/Widgets/StatusWidget.vala',
|
||||
|
|
|
@ -10,28 +10,6 @@ public class Tootle.Status{
|
|||
public string avatar;
|
||||
public string acct;
|
||||
|
||||
enum Visibility {
|
||||
PUBLIC,
|
||||
UNLISTED,
|
||||
PRIVATE,
|
||||
DIRECT;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
case PUBLIC:
|
||||
return "public";
|
||||
case UNLISTED:
|
||||
return "unlisted";
|
||||
case PRIVATE:
|
||||
return "private";
|
||||
case DIRECT:
|
||||
return "direct";
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public Status(int64 id) {
|
||||
this.id = id;
|
||||
}
|
||||
|
|
|
@ -0,0 +1,52 @@
|
|||
public enum Tootle.StatusVisibility {
|
||||
PUBLIC,
|
||||
UNLISTED,
|
||||
PRIVATE,
|
||||
DIRECT;
|
||||
|
||||
public string to_string() {
|
||||
switch (this) {
|
||||
case PUBLIC:
|
||||
return "public";
|
||||
case UNLISTED:
|
||||
return "unlisted";
|
||||
case PRIVATE:
|
||||
return "private";
|
||||
case DIRECT:
|
||||
return "direct";
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
public string get_desc() {
|
||||
switch (this) {
|
||||
case PUBLIC:
|
||||
return _("Post to public timelines");
|
||||
case UNLISTED:
|
||||
return _("Don\'t post to public timelines");
|
||||
case PRIVATE:
|
||||
return _("Post to followers only");
|
||||
case DIRECT:
|
||||
return _("Post to mentioned users only");
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
public string get_icon() {
|
||||
switch (this) {
|
||||
case PUBLIC:
|
||||
return "network-workgroup-symbolic";
|
||||
case UNLISTED:
|
||||
return "security-medium-symbolic";
|
||||
case PRIVATE:
|
||||
return "security-high-symbolic";
|
||||
case DIRECT:
|
||||
return "user-available-symbolic";
|
||||
default:
|
||||
assert_not_reached();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,10 +1,14 @@
|
|||
using Gtk;
|
||||
using Tootle;
|
||||
|
||||
public class Tootle.TootDialog : Gtk.Dialog {
|
||||
|
||||
private static TootDialog dialog;
|
||||
private Gtk.TextView text;
|
||||
private Gtk.Label counter;
|
||||
private Gtk.MenuButton visibility;
|
||||
|
||||
private StatusVisibility visibility_opt;
|
||||
|
||||
public TootDialog (Gtk.Window? parent) {
|
||||
Object (
|
||||
|
@ -14,39 +18,82 @@ public class Tootle.TootDialog : Gtk.Dialog {
|
|||
title: _("Toot"),
|
||||
transient_for: parent
|
||||
);
|
||||
var actions = get_action_area().get_parent() as Gtk.Box;
|
||||
var content = get_content_area();
|
||||
visibility_opt = StatusVisibility.PUBLIC;
|
||||
|
||||
var actions = get_action_area ().get_parent () as Gtk.Box;
|
||||
var content = get_content_area ();
|
||||
|
||||
visibility = get_visibility_btn ();
|
||||
var close = add_button(_("Cancel"), 5) as Gtk.Button;
|
||||
close.clicked.connect(() => {
|
||||
this.destroy ();
|
||||
});
|
||||
|
||||
var publish = add_button(_("Toot!"), 5) as Gtk.Button;
|
||||
publish.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
|
||||
publish.clicked.connect (() => {
|
||||
this.destroy (); //TODO: actually publish toots
|
||||
});
|
||||
|
||||
text = new Gtk.TextView();
|
||||
text = new Gtk.TextView ();
|
||||
text.margin_start = 6;
|
||||
text.margin_end = 6;
|
||||
text.get_style_context ().add_class ("toot-text");
|
||||
text.hexpand = true;
|
||||
text.wrap_mode = Gtk.WrapMode.WORD;
|
||||
text.buffer.changed.connect(update_counter);
|
||||
text.buffer.changed.connect (update_counter);
|
||||
|
||||
counter = new Gtk.Label ("500");
|
||||
|
||||
actions.pack_start (visibility, false, false, 6);
|
||||
actions.pack_start (counter, false, false, 6);
|
||||
content.pack_start (text, false, false, 0);
|
||||
content.set_size_request (300, 100);
|
||||
}
|
||||
|
||||
private void update_counter(){
|
||||
private Gtk.MenuButton get_visibility_btn (){
|
||||
var button = new Gtk.MenuButton ();
|
||||
var icon = new Gtk.Image.from_icon_name (visibility_opt.get_icon (), Gtk.IconSize.SMALL_TOOLBAR);
|
||||
var menu = new Gtk.Popover (null);
|
||||
var box = new Gtk.Box (Gtk.Orientation.VERTICAL, 6);
|
||||
box.margin = 6;
|
||||
menu.add (box);
|
||||
button.direction = Gtk.ArrowType.DOWN;
|
||||
|
||||
StatusVisibility[] opts = {StatusVisibility.PUBLIC, StatusVisibility.UNLISTED, StatusVisibility.PRIVATE, StatusVisibility.DIRECT};
|
||||
|
||||
Gtk.RadioButton* first = null;
|
||||
foreach (StatusVisibility opt in opts){
|
||||
var item = new Gtk.RadioButton.with_label_from_widget (first, opt.get_desc ());
|
||||
if(first == null)
|
||||
first = item;
|
||||
|
||||
item.toggled.connect (() => {
|
||||
visibility_opt = opt;
|
||||
button.remove (icon);
|
||||
icon = new Gtk.Image.from_icon_name (opt.get_icon (), Gtk.IconSize.SMALL_TOOLBAR);
|
||||
icon.show ();
|
||||
button.add (icon);
|
||||
});
|
||||
box.pack_start (item, false, false, 0);
|
||||
}
|
||||
|
||||
box.show_all ();
|
||||
button.use_popover = true;
|
||||
button.popover = menu;
|
||||
button.valign = Gtk.Align.CENTER;
|
||||
button.add (icon);
|
||||
button.show ();
|
||||
|
||||
return button;
|
||||
}
|
||||
|
||||
private void update_counter (){
|
||||
var len = text.buffer.text.length;
|
||||
|
||||
counter.label = (500 - len).to_string ();
|
||||
}
|
||||
|
||||
public static void open(Gtk.Window? parent){
|
||||
public static void open (Gtk.Window? parent){
|
||||
if(dialog == null){
|
||||
dialog = new TootDialog (parent);
|
||||
dialog.destroy.connect (() => {
|
||||
|
|
|
@ -9,7 +9,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
|||
|
||||
private class AccountView : Gtk.Grid{
|
||||
|
||||
public Gtk.Label name;
|
||||
public Gtk.Label display_name;
|
||||
public Gtk.Label user;
|
||||
public Gtk.Button logout;
|
||||
|
||||
|
@ -17,10 +17,10 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
|||
margin = 6;
|
||||
margin_start = 14;
|
||||
|
||||
name = new Gtk.Label ("<b>Anonymous</b>");
|
||||
name.hexpand = true;
|
||||
name.halign = Gtk.Align.START;
|
||||
name.use_markup = true;
|
||||
display_name = new Gtk.Label ("<b>Anonymous</b>");
|
||||
display_name.hexpand = true;
|
||||
display_name.halign = Gtk.Align.START;
|
||||
display_name.use_markup = true;
|
||||
user = new Gtk.Label ("@error");
|
||||
user.halign = Gtk.Align.START;
|
||||
logout = new Gtk.Button.from_icon_name ("pane-hide-symbolic", Gtk.IconSize.SMALL_TOOLBAR);
|
||||
|
@ -29,7 +29,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
|||
logout.clicked.connect (() => AccountManager.instance.logout ());
|
||||
show_all ();
|
||||
|
||||
attach(name, 1, 0, 1, 1);
|
||||
attach(display_name, 1, 0, 1, 1);
|
||||
attach(user, 1, 1, 1, 1);
|
||||
attach(logout, 2, 0, 2, 2);
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ public class Tootle.AccountsButton : Gtk.MenuButton{
|
|||
AccountManager.instance.changed_current.connect (account => {
|
||||
if (account != null){
|
||||
CacheManager.instance.load_avatar (account.avatar, avatar, 24);
|
||||
default_account.name.label = "<b>"+account.display_name+"</b>";
|
||||
default_account.display_name.label = "<b>"+account.display_name+"</b>";
|
||||
default_account.user.label = "@"+account.username;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue