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