From 38863b65d7d94bfd931422d716412a0adacc930e Mon Sep 17 00:00:00 2001 From: Martin Schreiber Date: Mon, 19 May 2014 09:18:44 +0200 Subject: [PATCH] Bug 434852: If the original project of the editor input file is a non accessiable project, it is a project rename scenario and the move can be handeled. Change-Id: Ibb718ea3310c3dfc40fa31d79c588371f78d6c91 Signed-off-by: Martin Schreiber Reviewed-on: https://git.eclipse.org/r/26815 Reviewed-by: Sergey Prigogin Tested-by: Sergey Prigogin Tested-by: Hudson CI --- .../cdt/internal/ui/editor/CEditor.java | 50 +++++++++++-------- 1 file changed, 30 insertions(+), 20 deletions(-) diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java index 1d538ab38e3..6fa1c6b9148 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/CEditor.java @@ -2085,35 +2085,45 @@ public class CEditor extends TextEditor implements ICEditor, ISelectionChangedLi @Override protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { String oldLanguage = ""; //$NON-NLS-1$ - if (originalElement instanceof IFileEditorInput) { - IFile file = ((IFileEditorInput) originalElement).getFile(); - if (file != null) { - IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); - if (type != null) { - oldLanguage = type.getId(); - } - if (oldLanguage == null) { - return false; - } + IFile originalFile = getEditorInputFile(originalElement); + + if (originalFile != null) { + // if the project of the original input cannot be accessed, + // we do have a project rename scenario and we can handle a move + // see Bug #434852 + if (originalFile.getProject() != null && !originalFile.getProject().isAccessible()) { + return true; + } + IContentType type = CCorePlugin.getContentType(originalFile.getProject(), originalFile.getName()); + if (type != null) { + oldLanguage = type.getId(); + } + if (oldLanguage == null) { + return false; } } String newLanguage = ""; //$NON-NLS-1$ - if (movedElement instanceof IFileEditorInput) { - IFile file = ((IFileEditorInput) movedElement).getFile(); - if (file != null) { - IContentType type = CCorePlugin.getContentType(file.getProject(), file.getName()); - if (type != null) { - newLanguage = type.getId(); - } - if (newLanguage == null) { - return false; - } + IFile movedFile = getEditorInputFile(movedElement); + if (movedFile != null) { + IContentType type = CCorePlugin.getContentType(movedFile.getProject(), movedFile.getName()); + if (type != null) { + newLanguage = type.getId(); + } + if (newLanguage == null) { + return false; } } return oldLanguage.equals(newLanguage); } + private IFile getEditorInputFile(IEditorInput editorInput) { + if (editorInput instanceof IFileEditorInput) { + return ((IFileEditorInput) editorInput).getFile(); + } + return null; + } + @Override protected void createActions() { super.createActions();