summaryrefslogtreecommitdiffstatsabout
diff options
context:
space:
mode:
authorKevin Sawicki2011-05-03 16:29:14 (EDT)
committer Kevin Sawicki2011-05-03 16:29:14 (EDT)
commit2b5e376932e3fb9a60ae4886b3f4efeb3a5ef38c (patch)
tree0e917ebe7a4fb95230de957c1174fcdfd83947d5
parente1971b1e5c1e5c3c3c81ca23a854eb0a6d50a6c3 (diff)
downloadegit-2b5e376932e3fb9a60ae4886b3f4efeb3a5ef38c.zip
egit-2b5e376932e3fb9a60ae4886b3f4efeb3a5ef38c.tar.gz
egit-2b5e376932e3fb9a60ae4886b3f4efeb3a5ef38c.tar.bz2
[repoView] Add commit message decorations to ref nodes.refs/changes/25/3325/3
Bug: 344639 Change-Id: I70a5c1afb2d65581e90642f726625ad0b670cceb Signed-off-by: Kevin Sawicki <kevin@github.com>
-rw-r--r--org.eclipse.egit.ui/plugin.properties3
-rw-r--r--org.eclipse.egit.ui/plugin.xml24
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java79
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/ToggleBranchCommitCommand.java47
4 files changed, 146 insertions, 7 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 17e409f..72e2daa 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -215,8 +215,11 @@ RepoViewLinkWithSelectionMenu.label = Link with &Selection
RepoViewCreateRepositoryCommand.name = Create a Repository
CreateRepositoryWizard.name = Git Repository
HierarchyLayout.label = &Hierarchical Branch Layout
+BranchCommit.label = &Display Latest Branch Commit
ToggleLayoutCommand.name = Toggle Branch Representation
+ToggleBranchCommitCommand.name = Toggle Latest Branch Commit
RepoViewHierarchicalBranchRepresenation.tooltip = Hierarchical Branch Layout
+RepoViewBranchCommit.tooltip = Display Latest Branch Commit
ConfigureTraceCommand.name = Configure Git Debug Trace
PullIntoCurrentBranchMenuLabel = P&ull
CherryPickCommand.name = CherryPick
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 5d601a9..5a2e112 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -2314,6 +2314,11 @@
style="toggle"
tooltip="%RepoViewHierarchicalBranchRepresenation.tooltip">
</command>
+ <command
+ commandId="org.eclipse.egit.ui.RepositoriesToggleBranchCommit"
+ style="toggle"
+ tooltip="%RepoViewBranchCommit.tooltip">
+ </command>
</menuContribution>
<menuContribution
locationURI="menu:org.eclipse.egit.ui.RepositoriesView">
@@ -2355,6 +2360,11 @@
label="%HierarchyLayout.label"
style="toggle">
</command>
+ <command
+ commandId="org.eclipse.egit.ui.RepositoriesToggleBranchCommit"
+ label="%BranchCommit.label"
+ style="toggle">
+ </command>
</menuContribution>
<menuContribution
locationURI="popup:org.eclipse.ui.popup.any?after=additions">
@@ -2841,6 +2851,16 @@
id="org.eclipse.ui.commands.toggleState">
</state>
</command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ defaultHandler="org.eclipse.egit.ui.internal.repository.tree.command.ToggleBranchCommitCommand"
+ id="org.eclipse.egit.ui.RepositoriesToggleBranchCommit"
+ name="%ToggleBranchCommitCommand.name">
+ <state
+ class="org.eclipse.ui.handlers.RegistryToggleState:false"
+ id="org.eclipse.ui.commands.toggleState">
+ </state>
+ </command>
<command
categoryId="org.eclipse.egit.ui.commandCategory"
defaultHandler="org.eclipse.egit.ui.internal.commands.shared.RebaseCurrentRefCommand"
@@ -2956,6 +2976,10 @@
commandId="org.eclipse.egit.ui.RepositoriesToggleBranchHierarchy"
icon="icons/elcl16/hierarchicalLayout.gif">
</image>
+ <image
+ commandId="org.eclipse.egit.ui.RepositoriesToggleBranchCommit"
+ icon="icons/obj16/changelog_obj.gif">
+ </image>
<image
commandId="org.eclipse.egit.ui.RepositoriesViewRemove"
icon="icons/obj16/clear.gif">
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
index 41e83e1..c8e097b 100644
--- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/RepositoriesViewLabelProvider.java
@@ -16,6 +16,8 @@ import java.io.IOException;
import java.util.HashMap;
import java.util.Map;
+import org.eclipse.core.commands.IStateListener;
+import org.eclipse.core.commands.State;
import org.eclipse.core.runtime.IPath;
import org.eclipse.egit.core.Activator;
import org.eclipse.egit.ui.UIIcons;
@@ -23,10 +25,11 @@ import org.eclipse.egit.ui.UIText;
import org.eclipse.egit.ui.internal.SWTUtils;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNodeType;
+import org.eclipse.egit.ui.internal.repository.tree.command.ToggleBranchCommitCommand;
import org.eclipse.jface.resource.CompositeImageDescriptor;
+import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.StyledString;
-import org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider;
import org.eclipse.jgit.errors.MissingObjectException;
import org.eclipse.jgit.lib.Constants;
import org.eclipse.jgit.lib.ObjectId;
@@ -40,12 +43,14 @@ import org.eclipse.jgit.revwalk.RevWalk;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
+import org.eclipse.ui.PlatformUI;
+import org.eclipse.ui.commands.ICommandService;
/**
* Label Provider for the Git Repositories View
*/
public class RepositoriesViewLabelProvider extends LabelProvider implements
- IStyledLabelProvider {
+ IStyledLabelProvider, IStateListener {
/**
* A map of regular images to their decorated counterpart.
@@ -57,6 +62,27 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
private Image lightweightTagImage = SWTUtils.getDecoratedImage(tagImage,
UIIcons.OVR_LIGHTTAG);
+ private final State verboseBranchModeState;
+
+ private boolean verboseBranchMode = false;
+
+ /**
+ * Constructs a repositories view label provider
+ */
+ public RepositoriesViewLabelProvider() {
+ ICommandService srv = (ICommandService) PlatformUI.getWorkbench()
+ .getService(ICommandService.class);
+ verboseBranchModeState = srv.getCommand(ToggleBranchCommitCommand.ID)
+ .getState(ToggleBranchCommitCommand.TOGGLE_STATE);
+ verboseBranchModeState.addListener(this);
+ try {
+ this.verboseBranchMode = ((Boolean) verboseBranchModeState
+ .getValue()).booleanValue();
+ } catch (Exception e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ }
+
@Override
public Image getImage(Object element) {
RepositoryTreeNode node = (RepositoryTreeNode) element;
@@ -99,6 +125,7 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
@Override
public void dispose() {
+ verboseBranchModeState.removeListener(this);
// dispose of our decorated images
for (Image image : decoratedImages.values()) {
image.dispose();
@@ -210,6 +237,18 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
return decoratedImage;
}
+ private RevCommit getLatestCommit(RepositoryTreeNode node) {
+ RevWalk walk = new RevWalk(node.getRepository());
+ walk.setRetainBody(true);
+ try {
+ return walk.parseCommit(((Ref) node.getObject()).getObjectId());
+ } catch (IOException ignored) {
+ return null;
+ } finally {
+ walk.release();
+ }
+ }
+
public StyledString getStyledText(Object element) {
if (!(element instanceof RepositoryTreeNode))
return null;
@@ -269,6 +308,23 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
.getAbsolutePath(), StyledString.QUALIFIER_STYLER);
}
return dirString;
+
+ case REF:
+ // fall through
+ case TAG:
+ StyledString styled = null;
+ String nodeText = getSimpleText(node);
+ if (nodeText != null) {
+ styled = new StyledString(nodeText);
+ if (verboseBranchMode) {
+ RevCommit latest = getLatestCommit(node);
+ if (latest != null)
+ styled.append(' ' + latest.abbreviate(7).name()
+ + ' ' + latest.getShortMessage(),
+ StyledString.QUALIFIER_STYLER);
+ }
+ }
+ return styled;
case PUSH:
// fall through
case FETCH:
@@ -293,11 +349,7 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
// fall through
case REMOTE:
// fall through
- case ERROR:
- // fall through
- case REF:
- // fall through
- case TAG: {
+ case ERROR: {
String label = getSimpleText(node);
if (label != null)
return new StyledString(label);
@@ -388,4 +440,17 @@ public class RepositoriesViewLabelProvider extends LabelProvider implements
return null;
}
+ /**
+ * @see org.eclipse.core.commands.IStateListener#handleStateChange(org.eclipse.core.commands.State,
+ * java.lang.Object)
+ */
+ public void handleStateChange(State state, Object oldValue) {
+ try {
+ this.verboseBranchMode = ((Boolean) state.getValue())
+ .booleanValue();
+ } catch (Exception e) {
+ Activator.logError(e.getMessage(), e);
+ }
+ }
+
}
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/ToggleBranchCommitCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/ToggleBranchCommitCommand.java
new file mode 100644
index 0000000..1cff83f
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/ToggleBranchCommitCommand.java
@@ -0,0 +1,47 @@
+/*******************************************************************************
+ * Copyright (c) 2011 GitHub Inc.
+ * 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
+ *
+ * Contributors:
+ * Kevin Sawicki (GitHub Inc.) - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.repository.tree.command;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+import org.eclipse.egit.ui.internal.repository.RepositoriesView;
+import org.eclipse.egit.ui.internal.repository.tree.RepositoryTreeNode;
+import org.eclipse.ui.IWorkbenchPart;
+import org.eclipse.ui.handlers.HandlerUtil;
+
+/**
+ * Toggles the "Display Latest Branch Commit" preference
+ */
+public class ToggleBranchCommitCommand extends
+ RepositoriesViewCommandHandler<RepositoryTreeNode> {
+
+ /**
+ * The toggle branch latest commit command id
+ */
+ public static final String ID = "org.eclipse.egit.ui.RepositoriesToggleBranchCommit"; //$NON-NLS-1$
+
+ /**
+ * The toggle state of this command
+ */
+ public static final String TOGGLE_STATE = "org.eclipse.ui.commands.toggleState"; //$NON-NLS-1$
+
+ /**
+ * @see org.eclipse.core.commands.IHandler#execute(org.eclipse.core.commands.ExecutionEvent)
+ */
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ HandlerUtil.toggleCommandState(event.getCommand());
+ IWorkbenchPart part = HandlerUtil.getActivePartChecked(event);
+ if (part instanceof RepositoriesView)
+ (((RepositoriesView) part).getCommonViewer()).refresh();
+ return null;
+ }
+
+}