mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[vcs]: change GitLocalBranch and RootAction rendering
* create common interface for popupElements woth additional info text;
This commit is contained in:
@@ -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> T getSpecificAction(Object value, @NotNull Class<T> 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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
@@ -31,7 +31,7 @@ import org.jetbrains.annotations.Nullable;
|
||||
* @author Kirill Likhodedov
|
||||
* @author Nadya Zabrodina
|
||||
*/
|
||||
public class RootAction<T extends Repository> extends ActionGroup {
|
||||
public class RootAction<T extends Repository> extends ActionGroup implements PopupElementWithAdditionalInfo {
|
||||
|
||||
@NotNull protected final T myRepository;
|
||||
@NotNull private final ActionGroup myGroup;
|
||||
@@ -55,12 +55,7 @@ public class RootAction<T extends Repository> 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<T extends Repository> extends ActionGroup {
|
||||
public AnAction[] getChildren(@Nullable AnActionEvent e) {
|
||||
return myGroup.getChildren(e);
|
||||
}
|
||||
|
||||
@NotNull
|
||||
@Override
|
||||
public String getInfoText() {
|
||||
return myBranchText;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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<GitRepository> 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<GitRepository> myRepositories;
|
||||
|
||||
Reference in New Issue
Block a user