From 9aebc8d6a2bf4181fbeafd170b4d9bb1a7f0420f Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Tue, 22 Jun 2004 16:34:55 +0000 Subject: [PATCH] Fix for 68028: Open Declaration into closed project causes PartInitException --- core/org.eclipse.cdt.ui/ChangeLog | 7 +++++++ .../cdt/internal/ui/CPluginResources.properties | 8 ++++++++ .../cdt/internal/ui/editor/OpenIncludeAction.java | 13 +++++++++++++ .../cdt/internal/ui/util/EditorUtility.java | 14 +++++++++----- 4 files changed, 37 insertions(+), 5 deletions(-) diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 6559fc646b0..2d9e1b942ce 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,10 @@ +2004-06-22 Bogdan Gheorghe + Fix for 68028: Open Declaration into closed project causes PartInitException + + * src/org/eclipse/cdt/internal/ui/util/EditorUtility.java + * src/org/eclipse/cdt/internal/ui/util/OpenIncludeAction.java + + 2004-06-21 Bogdan Gheorghe Fixed opening search external markers. diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties index 3c4a9dd8ef4..3637f125033 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/CPluginResources.properties @@ -298,6 +298,9 @@ OpenIncludeAction.tooltip=Open the Selected Include in the Editor OpenIncludeAction.description=Open the selected include in the editor OpenIncludeAction.dialog.title=Open Include OpenIncludeAction.dialog.message=Select the file to open +OpenIncludeAction.error = No Includes Found +OpenIncludeAction.error.description = No include files were found that matched that name. + # ------- SearchDialogAction --------------- SearchDialogAction.label=C/C++ Search... @@ -323,3 +326,8 @@ CreateFolderAction.text = F&older # ------- Drag and Drop Message Text ----------- CViewDragNDrop.txt = already exists. Would you like to overwrite it? + +# ------- EditorUtility Open Closed Project Text ----------- +EditorUtility.closedproject = Project is closed +Editorutility.closedproject.description = The project {0} containing that declaration is closed. + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java index 45937488e62..31d88d2fd1b 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/editor/OpenIncludeAction.java @@ -38,6 +38,8 @@ import org.eclipse.jface.viewers.ISelectionProvider; import org.eclipse.jface.viewers.IStructuredSelection; import org.eclipse.jface.viewers.LabelProvider; import org.eclipse.jface.window.Window; +import org.eclipse.swt.SWT; +import org.eclipse.swt.widgets.MessageBox; import org.eclipse.ui.IEditorDescriptor; import org.eclipse.ui.IEditorRegistry; import org.eclipse.ui.PlatformUI; @@ -97,6 +99,7 @@ public class OpenIncludeAction extends Action { IPath fileToOpen; int nElementsFound= filesFound.size(); if (nElementsFound == 0) { + noElementsFound(); fileToOpen= null; } else if (nElementsFound == 1) { fileToOpen= (IPath) filesFound.get(0); @@ -123,6 +126,16 @@ public class OpenIncludeAction extends Action { } } + /** + * + */ + private void noElementsFound() { + MessageBox errorMsg = new MessageBox(CUIPlugin.getActiveWorkbenchShell(), SWT.ICON_ERROR | SWT.OK); + errorMsg.setText(CUIPlugin.getResourceString("OpenIncludeAction.error")); //$NON-NLS-1$ + errorMsg.setMessage (CUIPlugin.getResourceString("OpenIncludeAction.error.description")); //$NON-NLS-1$ + errorMsg.open(); + } + private void findFile(String[] includePaths, String name, ArrayList list) throws CoreException { for (int i = 0; i < includePaths.length; i++) { IPath path = new Path(includePaths[i] + "/" + name); //$NON-NLS-1$ diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java index 49c37ae0a1c..e95dc39ac16 100644 --- a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/EditorUtility.java @@ -8,6 +8,7 @@ package org.eclipse.cdt.internal.ui.util; import java.io.ByteArrayInputStream; import java.io.File; import java.io.IOException; +import java.text.MessageFormat; import org.eclipse.cdt.core.model.CModelException; import org.eclipse.cdt.core.model.CoreModel; @@ -17,12 +18,12 @@ import org.eclipse.cdt.core.model.ISourceReference; import org.eclipse.cdt.core.model.ITranslationUnit; import org.eclipse.cdt.core.model.IWorkingCopy; import org.eclipse.cdt.core.resources.FileStorage; -import org.eclipse.cdt.internal.ui.cview.CViewMessages; import org.eclipse.cdt.internal.ui.editor.CEditor; import org.eclipse.cdt.internal.ui.editor.CEditorMessages; import org.eclipse.cdt.internal.ui.editor.ITranslationUnitEditorInput; import org.eclipse.cdt.ui.CUIPlugin; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.IStorage; import org.eclipse.core.runtime.IPath; @@ -118,7 +119,7 @@ public class EditorUtility { private static IEditorPart openInEditor(IFile file, boolean activate) throws PartInitException { if (!file.getProject().isAccessible()){ - closedProject(); + closedProject(file.getProject()); return null; } @@ -148,13 +149,16 @@ public class EditorUtility { } /** + * @param project * */ - private static void closedProject() { + private static void closedProject(IProject project) { MessageBox errorMsg = new MessageBox(CUIPlugin.getActiveWorkbenchShell(), SWT.ICON_ERROR | SWT.OK); - errorMsg.setText("ARGHH!"); //$NON-NLS-1$ - errorMsg.setMessage ("You tried to open that which cannot be opened..."); //$NON-NLS-1$ + errorMsg.setText(CUIPlugin.getResourceString("EditorUtility.closedproject")); //$NON-NLS-1$ + String desc= CUIPlugin.getResourceString("Editorutility.closedproject.description"); + errorMsg.setMessage (MessageFormat.format(desc, new Object[]{project.getName()})); //$NON-NLS-1$ errorMsg.open(); + } private static IEditorPart openInEditor(IEditorInput input, String editorID, boolean activate) throws PartInitException {