public CommitFileDiffViewer()

in org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/CommitFileDiffViewer.java [177:397]


	public CommitFileDiffViewer(final Composite parent,
			final IWorkbenchSite site, final int style) {
		super(parent, style);
		setUseHashlookup(true);
		this.site = site;
		final Table rawTable = getTable();

		Color fg = rawTable.getForeground();
		Color bg = rawTable.getBackground();
		RGB dimmedForegroundRgb = ColorUtil.blend(fg.getRGB(), bg.getRGB(), 60);

		ColumnViewerToolTipSupport.enableFor(this);

		setLabelProvider(new FileDiffLabelProvider(dimmedForegroundRgb));
		setContentProvider(ArrayContentProvider.getInstance());
		setComparator(new ViewerComparator() {

			@Override
			public int compare(Viewer viewer, Object left, Object right) {
				if (left instanceof FileDiff && right instanceof FileDiff) {
					return FileDiff.PATH_COMPARATOR.compare((FileDiff) left,
							(FileDiff) right);
				}
				return super.compare(viewer, left, right);
			}
		});
		addOpenListener(new IOpenListener() {
			@Override
			public void open(final OpenEvent event) {
				ISelection s = event.getSelection();
				if (s.isEmpty() || !(s instanceof IStructuredSelection)) {
					return;
				}
				IStructuredSelection iss = (IStructuredSelection) s;
				FileDiff d = (FileDiff) iss.getFirstElement();
				if (Activator.getDefault().getPreferenceStore().getBoolean(
						UIPreferences.RESOURCEHISTORY_COMPARE_MODE)) {
					showTwoWayFileDiff(d);
				} else {
					if (d.getChange() == ChangeType.DELETE) {
						openPreviousVersionInEditor(d);
					} else {
						openThisVersionInEditor(d);
					}
				}
			}
		});

		addSelectionChangedListener(new ISelectionChangedListener() {
			@Override
			public void selectionChanged(SelectionChangedEvent event) {
				updateActionEnablement(event.getSelection());
			}
		});

		clipboard = new Clipboard(rawTable.getDisplay());
		rawTable.addDisposeListener(new DisposeListener() {
			@Override
			public void widgetDisposed(final DisposeEvent e) {
				clipboard.dispose();
			}
		});

		final MenuManager mgr = new MenuManager();
		rawTable.setMenu(mgr.createContextMenu(rawTable));

		checkOutThisVersion = new CheckoutAction(this::getStructuredSelection);

		openThisVersion = new Action(
				UIText.CommitFileDiffViewer_OpenInEditorMenuLabel) {
			@Override
			public void run() {
				withSelection(
						CommitFileDiffViewer.this::openThisVersionInEditor);
			}
		};

		openPreviousVersion = new Action(
				UIText.CommitFileDiffViewer_OpenPreviousInEditorMenuLabel) {
			@Override
			public void run() {
				withSelection(
						CommitFileDiffViewer.this::openPreviousVersionInEditor);
			}
		};

		blame = new Action(UIText.CommitFileDiffViewer_ShowAnnotationsMenuLabel,
				UIIcons.ANNOTATE) {
			@Override
			public void run() {
				withSelection(CommitFileDiffViewer.this::showAnnotations);
			}
		};

		openWorkingTreeVersion = new Action(
				UIText.CommitFileDiffViewer_OpenWorkingTreeVersionInEditorMenuLabel) {
			@Override
			public void run() {
				withSelection(d -> {
					String relativePath = d.getPath();
					File file = new Path(
							d.getRepository().getWorkTree()
									.getAbsolutePath())
									.append(relativePath).toFile();
					DiffViewer.openFileInEditor(file, -1);
				});
			}
		};

		compareWithPrevious = new Action(
				UIText.CommitFileDiffViewer_CompareMenuLabel) {
			@Override
			public void run() {
				withFirstSelected(
						CommitFileDiffViewer.this::showTwoWayFileDiff);
			}
		};

		compareWorkingTreeVersion = new Action(
				UIText.CommitFileDiffViewer_CompareWorkingDirectoryMenuLabel) {
			@Override
			public void run() {
				IStructuredSelection selection = getStructuredSelection();
				if (selection == null || selection.isEmpty()) {
					return;
				}
				List<FileDiff> diffs = new ArrayList<>();
				Iterator<?> items = selection.iterator();
				while (items.hasNext()) {
					diffs.add((FileDiff) items.next());
				}
				if (diffs.size() == 1) {
					showWorkingDirectoryFileDiff(diffs.get(0));
				} else if (!diffs.isEmpty()) {
					FileDiff first = diffs.get(0);
					Repository repository = first.getRepository();
					IPath workingTree = Path.fromOSString(
							repository.getWorkTree().getAbsolutePath());
					List<IPath> paths = diffs.stream().map(FileDiff::getPath)
							.map(workingTree::append)
							.collect(Collectors.toList());
					GitCompareEditorInput comparison = new GitCompareEditorInput(
							null, first.getCommit().name(), repository,
							paths.toArray(new IPath[0]));
					CompareUtils.openInCompare(
							CommitFileDiffViewer.this.site.getPage(),
							comparison);
				}
			}
		};

		showInHistory = new Action(
				UIText.CommitFileDiffViewer_ShowInHistoryLabel,
				UIIcons.HISTORY) {
			@Override
			public void run() {
				ShowInContext context = getShowInContext();
				if (context == null)
					return;

				IWorkbenchWindow window = PlatformUI.getWorkbench()
						.getActiveWorkbenchWindow();
				IWorkbenchPage page = window.getActivePage();
				IWorkbenchPart part = page.getActivePart();
				// paranoia
				if (part instanceof IHistoryView) {
					((IShowInTarget) part).show(context);
				}
			}
		};

		mgr.add(openWorkingTreeVersion);
		mgr.add(openThisVersion);
		mgr.add(openPreviousVersion);
		mgr.add(new Separator());
		mgr.add(checkOutThisVersion);
		mgr.add(new Separator());
		mgr.add(compareWithPrevious);
		mgr.add(compareWorkingTreeVersion);
		mgr.add(blame);

		mgr.add(new Separator());
		mgr.add(showInHistory);
		MenuManager showInSubMenu = UIUtils
				.createShowInMenu(site.getWorkbenchWindow());
		mgr.add(showInSubMenu);

		mgr.add(new Separator());
		copy = ActionUtils.createGlobalAction(ActionFactory.COPY,
				() -> {
					IStructuredSelection selection = getStructuredSelection();
					if (selection != null && !selection.isEmpty()) {
						doCopy(selection.iterator());
					}
				});
		copy.setText(UIText.CommitFileDiffViewer_CopyFilePathMenuLabel);
		copy.setEnabled(true);
		if ((rawTable.getStyle() & SWT.MULTI) != 0) {
			selectAll = ActionUtils.createGlobalAction(ActionFactory.SELECT_ALL,
					this::doSelectAll);
			selectAll.setEnabled(true);
			ActionUtils.setGlobalActions(rawTable, copy, selectAll);
			mgr.add(selectAll);
		} else {
			ActionUtils.setGlobalActions(rawTable, copy);
		}
		mgr.add(copy);
		copyAll = new Action(
				UIText.CommitFileDiffViewer_CopyAllFilePathsMenuLabel) {

			@Override
			public void run() {
				doCopy(Arrays
						.asList(((IStructuredContentProvider) getContentProvider())
								.getElements(getInput()))
						.iterator());
			}
		};
		mgr.add(copyAll);
		mgr.addMenuListener(manager -> getControl().setFocus());
	}