Browse Source

Issue 2393 – When restored after operation completed while minimized the window is disabled

https://winscp.net/tracker/2393

Source commit: 4a7927649c3234d1b162cd2f3ad740f8745ba1af
Martin Prikryl 2 months ago
parent
commit
01ac603abc
2 changed files with 24 additions and 1 deletions
  1. 2 0
      source/forms/CustomScpExplorer.cpp
  2. 22 1
      source/windows/WinInterface.cpp

+ 2 - 0
source/forms/CustomScpExplorer.cpp

@@ -10384,6 +10384,7 @@ void __fastcall TCustomScpExplorerForm::LockWindow(bool Force)
   // Shouldn't we use IsApplicationMinimized() here?
   if ((FLockSuspendLevel == 0) && !IsIconic(Application->Handle) && (Force || (Screen->ActiveForm == this)))
   {
+    AppLog(L"Disabling window");
     Enabled = false;
   }
 
@@ -10398,6 +10399,7 @@ void __fastcall TCustomScpExplorerForm::UnlockWindow()
   if (FLockLevel == 0)
   {
     DebugAssert(FLockSuspendLevel == 0);
+    AppLog(L"Re-enabling window");
     Enabled = true;
     // VCL_COPY (TCustomForm.SetWindowFocus)
     if (Active && (ActiveControl != NULL))

+ 22 - 1
source/windows/WinInterface.cpp

@@ -1315,7 +1315,28 @@ static void __fastcall DoApplicationMinimizeRestore(bool Minimize)
     {
       if (Minimize)
       {
-        Application->Minimize();
+        // WORKAROUND:
+        // VCL enables minimized windows (why?) and restores the previous disabled state on restore.
+        // But if we meanwhile re-enable the window (like when transfer finishes while minimized),
+        // the VCL will re-disable the window on restore.
+        // (This does not help in scenario, then the main window is minimized with its own title's minimize window,
+        // but then it should not be disabled in the first place)
+        bool WasDisabled = !MainForm->Enabled;
+        if (WasDisabled)
+        {
+          MainForm->Enabled = true;
+        }
+        try
+        {
+          Application->Minimize();
+        }
+        __finally
+        {
+          if (WasDisabled)
+          {
+            MainForm->Enabled = false;
+          }
+        }
         MinimizedToTray = WinConfiguration->MinimizeToTray;
       }
       else