diff options
author | elektrahesse | 2010-09-13 04:59:36 +0200 |
---|---|---|
committer | elektrahesse | 2010-09-13 04:59:36 +0200 |
commit | 37aa6de0889eb864bbeba61341304b120a184eb0 (patch) | |
tree | 23fc36aabee5741a58ae94d8e6e22138214e89e5 /linden | |
parent | Fixed the regexp to match commas before the name (diff) | |
download | meta-impy-37aa6de0889eb864bbeba61341304b120a184eb0.zip meta-impy-37aa6de0889eb864bbeba61341304b120a184eb0.tar.gz meta-impy-37aa6de0889eb864bbeba61341304b120a184eb0.tar.bz2 meta-impy-37aa6de0889eb864bbeba61341304b120a184eb0.tar.xz |
Initial support for names autocompletion in chat using ctrl-esc
Diffstat (limited to 'linden')
-rw-r--r-- | linden/indra/newview/llchatbar.cpp | 81 |
1 files changed, 76 insertions, 5 deletions
diff --git a/linden/indra/newview/llchatbar.cpp b/linden/indra/newview/llchatbar.cpp index dc67448..88ef2b5 100644 --- a/linden/indra/newview/llchatbar.cpp +++ b/linden/indra/newview/llchatbar.cpp | |||
@@ -71,6 +71,8 @@ | |||
71 | 71 | ||
72 | #include "chatbar_as_cmdline.h" | 72 | #include "chatbar_as_cmdline.h" |
73 | 73 | ||
74 | #include "boost/regex.hpp" | ||
75 | |||
74 | // | 76 | // |
75 | // Globals | 77 | // Globals |
76 | // | 78 | // |
@@ -199,12 +201,83 @@ BOOL LLChatBar::handleKeyHere( KEY key, MASK mask ) | |||
199 | } | 201 | } |
200 | } | 202 | } |
201 | // only do this in main chatbar | 203 | // only do this in main chatbar |
202 | else if ( KEY_ESCAPE == key && gChatBar == this) | 204 | else if (KEY_ESCAPE == key && mask == MASK_NONE && gChatBar == this) |
203 | { | 205 | { |
204 | stopChat(); | 206 | stopChat(); |
205 | |||
206 | handled = TRUE; | 207 | handled = TRUE; |
207 | } | 208 | } |
209 | else if (key == KEY_ESCAPE && mask == MASK_CONTROL && gChatBar == this) | ||
210 | { | ||
211 | if (mInputEditor) | ||
212 | { | ||
213 | std::vector<LLUUID> avatar_ids; | ||
214 | std::vector<LLVector3d> positions; | ||
215 | LLWorld::getInstance()->getAvatars(&avatar_ids, &positions); | ||
216 | |||
217 | if (!avatar_ids.empty()) | ||
218 | { | ||
219 | std::string txt(mInputEditor->getText()); | ||
220 | |||
221 | std::string to_match(txt); | ||
222 | std::string left_part = ""; | ||
223 | std::string right_part = ""; | ||
224 | S32 cursorPos = mInputEditor->getCursor(); | ||
225 | |||
226 | if (cursorPos < txt.length()) | ||
227 | { | ||
228 | right_part = txt.substr(cursorPos); | ||
229 | left_part = txt.substr(0, cursorPos); | ||
230 | to_match = std::string(left_part); | ||
231 | } | ||
232 | else | ||
233 | { | ||
234 | to_match = std::string(txt); | ||
235 | left_part = txt; | ||
236 | } | ||
237 | |||
238 | std::string pattern_s = "(^|.*[\\.\\?!:;,\\*\\(\\s]+)([a-z0-9]+)$"; | ||
239 | boost::match_results<std::string::const_iterator> what; | ||
240 | boost::regex expression(pattern_s, boost::regex::icase); | ||
241 | if (boost::regex_search(to_match, what, expression, boost::match_extra)) | ||
242 | { | ||
243 | to_match = what[2]; | ||
244 | if (to_match.length() < 3) | ||
245 | return handled; | ||
246 | } | ||
247 | else | ||
248 | return handled; | ||
249 | |||
250 | for (U32 i=0; i<avatar_ids.size(); i++) | ||
251 | { | ||
252 | if (avatar_ids[i] == gAgent.getID() || avatar_ids[i].isNull()) | ||
253 | continue; | ||
254 | /* | ||
255 | // Commented out for now... doesn't work above 1024 meters as usual | ||
256 | F32 dist = F32(dist_vec(positions[i], gAgent.getPositionGlobal())); | ||
257 | if (dist > CHAT_NORMAL_RADIUS) | ||
258 | continue; | ||
259 | */ | ||
260 | |||
261 | std::string agent_name = " "; | ||
262 | std::string agent_surname = " "; | ||
263 | |||
264 | if(!gCacheName->getName(avatar_ids[i], agent_name, agent_surname) && (agent_name == " " || agent_surname == " ")) | ||
265 | continue; | ||
266 | |||
267 | std::string test_name(agent_name); | ||
268 | std::transform(test_name.begin(), test_name.end(), test_name.begin(), tolower); | ||
269 | |||
270 | if (test_name.find(to_match) == 0) | ||
271 | { | ||
272 | std::string rest_of_match = agent_name.substr(to_match.length(), agent_name.length()); | ||
273 | mInputEditor->setText(left_part.substr(0, left_part.length() - to_match.length()) + agent_name + right_part); | ||
274 | mInputEditor->setSelection(cursorPos, cursorPos + rest_of_match.length()); | ||
275 | return TRUE; | ||
276 | } | ||
277 | } | ||
278 | } | ||
279 | } | ||
280 | } | ||
208 | 281 | ||
209 | return handled; | 282 | return handled; |
210 | } | 283 | } |
@@ -598,9 +671,7 @@ void LLChatBar::onInputEditorKeystroke( LLLineEditor* caller, void* userdata ) | |||
598 | KEY key = gKeyboard->currentKey(); | 671 | KEY key = gKeyboard->currentKey(); |
599 | 672 | ||
600 | // Ignore "special" keys, like backspace, arrows, etc. | 673 | // Ignore "special" keys, like backspace, arrows, etc. |
601 | if (length > 1 | 674 | if (length > 1 && raw_text[0] == '/' && key < KEY_SPECIAL) |
602 | && raw_text[0] == '/' | ||
603 | && key < KEY_SPECIAL) | ||
604 | { | 675 | { |
605 | // we're starting a gesture, attempt to autocomplete | 676 | // we're starting a gesture, attempt to autocomplete |
606 | 677 | ||