annotate finch/libgnt/gntentry.c @ 27744:6d37c29df78a

Um, this was a memory leak, right?
author Mark Doliner <mark@kingant.net>
date Thu, 30 Jul 2009 23:45:45 +0000
parents c67d43408daa
children 650ab9eb4b21
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
17928
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
1 /**
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
2 * GNT - The GLib Ncurses Toolkit
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
3 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
4 * GNT is the legal property of its developers, whose names are too numerous
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
5 * to list here. Please refer to the COPYRIGHT file distributed with this
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
6 * source distribution.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
7 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
8 * This library is free software; you can redistribute it and/or modify
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
9 * it under the terms of the GNU General Public License as published by
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
10 * the Free Software Foundation; either version 2 of the License, or
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
11 * (at your option) any later version.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
12 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
13 * This program is distributed in the hope that it will be useful,
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
16 * GNU General Public License for more details.
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
17 *
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
18 * You should have received a copy of the GNU General Public License
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
19 * along with this program; if not, write to the Free Software
19681
44b4e8bd759b The FSF changed its address a while ago; our files were out of date.
John Bailey <rekkanoryo@rekkanoryo.org>
parents: 18873
diff changeset
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
17928
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
21 */
8410511f4dbb applied changes from 016401bd409e6229fae0ab1e80d9fef9365511b3
Eric Polino <aluink@pidgin.im>
parents: 16899
diff changeset
22
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
23 #include <ctype.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
24 #include <string.h>
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
25
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
26 #include "gntbox.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
27 #include "gntentry.h"
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
28 #include "gntmarshal.h"
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
29 #include "gntstyle.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
30 #include "gnttree.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
31 #include "gntutils.h"
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
32
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
33 enum
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
34 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
35 SIG_TEXT_CHANGED,
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
36 SIG_COMPLETION,
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
37 SIGS,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
38 };
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
39
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
40 typedef enum
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
41 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
42 ENTRY_JAIL = -1, /* Suspend the kill ring. */
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
43 ENTRY_DEL_BWD_WORD = 1,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
44 ENTRY_DEL_BWD_CHAR,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
45 ENTRY_DEL_FWD_WORD,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
46 ENTRY_DEL_FWD_CHAR,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
47 ENTRY_DEL_EOL,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
48 ENTRY_DEL_BOL,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
49 } GntEntryAction;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
50
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
51 struct _GntEntryKillRing
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
52 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
53 GString *buffer;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
54 GntEntryAction last;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
55 };
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
56
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
57 static guint signals[SIGS] = { 0 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
58
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
59 static GntWidgetClass *parent_class = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
60
15959
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
61 static gboolean gnt_entry_key_pressed(GntWidget *widget, const char *text);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
62 static void gnt_entry_set_text_internal(GntEntry *entry, const char *text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
63
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
64 static gboolean
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
65 update_kill_ring(GntEntry *entry, GntEntryAction action, const char *text, int len)
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
66 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
67 if (action < 0) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
68 entry->killring->last = action;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
69 return FALSE;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
70 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
71
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
72 if (len == 0)
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
73 len = strlen(text);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
74 else if (len < 0) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
75 text += len;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
76 len = -len;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
77 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
78
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
79 if (action != entry->killring->last) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
80 struct {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
81 GntEntryAction one;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
82 GntEntryAction two;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
83 } merges[] = {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
84 {ENTRY_DEL_BWD_WORD, ENTRY_DEL_FWD_WORD},
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
85 {ENTRY_DEL_BWD_CHAR, ENTRY_DEL_FWD_CHAR},
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
86 {ENTRY_DEL_BOL, ENTRY_DEL_EOL},
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
87 {ENTRY_JAIL, ENTRY_JAIL},
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
88 };
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
89 int i;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
90
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
91 for (i = 0; merges[i].one != ENTRY_JAIL; i++) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
92 if (merges[i].one == entry->killring->last &&
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
93 merges[i].two == action) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
94 g_string_append_len(entry->killring->buffer, text, len);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
95 break;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
96 } else if (merges[i].one == action &&
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
97 merges[i].two == entry->killring->last) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
98 g_string_prepend_len(entry->killring->buffer, text, len);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
99 break;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
100 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
101 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
102 if (merges[i].one == ENTRY_JAIL) {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
103 g_string_assign(entry->killring->buffer, text);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
104 g_string_truncate(entry->killring->buffer, len);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
105 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
106 entry->killring->last = action;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
107 } else {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
108 if (action == ENTRY_DEL_BWD_CHAR || action == ENTRY_DEL_BWD_WORD)
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
109 g_string_prepend_len(entry->killring->buffer, text, len);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
110 else
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
111 g_string_append_len(entry->killring->buffer, text, len);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
112 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
113 return TRUE;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
114 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
115
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
116 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
117 destroy_suggest(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
118 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
119 if (entry->ddown)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
120 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
121 gnt_widget_destroy(entry->ddown->parent);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
122 entry->ddown = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
123 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
124 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
125
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
126 static char *
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
127 get_beginning_of_word(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
128 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
129 char *s = entry->cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
130 while (s > entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
131 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
132 char *t = g_utf8_find_prev_char(entry->start, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
133 if (isspace(*t))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
134 break;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
135 s = t;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
136 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
137 return s;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
138 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
139
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
140 static gboolean
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
141 complete_suggest(GntEntry *entry, const char *text)
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
142 {
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
143 int offstart = 0, offend = 0;
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
144
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
145 if (entry->word) {
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
146 char *s = get_beginning_of_word(entry);
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
147 const char *iter = text;
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
148 offstart = g_utf8_pointer_to_offset(entry->start, s);
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
149 while (*iter && toupper(*s) == toupper(*iter)) {
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
150 *s++ = *iter++;
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
151 }
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
152 if (*iter) {
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
153 gnt_entry_key_pressed(GNT_WIDGET(entry), iter);
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
154 }
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
155 offend = g_utf8_pointer_to_offset(entry->start, entry->cursor);
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
156 } else {
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
157 offstart = 0;
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
158 gnt_entry_set_text_internal(entry, text);
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
159 offend = g_utf8_strlen(text, -1);
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
160 }
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
161
21699
760a8e024142 Emit the 'completion' signal when tab is pressed from a suggest word.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21680
diff changeset
162 g_signal_emit(G_OBJECT(entry), signals[SIG_COMPLETION], 0,
760a8e024142 Emit the 'completion' signal when tab is pressed from a suggest word.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21680
diff changeset
163 entry->start + offstart, entry->start + offend);
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
164 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
21699
760a8e024142 Emit the 'completion' signal when tab is pressed from a suggest word.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21680
diff changeset
165 return TRUE;
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
166 }
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
167
20088
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
168 static int
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
169 max_common_prefix(const char *s, const char *t)
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
170 {
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
171 const char *f = s;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
172 while (*f && *t && *f == *t++)
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
173 f++;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
174 return f - s;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
175 }
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
176
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
177 static gboolean
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
178 show_suggest_dropdown(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
179 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
180 char *suggest = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
181 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
182 int offset = 0, x, y;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
183 int count = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
184 GList *iter;
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
185 const char *text = NULL;
16899
6502a3846264 Fix tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16889
diff changeset
186 const char *sgst = NULL;
20088
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
187 int max = -1;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
188
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
189 if (entry->word)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
190 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
191 char *s = get_beginning_of_word(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
192 suggest = g_strndup(s, entry->cursor - s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
193 if (entry->scroll < s)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
194 offset = gnt_util_onscreen_width(entry->scroll, s);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
195 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
196 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
197 suggest = g_strdup(entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
198 len = strlen(suggest); /* Don't need to use the utf8-function here */
20088
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
199
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
200 if (entry->ddown == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
201 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
202 GntWidget *box = gnt_vbox_new(FALSE);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
203 entry->ddown = gnt_tree_new();
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
204 gnt_tree_set_compare_func(GNT_TREE(entry->ddown), (GCompareFunc)g_utf8_collate);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
205 gnt_box_add_widget(GNT_BOX(box), entry->ddown);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
206
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
207 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_TRANSIENT);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
208
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
209 gnt_widget_get_position(GNT_WIDGET(entry), &x, &y);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
210 x += offset;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
211 y++;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
212 if (y + 10 >= getmaxy(stdscr))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
213 y -= 11;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
214 gnt_widget_set_position(box, x, y);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
215 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
216 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
217 gnt_tree_remove_all(GNT_TREE(entry->ddown));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
218
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
219 for (count = 0, iter = entry->suggests; iter; iter = iter->next)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
220 {
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
221 text = iter->data;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
222 if (g_ascii_strncasecmp(suggest, text, len) == 0 && strlen(text) >= len)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
223 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
224 gnt_tree_add_row_after(GNT_TREE(entry->ddown), (gpointer)text,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
225 gnt_tree_create_row(GNT_TREE(entry->ddown), text),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
226 NULL, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
227 count++;
20088
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
228 if (max == -1)
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
229 max = strlen(text) - len;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
230 else if (max)
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
231 max = MIN(max, max_common_prefix(sgst + len, text + len));
16899
6502a3846264 Fix tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 16889
diff changeset
232 sgst = text;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
233 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
234 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
235 g_free(suggest);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
236
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
237 if (count == 0) {
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
238 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
239 return FALSE;
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
240 } else if (count == 1) {
22698
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
241 char *store = g_strndup(entry->start, entry->end - entry->start);
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
242 gboolean ret;
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
243
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
244 destroy_suggest(entry);
22698
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
245 complete_suggest(entry, sgst);
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
246
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
247 ret = (strncmp(store, entry->start, entry->end - entry->start) != 0);
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
248 g_free(store);
4a05b9db0b91 Return FALSE when nothing changes after an attempted tab-completion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22434
diff changeset
249 return ret;
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
250 } else {
20088
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
251 if (max > 0) {
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
252 GntWidget *ddown = entry->ddown;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
253 char *match = g_strndup(sgst + len, max);
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
254 entry->ddown = NULL;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
255 gnt_entry_key_pressed(GNT_WIDGET(entry), match);
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
256 g_free(match);
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
257 if (entry->ddown)
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
258 gnt_widget_destroy(ddown);
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
259 else
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
260 entry->ddown = ddown;
470feb3084a4 Tab-complete as much as possible when there are multiple suggests.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 19681
diff changeset
261 }
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
262 gnt_widget_draw(entry->ddown->parent);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
263 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
264
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
265 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
266 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
267
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
268 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
269 gnt_entry_draw(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
270 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
271 GntEntry *entry = GNT_ENTRY(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
272 int stop;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
273 gboolean focus;
26439
c67d43408daa Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24586
diff changeset
274 int curpos;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
275
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
276 if ((focus = gnt_widget_has_focus(widget)))
21250
9187d331aebe Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 20088
diff changeset
277 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_TEXT_NORMAL));
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
278 else
21250
9187d331aebe Add gnt_color_pair, which will replace color codes with 'appropriate' text
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 20088
diff changeset
279 wbkgdset(widget->window, '\0' | gnt_color_pair(GNT_COLOR_HIGHLIGHT_D));
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
280
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
281 if (entry->masked)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
282 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
283 mvwhline(widget->window, 0, 0, gnt_ascii_only() ? '*' : ACS_BULLET,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
284 g_utf8_pointer_to_offset(entry->scroll, entry->end));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
285 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
286 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
287 mvwprintw(widget->window, 0, 0, "%s", entry->scroll);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
288
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
289 stop = gnt_util_onscreen_width(entry->scroll, entry->end);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
290 if (stop < widget->priv.width)
18346
72a52cff76f3 Draw the password entries correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 17928
diff changeset
291 mvwhline(widget->window, 0, stop, ENTRY_CHAR, widget->priv.width - stop);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
292
26439
c67d43408daa Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24586
diff changeset
293 curpos = gnt_util_onscreen_width(entry->scroll, entry->cursor);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
294 if (focus)
26439
c67d43408daa Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24586
diff changeset
295 mvwchgat(widget->window, 0, curpos, 1, A_REVERSE, GNT_COLOR_TEXT_NORMAL, NULL);
c67d43408daa Update hardware cursor correctly.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24586
diff changeset
296 wmove(widget->window, 0, curpos);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
297
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
298 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
299 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
300
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
301 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
302 gnt_entry_size_request(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
303 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
304 if (!GNT_WIDGET_IS_FLAG_SET(widget, GNT_WIDGET_MAPPED))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
305 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
306 widget->priv.height = 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
307 widget->priv.width = 20;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
308 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
309 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
310
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
311 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
312 gnt_entry_map(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
313 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
314 if (widget->priv.width == 0 || widget->priv.height == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
315 gnt_widget_size_request(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
316 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
317 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
318
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
319 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
320 entry_redraw(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
321 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
322 gnt_entry_draw(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
323 gnt_widget_queue_update(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
324 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
325
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
326 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
327 entry_text_changed(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
328 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
329 g_signal_emit(entry, signals[SIG_TEXT_CHANGED], 0);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
330 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
331
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
332 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
333 move_back(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
334 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
335 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
336 if (entry->cursor <= entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
337 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
338 entry->cursor = g_utf8_find_prev_char(entry->start, entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
339 if (entry->cursor < entry->scroll)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
340 entry->scroll = entry->cursor;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
341 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
342 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
343 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
344 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
345
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
346 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
347 move_forward(GntBindable *bind, GList *list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
348 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
349 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
350 if (entry->cursor >= entry->end)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
351 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
352 entry->cursor = g_utf8_find_next_char(entry->cursor, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
353 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
354 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
355 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
356 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
357 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
358 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
359
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
360 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
361 backspace(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
362 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
363 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
364 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
365
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
366 if (entry->cursor <= entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
367 return TRUE;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
368
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
369 len = entry->cursor - g_utf8_find_prev_char(entry->start, entry->cursor);
24553
2675fda76ddf Do not alter the killring on delete-prev or delete-next (char) operations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24410
diff changeset
370 update_kill_ring(entry, ENTRY_JAIL, entry->cursor, -len);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
371 entry->cursor -= len;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
372
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
373 memmove(entry->cursor, entry->cursor + len, entry->end - entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
374 entry->end -= len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
375
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
376 if (entry->scroll > entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
377 entry->scroll = g_utf8_find_prev_char(entry->start, entry->scroll);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
378
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
379 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
380 if (entry->ddown)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
381 show_suggest_dropdown(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
382 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
383 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
384 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
385
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
386 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
387 delkey(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
388 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
389 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
390 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
391
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
392 if (entry->cursor >= entry->end)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
393 return FALSE;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
394
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
395 len = g_utf8_find_next_char(entry->cursor, NULL) - entry->cursor;
24553
2675fda76ddf Do not alter the killring on delete-prev or delete-next (char) operations.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24410
diff changeset
396 update_kill_ring(entry, ENTRY_JAIL, entry->cursor, len);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
397 memmove(entry->cursor, entry->cursor + len, entry->end - entry->cursor - len + 1);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
398 entry->end -= len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
399 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
400
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
401 if (entry->ddown)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
402 show_suggest_dropdown(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
403 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
404 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
405 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
406
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
407 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
408 move_start(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
409 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
410 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
411 entry->scroll = entry->cursor = entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
412 entry_redraw(GNT_WIDGET(entry));
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
413 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
414 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
415 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
416
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
417 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
418 move_end(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
419 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
420 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
421 entry->cursor = entry->end;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
422 /* This should be better than this */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
423 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= GNT_WIDGET(entry)->priv.width)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
424 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
425 entry_redraw(GNT_WIDGET(entry));
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
426 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
427 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
428 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
429
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
430 static gboolean
22434
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
431 history_next(GntBindable *bind, GList *null)
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
432 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
433 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
434 if (entry->histlength && entry->history->prev)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
435 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
436 entry->history = entry->history->prev;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
437 gnt_entry_set_text_internal(entry, entry->history->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
438 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
439 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
440
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
441 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
442 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
443 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
444 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
445 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
446
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
447 static gboolean
22434
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
448 history_prev(GntBindable *bind, GList *null)
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
449 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
450 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
451 if (entry->histlength && entry->history->next)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
452 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
453 if (entry->history->prev == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
454 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
455 /* Save the current contents */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
456 char *text = g_strdup(gnt_entry_get_text(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
457 g_free(entry->history->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
458 entry->history->data = text;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
459 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
460
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
461 entry->history = entry->history->next;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
462 gnt_entry_set_text_internal(entry, entry->history->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
463 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
464 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
465
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
466 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
467 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
468 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
469 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
470 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
471
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
472 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
473 clipboard_paste(GntBindable *bind, GList *n)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
474 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
475 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
476 gchar *i, *text, *a, *all;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
477 text = i = gnt_get_clipboard_string();
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
478 while (*i != '\0') {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
479 i = g_utf8_next_char(i);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
480 if (*i == '\r' || *i == '\n')
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
481 *i = ' ';
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
482 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
483 a = g_strndup(entry->start, entry->cursor - entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
484 all = g_strconcat(a, text, entry->cursor, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
485 gnt_entry_set_text_internal(entry, all);
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
486 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
487 g_free(a);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
488 g_free(text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
489 g_free(all);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
490 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
491 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
492
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
493 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
494 suggest_show(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
495 {
15959
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
496 GntEntry *entry = GNT_ENTRY(bind);
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
497 if (entry->ddown) {
16889
c31328dba5c2 Fix some ickyness in the tab-completion. Now, if there's only one suggest word, then the first tab will just complete the suggestion. If there's only one suggest word, and it's already completed, then tab will take focus to the next widget. If there is a dropdown, then you can select a suggest word by pressing tabs to move to it, then either space or enter to accept it.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15959
diff changeset
498 gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-down");
15959
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
499 return TRUE;
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
500 }
efbced3f38ac Update the tab completion a little bit. The binding for suggest-show will perform suggest-next if the suggest-dropdown is already showing. If there's just one suggestion, then complete with that suggestion.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 15817
diff changeset
501 return show_suggest_dropdown(entry);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
502 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
503
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
504 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
505 suggest_next(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
506 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
507 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
508 if (entry->ddown) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
509 gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-down", NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
510 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
511 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
512 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
513 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
514
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
515 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
516 suggest_prev(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
517 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
518 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
519 if (entry->ddown) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
520 gnt_bindable_perform_action_named(GNT_BINDABLE(entry->ddown), "move-up", NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
521 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
522 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
523 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
524 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
525
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
526 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
527 del_to_home(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
528 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
529 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
530 if (entry->cursor <= entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
531 return TRUE;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
532 update_kill_ring(entry, ENTRY_DEL_BOL, entry->start, entry->cursor - entry->start);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
533 memmove(entry->start, entry->cursor, entry->end - entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
534 entry->end -= (entry->cursor - entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
535 entry->cursor = entry->scroll = entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
536 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
537 entry_redraw(GNT_WIDGET(bind));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
538 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
539 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
540 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
541
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
542 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
543 del_to_end(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
544 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
545 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
546 if (entry->end <= entry->cursor)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
547 return TRUE;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
548 update_kill_ring(entry, ENTRY_DEL_EOL, entry->cursor, entry->end - entry->cursor);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
549 entry->end = entry->cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
550 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
551 entry_redraw(GNT_WIDGET(bind));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
552 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
553 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
554 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
555
23174
f3087936d594 Treat digits and alphabets as the same class of characters when looking
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22900
diff changeset
556 #define SAME(a,b) ((g_unichar_isalnum(a) && g_unichar_isalnum(b)) || \
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
557 (g_unichar_isspace(a) && g_unichar_isspace(b)) || \
23174
f3087936d594 Treat digits and alphabets as the same class of characters when looking
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22900
diff changeset
558 (g_unichar_iswide(a) && g_unichar_iswide(b)) || \
f3087936d594 Treat digits and alphabets as the same class of characters when looking
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22900
diff changeset
559 (g_unichar_ispunct(a) && g_unichar_ispunct(b)))
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
560
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
561 static const char *
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
562 begin_word(const char *text, const char *begin)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
563 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
564 gunichar ch = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
565 while (text > begin && (!*text || g_unichar_isspace(g_utf8_get_char(text))))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
566 text = g_utf8_find_prev_char(begin, text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
567 ch = g_utf8_get_char(text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
568 while ((text = g_utf8_find_prev_char(begin, text)) >= begin) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
569 gunichar cur = g_utf8_get_char(text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
570 if (!SAME(ch, cur))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
571 break;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
572 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
573
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
574 return (text ? g_utf8_find_next_char(text, NULL) : begin);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
575 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
576
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
577 static const char *
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
578 next_begin_word(const char *text, const char *end)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
579 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
580 gunichar ch = 0;
21680
65f2a29617a2 Fix cursor-next-word behaviour, noticed by jtb.
Richard Nelson <wabz@pidgin.im>
parents: 21280
diff changeset
581
65f2a29617a2 Fix cursor-next-word behaviour, noticed by jtb.
Richard Nelson <wabz@pidgin.im>
parents: 21280
diff changeset
582 while (text && text < end && g_unichar_isspace(g_utf8_get_char(text)))
65f2a29617a2 Fix cursor-next-word behaviour, noticed by jtb.
Richard Nelson <wabz@pidgin.im>
parents: 21280
diff changeset
583 text = g_utf8_find_next_char(text, end);
65f2a29617a2 Fix cursor-next-word behaviour, noticed by jtb.
Richard Nelson <wabz@pidgin.im>
parents: 21280
diff changeset
584
23294
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
585 if (text) {
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
586 ch = g_utf8_get_char(text);
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
587 while ((text = g_utf8_find_next_char(text, end)) != NULL && text <= end) {
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
588 gunichar cur = g_utf8_get_char(text);
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
589 if (!SAME(ch, cur))
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
590 break;
47492dabcb4a Fixes a crash when next_begin_word is called on trailing spaces at the
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 23174
diff changeset
591 }
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
592 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
593 return (text ? text : end);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
594 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
595
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
596 #undef SAME
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
597 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
598 move_back_word(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
599 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
600 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
601 const char *iter = g_utf8_find_prev_char(entry->start, entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
602
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
603 if (iter < entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
604 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
605 iter = begin_word(iter, entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
606 entry->cursor = (char*)iter;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
607 if (entry->cursor < entry->scroll)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
608 entry->scroll = entry->cursor;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
609 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
610 entry_redraw(GNT_WIDGET(bind));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
611 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
612 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
613
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
614 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
615 del_prev_word(GntBindable *bind, GList *null)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
616 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
617 GntWidget *widget = GNT_WIDGET(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
618 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
619 char *iter = g_utf8_find_prev_char(entry->start, entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
620 int count;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
621
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
622 if (iter < entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
623 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
624 iter = (char*)begin_word(iter, entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
625 count = entry->cursor - iter;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
626 update_kill_ring(entry, ENTRY_DEL_BWD_WORD, iter, count);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
627 memmove(iter, entry->cursor, entry->end - entry->cursor);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
628 entry->end -= count;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
629 entry->cursor = iter;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
630 if (entry->cursor <= entry->scroll) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
631 entry->scroll = entry->cursor - widget->priv.width + 2;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
632 if (entry->scroll < entry->start)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
633 entry->scroll = entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
634 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
635 memset(entry->end, '\0', entry->buffer - (entry->end - entry->start));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
636 entry_redraw(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
637 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
638
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
639 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
640 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
641
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
642 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
643 move_forward_word(GntBindable *bind, GList *list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
644 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
645 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
646 GntWidget *widget = GNT_WIDGET(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
647 entry->cursor = (char *)next_begin_word(entry->cursor, entry->end);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
648 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width) {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
649 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
650 }
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
651 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
652 entry_redraw(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
653 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
654 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
655
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
656 static gboolean
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
657 delete_forward_word(GntBindable *bind, GList *list)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
658 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
659 GntEntry *entry = GNT_ENTRY(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
660 GntWidget *widget = GNT_WIDGET(bind);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
661 char *iter = (char *)next_begin_word(entry->cursor, entry->end);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
662 int len = entry->end - iter + 1;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
663 if (len <= 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
664 return TRUE;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
665 update_kill_ring(entry, ENTRY_DEL_FWD_WORD, entry->cursor, iter - entry->cursor);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
666 memmove(entry->cursor, iter, len);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
667 len = iter - entry->cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
668 entry->end -= len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
669 memset(entry->end, '\0', len);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
670 entry_redraw(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
671 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
672 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
673 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
674
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
675 static gboolean
21262
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
676 transpose_chars(GntBindable *bind, GList *null)
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
677 {
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
678 GntEntry *entry = GNT_ENTRY(bind);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
679 char *current, *prev;
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
680 char hold[8]; /* that's right */
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
681
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
682 if (entry->cursor <= entry->start)
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
683 return FALSE;
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
684
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
685 if (!*entry->cursor)
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
686 entry->cursor = g_utf8_find_prev_char(entry->start, entry->cursor);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
687
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
688 current = entry->cursor;
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
689 prev = g_utf8_find_prev_char(entry->start, entry->cursor);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
690 move_forward(bind, null);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
691
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
692 /* Let's do this dance! */
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
693 memcpy(hold, prev, current - prev);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
694 memmove(prev, current, entry->cursor - current);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
695 memcpy(prev + (entry->cursor - current), hold, current - prev);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
696
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
697 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
21262
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
698 entry_redraw(GNT_WIDGET(entry));
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
699 entry_text_changed(entry);
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
700 return TRUE;
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
701 }
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
702
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
703 static gboolean
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
704 entry_yank(GntBindable *bind, GList *null)
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
705 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
706 GntEntry *entry = GNT_ENTRY(bind);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
707 gnt_entry_key_pressed(GNT_WIDGET(entry), entry->killring->buffer->str);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
708 return TRUE;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
709 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
710
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
711 static gboolean
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
712 gnt_entry_key_pressed(GntWidget *widget, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
713 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
714 GntEntry *entry = GNT_ENTRY(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
715
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
716 if (text[0] == 27)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
717 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
718 if (text[1] == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
719 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
720 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
721 return TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
722 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
723
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
724 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
725 }
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
726
22289
0ba0f2804299 '\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22007
diff changeset
727 if ((text[0] == '\r' || text[0] == ' ' || text[0] == '\n') && entry->ddown)
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
728 {
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
729 char *text = g_strdup(gnt_tree_get_selection_data(GNT_TREE(entry->ddown)));
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
730 destroy_suggest(entry);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
731 complete_suggest(entry, text);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
732 g_free(text);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
733 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
734 entry_text_changed(entry);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
735 return TRUE;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
736 }
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
737
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
738 if (!iscntrl(text[0]))
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
739 {
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
740 const char *str, *next;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
741
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
742 for (str = text; *str; str = next)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
743 {
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
744 int len;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
745 next = g_utf8_find_next_char(str, NULL);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
746 len = next - str;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
747
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
748 /* Valid input? */
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
749 /* XXX: Is it necessary to use _unichar_ variants here? */
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
750 if (ispunct(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_PUNCT))
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
751 continue;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
752 if (isspace(*str) && (entry->flag & GNT_ENTRY_FLAG_NO_SPACE))
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
753 continue;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
754 if (isalpha(*str) && !(entry->flag & GNT_ENTRY_FLAG_ALPHA))
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
755 continue;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
756 if (isdigit(*str) && !(entry->flag & GNT_ENTRY_FLAG_INT))
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
757 continue;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
758
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
759 /* Reached the max? */
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
760 if (entry->max && g_utf8_pointer_to_offset(entry->start, entry->end) >= entry->max)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
761 continue;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
762
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
763 if (entry->end + len - entry->start >= entry->buffer)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
764 {
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
765 /* This will cause the buffer to grow */
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
766 char *tmp = g_strdup(entry->start);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
767 gnt_entry_set_text_internal(entry, tmp);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
768 g_free(tmp);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
769 }
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
770
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
771 memmove(entry->cursor + len, entry->cursor, entry->end - entry->cursor + 1);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
772 entry->end += len;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
773
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
774 while (str < next)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
775 {
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
776 if (*str == '\r' || *str == '\n')
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
777 *entry->cursor = ' ';
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
778 else
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
779 *entry->cursor = *str;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
780 entry->cursor++;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
781 str++;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
782 }
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
783
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
784 while (gnt_util_onscreen_width(entry->scroll, entry->cursor) >= widget->priv.width)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
785 entry->scroll = g_utf8_find_next_char(entry->scroll, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
786
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
787 if (entry->ddown)
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
788 show_suggest_dropdown(entry);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
789 }
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
790 update_kill_ring(entry, ENTRY_JAIL, NULL, 0);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
791 entry_redraw(widget);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
792 entry_text_changed(entry);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
793 return TRUE;
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
794 }
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
795
22289
0ba0f2804299 '\n' (ctrl-j) should behave similar to '\r' (ctrl-m). Fixes #4833.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22007
diff changeset
796 if (text[0] == '\r' || text[0] == '\n') {
21280
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
797 gnt_widget_activate(widget);
cfbff4a9b2b6 Hitting Return in the entry will trigger the 'activate' signal.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21266
diff changeset
798 return TRUE;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
799 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
800
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
801 return FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
802 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
803
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
804 static void
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
805 jail_killring(GntEntryKillRing *kr)
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
806 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
807 g_string_free(kr->buffer, TRUE);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
808 g_free(kr);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
809 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
810
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
811 static void
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
812 gnt_entry_destroy(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
813 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
814 GntEntry *entry = GNT_ENTRY(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
815 g_free(entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
816
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
817 if (entry->history)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
818 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
819 entry->history = g_list_first(entry->history);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
820 g_list_foreach(entry->history, (GFunc)g_free, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
821 g_list_free(entry->history);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
822 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
823
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
824 if (entry->suggests)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
825 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
826 g_list_foreach(entry->suggests, (GFunc)g_free, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
827 g_list_free(entry->suggests);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
828 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
829
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
830 if (entry->ddown)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
831 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
832 gnt_widget_destroy(entry->ddown->parent);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
833 }
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
834
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
835 jail_killring(entry->killring);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
836 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
837
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
838 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
839 gnt_entry_lost_focus(GntWidget *widget)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
840 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
841 GntEntry *entry = GNT_ENTRY(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
842 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
843 entry_redraw(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
844 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
845
22900
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
846 static gboolean
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
847 gnt_entry_clicked(GntWidget *widget, GntMouseEvent event, int x, int y)
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
848 {
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
849 if (event == GNT_MIDDLE_MOUSE_DOWN) {
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
850 clipboard_paste(GNT_BINDABLE(widget), NULL);
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
851 return TRUE;
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
852 }
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
853 return FALSE;
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
854
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
855 }
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
856
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
857 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
858 gnt_entry_class_init(GntEntryClass *klass)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
859 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
860 GntBindableClass *bindable = GNT_BINDABLE_CLASS(klass);
24586
e1c3a984e47a Binding fixes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24553
diff changeset
861 char s[3] = {'\033', erasechar(), 0};
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
862
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
863 parent_class = GNT_WIDGET_CLASS(klass);
22900
c9aebd4762a8 Middle click pastes the internal clipboard
Richard Nelson <wabz@pidgin.im>
parents: 22698
diff changeset
864 parent_class->clicked = gnt_entry_clicked;
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
865 parent_class->destroy = gnt_entry_destroy;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
866 parent_class->draw = gnt_entry_draw;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
867 parent_class->map = gnt_entry_map;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
868 parent_class->size_request = gnt_entry_size_request;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
869 parent_class->key_pressed = gnt_entry_key_pressed;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
870 parent_class->lost_focus = gnt_entry_lost_focus;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
871
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
872 signals[SIG_TEXT_CHANGED] =
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
873 g_signal_new("text_changed",
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
874 G_TYPE_FROM_CLASS(klass),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
875 G_SIGNAL_RUN_LAST,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
876 G_STRUCT_OFFSET(GntEntryClass, text_changed),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
877 NULL, NULL,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
878 g_cclosure_marshal_VOID__VOID,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
879 G_TYPE_NONE, 0);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
880
18382
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
881 signals[SIG_COMPLETION] =
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
882 g_signal_new("completion",
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
883 G_TYPE_FROM_CLASS(klass),
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
884 G_SIGNAL_RUN_LAST,
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
885 0, NULL, NULL,
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
886 gnt_closure_marshal_VOID__POINTER_POINTER,
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
887 G_TYPE_NONE, 2, G_TYPE_POINTER, G_TYPE_POINTER);
aa60f5a89286 A 'completion' signal to emit whenever user accepts a completion suggest.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 18346
diff changeset
888
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
889 gnt_bindable_class_register_action(bindable, "cursor-home", move_start,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
890 GNT_KEY_CTRL_A, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
891 gnt_bindable_register_binding(bindable, "cursor-home", GNT_KEY_HOME, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
892 gnt_bindable_class_register_action(bindable, "cursor-end", move_end,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
893 GNT_KEY_CTRL_E, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
894 gnt_bindable_register_binding(bindable, "cursor-end", GNT_KEY_END, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
895 gnt_bindable_class_register_action(bindable, "delete-prev", backspace,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
896 GNT_KEY_BACKSPACE, NULL);
24586
e1c3a984e47a Binding fixes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24553
diff changeset
897 gnt_bindable_register_binding(bindable, "delete-prev", s + 1, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
898 gnt_bindable_register_binding(bindable, "delete-prev", GNT_KEY_CTRL_H, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
899 gnt_bindable_class_register_action(bindable, "delete-next", delkey,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
900 GNT_KEY_DEL, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
901 gnt_bindable_register_binding(bindable, "delete-next", GNT_KEY_CTRL_D, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
902 gnt_bindable_class_register_action(bindable, "delete-start", del_to_home,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
903 GNT_KEY_CTRL_U, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
904 gnt_bindable_class_register_action(bindable, "delete-end", del_to_end,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
905 GNT_KEY_CTRL_K, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
906 gnt_bindable_class_register_action(bindable, "delete-prev-word", del_prev_word,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
907 GNT_KEY_CTRL_W, NULL);
24586
e1c3a984e47a Binding fixes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 24553
diff changeset
908 gnt_bindable_register_binding(bindable, "delete-prev-word", s, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
909 gnt_bindable_class_register_action(bindable, "cursor-prev-word", move_back_word,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
910 "\033" "b", NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
911 gnt_bindable_class_register_action(bindable, "cursor-prev", move_back,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
912 GNT_KEY_LEFT, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
913 gnt_bindable_register_binding(bindable, "cursor-prev", GNT_KEY_CTRL_B, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
914 gnt_bindable_class_register_action(bindable, "cursor-next", move_forward,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
915 GNT_KEY_RIGHT, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
916 gnt_bindable_register_binding(bindable, "cursor-next", GNT_KEY_CTRL_F, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
917 gnt_bindable_class_register_action(bindable, "cursor-next-word", move_forward_word,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
918 "\033" "f", NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
919 gnt_bindable_class_register_action(bindable, "delete-next-word", delete_forward_word,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
920 "\033" "d", NULL);
21262
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
921 gnt_bindable_class_register_action(bindable, "transpose-chars", transpose_chars,
aee0d7fef769 transpose-chars action for the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21250
diff changeset
922 GNT_KEY_CTRL_T, NULL);
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
923 gnt_bindable_class_register_action(bindable, "yank", entry_yank,
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
924 GNT_KEY_CTRL_Y, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
925 gnt_bindable_class_register_action(bindable, "suggest-show", suggest_show,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
926 "\t", NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
927 gnt_bindable_class_register_action(bindable, "suggest-next", suggest_next,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
928 GNT_KEY_DOWN, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
929 gnt_bindable_class_register_action(bindable, "suggest-prev", suggest_prev,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
930 GNT_KEY_UP, NULL);
22434
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
931 gnt_bindable_class_register_action(bindable, "history-next", history_next,
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
932 GNT_KEY_CTRL_DOWN, NULL);
22434
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
933 gnt_bindable_class_register_action(bindable, "history-prev", history_prev,
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
934 GNT_KEY_CTRL_UP, NULL);
22434
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
935 gnt_bindable_register_binding(bindable, "history-prev", GNT_KEY_CTRL_P, NULL);
77737a3526f1 The names history-next and history-prev were backwards! Make them right, and add c-n/c-p bindings as the default bindings. Thanks to shofixti for reporting the bug. Fixes #4593.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 22289
diff changeset
936 gnt_bindable_register_binding(bindable, "history-next", GNT_KEY_CTRL_N, NULL);
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
937 gnt_bindable_class_register_action(bindable, "clipboard-paste", clipboard_paste,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
938 GNT_KEY_CTRL_V, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
939
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
940 gnt_style_read_actions(G_OBJECT_CLASS_TYPE(klass), GNT_BINDABLE_CLASS(klass));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
941 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
942 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
943
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
944 static GntEntryKillRing *
22007
c38d72677c8a Probe for -Wstrict-prototypes to get some more warnings. I then cleaned up
Richard Laager <rlaager@wiktel.com>
parents: 21699
diff changeset
945 new_killring(void)
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
946 {
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
947 GntEntryKillRing *kr = g_new0(GntEntryKillRing, 1);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
948 kr->buffer = g_string_new(NULL);
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
949 return kr;
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
950 }
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
951
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
952 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
953 gnt_entry_init(GTypeInstance *instance, gpointer class)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
954 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
955 GntWidget *widget = GNT_WIDGET(instance);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
956 GntEntry *entry = GNT_ENTRY(instance);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
957
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
958 entry->flag = GNT_ENTRY_FLAG_ALL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
959 entry->max = 0;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
960
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
961 entry->histlength = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
962 entry->history = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
963
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
964 entry->word = TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
965 entry->always = FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
966 entry->suggests = NULL;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
967 entry->killring = new_killring();
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
968
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
969 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(entry),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
970 GNT_WIDGET_NO_BORDER | GNT_WIDGET_NO_SHADOW | GNT_WIDGET_CAN_TAKE_FOCUS);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
971 GNT_WIDGET_SET_FLAGS(GNT_WIDGET(entry), GNT_WIDGET_GROW_X);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
972
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
973 widget->priv.minw = 3;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
974 widget->priv.minh = 1;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
975
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
976 GNTDEBUG;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
977 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
978
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
979 /******************************************************************************
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
980 * GntEntry API
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
981 *****************************************************************************/
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
982 GType
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
983 gnt_entry_get_gtype(void)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
984 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
985 static GType type = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
986
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
987 if(type == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
988 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
989 static const GTypeInfo info = {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
990 sizeof(GntEntryClass),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
991 NULL, /* base_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
992 NULL, /* base_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
993 (GClassInitFunc)gnt_entry_class_init,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
994 NULL, /* class_finalize */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
995 NULL, /* class_data */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
996 sizeof(GntEntry),
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
997 0, /* n_preallocs */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
998 gnt_entry_init, /* instance_init */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
999 NULL /* value_table */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1000 };
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1001
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1002 type = g_type_register_static(GNT_TYPE_WIDGET,
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1003 "GntEntry",
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1004 &info, 0);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1005 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1006
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1007 return type;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1008 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1009
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1010 GntWidget *gnt_entry_new(const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1011 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1012 GntWidget *widget = g_object_new(GNT_TYPE_ENTRY, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1013 GntEntry *entry = GNT_ENTRY(widget);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1014
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1015 gnt_entry_set_text_internal(entry, text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1016
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1017 return widget;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1018 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1019
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1020 static void
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1021 gnt_entry_set_text_internal(GntEntry *entry, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1022 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1023 int len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1024 int scroll, cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1025
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1026 g_free(entry->start);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1027
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1028 if (text && text[0])
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1029 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1030 len = strlen(text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1031 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1032 else
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1033 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1034 len = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1035 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1036
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1037 entry->buffer = len + 128;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1038
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1039 scroll = entry->scroll - entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1040 cursor = entry->end - entry->cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1041
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1042 entry->start = g_new0(char, entry->buffer);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1043 if (text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1044 snprintf(entry->start, len + 1, "%s", text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1045 entry->end = entry->start + len;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1046
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1047 entry->scroll = entry->start + scroll;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1048 entry->cursor = entry->end - cursor;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1049
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1050 if (GNT_WIDGET_IS_FLAG_SET(GNT_WIDGET(entry), GNT_WIDGET_MAPPED))
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1051 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1052 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1053
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1054 void gnt_entry_set_text(GntEntry *entry, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1055 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1056 gboolean changed = TRUE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1057 if (text == NULL && entry->start == NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1058 changed = FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1059 if (text && entry->start && g_utf8_collate(text, entry->start) == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1060 changed = FALSE;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1061 gnt_entry_set_text_internal(entry, text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1062 if (changed)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1063 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1064 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1065
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1066 void gnt_entry_set_max(GntEntry *entry, int max)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1067 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1068 entry->max = max;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1069 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1070
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1071 void gnt_entry_set_flag(GntEntry *entry, GntEntryFlag flag)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1072 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1073 entry->flag = flag;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1074 /* XXX: Check the existing string to make sure the flags are respected? */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1075 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1076
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1077 const char *gnt_entry_get_text(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1078 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1079 return entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1080 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1081
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1082 void gnt_entry_clear(GntEntry *entry)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1083 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1084 gnt_entry_set_text_internal(entry, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1085 entry->scroll = entry->cursor = entry->end = entry->start;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1086 entry_redraw(GNT_WIDGET(entry));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1087 destroy_suggest(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1088 entry_text_changed(entry);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1089 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1090
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1091 void gnt_entry_set_masked(GntEntry *entry, gboolean set)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1092 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1093 entry->masked = set;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1094 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1095
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1096 void gnt_entry_add_to_history(GntEntry *entry, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1097 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1098 g_return_if_fail(entry->history != NULL); /* Need to set_history_length first */
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1099
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1100 if (g_list_length(entry->history) >= entry->histlength)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1101 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1102
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1103 entry->history = g_list_first(entry->history);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1104 g_free(entry->history->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1105 entry->history->data = g_strdup(text);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1106 entry->history = g_list_prepend(entry->history, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1107 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1108
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1109 void gnt_entry_set_history_length(GntEntry *entry, int num)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1110 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1111 if (num == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1112 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1113 entry->histlength = num;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1114 if (entry->history)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1115 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1116 entry->history = g_list_first(entry->history);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1117 g_list_foreach(entry->history, (GFunc)g_free, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1118 g_list_free(entry->history);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1119 entry->history = NULL;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1120 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1121 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1122 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1123
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1124 if (entry->histlength == 0)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1125 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1126 entry->histlength = num;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1127 entry->history = g_list_append(NULL, NULL);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1128 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1129 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1130
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1131 if (num > 0 && num < entry->histlength)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1132 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1133 GList *first, *iter;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1134 int index = 0;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1135 for (first = entry->history, index = 0; first->prev; first = first->prev, index++);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1136 while ((iter = g_list_nth(first, num)) != NULL)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1137 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1138 g_free(iter->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1139 first = g_list_delete_link(first, iter);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1140 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1141 entry->histlength = num;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1142 if (index >= num)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1143 entry->history = g_list_last(first);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1144 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1145 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1146
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1147 entry->histlength = num;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1148 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1149
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1150 void gnt_entry_set_word_suggest(GntEntry *entry, gboolean word)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1151 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1152 entry->word = word;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1153 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1154
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1155 void gnt_entry_set_always_suggest(GntEntry *entry, gboolean always)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1156 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1157 entry->always = always;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1158 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1159
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1160 void gnt_entry_add_suggest(GntEntry *entry, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1161 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1162 GList *find;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1163
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1164 if (!text || !*text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1165 return;
21266
1f59065c606a Add 'yank' action in the entry boxes.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents: 21262
diff changeset
1166
15817
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1167 find = g_list_find_custom(entry->suggests, text, (GCompareFunc)g_utf8_collate);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1168 if (find)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1169 return;
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1170 entry->suggests = g_list_append(entry->suggests, g_strdup(text));
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1171 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1172
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1173 void gnt_entry_remove_suggest(GntEntry *entry, const char *text)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1174 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1175 GList *find = g_list_find_custom(entry->suggests, text, (GCompareFunc)g_utf8_collate);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1176 if (find)
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1177 {
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1178 g_free(find->data);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1179 entry->suggests = g_list_delete_link(entry->suggests, find);
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1180 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1181 }
0e3a8505ebbe renamed gaim-text to finch
Sean Egan <seanegan@gmail.com>
parents:
diff changeset
1182