Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorteicher2003-10-13 09:09:26 +0000
committerteicher2003-10-13 09:09:26 +0000
commitd032ff3620054e1266ff5dff421529288ee664a2 (patch)
treebacebf30bc7e92610fb1c8514278148db5598e15 /org.eclipse.ui.editors
parent054bd3bd5ab25a54cd3bd5c864e6235e2d6d3974 (diff)
downloadeclipse.platform.text-d032ff3620054e1266ff5dff421529288ee664a2.tar.gz
eclipse.platform.text-d032ff3620054e1266ff5dff421529288ee664a2.tar.xz
eclipse.platform.text-d032ff3620054e1266ff5dff421529288ee664a2.zip
fixes bug 44667: Quick Diff causes deletion to fail
Diffstat (limited to 'org.eclipse.ui.editors')
-rw-r--r--org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java68
1 files changed, 49 insertions, 19 deletions
diff --git a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
index f4ba45a4368..99d55676d3b 100644
--- a/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
+++ b/org.eclipse.ui.editors/src/org/eclipse/ui/internal/editors/quickdiff/LastSaveReferenceProvider.java
@@ -19,6 +19,8 @@ import java.io.Reader;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.Platform;
+import org.eclipse.core.runtime.jobs.IJobManager;
import org.eclipse.jface.text.Document;
import org.eclipse.jface.text.IDocument;
@@ -50,13 +52,15 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
private IEditorInput fEditorInput;
/** Private lock noone else will synchronize on. */
private final Object fLock= new Object();
+ /** The progress monitor for a currently running <code>getReference</code> operation, or <code>null</code>. */
+ private IProgressMonitor fProgressMonitor;
/*
* @see org.eclipse.ui.editors.quickdiff.IQuickDiffReferenceProvider#getReference()
*/
public IDocument getReference(IProgressMonitor monitor) {
if (!fDocumentRead)
- readDocument();
+ readDocument(monitor);
return fReference;
}
@@ -68,11 +72,17 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
if (provider != null)
provider.removeElementStateListener(this);
+ IProgressMonitor monitor= fProgressMonitor;
+ if (monitor != null) {
+ monitor.setCanceled(true);
+ }
+
synchronized (fLock) {
fEditorInput= null;
fDocumentProvider= null;
fReference= null;
fDocumentRead= false;
+ fProgressMonitor= null;
}
}
@@ -122,8 +132,11 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
/**
* Reads in the saved document into <code>fReference</code>.
+ *
+ * @param monitor a progress monitor, or <code>null</code>
*/
- private void readDocument() {
+ private void readDocument(IProgressMonitor monitor) {
+
// protect against concurrent disposal
IDocumentProvider prov= fDocumentProvider;
IEditorInput inp= fEditorInput;
@@ -140,20 +153,34 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
// addElementStateListener adds at most once - no problem to call repeatedly
((IDocumentProvider)provider).addElementStateListener(this);
- InputStream stream= getFileContents(input);
- if (stream == null)
- return;
-
- String encoding= getEncoding(input, provider);
- if (encoding == null)
- return;
+ IJobManager jobMgr= Platform.getJobManager();
+ IFile file= input.getFile();
try {
- setDocumentContent(doc, stream, encoding);
+ fProgressMonitor= monitor;
+ jobMgr.beginRule(file, monitor);
+
+ InputStream stream= getFileContents(file);
+ if (stream == null)
+ return;
+
+ String encoding= getEncoding(input, provider);
+ if (encoding == null)
+ return;
+
+ setDocumentContent(doc, stream, encoding, monitor);
+
} catch (IOException e) {
return;
+ } finally {
+ jobMgr.endRule(file);
+ fProgressMonitor= null;
}
+ if (monitor != null && monitor.isCanceled())
+ return;
+
+
// update state
synchronized (fLock) {
if (fDocumentProvider == provider && fEditorInput == input) {
@@ -169,15 +196,14 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
/* utility methods */
/**
- * Gets the contents of the file referred to by <code>input</code> as an input stream.
+ * Gets the contents of <code>file</code> as an input stream.
*
- * @param input the <code>IFileEditorInput</code> which we want the content for
+ * @param file the <code>IFile</code> which we want the content for
* @return an input stream for the file's content
*/
- private InputStream getFileContents(IFileEditorInput input) {
+ private static InputStream getFileContents(IFile file) {
InputStream stream= null;
try {
- IFile file= input.getFile();
if (file != null)
stream= file.getContents();
@@ -195,7 +221,7 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
* @param provider the current document provider
* @return the encoding for the file corresponding to <code>input</code>, or the default encoding
*/
- private String getEncoding(IFileEditorInput input, IStorageDocumentProvider provider) {
+ private static String getEncoding(IFileEditorInput input, IStorageDocumentProvider provider) {
String encoding= provider.getEncoding(input);
if (encoding == null)
encoding= provider.getDefaultEncoding();
@@ -208,9 +234,10 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
* @param document the document to be initialized
* @param contentStream the stream which delivers the document content
* @param encoding the character encoding for reading the given stream
- * @exception CoreException if the given stream can not be read
+ * @param monitor a progress monitor for cancellation, or <code>null</code>
+ * @exception IOException if the given stream can not be read
*/
- private static void setDocumentContent(IDocument document, InputStream contentStream, String encoding) throws IOException {
+ private static void setDocumentContent(IDocument document, InputStream contentStream, String encoding, IProgressMonitor monitor) throws IOException {
Reader in= null;
try {
final int DEFAULT_FILE_SIZE= 15 * 1024;
@@ -220,6 +247,9 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
char[] readBuffer= new char[2048];
int n= in.read(readBuffer);
while (n > 0) {
+ if (monitor != null && monitor.isCanceled())
+ return;
+
buffer.append(readBuffer, 0, n);
n= in.read(readBuffer);
}
@@ -242,7 +272,7 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
public void elementDirtyStateChanged(Object element, boolean isDirty) {
if (!isDirty && element == fEditorInput) {
// document has been saved or reverted - recreate reference
- readDocument();
+ readDocument(null);
}
}
@@ -258,7 +288,7 @@ public class LastSaveReferenceProvider implements IQuickDiffProviderImplementati
public void elementContentReplaced(Object element) {
if (element == fEditorInput) {
// document has been reverted or replaced
- readDocument();
+ readDocument(null);
}
}

Back to the top