Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Wolf2019-07-20 10:51:13 -0400
committerMichael Keppler2019-08-27 12:27:58 -0400
commitafe4fddbb3bf7d523fba637ad7e523d837aef9e9 (patch)
tree0900e3bc03104f25376d1aa5236643471522490a /org.eclipse.egit.ui
parent478756d3a953d31ad0bb3912a50a21a5dc2e2243 (diff)
downloadegit-afe4fddbb3bf7d523fba637ad7e523d837aef9e9.tar.gz
egit-afe4fddbb3bf7d523fba637ad7e523d837aef9e9.tar.xz
egit-afe4fddbb3bf7d523fba637ad7e523d837aef9e9.zip
History view: shorten view toolbar
Combine the four filter buttons into one single button with a drop-down menu. Selecting the button itself cycles though the filters. Use the new FilterAction also in the view menu; to be able to do so implement ToolBarMenuAction.getMenu(Menu) and rename the class to DropDownMenuAction. Also, as long as one only updates the image of an action it isn't necessary to update the whole toolbar. The framework listens for such changes and updates the corresponding ToolItem or Menu entry already. Change-Id: If7fb1e3199cd1721a4455bac10925fc2922c5ba8 Signed-off-by: Thomas Wolf <thomas.wolf@paranor.ch>
Diffstat (limited to 'org.eclipse.egit.ui')
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java6
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/DropDownMenuAction.java (renamed from org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToolbarMenuAction.java)62
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositoryMenuUtil.java2
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java147
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties2
6 files changed, 179 insertions, 67 deletions
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
index 3287530e1..394df7030 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/UIText.java
@@ -640,6 +640,12 @@ public class UIText extends NLS {
public static String GitHistoryPage_FilterSubMenuLabel;
/** */
+ public static String GitHistoryPage_FilterTooltip;
+
+ /** */
+ public static String GitHistoryPage_FilterTooltipCurrent;
+
+ /** */
public static String GitHistoryPage_IncompleteListTooltip;
/** */
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToolbarMenuAction.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/DropDownMenuAction.java
index 799913e8e..ca8b3516e 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/ToolbarMenuAction.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/DropDownMenuAction.java
@@ -28,25 +28,27 @@ import org.eclipse.ui.actions.ActionFactory.IWorkbenchAction;
/**
* Specialized {@link Action} intended to be used in a
- * {@link org.eclipse.jface.action.ToolBarManager ToolBarManager} for buttons
- * with a drop-down menu. By default selecting the button itself will also show
- * the menu; if that is not desired, override {@link #runWithEvent(Event)} or
- * {@link #run()}.
+ * {@link org.eclipse.jface.action.IContributionManager IContributionManager}
+ * for actions with a drop-down menu. In a tool bar, selecting the button itself
+ * will by default also show the menu; if that is not desired, override
+ * {@link #runWithEvent(Event)} or {@link #run()}.
*/
-public abstract class ToolbarMenuAction extends Action
+public abstract class DropDownMenuAction extends Action
implements IWorkbenchAction, IMenuCreator {
- private Menu menu;
+ private Menu controlMenu;
+
+ private Menu subMenu;
private boolean showMenu;
/**
- * Creates a new {@link ToolbarMenuAction}.
+ * Creates a new {@link DropDownMenuAction}.
*
* @param title
* for the action
*/
- public ToolbarMenuAction(String title) {
+ public DropDownMenuAction(String title) {
super(title, IAction.AS_DROP_DOWN_MENU);
}
@@ -80,27 +82,35 @@ public abstract class ToolbarMenuAction extends Action
return this;
}
+ private Menu fillMenu(Menu m) {
+ for (IAction action : getActions()) {
+ ActionContributionItem item = new ActionContributionItem(action);
+ item.fill(m, -1);
+ }
+ return m;
+ }
+
+ private Menu dispose(Menu m) {
+ if (m != null) {
+ if (!m.isDisposed()) {
+ m.dispose();
+ }
+ }
+ return null;
+ }
+
@Override
public Menu getMenu(Menu parent) {
- // Not used
- return null;
+ subMenu = dispose(subMenu);
+ subMenu = fillMenu(new Menu(parent));
+ return subMenu;
}
@Override
public Menu getMenu(Control parent) {
- if (menu != null) {
- menu.dispose();
- menu = null;
- }
- if (isEnabled()) {
- menu = new Menu(parent);
- for (IAction action : getActions()) {
- ActionContributionItem item = new ActionContributionItem(
- action);
- item.fill(menu, -1);
- }
- }
- return menu;
+ controlMenu = dispose(controlMenu);
+ controlMenu = fillMenu(new Menu(parent));
+ return controlMenu;
}
/**
@@ -113,10 +123,8 @@ public abstract class ToolbarMenuAction extends Action
@Override
public void dispose() {
- if (menu != null) {
- menu.dispose();
- menu = null;
- }
+ controlMenu = dispose(controlMenu);
+ subMenu = dispose(subMenu);
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositoryMenuUtil.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositoryMenuUtil.java
index 01ec794a2..8c9ac25f7 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositoryMenuUtil.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/components/RepositoryMenuUtil.java
@@ -156,7 +156,7 @@ public final class RepositoryMenuUtil {
* menu of all registered repositories, performing a given action on a
* selected repository.
*/
- public static class RepositoryToolbarAction extends ToolbarMenuAction {
+ public static class RepositoryToolbarAction extends DropDownMenuAction {
private final RepositoryUtil util = org.eclipse.egit.core.Activator
.getDefault().getRepositoryUtil();
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
index 6b87ed98b..031792707 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/history/GitHistoryPage.java
@@ -22,8 +22,11 @@ package org.eclipse.egit.ui.internal.history;
import java.io.File;
import java.io.IOException;
+import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.HashSet;
import java.util.List;
@@ -61,6 +64,7 @@ import org.eclipse.egit.ui.internal.commit.DiffDocument;
import org.eclipse.egit.ui.internal.commit.DiffRegionFormatter;
import org.eclipse.egit.ui.internal.commit.DiffViewer;
import org.eclipse.egit.ui.internal.commit.FocusTracker;
+import org.eclipse.egit.ui.internal.components.DropDownMenuAction;
import org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkSourceViewer;
import org.eclipse.egit.ui.internal.dialogs.HyperlinkTokenScanner;
@@ -299,6 +303,122 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
}
}
+ private static class FilterAction extends DropDownMenuAction {
+
+ private final @NonNull List<IAction> actions;
+
+ private final IPropertyChangeListener listener;
+
+ private boolean childEnablement = true;
+
+ public FilterAction(IAction... actions) {
+ super(UIText.GitHistoryPage_FilterSubMenuLabel);
+ @SuppressWarnings("null")
+ @NonNull
+ List<IAction> a = actions == null ? Collections.emptyList()
+ : Arrays.asList(actions);
+ this.actions = a;
+ setToolTipText(UIText.GitHistoryPage_FilterTooltip);
+ listener = e -> {
+ if (IAction.ENABLED.equals(e.getProperty())) {
+ boolean previousEnablement = isEnabled();
+ childEnablement = FilterAction.this.actions.stream()
+ .anyMatch(act -> act.isEnabled());
+ boolean currentEnablement = isEnabled();
+ if (currentEnablement != previousEnablement) {
+ IAction currentChild = currentEnablement
+ ? FilterAction.this.actions.stream()
+ .filter(act -> act.isChecked())
+ .findFirst().orElse(null)
+ : null;
+ if (currentChild == null) {
+ setToolTipText(
+ UIText.GitHistoryPage_FilterTooltip);
+ } else {
+ setToolTipText(MessageFormat.format(
+ UIText.GitHistoryPage_FilterTooltipCurrent,
+ currentChild.getToolTipText()));
+ }
+ firePropertyChange(IAction.ENABLED,
+ Boolean.valueOf(previousEnablement),
+ Boolean.valueOf(currentEnablement));
+ }
+ } else if (IAction.CHECKED.equals(e.getProperty())) {
+ Object newValue = e.getNewValue();
+ boolean isChecked = false;
+ if (newValue instanceof Boolean) {
+ isChecked = ((Boolean) newValue).booleanValue();
+ } else if (newValue instanceof String) {
+ isChecked = Boolean.parseBoolean((String) newValue);
+ }
+ if (isChecked) {
+ Object source = e.getSource();
+ if (source instanceof IAction) {
+ if (isEnabled()) {
+ setToolTipText(MessageFormat.format(
+ UIText.GitHistoryPage_FilterTooltipCurrent,
+ ((IAction) source)
+ .getToolTipText()));
+ }
+ ImageDescriptor image = ((IAction) source)
+ .getImageDescriptor();
+ if (image != null) {
+ setImageDescriptor(image);
+ }
+ }
+ }
+ }
+ };
+ for (IAction action : this.actions) {
+ action.addPropertyChangeListener(listener);
+ }
+ }
+
+ @Override
+ protected Collection<IAction> getActions() {
+ return actions;
+ }
+
+ @Override
+ public boolean isEnabled() {
+ return super.isEnabled() && childEnablement;
+ }
+
+ @Override
+ public void dispose() {
+ for (IAction action : this.actions) {
+ action.removePropertyChangeListener(listener);
+ }
+ super.dispose();
+ }
+
+ @Override
+ public void run() {
+ if (!isEnabled()) {
+ return;
+ }
+ // Cycle through the available actions
+ int i = 1;
+ for (IAction action : actions) {
+ if (action.isChecked()) {
+ IAction next = actions.get(i % actions.size());
+ while (next != action) {
+ if (next.isEnabled()) {
+ action.setChecked(false);
+ next.setChecked(true);
+ next.run();
+ break;
+ }
+ i++;
+ next = actions.get(i % actions.size());
+ }
+ return;
+ }
+ i++;
+ }
+ }
+ }
+
List<IWorkbenchAction> actionsToDispose;
BooleanPrefAction showRelativeDateAction;
@@ -343,6 +463,8 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
ShowFilterAction showAllResourceVersionsAction;
+ FilterAction filterAction;
+
RepositoryToolbarAction switchRepositoryAction;
private GitHistoryPage historyPage;
@@ -480,6 +602,10 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
UIText.GitHistoryPage_AllOfResourceMenuLabel,
UIText.GitHistoryPage_AllOfResourceTooltip);
+ filterAction = new FilterAction(showAllRepoVersionsAction,
+ showAllProjectVersionsAction, showAllFolderVersionsAction,
+ showAllResourceVersionsAction);
+
showAllRepoVersionsAction
.setChecked(historyPage.showAllFilter == showAllRepoVersionsAction.filter);
showAllProjectVersionsAction
@@ -488,6 +614,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
.setChecked(historyPage.showAllFilter == showAllFolderVersionsAction.filter);
showAllResourceVersionsAction
.setChecked(historyPage.showAllFilter == showAllResourceVersionsAction.filter);
+ actionsToDispose.add(filterAction);
}
private void createCompareModeAction() {
@@ -1689,12 +1816,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
IToolBarManager mgr = getSite().getActionBars().getToolBarManager();
mgr.add(actions.findAction);
mgr.add(actions.switchRepositoryAction);
- mgr.add(new Separator());
- mgr.add(actions.showAllRepoVersionsAction);
- mgr.add(actions.showAllProjectVersionsAction);
- mgr.add(actions.showAllFolderVersionsAction);
- mgr.add(actions.showAllResourceVersionsAction);
- mgr.add(new Separator());
+ mgr.add(actions.filterAction);
mgr.add(actions.compareModeAction);
mgr.add(actions.showAllBranchesAction);
mgr.add(actions.showFirstParentOnlyAction);
@@ -1764,13 +1886,7 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
showInMessageManager.add(actions.wrapCommentAction);
showInMessageManager.add(actions.fillCommentAction);
- IMenuManager filterSubMenuMgr = new MenuManager(
- UIText.GitHistoryPage_FilterSubMenuLabel);
- viewMenuMgr.add(filterSubMenuMgr);
- filterSubMenuMgr.add(actions.showAllRepoVersionsAction);
- filterSubMenuMgr.add(actions.showAllProjectVersionsAction);
- filterSubMenuMgr.add(actions.showAllFolderVersionsAction);
- filterSubMenuMgr.add(actions.showAllResourceVersionsAction);
+ viewMenuMgr.add(actions.filterAction);
viewMenuMgr.add(new Separator());
viewMenuMgr.add(actions.compareModeAction);
@@ -2128,9 +2244,10 @@ public class GitHistoryPage extends HistoryPage implements RefsChangedListener,
// disable the filters if we have a Repository as input
boolean filtersActive = inResources != null || inFiles != null;
actions.showAllRepoVersionsAction.setEnabled(filtersActive);
- actions.showAllProjectVersionsAction.setEnabled(filtersActive);
// the repository itself has no notion of projects
- actions.showAllFolderVersionsAction.setEnabled(inResources != null);
+ actions.showAllProjectVersionsAction
+ .setEnabled(inResources != null);
+ actions.showAllFolderVersionsAction.setEnabled(filtersActive);
actions.showAllResourceVersionsAction.setEnabled(filtersActive);
setErrorMessage(null);
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
index 07d60b409..10ded25b6 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/staging/StagingView.java
@@ -94,7 +94,7 @@ import org.eclipse.egit.ui.internal.commit.CommitProposalProcessor;
import org.eclipse.egit.ui.internal.commit.DiffViewer;
import org.eclipse.egit.ui.internal.components.PartVisibilityListener;
import org.eclipse.egit.ui.internal.components.RepositoryMenuUtil.RepositoryToolbarAction;
-import org.eclipse.egit.ui.internal.components.ToolbarMenuAction;
+import org.eclipse.egit.ui.internal.components.DropDownMenuAction;
import org.eclipse.egit.ui.internal.decorators.ProblemLabelDecorator;
import org.eclipse.egit.ui.internal.dialogs.CommandConfirmation;
import org.eclipse.egit.ui.internal.dialogs.CommitMessageArea;
@@ -1554,7 +1554,6 @@ public class StagingView extends ViewPart
unstagedToolBarManager.add(stageAction);
unstagedToolBarManager.add(stageAllAction);
unstagedToolBarManager.add(presentationAction);
- presentationAction.setToolbar(unstagedToolBarManager);
unstagedToolBarManager.add(sortAction);
unstagedToolBarManager.add(unstagedExpandAllAction);
unstagedToolBarManager.add(unstagedCollapseAllAction);
@@ -1815,7 +1814,6 @@ public class StagingView extends ViewPart
default:
break;
}
- presentationAction.update();
}
private void updateToolbar() {
@@ -1969,12 +1967,7 @@ public class StagingView extends ViewPart
UIPreferences.STAGING_VIEW_FILENAME_MODE));
IMenuManager dropdownMenu = actionBars.getMenuManager();
- MenuManager presentationMenu = new MenuManager(
- UIText.StagingView_Presentation);
- presentationMenu.add(listPresentationAction);
- presentationMenu.add(treePresentationAction);
- presentationMenu.add(compactTreePresentationAction);
- dropdownMenu.add(presentationMenu);
+ dropdownMenu.add(presentationAction);
dropdownMenu.add(new Separator());
dropdownMenu.add(openNewCommitsAction);
dropdownMenu.add(columnLayoutAction);
@@ -4547,11 +4540,9 @@ public class StagingView extends ViewPart
}
- private static class PresentationAction extends ToolbarMenuAction
+ private static class PresentationAction extends DropDownMenuAction
implements IPropertyChangeListener {
- private ToolBarManager toolbar;
-
private final IPreferenceStore store;
private final @NonNull List<IAction> actions;
@@ -4572,10 +4563,6 @@ public class StagingView extends ViewPart
return actions;
}
- public void setToolbar(ToolBarManager toolbar) {
- this.toolbar = toolbar;
- }
-
@Override
public void dispose() {
store.removePropertyChangeListener(this);
@@ -4601,15 +4588,7 @@ public class StagingView extends ViewPart
default:
return;
}
- update();
}
}
-
- public void update() {
- if (toolbar != null) {
- toolbar.update(true);
- }
- }
-
}
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
index 741f0fb81..dbc7ada86 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/uitext.properties
@@ -232,6 +232,8 @@ GitHistoryPage_ShowFirstParentOnlyMenuLabel=First &Parent Only
GitHistoryPage_FollowRenames=&Follow Renames
GitHistoryPage_FormatDiffJobName=Updating Diff
GitHistoryPage_FilterSubMenuLabel=&Filter
+GitHistoryPage_FilterTooltip=Change the file scope for the history
+GitHistoryPage_FilterTooltipCurrent=Change the file scope for the history. Current: {0}
GitHistoryPage_IncompleteListTooltip=Not all commits are shown, the limit may be exceeded or the job building the list may have been aborted
GitHistoryPage_InRevisionCommentSubMenuLabel=&In Revision Comment
GitHistoryPage_ListIncompleteWarningMessage=The list is incomplete

Back to the top