Move widget insertion logic from ConversationTitlebar to controller

This commit is contained in:
fiaxh 2020-02-22 03:00:55 +01:00
parent f282ef68a4
commit 420fcb909f
3 changed files with 22 additions and 38 deletions

View file

@ -10,13 +10,7 @@ public class Registry {
internal Gee.List<ConversationAdditionPopulator> conversation_addition_populators = new ArrayList<ConversationAdditionPopulator>();
internal Gee.List<NotificationPopulator> notification_populators = new ArrayList<NotificationPopulator>();
internal Gee.Collection<ConversationTitlebarEntry> conversation_titlebar_entries = new Gee.TreeSet<ConversationTitlebarEntry>((a, b) => {
if (a.order < b.order) {
return 1;
} else if (a.order > b.order) {
return -1;
} else {
return 0;
}
return (int)(a.order - b.order);
});
public bool register_encryption_list_entry(EncryptionListEntry entry) {

View file

@ -9,6 +9,8 @@ namespace Dino.Ui {
public interface ConversationTitlebar : Widget {
public abstract string? subtitle { get; set; }
public abstract string? title { get; set; }
public abstract void insert_entry(Plugins.ConversationTitlebarEntry entry);
}
public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box {
@ -26,12 +28,12 @@ public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box {
}
}
private Box content_box = new Box(Orientation.HORIZONTAL, 0) { margin=5, margin_start=15, margin_end=5, hexpand=true, visible=true };
private Box widgets_box = new Box(Orientation.HORIZONTAL, 0) { margin_start=15, valign=Align.END, visible=true };
private Label title_label = new Label("") { visible=true };
private Label subtitle_label = new Label("") { use_markup=true, ellipsize=EllipsizeMode.END, visible=false };
public GlobalSearchButton search_button = new GlobalSearchButton() { visible = true };
construct {
Box content_box = new Box(Orientation.HORIZONTAL, 0) { margin=5, margin_start=15, margin_end=10, hexpand=true, visible=true };
this.add(content_box);
Box titles_box = new Box(Orientation.VERTICAL, 0) { valign=Align.CENTER, hexpand=true, visible=true };
@ -42,25 +44,19 @@ public class ConversationTitlebarNoCsd : ConversationTitlebar, Gtk.Box {
subtitle_label.get_style_context().add_class("dim-label");
titles_box.add(subtitle_label);
Box placeholder_box = new Box(Orientation.VERTICAL, 0) { visible=true };
placeholder_box.add(new Label("") { xalign=0, visible=true });
placeholder_box.add(new Label("<span size='small'> </span>") { use_markup=true, xalign=0, visible=true });
content_box.add(placeholder_box);
content_box.add(widgets_box);
}
public ConversationTitlebarNoCsd() {
this.get_style_context().add_class("dino-header-right");
hexpand = true;
search_button.set_image(new Gtk.Image.from_icon_name("system-search-symbolic", Gtk.IconSize.MENU) { visible = true });
}
Application app = GLib.Application.get_default() as Application;
foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
Button gtk_widget = (Gtk.Button)widget;
gtk_widget.relief = ReliefStyle.NONE;
content_box.add(gtk_widget);
}
public void insert_entry(Plugins.ConversationTitlebarEntry entry) {
Plugins.ConversationTitlebarWidget widget = entry.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
Button gtk_widget = (Gtk.Button) widget;
gtk_widget.relief = ReliefStyle.NONE;
widgets_box.pack_end(gtk_widget);
}
}
}
@ -74,19 +70,12 @@ public class ConversationTitlebarCsd : ConversationTitlebar, Gtk.HeaderBar {
this.get_style_context().add_class("dino-right");
show_close_button = true;
hexpand = true;
}
Application app = GLib.Application.get_default() as Application;
ArrayList<Plugins.ConversationTitlebarWidget> widgets = new ArrayList<Plugins.ConversationTitlebarWidget>();
foreach(var e in app.plugin_registry.conversation_titlebar_entries) {
Plugins.ConversationTitlebarWidget widget = e.get_widget(Plugins.WidgetType.GTK);
if (widget != null) {
widgets.insert(0, widget);
}
}
foreach (var w in widgets) {
Button gtk_widget = (Gtk.Button)w;
this.pack_end(gtk_widget);
}
public void insert_entry(Plugins.ConversationTitlebarEntry entry) {
Plugins.ConversationTitlebarWidget widget = entry.get_widget(Plugins.WidgetType.GTK);
Button gtk_widget = (Gtk.Button)widget;
this.pack_end(gtk_widget);
}
}

View file

@ -77,12 +77,13 @@ public class ConversationViewController : Object {
}
});
// Register headerbar plugins
// Headerbar plugins
app.plugin_registry.register_contact_titlebar_entry(new MenuEntry(stream_interactor));
app.plugin_registry.register_contact_titlebar_entry(search_menu_entry);
app.plugin_registry.register_contact_titlebar_entry(new OccupantsEntry(stream_interactor));
foreach(var entry in app.plugin_registry.conversation_titlebar_entries) {
titlebar.insert_entry(entry);
}
}
public void select_conversation(Conversation? conversation, bool default_initialize_conversation) {