From 88f6cff42383081fb2e705e84d370e3e23062aed Mon Sep 17 00:00:00 2001 From: Bogdan Gheorghe Date: Wed, 2 Feb 2005 21:08:23 +0000 Subject: [PATCH] Added a delete IProblem Markers action to context menu to allow users to manually remove problems reported by the parser during an index. --- core/org.eclipse.cdt.ui/ChangeLog | 8 ++ core/org.eclipse.cdt.ui/plugin.properties | 1 + core/org.eclipse.cdt.ui/plugin.xml | 13 +++ .../ui/util/DeleteIProblemMarkerAction.java | 92 +++++++++++++++++++ 4 files changed, 114 insertions(+) create mode 100644 core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/DeleteIProblemMarkerAction.java diff --git a/core/org.eclipse.cdt.ui/ChangeLog b/core/org.eclipse.cdt.ui/ChangeLog index 2e4c77894d0..e5034f2a314 100644 --- a/core/org.eclipse.cdt.ui/ChangeLog +++ b/core/org.eclipse.cdt.ui/ChangeLog @@ -1,3 +1,11 @@ +2005-02-02 Bogdan Gheorghe + Added a delete IProblem Markers action to context menu to allow users to manually + remove problems reported by the parser during an index. + + * src/org/eclipse/cdt/internal/ui/util/DeleteIProblemMarkerAction.java + * plugin.xml + * plugin.properties + 2005-01-29 Alain Magloire Fix for 81403: Move the Code Assist preference page out of the CEditor preference page. It clean the CEditorPreferencePage diff --git a/core/org.eclipse.cdt.ui/plugin.properties b/core/org.eclipse.cdt.ui/plugin.properties index 6af7d22954c..160bdfde5e7 100644 --- a/core/org.eclipse.cdt.ui/plugin.properties +++ b/core/org.eclipse.cdt.ui/plugin.properties @@ -123,6 +123,7 @@ CFolderActionSet.description=C Folder Action Set # Task Action DeleteTaskAction.label=Delete C/C++ Markers +DeleteIProblemMarkerAction.label=Delete IProblem Markers # C/C++ Search CSearchPage.label= C/C++ Search diff --git a/core/org.eclipse.cdt.ui/plugin.xml b/core/org.eclipse.cdt.ui/plugin.xml index 62b47edcd27..c84b65bde54 100644 --- a/core/org.eclipse.cdt.ui/plugin.xml +++ b/core/org.eclipse.cdt.ui/plugin.xml @@ -673,6 +673,19 @@ id="org.eclipse.ui.texteditor.BookmarkRulerAction"> + + + + diff --git a/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/DeleteIProblemMarkerAction.java b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/DeleteIProblemMarkerAction.java new file mode 100644 index 00000000000..e69f8d0790a --- /dev/null +++ b/core/org.eclipse.cdt.ui/src/org/eclipse/cdt/internal/ui/util/DeleteIProblemMarkerAction.java @@ -0,0 +1,92 @@ +/********************************************************************** + * Copyright (c) 2005 IBM Corporation and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * IBM - Initial API and implementation + **********************************************************************/ +package org.eclipse.cdt.internal.ui.util; + +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +import org.eclipse.cdt.core.model.ICModelMarker; +import org.eclipse.core.resources.IMarker; +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.core.runtime.CoreException; +import org.eclipse.jface.action.IAction; +import org.eclipse.jface.viewers.ISelection; +import org.eclipse.jface.viewers.IStructuredSelection; +import org.eclipse.ui.IObjectActionDelegate; +import org.eclipse.ui.IWorkbenchPart; +import org.eclipse.ui.actions.ActionDelegate; + +/** + * @author Bogdan Gheorghe + */ +public class DeleteIProblemMarkerAction extends ActionDelegate implements IObjectActionDelegate { + + private IStructuredSelection selection; + + /** + * @see ActionDelegate#run(IAction) + */ + public void run(IAction action) { + + if (selection != null) { + if (selection.isEmpty()) { + return; + } + try { + List list = selection.toList(); + List listMarkers = new ArrayList(); + Iterator iterator = list.iterator(); + while (iterator.hasNext()) { + IMarker marker = (IMarker)iterator.next(); + if (marker.isSubtypeOf(ICModelMarker.INDEXER_MARKER)) { + listMarkers.add(marker); + } + } + // Bail out early + if (listMarkers.isEmpty()) { + return; + } + IMarker[] markers = new IMarker[listMarkers.size()]; + listMarkers.toArray(markers); + // be sure to only invoke one workspace operation + ResourcesPlugin.getWorkspace().deleteMarkers(markers); + selection = null; + } catch (CoreException e) { + } + } + } + + /** + * @see IObjectActionDelegate#setActivePart(IAction, IWorkbenchPart) + */ + public void setActivePart(IAction action, IWorkbenchPart targetPart) { + } + + public void selectionChanged(IAction action, ISelection selection) { + boolean enable = false; + if (selection instanceof IStructuredSelection) { + Object object = ((IStructuredSelection) selection).getFirstElement(); + if (object instanceof IMarker) { + try { + IMarker marker = (IMarker) object; + if (marker.isSubtypeOf(ICModelMarker.INDEXER_MARKER)) { + enable = true; + } + this.selection = (IStructuredSelection)selection; + action.setEnabled(enable); + } catch (CoreException e) { + } + } + } + } + +}