Search in sources :

Example 16 with GitHistoryPage

use of org.eclipse.egit.ui.internal.history.GitHistoryPage in project egit by eclipse.

the class SquashHandler method isEnabled.

@Override
public boolean isEnabled() {
    GitHistoryPage page = getPage();
    if (page == null)
        return false;
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return false;
    Repository repository = getRepository(page);
    if (repository.getRepositoryState() != RepositoryState.SAFE)
        return false;
    List elements = selection.toList();
    int parentsNotSelected = 0;
    for (Object element : elements) {
        RevCommit commit = (RevCommit) element;
        // one parent (this includes the root commit)
        if (commit.getParentCount() != 1)
            return false;
        RevCommit parentCommit = commit.getParent(0);
        if (!elements.contains(parentCommit))
            parentsNotSelected++;
        // contiguous selection of commits
        if (parentsNotSelected > 1)
            return false;
    }
    // has not been selected
    if (parentsNotSelected != 1)
        return false;
    return true;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) ArrayList(java.util.ArrayList) List(java.util.List) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 17 with GitHistoryPage

use of org.eclipse.egit.ui.internal.history.GitHistoryPage in project egit by eclipse.

the class AbstractHistoryCommandHandler method getPageFromPart.

private GitHistoryPage getPageFromPart(IWorkbenchPart part) {
    if (!(part instanceof IHistoryView))
        return null;
    IHistoryView view = (IHistoryView) part;
    IHistoryPage page = view.getHistoryPage();
    if (page instanceof GitHistoryPage)
        return (GitHistoryPage) page;
    return null;
}
Also used : IHistoryPage(org.eclipse.team.ui.history.IHistoryPage) GitHistoryPage(org.eclipse.egit.ui.internal.history.GitHistoryPage) IHistoryView(org.eclipse.team.ui.history.IHistoryView)

Aggregations

GitHistoryPage (org.eclipse.egit.ui.internal.history.GitHistoryPage)17 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)10 RevCommit (org.eclipse.jgit.revwalk.RevCommit)9 Repository (org.eclipse.jgit.lib.Repository)6 IOException (java.io.IOException)2 Ref (org.eclipse.jgit.lib.Ref)2 IHistoryPage (org.eclipse.team.ui.history.IHistoryPage)2 IHistoryView (org.eclipse.team.ui.history.IHistoryView)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 IResource (org.eclipse.core.resources.IResource)1 ResourceMapping (org.eclipse.core.resources.mapping.ResourceMapping)1 CommitFileRevision (org.eclipse.egit.core.internal.storage.CommitFileRevision)1 BlameOperation (org.eclipse.egit.ui.internal.blame.BlameOperation)1 RepositoryTreeNode (org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode)1 GitModelWorkbenchAdapter (org.eclipse.egit.ui.internal.synchronize.mapping.GitModelWorkbenchAdapter)1 GitModelBlob (org.eclipse.egit.ui.internal.synchronize.model.GitModelBlob)1 GitModelObject (org.eclipse.egit.ui.internal.synchronize.model.GitModelObject)1 GitModelTree (org.eclipse.egit.ui.internal.synchronize.model.GitModelTree)1