mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-163208: fixes for popover
1. fixed width popover via layout constrints 2. add ButtonImgText (to use as tap-and-hold item)
This commit is contained in:
Binary file not shown.
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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;
|
||||
|
||||
@@ -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];
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user