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