/*******************************************************************************
 * Copyright (C) 2010, Matthias Sohn <matthias.sohn@sap.com>
 *
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *******************************************************************************/
package org.eclipse.egit.ui.internal.actions;

import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.runtime.jobs.Job;
import org.eclipse.egit.core.op.AddToIndexOperation;
import org.eclipse.egit.ui.Activator;
import org.eclipse.egit.ui.JobFamilies;
import org.eclipse.egit.ui.UIText;


/**
 * Action for adding a resource to the git index
 *
 * @see AddToIndexOperation
 *
 */
public class AddToIndexActionHandler extends RepositoryActionHandler {

	public Object execute(ExecutionEvent event) throws ExecutionException {
		final IResource[] sel = getSelectedResources(event);
		if (sel.length == 0)
			return null;
		final AddToIndexOperation operation = new AddToIndexOperation(sel);
		String jobname = UIText.AddToIndexAction_addingFiles;
		Job job = new Job(jobname) {
			@Override
			protected IStatus run(IProgressMonitor monitor) {
				try {
					operation.execute(monitor);
				} catch (CoreException e) {
					return Activator.createErrorStatus(e.getStatus()
							.getMessage(), e);
				}
				return Status.OK_STATUS;
			}

			@Override
			public boolean belongsTo(Object family) {
				if (JobFamilies.ADD_TO_INDEX.equals(family))
					return true;

				return super.belongsTo(family);
			}
		};
		job.setUser(true);
		job.setRule(operation.getSchedulingRule());
		job.schedule();
		return null;
	}

	@Override
	public boolean isEnabled() {
		return getProjectsInRepositoryOfSelectedResources().length > 0;
	}

}

@@ -1046,17 +1046,115 @@
 UIText;%0A
+import org.eclipse.egit.ui.internal.operations.GitScopeUtil;%0Aimport org.eclipse.ui.IWorkbenchPart;
 %0A
-
 %0A/**%0A * 
@@ -1476,16 +1476,312 @@
 n null;%0A
+%0A%09%09IResource%5B%5D resourcesInScope;%0A%09%09try %7B%0A%09%09%09IWorkbenchPart part = getPart(event);%0A%09%09%09resourcesInScope = GitScopeUtil.getRelatedChanges(part, sel);%0A%09%09%7D catch (InterruptedException e) %7B%0A%09%09%09// ignore, we will not add the files in case the user%0A%09%09%09// cancels the scope operation%0A%09%09%09return null;%0A%09%09%7D%0A%0A
 %09%09final 
@@ -1836,19 +1836,37 @@
 eration(
-sel
+%0A%09%09%09%09resourcesInScope
 );%0A%09%09Str

Consider logical models when staging files