From cc6a0b5302fa4d081d0deb39ab0bf7772e9cf4a7 Mon Sep 17 00:00:00 2001 From: Japnit Singh Date: Sat, 24 May 2025 01:39:57 -0400 Subject: [PATCH 1/3] Functioning fix for the run/debug icon. --- .../src/io/flutter/run/LaunchState.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/flutter-idea/src/io/flutter/run/LaunchState.java b/flutter-idea/src/io/flutter/run/LaunchState.java index 2b37d5a44a..b5b534e8e8 100644 --- a/flutter-idea/src/io/flutter/run/LaunchState.java +++ b/flutter-idea/src/io/flutter/run/LaunchState.java @@ -32,6 +32,10 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.BadgeIcon; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugProcessStarter; import com.intellij.xdebugger.XDebugSession; @@ -49,6 +53,8 @@ import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; +import javax.swing.*; +import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -152,6 +158,30 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(env); final RunContentDescriptor descriptor; if (launchMode.supportsDebugConnection()) { + ToolWindowManager manager = ToolWindowManager.getInstance(project); + ToolWindow runToolWindow = manager.getToolWindow(ToolWindowId.RUN); + ToolWindow debugToolWindow = manager.getToolWindow(ToolWindowId.DEBUG); + Paint badgePaint = Color.decode("#5ca963"); + + if(app.getMode() == RunMode.RUN) { + if (runToolWindow != null) { + manager.invokeLater(() -> { + Icon baseIcon = AllIcons.Toolwindows.ToolWindowRun; + BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, badgePaint); + + runToolWindow.setIcon(iconWithBadge); + }); + } + } + else if(app.getMode() == RunMode.DEBUG) { + manager.invokeLater(() -> { + Icon baseIcon = AllIcons.Toolwindows.ToolWindowDebugger; + BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, badgePaint); + + debugToolWindow.setIcon(iconWithBadge); + }); + } + descriptor = createDebugSession(env, app, result).getRunContentDescriptor(); } else { From f3140061f10b72f7bb00c1b17207c0293b0d5027 Mon Sep 17 00:00:00 2001 From: Japnit Singh Date: Sat, 24 May 2025 14:41:27 -0400 Subject: [PATCH 2/3] New file to handle icon update. --- .../src/io/flutter/run/LaunchState.java | 32 +------------ .../toolwindow/ToolWindowBadgeUpdater.java | 48 +++++++++++++++++++ 2 files changed, 50 insertions(+), 30 deletions(-) create mode 100644 flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java diff --git a/flutter-idea/src/io/flutter/run/LaunchState.java b/flutter-idea/src/io/flutter/run/LaunchState.java index b5b534e8e8..0e3fc18ba7 100644 --- a/flutter-idea/src/io/flutter/run/LaunchState.java +++ b/flutter-idea/src/io/flutter/run/LaunchState.java @@ -32,10 +32,6 @@ import com.intellij.openapi.util.Key; import com.intellij.openapi.util.text.StringUtil; import com.intellij.openapi.vfs.VirtualFile; -import com.intellij.openapi.wm.ToolWindow; -import com.intellij.openapi.wm.ToolWindowId; -import com.intellij.openapi.wm.ToolWindowManager; -import com.intellij.ui.BadgeIcon; import com.intellij.xdebugger.XDebugProcess; import com.intellij.xdebugger.XDebugProcessStarter; import com.intellij.xdebugger.XDebugSession; @@ -50,11 +46,10 @@ import io.flutter.run.daemon.DaemonConsoleView; import io.flutter.run.daemon.DeviceService; import io.flutter.run.daemon.FlutterApp; +import io.flutter.toolwindow.ToolWindowBadgeUpdater; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; -import javax.swing.*; -import java.awt.*; import java.lang.reflect.Field; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; @@ -158,30 +153,7 @@ protected RunContentDescriptor launch(@NotNull ExecutionEnvironment env) throws final FlutterLaunchMode launchMode = FlutterLaunchMode.fromEnv(env); final RunContentDescriptor descriptor; if (launchMode.supportsDebugConnection()) { - ToolWindowManager manager = ToolWindowManager.getInstance(project); - ToolWindow runToolWindow = manager.getToolWindow(ToolWindowId.RUN); - ToolWindow debugToolWindow = manager.getToolWindow(ToolWindowId.DEBUG); - Paint badgePaint = Color.decode("#5ca963"); - - if(app.getMode() == RunMode.RUN) { - if (runToolWindow != null) { - manager.invokeLater(() -> { - Icon baseIcon = AllIcons.Toolwindows.ToolWindowRun; - BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, badgePaint); - - runToolWindow.setIcon(iconWithBadge); - }); - } - } - else if(app.getMode() == RunMode.DEBUG) { - manager.invokeLater(() -> { - Icon baseIcon = AllIcons.Toolwindows.ToolWindowDebugger; - BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, badgePaint); - - debugToolWindow.setIcon(iconWithBadge); - }); - } - + ToolWindowBadgeUpdater.updateBadgedIcon(app, project); descriptor = createDebugSession(env, app, result).getRunContentDescriptor(); } else { diff --git a/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java b/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java new file mode 100644 index 0000000000..3e43d97278 --- /dev/null +++ b/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java @@ -0,0 +1,48 @@ +/* + * Copyright 2025 The Chromium Authors. All rights reserved. + * Use of this source code is governed by a BSD-style license that can be + * found in the LICENSE file. + */ +package io.flutter.toolwindow; + +import com.intellij.icons.AllIcons; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.wm.ToolWindow; +import com.intellij.openapi.wm.ToolWindowId; +import com.intellij.openapi.wm.ToolWindowManager; +import com.intellij.ui.BadgeIcon; +import io.flutter.run.common.RunMode; +import io.flutter.run.daemon.FlutterApp; + +import java.awt.Color; +import java.awt.Paint; +import java.util.Objects; +import javax.swing.Icon; +public class ToolWindowBadgeUpdater { + public static final Paint BADGE_PAINT = Color.decode("#5ca963"); + public static void updateBadgedIcon(FlutterApp app, Project project) { + final ToolWindowManager manager = ToolWindowManager.getInstance(Objects.requireNonNull(project)); + final ToolWindow runToolWindow = manager.getToolWindow(ToolWindowId.RUN); + final ToolWindow debugToolWindow = manager.getToolWindow(ToolWindowId.DEBUG); + + if(Objects.requireNonNull(app).getMode() == RunMode.RUN) { + if (runToolWindow != null) { + manager.invokeLater(() -> { + Icon baseIcon = AllIcons.Toolwindows.ToolWindowRun; + BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, BADGE_PAINT); + + runToolWindow.setIcon(iconWithBadge); + }); + } + } + else if(app.getMode() == RunMode.DEBUG) { + manager.invokeLater(() -> { + Icon baseIcon = AllIcons.Toolwindows.ToolWindowDebugger; + BadgeIcon iconWithBadge = new BadgeIcon(baseIcon, BADGE_PAINT); + + Objects.requireNonNull(debugToolWindow).setIcon(iconWithBadge); + }); + } + + } +} From a6aa95eb8a50ca4dcf0fa601f65943aa3fc256ba Mon Sep 17 00:00:00 2001 From: Japnit Singh Date: Sat, 24 May 2025 15:35:39 -0400 Subject: [PATCH 3/3] Added JavaDoc comments and added name in AUTHORS --- AUTHORS | 1 + .../src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java | 8 ++++++++ 2 files changed, 9 insertions(+) diff --git a/AUTHORS b/AUTHORS index 67872636d4..462c0a3049 100644 --- a/AUTHORS +++ b/AUTHORS @@ -24,3 +24,4 @@ Wagner Silvestre Eli Albert Mohamed El Sayed Edwin Ludik +Japnit Singh diff --git a/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java b/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java index 3e43d97278..871114efe7 100644 --- a/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java +++ b/flutter-idea/src/io/flutter/toolwindow/ToolWindowBadgeUpdater.java @@ -18,8 +18,16 @@ import java.awt.Paint; import java.util.Objects; import javax.swing.Icon; + public class ToolWindowBadgeUpdater { public static final Paint BADGE_PAINT = Color.decode("#5ca963"); + + /** + * Updates the tool window icons for RUN or DEBUG mode with a green badge. + * + * @param app The FlutterApp instance running in a given mode. + * @param project The current IntelliJ project context. + */ public static void updateBadgedIcon(FlutterApp app, Project project) { final ToolWindowManager manager = ToolWindowManager.getInstance(Objects.requireNonNull(project)); final ToolWindow runToolWindow = manager.getToolWindow(ToolWindowId.RUN);