1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-04-23 22:52:11 +02:00

Bug 426675: fix "index update with modified files" for a sub-directory

Change-Id: I3dad716cd11a464c97ee35fdabb8b9762238ccf3
Signed-off-by: Wei Li <wei.r.li@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/34434
Reviewed-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
Tested-by: Sergey Prigogin <eclipse.sprigogin@gmail.com>
This commit is contained in:
Wei Li 2014-10-06 07:57:29 +00:00 committed by Sergey Prigogin
parent d9cefc1e0c
commit 856b684824
3 changed files with 30 additions and 22 deletions

View file

@ -44,13 +44,13 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) { if(!(fSelection instanceof IStructuredSelection) && !(fSelection instanceof ITextSelection)) {
return; return;
} }
ICProject[] projects = getSelectedCProjects(); ICElement[] elements = getSelectedCElements();
doRun(projects); doRun(elements);
} }
protected void doRun(ICProject[] projects) { protected void doRun(ICElement[] elements) {
try { try {
CCorePlugin.getIndexManager().update(projects, getUpdateOptions()); CCorePlugin.getIndexManager().update(elements, getUpdateOptions());
} catch (CoreException e) { } catch (CoreException e) {
CUIPlugin.log(e); CUIPlugin.log(e);
} }
@ -70,20 +70,20 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
public boolean isEnabledFor(ISelection selection) { public boolean isEnabledFor(ISelection selection) {
selectionChanged(null, selection); selectionChanged(null, selection);
ICProject[] project = getSelectedCProjects(); ICElement[] elements = getSelectedCElements();
return project.length > 0; return elements.length > 0;
} }
protected ICProject[] getSelectedCProjects() { protected ICElement[] getSelectedCElements() {
ArrayList<ICProject> tuSelection= new ArrayList<ICProject>(); ArrayList<ICElement> tuSelection= new ArrayList<ICElement>();
if(fSelection instanceof IStructuredSelection) { if(fSelection instanceof IStructuredSelection) {
IStructuredSelection resources = SelectionConverter.convertSelectionToResources(fSelection); IStructuredSelection resources = SelectionConverter.convertSelectionToResources(fSelection);
for (Iterator<?> i= resources.iterator(); i.hasNext();) { for (Iterator<?> i= resources.iterator(); i.hasNext();) {
Object o= i.next(); Object o= i.next();
if(o instanceof IResource) { if(o instanceof IResource) {
ICProject cproject= CCorePlugin.getDefault().getCoreModel().create(((IResource)o).getProject()); ICElement celement= CCorePlugin.getDefault().getCoreModel().create((IResource)o);
if(cproject != null) { if(celement != null) {
tuSelection.add(cproject); tuSelection.add(celement);
} }
} }
} }
@ -96,6 +96,6 @@ public abstract class AbstractUpdateIndexAction implements IObjectActionDelegate
} }
} }
} }
return tuSelection.toArray(new ICProject[tuSelection.size()]); return tuSelection.toArray(new ICElement[tuSelection.size()]);
} }
} }

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2007, 2013 Wind River Systems, Inc. and others. * Copyright (c) 2007, 2014 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -7,21 +7,29 @@
* *
* Contributors: * Contributors:
* Markus Schorn - initial API and implementation * Markus Schorn - initial API and implementation
* Sergey Prigogin (Google)
*******************************************************************************/ *******************************************************************************/
package org.eclipse.cdt.internal.ui.actions; package org.eclipse.cdt.internal.ui.actions;
import java.util.LinkedHashSet;
import java.util.Set;
import org.eclipse.cdt.core.CCorePlugin; import org.eclipse.cdt.core.CCorePlugin;
import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICProject;
public class RebuildIndexAction extends AbstractUpdateIndexAction { public class RebuildIndexAction extends AbstractUpdateIndexAction {
@Override @Override
protected void doRun(ICProject[] projects) { protected void doRun(ICElement[] elements) {
for (ICProject proj : projects) { Set<ICProject> projects = new LinkedHashSet<>();
if(proj != null) { for (ICElement element : elements) {
CCorePlugin.getIndexManager().reindex(proj); if (element != null) {
projects.add(element.getCProject());
} }
} }
for (ICProject project : projects) {
CCorePlugin.getIndexManager().reindex(project);
}
} }
@Override @Override

View file

@ -16,7 +16,7 @@ import org.eclipse.search.ui.NewSearchUI;
import org.eclipse.ui.IWorkbenchPart; import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchSite; import org.eclipse.ui.IWorkbenchSite;
import org.eclipse.cdt.core.model.ICProject; import org.eclipse.cdt.core.model.ICElement;
import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction; import org.eclipse.cdt.internal.ui.actions.AbstractUpdateIndexAction;
import org.eclipse.cdt.internal.ui.search.CSearchMessages; import org.eclipse.cdt.internal.ui.search.CSearchMessages;
@ -34,13 +34,13 @@ public class FindUnresolvedIncludesProjectAction extends AbstractUpdateIndexActi
} }
@Override @Override
protected void doRun(ICProject[] projects) { protected void doRun(ICElement[] elements) {
if (projects.length == 0) { if (elements.length == 0) {
StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message); StatusLineHandler.showStatusLineMessage(fSite, CSearchMessages.CSearchOperation_operationUnavailable_message);
return; return;
} }
ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(projects); ISearchQuery searchJob= new CSearchUnresolvedIncludesQuery(elements);
StatusLineHandler.clearStatusLine(fSite); StatusLineHandler.clearStatusLine(fSite);
NewSearchUI.activateSearchResultView(); NewSearchUI.activateSearchResultView();