# This patch file was generated by NetBeans IDE # Following Index: paths are relative to: /Users/catlan/Projekte/netbeans/collab/chat/src/org/netbeans/modules/collab/channel/chat # This patch can be applied using context Tools: Patch action on respective folder. # It uses platform neutral UTF-8 endcoding and \n newlines. # Above lines and this line are ignored by the patching process. Index: ChatComponent.java *** /Users/catlan/Projekte/netbeans/collab/chat/src/org/netbeans/modules/collab/channel/chat/ChatComponent.java Base (1.6) --- /Users/catlan/Projekte/netbeans/collab/chat/src/org/netbeans/modules/collab/channel/chat/ChatComponent.java Locally Modified (Based On 1.6) *************** *** 140,141 **** --- 140,146 ---- private JPopupMenu newMenu; private JButton smileyButton; private JToggleButton chatFocusButton; + private Map nickCompletion/**/ = new HashMap/**/(); /** * *************** *** 152,153 **** --- 153,166 ---- initialize(); initTypingTimer(); + CollabPrincipal[] participants = channel.getConversation().getParticipants(); + for (int i = 0; i < participants.length; i++) { + nickCompletion.put( + participants[i].getDisplayName().toLowerCase(), + participants[i].getDisplayName() + ); + } + // Listen to conversation changes conversationListener = new ConversationChangeListener(); channel.addPropertyChangeListener(conversationListener); *************** *** 275,276 **** --- 284,293 ---- KeyStroke snd = KeyStroke.getKeyStroke("control ENTER"); // NOI18N inputPane.getInputMap().put(snd, "sendAction"); // NOI18N inputPane.getActionMap().put("sendAction", new SendButtonActionListener()); + + KeyStroke completionKS = KeyStroke.getKeyStroke("control SPACE"); // NOI18N + inputPane.getInputMap().put(completionKS, "nickCompletionAction"); // NOI18N + inputPane.getActionMap().put("nickCompletionAction", new NickCompletionActionListener()); // registers itself InputPaneDocumentListener lst = new InputPaneDocumentListener(); *************** *** 813,819 **** previouslySelectedContentType = null; } } ! private String replaceAll(String origStr, String targetStr, String replacedStr) { StringBuffer sb = new StringBuffer(origStr); int idx; --- 826,873 ---- previouslySelectedContentType = null; } } ! ! protected void nickCompletion() { ! ChatInputPane pane = getInputPane(); ! int cp = pane.getCaretPosition(); ! String text = pane.getText(); ! ! if (text.length() <= 0) ! return; ! ! String textFromStartToCaretPosition = text.substring(0, cp); ! int lastWordStartPostion = textFromStartToCaretPosition.lastIndexOf(" ") + 1; ! ! String searchItem; ! searchItem = textFromStartToCaretPosition.substring(lastWordStartPostion).toLowerCase(); ! ! Iterator keySet = nickCompletion.keySet().iterator(); ! for (;keySet.hasNext();) { ! String value = (String)keySet.next(); ! if (value.startsWith(searchItem)) { ! StringBuffer sb = new StringBuffer(); ! int newCP = -1; ! if (lastWordStartPostion != 0) { ! sb.append(textFromStartToCaretPosition.substring(0, lastWordStartPostion)); ! sb.append(nickCompletion.get(value)).append(" "); ! newCP = sb.length(); ! } else { ! sb.append(nickCompletion.get(value)).append(", "); ! } ! ! if (cp != text.length()) { ! sb.append( text.substring(cp, text.length()) ); ! } ! ! pane.setText(sb.toString()); ! if(newCP != -1) ! pane.setCaretPosition(newCP); ! ! break; ! } ! } ! } ! private String replaceAll(String origStr, String targetStr, String replacedStr) { StringBuffer sb = new StringBuffer(origStr); int idx; *************** *** 1354,1355 **** --- 1408,1420 ---- // TODO: Do something appropriate here Debug.errorManager.notify(e); } + + if (joined) { + nickCompletion.put(principal.getDisplayName().toLowerCase(), + principal.getDisplayName()); + } else { + nickCompletion.remove(principal.getDisplayName().toLowerCase()); + } } else if (event.getPropertyName().equals(Conversation.USER_TYPING_ON)) { CollabPrincipal principal = (CollabPrincipal) event.getNewValue(); updateStatusMessage(principal, true); *************** *** 1506,1507 **** --- 1567,1590 ---- //////////////////////////////////////////////////////////////////////////// /** + * + * + */ + protected class NickCompletionActionListener extends AbstractAction implements ActionListener { + /** + * + * + */ + public void actionPerformed(ActionEvent event) { + nickCompletion(); + } + } + + //////////////////////////////////////////////////////////////////////////// + // Inner class + //////////////////////////////////////////////////////////////////////////// + + /** * HACK: This class implements a proxy pattern in order to allow us to * "sniff" pasted content. Unfortunately, because TransferHandler has * protected methods, it requires us to use AccessibleObject to invoke