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