Search in sources :

Example 1 with FileHistoryUi

use of com.intellij.vcs.log.history.FileHistoryUi in project intellij-community by JetBrains.

the class CompareRevisionsFromHistoryAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
    FilePath filePath = e.getRequiredData(VcsDataKeys.FILE_PATH);
    if (e.getInputEvent() instanceof MouseEvent && ui.getTable().isResizingColumns()) {
        // disable action during columns resize
        return;
    }
    VcsLogUtil.triggerUsage(e);
    List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
    if (commits.size() != 1 && commits.size() != 2)
        return;
    List<Integer> commitIds = ContainerUtil.map(commits, c -> ui.getLogData().getCommitIndex(c.getHash(), c.getRoot()));
    ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIds, details -> {
        if (details.size() == 2) {
            VcsFileRevision newestRevision = ui.createRevision(details.get(0));
            VcsFileRevision olderRevision = ui.createRevision(details.get(1));
            if (olderRevision != null && newestRevision != null) {
                myDiffHandler.showDiffForTwo(project, filePath, olderRevision, newestRevision);
            }
        } else if (details.size() == 1) {
            VcsFullCommitDetails detail = ObjectUtils.notNull(ContainerUtil.getFirstItem(details));
            List<Change> changes = ui.collectRelevantChanges(detail);
            if (filePath.isDirectory()) {
                VcsDiffUtil.showChangesDialog(project, "Changes in " + detail.getId().toShortString() + " for " + filePath.getName(), ContainerUtil.newArrayList(changes));
            } else {
                ShowDiffAction.showDiffForChange(project, changes, 0, new ShowDiffContext());
            }
        }
    }, null);
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) Project(com.intellij.openapi.project.Project) MouseEvent(java.awt.event.MouseEvent) CommitId(com.intellij.vcs.log.CommitId) ShowDiffContext(com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext) List(java.util.List) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Example 2 with FileHistoryUi

use of com.intellij.vcs.log.history.FileHistoryUi in project intellij-community by JetBrains.

the class FileHistorySingleCommitAction method update.

@Override
public void update(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    FileHistoryUi ui = e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
    if (project == null || ui == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setVisible(true);
    List<VcsFullCommitDetails> details = ui.getVcsLog().getSelectedDetails();
    if (details.isEmpty()) {
        e.getPresentation().setEnabled(false);
        return;
    }
    VcsFullCommitDetails detail = getFirstItem(details);
    if (detail instanceof LoadingDetails)
        detail = null;
    e.getPresentation().setEnabled(details.size() == 1 && isEnabled(ui, detail, e));
}
Also used : Project(com.intellij.openapi.project.Project) LoadingDetails(com.intellij.vcs.log.data.LoadingDetails) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Example 3 with FileHistoryUi

use of com.intellij.vcs.log.history.FileHistoryUi in project intellij-community by JetBrains.

the class FileHistorySingleCommitAction method actionPerformed.

@Override
public void actionPerformed(@NotNull AnActionEvent e) {
    VcsLogUtil.triggerUsage(e);
    Project project = e.getRequiredData(CommonDataKeys.PROJECT);
    FileHistoryUi ui = e.getRequiredData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
    List<CommitId> commits = ui.getVcsLog().getSelectedCommits();
    if (commits.size() != 1)
        return;
    CommitId commit = notNull(getFirstItem(commits));
    List<Integer> commitIndex = Ints.asList(ui.getLogData().getCommitIndex(commit.getHash(), commit.getRoot()));
    ui.getLogData().getCommitDetailsGetter().loadCommitsData(commitIndex, details -> {
        if (!details.isEmpty()) {
            performAction(project, ui, notNull(getFirstItem(details)), e);
        }
    }, null);
}
Also used : Project(com.intellij.openapi.project.Project) CommitId(com.intellij.vcs.log.CommitId) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi)

Example 4 with FileHistoryUi

use of com.intellij.vcs.log.history.FileHistoryUi in project intellij-community by JetBrains.

the class VcsLogActionPromoter method promote.

@Override
public List<AnAction> promote(@NotNull List<AnAction> actions, @NotNull DataContext context) {
    List<AnAction> promoted = ContainerUtil.newArrayList();
    VcsLogUi ui = VcsLogDataKeys.VCS_LOG_UI.getData(context);
    if (ui != null && ui instanceof FileHistoryUi) {
        CompareRevisionsFromHistoryAction compareAction = ContainerUtil.findInstance(actions, CompareRevisionsFromHistoryAction.class);
        if (compareAction != null)
            promoted.add(compareAction);
    }
    return promoted;
}
Also used : VcsLogUi(com.intellij.vcs.log.VcsLogUi) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) CompareRevisionsFromHistoryAction(com.intellij.vcs.log.ui.actions.history.CompareRevisionsFromHistoryAction) AnAction(com.intellij.openapi.actionSystem.AnAction)

Example 5 with FileHistoryUi

use of com.intellij.vcs.log.history.FileHistoryUi in project intellij-community by JetBrains.

the class CompareRevisionsFromHistoryAction method update.

public void update(@NotNull AnActionEvent e) {
    Project project = e.getProject();
    FileHistoryUi ui = e.getData(VcsLogInternalDataKeys.FILE_HISTORY_UI);
    FilePath filePath = e.getData(VcsDataKeys.FILE_PATH);
    if (project == null || ui == null || filePath == null) {
        e.getPresentation().setEnabledAndVisible(false);
        return;
    }
    e.getPresentation().setVisible(true);
    List<VcsFullCommitDetails> details = ui.getVcsLog().getSelectedDetails();
    if (e.getInputEvent() instanceof KeyEvent) {
        e.getPresentation().setEnabled(true);
    } else {
        if (details.size() == 2) {
            VcsFullCommitDetails detail0 = details.get(0);
            VcsFullCommitDetails detail1 = details.get(1);
            if (detail0 != null && !(detail0 instanceof LoadingDetails) && detail1 != null && !(detail1 instanceof LoadingDetails)) {
                VcsFileRevision newestRevision = ui.createRevision(detail0);
                VcsFileRevision olderRevision = ui.createRevision(detail1);
                e.getPresentation().setEnabled(newestRevision != null && olderRevision != null && !filePath.isDirectory());
            } else {
                e.getPresentation().setEnabled(!filePath.isDirectory());
            }
        } else {
            e.getPresentation().setEnabled(details.size() == 1);
        }
    }
    if (details.size() == 2) {
        e.getPresentation().setText(COMPARE_TEXT);
        e.getPresentation().setDescription(COMPARE_DESCRIPTION);
    } else {
        e.getPresentation().setText(DIFF_TEXT);
        e.getPresentation().setDescription(DIFF_DESCRIPTION);
    }
}
Also used : FilePath(com.intellij.openapi.vcs.FilePath) KeyEvent(java.awt.event.KeyEvent) Project(com.intellij.openapi.project.Project) LoadingDetails(com.intellij.vcs.log.data.LoadingDetails) FileHistoryUi(com.intellij.vcs.log.history.FileHistoryUi) VcsFileRevision(com.intellij.openapi.vcs.history.VcsFileRevision) VcsFullCommitDetails(com.intellij.vcs.log.VcsFullCommitDetails)

Aggregations

FileHistoryUi (com.intellij.vcs.log.history.FileHistoryUi)7 Project (com.intellij.openapi.project.Project)6 CommitId (com.intellij.vcs.log.CommitId)3 VcsFullCommitDetails (com.intellij.vcs.log.VcsFullCommitDetails)3 FilePath (com.intellij.openapi.vcs.FilePath)2 VcsFileRevision (com.intellij.openapi.vcs.history.VcsFileRevision)2 LoadingDetails (com.intellij.vcs.log.data.LoadingDetails)2 AnAction (com.intellij.openapi.actionSystem.AnAction)1 Change (com.intellij.openapi.vcs.changes.Change)1 ShowDiffContext (com.intellij.openapi.vcs.changes.actions.diff.ShowDiffContext)1 VcsLogUi (com.intellij.vcs.log.VcsLogUi)1 CompareRevisionsFromHistoryAction (com.intellij.vcs.log.ui.actions.history.CompareRevisionsFromHistoryAction)1 KeyEvent (java.awt.event.KeyEvent)1 MouseEvent (java.awt.event.MouseEvent)1 List (java.util.List)1