Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 134757 Details for
Bug 97228
[navigation] NLSKeyHyperlink to reveal/goto the key in the properties file editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
Replaces the last patch - copied wrong patch
NLSKeyHyperlink_nonTextEditors_3.patch (text/plain), 9.17 KB, created by
Florian Albrecht
on 2009-05-07 04:42:52 EDT
(
hide
)
Description:
Replaces the last patch - copied wrong patch
Filename:
MIME Type:
Creator:
Florian Albrecht
Created:
2009-05-07 04:42:52 EDT
Size:
9.17 KB
patch
obsolete
>Index: ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java >=================================================================== >RCS file: /cvsroot/eclipse/org.eclipse.jdt.ui/ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java,v >retrieving revision 1.23 >diff -u -r1.23 NLSKeyHyperlink.java >--- ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java 6 May 2008 09:43:45 -0000 1.23 >+++ ui/org/eclipse/jdt/internal/ui/javaeditor/NLSKeyHyperlink.java 7 May 2009 08:42:11 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2008 IBM Corporation and others. >+ * Copyright (c) 2000, 2009 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -11,6 +11,11 @@ > package org.eclipse.jdt.internal.ui.javaeditor; > > import org.eclipse.core.runtime.Assert; >+import org.eclipse.core.runtime.IPath; >+ >+import org.eclipse.core.filebuffers.FileBuffers; >+import org.eclipse.core.filebuffers.ITextFileBuffer; >+import org.eclipse.core.filebuffers.LocationKind; > > import org.eclipse.core.resources.IStorage; > >@@ -27,9 +32,9 @@ > > import org.eclipse.ui.IEditorInput; > import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IFileEditorInput; > import org.eclipse.ui.PartInitException; > import org.eclipse.ui.texteditor.IEditorStatusLine; >-import org.eclipse.ui.texteditor.ITextEditor; > > import org.eclipse.jdt.core.JavaModelException; > import org.eclipse.jdt.core.dom.ITypeBinding; >@@ -41,7 +46,6 @@ > import org.eclipse.jdt.internal.corext.util.Messages; > > import org.eclipse.jdt.internal.ui.propertiesfileeditor.IPropertiesFilePartitions; >-import org.eclipse.jdt.internal.ui.propertiesfileeditor.PropertyKeyHyperlinkDetector; > import org.eclipse.jdt.internal.ui.viewsupport.BasicElementLabels; > > >@@ -60,10 +64,10 @@ > > /** > * Creates a new NLS key hyperlink. >- * >- * @param region >- * @param keyName >- * @param ref >+ * >+ * @param region the region of the link >+ * @param keyName the name of the key >+ * @param ref the accessor class reference > * @param editor the editor which contains the hyperlink > */ > public NLSKeyHyperlink(IRegion region, String keyName, AccessorClassReference ref, IEditorPart editor) { >@@ -96,8 +100,19 @@ > } catch (JavaModelException e) { > // Don't open the file > } >+ openKeyInPropertiesFile(fKeyName, propertiesFile, fEditor); >+ } >+ >+ /** >+ * Calculates the region of the NLS key in the properties file and reveals it in editor. >+ * >+ * @param keyName the NLS key >+ * @param propertiesFile the properties file, or <code>null</code> >+ * @param activeEditor the active editor part >+ */ >+ public static void openKeyInPropertiesFile(String keyName, IStorage propertiesFile, IEditorPart activeEditor) { > if (propertiesFile == null) { >- showErrorInStatusLine(fEditor, JavaEditorMessages.Editor_OpenPropertiesFile_error_fileNotFound_dialogMessage); >+ showErrorInStatusLine(activeEditor, JavaEditorMessages.Editor_OpenPropertiesFile_error_fileNotFound_dialogMessage); > return; > } > >@@ -105,68 +120,70 @@ > try { > editor= EditorUtility.openInEditor(propertiesFile, true); > } catch (PartInitException e) { >- handleOpenPropertiesFileFailed(propertiesFile); >+ handleOpenPropertiesFileFailed(propertiesFile, activeEditor); > return; > } >- >- // Reveal the key in the properties file >- if (editor instanceof ITextEditor) { >- IRegion region= null; >- boolean found= false; >- >- // Find key in document >- IEditorInput editorInput= editor.getEditorInput(); >- IDocument document= ((ITextEditor)editor).getDocumentProvider().getDocument(editorInput); >- if (document != null) { >- FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document); >- PropertyKeyHyperlinkDetector detector= new PropertyKeyHyperlinkDetector(); >- detector.setContext(editor); >- String key= PropertyFileDocumentModel.unwindEscapeChars(fKeyName); >- int offset= document.getLength() - 1; >- try { >- while (!found && offset >= 0) { >- region= finder.find(offset, key, false, true, false, false); >- if (region == null) >- offset= -1; >- else { >- // test whether it's the key >- IHyperlink[] hyperlinks= detector.detectHyperlinks(null, region, false); >- if (hyperlinks != null) { >- for (int i= 0; i < hyperlinks.length; i++) { >- IRegion hyperlinkRegion= hyperlinks[i].getHyperlinkRegion(); >- found= key.equals(document.get(hyperlinkRegion.getOffset(), hyperlinkRegion.getLength())); >+ >+ // Reveal the key in the editor >+ IEditorInput input = editor.getEditorInput(); >+ if (input instanceof IFileEditorInput) { >+ IPath path= ((IFileEditorInput)input).getFile().getFullPath(); >+ ITextFileBuffer buffer= FileBuffers.getTextFileBufferManager().getTextFileBuffer( >+ path, LocationKind.IFILE); >+ if (buffer != null) { >+ // Find key in document >+ IDocument document= buffer.getDocument(); >+ boolean found= false; >+ IRegion region= null; >+ if (document != null) { >+ FindReplaceDocumentAdapter finder= new FindReplaceDocumentAdapter(document); >+ String key= PropertyFileDocumentModel.unwindEscapeChars(keyName); >+ int offset= document.getLength() - 1; >+ try { >+ while (!found && offset >= 0) { >+ region= finder.find(offset, key, false, true, false, false); >+ if (region == null) >+ offset= -1; >+ else { >+ // test whether it's the key >+ if (document instanceof IDocumentExtension3) { >+ // test using properties file partitioning >+ ITypedRegion partition= null; >+ partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false); >+ found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) >+ && key.equals(document.get(partition.getOffset(), partition.getLength()).trim()); > } >- } else if (document instanceof IDocumentExtension3) { >- // Fall back: test using properties file partitioning >- ITypedRegion partition= null; >- partition= ((IDocumentExtension3)document).getPartition(IPropertiesFilePartitions.PROPERTIES_FILE_PARTITIONING, region.getOffset(), false); >- found= IDocument.DEFAULT_CONTENT_TYPE.equals(partition.getType()) >- && key.equals(document.get(partition.getOffset(), partition.getLength()).trim()); >+ // Prevent endless loop (panic code, shouldn't be needed) >+ if (offset == region.getOffset()) >+ offset= -1; >+ else >+ offset= region.getOffset(); > } >- // Prevent endless loop (panic code, shouldn't be needed) >- if (offset == region.getOffset()) >- offset= -1; >- else >- offset= region.getOffset(); > } >+ } catch (BadLocationException ex) { >+ found= false; >+ } catch (BadPartitioningException e1) { >+ found= false; > } >- } catch (BadLocationException ex) { >- found= false; >- } catch (BadPartitioningException e1) { >- found= false; > } >- } >- if (found) >- EditorUtility.revealInEditor(editor, region); >- else { >- EditorUtility.revealInEditor(editor, 0, 0); >- showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, fKeyName)); >+ if (found) >+ EditorUtility.revealInEditor(editor, region); >+ else { >+ EditorUtility.revealInEditor(editor, 0, 0); >+ showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_keyNotFound, keyName)); >+ } > } > } > } > >- private void showErrorInStatusLine(IEditorPart editor, final String message) { >- final Display display= fEditor.getSite().getShell().getDisplay(); >+ /** >+ * Shows the given message as error on the status line. >+ * >+ * @param editor the editor part >+ * @param message message to be displayed >+ */ >+ private static void showErrorInStatusLine(IEditorPart editor, final String message) { >+ final Display display= editor.getSite().getShell().getDisplay(); > display.beep(); > final IEditorStatusLine statusLine= (IEditorStatusLine)editor.getAdapter(IEditorStatusLine.class); > if (statusLine != null) { >@@ -181,8 +198,14 @@ > } > } > >- private void handleOpenPropertiesFileFailed(IStorage propertiesFile) { >- showErrorInStatusLine(fEditor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_openEditor_dialogMessage, BasicElementLabels.getPathLabel(propertiesFile.getFullPath(), true))); >+ /** >+ * Shows error message in status line if opening the properties file in editor fails. >+ * >+ * @param propertiesFile the propertiesFile >+ * @param editor the editor part >+ */ >+ private static void handleOpenPropertiesFileFailed(IStorage propertiesFile, IEditorPart editor) { >+ showErrorInStatusLine(editor, Messages.format(JavaEditorMessages.Editor_OpenPropertiesFile_error_openEditor_dialogMessage, BasicElementLabels.getPathLabel(propertiesFile.getFullPath(), true))); > } > > /*
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 97228
:
134625
|
134755
|
134757
|
134766
|
134937