mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
IDEA-163208: use principal group-item to center main confirmation buttons of dialog
This commit is contained in:
Binary file not shown.
@@ -53,7 +53,7 @@ static void _setButtonData(NSButtonJAction *button, int updateOptions, int butto
|
||||
|
||||
if (updateOptions & BUTTON_UPDATE_FLAGS) {
|
||||
if (buttonFlags & BUTTON_FLAG_COLORED) {
|
||||
button.bezelColor = NSColor.blueColor;
|
||||
button.bezelColor = [NSColor colorWithRed:0 green:130/255.f blue:215/255.f alpha:1];
|
||||
} else if (buttonFlags & BUTTON_FLAG_SELECTED) {
|
||||
button.bezelColor = NSColor.selectedControlColor;
|
||||
} else {
|
||||
|
||||
@@ -73,10 +73,27 @@ id createTouchBar(const char * name, createItem jcreator, const char * escId) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void setPrincipal(id tbobj, const char * uid) {
|
||||
TouchBar * tb = (TouchBar *)tbobj; // TODO: check types
|
||||
[tb.touchBar setPrincipalItemIdentifier:getString(uid)];
|
||||
}
|
||||
|
||||
void releaseTouchBar(id tbobj) {
|
||||
[tbobj release];
|
||||
}
|
||||
|
||||
id createGroupItem(const char * uid, id * items, int count) {
|
||||
NSMutableArray *allItems = [NSMutableArray arrayWithCapacity:count];
|
||||
for (int c = 0; c < count; ++c)
|
||||
[allItems addObject:items[c]];
|
||||
|
||||
NSGroupTouchBarItem * result = [NSGroupTouchBarItem groupItemWithIdentifier:getString(uid) items:allItems];
|
||||
// NOTE: should create non-autorelease object to be owned by java-wrapper
|
||||
// the simplest way to create working NSGroupTouchBarItem with fixed item set is to call groupItemWithIdentifier, which creates autorelease object, so do retain..
|
||||
[result retain];
|
||||
return result;
|
||||
}
|
||||
|
||||
void setTouchBar(id tb) {
|
||||
dispatch_async(dispatch_get_main_queue(), ^{
|
||||
[[NSApplication sharedApplication] setTouchBar:((TouchBar *) tb).touchBar];
|
||||
|
||||
@@ -772,7 +772,7 @@ public abstract class DialogWrapper {
|
||||
}
|
||||
|
||||
@NotNull
|
||||
private static Pair<Integer, String> extractMnemonic(@Nullable String text) {
|
||||
public static Pair<Integer, String> extractMnemonic(@Nullable String text) {
|
||||
if (text == null) return Pair.create(0, null);
|
||||
|
||||
int mnemonic = 0;
|
||||
|
||||
@@ -88,6 +88,10 @@ public class NST {
|
||||
ourNSTLibrary.selectItemsToShow(tbObj, ids, count);
|
||||
}
|
||||
|
||||
public static void setPrincipal(ID tbObj, String uid) {
|
||||
ourNSTLibrary.setPrincipal(tbObj, uid);
|
||||
}
|
||||
|
||||
public static ID createButton(String uid,
|
||||
int buttWidth,
|
||||
int buttFlags,
|
||||
@@ -117,6 +121,10 @@ public class NST {
|
||||
return ourNSTLibrary.createScrubber(uid, itemWidth, items, count);
|
||||
}
|
||||
|
||||
public static ID createGroupItem(String uid, ID[] items, int count) {
|
||||
return ourNSTLibrary.createGroupItem(uid, items, count);
|
||||
}
|
||||
|
||||
public static void updateButton(ID buttonObj,
|
||||
int updateOptions,
|
||||
int buttWidth,
|
||||
|
||||
@@ -15,6 +15,7 @@ public interface NSTLibrary extends Library {
|
||||
void releaseTouchBar(ID tbObj);
|
||||
void setTouchBar(ID tbObj);
|
||||
void selectItemsToShow(ID tbObj, String[] ids, int count);
|
||||
void setPrincipal(ID tbObj, String uid);
|
||||
|
||||
interface Action extends Callback {
|
||||
void execute();
|
||||
@@ -44,6 +45,7 @@ public interface NSTLibrary extends Library {
|
||||
ID createButton(String uid, int buttWidth, int buttonFlags, String text, byte[] raster4ByteRGBA, int w, int h, Action action);
|
||||
ID createPopover(String uid, int itemWidth, String text, byte[] raster4ByteRGBA, int w, int h, ID tbObjExpand, ID tbObjTapAndHold);
|
||||
ID createScrubber(String uid, int itemWidth, ScrubberItemData[] items, int count);
|
||||
ID createGroupItem(String uid, ID[] items, int count);
|
||||
|
||||
int BUTTON_UPDATE_WIDTH = 1;
|
||||
int BUTTON_UPDATE_FLAGS = 1 << 1;
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
// 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 org.jetbrains.annotations.NotNull;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TBItemGroup extends TBItem {
|
||||
private final List<TBItem> myGroupItems = new ArrayList<>();
|
||||
|
||||
TBItemGroup(@NotNull String uid, @NotNull List<TBItem> items) {
|
||||
super(uid);
|
||||
myGroupItems.addAll(items);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void _updateNativePeer() { myGroupItems.forEach(item->item._updateNativePeer()); }
|
||||
|
||||
@Override
|
||||
protected ID _createNativePeer() {
|
||||
if (myGroupItems.isEmpty())
|
||||
return ID.NIL;
|
||||
|
||||
final ID[] ids = myGroupItems.stream().map(item->item.getNativePeer()).toArray(size -> new ID[size]);
|
||||
return NST.createGroupItem(myUid, ids, ids.length);
|
||||
}
|
||||
}
|
||||
@@ -92,6 +92,12 @@ public class TouchBar implements NSTLibrary.ItemCreator {
|
||||
return butt;
|
||||
}
|
||||
|
||||
public TBItemGroup addGroup(List<TBItem> items) {
|
||||
final TBItemGroup group = new TBItemGroup(_genNewID("group"), items);
|
||||
myItems.add(group);
|
||||
return group;
|
||||
}
|
||||
|
||||
public TBItemPopover addPopover(Icon icon, String text, int width, TouchBar expandTB, TouchBar tapAndHoldTB) {
|
||||
final TBItemPopover popover = new TBItemPopover(_genNewID("popover"), icon, text, width, expandTB, tapAndHoldTB);
|
||||
myItems.add(popover);
|
||||
@@ -131,6 +137,8 @@ public class TouchBar implements NSTLibrary.ItemCreator {
|
||||
NST.selectItemsToShow(myNativePeer, ids, ids.length);
|
||||
}
|
||||
|
||||
public void setPrincipal(@NotNull TBItem item) { NST.setPrincipal(myNativePeer, item.myUid); }
|
||||
|
||||
public void onBeforeShow() {}
|
||||
public void onHide() {}
|
||||
|
||||
|
||||
@@ -265,6 +265,8 @@ public class TouchBarsManager {
|
||||
try (NSAutoreleaseLock lock = new NSAutoreleaseLock()) {
|
||||
TouchBarActionBase result = new TouchBarActionBase("dialog_buttons", project, null);
|
||||
final ModalityState ms = LaterInvocator.getCurrentModalityState();
|
||||
|
||||
// 1. add option buttons (at left)
|
||||
for (JButton jb : jbuttons) {
|
||||
if (jb instanceof JBOptionButton) {
|
||||
JBOptionButton ob = (JBOptionButton)jb;
|
||||
@@ -282,12 +284,25 @@ public class TouchBarsManager {
|
||||
if (ag.getChildrenCount() > 0)
|
||||
result.addActionGroupButtons(ag, ob, ms);
|
||||
}
|
||||
}
|
||||
|
||||
// 2. add main buttons and make principal
|
||||
final List<TBItem> groupButtons = new ArrayList<>();
|
||||
for (JButton jb : jbuttons) {
|
||||
// TODO: make correct processing for disabled buttons, add them and update state by timer
|
||||
// NOTE: can be true: jb.getAction().isEnabled() && !jb.isEnabled()
|
||||
final NSTLibrary.Action act = () -> ApplicationManager.getApplication().invokeLater(() -> jb.doClick(), ms);
|
||||
final boolean isDefault = jb.getAction().getValue(DialogWrapper.DEFAULT_ACTION) != null;
|
||||
result.addButton(null, jb.getText(), act, isDefault ? NSTLibrary.BUTTON_FLAG_COLORED : 0);
|
||||
final TBItemButton butt = new TBItemButton(
|
||||
"dialog_buttons_group_item_" + jbuttons.indexOf(jb),
|
||||
null, DialogWrapper.extractMnemonic(jb.getText()).second, act, -1, isDefault ? NSTLibrary.BUTTON_FLAG_COLORED : 0
|
||||
);
|
||||
groupButtons.add(butt);
|
||||
}
|
||||
|
||||
final TBItemGroup gr = result.addGroup(groupButtons);
|
||||
result.setPrincipal(gr);
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user