diff options
author | Jon Trowbridge <trow@ximian.com> | 2001-12-28 11:08:27 +0800 |
---|---|---|
committer | Jon Trowbridge <trow@src.gnome.org> | 2001-12-28 11:08:27 +0800 |
commit | 2786536d7f25b29b20a41b417896cff810368d85 (patch) | |
tree | 3ecdda5c24e1de152937a451a10bc09a5be891ba /addressbook/gui/component/select-names/e-select-names-text-model.c | |
parent | b054d4b4e6f7eff593a2ac7c3b40f2d8bb92b82c (diff) | |
download | gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar.gz gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar.bz2 gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar.lz gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar.xz gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.tar.zst gsoc2013-evolution-2786536d7f25b29b20a41b417896cff810368d85.zip |
When we clean, don't clean the model's last element. This helps keep
2001-12-27 Jon Trowbridge <trow@ximian.com>
* gui/component/select-names/e-select-names.c
(real_add_address_cb): When we clean, don't clean the model's last
element. This helps keep things working properly when we have
signal-character separators.
(section_right_click_cb): Changed to work properly with our
EText-emitted popup signal.
(e_select_names_add_section): Use ETexts for the recipient
sections, rather than tables. This lets us make them directly
editable. (Bug #1721)
* gui/component/select-names/e-select-names-popup.c
(popup_info_new): Pass in a ESelectNamesTextModel, not a
ESelectNamesModel.
(e_select_names_popup): Adjust for the new signature for
e_select_names_model_text_pos.
* gui/component/select-names/e-select-names-manager.c
(focus_out_cb): Schedule a cleaning when we focus out.
(focus_in_cb): Cancel pending cleaning when we get focus. This
helps us avoid bad things happening during the fast focus out/ins
that happen when the completion dropdown appears.
(completion_handler): Adjust for new signatures of
e_select_names_model_text_pos and e_select_names_model_name_pos.
(e_select_names_manager_entry_new): Pass in our
ESelectNamesTextModel when constructing the
ESelectNamesCompletion.
(e_select_names_manager_entry_free): Cancel any pending clean-ups.
* gui/component/select-names/e-select-names-bonobo.c
(entry_get_property_fn): Get the text off of the text model.
Which is the only way that really makes sense when you think about
it.
* gui/component/select-names/e-select-names-completion.c: Added a
copy of the associated ESelectNamesTextModel to
ESelectNamesCompletionPrivate. This replaces the
ESelectNamesModel.
(e_select_names_completion_destroy): Unref ->text_model.
(e_select_names_completion_handle_request): Pass in our text
model's separator info when calling e_select_names_model_text_pos.
(e_select_names_completion_new): Pass in the text model as an arg
instead of the model, and ref it as needed.
* gui/component/select-names/e-select-names-text-model.c
(e_select_names_text_model_init): Set separator as either ", " or
",", depending on the value of the EVOLUTION_DISABLE_MAGIC_COMMA
environment variable.
(e_select_names_text_model_destroy): Free the separator.
(changed_cb): Flush our cached text on changed.
(e_select_names_text_model_set_source): Use our own changed_cb
callback on changed, rather than just connecting up
e_text_model_changed.
(e_select_names_text_model_set_separator): Added. Lets the
separator between recipients be specified.
(e_select_names_text_model_get_text): Cache the text we get from
calling e_select_names_model_get_textification.
(e_select_names_text_model_insert_length): A bunch of small
changes to properly support generic separators, rather than
(implicit and explicitly) assuming ", ".
(e_select_names_text_model_delete): More small tweaks to handle
generic separators.
(e_select_names_text_model_get_nth_obj): Use new signature when
calling e_select_names_model_name_pos, and use our cached text.
* gui/component/select-names/e-select-names-model.c
(e_select_names_model_destroy): We don't cache the text or
addr_text anymore, so no need to free them here.
(e_select_names_model_changed): ...and no need to reset our text
and addr_text caches here.
(e_select_names_model_get_textification): Take a separator as an
arg, rather than just using ", ". Also, no caching.
(e_select_names_model_get_address_text): Take a separator as an
arg, rather than just using ", ". And no caching here either.
(e_select_names_model_clean): Add arg that give us control over
whether or not the last entry should get cleaned. We need this
when using a one-character separator, so that new destinations
that get tacked onto the end don't get immediately cleaned away
for being empty.
(e_select_names_model_name_pos): Take the separator length as an
argument, remove implicit assumption of length 2.
(e_select_names_model_text_pos): Take the separator length as an
argument, remove implicit assumption of length 2.CVS: ----------------------------------------------------------------------
svn path=/trunk/; revision=15221
Diffstat (limited to 'addressbook/gui/component/select-names/e-select-names-text-model.c')
-rw-r--r-- | addressbook/gui/component/select-names/e-select-names-text-model.c | 119 |
1 files changed, 80 insertions, 39 deletions
diff --git a/addressbook/gui/component/select-names/e-select-names-text-model.c b/addressbook/gui/component/select-names/e-select-names-text-model.c index d2e77d6316..8faa99d0e4 100644 --- a/addressbook/gui/component/select-names/e-select-names-text-model.c +++ b/addressbook/gui/component/select-names/e-select-names-text-model.c @@ -22,8 +22,6 @@ static FILE *out = NULL; /* stream for debugging spew */ -#define SEPLEN 2 - /* Object argument IDs */ enum { ARG_0, @@ -140,7 +138,16 @@ dump_model (ESelectNamesTextModel *text_model) static void e_select_names_text_model_init (ESelectNamesTextModel *model) { + const gchar *default_sep; + model->last_magic_comma_pos = -1; + + if (getenv ("EVOLUTION_DISABLE_MAGIC_COMMA")) + default_sep = ","; + else + default_sep = ", "; + + e_select_names_text_model_set_separator (model, default_sep); } static void @@ -149,6 +156,9 @@ e_select_names_text_model_destroy (GtkObject *object) ESelectNamesTextModel *model; model = E_SELECT_NAMES_TEXT_MODEL (object); + + g_free (model->text); + g_free (model->sep); e_select_names_text_model_set_source (model, NULL); @@ -195,8 +205,9 @@ resize_cb (ESelectNamesModel *source, gint index, gint old_len, gint new_len, ET EReposDeleteShift repos_del; EReposInsertShift repos_ins; gint pos; + gint seplen = E_SELECT_NAMES_TEXT_MODEL (model)->seplen; - e_select_names_model_name_pos (source, index, &pos, NULL); + e_select_names_model_name_pos (source, seplen, index, &pos, NULL); if (new_len < old_len) { @@ -215,6 +226,17 @@ resize_cb (ESelectNamesModel *source, gint index, gint old_len, gint new_len, ET } } +static void +changed_cb (ETextModel *model) +{ + ESelectNamesTextModel *text_model = E_SELECT_NAMES_TEXT_MODEL (model); + + g_free (text_model->text); + text_model->text = NULL; + + e_text_model_changed (model); +} + static void e_select_names_text_model_set_source (ESelectNamesTextModel *model, @@ -235,7 +257,7 @@ e_select_names_text_model_set_source (ESelectNamesTextModel *model, gtk_object_ref (GTK_OBJECT (model->source)); model->source_changed_id = gtk_signal_connect_object (GTK_OBJECT(model->source), "changed", - GTK_SIGNAL_FUNC (e_text_model_changed), + GTK_SIGNAL_FUNC (changed_cb), GTK_OBJECT (model)); model->source_resize_id = gtk_signal_connect (GTK_OBJECT(model->source), "resized", @@ -252,12 +274,28 @@ e_select_names_text_model_new (ESelectNamesModel *source) return model; } +void +e_select_names_text_model_set_separator (ESelectNamesTextModel *model, const char *sep) +{ + g_return_if_fail (E_IS_SELECT_NAMES_TEXT_MODEL (model)); + g_return_if_fail (sep && *sep); + + g_free (model->sep); + model->sep = g_strdup (sep); + model->seplen = strlen (sep); +} + static const gchar * e_select_names_text_model_get_text (ETextModel *model) { ESelectNamesTextModel *snm = E_SELECT_NAMES_TEXT_MODEL(model); - return snm ? e_select_names_model_get_textification (snm->source) : ""; + if (snm == NULL) + return ""; + else if (snm->text == NULL) + snm->text = e_select_names_model_get_textification (snm->source, snm->sep); + + return snm->text; } static void @@ -278,11 +316,10 @@ e_select_names_text_model_insert (ETextModel *model, gint position, const gchar static void e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gchar *text, gint length) { - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; - gint i; + ESelectNamesTextModel *text_model = E_SELECT_NAMES_TEXT_MODEL (model); + ESelectNamesModel *source = text_model->source; - g_return_if_fail (model != NULL); - g_return_if_fail (E_IS_SELECT_NAMES_TEXT_MODEL (model)); + gint i; if (out) { gchar *tmp = g_strndup (text, length); @@ -290,11 +327,11 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha g_free (tmp); } - pos = CLAMP (pos, 0, strlen (e_select_names_model_get_textification (source))); + pos = CLAMP (pos, 0, strlen (e_select_names_model_get_textification (source, text_model->sep))); /* We want to control all cursor motions ourselves, rather than taking hints from the ESelectNamesModel. */ - gtk_signal_handler_block (GTK_OBJECT (source), E_SELECT_NAMES_TEXT_MODEL (model)->source_resize_id); + gtk_signal_handler_block (GTK_OBJECT (source), text_model->source_resize_id); /* We handle this one character at a time. */ @@ -302,17 +339,17 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha gint index, start_pos, text_len; gboolean inside_quote = FALSE; - E_SELECT_NAMES_TEXT_MODEL (model)->last_magic_comma_pos = -1; + text_model->last_magic_comma_pos = -1; if (out) fprintf (out, "processing [%c]\n", text[i]); - e_select_names_model_text_pos (source, pos, &index, &start_pos, &text_len); + e_select_names_model_text_pos (source, text_model->seplen, pos, &index, &start_pos, &text_len); if (out) fprintf (out, "index=%d start_pos=%d text_len=%d\n", index, start_pos, text_len); - if (text[i] == ',' && index >= 0) { /* Is this a quoted or an unquoted comma we are dealing with? */ + if (text[i] == *text_model->sep && index >= 0) { /* Is this a quoted or an unquoted separator we are dealing with? */ const EDestination *dest = e_select_names_model_get_destination (source, index); if (dest) { const gchar *str = e_destination_get_textrep (dest); @@ -331,7 +368,7 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha } - if (text[i] == ',' && !inside_quote) { + if (text[i] == *text_model->sep && !inside_quote) { /* This is the case of hitting , first thing in an empty entry */ if (index == -1) { @@ -361,9 +398,9 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha repos.model = model; repos.pos = pos; - repos.len = SEPLEN; + repos.len = text_model->seplen; e_text_model_reposition (model, e_repos_insert_shift, &repos); - pos += SEPLEN; + pos += text_model->seplen; } } else { @@ -385,12 +422,13 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha repos.model = model; repos.pos = pos; - repos.len = SEPLEN; + repos.len = text_model->seplen; e_text_model_reposition (model, e_repos_insert_shift, &repos); - pos += SEPLEN; + pos += text_model->seplen; } - E_SELECT_NAMES_TEXT_MODEL (model)->last_magic_comma_pos = pos; + if (text_model->seplen > 1) + text_model->last_magic_comma_pos = pos; } else { EReposInsertShift repos; @@ -408,6 +446,7 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha this_length = 0; } else { /* Adjust for our "magic white space" */ + /* FIXME: This code does the wrong thing if seplen > 2 */ new_str = g_strdup_printf("%c%s%s", text[i], pos < start_pos ? " " : "", str); if (pos < start_pos) ++this_length; @@ -447,20 +486,21 @@ e_select_names_text_model_insert_length (ETextModel *model, gint pos, const gcha } } - dump_model (E_SELECT_NAMES_TEXT_MODEL (model)); + dump_model (text_model); - gtk_signal_handler_unblock (GTK_OBJECT (source), E_SELECT_NAMES_TEXT_MODEL (model)->source_resize_id); + gtk_signal_handler_unblock (GTK_OBJECT (source), text_model->source_resize_id); } static void e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) { - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; + ESelectNamesTextModel *text_model = E_SELECT_NAMES_TEXT_MODEL (model); + ESelectNamesModel *source = text_model->source; gint index, start_pos, text_len, offset; if (out) { - const gchar *str = e_select_names_model_get_textification (source); + const gchar *str = e_select_names_model_get_textification (source, text_model->sep); gint i, len; fprintf (out, ">> delete %d at pos %d\n", length, pos); @@ -480,15 +520,14 @@ e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) if (length < 0) return; - if (E_SELECT_NAMES_TEXT_MODEL (model)->last_magic_comma_pos == pos+1 - && length == 1) { - --pos; + if (text_model->last_magic_comma_pos == pos+1 && length == 1) { + pos -= text_model->seplen-1; if (pos >= 0) - ++length; - E_SELECT_NAMES_TEXT_MODEL (model)->last_magic_comma_pos = -1; + length = text_model->seplen; + text_model->last_magic_comma_pos = -1; } - e_select_names_model_text_pos (source, pos, &index, &start_pos, &text_len); + e_select_names_model_text_pos (source, text_model->seplen, pos, &index, &start_pos, &text_len); if (out) fprintf (out, "index=%d, start_pos=%d, text_len=%d\n", index, start_pos, text_len); @@ -529,7 +568,7 @@ e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) ++str2; if (str1 && str2) - new_str = g_strdup_printf ("%s %s", str1, str2); + new_str = g_strdup_printf ("%s%s%s", str1, text_model->sep+1, str2); else if (str1) new_str = g_strdup (str1); else if (str2) @@ -549,7 +588,7 @@ e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) repos.model = model; repos.pos = pos; - repos.len = SEPLEN - 1; + repos.len = text_model->seplen; e_text_model_reposition (model, e_repos_delete_shift, &repos); @@ -577,11 +616,11 @@ e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) repos.model = model; repos.pos = pos; - repos.len = text_len + SEPLEN; + repos.len = text_len + text_model->seplen; e_text_model_reposition (model, e_repos_delete_shift, &repos); - length -= text_len + SEPLEN; + length -= text_len + text_model->seplen; if (length > 0) e_select_names_text_model_delete (model, pos, length); @@ -644,7 +683,7 @@ e_select_names_text_model_delete (ETextModel *model, gint pos, gint length) repos.model = model; repos.pos = pos; - repos.len = SEPLEN; + repos.len = text_model->seplen; e_text_model_reposition (model, e_repos_delete_shift, &repos); } @@ -700,7 +739,8 @@ nth_obj_index (ESelectNamesModel *source, gint n) static const gchar * e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len) { - ESelectNamesModel *source = E_SELECT_NAMES_TEXT_MODEL (model)->source; + ESelectNamesTextModel *text_model = E_SELECT_NAMES_TEXT_MODEL (model); + ESelectNamesModel *source = text_model->source; const gchar *txt; gint i, pos; @@ -708,12 +748,13 @@ e_select_names_text_model_get_nth_obj (ETextModel *model, gint n, gint *len) if (i < 0) return NULL; - e_select_names_model_name_pos (source, i, &pos, len); + e_select_names_model_name_pos (source, text_model->seplen, i, &pos, len); if (pos < 0) return NULL; - txt = e_select_names_model_get_textification (source); - return txt + pos; + if (text_model->text == NULL) + text_model->text = e_select_names_model_get_textification (source, text_model->sep); + return text_model->text + pos; } static void |