This commit is contained in:
bleakgrey 2018-10-31 15:05:36 +03:00
parent ac5c5e23a7
commit e662bc4712
3 changed files with 65 additions and 66 deletions

View File

@ -61,7 +61,7 @@ public class Tootle.Notification {
public Soup.Message? dismiss () { public Soup.Message? dismiss () {
if (type == NotificationType.WATCHLIST) { if (type == NotificationType.WATCHLIST) {
if (accounts.formal.cached_notifications.remove (this)); if (accounts.formal.cached_notifications.remove (this))
accounts.save (); accounts.save ();
return null; return null;
} }

View File

@ -1,17 +1,17 @@
using Gtk; using Gtk;
using Tootle; using Gee;
public class Tootle.WatchlistDialog : Gtk.Dialog { public class Tootle.WatchlistDialog : Gtk.Dialog {
private static WatchlistDialog dialog; private static WatchlistDialog dialog;
private HeaderBar header;
private StackSwitcher switcher; private StackSwitcher switcher;
private Gtk.MenuButton button_add; private Gtk.MenuButton button_add;
private Button button_remove;
private Stack stack; private Stack stack;
private ListStack users; private ListStack users;
private ListStack hashtags; private ListStack hashtags;
private ActionBar actionbar;
private Popover popover; private Popover popover;
private Grid popover_grid; private Grid popover_grid;
private Entry popover_entry; private Entry popover_entry;
@ -22,39 +22,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
private class ModelItem : GLib.Object { private class ModelItem : GLib.Object {
public string name; public string name;
public bool is_hashtag;
public ModelItem (string name, bool is_hashtag) { public ModelItem (string name) {
this.name = name; this.name = name;
this.is_hashtag = is_hashtag;
} }
} }
private class ModelView : ListBoxRow { private class ModelView : ListBoxRow {
private Box box; public Label label;
private Button button_remove;
private Label label;
private bool is_hashtag;
public ModelView (ModelItem item) { public ModelView (ModelItem item) {
is_hashtag = item.is_hashtag;
box = new Box (Orientation.HORIZONTAL, 0);
box.margin = 6;
label = new Label (item.name); label = new Label (item.name);
label.vexpand = true; label.margin = 6;
label.valign = Align.CENTER; label.halign = Align.START;
label.justify = Justification.LEFT; label.justify = Justification.LEFT;
button_remove = new Button.from_icon_name ("list-remove-symbolic", IconSize.BUTTON); add (label);
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);
show_all (); show_all ();
} }
} }
@ -88,29 +69,20 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
private class ListStack : ScrolledWindow { private class ListStack : ScrolledWindow {
public Model model; public Model model;
public ListBox list; public ListBox list;
private bool is_hashtags;
public void update () { public void update (ArrayList<string> array) {
if (is_hashtags) array.@foreach (item => {
watchlist.hashtags.@foreach (item => { model.append (new ModelItem (item));
model.append (new ModelItem (item, true)); return true;
return true; });
});
else
watchlist.users.@foreach (item => {
model.append (new ModelItem (item, false));
return true;
});
list.bind_model (model, create_row); list.bind_model (model, create_row);
} }
public ListStack (bool is_hashtags) { public ListStack (ArrayList<string> array) {
this.is_hashtags = is_hashtags;
model = new Model (); model = new Model ();
list = new ListBox (); list = new ListBox ();
add (list); add (list);
update (); update (array);
} }
} }
@ -120,24 +92,26 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
} }
public WatchlistDialog () { public WatchlistDialog () {
deletable = true; border_width = 6;
deletable = false;
resizable = false; resizable = false;
transient_for = window; transient_for = window;
title = _("Watchlist");
var content = get_content_area (); users = new ListStack (watchlist.users);
hashtags = new ListStack (watchlist.hashtags);
stack = new Stack (); stack = new Stack ();
stack.transition_type = StackTransitionType.SLIDE_LEFT_RIGHT; stack.transition_type = StackTransitionType.SLIDE_LEFT_RIGHT;
stack.hexpand = true; stack.hexpand = true;
stack.vexpand = true; stack.vexpand = true;
users = new ListStack (false);
hashtags = new ListStack (true);
stack.add_titled (users, "users", _("Users")); stack.add_titled (users, "users", _("Users"));
stack.add_titled (hashtags, "hashtags", _("Hashtags")); 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 = new Entry ();
popover_entry.hexpand = true; popover_entry.hexpand = true;
@ -161,25 +135,52 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
button_add = new MenuButton (); button_add = new MenuButton ();
button_add.image = new Image.from_icon_name ("list-add-symbolic", IconSize.BUTTON); 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.popover = popover;
button_add.clicked.connect (() => set_tip ()); button_add.clicked.connect (() => set_tip ());
switcher = new StackSwitcher (); button_remove = new Button ();
switcher.stack = stack; button_remove.image = new Image.from_icon_name ("list-remove-symbolic", IconSize.BUTTON);
switcher.halign = Align.CENTER; button_remove.clicked.connect (on_remove);
header = new HeaderBar (); actionbar = new ActionBar ();
header.show_close_button = true; actionbar.add (button_add);
header.pack_start (button_add); actionbar.add (button_remove);
header.set_custom_title (switcher);
set_titlebar (header);
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 (); show_all ();
response.connect (on_response);
destroy.connect (() => dialog = null); 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 () { private void submit () {
if (popover_entry.text_length < 1) if (popover_entry.text_length < 1)
return; return;
@ -193,10 +194,8 @@ public class Tootle.WatchlistDialog : Gtk.Dialog {
watchlist.save (); watchlist.save ();
button_add.active = false; button_add.active = false;
if (is_hashtag) var stack = is_hashtag ? hashtags : users;
hashtags.list.insert (create_row (new ModelItem (entity, true)), 0); stack.list.insert (create_row (new ModelItem (entity)), 0);
else
users.list.insert (create_row (new ModelItem (entity, false)), 0);
} }
public static void open () { public static void open () {

View File

@ -108,7 +108,7 @@ public class Tootle.Watchlist : Object {
public void remove (string entity, bool is_hashtag) { public void remove (string entity, bool is_hashtag) {
if (entity == "") if (entity == "")
return; return;
if (is_hashtag) { if (is_hashtag) {
var i = hashtags.index_of (entity); var i = hashtags.index_of (entity);
var notificator = notificators.@get(i); var notificator = notificators.@get(i);