use of org.eclipse.egit.ui.internal.resources.IResourceState in project egit by eclipse.
the class GitActionContributor method fillContextMenu.
@Override
public void fillContextMenu(IMenuManager menu) {
IStructuredSelection selection = (IStructuredSelection) getContext().getSelection();
if (selection.isEmpty())
return;
Object element = selection.getFirstElement();
IResource resource = ResourceUtil.getResource(element);
if (resource != null) {
// add standard git action for 'workspace' models
menu.appendToGroup(GIT_ACTIONS, createItem(COMMIT_ACTION));
IResourceState state = ResourceStateFactory.getInstance().get(resource);
if (state.hasUnstagedChanges()) {
menu.appendToGroup(GIT_ACTIONS, createItem(ADD_TO_INDEX));
}
if (state.isStaged()) {
menu.appendToGroup(GIT_ACTIONS, createItem(REMOVE_FROM_INDEX));
}
if (!state.isIgnored()) {
menu.appendToGroup(GIT_ACTIONS, createItem(IGNORE_ACTION));
}
menu.appendToGroup(GIT_ACTIONS, createItem(MERGE_TOOL_ACTION));
menu.appendToGroup(GIT_ACTIONS, createItem(CREATE_PATCH));
} else if (element instanceof GitModelObject && selection.size() == 1) {
createMenuForGitModelObject(menu, (GitModelObject) element);
}
IContributionItem fileGroup = findGroup(menu, ISynchronizePageConfiguration.FILE_GROUP);
if (fileGroup != null) {
ModelSynchronizeParticipant msp = ((ModelSynchronizeParticipant) getConfiguration().getParticipant());
if (msp.hasCompareInputFor(element))
menu.appendToGroup(fileGroup.getId(), openWorkingFileAction);
}
}
use of org.eclipse.egit.ui.internal.resources.IResourceState in project egit by eclipse.
the class SubmoduleFolderTest method testStageUnstageInSubRepo.
/**
* Tests AddToIndex and RemoveFromIndex commands on a file from a submodule
* folder. Verifies the execution of the command by testing the state of the
* file in the index diff after it has been executed. Additionally verifies
* that decorations do get updated.
*
* @throws Exception
*/
@Test
public void testStageUnstageInSubRepo() throws Exception {
IFolder childProjectFolder = childFolder.getFolder(CHILDPROJECT);
IFolder folder = childProjectFolder.getFolder(FOLDER);
IFile file = folder.getFile(FILE1);
touch(PROJ1, file.getProjectRelativePath().toOSString(), "Modified");
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
SWTBotTree projectExplorerTree = TestUtil.getExplorerTree();
SWTBotTreeItem node = TestUtil.navigateTo(projectExplorerTree, file.getFullPath().segments());
TestUtil.waitForDecorations();
assertTrue(node.getText().startsWith("> " + file.getName()));
node.select();
ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team", util.getPluginLocalizedValue("AddToIndexAction_label"));
TestUtil.joinJobs(ADD_TO_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
IndexDiffCacheEntry cache = Activator.getDefault().getIndexDiffCache().getIndexDiffCacheEntry(subRepository);
IResourceState state = ResourceStateFactory.getInstance().get(cache.getIndexDiff(), file);
assertTrue("File should be staged", state.isStaged());
TestUtil.waitForDecorations();
assertFalse(node.getText().startsWith("> "));
ContextMenuHelper.clickContextMenuSync(projectExplorerTree, "Team", util.getPluginLocalizedValue("RemoveFromIndexAction_label"));
TestUtil.joinJobs(REMOVE_FROM_INDEX);
TestUtil.joinJobs(JobFamilies.INDEX_DIFF_CACHE_UPDATE);
state = ResourceStateFactory.getInstance().get(cache.getIndexDiff(), file);
assertFalse("File should not be staged", state.isStaged());
assertTrue("File should be dirty", state.isDirty());
TestUtil.waitForDecorations();
assertTrue(node.getText().startsWith("> " + file.getName()));
}
use of org.eclipse.egit.ui.internal.resources.IResourceState in project egit by eclipse.
the class StagingUtil method assertStaging.
public static void assertStaging(String projectName, String filePath, boolean expected) {
IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
IResource resource = project.findMember(filePath);
assertNotNull(filePath + " should exist", resource);
IResourceState state = ResourceStateFactory.getInstance().get(resource);
if (expected) {
assertTrue(projectName + '/' + filePath + " should be staged", state.isStaged());
} else {
assertFalse(projectName + '/' + filePath + " should be unstaged", state.isStaged());
}
}
Aggregations