[gnome-contacts/new-design] Add support for not editing
- From: Alexander Larsson <alexl src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-contacts/new-design] Add support for not editing
- Date: Thu, 15 Dec 2011 20:55:32 +0000 (UTC)
commit 56fa295f1a70ebfe94f46e24ceaa5212d533d94f
Author: Alexander Larsson <alexl redhat com>
Date: Thu Dec 15 21:48:59 2011 +0100
Add support for not editing
src/contacts-contact-pane.vala | 70 +++++++++++++++++++++++++++++++++++++++-
1 files changed, 69 insertions(+), 1 deletions(-)
---
diff --git a/src/contacts-contact-pane.vala b/src/contacts-contact-pane.vala
index c2c316b..17cbb23 100644
--- a/src/contacts-contact-pane.vala
+++ b/src/contacts-contact-pane.vala
@@ -845,6 +845,24 @@ public abstract class Contacts.DataFieldRow : FieldRow {
return false;
});
}
+
+ public void setup_text_view_for_edit (TextView text, bool grab_focus = true) {
+ if (grab_focus) {
+ ulong id = 0;
+ id = text.size_allocate.connect ( () => {
+ text.grab_focus ();
+ text.disconnect (id);
+ });
+ }
+ text.key_press_event.connect ( (key_event) => {
+ if (key_event.keyval == Gdk.keyval_from_name ("Escape")) {
+ field_set.sheet.pane.exit_edit_mode (false);
+ }
+ return false;
+ });
+ }
+
+
}
class Contacts.LinkFieldRow : DataFieldRow {
@@ -1173,8 +1191,9 @@ class Contacts.NicknameFieldSet : FieldSet {
}
class Contacts.NoteFieldRow : DataFieldRow {
- NoteFieldDetails details;
+ public NoteFieldDetails details;
Label text_label;
+ TextView? text;
public NoteFieldRow (FieldSet field_set, NoteFieldDetails details) {
base (field_set);
@@ -1186,6 +1205,39 @@ class Contacts.NoteFieldRow : DataFieldRow {
public override void update () {
text_label.set_text (details.value);
}
+
+ public override void pack_edit_widgets () {
+ text = new TextView ();
+ text.set_hexpand (true);
+ text.set_vexpand (true);
+ var scrolled = new ScrolledWindow (null, null);
+ scrolled.set_shadow_type (ShadowType.OUT);
+ scrolled.add_with_viewport (text);
+
+ pack (scrolled);
+
+ delete_button.set_valign (Align.START);
+
+ text.get_buffer ().set_text (details.value);
+ text.get_buffer ().set_modified (false);
+
+ setup_text_view_for_edit (text);
+ }
+
+ public override bool finish_edit_widgets (bool save) {
+ var old_details = details;
+ var changed = text.get_buffer (). get_modified ();
+ if (save && changed) {
+ TextIter start, end;
+ text.get_buffer ().get_start_iter (out start);
+ text.get_buffer ().get_end_iter (out end);
+ var value = text.get_buffer ().get_text (start, end, true);
+ details = new NoteFieldDetails (value, old_details.parameters);
+ }
+ text = null;
+
+ return changed;
+ }
}
class Contacts.NoteFieldSet : FieldSet {
@@ -1203,6 +1255,22 @@ class Contacts.NoteFieldSet : FieldSet {
add_row (row);
}
}
+ public override Value? get_value () {
+ var details = sheet.persona as NoteDetails;
+ if (details == null)
+ return null;
+
+ var new_details = new HashSet<NoteFieldDetails>();
+ foreach (var row in data_rows) {
+ var note_row = row as NoteFieldRow;
+ new_details.add (note_row.details);
+ }
+
+ var value = Value(new_details.get_type ());
+ value.set_object (new_details);
+
+ return value;
+ }
}
class Contacts.AddressFieldRow : DataFieldRow {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]