[PR #1002] [CLOSED] Fix popup window causing main window to be hidden after closing file dialogs (Issue #951) #932

Closed
opened 2026-02-26 12:00:31 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/1Remote/1Remote/pull/1002
Author: @Copilot
Created: 10/18/2025
Status: Closed

Base: mainHead: copilot/analyze-issue-951


📝 Commits (3)

  • 3bc4ec2 Initial plan
  • 396bb6b Fix popup window causing main window to be hidden (Issue #951)
  • bd1cd55 Update Shawn.Utils submodule with window reactivation fix

📊 Changes

2 files changed (+23 additions, -2 deletions)

View changed files

📝 Shawn.Utils (+1 -1)
📝 Ui/View/Host/ProtocolHosts/VmFileTransmitHost.cs (+22 -1)

📄 Description

Problem

When file selection dialogs (OpenFileDialog, SaveFileDialog, or FolderBrowserDialog) were opened from popup windows and then closed, the parent main window would be moved to the bottom layer of the window z-order, effectively becoming hidden behind other windows. This created a poor user experience where users had to manually click on the taskbar or use Alt+Tab to bring the main window back to the foreground.

Root Cause

The issue occurred because:

  1. File dialogs in SelectFileHelper.cs (Shawn.Utils submodule) were calling ShowDialog() without specifying an owner window
  2. The FolderBrowserDialog in VmFileTransmitHost.cs also lacked proper owner window handling
  3. When dialogs closed without an owner, Windows would not properly restore focus to the parent window, causing it to lose its z-order position

Solution

Changes to Shawn.Utils Submodule

Modified Shawn.Utils.Wpf/FileSystem/SelectFileHelper.cs to properly handle window ownership and reactivation:

  • Added GetActiveWindow() helper method to retrieve the currently active WPF window
  • Added ReactivateWindow() helper method to explicitly reactivate a window
  • Updated OpenFile(), SaveFile(), and OpenFiles() methods to:
    • Capture the active window before showing the dialog
    • Pass the owner window parameter to ShowDialog(ownerWindow)
    • Use a finally block to ensure the owner window is reactivated after the dialog closes (even if an exception occurs)

Changes to Main Repository

Modified Ui/View/Host/ProtocolHosts/VmFileTransmitHost.cs to fix FolderBrowserDialog behavior:

  • Updated folder upload functionality to capture and reactivate the owner window
  • Added Wpf32Window helper class to wrap WPF Window objects for use with Windows Forms dialogs (which require the IWin32Window interface)

Technical Details

The fix ensures that:

  1. All file dialogs have a proper parent window reference
  2. The parent window is explicitly reactivated using Window.Activate() and Window.Focus() after any dialog closes
  3. The finally block guarantees window reactivation even if the user cancels the dialog or an error occurs

Note on Submodule Changes

The Shawn.Utils changes are in a git submodule. The submodule has been updated locally with a new commit, and this PR updates the parent repository reference to point to the fixed version. Since Shawn.Utils is a separate repository (https://github.com/VShawn/Shawn.Utils), maintainers may need to push these changes to that repository separately.

Testing

  • Code review passed - no issues found
  • Security scan (CodeQL) passed - no vulnerabilities detected
  • Changes are minimal and surgical, only affecting window activation behavior around file dialogs

Closes #951

Original prompt

根据 #951,分析问题和原因,并尝试解决。


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/1Remote/1Remote/pull/1002 **Author:** [@Copilot](https://github.com/apps/copilot-swe-agent) **Created:** 10/18/2025 **Status:** ❌ Closed **Base:** `main` ← **Head:** `copilot/analyze-issue-951` --- ### 📝 Commits (3) - [`3bc4ec2`](https://github.com/1Remote/1Remote/commit/3bc4ec26881ed4609691ff598fac917ba45902d0) Initial plan - [`396bb6b`](https://github.com/1Remote/1Remote/commit/396bb6bec7988ba05dc75f88746c1a2740f2e814) Fix popup window causing main window to be hidden (Issue #951) - [`bd1cd55`](https://github.com/1Remote/1Remote/commit/bd1cd55fa044b64e26f84b29ed30518cc8e08b8b) Update Shawn.Utils submodule with window reactivation fix ### 📊 Changes **2 files changed** (+23 additions, -2 deletions) <details> <summary>View changed files</summary> 📝 `Shawn.Utils` (+1 -1) 📝 `Ui/View/Host/ProtocolHosts/VmFileTransmitHost.cs` (+22 -1) </details> ### 📄 Description ## Problem When file selection dialogs (OpenFileDialog, SaveFileDialog, or FolderBrowserDialog) were opened from popup windows and then closed, the parent main window would be moved to the bottom layer of the window z-order, effectively becoming hidden behind other windows. This created a poor user experience where users had to manually click on the taskbar or use Alt+Tab to bring the main window back to the foreground. ## Root Cause The issue occurred because: 1. File dialogs in `SelectFileHelper.cs` (Shawn.Utils submodule) were calling `ShowDialog()` without specifying an owner window 2. The `FolderBrowserDialog` in `VmFileTransmitHost.cs` also lacked proper owner window handling 3. When dialogs closed without an owner, Windows would not properly restore focus to the parent window, causing it to lose its z-order position ## Solution ### Changes to Shawn.Utils Submodule Modified `Shawn.Utils.Wpf/FileSystem/SelectFileHelper.cs` to properly handle window ownership and reactivation: - Added `GetActiveWindow()` helper method to retrieve the currently active WPF window - Added `ReactivateWindow()` helper method to explicitly reactivate a window - Updated `OpenFile()`, `SaveFile()`, and `OpenFiles()` methods to: - Capture the active window before showing the dialog - Pass the owner window parameter to `ShowDialog(ownerWindow)` - Use a `finally` block to ensure the owner window is reactivated after the dialog closes (even if an exception occurs) ### Changes to Main Repository Modified `Ui/View/Host/ProtocolHosts/VmFileTransmitHost.cs` to fix `FolderBrowserDialog` behavior: - Updated folder upload functionality to capture and reactivate the owner window - Added `Wpf32Window` helper class to wrap WPF `Window` objects for use with Windows Forms dialogs (which require the `IWin32Window` interface) ## Technical Details The fix ensures that: 1. All file dialogs have a proper parent window reference 2. The parent window is explicitly reactivated using `Window.Activate()` and `Window.Focus()` after any dialog closes 3. The `finally` block guarantees window reactivation even if the user cancels the dialog or an error occurs ## Note on Submodule Changes The Shawn.Utils changes are in a git submodule. The submodule has been updated locally with a new commit, and this PR updates the parent repository reference to point to the fixed version. Since Shawn.Utils is a separate repository (https://github.com/VShawn/Shawn.Utils), maintainers may need to push these changes to that repository separately. ## Testing - ✅ Code review passed - no issues found - ✅ Security scan (CodeQL) passed - no vulnerabilities detected - Changes are minimal and surgical, only affecting window activation behavior around file dialogs Closes #951 <!-- START COPILOT CODING AGENT SUFFIX --> <details> <summary>Original prompt</summary> > 根据 #951,分析问题和原因,并尝试解决。 </details> <!-- START COPILOT CODING AGENT TIPS --> --- 💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click [here](https://survey3.medallia.com/?EAHeSx-AP01bZqG0Ld9QLQ) to start the survey. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-02-26 12:00:31 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/1Remote#932
No description provided.