mirror of
https://github.com/eclipse-cdt/cdt
synced 2025-07-21 16:05:25 +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:
|
* Contributors:
|
||||||
* Marc-Andre Laperle - Initial API and implementation
|
* 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;
|
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.IProject;
|
||||||
import org.eclipse.core.resources.ResourcesPlugin;
|
import org.eclipse.core.resources.ResourcesPlugin;
|
||||||
import org.eclipse.core.runtime.IProgressMonitor;
|
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.PartInitException;
|
||||||
import org.eclipse.ui.PlatformUI;
|
import org.eclipse.ui.PlatformUI;
|
||||||
import org.eclipse.ui.ide.IDE;
|
import org.eclipse.ui.ide.IDE;
|
||||||
|
@ -43,11 +48,15 @@ public class OpenFiles extends ProcessRunner {
|
||||||
IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
IProject projectHandle = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
|
||||||
IFile iFile = projectHandle.getFile(fileTargetPath);
|
IFile iFile = projectHandle.getFile(fileTargetPath);
|
||||||
if (iFile.exists()) {
|
if (iFile.exists()) {
|
||||||
|
// Only open files if they are not open to avoid refresh problem if files have been modified multiple times
|
||||||
|
if (!isOpen(iFile)) {
|
||||||
try {
|
try {
|
||||||
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
|
IDE.openEditor(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage(),
|
||||||
iFile);
|
iFile);
|
||||||
} catch (PartInitException e) {
|
} catch (PartInitException e) {
|
||||||
throw new ProcessFailureException(Messages.OpenFiles_CannotOpen_error + fileTargetPath);
|
throw new ProcessFailureException(Messages.OpenFiles_CannotOpen_error
|
||||||
|
+ fileTargetPath);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
@ -56,4 +65,22 @@ 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