diff --git a/bin/mac/libnst64.dylib b/bin/mac/libnst64.dylib index 0e2f0599dfe5..35e1d2507306 100755 Binary files a/bin/mac/libnst64.dylib and b/bin/mac/libnst64.dylib differ diff --git a/native/MacTouchBar/src/ButtonDesc.h b/native/MacTouchBar/src/ButtonDesc.h index dd23ea615529..ec4583236d1c 100644 --- a/native/MacTouchBar/src/ButtonDesc.h +++ b/native/MacTouchBar/src/ButtonDesc.h @@ -13,3 +13,7 @@ @interface ButtonTextDesc : ButtonDesc - (id)init:(NSString*)text act:(execute)act; @end + +@interface ButtonImgTextDesc : ButtonDesc +- (id)init:(NSImage *)img text:(NSString*)text act:(execute)act; +@end diff --git a/native/MacTouchBar/src/ButtonDesc.m b/native/MacTouchBar/src/ButtonDesc.m index d6a19c89339f..83f4e5190b4d 100644 --- a/native/MacTouchBar/src/ButtonDesc.m +++ b/native/MacTouchBar/src/ButtonDesc.m @@ -14,6 +14,11 @@ @property (retain, nonatomic) NSString * text; @end +@interface ButtonImgTextDesc() +@property (retain, nonatomic) NSImage * img; +@property (retain, nonatomic) NSString * text; +@end + @implementation ButtonDesc - (id)init:(execute)act { self = [super init]; @@ -61,3 +66,31 @@ @synthesize text; @end + +@implementation ButtonImgTextDesc +- (id)init:(NSImage *)img text:(NSString*)text act:(execute)act { + self = [super init:act]; + if (self) { + self.text = text; + self.img = img; + } + return self; +} +- (nullable __kindof NSTouchBarItem *)create { + nstrace(@"create button.imgAndText [%@]", self.uid); + + NSButton *button = [[[NSButton alloc] init] autorelease]; + [button setImagePosition:NSImageLeft]; + [button setImage:self.img]; + [button setTitle:self.text]; + [button setTarget:self]; + [button setAction:@selector(doAction)]; + [button setBezelStyle:NSRoundedBezelStyle]; + + NSCustomTouchBarItem *customItemForButton = [[[NSCustomTouchBarItem alloc] initWithIdentifier:self.uid] autorelease]; + customItemForButton.view = button; // NOTE: view is strong + return customItemForButton; +} +@synthesize img, text; +@end + diff --git a/native/MacTouchBar/src/PopoverDesc.m b/native/MacTouchBar/src/PopoverDesc.m index 0a9fbfeaab6d..9945ab406402 100644 --- a/native/MacTouchBar/src/PopoverDesc.m +++ b/native/MacTouchBar/src/PopoverDesc.m @@ -25,28 +25,15 @@ - (nullable __kindof NSTouchBarItem *)create { nstrace(@"create popover [%@]", self.uid); NSPopoverTouchBarItem * popoverTouchBarItem = [[[NSPopoverTouchBarItem alloc] initWithIdentifier:self.uid] autorelease]; + + if (self.img != nil) + popoverTouchBarItem.collapsedRepresentationImage = self.img; + if (self.text != nil) + popoverTouchBarItem.collapsedRepresentationLabel = self.text; + if (_width > 0) // Otherwise: create 'flexible' view + [popoverTouchBarItem.collapsedRepresentation.widthAnchor constraintEqualToConstant:_width].active = YES; + popoverTouchBarItem.showsCloseButton = YES; - - if (_width <= 0) { - // create 'flexible' view - if (self.img != nil) - popoverTouchBarItem.collapsedRepresentationImage = self.img; - if (self.text != nil) - popoverTouchBarItem.collapsedRepresentationLabel = self.text; - } else { - // create fixed width view - NSButton *button = [[[NSButton alloc] init] autorelease]; - [button setImagePosition:NSImageLeft]; - [button setImage:self.img]; - [button setTitle:self.text]; - [button setTarget:popoverTouchBarItem]; - [button setAction:@selector(showPopover:)]; - [button setBezelStyle:NSRoundedBezelStyle]; - [button.widthAnchor constraintEqualToConstant:_width].active = YES; - - popoverTouchBarItem.collapsedRepresentation = button; // strong - } - popoverTouchBarItem.popoverTouchBar = self.expandBar.touchBar; popoverTouchBarItem.pressAndHoldTouchBar = self.tapHoldBar.touchBar; return popoverTouchBarItem; diff --git a/native/MacTouchBar/src/TouchBar.m b/native/MacTouchBar/src/TouchBar.m index 6ebfb88aa9d0..8e6c86738aae 100644 --- a/native/MacTouchBar/src/TouchBar.m +++ b/native/MacTouchBar/src/TouchBar.m @@ -110,6 +110,16 @@ id registerButtonImg(id tbobj, char* raster4ByteRGBA, int w, int h, execute acti return bdesc; } +id registerButtonImgText(id tbobj, char* text, char* raster4ByteRGBA, int w, int h, execute action) { + if (w <= 0 || h <= 0) { + nserror(@"incorrect image sizes"); + return nil; + } + ButtonDesc * bdesc = [[[ButtonImgTextDesc alloc] init:createImgFrom4ByteRGBA((unsigned char *)raster4ByteRGBA, w, h) text:[NSString stringWithUTF8String:text] act:action] autorelease]; + [(TouchBar *)tbobj registerItem:bdesc]; + return bdesc; +} + id registerSpacing(id tbobj, char* type) { SpacingDesc * spdesc = [[[SpacingDesc alloc] init:[NSString stringWithUTF8String:type]] autorelease]; [(TouchBar *)tbobj registerItem:spdesc]; diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NSTLibrary.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NSTLibrary.java index 74faa15989f2..620b180cdf60 100644 --- a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NSTLibrary.java +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/NSTLibrary.java @@ -16,6 +16,7 @@ public interface NSTLibrary extends Library { ID registerSpacing(ID tbObj, String type); // allowed types: 'small', 'large', 'flexible' ID registerButtonText(ID tbObj, String text, Action action); ID registerButtonImg(ID tbObj, byte[] raster4ByteRGBA, int w, int h, Action action); + ID registerButtonImgText(ID tbObj, String text, byte[] raster4ByteRGBA, int w, int h, Action action); ID registerPopover(ID tbObj, String text, byte[] raster4ByteRGBA, int w, int h, int popW); void setPopoverExpandTouchBar(ID popoverObj, ID expandTbObj); void setPopoverTapAndHoldTouchBar(ID popoverObj, ID tapHoldTbObj); diff --git a/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TBItemButtonImgText.java b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TBItemButtonImgText.java new file mode 100644 index 000000000000..6c88c696526e --- /dev/null +++ b/platform/platform-impl/src/com/intellij/ui/mac/touchbar/TBItemButtonImgText.java @@ -0,0 +1,25 @@ +// 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.ui.mac.foundation.ID; + +import javax.swing.*; + +public class TBItemButtonImgText extends TBItemButton { + private final Icon myIcon; + private final String myText; + + public TBItemButtonImgText(Icon icon, String text, NSTLibrary.Action action) { + super(action); + myIcon = icon; + myText = text; + } + + @Override + protected ID _register(ID tbOwner) { + return TouchBarManager.getNSTLibrary().registerButtonImgText( + tbOwner, myText, NSTLibrary.getRasterFromIcon(myIcon), + myIcon.getIconWidth(), myIcon.getIconHeight(), myAction + ); + } +}