Browse Source

Bug fix: When there are both site folder and site with the same name and the site was selected when closing the Login dialog, when reopening, the folder was selected instead

Similarly when importing size with the same name as existing site folder, the folder was selected after the imported instead of the imported site

Source commit: 27ce5982bbdc6fb901870f7191a0e2126b1ccd0d
Martin Prikryl 4 years ago
parent
commit
5dabeda2f7
1 changed files with 9 additions and 6 deletions
  1. 9 6
      source/forms/Login.cpp

+ 9 - 6
source/forms/Login.cpp

@@ -1461,7 +1461,12 @@ void __fastcall TLoginDialog::SaveState()
 
     WinConfiguration->OpenedStoredSessionFolders = OpenedStoredSessionFolders->CommaText;
 
-    WinConfiguration->LastStoredSession = SessionNodePath(SessionTree->Selected);
+    UnicodeString LastStoredSession = SessionNodePath(SessionTree->Selected);
+    if (IsFolderNode(SessionTree->Selected))
+    {
+      LastStoredSession = UnixIncludeTrailingBackslash(LastStoredSession);
+    }
+    WinConfiguration->LastStoredSession = LastStoredSession;
 
     TLoginDialogConfiguration DialogConfiguration = CustomWinConfiguration->LoginDialog;
     DialogConfiguration.WindowSize = StoreFormSize(this);
@@ -1533,7 +1538,8 @@ void __fastcall TLoginDialog::LoadState()
   if (!FForceNewSite &&
       !WinConfiguration->LastStoredSession.IsEmpty() && DebugAlwaysTrue(Visible))
   {
-    UnicodeString Path = WinConfiguration->LastStoredSession;
+    UnicodeString Path = UnixExcludeTrailingBackslash(WinConfiguration->LastStoredSession);
+    bool Folder = (Path != WinConfiguration->LastStoredSession);
 
     UnicodeString ParentPath = UnixExtractFilePath(Path);
     TTreeNode * Node;
@@ -1550,10 +1556,7 @@ void __fastcall TLoginDialog::LoadState()
     if (Node != NULL)
     {
       UnicodeString Name = UnixExtractFileName(Path);
-      // actually we cannot distinguish folder and session here
-      // (note that we allow folder and session with the same name),
-      // this is pending for future improvements
-      while ((Node != NULL) && !AnsiSameText(Node->Text, Name))
+      while ((Node != NULL) && (!SameText(Node->Text, Name) || (IsFolderNode(Node) != Folder)))
       {
         Node = Node->getNextSibling();
       }