Browse Source

Bug fix: When the active tab was disconnected, closing window with another active session did not require a confirmation

(cherry picked from commit 4d0a39d9eb1ed06f2e09f426fabe77bdc6cba87d)

Source commit: ce372072cce5744190f719c4e758569eef10da6f
Martin Prikryl 4 years ago
parent
commit
b0b968cceb
1 changed files with 23 additions and 9 deletions
  1. 23 9
      source/forms/CustomScpExplorer.cpp

+ 23 - 9
source/forms/CustomScpExplorer.cpp

@@ -4948,36 +4948,50 @@ void __fastcall TCustomScpExplorerForm::FormCloseQuery(TObject * /*Sender*/,
   {
     CanClose = false;
   }
-  else if (Terminal != NULL)
+  else
   {
-    if (Terminal->Active && WinConfiguration->ConfirmClosingSession)
+    TTerminalManager * Manager = TTerminalManager::Instance();
+
+    int ActiveSessions = 0;
+    for (int Index = 0; Index < Manager->Count; Index++)
+    {
+      if (Manager->Sessions[Index]->Active)
+      {
+        ActiveSessions++;
+      }
+    }
+    // Confirm, when there's at least one active remote session
+    if ((ActiveSessions > 0) &&
+        WinConfiguration->ConfirmClosingSession)
     {
       unsigned int Result;
       TMessageParams Params(mpNeverAskAgainCheck);
       UnicodeString Message;
       int Answers = qaOK | qaCancel;
-      if (TTerminalManager::Instance()->Count > 1)
+      // The current session is the only active session
+      if ((ActiveSessions == 1) && (Terminal != NULL) && Terminal->Active)
       {
         if (!WinConfiguration->AutoSaveWorkspace)
         {
-          Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
+          Message = LoadStr(CLOSE_SESSION_WORKSPACE);
         }
         else
         {
-          Message = LoadStr(CLOSE_SESSIONS);
+          Message = LoadStr(CLOSE_SESSION);
         }
+        Message = FORMAT(Message, (Terminal->SessionData->SessionName));
       }
-      else
+      // Multiple active sessions or one active session, but it's not the current one
+      else if (DebugAlwaysTrue(ActiveSessions > 0))
       {
         if (!WinConfiguration->AutoSaveWorkspace)
         {
-          Message = LoadStr(CLOSE_SESSION_WORKSPACE);
+          Message = LoadStr(CLOSE_SESSIONS_WORKSPACE3);
         }
         else
         {
-          Message = LoadStr(CLOSE_SESSION);
+          Message = LoadStr(CLOSE_SESSIONS);
         }
-        Message = FORMAT(Message, (Terminal->SessionData->SessionName));
       }
 
       UnicodeString Note;