浏览代码

Bug fix: Failure when attempting to switch to an unconnected sessions using keyboard shortcuts while another session is being connected

Source commit: 16458bfd6be421aa7556d2b483b21622f9e071ba
Martin Prikryl 3 年之前
父节点
当前提交
fcca527ee2
共有 2 个文件被更改,包括 123 次插入106 次删除
  1. 49 46
      source/forms/CustomScpExplorer.cpp
  2. 74 60
      source/windows/TerminalManager.cpp

+ 49 - 46
source/forms/CustomScpExplorer.cpp

@@ -4662,63 +4662,66 @@ void __fastcall TCustomScpExplorerForm::CheckCustomCommandShortCut(
 //---------------------------------------------------------------------------
 void __fastcall TCustomScpExplorerForm::KeyDown(Word & Key, Classes::TShiftState Shift)
 {
-  if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
+  if (!NonVisualDataModule->Busy)
   {
-    QueueView3->OnKeyDown(QueueView3, Key, Shift);
-  }
+    if (QueueView3->Focused() && (QueueView3->OnKeyDown != NULL))
+    {
+      QueueView3->OnKeyDown(QueueView3, Key, Shift);
+    }
 
-  if ((Key != 0) && !DirView(osCurrent)->IsEditing())
-  {
-    TShortCut KeyShortCut = ShortCut(Key, Shift);
-    for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
+    if ((Key != 0) && !DirView(osCurrent)->IsEditing())
     {
-      // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
-      // But so far it's not a problem, as it does what we want.
-      TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
-      if (((Action->ShortCut == KeyShortCut) ||
-           (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
-          AllowedAction(Action, aaShortCut))
+      TShortCut KeyShortCut = ShortCut(Key, Shift);
+      for (int Index = 0; Index < NonVisualDataModule->ExplorerActions->ActionCount; Index++)
       {
-        // Has to be called before the action as the dialog char is already in queue.
-        // So when the action consumes message queue, we already need to have the
-        // FIgnoreNextDialogChar set
-        KeyProcessed(Key, Shift);
-        // Reset reference to previous component (when menu/toolbar was clicked).
-        // Needed to detect that action was invoked by keyboard shortcut
-        // in TNonVisualDataModule::ExplorerActionsExecute
-        Action->ActionComponent = NULL;
-        Action->Execute();
-        return;
+        // Note that handling shortcuts on panel (current control) popup menu has precendence over this.
+        // But so far it's not a problem, as it does what we want.
+        TAction * Action = (TAction *)NonVisualDataModule->ExplorerActions->Actions[Index];
+        if (((Action->ShortCut == KeyShortCut) ||
+             (Action->SecondaryShortCuts->IndexOfShortCut(KeyShortCut) >= 0)) &&
+            AllowedAction(Action, aaShortCut))
+        {
+          // Has to be called before the action as the dialog char is already in queue.
+          // So when the action consumes message queue, we already need to have the
+          // FIgnoreNextDialogChar set
+          KeyProcessed(Key, Shift);
+          // Reset reference to previous component (when menu/toolbar was clicked).
+          // Needed to detect that action was invoked by keyboard shortcut
+          // in TNonVisualDataModule::ExplorerActionsExecute
+          Action->ActionComponent = NULL;
+          Action->Execute();
+          return;
+        }
       }
-    }
-    for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
-    {
-      if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
+      for (int i = 0; i < TTerminalManager::Instance()->Count; i++)
+      {
+        if (NonVisualDataModule->OpenSessionShortCut(i) == KeyShortCut)
+        {
+          KeyProcessed(Key, Shift);
+          TTerminalManager::Instance()->ActiveSessionIndex = i;
+          return;
+        }
+      }
+      if (Key == VK_TAB && Shift.Contains(ssCtrl))
       {
         KeyProcessed(Key, Shift);
-        TTerminalManager::Instance()->ActiveSessionIndex = i;
-        return;
+        TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
       }
-    }
-    if (Key == VK_TAB && Shift.Contains(ssCtrl))
-    {
-      KeyProcessed(Key, Shift);
-      TTerminalManager::Instance()->CycleTerminals(!Shift.Contains(ssShift));
-    }
 
-    TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
-    if (IsCustomShortCut(CustomShortCut))
-    {
-      CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
-      CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
-
-      if (WinConfiguration->SharedBookmarks != NULL)
+      TShortCut CustomShortCut = NormalizeCustomShortCut(KeyShortCut);
+      if (IsCustomShortCut(CustomShortCut))
       {
-        TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
-        if ((Bookmark != NULL) &&
-            OpenBookmark(FCurrentSide, Bookmark))
+        CheckCustomCommandShortCut(WinConfiguration->CustomCommandList, Key, Shift, CustomShortCut);
+        CheckCustomCommandShortCut(WinConfiguration->ExtensionList, Key, Shift, CustomShortCut);
+
+        if (WinConfiguration->SharedBookmarks != NULL)
         {
-          KeyProcessed(Key, Shift);
+          TBookmark * Bookmark = WinConfiguration->SharedBookmarks->FindByShortCut(CustomShortCut);
+          if ((Bookmark != NULL) &&
+              OpenBookmark(FCurrentSide, Bookmark))
+          {
+            KeyProcessed(Key, Shift);
+          }
         }
       }
     }

+ 74 - 60
source/windows/TerminalManager.cpp

@@ -731,89 +731,103 @@ void __fastcall TTerminalManager::DoSetActiveSession(TManagedTerminal * value, b
 {
   if (ActiveSession != value)
   {
-    // here used to be call to TCustomScpExporer::UpdateSessionData (now UpdateSession)
-    // but it seems to be duplicate to call from TCustomScpExporer::SessionChanging
-
-    TManagedTerminal * PActiveSession = ActiveSession;
-    FActiveSession = value;
-    if (ScpExplorer)
+    if (NonVisualDataModule != NULL)
     {
-      if ((ActiveSession != NULL) &&
-          ((ActiveSession->Status == ssOpened) || ActiveSession->Disconnected || ActiveSession->LocalBrowser))
-      {
-        SessionReady();
-      }
-      else
-      {
-        UpdateScpExplorer(NULL, NULL);
-      }
+      NonVisualDataModule->StartBusy();
     }
-    UpdateAppTitle();
-
-    if (PActiveSession != NULL)
+    try
     {
-      if (PActiveSession->DisconnectedTemporarily && DebugAlwaysTrue(PActiveSession->Disconnected))
-      {
-        PActiveSession->Disconnected = false;
-        PActiveSession->DisconnectedTemporarily = false;
-      }
+      // here used to be call to TCustomScpExporer::UpdateSessionData (now UpdateSession)
+      // but it seems to be duplicate to call from TCustomScpExporer::SessionChanging
 
-      if (!PActiveSession->Active)
+      TManagedTerminal * PActiveSession = ActiveSession;
+      FActiveSession = value;
+      if (ScpExplorer)
       {
-        SaveTerminal(PActiveSession);
+        if ((ActiveSession != NULL) &&
+            ((ActiveSession->Status == ssOpened) || ActiveSession->Disconnected || ActiveSession->LocalBrowser))
+        {
+          SessionReady();
+        }
+        else
+        {
+          UpdateScpExplorer(NULL, NULL);
+        }
       }
-    }
+      UpdateAppTitle();
 
-    if (ActiveSession != NULL)
-    {
-      int Index = ActiveSessionIndex;
-      if (!ActiveSession->Active &&
-          !FTerminationMessages->Strings[Index].IsEmpty() &&
-          DebugAlwaysTrue(!ActiveSession->LocalBrowser))
+      if (PActiveSession != NULL)
       {
-        UnicodeString Message = FTerminationMessages->Strings[Index];
-        FTerminationMessages->Strings[Index] = L"";
-        if (AutoReconnect)
+        if (PActiveSession->DisconnectedTemporarily && DebugAlwaysTrue(PActiveSession->Disconnected))
         {
-          ReconnectActiveTerminal();
+          PActiveSession->Disconnected = false;
+          PActiveSession->DisconnectedTemporarily = false;
         }
-        else
+
+        if (!PActiveSession->Active)
+        {
+          SaveTerminal(PActiveSession);
+        }
+      }
+
+      if (ActiveSession != NULL)
+      {
+        int Index = ActiveSessionIndex;
+        if (!ActiveSession->Active &&
+            !FTerminationMessages->Strings[Index].IsEmpty() &&
+            DebugAlwaysTrue(!ActiveSession->LocalBrowser))
         {
-          Exception * E = new ESshFatal(NULL, Message);
-          try
+          UnicodeString Message = FTerminationMessages->Strings[Index];
+          FTerminationMessages->Strings[Index] = L"";
+          if (AutoReconnect)
           {
-            // finally show pending terminal message,
-            // this gives user also possibility to reconnect
-            ActiveTerminal->ShowExtendedException(E);
+            ReconnectActiveTerminal();
           }
-          __finally
+          else
           {
-            delete E;
+            Exception * E = new ESshFatal(NULL, Message);
+            try
+            {
+              // finally show pending terminal message,
+              // this gives user also possibility to reconnect
+              ActiveTerminal->ShowExtendedException(E);
+            }
+            __finally
+            {
+              delete E;
+            }
           }
         }
+
+        // LastTerminalClosed is true only for a replacement local session,
+        // and it should never happen that it fails to be activated
+        if (LastTerminalClosed && DebugAlwaysFalse(value != ActiveSession))
+        {
+          LastTerminalClosed = false; // just in case
+        }
+      }
+      else
+      {
+        LastTerminalClosed = true;
       }
 
-      // LastTerminalClosed is true only for a replacement local session,
-      // and it should never happen that it fails to be activated
-      if (LastTerminalClosed && DebugAlwaysFalse(value != ActiveSession))
+      if (LastTerminalClosed && !Updating && (ScpExplorer != NULL))
       {
-        LastTerminalClosed = false; // just in case
+        ScpExplorer->LastTerminalClosed();
       }
-    }
-    else
-    {
-      LastTerminalClosed = true;
-    }
 
-    if (LastTerminalClosed && !Updating && (ScpExplorer != NULL))
-    {
-      ScpExplorer->LastTerminalClosed();
+      if ((ActiveSession != NULL) &&
+          !ActiveSession->Active && !ActiveSession->Disconnected && !ActiveSession->LocalBrowser)
+      {
+        ConnectActiveTerminal();
+      }
     }
-
-    if ((ActiveSession != NULL) &&
-        !ActiveSession->Active && !ActiveSession->Disconnected && !ActiveSession->LocalBrowser)
+    __finally
     {
-      ConnectActiveTerminal();
+      if (NonVisualDataModule != NULL)
+      {
+        NonVisualDataModule->EndBusy();
+      }
     }
   }
 }