use of org.eclipse.egit.ui.internal.actions.ReplaceWithOursTheirsMenu in project egit by eclipse.
the class StagingView method createPopupMenu.
private void createPopupMenu(final TreeViewer treeViewer) {
final MenuManager menuMgr = new MenuManager();
menuMgr.setRemoveAllWhenShown(true);
Control control = treeViewer.getControl();
control.setMenu(menuMgr.createContextMenu(control));
menuMgr.addMenuListener(new IMenuListener() {
@Override
public void menuAboutToShow(IMenuManager manager) {
control.setFocus();
final IStructuredSelection selection = (IStructuredSelection) treeViewer.getSelection();
if (selection.isEmpty())
return;
Set<StagingEntry> stagingEntrySet = new LinkedHashSet<>();
Set<StagingFolderEntry> stagingFolderSet = new LinkedHashSet<>();
boolean submoduleSelected = false;
boolean folderSelected = false;
boolean onlyFoldersSelected = true;
for (Object element : selection.toArray()) {
if (element instanceof StagingFolderEntry) {
StagingFolderEntry folder = (StagingFolderEntry) element;
folderSelected = true;
if (onlyFoldersSelected) {
stagingFolderSet.add(folder);
}
StagingViewContentProvider contentProvider = getContentProvider(treeViewer);
stagingEntrySet.addAll(contentProvider.getStagingEntriesFiltered(folder));
} else if (element instanceof StagingEntry) {
if (onlyFoldersSelected) {
stagingFolderSet.clear();
}
onlyFoldersSelected = false;
StagingEntry entry = (StagingEntry) element;
if (entry.isSubmodule()) {
submoduleSelected = true;
}
stagingEntrySet.add(entry);
}
}
List<StagingEntry> stagingEntryList = new ArrayList<>(stagingEntrySet);
final IStructuredSelection fileSelection = new StructuredSelection(stagingEntryList);
stagingEntrySet = null;
if (!folderSelected) {
Action openWorkingTreeVersion = new Action(UIText.CommitFileDiffViewer_OpenWorkingTreeVersionInEditorMenuLabel) {
@Override
public void run() {
openSelectionInEditor(fileSelection);
}
};
openWorkingTreeVersion.setEnabled(!submoduleSelected && anyElementIsExistingFile(fileSelection));
menuMgr.add(openWorkingTreeVersion);
String label = stagingEntryList.get(0).isStaged() ? UIText.CommitFileDiffViewer_CompareWorkingDirectoryMenuLabel : UIText.StagingView_CompareWithIndexMenuLabel;
Action openCompareWithIndex = new Action(label) {
@Override
public void run() {
runCommand(ActionCommands.COMPARE_WITH_INDEX_ACTION, fileSelection);
}
};
menuMgr.add(openCompareWithIndex);
}
menuMgr.add(createSelectionPathCopyAction(treeViewer));
Set<StagingEntry.Action> availableActions = getAvailableActions(fileSelection);
boolean addReplaceWithFileInGitIndex = availableActions.contains(StagingEntry.Action.REPLACE_WITH_FILE_IN_GIT_INDEX);
boolean addReplaceWithHeadRevision = availableActions.contains(StagingEntry.Action.REPLACE_WITH_HEAD_REVISION);
boolean addStage = availableActions.contains(StagingEntry.Action.STAGE);
boolean addUnstage = availableActions.contains(StagingEntry.Action.UNSTAGE);
boolean addDelete = availableActions.contains(StagingEntry.Action.DELETE);
boolean addIgnore = availableActions.contains(StagingEntry.Action.IGNORE);
boolean addLaunchMergeTool = availableActions.contains(StagingEntry.Action.LAUNCH_MERGE_TOOL);
boolean addReplaceWithOursTheirsMenu = availableActions.contains(StagingEntry.Action.REPLACE_WITH_OURS_THEIRS_MENU);
boolean addAssumeUnchanged = availableActions.contains(StagingEntry.Action.ASSUME_UNCHANGED);
boolean addUntrack = availableActions.contains(StagingEntry.Action.UNTRACK);
if (addStage) {
menuMgr.add(new Action(UIText.StagingView_StageItemMenuLabel, UIIcons.ELCL16_ADD) {
@Override
public void run() {
stage(selection);
}
});
}
if (addUnstage) {
menuMgr.add(new Action(UIText.StagingView_UnstageItemMenuLabel, UIIcons.UNSTAGE) {
@Override
public void run() {
unstage(selection);
}
});
}
boolean selectionIncludesNonWorkspaceResources = selectionIncludesNonWorkspaceResources(fileSelection);
if (addReplaceWithFileInGitIndex) {
if (selectionIncludesNonWorkspaceResources) {
menuMgr.add(new ReplaceAction(UIText.StagingView_replaceWithFileInGitIndex, fileSelection, false));
} else {
menuMgr.add(createItem(UIText.StagingView_replaceWithFileInGitIndex, ActionCommands.DISCARD_CHANGES_ACTION, // replace with index
fileSelection));
}
}
if (addReplaceWithHeadRevision) {
if (selectionIncludesNonWorkspaceResources) {
menuMgr.add(new ReplaceAction(UIText.StagingView_replaceWithHeadRevision, fileSelection, true));
} else {
menuMgr.add(createItem(UIText.StagingView_replaceWithHeadRevision, ActionCommands.REPLACE_WITH_HEAD_ACTION, fileSelection));
}
}
if (addIgnore) {
if (!stagingFolderSet.isEmpty()) {
menuMgr.add(new IgnoreFoldersAction(stagingFolderSet));
}
menuMgr.add(new IgnoreAction(fileSelection));
}
if (addDelete) {
menuMgr.add(new DeleteAction(fileSelection));
}
if (addLaunchMergeTool) {
menuMgr.add(createItem(UIText.StagingView_MergeTool, ActionCommands.MERGE_TOOL_ACTION, fileSelection));
}
if (addReplaceWithOursTheirsMenu) {
MenuManager replaceWithMenu = new MenuManager(UIText.StagingView_ReplaceWith);
ReplaceWithOursTheirsMenu oursTheirsMenu = new ReplaceWithOursTheirsMenu();
oursTheirsMenu.initialize(getSite());
replaceWithMenu.add(oursTheirsMenu);
menuMgr.add(replaceWithMenu);
}
if (addAssumeUnchanged) {
menuMgr.add(new Action(UIText.StagingView_Assume_Unchanged, UIIcons.ASSUME_UNCHANGED) {
@Override
public void run() {
assumeUnchanged(selection);
}
});
}
if (addUntrack) {
menuMgr.add(new Action(UIText.StagingView_Untrack, UIIcons.UNTRACK) {
@Override
public void run() {
untrack(selection);
}
});
}
menuMgr.add(new Separator());
menuMgr.add(createShowInMenu());
}
});
}
Aggregations