Please use the Apache issue tracking system for new NetBeans issues (https://issues.apache.org/jira/projects/NETBEANS0/issues) !!
View | Details | Raw Unified | Return to bug 217050
Collapse All | Expand All

(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileDescription.java (-8 / +38 lines)
 Lines 43-48    Link Here 
43
 * made subject to such option by the copyright holder.
43
 * made subject to such option by the copyright holder.
44
 *
44
 *
45
 * Contributor(s): Petr Hrebejk
45
 * Contributor(s): Petr Hrebejk
46
  *                markiewb@netbeans.org
46
 */
47
 */
47
48
48
package org.netbeans.modules.jumpto.file;
49
package org.netbeans.modules.jumpto.file;
 Lines 55-65    Link Here 
55
import org.netbeans.api.project.ProjectInformation;
56
import org.netbeans.api.project.ProjectInformation;
56
import org.netbeans.api.project.ProjectUtils;
57
import org.netbeans.api.project.ProjectUtils;
57
import org.netbeans.spi.jumpto.file.FileDescriptor;
58
import org.netbeans.spi.jumpto.file.FileDescriptor;
59
import org.openide.ErrorManager;
58
import org.openide.cookies.EditCookie;
60
import org.openide.cookies.EditCookie;
61
import org.openide.cookies.LineCookie;
59
import org.openide.cookies.OpenCookie;
62
import org.openide.cookies.OpenCookie;
60
import org.openide.filesystems.FileObject;
63
import org.openide.filesystems.FileObject;
61
import org.openide.loaders.DataObject;
64
import org.openide.loaders.DataObject;
62
import org.openide.loaders.DataObjectNotFoundException;
65
import org.openide.loaders.DataObjectNotFoundException;
66
import org.openide.text.Line;
63
import org.openide.util.ImageUtilities;
67
import org.openide.util.ImageUtilities;
64
68
65
/** Contains interesting information about file found in the search.
69
/** Contains interesting information about file found in the search.
 Lines 83-93    Link Here 
83
    private Icon icon;
87
    private Icon icon;
84
    private String projectName;
88
    private String projectName;
85
    private Icon projectIcon;
89
    private Icon projectIcon;
90
    private int lineNr;
86
91
87
    public FileDescription(FileObject file, String ownerPath, Project project) {
92
    public FileDescription(FileObject file, String ownerPath, Project project) {
93
        this(file, ownerPath, project, -1);
94
    }
95
96
    public FileDescription(FileObject file, String ownerPath, Project project, int lineNr) {
88
        this.fileObject = file;
97
        this.fileObject = file;
89
        this.ownerPath = ownerPath;
98
        this.ownerPath = ownerPath;
90
        this.project = project;
99
        this.project = project;
100
        this.lineNr = lineNr;
91
    }
101
    }
92
102
93
    @Override
103
    @Override
 Lines 133-152    Link Here 
133
    public void open() {
143
    public void open() {
134
        DataObject od = getDataObject();
144
        DataObject od = getDataObject();
135
        if ( od != null ) {
145
        if ( od != null ) {
136
            EditCookie ec = (EditCookie) od.getCookie(EditCookie.class);
146
137
            if (ec != null) {
147
            // if linenumber is given then try to open file at this line
138
                ec.edit();
148
            // code taken from org.netbeans.modules.java.stackanalyzer.StackLineAnalyser.Link.show()
149
            LineCookie lineCookie = od.getLookup().lookup(LineCookie.class);
150
            if (lineCookie != null && lineNr != -1) {
151
                try {
152
                    Line l = lineCookie.getLineSet().getCurrent(lineNr - 1);
153
154
                    if (l != null) {
155
                        // open file at the given line
156
                        l.show(Line.ShowOpenType.OPEN, Line.ShowVisibilityType.FOCUS, -1);
157
                        return;
158
                    }
159
                } catch (IndexOutOfBoundsException oob) {
160
                    //line number is no more valid
161
                    ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, oob);
162
                }
139
            }
163
            }
140
            else {
164
            // fallback to default for non-linenumber stuff
141
                OpenCookie oc = od.getCookie( OpenCookie.class );
165
            {
142
                if ( oc != null ) {
166
                EditCookie ec = od.getLookup().lookup(EditCookie.class);
143
                    oc.open();
167
                if (ec != null) {
168
                    ec.edit();
169
                } else {
170
                    OpenCookie oc = od.getLookup().lookup(OpenCookie.class);
171
                    if (oc != null) {
172
                        oc.open();
173
                    }
144
                }
174
                }
145
            }
175
            }
146
        }
176
        }
147
177
148
    }
178
    }
149
179
    
150
    @Override
180
    @Override
151
    public FileObject getFileObject() {
181
    public FileObject getFileObject() {
152
        return fileObject;
182
        return fileObject;
(-)a/jumpto/src/org/netbeans/modules/jumpto/file/FileSearchAction.java (-4 / +31 lines)
 Lines 44-49    Link Here 
44
 *
44
 *
45
 * Contributor(s): Andrei Badea
45
 * Contributor(s): Andrei Badea
46
 *                 Petr Hrebejk
46
 *                 Petr Hrebejk
47
 *                 markiewb@netbeans.org
47
 */
48
 */
48
49
49
package org.netbeans.modules.jumpto.file;
50
package org.netbeans.modules.jumpto.file;
 Lines 70-75    Link Here 
70
import java.util.Set;
71
import java.util.Set;
71
import java.util.logging.Level;
72
import java.util.logging.Level;
72
import java.util.logging.Logger;
73
import java.util.logging.Logger;
74
import java.util.regex.Matcher;
73
import java.util.regex.Pattern;
75
import java.util.regex.Pattern;
74
import java.util.regex.PatternSyntaxException;
76
import java.util.regex.PatternSyntaxException;
75
import javax.swing.AbstractAction;
77
import javax.swing.AbstractAction;
 Lines 139-150    Link Here 
139
    private FileSearchPanel panel;
141
    private FileSearchPanel panel;
140
    private Dimension initialDimension;
142
    private Dimension initialDimension;
141
    private Iterable<? extends FileProvider> providers;
143
    private Iterable<? extends FileProvider> providers;
144
    private final Pattern patternWithLineNumber;
142
    
145
    
143
    public FileSearchAction() {
146
    public FileSearchAction() {
144
        super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") );
147
        super( NbBundle.getMessage(FileSearchAction.class, "CTL_FileSearchAction") );
145
        // XXX this should be in initialize()?
148
        // XXX this should be in initialize()?
146
        putValue("PopupMenuText", NbBundle.getBundle(FileSearchAction.class).getString("editor-popup-CTL_FileSearchAction")); // NOI18N
149
        putValue("PopupMenuText", NbBundle.getBundle(FileSearchAction.class).getString("editor-popup-CTL_FileSearchAction")); // NOI18N
147
        putValue("noIconInMenu", Boolean.TRUE); // NOI18N
150
        putValue("noIconInMenu", Boolean.TRUE); // NOI18N
151
        
152
        this.patternWithLineNumber = Pattern.compile("(.*):(\\d+)");
148
    }
153
    }
149
154
150
    @Override
155
    @Override
 Lines 212-222    Link Here 
212
        else {
217
        else {
213
            nameKind = panel.isCaseSensitive() ? QuerySupport.Kind.PREFIX : QuerySupport.Kind.CASE_INSENSITIVE_PREFIX;
218
            nameKind = panel.isCaseSensitive() ? QuerySupport.Kind.PREFIX : QuerySupport.Kind.CASE_INSENSITIVE_PREFIX;
214
        }
219
        }
220
        
221
        
222
        //Extract linenumber from search text
223
        //Pattern is like 'My*Object.java:123'
224
        Matcher matcher = patternWithLineNumber.matcher(text);
225
        boolean endsWithLineNumber = matcher.matches();
226
        int lineNr;
227
        if (endsWithLineNumber) 
228
        {
229
            text = matcher.group(1);
230
            try {
231
                lineNr = Integer.parseInt(matcher.group(2));
232
            } catch (NumberFormatException numberFormatException) {
233
                //prevent non convertable numbers
234
                lineNr=-1;
235
            }
236
        }
237
        else {
238
            lineNr = -1;
239
        }
215
240
216
        // Compute in other thread
241
        // Compute in other thread
217
242
218
        synchronized( this ) {
243
        synchronized( this ) {
219
            running = new Worker(text , nameKind, panel.getCurrentProject());
244
            running = new Worker(text , nameKind, panel.getCurrentProject(), lineNr);
220
            task = rp.post( running, 220);
245
            task = rp.post( running, 220);
221
            if ( panel.time != -1 ) {
246
            if ( panel.time != -1 ) {
222
                LOGGER.log( Level.FINE, "Worker posted after {0} ms.",  System.currentTimeMillis() - panel.time );
247
                LOGGER.log( Level.FINE, "Worker posted after {0} ms.",  System.currentTimeMillis() - panel.time );
 Lines 395-403    Link Here 
395
        private final QuerySupport.Kind searchType;
420
        private final QuerySupport.Kind searchType;
396
        private final Project currentProject;
421
        private final Project currentProject;
397
        private final long createTime;
422
        private final long createTime;
423
        private final int lineNr;
398
424
399
        public Worker(String text, QuerySupport.Kind searchType, Project currentProject) {
425
        public Worker(String text, QuerySupport.Kind searchType, Project currentProject, int lineNr) {
400
            this.text = text;
426
            this.text = text;
427
            this.lineNr = lineNr;
401
            this.searchType = searchType;
428
            this.searchType = searchType;
402
            this.currentProject = currentProject;
429
            this.currentProject = currentProject;
403
            this.createTime = System.currentTimeMillis();
430
            this.createTime = System.currentTimeMillis();
 Lines 516-522    Link Here 
516
                    FileDescriptor fd = new FileDescription(
543
                    FileDescriptor fd = new FileDescription(
517
                        file,
544
                        file,
518
                        r.getRelativePath().substring(0, Math.max(r.getRelativePath().length() - file.getNameExt().length() - 1, 0)),
545
                        r.getRelativePath().substring(0, Math.max(r.getRelativePath().length() - file.getNameExt().length() - 1, 0)),
519
                        project);
546
                        project, lineNr);
520
                    FileProviderAccessor.getInstance().setFromCurrentProject(fd, preferred);
547
                    FileProviderAccessor.getInstance().setFromCurrentProject(fd, preferred);
521
                    files.add(fd);
548
                    files.add(fd);
522
                    LOGGER.log(Level.FINER, "Found: {0}, project={1}, currentProject={2}, preferred={3}",
549
                    LOGGER.log(Level.FINER, "Found: {0}, project={1}, currentProject={2}, preferred={3}",
 Lines 599-605    Link Here 
599
                            FileDescriptor fd = new FileDescription(
626
                            FileDescriptor fd = new FileDescription(
600
                                file,
627
                                file,
601
                                relativePath,
628
                                relativePath,
602
                                project
629
                                project, lineNr
603
                            );
630
                            );
604
                            FileProviderAccessor.getInstance().setFromCurrentProject(fd, preferred);
631
                            FileProviderAccessor.getInstance().setFromCurrentProject(fd, preferred);
605
                            files.add(fd);
632
                            files.add(fd);

Return to bug 217050
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2014, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo