edit-mode: added [Cancel] button
build: moved a bunch of constraints to use gproperty bindings
This commit is contained in:
parent
cbb437071e
commit
07c015655b
3 changed files with 122 additions and 60 deletions
|
@ -236,6 +236,22 @@
|
|||
<class name="contacts-right-header-bar"/>
|
||||
<class name="titlebar"/>
|
||||
</style>
|
||||
<child>
|
||||
<object class="GtkButton" id="cancel_button">
|
||||
<property name="visible">False</property>
|
||||
<property name="can_focus">True</property>
|
||||
<property name="focus_on_click">False</property>
|
||||
<property name="label" translatable="yes">Cancel</property>
|
||||
<property name="width_request">70</property>
|
||||
<property name="valign">center</property>
|
||||
<style>
|
||||
<class name="text-button"/>
|
||||
</style>
|
||||
</object>
|
||||
<packing>
|
||||
<property name="pack_type">start</property>
|
||||
</packing>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkButton" id="edit_button">
|
||||
<property name="visible">False</property>
|
||||
|
|
|
@ -425,7 +425,7 @@ public class Contacts.ContactPane : Notebook {
|
|||
set_current_page (0);
|
||||
}
|
||||
|
||||
public void set_edit_mode (bool on_edit) {
|
||||
public void set_edit_mode (bool on_edit, bool drop_changes = false) {
|
||||
if (on_edit == on_edit_mode)
|
||||
return;
|
||||
|
||||
|
@ -450,31 +450,33 @@ public class Contacts.ContactPane : Notebook {
|
|||
} else {
|
||||
on_edit_mode = false;
|
||||
/* saving changes */
|
||||
foreach (var prop in editor.properties_changed ().entries) {
|
||||
Contact.set_persona_property.begin (prop.value.persona, prop.key, prop.value.value,
|
||||
(obj, result) => {
|
||||
try {
|
||||
Contact.set_persona_property.end (result);
|
||||
} catch (Error e2) {
|
||||
App.app.show_message (e2.message);
|
||||
update_sheet ();
|
||||
}
|
||||
});
|
||||
}
|
||||
if (!drop_changes) {
|
||||
foreach (var prop in editor.properties_changed ().entries) {
|
||||
Contact.set_persona_property.begin (prop.value.persona, prop.key, prop.value.value,
|
||||
(obj, result) => {
|
||||
try {
|
||||
Contact.set_persona_property.end (result);
|
||||
} catch (Error e2) {
|
||||
App.app.show_message (e2.message);
|
||||
update_sheet ();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
if (editor.name_changed ()) {
|
||||
var v = editor.get_full_name_value ();
|
||||
Contact.set_individual_property.begin (contact,
|
||||
"full-name", v,
|
||||
(obj, result) => {
|
||||
try {
|
||||
Contact.set_individual_property.end (result);
|
||||
} catch (Error e) {
|
||||
App.app.show_message (e.message);
|
||||
/* FIXME: add this back */
|
||||
/* l.set_markup (Markup.printf_escaped ("<span font='16'>%s</span>", contact.display_name)); */
|
||||
}
|
||||
});
|
||||
if (editor.name_changed ()) {
|
||||
var v = editor.get_full_name_value ();
|
||||
Contact.set_individual_property.begin (contact,
|
||||
"full-name", v,
|
||||
(obj, result) => {
|
||||
try {
|
||||
Contact.set_individual_property.end (result);
|
||||
} catch (Error e) {
|
||||
App.app.show_message (e.message);
|
||||
/* FIXME: add this back */
|
||||
/* l.set_markup (Markup.printf_escaped ("<span font='16'>%s</span>", contact.display_name)); */
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
editor.clear ();
|
||||
|
|
|
@ -41,6 +41,8 @@ public class Contacts.Window : Gtk.ApplicationWindow {
|
|||
[GtkChild]
|
||||
private Button edit_button;
|
||||
[GtkChild]
|
||||
private Button cancel_button;
|
||||
[GtkChild]
|
||||
private Button done_button;
|
||||
|
||||
[GtkChild]
|
||||
|
@ -85,12 +87,57 @@ public class Contacts.Window : Gtk.ApplicationWindow {
|
|||
get; construct set;
|
||||
}
|
||||
|
||||
public bool selection_mode {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public bool edit_mode {
|
||||
get; set;
|
||||
}
|
||||
|
||||
public Window (Gtk.Application app, Store contacts_store) {
|
||||
Object (application: app, store: contacts_store);
|
||||
debug ("everyone creation: finalized already!!!");
|
||||
|
||||
contact_pane.store = contacts_store;
|
||||
|
||||
/* stablishing constraints */
|
||||
this.bind_property ("selection-mode",
|
||||
right_toolbar, "show-close-button",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
this.bind_property ("selection-mode",
|
||||
add_button, "visible",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
this.bind_property ("selection-mode",
|
||||
edit_button, "visible",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
|
||||
this.bind_property ("edit-mode",
|
||||
edit_button, "visible",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
this.bind_property ("edit-mode",
|
||||
done_button, "visible",
|
||||
BindingFlags.DEFAULT);
|
||||
this.bind_property ("edit-mode",
|
||||
cancel_button, "visible",
|
||||
BindingFlags.DEFAULT);
|
||||
this.bind_property ("edit-mode",
|
||||
add_button, "visible",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
this.bind_property ("edit-mode",
|
||||
select_button, "visible",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
this.bind_property ("edit-mode",
|
||||
right_toolbar, "show-close-button",
|
||||
BindingFlags.DEFAULT |
|
||||
BindingFlags.INVERT_BOOLEAN);
|
||||
|
||||
if ((app as App).settings.get_boolean ("did-initial-setup")) {
|
||||
view_switcher.visible_child_name = "content-view";
|
||||
set_titlebar (content_header_bar);
|
||||
|
@ -164,64 +211,57 @@ public class Contacts.Window : Gtk.ApplicationWindow {
|
|||
|
||||
public void activate_selection_mode (bool active) {
|
||||
if (active) {
|
||||
add_button.hide ();
|
||||
edit_button.hide ();
|
||||
selection_mode = true;
|
||||
|
||||
left_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
|
||||
left_toolbar.set_title (_("Select"));
|
||||
right_toolbar.show_close_button = false;
|
||||
|
||||
list_pane.show_selection ();
|
||||
} else {
|
||||
add_button.show ();
|
||||
selection_mode = false;
|
||||
|
||||
left_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
|
||||
left_toolbar.set_title (_("All Contacts"));
|
||||
right_toolbar.show_close_button = true;
|
||||
|
||||
list_pane.hide_selection ();
|
||||
|
||||
/* could be no contact selected whatsoever */
|
||||
if (contact_pane.contact != null)
|
||||
edit_button.show ();
|
||||
if (contact_pane.contact == null)
|
||||
edit_button.hide ();
|
||||
}
|
||||
}
|
||||
|
||||
public void activate_edit_mode (bool active) {
|
||||
if (active) {
|
||||
if (contact_pane.contact == null)
|
||||
return;
|
||||
public void enter_edit_mode () {
|
||||
if (contact_pane.contact == null)
|
||||
return;
|
||||
|
||||
var name = contact_pane.contact.display_name;
|
||||
right_title = _("Editing %s").printf (name);
|
||||
edit_mode = true;
|
||||
|
||||
left_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
var name = contact_pane.contact.display_name;
|
||||
right_title = _("Editing %s").printf (name);
|
||||
|
||||
edit_button.hide ();
|
||||
done_button.show ();
|
||||
contact_pane.set_edit_mode (true);
|
||||
} else {
|
||||
done_button.hide ();
|
||||
edit_button.show ();
|
||||
contact_pane.set_edit_mode (false);
|
||||
left_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().add_class ("selection-mode");
|
||||
|
||||
left_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
contact_pane.set_edit_mode (true);
|
||||
}
|
||||
|
||||
if (contact_pane.contact != null)
|
||||
right_title = contact_pane.contact.display_name;
|
||||
else
|
||||
right_title = "";
|
||||
}
|
||||
public void leave_edit_mode (bool drop_changes = false) {
|
||||
edit_mode = false;
|
||||
|
||||
add_button.visible = !active;
|
||||
select_button.visible = !active;
|
||||
right_toolbar.show_close_button = !active;
|
||||
contact_pane.set_edit_mode (false, drop_changes);
|
||||
|
||||
left_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
right_toolbar.get_style_context ().remove_class ("selection-mode");
|
||||
|
||||
if (contact_pane.contact != null)
|
||||
right_title = contact_pane.contact.display_name;
|
||||
else
|
||||
right_title = "";
|
||||
}
|
||||
|
||||
public void add_notification (Widget notification) {
|
||||
|
@ -231,7 +271,7 @@ public class Contacts.Window : Gtk.ApplicationWindow {
|
|||
public void set_shown_contact (Contact? c) {
|
||||
/* FIXME: ask the user to leave edit-mode and act accordingly */
|
||||
if (contact_pane.on_edit_mode) {
|
||||
activate_edit_mode (false);
|
||||
leave_edit_mode ();
|
||||
}
|
||||
|
||||
contact_pane.show_contact (c, false);
|
||||
|
@ -262,11 +302,15 @@ public class Contacts.Window : Gtk.ApplicationWindow {
|
|||
});
|
||||
|
||||
edit_button.clicked.connect (() => {
|
||||
activate_edit_mode (true);
|
||||
enter_edit_mode ();
|
||||
});
|
||||
|
||||
done_button.clicked.connect (() => {
|
||||
activate_edit_mode (false);
|
||||
leave_edit_mode ();
|
||||
});
|
||||
|
||||
cancel_button.clicked.connect (() => {
|
||||
leave_edit_mode (true);
|
||||
});
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue