summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormhussein2012-10-09 02:51:17 (EDT)
committerMarc-Andre Laperle2012-10-09 23:25:23 (EDT)
commit516e23c935fa12f30c37a395dfcf794a05927f87 (patch)
treeb8af607e41b507bda428bde50cabda5cd7c010d1
parent0a4f6638ce212b8562e40e9ba899d1ee51f93b0f (diff)
downloadorg.eclipse.cdt-516e23c935fa12f30c37a395dfcf794a05927f87.zip
org.eclipse.cdt-516e23c935fa12f30c37a395dfcf794a05927f87.tar.gz
org.eclipse.cdt-516e23c935fa12f30c37a395dfcf794a05927f87.tar.bz2
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>
-rw-r--r--core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/processes/OpenFiles.java37
1 files changed, 32 insertions, 5 deletions
diff --git a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/processes/OpenFiles.java b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/processes/OpenFiles.java
index 4bd1379..90fff3c 100644
--- a/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/processes/OpenFiles.java
+++ b/core/org.eclipse.cdt.ui/templateengine/org/eclipse/cdt/ui/templateengine/processes/OpenFiles.java
@@ -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;
+ }
}