From 14ac3efaab9305704a864903de54c76e33dd4043 Mon Sep 17 00:00:00 2001 From: Mathias Kinzler Date: Thu, 18 Mar 2010 17:28:50 +0100 Subject: [PATCH] Allow to use the repository name in Git Label Decorations Currently, the Git (text-) label decorations include variables for dirty, staged, and branch. Since there are many repositories with the same "master" branch, we should have a "repository name" variable. This should be the name of the repository's directory. While not necessarily unique, this helps in identifying the repository in the project explorer. Bug: 306397 Change-Id: I08f8bc2681fc2440ca684bd1735a4a0d7468cea6 Signed-off-by: Mathias Kinzler Signed-off-by: Matthias Sohn --- .../src/org/eclipse/egit/ui/UIText.java | 3 ++ .../decorators/DecoratableResourceAdapter.java | 12 ++++++++ .../decorators/GitLightweightDecorator.java | 4 +++ .../internal/decorators/IDecoratableResource.java | 8 +++++ .../preferences/GitDecoratorPreferencePage.java | 35 ++++++++++++++-------- .../src/org/eclipse/egit/ui/uitext.properties | 1 + 6 files changed, 50 insertions(+), 13 deletions(-) diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java index 6d154646..6926529b 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/UIText.java @@ -124,6 +124,9 @@ public class UIText extends NLS { public static String GitCloneWizard_errorCannotCreate; /** */ + public static String GitDecoratorPreferencePage_bindingRepositoryNameFlag; + + /** */ public static String GitHistoryPage_CompareVersions; /** */ diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java index f83134c3..2cf5b8bd 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/DecoratableResourceAdapter.java @@ -61,6 +61,8 @@ class DecoratableResourceAdapter implements IDecoratableResource { private String branch = ""; //$NON-NLS-1$ + private final String repositoryName; + private boolean tracked = false; private boolean ignored = false; @@ -89,6 +91,12 @@ class DecoratableResourceAdapter implements IDecoratableResource { store = Activator.getDefault().getPreferenceStore(); + File gitDir = repository.getDirectory(); + if (gitDir != null) + repositoryName = repository.getDirectory().getParentFile() + .getName(); + else + repositoryName = ""; //$NON-NLS-1$ // TODO: Add option to shorten branch name to 6 chars if it's a SHA branch = repository.getBranch(); @@ -379,6 +387,10 @@ class DecoratableResourceAdapter implements IDecoratableResource { return resource.getType(); } + public String getRepositoryName() { + return repositoryName; + } + public String getBranch() { return branch; } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java index 8e9083c2..446fe6b5 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/GitLightweightDecorator.java @@ -231,6 +231,9 @@ public class GitLightweightDecorator extends LabelProvider implements public static final String BINDING_BRANCH_NAME = "branch"; //$NON-NLS-1$ /** */ + public static final String BINDING_REPOSITORY_NAME = "repository"; //$NON-NLS-1$ + + /** */ public static final String BINDING_DIRTY_FLAG = "dirty"; //$NON-NLS-1$ /** */ @@ -355,6 +358,7 @@ public class GitLightweightDecorator extends LabelProvider implements Map bindings = new HashMap(); bindings.put(BINDING_RESOURCE_NAME, resource.getName()); + bindings.put(BINDING_REPOSITORY_NAME, resource.getRepositoryName()); bindings.put(BINDING_BRANCH_NAME, resource.getBranch()); bindings.put(BINDING_DIRTY_FLAG, resource.isDirty() ? ">" : null); //$NON-NLS-1$ bindings.put(BINDING_STAGED_FLAG, diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/IDecoratableResource.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/IDecoratableResource.java index b45a13c9..6ab99a14 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/IDecoratableResource.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/decorators/IDecoratableResource.java @@ -47,6 +47,14 @@ public interface IDecoratableResource { String getName(); /** + * Gets the name of the repository of the resource + * + * @return the name of the current branch, or null if not + * applicable + */ + String getRepositoryName(); + + /** * Gets the current branch of the resource if applicable * * @return the name of the current branch, or null if not diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java index fb1462eb..908cd254 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/preferences/GitDecoratorPreferencePage.java @@ -102,42 +102,42 @@ public class GitDecoratorPreferencePage extends PreferencePage implements static { final PreviewResource project = new PreviewResource( - "Project", IResource.PROJECT, "master", true, false, true, Staged.NOT_STAGED, false, false); //$NON-NLS-1$ //$NON-NLS-2$1 + "Project", IResource.PROJECT, "repository", "master", true, false, true, Staged.NOT_STAGED, false, false); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ final ArrayList children = new ArrayList(); children .add(new PreviewResource( - "folder", IResource.FOLDER, null, true, false, true, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ + "folder", IResource.FOLDER, "repository", null, true, false, true, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "tracked.txt", IResource.FILE, null, true, false, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ + "tracked.txt", IResource.FILE, "repository", null, true, false, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "untracked.txt", IResource.FILE, null, false, false, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ + "untracked.txt", IResource.FILE, "repository", null, false, false, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "ignored.txt", IResource.FILE, null, false, true, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ + "ignored.txt", IResource.FILE, "repository", null, false, true, false, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "dirty.txt", IResource.FILE, null, true, false, true, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ + "dirty.txt", IResource.FILE, "repository", null, true, false, true, Staged.NOT_STAGED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "staged.txt", IResource.FILE, null, true, false, false, Staged.MODIFIED, false, false)); //$NON-NLS-1$ + "staged.txt", IResource.FILE, "repository", null, true, false, false, Staged.MODIFIED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "partially-staged.txt", IResource.FILE, null, true, false, true, Staged.MODIFIED, false, false)); //$NON-NLS-1$ + "partially-staged.txt", IResource.FILE, "repository", null, true, false, true, Staged.MODIFIED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "added.txt", IResource.FILE, null, true, false, false, Staged.ADDED, false, false)); //$NON-NLS-1$ + "added.txt", IResource.FILE, "repository", null, true, false, false, Staged.ADDED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "removed.txt", IResource.FILE, null, true, false, false, Staged.REMOVED, false, false)); //$NON-NLS-1$ + "removed.txt", IResource.FILE, "repository", null, true, false, false, Staged.REMOVED, false, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "conflict.txt", IResource.FILE, null, true, false, true, Staged.NOT_STAGED, true, false)); //$NON-NLS-1$ + "conflict.txt", IResource.FILE, "repository", null, true, false, true, Staged.NOT_STAGED, true, false)); //$NON-NLS-1$ //$NON-NLS-2$ children .add(new PreviewResource( - "assume-valid.txt", IResource.FILE, null, true, false, false, Staged.NOT_STAGED, false, true)); //$NON-NLS-1$ + "assume-valid.txt", IResource.FILE, "repository", null, true, false, false, Staged.NOT_STAGED, false, true)); //$NON-NLS-1$ //$NON-NLS-2$ project.children = children; PREVIEW_FILESYSTEM_ROOT = Collections.singleton(project); @@ -156,6 +156,8 @@ public class GitDecoratorPreferencePage extends PreferencePage implements UIText.DecoratorPreferencesPage_bindingDirtyFlag); PROJECT_BINDINGS.put(DecorationHelper.BINDING_STAGED_FLAG, UIText.DecoratorPreferencesPage_bindingStagedFlag); + PROJECT_BINDINGS.put(DecorationHelper.BINDING_REPOSITORY_NAME, + UIText.GitDecoratorPreferencePage_bindingRepositoryNameFlag); PROJECT_BINDINGS.put(DecorationHelper.BINDING_BRANCH_NAME, UIText.DecoratorPreferencesPage_bindingBranchName); } @@ -800,6 +802,8 @@ public class GitDecoratorPreferencePage extends PreferencePage implements private static class PreviewResource implements IDecoratableResource { private final String name; + private final String repositoryName; + private final String branch; private final int type; @@ -818,11 +822,12 @@ public class GitDecoratorPreferencePage extends PreferencePage implements private boolean assumeValid; - public PreviewResource(String name, int type, String branch, + public PreviewResource(String name, int type, String repositoryName, String branch, boolean tracked, boolean ignored, boolean dirty, Staged staged, boolean conflicts, boolean assumeValid) { this.name = name; + this.repositoryName = repositoryName; this.branch = branch; this.type = type; this.children = Collections.EMPTY_LIST; @@ -838,6 +843,10 @@ public class GitDecoratorPreferencePage extends PreferencePage implements return name; } + public String getRepositoryName() { + return repositoryName; + } + public int getType() { return type; } diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties index 01e95f29..b2aca2a7 100644 --- a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties +++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/uitext.properties @@ -46,6 +46,7 @@ GitCloneWizard_title=Import Git Repository GitCloneWizard_jobName=Cloning from {0} GitCloneWizard_failed=Git repository clone failed. GitCloneWizard_errorCannotCreate=Cannot create directory {0}. +GitDecoratorPreferencePage_bindingRepositoryNameFlag=name of the repository GitHistoryPage_CompareVersions=Compare with each other GitHistoryPage_CompareWithWorking=Compare with working tree GitHistoryPage_FileNotInCommit={0} not in {1} -- 2.11.4.GIT