You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by "errael (via GitHub)" <gi...@apache.org> on 2023/05/26 01:52:47 UTC

[GitHub] [netbeans] errael commented on a diff in pull request #5989: #5987: Use the currently active dialog as the presenter parent

errael commented on code in PR #5989:
URL: https://github.com/apache/netbeans/pull/5989#discussion_r1206147436


##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1357,17 +1357,50 @@ private static Frame findMainWindow()
      */
     // PR4739
     public static Component findDialogParent() {
-        Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+        return findDialogParent(null);
+    }
+
+    /**
+     * Finds an appropriate component to use for a dialog's parent. Similar to {@link #findDialogParent()}
+     * with the ability to specify a suggested parent component.
+     *
+     * @param suggestedParent the component to return if suitable
+     * @return A suitable parent component for swing dialog displayers.

Review Comment:
   Seems like this is for any dialog, not "dialog displayer". Maybe I'm just confusing myself.
   
   Is it useful to mention that a suggestedParent is unsuitable if there's a modal dialog active and the suggestParent is not it.



##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1357,17 +1357,50 @@ private static Frame findMainWindow()
      */
     // PR4739
     public static Component findDialogParent() {
-        Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+        return findDialogParent(null);
+    }
+
+    /**
+     * Finds an appropriate component to use for a dialog's parent. Similar to {@link #findDialogParent()}
+     * with the ability to specify a suggested parent component.
+     *
+     * @param suggestedParent the component to return if suitable
+     * @return A suitable parent component for swing dialog displayers.
+     *
+     * @see #findMainWindow()

Review Comment:
   `findMainWindow()` is private, probably shouldn't be referenced in javadoc. Could just say the main window is the default if nothing better is found.
   



##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1357,17 +1357,50 @@ private static Frame findMainWindow()
      */
     // PR4739
     public static Component findDialogParent() {
-        Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+        return findDialogParent(null);
+    }
+
+    /**
+     * Finds an appropriate component to use for a dialog's parent. Similar to {@link #findDialogParent()}
+     * with the ability to specify a suggested parent component.
+     *
+     * @param suggestedParent the component to return if suitable
+     * @return A suitable parent component for swing dialog displayers.
+     *
+     * @see #findMainWindow()
+     * @since 9.30
+     */
+    public static Component findDialogParent(Component suggestedParent) {
+        Component parent = suggestedParent;
         if (parent == null) {
-            parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
+            parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+        }
+        Window active = KeyboardFocusManager.getCurrentKeyboardFocusManager().getActiveWindow();
+        if (parent == null) {
+            parent = active;
+        } else if (active instanceof Dialog && ((Dialog) active).isModal()) {
+            Window suggested = parent instanceof Window ? (Window) parent : SwingUtilities.windowForComponent(parent);
+            if (suggested != active) {
+                return active;
+            }
         }
         if (parent == null) {
             // PR#5280
-            parent = findMainWindow();
+            return findMainWindow();
         }
         return parent;
     }
 
+    /**
+     * Gets whether a modal dialog is open.
+     * @return true if a modal dialog is open, false otherwise
+     * @since 9.30
+     */
+    public static boolean isModalDialogOpen() {

Review Comment:
   I guess `isModaldialogOpen` is here, even though it's only used from one spot, to keep this stuff together/centralized. Remember to document any API changes; this one in `platform/openide.util.ui/apichanges.xml`.
   



##########
platform/openide.util.ui/src/org/openide/util/Utilities.java:
##########
@@ -1357,17 +1357,50 @@ private static Frame findMainWindow()
      */
     // PR4739
     public static Component findDialogParent() {
-        Component parent = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
+        return findDialogParent(null);
+    }
+
+    /**
+     * Finds an appropriate component to use for a dialog's parent. Similar to {@link #findDialogParent()}
+     * with the ability to specify a suggested parent component.
+     *
+     * @param suggestedParent the component to return if suitable
+     * @return A suitable parent component for swing dialog displayers.
+     *
+     * @see #findMainWindow()
+     * @since 9.30
+     */
+    public static Component findDialogParent(Component suggestedParent) {

Review Comment:
   Don't see `Component findDialogParent(Component suggestedParent)` used anywhere in the PR. You're suggesting adding it to the API? I see how it's convenient to check if the suggestedParent is unsuitable because there's a modal dialog active.
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists