Commit d66abfee authored by Julian Sparber's avatar Julian Sparber

Move narrow property to contact-pane

This makes the narrow property more globale so it can be used by
different widgets
parent 8bdb6e35
......@@ -263,8 +263,6 @@ public class Contacts.ContactEditor : ContactForm {
/* the key of the hash_map is the uid of the persona */
private HashMap<string, HashMap<string, Field?>> writable_personas;
public bool narrow { get; set; default = true; }
public bool has_birthday_row {
get; private set; default = false;
}
......@@ -282,27 +280,20 @@ public class Contacts.ContactEditor : ContactForm {
this.writable_personas = new HashMap<string, HashMap<string, Field?>> ();
this.container_grid.size_allocate.connect(on_container_grid_size_allocate);
int old_width = this.get_allocated_width ();
Image trash_icon = new Image.from_icon_name ("user-trash-symbolic", IconSize.MENU);
string label = _("Remove Contact");
this.remove_button.image = trash_icon;
this.remove_button.label = label;
size_allocate.connect(() => {
int width = this.get_allocated_width ();
if (old_width != width) {
if (!narrow && width <= RESIZE_WIDTH) {
notify["narrow"].connect(() => {
if (narrow) {
this.avatar.set_display_size (PROFILE_SMALL_SIZE);
this.remove_button.image = trash_icon;
this.remove_button.label = null;
narrow = true;
} else if (narrow && width > RESIZE_WIDTH) {
} else {
this.avatar.set_display_size (PROFILE_SIZE);
this.remove_button.image = null;
this.remove_button.label = label;
narrow = false;
}
old_width = this.get_allocated_width ();
}
});
}
......
......@@ -51,6 +51,8 @@ public abstract class Contacts.ContactForm : Grid {
protected Grid container_grid;
protected int last_row = 0;
public bool narrow { get; set; default = true; }
construct {
this.container_grid.set_focus_vadjustment (this.main_sw.get_vadjustment ());
this.main_sw.get_style_context ().add_class ("contacts-contact-form");
......
......@@ -65,6 +65,7 @@ public class Contacts.ContactPane : Stack {
public bool on_edit_mode = false;
private LinkSuggestionGrid? suggestion_grid = null;
public bool narrow { get; set; default = true; }
/* Signals */
public signal void contacts_linked (string? main_contact, string linked_contact, LinkOperation operation);
......@@ -74,6 +75,21 @@ public class Contacts.ContactPane : Stack {
*/
public signal void display_name_changed (string new_display_name);
construct {
int old_width = this.get_allocated_width ();
size_allocate.connect(() => {
int width = this.get_allocated_width ();
if (old_width != width) {
if (!narrow && width <= RESIZE_WIDTH) {
narrow = true;
} else if (narrow && width > RESIZE_WIDTH) {
narrow = false;
}
old_width = this.get_allocated_width ();
}
});
}
public ContactPane (Window parent_window, Store contacts_store) {
this.parent_window = parent_window;
this.store = contacts_store;
......@@ -123,6 +139,7 @@ public class Contacts.ContactPane : Stack {
remove_contact_sheet();
this.sheet = new ContactSheet (this.contact, this.store);
bind_property ("narrow", this.sheet, "narrow", BindingFlags.SYNC_CREATE);
this.contact_sheet_page.add (this.sheet);
set_visible_child (this.contact_sheet_page);
......@@ -156,6 +173,8 @@ public class Contacts.ContactPane : Stack {
this.editor.remove_button.clicked.connect (delete_contact);
bind_property ("narrow", this.editor, "narrow", BindingFlags.SYNC_CREATE);
/* enable/disable actions*/
var birthday_action = this.edit_contact_actions.lookup_action ("add.birthday") as SimpleAction;
this.editor.bind_property ("has-birthday-row", birthday_action, "enabled",
......
......@@ -80,15 +80,14 @@ public class Contacts.ContactSheet : ContactForm {
image_frame.set_vexpand (false);
image_frame.set_valign (Align.START);
image_frame.set_display_size (PROFILE_SMALL_SIZE);
/* Resize the avatar based on the avabile space */
size_allocate.connect(() => {
Allocation size;
get_allocation(out size);
if (size.width < RESIZE_WIDTH) {
notify["narrow"].connect(() => {
if (narrow)
image_frame.set_display_size (PROFILE_SMALL_SIZE);
} else {
else
image_frame.set_display_size (PROFILE_SIZE);
}
});
this.container_grid.attach (image_frame, 0, 0, 1, 3);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment