From 412410a881347cb35e0293fe02eafad1230c2549 Mon Sep 17 00:00:00 2001 From: Alain Magloire Date: Sun, 2 May 2004 00:43:59 +0000 Subject: [PATCH] Fix for PR 57620 --- core/org.eclipse.cdt.ui/ChangeLog | 5 ++ .../cdt/internal/ui/editor/CEditor.java | 59 ++++++++++++------- 2 files changed, 42 insertions(+), 22 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 06fb6471887..edb16df3b93 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,8 @@ +2004-05-01 Alain Magloire + + Fix for PR 57620 + * src/org/eclipse/cdt/internal/ui/editor/CEditor.java + 2004-04-30 Hoda Amer Partial fix for bug#60298 : [Content Assist] "No completions available" when using Content Assist during class definitions 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 686204ec1c9..66ed7b971b0 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 @@ -11,8 +11,8 @@ import java.util.List; import java.util.StringTokenizer; import org.eclipse.cdt.core.CCorePlugin; +import org.eclipse.cdt.core.filetype.ICFileType; import org.eclipse.cdt.core.model.CModelException; -import org.eclipse.cdt.core.model.CoreModel; import org.eclipse.cdt.core.model.ICElement; import org.eclipse.cdt.core.model.ISourceRange; import org.eclipse.cdt.core.model.ISourceReference; @@ -31,7 +31,6 @@ import org.eclipse.cdt.ui.actions.RefactoringActionGroup; import org.eclipse.cdt.ui.actions.ShowInCViewAction; import org.eclipse.core.resources.IFile; import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.Preferences; import org.eclipse.jface.action.IAction; @@ -198,7 +197,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS * Gets the current input */ public IFile getInputFile() { - //IFileEditorInput editorInput = (IFileEditorInput)getEditorInput(); IEditorInput editorInput = getEditorInput(); if (editorInput != null) { if ((editorInput instanceof IFileEditorInput)) { @@ -448,6 +446,36 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS super.dispose(); } + /* + * @see AbstractTextEditor#canHandleMove(IEditorInput, IEditorInput) + */ + protected boolean canHandleMove(IEditorInput originalElement, IEditorInput movedElement) { + String oldLanguage = ""; //$NON-NLS-1$ + if (originalElement instanceof IFileEditorInput) { + IFile file= ((IFileEditorInput) originalElement).getFile(); + if (file != null) { + ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName()); + oldLanguage = type.getLanguageId(); + if (oldLanguage == null) { + return false; + } + } + } + + String newLanguage = ""; //$NON-NLS-1$ + if (movedElement instanceof IFileEditorInput) { + IFile file = ((IFileEditorInput) movedElement).getFile(); + if (file != null) { + ICFileType type = CCorePlugin.getDefault().getFileType(file.getProject(), file.getName()); + newLanguage = type.getLanguageId(); + if (newLanguage == null) { + return false; + } + } + } + return oldLanguage.equals(newLanguage); + } + protected void createActions() { super.createActions(); @@ -665,11 +693,8 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS } }; provider.addSelectionChangedListener(fStatusLineClearer); - } else { - getStatusLineManager().setErrorMessage(""); //$NON-NLS-1$ - } } @@ -860,18 +885,10 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS */ protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) { // Figure out if this is a C or C++ source file - String filename = getEditorInput().getName(); - boolean c_file = filename.endsWith(".c"); //$NON-NLS-1$ - - if (!c_file && filename.endsWith(".h")) { //$NON-NLS-1$ - // ensure that this .h file is part of a C project & not a CPP project - - IFile file = getInputFile(); - if (file != null) { - IProject project = file.getProject(); - c_file = !CoreModel.getDefault().hasCCNature(project); - } - } + IWorkingCopyManager mgr = CUIPlugin.getDefault().getWorkingCopyManager(); + ITranslationUnit unit = mgr.getWorkingCopy(getEditorInput()); + String fileType = (unit != null && unit.isCXXLanguage()) ? LANGUAGE_CPP : LANGUAGE_C; + fAnnotationAccess = createAnnotationAccess(); ISharedTextColors sharedColors = CUIPlugin.getDefault().getSharedTextColors(); @@ -890,7 +907,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS styles, fOverviewRuler, isOverviewRulerVisible(), - c_file ? LANGUAGE_C : LANGUAGE_CPP); + fileType); fSourceViewerDecorationSupport = new SourceViewerDecorationSupport(sourceViewer, fOverviewRuler, fAnnotationAccess, sharedColors); @@ -899,7 +916,6 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS return sourceViewer; } - /** Outliner context menu Id */ protected String fOutlinerContextMenuId; @@ -952,8 +968,7 @@ public class CEditor extends TextEditor implements ISelectionChangedListener, IS statusLine.setMessage(true, msg, null); } - - + //Links /** * Enables browser like links.