*** empty log message ***
[phpeclipse.git] / net.sourceforge.phpeclipse.xml.ui / src / net / sourceforge / phpeclipse / xml / ui / internal / text / TagDoubleClickStrategy.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: TagDoubleClickStrategy.java,v 1.1 2004-09-02 18:28:03 jsurfer Exp $
12  */
13
14 package net.sourceforge.phpeclipse.xml.ui.internal.text;
15
16 import org.eclipse.jface.text.BadLocationException;
17 import org.eclipse.jface.text.IDocument;
18 import org.eclipse.jface.text.ITextViewer;
19 import org.eclipse.jface.text.ITypedRegion;
20
21 import net.sourceforge.phpeclipse.ui.text.TextDoubleClickStrategy;
22
23
24 /**
25  * 
26  * 
27  * @author Igor Malinin
28  */
29 public class TagDoubleClickStrategy extends TextDoubleClickStrategy {
30         /*
31          * @see org.eclipse.jface.text.ITextDoubleClickStrategy#doubleClicked(ITextViewer)
32          */
33         public void doubleClicked( ITextViewer viewer ) {
34                 int offset = viewer.getSelectedRange().x;
35                 if ( offset < 0 ) {
36                         return;
37                 }
38
39                 try {
40                         IDocument document = viewer.getDocument();
41
42                         ITypedRegion region = document.getPartition( offset );
43
44                         int start = region.getOffset();
45
46                         if ( offset == start && document.getChar(offset) == '<' ) {
47                                 region = document.getPartition( offset );
48                                 offset = region.getOffset() + region.getLength();
49
50                                 if ( document.getChar(offset - 1) != '>' ) {
51                                         while ( true ) {
52                                                 if ( offset >= document.getLength() ) {
53                                                         break;
54                                                 }
55
56                                                 region = document.getPartition( offset );
57                                                 offset = region.getOffset() + region.getLength();
58
59                                                 if ( XMLPartitionScanner.XML_ATTRIBUTE
60                                                                 .equals(region.getType()) ) {
61                                                         continue;
62                                                 }
63
64                                                 if ( XMLPartitionScanner.XML_TAG
65                                                                 .equals(region.getType()) ) {
66                                                         if ( document.getChar(region.getOffset()) == '<' ) {
67                                                                 break;
68                                                         }
69
70                                                         if ( document.getChar(offset - 1) == '>' ) {
71                                                                 break;
72                                                         }
73
74                                                         continue;
75                                                 }
76
77                                                 offset = region.getOffset();
78                                                 break;
79                                         }
80                                 }
81
82                                 viewer.setSelectedRange( start, offset - start );
83                                 return;
84                         }
85
86                         int end = start + region.getLength();
87
88                         if ( offset == end - 1 && document.getChar(offset) == '>' ) {
89                                 region = document.getPartition( offset );
90                                 offset = region.getOffset();
91
92                                 if ( document.getChar(offset) != '<' ) {
93                                         while ( true ) {
94                                                 if ( offset <= 0 ) {
95                                                         break;
96                                                 }
97
98                                                 region = document.getPartition( offset - 1 );
99                                                 offset = region.getOffset();
100
101                                                 if ( XMLPartitionScanner.XML_ATTRIBUTE
102                                                                 .equals(region.getType()) ) {
103                                                         continue;
104                                                 }
105
106                                                 if ( XMLPartitionScanner.XML_TAG
107                                                                 .equals(region.getType()) ) {
108                                                         if ( document.getChar(offset) == '<' ) {
109                                                                 break;
110                                                         }
111
112                                                         continue;
113                                                 }
114
115                                                 offset += region.getLength();
116                                                 break;
117                                         }
118                                 }
119
120                                 viewer.setSelectedRange( offset, end - offset );
121                                 return;
122                         }
123
124                         super.doubleClicked( viewer );
125                 } catch ( BadLocationException e ) {}
126         }
127 }