diff options
author | Thomas Wolf | 2017-07-14 12:24:20 +0000 |
---|---|---|
committer | Thomas Wolf | 2017-10-16 21:10:51 +0000 |
commit | ee5336775acf9efa647ba8e0f5a9009ac90da77e (patch) | |
tree | d3b524907024ec8dabf464391d130f54791cbd6e | |
parent | 4e6d5f451b699842e725cd76bddd5e93158183fb (diff) | |
download | egit-ee5336775acf9efa647ba8e0f5a9009ac90da77e.tar.gz egit-ee5336775acf9efa647ba8e0f5a9009ac90da77e.tar.xz egit-ee5336775acf9efa647ba8e0f5a9009ac90da77e.zip |
Add a property tester specific to the GitHistoryPage
This allows us to test in plugin.xml whether the currently active
view is the history view, showing the GitHistoryPage, which shows
the history filtered to a single file.
Change-Id: I8c53e09dd2ebe68f006d68cbd7854432733a9ce9
Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
-rw-r--r-- | org.eclipse.egit.ui/plugin.xml | 7 | ||||
-rw-r--r-- | org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPropertyTester.java | 67 |
2 files changed, 74 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml index 740c838381..f65644724e 100644 --- a/org.eclipse.egit.ui/plugin.xml +++ b/org.eclipse.egit.ui/plugin.xml @@ -5609,6 +5609,13 @@ properties="parentCount" type="org.eclipse.jgit.revwalk.RevCommit"> </propertyTester> + <propertyTester + class="org.eclipse.egit.ui.internal.history.GitHistoryPropertyTester" + id="org.eclipse.egit.ui.GitHistoryTester" + namespace="GitHistory" + properties="isSingleFileHistory" + type="org.eclipse.team.ui.history.IHistoryView"> + </propertyTester> </extension> <extension point="org.eclipse.ui.navigator.linkHelper"> diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPropertyTester.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPropertyTester.java new file mode 100644 index 0000000000..be31b3b751 --- /dev/null +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPropertyTester.java @@ -0,0 +1,67 @@ +/******************************************************************************* + * Copyright (C) 2017, Thomas Wolf <thomas.wolf@paranor.ch> + * + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + *******************************************************************************/ +package org.eclipse.egit.ui.internal.history; + +import java.io.File; + +import org.eclipse.core.expressions.PropertyTester; +import org.eclipse.core.resources.IResource; +import org.eclipse.egit.ui.internal.expressions.AbstractPropertyTester; +import org.eclipse.team.ui.history.IHistoryPage; +import org.eclipse.team.ui.history.IHistoryView; + +/** + * A {@link PropertyTester} specific to the git history page. Offers the + * following tests: + * <dl> + * <dt>IHistoryView.isSingleFileHistory</dt> + * <dd><code>true</code> if the active part is the history view, and the active + * page is the git history page, and the page is filtered to a single file. The + * expected <code>value</code> "resource" matches only if that single file is an + * {@link IResource}, and likewise the <code>value</code> "file" matches only if + * the single file is a {@link File}. Otherwise the test is <code>true</code> in + * either case.</dd> + * </dl> + */ +public class GitHistoryPropertyTester extends AbstractPropertyTester { + + @Override + public boolean test(Object receiver, String property, Object[] args, + Object expectedValue) { + if ("isSingleFileHistory".equals(property)) { //$NON-NLS-1$ + GitHistoryPage page = getGitHistoryPage(receiver); + if (page == null) { + return false; + } + Object single = page.getInputInternal().getSingleFile(); + if (expectedValue instanceof String) { + if (expectedValue.equals("resource")) { //$NON-NLS-1$ + return single instanceof IResource; + } else if (expectedValue.equals("file")) { //$NON-NLS-1$ + return single instanceof File; + } + } else { + return computeResult(expectedValue, single != null); + } + } + return false; + } + + private GitHistoryPage getGitHistoryPage(Object receiver) { + if (!(receiver instanceof IHistoryView)) { + return null; + } + IHistoryPage page = ((IHistoryView) receiver).getHistoryPage(); + if (page instanceof GitHistoryPage) { + return (GitHistoryPage) page; + } + return null; + } + +} |