Search in sources :

Example 1 with IResourceState

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);
    }
}
Also used : IResourceState(org.eclipse.egit.ui.internal.resources.IResourceState) IContributionItem(org.eclipse.jface.action.IContributionItem) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ModelSynchronizeParticipant(org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant) IResource(org.eclipse.core.resources.IResource) GitModelObject(org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)

Example 2 with IResourceState

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()));
}
Also used : IResourceState(org.eclipse.egit.ui.internal.resources.IResourceState) IFile(org.eclipse.core.resources.IFile) SWTBotTree(org.eclipse.swtbot.swt.finder.widgets.SWTBotTree) IndexDiffCacheEntry(org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry) SWTBotTreeItem(org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem) IFolder(org.eclipse.core.resources.IFolder) Test(org.junit.Test)

Example 3 with IResourceState

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());
    }
}
Also used : IResourceState(org.eclipse.egit.ui.internal.resources.IResourceState) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Aggregations

IResourceState (org.eclipse.egit.ui.internal.resources.IResourceState)3 IResource (org.eclipse.core.resources.IResource)2 IFile (org.eclipse.core.resources.IFile)1 IFolder (org.eclipse.core.resources.IFolder)1 IProject (org.eclipse.core.resources.IProject)1 IndexDiffCacheEntry (org.eclipse.egit.core.internal.indexdiff.IndexDiffCacheEntry)1 GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)1 IContributionItem (org.eclipse.jface.action.IContributionItem)1 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)1 SWTBotTree (org.eclipse.swtbot.swt.finder.widgets.SWTBotTree)1 SWTBotTreeItem (org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem)1 ModelSynchronizeParticipant (org.eclipse.team.ui.synchronize.ModelSynchronizeParticipant)1 Test (org.junit.Test)1