Browse Source

Warning when opening more than 100 tabs

https://winscp.net/tracker/1997

Source commit: 0c8a3bb472d3256797cfc60d13a30a79be1fed89
Martin Prikryl 4 years ago
parent
commit
a46181d494

+ 1 - 0
source/resource/HelpWin.h

@@ -69,5 +69,6 @@
 #define HELP_PUTTY_SETTINGS          "ui_login_environment#putty"
 #define HELP_CLOSE_SESSION_WORKSPACE "workspace"
 #define HELP_ADD_EXTENSION           "ui_pref_commands#extensions"
+#define HELP_TOO_MANY_SESSIONS       "ui_sessiontabs"
 
 #endif // TextsWin

+ 1 - 0
source/resource/TextsWin.h

@@ -159,6 +159,7 @@
 #define READONLY_INI_FILE_OVERWRITE 1370
 #define CLOSE_SESSION_WORKSPACE 1371
 #define CLOSE_WORKSPACE         1372
+#define TOO_MANY_SESSIONS       1373
 
 #define WIN_INFORMATION_STRINGS 1400
 #define COMPARE_NO_DIFFERENCES  1402

+ 1 - 0
source/resource/TextsWin1.rc

@@ -163,6 +163,7 @@ BEGIN
         READONLY_INI_FILE_OVERWRITE, "**Do you want to overwrite a read-only INI file '%s' to save your current configuration?**This question is asked, when you hold down Shift key while closing WinSCP and your INI file is set read-only. Normally read-only INI files are not overwritten and any changes to configuration are lost when closing WinSCP."
         CLOSE_SESSION_WORKSPACE, "Terminate session '%s' and close application without saving a workspace?"
         CLOSE_WORKSPACE, "Close application without saving a workspace?"
+        TOO_MANY_SESSIONS, "**Do you really want to open another tab?**\nYou have %d tabs opened already. Please consider closing some tabs first to free resources of your computer."
 
         WIN_INFORMATION_STRINGS, "WIN_INFORMATION"
         COMPARE_NO_DIFFERENCES, "No differences found."

+ 11 - 0
source/windows/TerminalManager.cpp

@@ -95,6 +95,8 @@ __fastcall TTerminalManager::TTerminalManager() :
   DebugAssert(Configuration && !Configuration->OnChange);
   Configuration->OnChange = ConfigurationChange;
 
+  FMaxSessions = WinConfiguration->MaxSessions;
+
   FSessionList = new TStringList();
   FQueues = new TList();
   FTerminationMessages = new TStringList();
@@ -178,6 +180,15 @@ void __fastcall TTerminalManager::SetupTerminal(TTerminal * Terminal)
 //---------------------------------------------------------------------------
 TManagedTerminal * __fastcall TTerminalManager::DoNewSession(TSessionData * Data)
 {
+  if (Count >= FMaxSessions)
+  {
+    UnicodeString Msg = FMTLOAD(TOO_MANY_SESSIONS, (Count));
+    if (MessageDialog(Msg, qtConfirmation, qaOK | qaCancel, HELP_TOO_MANY_SESSIONS) == qaCancel)
+    {
+      Abort();
+    }
+    FMaxSessions = FMaxSessions * 3 / 2; // increase limit before the next warning by 50%
+  }
   TManagedTerminal * Session = DebugNotNull(dynamic_cast<TManagedTerminal *>(TTerminalList::NewTerminal(Data)));
   try
   {

+ 1 - 0
source/windows/TerminalManager.h

@@ -123,6 +123,7 @@ private:
   std::unique_ptr<TApplicationEvents> FApplicationsEvents;
   bool FKeepAuthenticateForm;
   int FUpdating;
+  int FMaxSessions;
 
   bool __fastcall ConnectActiveTerminalImpl(bool Reopen);
   bool __fastcall ConnectActiveTerminal();