ContactPane: use popover in "new detail" button
Replaced old menu for actions. Now the code is cleaner and easier to read.
This commit is contained in:
parent
12d772dc8f
commit
ed0e1b2397
2 changed files with 90 additions and 81 deletions
|
@ -22,4 +22,50 @@
|
||||||
</item>
|
</item>
|
||||||
</section>
|
</section>
|
||||||
</menu>
|
</menu>
|
||||||
|
<menu id="edit-contact">
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.email-addresses.personal</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Personal email</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.email-addresses.work</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Work email</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.phone-numbers.cell</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Mobile phone</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.phone-numbers.home</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Home phone</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.phone-numbers.work</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Work phone</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.urls</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Website</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.nickname</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Nickname</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.birthday</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Birthday</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.postal-addresses.home</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Home address</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.postal-addresses.work</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Work address</attribute>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<attribute name="action">edit.add.notes</attribute>
|
||||||
|
<attribute name="label" translatable="yes">Notes</attribute>
|
||||||
|
</item>
|
||||||
|
</menu>
|
||||||
</interface>
|
</interface>
|
||||||
|
|
|
@ -104,15 +104,25 @@ public class Contacts.ContactPane : Notebook {
|
||||||
/* second page */
|
/* second page */
|
||||||
private ContactSheet sheet;
|
private ContactSheet sheet;
|
||||||
|
|
||||||
/* thrid page */
|
/* third page */
|
||||||
private ContactEditor editor;
|
private ContactEditor editor;
|
||||||
private Button linked_button;
|
private Button linked_button;
|
||||||
private Button remove_button;
|
private Button remove_button;
|
||||||
|
|
||||||
/* single value details */
|
private SimpleActionGroup edit_contact_actions;
|
||||||
private Gtk.MenuItem nickname_item;
|
private const GLib.ActionEntry[] action_entries = {
|
||||||
private Gtk.MenuItem birthday_item;
|
{ "add.email-addresses.personal", on_add_detail },
|
||||||
private Gtk.MenuItem notes_item;
|
{ "add.email-addresses.work", on_add_detail },
|
||||||
|
{ "add.phone-numbers.cell", on_add_detail },
|
||||||
|
{ "add.phone-numbers.home", on_add_detail },
|
||||||
|
{ "add.phone-numbers.work", on_add_detail },
|
||||||
|
{ "add.urls", on_add_detail },
|
||||||
|
{ "add.nickname", on_add_detail },
|
||||||
|
{ "add.birthday", on_add_detail },
|
||||||
|
{ "add.postal-addresses.home", on_add_detail },
|
||||||
|
{ "add.postal-addresses.work", on_add_detail },
|
||||||
|
{ "add.notes", on_add_detail },
|
||||||
|
};
|
||||||
|
|
||||||
public bool on_edit_mode;
|
public bool on_edit_mode;
|
||||||
public Grid suggestion_grid;
|
public Grid suggestion_grid;
|
||||||
|
@ -274,6 +284,9 @@ public class Contacts.ContactPane : Notebook {
|
||||||
|
|
||||||
this.contacts_store = contacts_store;
|
this.contacts_store = contacts_store;
|
||||||
|
|
||||||
|
this.edit_contact_actions = new SimpleActionGroup ();
|
||||||
|
this.edit_contact_actions.add_action_entries (action_entries, this);
|
||||||
|
|
||||||
/* starts with no_selection_frame 'til someone select something */
|
/* starts with no_selection_frame 'til someone select something */
|
||||||
show_no_selection_frame ();
|
show_no_selection_frame ();
|
||||||
|
|
||||||
|
@ -347,7 +360,9 @@ public class Contacts.ContactPane : Notebook {
|
||||||
edit_toolbar.set_vexpand (false);
|
edit_toolbar.set_vexpand (false);
|
||||||
|
|
||||||
var add_detail_button = new Gtk.MenuButton ();
|
var add_detail_button = new Gtk.MenuButton ();
|
||||||
|
/* FIXME: this set_vexpand is unnecesary here, or should be */
|
||||||
add_detail_button.set_vexpand (true);
|
add_detail_button.set_vexpand (true);
|
||||||
|
|
||||||
var box = new Grid ();
|
var box = new Grid ();
|
||||||
var w = new Label (_("New Detail")) as Widget;
|
var w = new Label (_("New Detail")) as Widget;
|
||||||
w.set_valign (Align.CENTER);
|
w.set_valign (Align.CENTER);
|
||||||
|
@ -359,73 +374,14 @@ public class Contacts.ContactPane : Notebook {
|
||||||
w.set_vexpand (true);
|
w.set_vexpand (true);
|
||||||
box.add (w);
|
box.add (w);
|
||||||
add_detail_button.add (box);
|
add_detail_button.add (box);
|
||||||
var details_menu = new Gtk.Menu ();
|
|
||||||
details_menu.set_halign (Align.START);
|
|
||||||
|
|
||||||
/* building menu */
|
var builder = load_ui ("app-menu.ui");
|
||||||
var item = new Gtk.MenuItem.with_label (_("Personal email"));
|
var gmenu = builder.get_object ("edit-contact") as MenuModel;
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "email-addresses", "PERSONAL");
|
|
||||||
});
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Work email"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "email-addresses", "WORK");
|
|
||||||
});
|
|
||||||
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Mobile phone"));
|
add_detail_button.use_popover = true;
|
||||||
details_menu.append (item);
|
add_detail_button.set_menu_model (gmenu);
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "phone-numbers", "CELL");
|
|
||||||
});
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Home phone"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "phone-numbers", "HOME");
|
|
||||||
});
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Work phone"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "phone-numbers", "WORK");
|
|
||||||
});
|
|
||||||
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Website"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "urls");
|
|
||||||
});
|
|
||||||
nickname_item = new Gtk.MenuItem.with_label (_("Nickname"));
|
|
||||||
details_menu.append (nickname_item);
|
|
||||||
nickname_item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "nickname");
|
|
||||||
});
|
|
||||||
birthday_item = new Gtk.MenuItem.with_label (_("Birthday"));
|
|
||||||
details_menu.append (birthday_item);
|
|
||||||
birthday_item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "birthday");
|
|
||||||
});
|
|
||||||
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Home address"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "postal-addresses", "HOME");
|
|
||||||
});
|
|
||||||
item = new Gtk.MenuItem.with_label (_("Work address"));
|
|
||||||
details_menu.append (item);
|
|
||||||
item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "postal-addresses", "WORK");
|
|
||||||
});
|
|
||||||
|
|
||||||
notes_item = new Gtk.MenuItem.with_label (_("Notes"));
|
|
||||||
details_menu.append (notes_item);
|
|
||||||
notes_item.activate.connect (() => {
|
|
||||||
editor.add_new_row_for_property (contact.find_primary_persona (), "notes");
|
|
||||||
});
|
|
||||||
details_menu.show_all ();
|
|
||||||
|
|
||||||
add_detail_button.set_popup (details_menu);
|
|
||||||
add_detail_button.set_direction (ArrowType.UP);
|
add_detail_button.set_direction (ArrowType.UP);
|
||||||
|
add_detail_button.get_popover ().insert_action_group ("edit", this.edit_contact_actions);
|
||||||
|
|
||||||
var tool_item = new ToolItem ();
|
var tool_item = new ToolItem ();
|
||||||
tool_item.add (add_detail_button);
|
tool_item.add (add_detail_button);
|
||||||
|
@ -462,6 +418,18 @@ public class Contacts.ContactPane : Notebook {
|
||||||
insert_page (top_grid, null, 2);
|
insert_page (top_grid, null, 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void on_add_detail (GLib.SimpleAction action, GLib.Variant? parameter) {
|
||||||
|
print ("activated %s\n", action.name);
|
||||||
|
|
||||||
|
var tok = action.name.split (".");
|
||||||
|
|
||||||
|
if (tok[0] == "add") {
|
||||||
|
editor.add_new_row_for_property (contact.find_primary_persona (),
|
||||||
|
tok[1],
|
||||||
|
tok.length > 2 ? tok[2].up () : null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void linked_accounts () {
|
void linked_accounts () {
|
||||||
var dialog = new LinkedAccountsDialog (contact);
|
var dialog = new LinkedAccountsDialog (contact);
|
||||||
var result = dialog.run ();
|
var result = dialog.run ();
|
||||||
|
@ -534,20 +502,15 @@ public class Contacts.ContactPane : Notebook {
|
||||||
|
|
||||||
on_edit_mode = true;
|
on_edit_mode = true;
|
||||||
|
|
||||||
if (contact.has_birthday ())
|
/* enable/disable actions*/
|
||||||
birthday_item.hide ();
|
var action = this.edit_contact_actions.lookup_action ("add.birthday") as SimpleAction;
|
||||||
else
|
action.set_enabled (! contact.has_birthday ());
|
||||||
birthday_item.show ();
|
|
||||||
|
|
||||||
if (contact.has_nickname ())
|
action = this.edit_contact_actions.lookup_action ("add.nickname") as SimpleAction;
|
||||||
nickname_item.hide ();
|
action.set_enabled (! contact.has_nickname ());
|
||||||
else
|
|
||||||
nickname_item.show ();
|
|
||||||
|
|
||||||
if (contact.has_notes ())
|
action = this.edit_contact_actions.lookup_action ("add.notes") as SimpleAction;
|
||||||
notes_item.hide ();
|
action.set_enabled (! contact.has_notes ());
|
||||||
else
|
|
||||||
notes_item.show ();
|
|
||||||
|
|
||||||
sheet.clear ();
|
sheet.clear ();
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue