From 24cde879cb8d544bbcda76d680d42f54f214266e Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Tue, 15 Nov 2016 18:48:54 +0300 Subject: [PATCH] [vcs]: change GitLocalBranch and RootAction rendering * create common interface for popupElements woth additional info text; --- .../dvcs/ui/BranchActionGroupPopup.java | 37 +++++++++++-------- .../ui/PopupElementWithAdditionalInfo.java | 23 ++++++++++++ .../src/com/intellij/dvcs/ui/RootAction.java | 15 ++++---- .../ui/branch/GitBranchPopupActions.java | 18 ++++----- 4 files changed, 61 insertions(+), 32 deletions(-) create mode 100644 platform/dvcs-impl/src/com/intellij/dvcs/ui/PopupElementWithAdditionalInfo.java diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java index b64c6e837624..1aa9d7bb5e9b 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/ui/BranchActionGroupPopup.java @@ -22,6 +22,7 @@ import com.intellij.openapi.actionSystem.impl.SimpleDataContext; import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.popup.PopupStep; import com.intellij.openapi.util.Condition; +import com.intellij.openapi.vcs.ui.FlatSpeedSearchPopup; import com.intellij.ui.ErrorLabel; import com.intellij.ui.JBColor; import com.intellij.ui.components.panels.OpaquePanel; @@ -30,7 +31,6 @@ import com.intellij.ui.popup.WizardPopup; import com.intellij.ui.popup.list.PopupListElementRenderer; import com.intellij.util.ui.JBUI; import com.intellij.util.ui.UIUtil; -import com.intellij.openapi.vcs.ui.FlatSpeedSearchPopup; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; @@ -92,10 +92,14 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { @Nullable private static RootAction getRootAction(Object value) { + return getSpecificAction(value, RootAction.class); + } + + private static T getSpecificAction(Object value, @NotNull Class clazz) { if (value instanceof PopupFactoryImpl.ActionItem) { AnAction action = ((PopupFactoryImpl.ActionItem)value).getAction(); - if (action instanceof RootAction) { - return (RootAction)action; + if (clazz.isInstance(action)) { + return clazz.cast(action); } } return null; @@ -105,27 +109,28 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { protected ListCellRenderer getListElementRenderer() { return new PopupListElementRenderer(this) { - private ErrorLabel myBranchLabel; + private ErrorLabel myInfoLabel; @Override protected void customizeComponent(JList list, Object value, boolean isSelected) { super.customizeComponent(list, value, isSelected); - RootAction rootAction = getRootAction(value); - if (rootAction != null) { - myBranchLabel.setVisible(true); - myBranchLabel.setText(String.format("[%s]", rootAction.getDisplayableBranchText())); + PopupElementWithAdditionalInfo additionalInfoAction = getSpecificAction(value, PopupElementWithAdditionalInfo.class); + String infoText = additionalInfoAction != null ? additionalInfoAction.getInfoText() : null; + if (infoText != null) { + myInfoLabel.setVisible(true); + myInfoLabel.setText(infoText); if (isSelected) { - setSelected(myBranchLabel); + setSelected(myInfoLabel); } else { - myBranchLabel.setBackground(getBackground()); - myBranchLabel.setForeground(JBColor.GRAY); // different foreground than for other elements + myInfoLabel.setBackground(getBackground()); + myInfoLabel.setForeground(JBColor.GRAY); // different foreground than for other elements } } else { - myBranchLabel.setVisible(false); + myInfoLabel.setVisible(false); } } @@ -135,13 +140,13 @@ public class BranchActionGroupPopup extends FlatSpeedSearchPopup { myTextLabel.setOpaque(true); myTextLabel.setBorder(JBUI.Borders.empty(1)); - myBranchLabel = new ErrorLabel(); - myBranchLabel.setOpaque(true); - myBranchLabel.setBorder(JBUI.Borders.empty(1, UIUtil.DEFAULT_HGAP, 1, 1)); + myInfoLabel = new ErrorLabel(); + myInfoLabel.setOpaque(true); + myInfoLabel.setBorder(JBUI.Borders.empty(1, UIUtil.DEFAULT_HGAP, 1, 1)); JPanel compoundPanel = new OpaquePanel(new BorderLayout(), JBColor.WHITE); compoundPanel.add(myTextLabel, BorderLayout.CENTER); - compoundPanel.add(myBranchLabel, BorderLayout.EAST); + compoundPanel.add(myInfoLabel, BorderLayout.EAST); return layoutComponent(compoundPanel); } diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/ui/PopupElementWithAdditionalInfo.java b/platform/dvcs-impl/src/com/intellij/dvcs/ui/PopupElementWithAdditionalInfo.java new file mode 100644 index 000000000000..d59929095a9f --- /dev/null +++ b/platform/dvcs-impl/src/com/intellij/dvcs/ui/PopupElementWithAdditionalInfo.java @@ -0,0 +1,23 @@ +/* + * Copyright 2000-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.dvcs.ui; + +import org.jetbrains.annotations.Nullable; + +public interface PopupElementWithAdditionalInfo { + @Nullable + String getInfoText(); +} diff --git a/platform/dvcs-impl/src/com/intellij/dvcs/ui/RootAction.java b/platform/dvcs-impl/src/com/intellij/dvcs/ui/RootAction.java index 93e49042648c..86fa16fe6baa 100644 --- a/platform/dvcs-impl/src/com/intellij/dvcs/ui/RootAction.java +++ b/platform/dvcs-impl/src/com/intellij/dvcs/ui/RootAction.java @@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable; * @author Kirill Likhodedov * @author Nadya Zabrodina */ -public class RootAction extends ActionGroup { +public class RootAction extends ActionGroup implements PopupElementWithAdditionalInfo { @NotNull protected final T myRepository; @NotNull private final ActionGroup myGroup; @@ -55,12 +55,7 @@ public class RootAction extends ActionGroup { @NotNull public String getCaption() { - return "Current branch in " + DvcsUtil.getShortRepositoryName(myRepository) + ": " + getDisplayableBranchText(); - } - - @NotNull - public String getDisplayableBranchText() { - return myBranchText; + return "Current branch in " + DvcsUtil.getShortRepositoryName(myRepository) + ": " + getInfoText(); } @NotNull @@ -68,6 +63,12 @@ public class RootAction extends ActionGroup { public AnAction[] getChildren(@Nullable AnActionEvent e) { return myGroup.getChildren(e); } + + @NotNull + @Override + public String getInfoText() { + return myBranchText; + } } diff --git a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java index bcd99c3ebdf0..dd21294af289 100644 --- a/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java +++ b/plugins/git4idea/src/git4idea/ui/branch/GitBranchPopupActions.java @@ -17,6 +17,7 @@ package git4idea.ui.branch; import com.intellij.dvcs.ui.BranchActionGroup; import com.intellij.dvcs.ui.NewBranchAction; +import com.intellij.dvcs.ui.PopupElementWithAdditionalInfo; import com.intellij.openapi.actionSystem.ActionGroup; import com.intellij.openapi.actionSystem.AnAction; import com.intellij.openapi.actionSystem.AnActionEvent; @@ -27,7 +28,6 @@ import com.intellij.openapi.project.Project; import com.intellij.openapi.ui.Messages; import com.intellij.openapi.util.Condition; import com.intellij.util.containers.ContainerUtil; -import com.intellij.util.ui.UIUtil; import git4idea.GitBranch; import git4idea.branch.GitBranchUtil; import git4idea.branch.GitBrancher; @@ -142,7 +142,7 @@ class GitBranchPopupActions { /** * Actions available for local branches. */ - static class LocalBranchActions extends BranchActionGroup { + static class LocalBranchActions extends BranchActionGroup implements PopupElementWithAdditionalInfo { private final Project myProject; private final List myRepositories; @@ -160,13 +160,7 @@ class GitBranchPopupActions { @NotNull private String calcBranchText() { - String trackedBranch = new GitMultiRootBranchConfig(myRepositories).getTrackedBranch(myBranchName); - if (trackedBranch != null) { - return myBranchName + " " + UIUtil.rightArrow() + " " + trackedBranch; - } - else { - return myBranchName; - } + return myBranchName; } @NotNull @@ -194,6 +188,12 @@ class GitBranchPopupActions { }; } + @Override + @Nullable + public String getInfoText() { + return new GitMultiRootBranchConfig(myRepositories).getTrackedBranch(myBranchName); + } + static class CheckoutAction extends DumbAwareAction { private final Project myProject; private final List myRepositories;