Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlexander Nittka2019-11-17 09:20:06 +0000
committerMichael Keppler2019-11-22 07:04:44 +0000
commit45bc68761130dda2ddbd806ab23f8922d932b74b (patch)
tree1a0cc13ace793af35996b99bd655d7fe7e6305e2
parentf15d363905a3798b5fc4bf35c6ee35587e2f46da (diff)
downloadegit-45bc68761130dda2ddbd806ab23f8922d932b74b.tar.gz
egit-45bc68761130dda2ddbd806ab23f8922d932b74b.tar.xz
egit-45bc68761130dda2ddbd806ab23f8922d932b74b.zip
[repo view] Add collapse working tree command
If link with selection is enabled the working tree might be expanded quite deeply. Collapse all may be too extreme as the user may want to keep expanded repository groups/branches etc. open. With the left arrow key, you can go up and close one level at a time, which is slow. This change adds a short cut for collapsing the entire working tree in one step (ctrl+left arrow key). Change-Id: Ib797583cef03655ae73c5ed474718cf7bd6e1b33 Signed-off-by: Alexander Nittka <alex@nittka.de>
-rw-r--r--org.eclipse.egit.ui/plugin.properties2
-rw-r--r--org.eclipse.egit.ui/plugin.xml27
-rw-r--r--org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CollapseWorkingTreeCommand.java56
3 files changed, 85 insertions, 0 deletions
diff --git a/org.eclipse.egit.ui/plugin.properties b/org.eclipse.egit.ui/plugin.properties
index 52d3b1ffa..f59ae3afb 100644
--- a/org.eclipse.egit.ui/plugin.properties
+++ b/org.eclipse.egit.ui/plugin.properties
@@ -265,6 +265,8 @@ RepoViewFilterSubmodules.label = Submodules
RepoViewFilterSubmodules.description = Hides Submodules
RepoViewFilterWorktree.label = Working Tree
RepoViewFilterWorktree.description = Hides Working Tree
+RepoViewCollapseWorktreeCommand.label = Collapse Working Tree
+RepoViewCollapseWorktreeCommand.description = Collapse the complete Working Tree of the current Repositories View selection
AddToIndexCommand.name = Add to Index
RemoveFromIndexCommand.name = Remove from Index
BranchCommand.name = Branch
diff --git a/org.eclipse.egit.ui/plugin.xml b/org.eclipse.egit.ui/plugin.xml
index 019a8abfe..b99ce978a 100644
--- a/org.eclipse.egit.ui/plugin.xml
+++ b/org.eclipse.egit.ui/plugin.xml
@@ -3116,6 +3116,21 @@
</with>
</activeWhen>
</handler>
+ <handler
+ commandId="org.eclipse.egit.ui.RepositoriesViewCollapseWorkingTree">
+ <class
+ class="org.eclipse.egit.ui.internal.repository.tree.command.CollapseWorkingTreeCommand">
+ </class>
+ <activeWhen>
+ <iterate>
+ <or>
+ <instanceof value="org.eclipse.egit.ui.internal.repository.tree.FileNode" />
+ <instanceof value="org.eclipse.egit.ui.internal.repository.tree.FolderNode" />
+ <instanceof value="org.eclipse.egit.ui.internal.repository.tree.WorkingDirNode" />
+ </or>
+ </iterate>
+ </activeWhen>
+ </handler>
</extension>
<extension
point="org.eclipse.ui.views">
@@ -6029,6 +6044,12 @@
id="org.eclipse.egit.ui.RepositoriesViewDelete"
name="%DeleteRepositoryCommand.name">
</command>
+ <command
+ categoryId="org.eclipse.egit.ui.commandCategory"
+ id="org.eclipse.egit.ui.RepositoriesViewCollapseWorkingTree"
+ name="%RepoViewCollapseWorktreeCommand.label">
+ description="%RepoViewCollapseWorktreeCommand.description">
+ </command>
<command
categoryId="org.eclipse.egit.ui.commandCategory"
id="org.eclipse.egit.ui.RepositoriesCreateGroup"
@@ -6794,6 +6815,12 @@
schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
sequence="F2">
</key>
+ <key
+ commandId="org.eclipse.egit.ui.RepositoriesViewCollapseWorkingTree"
+ contextId="org.eclipse.egit.ui.RepositoriesView"
+ schemeId="org.eclipse.ui.defaultAcceleratorConfiguration"
+ sequence="M1+ARROW_LEFT">
+ </key>
</extension>
<extension
name="%HistoryViewCommands.extension.name"
diff --git a/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CollapseWorkingTreeCommand.java b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CollapseWorkingTreeCommand.java
new file mode 100644
index 000000000..c9ef7abd6
--- /dev/null
+++ b/org.eclipse.egit.ui/src/org/eclipse/egit/ui/internal/repository/tree/command/CollapseWorkingTreeCommand.java
@@ -0,0 +1,56 @@
+/*******************************************************************************
+ * Copyright (C) 2019, Alexander Nittka <alex@nittka.de>
+ *
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License 2.0
+ * which accompanies this distribution, and is available at
+ * https://www.eclipse.org/legal/epl-2.0/
+ *
+ * SPDX-License-Identifier: EPL-2.0
+ *******************************************************************************/
+package org.eclipse.egit.ui.internal.repository.tree.command;
+
+import java.util.List;
+import java.util.Objects;
+import java.util.Set;
+import java.util.stream.Collectors;
+
+import org.eclipse.core.commands.ExecutionEvent;
+import org.eclipse.core.commands.ExecutionException;
+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.WorkingDirNode;
+import org.eclipse.jface.viewers.AbstractTreeViewer;
+import org.eclipse.ui.navigator.CommonViewer;
+
+/**
+ * Collapse the working directory ancestors of the current repositories view
+ * selection.
+ */
+public class CollapseWorkingTreeCommand
+ extends RepositoriesViewCommandHandler<RepositoryTreeNode<?>> {
+
+ @Override
+ public Object execute(ExecutionEvent event) throws ExecutionException {
+ List<RepositoryTreeNode<?>> nodes = getSelectedNodes();
+ Set<WorkingDirNode> nodesToCollapse = nodes.stream()
+ .map(this::getWorkingDirParent).filter(Objects::nonNull)
+ .collect(Collectors.toSet());
+ if (!nodesToCollapse.isEmpty()) {
+ CommonViewer viewer = getView(event).getCommonViewer();
+ for (WorkingDirNode node : nodesToCollapse) {
+ viewer.collapseToLevel(node, AbstractTreeViewer.ALL_LEVELS);
+ }
+ }
+ return null;
+ }
+
+ private WorkingDirNode getWorkingDirParent(RepositoryTreeNode<?> node) {
+ RepositoryTreeNode<?> candidate = node;
+ while (candidate != null
+ && candidate.getType() != RepositoryTreeNodeType.WORKINGDIR) {
+ candidate = candidate.getParent();
+ }
+ return (WorkingDirNode) candidate;
+ }
+}

Back to the top