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