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