mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-04-29 19:45:01 +02:00
Bug 389392 - Editor refresh problem when template executed twice
Modify OpenFiles so that it doesn't attempt to open files if they are already opened. Update: added copyright message. Change-Id: I09fd41b3b34d2b1469cc11a8678f99645a0f9c43 Reviewed-on: https://git.eclipse.org/r/7725 Reviewed-by: Marc-Andre Laperle <malaperle@gmail.com> IP-Clean: Marc-Andre Laperle <malaperle@gmail.com> Tested-by: Marc-Andre Laperle <malaperle@gmail.com>
This commit is contained in:
parent
0a4f6638ce
commit
516e23c935
1 changed files with 32 additions and 5 deletions
|
@ -7,6 +7,7 @@
|
|||
*
|
||||
* Contributors:
|
||||
* Marc-Andre Laperle - Initial API and implementation
|
||||
* Mohamed Hussein (Mentor Graphics) - Bug 389392 fix refresh when open existing editor
|
||||
*******************************************************************************/
|
||||
package org.eclipse.cdt.ui.templateengine.processes;
|
||||
|
||||
|
@ -19,6 +20,10 @@ import org.eclipse.core.resources.IFile;
|
|||
import org.eclipse.core.resources.IProject;
|
||||
import org.eclipse.core.resources.ResourcesPlugin;
|
||||
import org.eclipse.core.runtime.IProgressMonitor;
|
||||
import org.eclipse.ui.IEditorInput;
|
||||
import org.eclipse.ui.IEditorPart;
|
||||
import org.eclipse.ui.IEditorReference;
|
||||
import org.eclipse.ui.IFileEditorInput;
|
||||
import org.eclipse.ui.PartInitException;
|
||||
import org.eclipse.ui.PlatformUI;
|
||||
import org.eclipse.ui.ide.IDE;
|
||||
|
@ -43,11 +48,15 @@ public class OpenFiles extends ProcessRunner {
|
|||
IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||
IFile iFile = projectHandle.getFile(fileTargetPath);
|
||||
if (iFile.exists()) {
|
||||
try {
|
||||
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
|
||||
iFile);
|
||||
} catch (PartInitException e) {
|
||||
throw new ProcessFailureException(Messages.OpenFiles_CannotOpen_error + fileTargetPath);
|
||||
// Only open files if they are not open to avoid refresh problem if files have been modified multiple times
|
||||
if (!isOpen(iFile)) {
|
||||
try {
|
||||
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
|
||||
iFile);
|
||||
} catch (PartInitException e) {
|
||||
throw new ProcessFailureException(Messages.OpenFiles_CannotOpen_error
|
||||
+ fileTargetPath);
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
@ -55,5 +64,23 @@ public class OpenFiles extends ProcessRunner {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isOpen(IFile file) {
|
||||
IEditorReference[] editorReferences = PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().getEditorReferences();
|
||||
if (editorReferences != null) {
|
||||
IEditorInput editorInput;
|
||||
for (IEditorReference editorReference : editorReferences) {
|
||||
try {
|
||||
editorInput = editorReference.getEditorInput();
|
||||
if (editorInput instanceof IFileEditorInput
|
||||
&& file.equals(((IFileEditorInput)editorInput).getFile())) {
|
||||
return true;
|
||||
}
|
||||
} catch (PartInitException e) {}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue