Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
- Set the device selector component to opaque during its creation to avoid an unexpected background color (#8471)
- Refactored `DeviceSelectorAction` and add rich icons to different platform devices (#8475)
- Fix DTD freezes when opening projects, and EDT freezes when the theme is changed and opening embedded DevTools (#8477)
- Fix `DeviceSelectorAction` `NoSuchElementException` in the toolbar layout (#8515)

## 87.1.0

Expand Down
2 changes: 2 additions & 0 deletions src/io/flutter/FlutterBundle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,8 @@ flutter.io.gettingStarted.IDE.url=https://docs.flutter.dev/tools/android-studio
flutter.io.runAndDebug.url=https://docs.flutter.dev/tools/android-studio#running-and-debugging

devicelist.loading=Loading...
devicelist.noDevices=<no devices>
devicelist.noDeviceSelected=<no device selected>

flutter.pop.frame.action.text=Drop Frame (Flutter)
flutter.pop.frame.action.description=Pop the current frame off the stack
Expand Down
38 changes: 31 additions & 7 deletions src/io/flutter/actions/DeviceSelectorAction.java
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ public class DeviceSelectorAction extends AnAction implements CustomComponentAct
private static final Key<JBLabel> ICON_LABEL_KEY = Key.create("iconLabel");
private static final Key<JBLabel> TEXT_LABEL_KEY = Key.create("textLabel");
private static final Key<JBLabel> ARROW_LABEL_KEY = Key.create("arrowLabel");
private static final @NotNull Icon DEFAULT_DEVICE_ICON = FlutterIcons.Mobile;
private static final @NotNull Icon DEFAULT_ARROW_ICON = IconUtil.scale(AllIcons.General.ChevronDown, null, 1.2f);

private final List<AnAction> actions = new ArrayList<>();
private final List<Project> knownProjects = Collections.synchronizedList(new ArrayList<>());
Expand Down Expand Up @@ -87,9 +89,9 @@ public void actionPerformed(@NotNull AnActionEvent e) {

@Override
public @NotNull JComponent createCustomComponent(@NotNull Presentation presentation, @NotNull String place) {
final JBLabel iconLabel = new JBLabel(FlutterIcons.Mobile);
final JBLabel iconLabel = new JBLabel(DEFAULT_DEVICE_ICON);
final JBLabel textLabel = new JBLabel();
final JBLabel arrowLabel = new JBLabel(IconUtil.scale(AllIcons.General.ChevronDown, null, 1.2f));
final JBLabel arrowLabel = new JBLabel(DEFAULT_ARROW_ICON);

// Create a wrapper button for hover effects
final JButton button = new JButton() {
Expand Down Expand Up @@ -119,17 +121,39 @@ public Dimension getPreferredSize() {
width += icon.getIconWidth();
height = Math.max(height, icon.getIconHeight());
}
else {
// Fallback: use the default mobile icon size when the component is not fully initialized
final Icon defaultIcon = DEFAULT_DEVICE_ICON;
width += defaultIcon.getIconWidth();
height = Math.max(height, defaultIcon.getIconHeight());
}

final @Nullable FontMetrics fm;
final @NotNull String textLabelText;
if (textLabel instanceof JBLabel label && label.getText() instanceof String text && !text.isEmpty()) {
final FontMetrics fm = label.getFontMetrics(label.getFont());
width += Objects.requireNonNull(fm).stringWidth(text);
fm = label.getFontMetrics(label.getFont());
textLabelText = text;
}
else {
// Fallback: estimate width for typical device name length
fm = getFontMetrics(getFont());
textLabelText = FlutterBundle.message("devicelist.noDevices");
}
if (fm != null) {
width += fm.stringWidth(textLabelText);
height = Math.max(height, fm.getHeight());
}

if (arrowLabel instanceof JBLabel label && label.getIcon() instanceof Icon icon) {
width += icon.getIconWidth();
height = Math.max(height, icon.getIconHeight());
}
else {
// Fallback: use the default arrow icon size
final Icon defaultArrow = DEFAULT_ARROW_ICON;
width += defaultArrow.getIconWidth();
height = Math.max(height, defaultArrow.getIconHeight());
}

width += JBUI.scale(24);
height += JBUI.scale(8);
Expand Down Expand Up @@ -278,19 +302,19 @@ public void projectClosing(@NotNull Project project) {
final Collection<FlutterDevice> devices = deviceService.getConnectedDevices();

final String text;
Icon icon = FlutterIcons.Mobile;
Icon icon = DEFAULT_DEVICE_ICON;

if (devices.isEmpty()) {
final boolean isLoading = deviceService.getStatus() == DeviceService.State.LOADING;
if (isLoading) {
text = FlutterBundle.message("devicelist.loading");
}
else {
text = "<no devices>";
text = FlutterBundle.message("devicelist.noDevices");
}
}
else if (selectedDevice == null) {
text = "<no device selected>";
text = FlutterBundle.message("devicelist.noDeviceSelected");
}
else {
text = selectedDevice.presentationName();
Expand Down