This Bugzilla instance is a read-only archive of historic NetBeans bug reports. To report a bug in NetBeans please follow the project's instructions for reporting issues.

View | Details | Raw Unified | Return to bug 190209
Collapse All | Expand All

(-)a/csl.api/nbproject/project.properties (-1 / +1 lines)
Lines 40-46 Link Here
40
# Version 2 license, then the option applies only if the new code is
40
# Version 2 license, then the option applies only if the new code is
41
# made subject to such option by the copyright holder.
41
# made subject to such option by the copyright holder.
42
42
43
spec.version.base=2.8.0
43
spec.version.base=2.9.0
44
is.autoload=true
44
is.autoload=true
45
javac.source=1.6
45
javac.source=1.6
46
46
(-)a/csl.api/src/org/netbeans/modules/csl/api/Bundle.properties (+5 lines)
Lines 10-12 Link Here
10
#SelectCodeElementAction
10
#SelectCodeElementAction
11
select-element-next=Select Next Element
11
select-element-next=Select Next Element
12
select-element-previous=Select Previous Element
12
select-element-previous=Select Previous Element
13
14
#GoToMarkOccurrencesAction
15
csl-next-marked-occurrence=Navigate to Next Occurrence
16
csl-prev-marked-occurrence=Navigate to Previous Occurrence
17
csl-no-marked-occurrence=There is no occurrence to navigate to.
(-)aacf01ff6f73 (+165 lines)
Added Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 * 
38
 * Contributor(s):
39
 * 
40
 * The Original Software is NetBeans. The Initial Developer of the Original
41
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
42
 * Microsystems, Inc. All Rights Reserved.
43
 *
44
 * If you wish your version of this file to be governed by only the CDDL
45
 * or only the GPL Version 2, indicate your decision by adding
46
 * "[Contributor] elects to include this software in this distribution
47
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
48
 * single choice of license, a recipient has the option to distribute
49
 * your version of this file under either the CDDL, the GPL Version 2 or
50
 * to extend the choice of license to its licensees as provided above.
51
 * However, if you add GPL Version 2 code and therefore, elected the GPL
52
 * Version 2 license, then the option applies only if the new code is
53
 * made subject to such option by the copyright holder.
54
 */
55
56
package org.netbeans.modules.csl.api;
57
58
import java.awt.event.ActionEvent;
59
import javax.swing.text.Document;
60
import javax.swing.text.JTextComponent;
61
import org.netbeans.editor.BaseAction;
62
import org.netbeans.modules.csl.editor.semantic.MarkOccurrencesHighlighter;
63
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
64
import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
65
import org.openide.awt.StatusDisplayer;
66
import org.openide.util.NbBundle;
67
68
/**
69
 * This file is originally from Retouche, the Java Support 
70
 * infrastructure in NetBeans. I have modified the file as little
71
 * as possible to make merging Retouche fixes back as simple as
72
 * possible. 
73
 *
74
 * @todo The Java implementation changed to jumping to the
75
 *   END of identifiers in this integration:
76
 *    http://hg.netbeans.org/main/rev/8f417bdb256d
77
 *  to handle bug 136665 - should we do the same to be
78
 *  consistent?
79
 *
80
 * @author Vladimir Voskresensky
81
 */
82
public final class GoToMarkOccurrencesAction extends BaseAction {
83
84
    private static final String prevActionName = "csl-prev-marked-occurrence"; // NOI18N
85
    private static final String nextActionName = "csl-next-marked-occurrence"; // NOI18N
86
87
    private final boolean next;
88
89
    public GoToMarkOccurrencesAction(boolean nextOccurrence) {
90
        super(getNameString(nextOccurrence));
91
        this.next = nextOccurrence;
92
        putValue(SHORT_DESCRIPTION, getDefaultShortDescription());
93
    }
94
95
    public void actionPerformed(ActionEvent evt, JTextComponent txt) {
96
        navigateToOccurence(next, txt);
97
    }
98
99
    @Override
100
    protected Object getDefaultShortDescription() {
101
        return NbBundle.getMessage(GoToMarkOccurrencesAction.class, getNameString(next));
102
    }
103
    
104
    private static String getNameString(boolean nextOccurrence) {
105
        return nextOccurrence ? nextActionName : prevActionName;
106
    }
107
    
108
    @SuppressWarnings("empty-statement")
109
    private static int findOccurrencePosition(boolean directionForward, Document doc, int curPos) {
110
        OffsetsBag bag = MarkOccurrencesHighlighter.getHighlightsBag(doc);
111
        HighlightsSequence hs = bag.getHighlights(0, doc.getLength());
112
113
        if (hs.moveNext()) {
114
            if (directionForward) {
115
                int firstStart = hs.getStartOffset(), firstEnd = hs.getEndOffset();
116
117
                while (hs.getStartOffset() <= curPos && hs.moveNext());
118
119
                if (hs.getStartOffset() > curPos) {
120
                    // we found next occurrence
121
                    return hs.getStartOffset();
122
                } else if (!(firstEnd >= curPos && firstStart <= curPos)) {
123
                    // cyclic jump to first occurrence unless we already there
124
                    return firstStart;
125
                }
126
            } else {
127
                int current = hs.getStartOffset(), last;
128
                boolean stuck = false;
129
                do {
130
                    last = current;
131
                    current = hs.getStartOffset();
132
                } while (hs.getEndOffset() < curPos && (stuck = hs.moveNext()));
133
134
                if (last == current) {
135
                    // we got no options to jump, cyclic jump to last in file unless we already there
136
                    while (hs.moveNext());
137
                    if (!(hs.getEndOffset() >= curPos && hs.getStartOffset() <= curPos)) {
138
                        return hs.getStartOffset();
139
                    }
140
                } else if (stuck) {
141
                    // just move to previous occurence
142
                    return last;
143
                } else {
144
                    // it was last occurence in the file
145
                    return current;
146
                }
147
            }
148
        }
149
        return -1;
150
    }
151
152
    private static void navigateToOccurence(boolean next, JTextComponent txt) {
153
        if (txt != null && txt.getDocument() != null) {
154
            Document doc = txt.getDocument();
155
            int position = txt.getCaretPosition();
156
            int goTo = findOccurrencePosition(next, doc, position);
157
            if (goTo > 0) {
158
                txt.setCaretPosition(goTo);
159
            } else {
160
                StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToMarkOccurrencesAction.class, "csl-no-marked-occurrence"));
161
            }
162
        }
163
164
    }    
165
}
(-)a/csl.api/src/org/netbeans/modules/csl/core/CslEditorKit.java (-1 / +1 lines)
Lines 77-83 Link Here
77
import org.netbeans.modules.csl.api.ToggleBlockCommentAction;
77
import org.netbeans.modules.csl.api.ToggleBlockCommentAction;
78
import org.netbeans.modules.csl.api.UiUtils;
78
import org.netbeans.modules.csl.api.UiUtils;
79
import org.netbeans.modules.csl.editor.hyperlink.GoToSupport;
79
import org.netbeans.modules.csl.editor.hyperlink.GoToSupport;
80
import org.netbeans.modules.csl.editor.semantic.GoToMarkOccurrencesAction;
80
import org.netbeans.modules.csl.api.GoToMarkOccurrencesAction;
81
import org.netbeans.modules.editor.NbEditorKit;
81
import org.netbeans.modules.editor.NbEditorKit;
82
import org.openide.awt.Mnemonics;
82
import org.openide.awt.Mnemonics;
83
import org.openide.filesystems.FileObject;
83
import org.openide.filesystems.FileObject;
(-)a/csl.api/src/org/netbeans/modules/csl/editor/semantic/Bundle.properties (-5 lines)
Lines 56-63 Link Here
56
#LBL_UnusedEnum=Enum {0} is not used
56
#LBL_UnusedEnum=Enum {0} is not used
57
LBL_UNUSED=Unused
57
LBL_UNUSED=Unused
58
LBL_ES_TOOLTIP=Mark Occurrences
58
LBL_ES_TOOLTIP=Mark Occurrences
59
60
csl-next-marked-occurrence=Navigate to Next Occurrence
61
csl-prev-marked-occurrence=Navigate to Previous Occurrence
62
csl-no-marked-occurrence=There is no occurrence to navigate to.
63
(-)a/csl.api/src/org/netbeans/modules/csl/editor/semantic/GoToMarkOccurrencesAction.java (-164 lines)
Removed Link Here
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 *
4
 * Copyright 2010 Oracle and/or its affiliates. All rights reserved.
5
 *
6
 * Oracle and Java are registered trademarks of Oracle and/or its affiliates.
7
 * Other names may be trademarks of their respective owners.
8
 *
9
 * The contents of this file are subject to the terms of either the GNU
10
 * General Public License Version 2 only ("GPL") or the Common
11
 * Development and Distribution License("CDDL") (collectively, the
12
 * "License"). You may not use this file except in compliance with the
13
 * License. You can obtain a copy of the License at
14
 * http://www.netbeans.org/cddl-gplv2.html
15
 * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
16
 * specific language governing permissions and limitations under the
17
 * License.  When distributing the software, include this License Header
18
 * Notice in each file and include the License file at
19
 * nbbuild/licenses/CDDL-GPL-2-CP.  Oracle designates this
20
 * particular file as subject to the "Classpath" exception as provided
21
 * by Oracle in the GPL Version 2 section of the License file that
22
 * accompanied this code. If applicable, add the following below the
23
 * License Header, with the fields enclosed by brackets [] replaced by
24
 * your own identifying information:
25
 * "Portions Copyrighted [year] [name of copyright owner]"
26
 * 
27
 * If you wish your version of this file to be governed by only the CDDL
28
 * or only the GPL Version 2, indicate your decision by adding
29
 * "[Contributor] elects to include this software in this distribution
30
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
31
 * single choice of license, a recipient has the option to distribute
32
 * your version of this file under either the CDDL, the GPL Version 2 or
33
 * to extend the choice of license to its licensees as provided above.
34
 * However, if you add GPL Version 2 code and therefore, elected the GPL
35
 * Version 2 license, then the option applies only if the new code is
36
 * made subject to such option by the copyright holder.
37
 * 
38
 * Contributor(s):
39
 * 
40
 * The Original Software is NetBeans. The Initial Developer of the Original
41
 * Software is Sun Microsystems, Inc. Portions Copyright 1997-2008 Sun
42
 * Microsystems, Inc. All Rights Reserved.
43
 *
44
 * If you wish your version of this file to be governed by only the CDDL
45
 * or only the GPL Version 2, indicate your decision by adding
46
 * "[Contributor] elects to include this software in this distribution
47
 * under the [CDDL or GPL Version 2] license." If you do not indicate a
48
 * single choice of license, a recipient has the option to distribute
49
 * your version of this file under either the CDDL, the GPL Version 2 or
50
 * to extend the choice of license to its licensees as provided above.
51
 * However, if you add GPL Version 2 code and therefore, elected the GPL
52
 * Version 2 license, then the option applies only if the new code is
53
 * made subject to such option by the copyright holder.
54
 */
55
56
package org.netbeans.modules.csl.editor.semantic;
57
58
import java.awt.event.ActionEvent;
59
import javax.swing.text.Document;
60
import javax.swing.text.JTextComponent;
61
import org.netbeans.editor.BaseAction;
62
import org.netbeans.spi.editor.highlighting.HighlightsSequence;
63
import org.netbeans.spi.editor.highlighting.support.OffsetsBag;
64
import org.openide.awt.StatusDisplayer;
65
import org.openide.util.NbBundle;
66
67
/**
68
 * This file is originally from Retouche, the Java Support 
69
 * infrastructure in NetBeans. I have modified the file as little
70
 * as possible to make merging Retouche fixes back as simple as
71
 * possible. 
72
 *
73
 * @todo The Java implementation changed to jumping to the
74
 *   END of identifiers in this integration:
75
 *    http://hg.netbeans.org/main/rev/8f417bdb256d
76
 *  to handle bug 136665 - should we do the same to be
77
 *  consistent?
78
 *
79
 * @author Vladimir Voskresensky
80
 */
81
public class GoToMarkOccurrencesAction extends BaseAction {
82
83
    private static final String prevActionName = "csl-prev-marked-occurrence"; // NOI18N
84
    private static final String nextActionName = "csl-next-marked-occurrence"; // NOI18N
85
86
    private final boolean next;
87
88
    public GoToMarkOccurrencesAction(boolean nextOccurrence) {
89
        super(getNameString(nextOccurrence));
90
        this.next = nextOccurrence;
91
        putValue(SHORT_DESCRIPTION, getDefaultShortDescription());
92
    }
93
94
    public void actionPerformed(ActionEvent evt, JTextComponent txt) {
95
        navigateToOccurence(next, txt);
96
    }
97
98
    @Override
99
    protected Object getDefaultShortDescription() {
100
        return NbBundle.getMessage(GoToMarkOccurrencesAction.class, getNameString(next));
101
    }
102
    
103
    private static String getNameString(boolean nextOccurrence) {
104
        return nextOccurrence ? nextActionName : prevActionName;
105
    }
106
    
107
    @SuppressWarnings("empty-statement")
108
    private static int findOccurrencePosition(boolean directionForward, Document doc, int curPos) {
109
        OffsetsBag bag = MarkOccurrencesHighlighter.getHighlightsBag(doc);
110
        HighlightsSequence hs = bag.getHighlights(0, doc.getLength());
111
112
        if (hs.moveNext()) {
113
            if (directionForward) {
114
                int firstStart = hs.getStartOffset(), firstEnd = hs.getEndOffset();
115
116
                while (hs.getStartOffset() <= curPos && hs.moveNext());
117
118
                if (hs.getStartOffset() > curPos) {
119
                    // we found next occurrence
120
                    return hs.getStartOffset();
121
                } else if (!(firstEnd >= curPos && firstStart <= curPos)) {
122
                    // cyclic jump to first occurrence unless we already there
123
                    return firstStart;
124
                }
125
            } else {
126
                int current = hs.getStartOffset(), last;
127
                boolean stuck = false;
128
                do {
129
                    last = current;
130
                    current = hs.getStartOffset();
131
                } while (hs.getEndOffset() < curPos && (stuck = hs.moveNext()));
132
133
                if (last == current) {
134
                    // we got no options to jump, cyclic jump to last in file unless we already there
135
                    while (hs.moveNext());
136
                    if (!(hs.getEndOffset() >= curPos && hs.getStartOffset() <= curPos)) {
137
                        return hs.getStartOffset();
138
                    }
139
                } else if (stuck) {
140
                    // just move to previous occurence
141
                    return last;
142
                } else {
143
                    // it was last occurence in the file
144
                    return current;
145
                }
146
            }
147
        }
148
        return -1;
149
    }
150
151
    private static void navigateToOccurence(boolean next, JTextComponent txt) {
152
        if (txt != null && txt.getDocument() != null) {
153
            Document doc = txt.getDocument();
154
            int position = txt.getCaretPosition();
155
            int goTo = findOccurrencePosition(next, doc, position);
156
            if (goTo > 0) {
157
                txt.setCaretPosition(goTo);
158
            } else {
159
                StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(GoToMarkOccurrencesAction.class, "csl-no-marked-occurrence"));
160
            }
161
        }
162
163
    }    
164
}
(-)a/csl.api/src/org/netbeans/modules/csl/editor/semantic/MarkOccurrencesHighlighter.java (-1 / +1 lines)
Lines 213-219 Link Here
213
        canceled = false;
213
        canceled = false;
214
    }
214
    }
215
    
215
    
216
    static OffsetsBag getHighlightsBag(Document doc) {
216
    public static OffsetsBag getHighlightsBag(Document doc) {
217
        OffsetsBag bag = (OffsetsBag) doc.getProperty(MarkOccurrencesHighlighter.class);
217
        OffsetsBag bag = (OffsetsBag) doc.getProperty(MarkOccurrencesHighlighter.class);
218
        
218
        
219
        if (bag == null) {
219
        if (bag == null) {

Return to bug 190209