Przeglądaj źródła

Tabs of standalone sessions (not part of a folder or workspace) are not preserved, when the session fails to connect on the initial attempt already

Source commit: 91978e3e7f35c547e1bc977b7a7f589ba8e862d1
Martin Prikryl 6 lat temu
rodzic
commit
babb4519fc

+ 1 - 1
source/forms/CustomScpExplorer.cpp

@@ -6526,7 +6526,7 @@ void __fastcall TCustomScpExplorerForm::NeedSession(bool ReloadSessions)
     __finally
     {
       if (!WinConfiguration->KeepOpenWhenNoSession &&
-          (!Terminal || !Terminal->Active))
+          ((Terminal == NULL) || (!Terminal->Active && !Terminal->Permanent)))
       {
         TerminateApplication();
       }

+ 19 - 3
source/windows/TerminalManager.cpp

@@ -213,8 +213,16 @@ TManagedTerminal * __fastcall TTerminalManager::NewTerminals(TList * DataList)
   TManagedTerminal * Result = NULL;
   for (int Index = 0; Index < DataList->Count; Index++)
   {
-    TManagedTerminal * Terminal =
-      DoNewTerminal(reinterpret_cast<TSessionData *>(DataList->Items[Index]));
+    TSessionData * Data = reinterpret_cast<TSessionData *>(DataList->Items[Index]);
+    TManagedTerminal * Terminal = DoNewTerminal(Data);
+    // When opening workspace/folder, keep the sessions open, even if they fail to connect.
+    // We cannot detect a folder here, so we "guess" it by a session set size.
+    // After all, no one will have a folder with a one session only (while a workspace with one session is likely).
+    // And when when opening a folder with a one session only, it's not that big problem, if we treat it the same way
+    // as when opening the session only.
+    // Also closing a workspace session will remove the session from the workspace.
+    // While closing a folder session won't remove the session from the folder.
+    Terminal->Permanent = Data->IsWorkspace || (DataList->Count > 1);
     if (Index == 0)
     {
       Result = Terminal;
@@ -327,6 +335,7 @@ void __fastcall TTerminalManager::DoConnectTerminal(TTerminal * Terminal, bool R
     if (Terminal->Active && (ManagedTerminal != NULL))
     {
       ManagedTerminal->ReopenStart = 0;
+      ManagedTerminal->Permanent = true;
     }
   }
 
@@ -407,7 +416,14 @@ bool __fastcall TTerminalManager::ConnectActiveTerminalImpl(bool Reopen)
 
   if (Action == tpFree)
   {
-    DisconnectActiveTerminal();
+    if (ActiveTerminal->Permanent)
+    {
+      DisconnectActiveTerminal();
+    }
+    else
+    {
+      FreeActiveTerminal();
+    }
   }
 
   return Result;

+ 3 - 0
source/windows/TerminalManager.h

@@ -31,6 +31,9 @@ public:
   // To distinguish sessions that were explicitly disconnected and
   // should not be reconnected when their tab is activated.
   bool Disconnected;
+  // Sessions that should not close when they fail to connect
+  // (i.e. those that were ever connected or were opened as a part of a workspace)
+  bool Permanent;
 };
 //---------------------------------------------------------------------------
 class TTerminalManager : public TTerminalList