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 1543 Details for
Bug 20706
Start replace fails if it is not a text or Java editor
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
[patch]
Final patch
20706_patch.txt (text/plain), 12.82 KB, created by
Dirk Baeumer
on 2002-06-21 06:01:18 EDT
(
hide
)
Description:
Final patch
Filename:
MIME Type:
Creator:
Dirk Baeumer
Created:
2002-06-21 06:01:18 EDT
Size:
12.82 KB
patch
obsolete
>Index: search/org/eclipse/search/internal/ui/SearchMessages.properties >=================================================================== >RCS file: /home/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/SearchMessages.properties,v >retrieving revision 1.49 >diff -u -r1.49 SearchMessages.properties >--- search/org/eclipse/search/internal/ui/SearchMessages.properties 12 Jun 2002 07:52:17 -0000 1.49 >+++ search/org/eclipse/search/internal/ui/SearchMessages.properties 21 Jun 2002 09:43:20 -0000 >@@ -160,7 +160,12 @@ > ReplaceAction.label_selected= Replace Selected... > ReplaceAction.error.only_on_text_search= Replace is only available on text search. > ReplaceAction.error.unable_to_perform= Replace operation can\'t be performed. >-ReplaceAction.error.changed_files= The content of the following file(s) has changed. Please redo the search to ensure that all matches are correct. >+ReplaceAction.error.changed_file= The content of the following file has changed. Please redo the search to ensure that all matches are correct. >+ReplaceAction.error.changed_files= The content of the following files have changed. Please redo the search to ensure that all matches are correct. >+ReplaceAction.error.opened_file= The following file is already open in an editor, but the replace operation cannot handle this editor. Please close the editor. >+ReplaceAction.error.opened_files= The following files are already open in editors, but the replace operation cannot handle these editors. Please close the editors. >+ReplaceAction.error.not_file= The following resource is not a file and cannot be handled. Please exclude it from the replace operation. >+ReplaceAction.error.not_files= The following resources are not files and cannot be handled. Please exclude them from the replace operation. > ReplaceAction.dialog.title= Replace > > ReplaceDialog.replace_label= Replace: >@@ -176,3 +181,5 @@ > ReplaceDialog.error.reenable_auto_build_failed=Couldn\'t reactivate auto building. > ReplaceDialog.error.auto_building= Couldn\'t disable auto building. > ReplaceDialog.error.no_matches= Couldn\'t find first match. >+ReplaceDialog.error.no_file_for_marker=Current match is not associated with a file. It is not possible to open an editor. >+ReplaceDialog.error.unable_to_open_text_editor=It is not possible to open the built-in text editor for file ''{0}''. >\ No newline at end of file >Index: search/org/eclipse/search/internal/ui/text/ReplaceAction.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceAction.java,v >retrieving revision 1.2 >diff -u -r1.2 ReplaceAction.java >--- search/org/eclipse/search/internal/ui/text/ReplaceAction.java 16 May 2002 12:55:39 -0000 1.2 >+++ search/org/eclipse/search/internal/ui/text/ReplaceAction.java 21 Jun 2002 09:43:20 -0000 >@@ -30,8 +30,12 @@ > import org.eclipse.core.resources.ResourcesPlugin; > import org.eclipse.core.runtime.IStatus; > >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchSite; > import org.eclipse.ui.model.WorkbenchLabelProvider; >+import org.eclipse.ui.part.FileEditorInput; >+import org.eclipse.ui.texteditor.ITextEditor; > > import org.eclipse.search.internal.ui.Search; > import org.eclipse.search.internal.ui.SearchManager; >@@ -78,16 +82,39 @@ > > private boolean validateResources() { > List modifiedFiles= new ArrayList(); >+ List openedFilesInNonTextEditor= new ArrayList(); >+ List notFiles= new ArrayList(); >+ IWorkbenchPage activePage = fSite.getWorkbenchWindow().getActivePage(); >+ > for (Iterator iter = fElements.iterator(); iter.hasNext();) { > SearchResultViewEntry entry= (SearchResultViewEntry) iter.next(); > IResource resource= entry.getResource(); >- if (resource instanceof IFile && ((IFile)resource).getModificationStamp() != entry.getModificationStamp()) >- modifiedFiles.add(resource); >+ if (resource instanceof IFile) { >+ IFile file= (IFile)resource; >+ if (file.getModificationStamp() != entry.getModificationStamp() || !file.isSynchronized(IResource.DEPTH_ZERO)) { >+ modifiedFiles.add(resource); >+ } else if (activePage != null) { >+ IEditorPart part= activePage.findEditor(new FileEditorInput(file)); >+ if (part != null && !(part instanceof ITextEditor)) >+ openedFilesInNonTextEditor.add(file); >+ } >+ } else { >+ if (resource != null) >+ notFiles.add(resource); >+ } > } > if (!modifiedFiles.isEmpty()) { > showModifiedFileDialog(modifiedFiles); > return false; > } >+ if (!openedFilesInNonTextEditor.isEmpty()) { >+ showOpenedFileDialog(openedFilesInNonTextEditor); >+ return false; >+ } >+ if (!notFiles.isEmpty()) { >+ showNotFilesDialog(openedFilesInNonTextEditor); >+ return false; >+ } > IFile[] readOnlyFiles= getReadOnlyFiles(); > if (readOnlyFiles.length == 0) > return true; >@@ -113,8 +140,11 @@ > } > > private void showModifiedFileDialog(List modifiedFiles) { >+ String message= (modifiedFiles.size() == 1 >+ ? SearchMessages.getString("ReplaceAction.error.changed_file") //$NON-NLS-1$ >+ : SearchMessages.getString("ReplaceAction.error.changed_files")); //$NON-NLS-1$ > ListDialog dialog= new ListDialog(fSite.getShell(), modifiedFiles, getDialogTitle(), >- SearchMessages.getString("ReplaceAction.error.changed_files"), //$NON-NLS-1$ >+ message, > new IStructuredContentProvider() { > public Object[] getElements(Object inputElement) { > return ((List)inputElement).toArray(); >@@ -151,4 +181,44 @@ > private String getDialogTitle() { > return SearchMessages.getString("ReplaceAction.dialog.title"); //$NON-NLS-1$ > } >+ >+ private void showOpenedFileDialog(List openedFilesInNonTextEditor) { >+ String message= (openedFilesInNonTextEditor.size() == 1 >+ ? SearchMessages.getString("ReplaceAction.error.opened_file") //$NON-NLS-1$ >+ : SearchMessages.getString("ReplaceAction.error.opened_files")); //$NON-NLS-1$ >+ ListDialog dialog= new ListDialog(fSite.getShell(), openedFilesInNonTextEditor, getDialogTitle(), >+ message, >+ new IStructuredContentProvider() { >+ public Object[] getElements(Object inputElement) { >+ return ((List)inputElement).toArray(); >+ } >+ public void dispose() { >+ } >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ }, >+ new WorkbenchLabelProvider()); >+ dialog.setCreateCancelButton(false); >+ dialog.open(); >+ } >+ >+ private void showNotFilesDialog(List notFiles) { >+ String message= (notFiles.size() == 1 >+ ? SearchMessages.getString("ReplaceAction.error.not_file") //$NON-NLS-1$ >+ : SearchMessages.getString("ReplaceAction.error.not_files")); //$NON-NLS-1$ >+ ListDialog dialog= new ListDialog(fSite.getShell(), notFiles, getDialogTitle(), >+ message, >+ new IStructuredContentProvider() { >+ public Object[] getElements(Object inputElement) { >+ return ((List)inputElement).toArray(); >+ } >+ public void dispose() { >+ } >+ public void inputChanged(Viewer viewer, Object oldInput, Object newInput) { >+ } >+ }, >+ new WorkbenchLabelProvider()); >+ dialog.setCreateCancelButton(false); >+ dialog.open(); >+ } > } >Index: search/org/eclipse/search/internal/ui/text/ReplaceDialog.java >=================================================================== >RCS file: /home/eclipse/org.eclipse.search/search/org/eclipse/search/internal/ui/text/ReplaceDialog.java,v >retrieving revision 1.3 >diff -u -r1.3 ReplaceDialog.java >--- search/org/eclipse/search/internal/ui/text/ReplaceDialog.java 11 Jun 2002 08:34:56 -0000 1.3 >+++ search/org/eclipse/search/internal/ui/text/ReplaceDialog.java 21 Jun 2002 09:43:21 -0000 >@@ -10,9 +10,11 @@ > ******************************************************************************/ > package org.eclipse.search.internal.ui.text; > >+import java.text.MessageFormat; > import java.util.ArrayList; > import java.util.List; > >+import org.eclipse.core.resources.IFile; > import org.eclipse.core.resources.IMarker; > import org.eclipse.core.resources.IWorkspace; > import org.eclipse.core.resources.IWorkspaceDescription; >@@ -41,9 +43,13 @@ > import org.eclipse.jface.text.Position; > import org.eclipse.jface.util.Assert; > >+import org.eclipse.ui.IEditorDescriptor; > import org.eclipse.ui.IEditorInput; >+import org.eclipse.ui.IEditorPart; >+import org.eclipse.ui.IEditorRegistry; > import org.eclipse.ui.IWorkbenchPage; > import org.eclipse.ui.IWorkbenchWindow; >+import org.eclipse.ui.PartInitException; > import org.eclipse.ui.actions.GlobalBuildAction; > import org.eclipse.ui.texteditor.AbstractMarkerAnnotationModel; > import org.eclipse.ui.texteditor.IDocumentProvider; >@@ -91,6 +97,16 @@ > private int fMarkerIndex; > private IMarker fCurrentMatch; > >+ private static class MarkerNotPresentableException extends Exception { >+ private IFile fFile; >+ MarkerNotPresentableException(IFile file) { >+ fFile= file; >+ } >+ public IFile getFile() { >+ return fFile; >+ } >+ } >+ > protected ReplaceDialog(Shell parentShell, List elements, IWorkbenchWindow window, String searchPattern) { > super(parentShell); > Assert.isNotNull(elements); >@@ -126,6 +142,9 @@ > } catch (CoreException e) { > ExceptionHandler.handle(e, getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.no_matches")); //$NON-NLS-1$ > fFatalError= true; >+ } catch (MarkerNotPresentableException e) { >+ handleMarkerNotPresentableException(e); >+ fFatalError= true; > } > return super.open(); > } >@@ -217,6 +236,9 @@ > } catch (BadLocationException e) { > MessageDialog.openError(getShell(), getDialogTitle(), SearchMessages.getString("ReplaceDialog.error.different_content")); //$NON-NLS-1$ > fFatalError= true; >+ } catch (MarkerNotPresentableException e) { >+ handleMarkerNotPresentableException(e); >+ fFatalError= true; > } > updateButtons(); > super.buttonPressed(buttonId); >@@ -238,7 +260,7 @@ > return fElementIndex < fElements.size(); > } > >- private IMarker getNextMatch(boolean save) throws CoreException { >+ private IMarker getNextMatch(boolean save) throws CoreException, MarkerNotPresentableException { > if (fCurrentMarkers == null) { > if (fElementIndex >= fElements.size()) > return null; >@@ -251,7 +273,9 @@ > if (fEditor == null) { > IWorkbenchPage activePage = fWindow.getActivePage(); > int openEditors= activePage.getEditorReferences().length; >- fEditor= (ITextEditor)activePage.openEditor(result, false); >+ >+ fEditor= openFile(result, activePage); >+ fEditor.gotoMarker(result); > IDocumentProvider provider= fEditor.getDocumentProvider(); > IEditorInput input = fEditor.getEditorInput(); > fDocument= provider.getDocument(input); >@@ -268,9 +292,32 @@ > return result; > } > >+ private ITextEditor openFile(IMarker marker, IWorkbenchPage activePage) throws MarkerNotPresentableException, PartInitException { >+ IFile markerFile= marker.getResource() instanceof IFile ? (IFile)marker.getResource() : null; >+ if (markerFile == null) >+ throw new MarkerNotPresentableException(null); >+ >+ String currentEditorId= null; >+ IEditorRegistry editorRegistry= SearchPlugin.getDefault().getWorkbench().getEditorRegistry(); >+ IEditorDescriptor desc= editorRegistry.getDefaultEditor(markerFile); >+ if (desc != null) >+ currentEditorId= desc.getId(); >+ try { >+ IEditorPart result= activePage.openEditor(markerFile, "org.eclipse.ui.DefaultTextEditor", false); //$NON-NLS-1$ >+ if (!(result instanceof ITextEditor)) >+ throw new MarkerNotPresentableException(markerFile); >+ return (ITextEditor)result; >+ } finally { >+ if (currentEditorId != null) >+ editorRegistry.setDefaultEditor(markerFile, currentEditorId); >+ } >+ } >+ > private void saveEditor(boolean save) throws CoreException { >- if (fEditor != null) >- save= save && fEditor.isDirty(); >+ if (fEditor == null) >+ return; >+ >+ save= save && fEditor.isDirty(); > if (save) { > IDocumentProvider provider= fEditor.getDocumentProvider(); > IEditorInput input = fEditor.getEditorInput(); >@@ -282,7 +329,7 @@ > provider.changed(input); > } > } >- if (fEditor != null && fCloseEditor && save) >+ if (fCloseEditor && !fEditor.isDirty()) > fEditor.close(false); > fEditor= null; > fDocument= null; >@@ -321,5 +368,16 @@ > > private String getDialogTitle() { > return SearchMessages.getString("ReplaceDialog.dialog.title"); //$NON-NLS-1$ >+ } >+ >+ private void handleMarkerNotPresentableException(MarkerNotPresentableException e) { >+ IFile file= e.getFile(); >+ String message; >+ if (file == null) { >+ message= SearchMessages.getString("ReplaceDialog.error.no_file_for_marker"); //$NON-NLS-1$ >+ } else { >+ message= SearchMessages.getFormattedString("ReplaceDialog.error.unable_to_open_text_editor", file.getName()); //$NON-NLS-1$ >+ } >+ MessageDialog.openError(getParentShell(), getDialogTitle(), message); > } > }
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 20706
:
1529
| 1543