comparison src/gtkconv.c @ 8021:fef1723f724a

[gaim-migrate @ 8701] tab complete doesn't complete the latter part of nicks, and old-style tab complete now works how it was intended committer: Tailor Script <tailor@pidgin.im>
author Nathan Walp <nwalp@pidgin.im>
date Tue, 06 Jan 2004 07:48:10 +0000
parents 934f5df83b29
children 89ec7c63113c
comparison
equal deleted inserted replaced
8020:35c2526dba16 8021:fef1723f724a
2828 GtkTextIter cursor, word_start, start_buffer; 2828 GtkTextIter cursor, word_start, start_buffer;
2829 int start; 2829 int start;
2830 int most_matched = -1; 2830 int most_matched = -1;
2831 char *entered, *partial = NULL; 2831 char *entered, *partial = NULL;
2832 char *text; 2832 char *text;
2833 char *nick_partial;
2833 GList *matches = NULL; 2834 GList *matches = NULL;
2834 GList *nicks = NULL; 2835 GList *nicks = NULL;
2835 2836
2836 gtkconv = GAIM_GTK_CONVERSATION(conv); 2837 gtkconv = GAIM_GTK_CONVERSATION(conv);
2837 chat = GAIM_CONV_CHAT(conv); 2838 chat = GAIM_CONV_CHAT(conv);
2850 &cursor, FALSE); 2851 &cursor, FALSE);
2851 2852
2852 /* if we're at the end of ": " we need to move back 2 spaces */ 2853 /* if we're at the end of ": " we need to move back 2 spaces */
2853 start = strlen(text) - 1; 2854 start = strlen(text) - 1;
2854 2855
2855 if (strlen(text) >= 2 && !strncmp(&text[start-1], ": ", 2)) 2856 if (strlen(text) >= 2 && !strncmp(&text[start-1], ": ", 2)) {
2856 gtk_text_iter_backward_chars(&word_start, 2); 2857 gtk_text_iter_backward_chars(&word_start, 2);
2858 start-=2;
2859 }
2857 2860
2858 /* find the start of the word that we're tabbing */ 2861 /* find the start of the word that we're tabbing */
2859 while (start >= 0 && text[start] != ' ') { 2862 while (start >= 0 && text[start] != ' ') {
2860 gtk_text_iter_backward_char(&word_start); 2863 gtk_text_iter_backward_char(&word_start);
2861 start--; 2864 start--;
2872 2875
2873 entered[strlen(entered) - 2] = 0; 2876 entered[strlen(entered) - 2] = 0;
2874 } 2877 }
2875 } 2878 }
2876 2879
2877 if (!strlen(entered)) { 2880 if (!g_utf8_strlen(entered, -1)) {
2878 g_free(entered); 2881 g_free(entered);
2879 return; 2882 return;
2880 } 2883 }
2884
2885 nick_partial = g_malloc(strlen(entered)+1);
2881 2886
2882 for (nicks = gaim_conv_chat_get_users(chat); 2887 for (nicks = gaim_conv_chat_get_users(chat);
2883 nicks != NULL; 2888 nicks != NULL;
2884 nicks = nicks->next) { 2889 nicks = nicks->next) {
2885 2890
2886 char *nick = nicks->data; 2891 char *nick = nicks->data;
2887 /* this checks to see if the current nick could be a completion */ 2892
2888 if (g_ascii_strncasecmp(nick, entered, strlen(entered))) { 2893 g_utf8_strncpy(nick_partial, nick, strlen(entered));
2889 if (g_ascii_strncasecmp(nick + 1, entered, strlen(entered))) { 2894 if(gaim_utf8_strcasecmp(nick_partial, entered))
2890 if (g_ascii_strncasecmp(nick + 2, entered, strlen(entered))) 2895 continue;
2891 continue;
2892 else
2893 nick += 2;
2894 }
2895 else
2896 nick++;
2897 }
2898 2896
2899 /* if we're here, it's a possible completion */ 2897 /* if we're here, it's a possible completion */
2900 2898
2901 /* if we're doing old-style, just fill in the completion */ 2899 /* if we're doing old-style, just fill in the completion */
2902 if (gaim_prefs_get_bool("/gaim/gtk/conversations/chat/old_tab_complete")) { 2900 if (gaim_prefs_get_bool("/gaim/gtk/conversations/chat/old_tab_complete")) {
2924 } 2922 }
2925 else 2923 else
2926 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer, 2924 gtk_text_buffer_insert_at_cursor(gtkconv->entry_buffer,
2927 nick, -1); 2925 nick, -1);
2928 2926
2927 g_free(nick_partial);
2929 g_free(entered); 2928 g_free(entered);
2930 2929
2931 return; 2930 return;
2932 } 2931 }
2933 2932
2939 */ 2938 */
2940 most_matched = strlen(nick); 2939 most_matched = strlen(nick);
2941 partial = g_strdup(nick); 2940 partial = g_strdup(nick);
2942 } 2941 }
2943 else if (most_matched) { 2942 else if (most_matched) {
2944 while (g_ascii_strncasecmp(nick, partial, most_matched)) 2943 char *tmp = g_strdup(nick);
2944
2945 while (gaim_utf8_strcasecmp(tmp, partial)) {
2946 partial[most_matched] = '\0';
2947 if(most_matched < strlen(tmp))
2948 tmp[most_matched] = '\0';
2945 most_matched--; 2949 most_matched--;
2946 2950 }
2947 partial[most_matched] = 0; 2951
2952 g_free(tmp);
2948 } 2953 }
2949 2954
2950 matches = g_list_append(matches, nick); 2955 matches = g_list_append(matches, nick);
2951 } 2956 }
2957
2958 g_free(nick_partial);
2952 2959
2953 /* we're only here if we're doing new style */ 2960 /* we're only here if we're doing new style */
2954 2961
2955 /* if there weren't any matches, return */ 2962 /* if there weren't any matches, return */
2956 if (!matches) { 2963 if (!matches) {