sysmodelmgr/com.symbian.smt.gui/src/com/symbian/smt/gui/editors/xmleditor/XMLDoubleClickStrategy.java
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/sysmodelmgr/com.symbian.smt.gui/src/com/symbian/smt/gui/editors/xmleditor/XMLDoubleClickStrategy.java Thu Mar 11 19:08:43 2010 +0200
@@ -0,0 +1,138 @@
+// Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
+// All rights reserved.
+// This component and the accompanying materials are made available
+// under the terms of "Eclipse Public License v1.0"
+// which accompanies this distribution, and is available
+// at the URL "http://www.eclipse.org/legal/epl-v10.html".
+//
+// Initial Contributors:
+// Nokia Corporation - initial contribution.
+//
+// Contributors:
+//
+// Description:
+//
+
+
+
+package com.symbian.smt.gui.editors.xmleditor;
+
+import org.eclipse.jface.text.BadLocationException;
+import org.eclipse.jface.text.IDocument;
+import org.eclipse.jface.text.ITextDoubleClickStrategy;
+import org.eclipse.jface.text.ITextViewer;
+
+/**
+ * @author barbararosi-schwartz
+ *
+ */
+public class XMLDoubleClickStrategy implements ITextDoubleClickStrategy {
+ protected ITextViewer fText;
+
+ public void doubleClicked(ITextViewer part) {
+ int pos = part.getSelectedRange().x;
+
+ if (pos < 0)
+ return;
+
+ fText = part;
+
+ if (!selectComment(pos)) {
+ selectWord(pos);
+ }
+ }
+
+ protected boolean selectComment(int caretPos) {
+ IDocument doc = fText.getDocument();
+ int startPos, endPos;
+
+ try {
+ int pos = caretPos;
+ char c = ' ';
+
+ while (pos >= 0) {
+ c = doc.getChar(pos);
+ if (c == '\\') {
+ pos -= 2;
+ continue;
+ }
+ if (c == Character.LINE_SEPARATOR || c == '\"')
+ break;
+ --pos;
+ }
+
+ if (c != '\"')
+ return false;
+
+ startPos = pos;
+
+ pos = caretPos;
+ int length = doc.getLength();
+ c = ' ';
+
+ while (pos < length) {
+ c = doc.getChar(pos);
+ if (c == Character.LINE_SEPARATOR || c == '\"')
+ break;
+ ++pos;
+ }
+ if (c != '\"')
+ return false;
+
+ endPos = pos;
+
+ int offset = startPos + 1;
+ int len = endPos - offset;
+ fText.setSelectedRange(offset, len);
+ return true;
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+
+ private void selectRange(int startPos, int stopPos) {
+ int offset = startPos + 1;
+ int length = stopPos - offset;
+ fText.setSelectedRange(offset, length);
+ }
+
+ protected boolean selectWord(int caretPos) {
+
+ IDocument doc = fText.getDocument();
+ int startPos, endPos;
+
+ try {
+
+ int pos = caretPos;
+ char c;
+
+ while (pos >= 0) {
+ c = doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ --pos;
+ }
+
+ startPos = pos;
+
+ pos = caretPos;
+ int length = doc.getLength();
+
+ while (pos < length) {
+ c = doc.getChar(pos);
+ if (!Character.isJavaIdentifierPart(c))
+ break;
+ ++pos;
+ }
+
+ endPos = pos;
+ selectRange(startPos, endPos);
+ return true;
+
+ } catch (BadLocationException x) {
+ }
+
+ return false;
+ }
+}
\ No newline at end of file