Close #101
This commit is contained in:
parent
ac5c5e23a7
commit
e662bc4712
|
@ -61,7 +61,7 @@ public class Tootle.Notification {
|
|||
|
||||
public Soup.Message? dismiss () {
|
||||
if (type == NotificationType.WATCHLIST) {
|
||||
if (accounts.formal.cached_notifications.remove (this));
|
||||
if (accounts.formal.cached_notifications.remove (this))
|
||||
accounts.save ();
|
||||
return null;
|
||||
}
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
using Gtk;
|
||||
using Tootle;
|
||||
using Gee;
|
||||
|
||||
public class Tootle.WatchlistDialog : Gtk.Dialog {
|
||||
|
||||
private static WatchlistDialog dialog;
|
||||
|
||||
private HeaderBar header;
|
||||
private StackSwitcher switcher;
|
||||
private Gtk.MenuButton button_add;
|
||||
private Button button_remove;
|
||||
private Stack stack;
|
||||
private ListStack users;
|
||||
private ListStack hashtags;
|
||||
|
||||
private ActionBar actionbar;
|
||||
private Popover popover;
|
||||
private Grid popover_grid;
|
||||
private Entry popover_entry;
|
||||
|
@ -22,39 +22,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
|
|||
|
||||
private class ModelItem : GLib.Object {
|
||||
public string name;
|
||||
public bool is_hashtag;
|
||||
|
||||
public ModelItem (string name, bool is_hashtag) {
|
||||
public ModelItem (string name) {
|
||||
this.name = name;
|
||||
this.is_hashtag = is_hashtag;
|
||||
}
|
||||
}
|
||||
|
||||
private class ModelView : ListBoxRow {
|
||||
private Box box;
|
||||
private Button button_remove;
|
||||
private Label label;
|
||||
private bool is_hashtag;
|
||||
|
||||
public Label label;
|
||||
public ModelView (ModelItem item) {
|
||||
is_hashtag = item.is_hashtag;
|
||||
box = new Box (Orientation.HORIZONTAL, 0);
|
||||
box.margin = 6;
|
||||
label = new Label (item.name);
|
||||
label.vexpand = true;
|
||||
label.valign = Align.CENTER;
|
||||
label.margin = 6;
|
||||
label.halign = Align.START;
|
||||
label.justify = Justification.LEFT;
|
||||
button_remove = new Button.from_icon_name ("list-remove-symbolic", IconSize.BUTTON);
|
||||
button_remove.get_style_context ().add_class (Gtk.STYLE_CLASS_FLAT);
|
||||
button_remove.clicked.connect (() => {
|
||||
watchlist.remove (label.label, is_hashtag);
|
||||
watchlist.save ();
|
||||
destroy ();
|
||||
});
|
||||
|
||||
box.pack_start (label, false, false, 0);
|
||||
box.pack_end (button_remove, false, false, 0);
|
||||
add (box);
|
||||
add (label);
|
||||
show_all ();
|
||||
}
|
||||
}
|
||||
|
@ -88,29 +69,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
|
|||
private class ListStack : ScrolledWindow {
|
||||
public Model model;
|
||||
public ListBox list;
|
||||
private bool is_hashtags;
|
||||
|
||||
public void update () {
|
||||
if (is_hashtags)
|
||||
watchlist.hashtags.@foreach (item => {
|
||||
model.append (new ModelItem (item, true));
|
||||
return true;
|
||||
});
|
||||
else
|
||||
watchlist.users.@foreach (item => {
|
||||
model.append (new ModelItem (item, false));
|
||||
return true;
|
||||
});
|
||||
|
||||
public void update (ArrayList<string> array) {
|
||||
array.@foreach (item => {
|
||||
model.append (new ModelItem (item));
|
||||
return true;
|
||||
});
|
||||
list.bind_model (model, create_row);
|
||||
}
|
||||
|
||||
public ListStack (bool is_hashtags) {
|
||||
this.is_hashtags = is_hashtags;
|
||||
public ListStack (ArrayList<string> array) {
|
||||
model = new Model ();
|
||||
list = new ListBox ();
|
||||
add (list);
|
||||
update ();
|
||||
update (array);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,24 +92,26 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
|
|||
}
|
||||
|
||||
public WatchlistDialog () {
|
||||
deletable = true;
|
||||
border_width = 6;
|
||||
deletable = false;
|
||||
resizable = false;
|
||||
transient_for = window;
|
||||
title = _("Watchlist");
|
||||
|
||||
var content = get_content_area ();
|
||||
users = new ListStack (watchlist.users);
|
||||
hashtags = new ListStack (watchlist.hashtags);
|
||||
|
||||
stack = new Stack ();
|
||||
stack.transition_type = StackTransitionType.SLIDE_LEFT_RIGHT;
|
||||
stack.hexpand = true;
|
||||
stack.vexpand = true;
|
||||
|
||||
users = new ListStack (false);
|
||||
hashtags = new ListStack (true);
|
||||
|
||||
stack.add_titled (users, "users", _("Users"));
|
||||
stack.add_titled (hashtags, "hashtags", _("Hashtags"));
|
||||
stack.set_size_request (350, 400);
|
||||
content.pack_start (stack, true, true, 0);
|
||||
|
||||
switcher = new StackSwitcher ();
|
||||
switcher.stack = stack;
|
||||
switcher.halign = Align.CENTER;
|
||||
switcher.margin_bottom = 12;
|
||||
|
||||
popover_entry = new Entry ();
|
||||
popover_entry.hexpand = true;
|
||||
|
@ -161,25 +135,52 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
|
|||
|
||||
button_add = new MenuButton ();
|
||||
button_add.image = new Image.from_icon_name ("list-add-symbolic", IconSize.BUTTON);
|
||||
button_add.get_style_context ().add_class (Gtk.STYLE_CLASS_SUGGESTED_ACTION);
|
||||
button_add.popover = popover;
|
||||
button_add.clicked.connect (() => set_tip ());
|
||||
|
||||
switcher = new StackSwitcher ();
|
||||
switcher.stack = stack;
|
||||
switcher.halign = Align.CENTER;
|
||||
button_remove = new Button ();
|
||||
button_remove.image = new Image.from_icon_name ("list-remove-symbolic", IconSize.BUTTON);
|
||||
button_remove.clicked.connect (on_remove);
|
||||
|
||||
header = new HeaderBar ();
|
||||
header.show_close_button = true;
|
||||
header.pack_start (button_add);
|
||||
header.set_custom_title (switcher);
|
||||
set_titlebar (header);
|
||||
actionbar = new ActionBar ();
|
||||
actionbar.add (button_add);
|
||||
actionbar.add (button_remove);
|
||||
|
||||
var grid = new Grid ();
|
||||
grid.attach (stack, 0, 1);
|
||||
grid.attach (actionbar, 0, 2);
|
||||
|
||||
var frame = new Frame (null);
|
||||
frame.margin_bottom = 6;
|
||||
frame.add (grid);
|
||||
frame.set_size_request (350, 350);
|
||||
|
||||
var content = get_content_area ();
|
||||
content.pack_start (switcher, true, true, 0);
|
||||
content.pack_start (frame, true, true, 0);
|
||||
|
||||
add_button (_("_Close"), ResponseType.DELETE_EVENT);
|
||||
show_all ();
|
||||
|
||||
response.connect (on_response);
|
||||
destroy.connect (() => dialog = null);
|
||||
}
|
||||
|
||||
private void on_response (int i) {
|
||||
destroy ();
|
||||
}
|
||||
|
||||
private void on_remove () {
|
||||
var is_hashtag = stack.visible_child_name == "hashtags";
|
||||
ListStack stack = is_hashtag ? hashtags : users;
|
||||
stack.list.get_selected_rows ().@foreach (_row => {
|
||||
var row = _row as ModelView;
|
||||
watchlist.remove (row.label.label, is_hashtag);
|
||||
watchlist.save ();
|
||||
row.destroy ();
|
||||
});
|
||||
}
|
||||
|
||||
private void submit () {
|
||||
if (popover_entry.text_length < 1)
|
||||
return;
|
||||
|
@ -193,10 +194,8 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
|
|||
watchlist.save ();
|
||||
button_add.active = false;
|
||||
|
||||
if (is_hashtag)
|
||||
hashtags.list.insert (create_row (new ModelItem (entity, true)), 0);
|
||||
else
|
||||
users.list.insert (create_row (new ModelItem (entity, false)), 0);
|
||||
var stack = is_hashtag ? hashtags : users;
|
||||
stack.list.insert (create_row (new ModelItem (entity)), 0);
|
||||
}
|
||||
|
||||
public static void open () {
|
||||
|
|
|
@ -108,7 +108,7 @@ public class Tootle.Watchlist : Object {
|
|||
public void remove (string entity, bool is_hashtag) {
|
||||
if (entity == "")
|
||||
return;
|
||||
|
||||
|
||||
if (is_hashtag) {
|
||||
var i = hashtags.index_of (entity);
|
||||
var notificator = notificators.@get(i);
|
||||
|
|
Loading…
Reference in New Issue