mirror of
https://gitlab.gnome.org/World/tootle
synced 2025-02-02 00:46:48 +01:00
Add menu item for removing attachments
This commit is contained in:
parent
47d1ba1d4a
commit
2b6af0c9aa
@ -5,7 +5,6 @@ public class Tootle.AttachmentBox : Gtk.ScrolledWindow {
|
||||
|
||||
private Gtk.Box box;
|
||||
private bool edit_mode;
|
||||
private int64[] ids;
|
||||
|
||||
construct {
|
||||
box = new Gtk.Box (Gtk.Orientation.HORIZONTAL, 6);
|
||||
@ -53,7 +52,6 @@ public class Tootle.AttachmentBox : Gtk.ScrolledWindow {
|
||||
show ();
|
||||
foreach (unowned string uri in chooser.get_uris ()) {
|
||||
var widget = new AttachmentWidget.upload (uri);
|
||||
widget.uploaded.connect (id => ids += id);
|
||||
box.pack_start (widget, false, false, 6);
|
||||
}
|
||||
}
|
||||
@ -62,8 +60,11 @@ public class Tootle.AttachmentBox : Gtk.ScrolledWindow {
|
||||
|
||||
public string get_uri_array () {
|
||||
var str = "";
|
||||
foreach (int64 item in ids)
|
||||
str += "&media_ids[]=" + item.to_string ();
|
||||
box.get_children ().@foreach (widget => {
|
||||
var w = (AttachmentWidget) widget;
|
||||
if (w.attachment != null)
|
||||
str += "&media_ids[]=%lld".printf (w.attachment.id);
|
||||
});
|
||||
return str;
|
||||
}
|
||||
|
||||
|
@ -3,16 +3,13 @@ using Gdk;
|
||||
|
||||
public class Tootle.AttachmentWidget : Gtk.EventBox {
|
||||
|
||||
public abstract signal void uploaded (int64 id);
|
||||
public abstract signal void removed (int64 id);
|
||||
|
||||
Attachment? attachment;
|
||||
public Attachment? attachment;
|
||||
private bool editable = false;
|
||||
private const int SMALL_SIZE = 64;
|
||||
|
||||
public Gtk.Label label;
|
||||
Gtk.Grid grid;
|
||||
Gtk.Image? image;
|
||||
private Gtk.Grid grid;
|
||||
private Gtk.Image? image;
|
||||
|
||||
construct {
|
||||
set_size_request (SMALL_SIZE, SMALL_SIZE);
|
||||
@ -78,7 +75,7 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
|
||||
var mime = type.get_content_type ();
|
||||
|
||||
debug ("Uploading %s (%s)", uri, mime);
|
||||
label.label = _("Uploading file...");
|
||||
label.label = _("Uploading...");
|
||||
label.show ();
|
||||
show ();
|
||||
|
||||
@ -88,14 +85,13 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
|
||||
var url = "%s/api/v1/media".printf (Tootle.accounts.formal.instance);
|
||||
var msg = Soup.Form.request_new_from_multipart (url, multipart);
|
||||
|
||||
Tootle.network.queue(msg, (sess, mess) => {
|
||||
network.queue(msg, (sess, mess) => {
|
||||
var root = Tootle.network.parse (mess);
|
||||
attachment = Attachment.parse (root);
|
||||
editable = true;
|
||||
rebind ();
|
||||
|
||||
rebind ();
|
||||
debug ("Uploaded media: %lld", attachment.id);
|
||||
uploaded (attachment.id);
|
||||
});
|
||||
}
|
||||
catch (Error e) {
|
||||
@ -119,6 +115,13 @@ public class Tootle.AttachmentWidget : Gtk.EventBox {
|
||||
menu.destroy ();
|
||||
});
|
||||
|
||||
if (editable && attachment != null) {
|
||||
var item_remove = new Gtk.MenuItem.with_label (_("Remove"));
|
||||
item_remove.activate.connect (() => destroy ());
|
||||
menu.add (item_remove);
|
||||
menu.add (new Gtk.SeparatorMenuItem ());
|
||||
}
|
||||
|
||||
var item_open_link = new Gtk.MenuItem.with_label (_("Open in Browser"));
|
||||
item_open_link.activate.connect (() => Desktop.open_url (attachment.url));
|
||||
var item_copy_link = new Gtk.MenuItem.with_label (_("Copy Link"));
|
||||
|
Loading…
x
Reference in New Issue
Block a user