2ce9fb12f9d35d715f0e1ee91e641de4a9a35067
[phpeclipse.git] / net.sourceforge.phpeclipse.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / AttValueDoubleClickStrategy.java
1 /*
2  * Copyright (c) 2002-2004 Widespace, OU and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  *
8  * Contributors:
9  *     Igor Malinin - initial contribution
10  *
11  * $Id: AttValueDoubleClickStrategy.java,v 1.3 2006-10-21 23:14:13 pombredanne Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15
16 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
17
18 import org.eclipse.jface.text.BadLocationException;
19 import org.eclipse.jface.text.IDocument;
20 import org.eclipse.jface.text.ITextViewer;
21 import org.eclipse.jface.text.ITypedRegion;
22
23 /**
24  * 
25  * 
26  * @author Igor Malinin
27  */
28 public class AttValueDoubleClickStrategy extends TextDoubleClickStrategy {
29         /*
30          * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(ITextViewer)
31          */
32         public void doubleClicked(ITextViewer viewer) {
33                 int offset = viewer.getSelectedRange().x;
34                 if (offset < 0) {
35                         return;
36                 }
37
38                 try {
39                         IDocument document = viewer.getDocument();
40
41                         ITypedRegion region = document.getPartition(offset);
42
43                         int start = region.getOffset();
44                         int length = region.getLength();
45                         int end = start + length - 1;
46
47                         if (offset == start) {
48                                 if (document.getChar(start) == document.getChar(end)) {
49                                         viewer.setSelectedRange(start + 1, length - 2);
50                                 } else {
51                                         viewer.setSelectedRange(start + 1, length - 1);
52                                 }
53
54                                 return;
55                         }
56
57                         if (offset == end) {
58                                 if (document.getChar(start) == document.getChar(end)) {
59                                         viewer.setSelectedRange(start + 1, length - 2);
60                                         return;
61                                 }
62                         }
63
64                         super.doubleClicked(viewer);
65                 } catch (BadLocationException e) {
66                 }
67         }
68 }