MacBook touch bar: remove arrow-icon from 'Add configuration' button (of default touchbar)

also hide run-buttons when configuration isn't defined
fixed point 3 from IDEA-194893 MacBook touch bar: improve Configurations popover
This commit is contained in:
Artem Bochkarev
2018-07-16 17:32:42 +07:00
parent 23e9412db6
commit 607d3cc44d
6 changed files with 84 additions and 19 deletions

Binary file not shown.

View File

@@ -403,15 +403,23 @@ void updateButton(
void setArrowImage(id buttObj, const char *raster4ByteRGBA, int w, int h) {
NSCustomTouchBarItem *container = buttObj; // TODO: check types
NSButtonJAction *button = (container).view; // TODO: check types
NSAutoreleasePool *edtPool = [NSAutoreleasePool new];
if (raster4ByteRGBA == NULL || w <= 0) {
[button setArrowImg:nil];
return;
NSImage *img = nil;
if (raster4ByteRGBA != NULL && w > 0)
img = createImgFrom4ByteRGBA((const unsigned char *) raster4ByteRGBA, w, h);
if ([NSThread isMainThread]) {
[button setArrowImg:img];
//NSLog(@"sync set arrow: w=%d h=%d", w, h);
} else {
dispatch_async(dispatch_get_main_queue(), ^{
// NOTE: block is copied, img/text objects is automatically retained
// nstrace(@"\tperform update button [%@] (thread: %@)", container.identifier, [NSThread currentThread]);
[button setArrowImg:img];
//NSLog(@"async set arrow: w=%d h=%d", w, h);
});
}
NSAutoreleasePool *edtPool = [NSAutoreleasePool new];
NSImage *img = createImgFrom4ByteRGBA((const unsigned char *) raster4ByteRGBA, w, h);
[button setArrowImg:img];
//NSLog(@"set arrow: w=%d h=%d", w, h);
[edtPool release];
}

View File

@@ -113,7 +113,6 @@ id createScrubber(const char* uid, int itemWidth, ScrubberItemData * items, int
[scrubber registerClass:[ScrubberItemView class] forItemIdentifier:g_scrubberItemIdentifier];
scrubber.showsAdditionalContentIndicators = NO;// For the image scrubber, we want the control to draw a fade effect to indicate that there is additional unscrolled content.
scrubber.selectedIndex = -1;
NSScrubberFlowLayout *scrubberLayout = [[[NSScrubberFlowLayout alloc] init] autorelease];
@@ -123,6 +122,7 @@ id createScrubber(const char* uid, int itemWidth, ScrubberItemData * items, int
scrubber.mode = NSScrubberModeFree;
scrubber.showsArrowButtons = NO;
scrubber.showsAdditionalContentIndicators = YES;
scrubber.selectionOverlayStyle = nil;
[scrubber.widthAnchor constraintGreaterThanOrEqualToConstant:itemWidth].active = YES;

View File

@@ -48,13 +48,14 @@ class BuildUtils {
private static final String ourLargeSeparatorText = "type.large";
private static final String ourFlexibleSeparatorText = "type.flexible";
private static final int ourRunConfigurationPopoverWidth = 143;
private static final int BUTTON_MIN_WIDTH_DLG = 107;
private static final int BUTTON_BORDER = 16;
private static final int BUTTON_IMAGE_MARGIN = 2;
static void addActionGroupButtons(@NotNull TouchBar out, @NotNull ActionGroup actionGroup, @Nullable String filterGroupPrefix, @Nullable Customizer customizer) {
_traverse(actionGroup, new GroupVisitor(out, filterGroupPrefix, customizer));
if (customizer != null)
customizer.finish();
}
static ActionGroup getCustomizedGroup(@NotNull String barId) {
@@ -401,6 +402,9 @@ class BuildUtils {
private final int myShowMode;
private final @Nullable ModalityState myModality;
private TBItemAnActionButton myRunConfigurationButton;
private List<TBItemAnActionButton> myRunnerButtons;
Customizer(int showMode, @Nullable ModalityState modality) {
myShowMode = showMode;
myModality = modality;
@@ -430,15 +434,23 @@ class BuildUtils {
butt.setHiddenWhenDisabled(true);
if (isRunConfigPopover) {
myRunConfigurationButton = butt;
} else if (butt.getAnAction() instanceof WelcomePopupAction) {
butt.setHasArrowIcon(true);
butt.setLayout(ourRunConfigurationPopoverWidth, 0, 5, 8);
} else if (butt.getAnAction() instanceof WelcomePopupAction)
butt.setHasArrowIcon(true);
} else if ("RunnerActionsTouchbar".equals(ni.getParentGroupID()) || "Stop".equals(actId)) {
if (myRunnerButtons == null) myRunnerButtons = new ArrayList<>();
myRunnerButtons.add(butt);
}
final TouchbarDataKeys.ActionDesc actionDesc = butt.getAnAction().getTemplatePresentation().getClientProperty(TouchbarDataKeys.ACTIONS_DESCRIPTOR_KEY);
if (actionDesc != null && actionDesc.getContextComponent() != null)
butt.setComponent(actionDesc.getContextComponent());
}
void finish() {
if (myRunConfigurationButton != null && myRunnerButtons != null && !myRunnerButtons.isEmpty())
myRunConfigurationButton.setLinkedButtons(myRunnerButtons);
}
}
static @Nullable String getActionId(AnAction act) {

View File

@@ -1,6 +1,7 @@
// Copyright 2000-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license that can be found in the LICENSE file.
package com.intellij.ui.mac.touchbar;
import com.intellij.icons.AllIcons;
import com.intellij.ide.DataManager;
import com.intellij.openapi.actionSystem.*;
import com.intellij.openapi.actionSystem.ex.ActionManagerEx;
@@ -16,10 +17,13 @@ import javax.swing.*;
import java.awt.*;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import java.util.List;
import static java.awt.event.ComponentEvent.COMPONENT_FIRST;
class TBItemAnActionButton extends TBItemButton {
private static final int ourRunConfigurationPopoverWidth = 143;
public static final int SHOWMODE_IMAGE_ONLY = 0;
public static final int SHOWMODE_TEXT_ONLY = 1;
public static final int SHOWMODE_IMAGE_TEXT = 2;
@@ -34,13 +38,12 @@ class TBItemAnActionButton extends TBItemButton {
private boolean myAutoVisibility = true;
private boolean myHiddenWhenDisabled = false;
private Component myComponent;
private @Nullable Component myComponent;
private @Nullable List<TBItemAnActionButton> myLinkedButtons;
TBItemAnActionButton(@NotNull String uid, @Nullable ItemListener listener, @NotNull AnAction action) {
super(uid, listener);
myAnAction = action;
myActionId = ApplicationManager.getApplication() == null ? action.toString() : ActionManager.getInstance().getId(myAnAction);
setAnAction(action);
setModality(null);
if (action instanceof Toggleable) {
@@ -55,6 +58,8 @@ class TBItemAnActionButton extends TBItemButton {
TBItemAnActionButton setModality(ModalityState modality) { setAction(this::_performAction, true, modality); return this; }
TBItemAnActionButton setShowMode(int showMode) { myShowMode = showMode; return this; }
void setLinkedButtons(@Nullable List<TBItemAnActionButton> linkedButtons) { myLinkedButtons = linkedButtons; }
void updateAnAction(Presentation presentation) {
if (ApplicationManager.getApplication() == null) {
if (myComponent instanceof JButton) {
@@ -83,7 +88,11 @@ class TBItemAnActionButton extends TBItemButton {
void setHiddenWhenDisabled(boolean hiddenWhenDisabled) { myHiddenWhenDisabled = hiddenWhenDisabled; }
@NotNull AnAction getAnAction() { return myAnAction; }
void setAnAction(@NotNull AnAction newAction) { myAnAction = newAction; } // can be safely replaced without setAction (because _performAction will use updated reference to AnAction)
void setAnAction(@NotNull AnAction newAction) {
// can be safely replaced without setAction (because _performAction will use updated reference to AnAction)
myAnAction = newAction;
myActionId = ApplicationManager.getApplication() == null ? newAction.toString() : ActionManager.getInstance().getId(newAction);
}
// returns true when visibility changed
boolean updateVisibility(Presentation presentation) { // called from EDT
@@ -91,11 +100,14 @@ class TBItemAnActionButton extends TBItemButton {
return false;
final boolean isVisible = presentation.isVisible() && (presentation.isEnabled() || !myHiddenWhenDisabled);
final boolean visibilityChanged = isVisible != myIsVisible;
boolean visibilityChanged = isVisible != myIsVisible;
if (visibilityChanged) {
myIsVisible = isVisible;
// System.out.println(String.format("%s: visibility changed, now is [%s]", toString(), isVisible ? "visible" : "hidden"));
}
if ("RunConfiguration".equals(myActionId))
visibilityChanged = visibilityChanged || _setLinkedVisibility(presentation.getIcon() != AllIcons.General.Add);
return visibilityChanged;
}
void updateView(Presentation presentation) { // called from EDT
@@ -119,6 +131,15 @@ class TBItemAnActionButton extends TBItemButton {
final Object selectedProp = presentation.getClientProperty(Toggleable.SELECTED_PROPERTY);
isSelected = selectedProp != null && selectedProp == Boolean.TRUE;
}
if ("RunConfiguration".equals(myActionId)) {
if (presentation.getIcon() != AllIcons.General.Add) {
setHasArrowIcon(true);
setLayout(ourRunConfigurationPopoverWidth, 0, 5, 8);
} else {
setHasArrowIcon(false);
setLayout(0, 0, 5, 8);
}
}
final boolean hideText = myShowMode == SHOWMODE_IMAGE_ONLY || (myShowMode == SHOWMODE_IMAGE_ONLY_IF_PRESENTED && icon != null);
final String text = hideText ? null : presentation.getText();
@@ -126,6 +147,19 @@ class TBItemAnActionButton extends TBItemButton {
update(icon, text, isSelected, !presentation.isEnabled());
}
private boolean _setLinkedVisibility(boolean visible) {
if (myLinkedButtons == null)
return false;
boolean visibilityChanged = false;
for (TBItemAnActionButton butt: myLinkedButtons) {
if (butt.myAutoVisibility != visible)
visibilityChanged = true;
butt.setAutoVisibility(visible);
butt.myIsVisible = visible;
}
return visibilityChanged;
}
private void _performAction() {
if (ApplicationManager.getApplication() == null) {
if (myComponent instanceof JButton)
@@ -147,6 +181,8 @@ class TBItemAnActionButton extends TBItemButton {
private static Component _getCurrentFocusComponent() {
final KeyboardFocusManager focusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
Component focusOwner = focusManager.getFocusOwner();
if (focusOwner == null)
focusOwner = focusManager.getPermanentFocusOwner();
if (focusOwner == null) {
// LOG.info(String.format("WARNING: [%s:%s] _getCurrentFocusContext: null focus-owner, use focused window", myUid, myActionId));
return focusManager.getFocusedWindow();

View File

@@ -40,7 +40,16 @@ class TBItemButton extends TBItem {
return this;
}
TBItemButton setHasArrowIcon(boolean hasArrowIcon) { myHasArrowIcon = hasArrowIcon; return this; }
TBItemButton setHasArrowIcon(boolean hasArrowIcon) {
if (hasArrowIcon != myHasArrowIcon) {
myHasArrowIcon = hasArrowIcon;
if (myNativePeer != ID.NIL) {
final Icon ic = myHasArrowIcon ? IconLoader.getIcon("/mac/touchbar/popoverArrow_dark.svg") : null;
NST.setArrowImage(myNativePeer, ic);
}
}
return this;
}
TBItemButton setText(String text) {
if (!Comparing.equal(text, myText)) {