Explorar el Código

Bug 1697: Failure when dropping down bookmark menu while no bookmark is saved

https://winscp.net/tracker/1697

Source commit: 2ada9b51446c2f5649775a99c29662b3e064e446
Martin Prikryl hace 7 años
padre
commit
acd9b6c82c
Se han modificado 1 ficheros con 72 adiciones y 70 borrados
  1. 72 70
      source/forms/CustomScpExplorer.cpp

+ 72 - 70
source/forms/CustomScpExplorer.cpp

@@ -9815,91 +9815,95 @@ void __fastcall TCustomScpExplorerForm::RemoteBookmarkClick(TObject * Sender)
 void __fastcall TCustomScpExplorerForm::CreateOpenDirMenuList(
   TTBCustomItem * Menu, TOperationSide Side, TBookmarkList * BookmarkList)
 {
-  TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
-
-  if (!WinConfiguration->UseLocationProfiles)
+  if (BookmarkList != NULL)
   {
-    std::unique_ptr<TStringList> Directories(new TStringList());
-    Directories->CaseSensitive = (Side == osRemote);
-    for (int Index = 0; Index < BookmarkList->Count; Index++)
+    TNotifyEvent OnBookmarkClick = (Side == osLocal) ? &LocalBookmarkClick : &RemoteBookmarkClick;
+
+    if (!WinConfiguration->UseLocationProfiles)
     {
-      TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
-      UnicodeString Directory = Bookmark->GetSideDirectory(Side);
-      if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
+      std::unique_ptr<TStringList> Directories(new TStringList());
+      Directories->CaseSensitive = (Side == osRemote);
+      for (int Index = 0; Index < BookmarkList->Count; Index++)
       {
-        std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
-        Item->Caption = EscapeHotkey(Directory);
-        Item->ShortCut = Bookmark->ShortCut;
-        Item->OnClick = OnBookmarkClick;
-        Item->Tag = reinterpret_cast<int>(Bookmark);
-        Directories->Add(Directory);
-        Menu->Add(Item.release());
+        TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
+        UnicodeString Directory = Bookmark->GetSideDirectory(Side);
+        if (!Directory.IsEmpty() && (Directories->IndexOf(Directory) < 0))
+        {
+          std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
+          Item->Caption = EscapeHotkey(Directory);
+          Item->ShortCut = Bookmark->ShortCut;
+          Item->OnClick = OnBookmarkClick;
+          Item->Tag = reinterpret_cast<int>(Bookmark);
+          Directories->Add(Directory);
+          Menu->Add(Item.release());
+        }
       }
     }
-  }
-  else
-  {
-    std::unique_ptr<TStrings> Folders(CreateSortedStringList());
-    for (int Index = 0; Index < BookmarkList->Count; Index++)
+    else
     {
-      TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
-      if (!Bookmark->Node.IsEmpty())
+      std::unique_ptr<TStrings> Folders(CreateSortedStringList());
+      for (int Index = 0; Index < BookmarkList->Count; Index++)
       {
-        Folders->Add(Bookmark->Node);
+        TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
+        if (!Bookmark->Node.IsEmpty())
+        {
+          Folders->Add(Bookmark->Node);
+        }
       }
-    }
-
-    for (int Index = 0; Index < Folders->Count; Index++)
-    {
-      std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
-      Item->Caption = Folders->Strings[Index];
-      Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
-      Folders->Objects[Index] = Item.get();
-      Menu->Add(Item.release());
-    }
 
-    for (int Index = 0; Index < BookmarkList->Count; Index++)
-    {
-      TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
-      TTBCustomItem * Parent;
-      if (!Bookmark->Node.IsEmpty())
-      {
-        DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
-        Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
-      }
-      else
+      for (int Index = 0; Index < Folders->Count; Index++)
       {
-        Parent = Menu;
+        std::unique_ptr<TTBCustomItem> Item(new TTBXSubmenuItem(Owner));
+        Item->Caption = Folders->Strings[Index];
+        Item->ImageIndex = NonVisualDataModule->RemoteChangePathAction->ImageIndex;
+        Folders->Objects[Index] = Item.get();
+        Menu->Add(Item.release());
       }
-      std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
-      Item->Caption = Bookmark->Name;
-      Item->ShortCut = Bookmark->ShortCut;
-      Item->OnClick = OnBookmarkClick;
-      Item->Tag = reinterpret_cast<int>(Bookmark);
 
-      if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
-          (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
+      for (int Index = 0; Index < BookmarkList->Count; Index++)
       {
-        // No hint for location profiles that are actually mere "bookmarks"
-      }
-      else
-      {
-        UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
-        UnicodeString LongHint;
-        if (!Bookmark->Local.IsEmpty())
+        TBookmark * Bookmark = BookmarkList->Bookmarks[Index];
+        TTBCustomItem * Parent;
+        if (!Bookmark->Node.IsEmpty())
         {
-          AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
+          DebugAssert(Folders->IndexOf(Bookmark->Node) >= 0);
+          Parent = dynamic_cast<TTBCustomItem *>(Folders->Objects[Folders->IndexOf(Bookmark->Node)]);
         }
-        if (!Bookmark->Remote.IsEmpty())
+        else
         {
-          AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
+          Parent = Menu;
+        }
+        std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
+        Item->Caption = Bookmark->Name;
+        Item->ShortCut = Bookmark->ShortCut;
+        Item->OnClick = OnBookmarkClick;
+        Item->Tag = reinterpret_cast<int>(Bookmark);
+
+        if (((Bookmark->Name == Bookmark->Local) || (Bookmark->Name == Bookmark->Remote)) &&
+            (Bookmark->Local.IsEmpty() || Bookmark->Remote.IsEmpty()))
+        {
+          // No hint for location profiles that are actually mere "bookmarks"
+        }
+        else
+        {
+          UnicodeString Hint = FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 1), (Bookmark->Name));
+          UnicodeString LongHint;
+          if (!Bookmark->Local.IsEmpty())
+          {
+            AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 2), (Bookmark->Local)), L"\n");
+          }
+          if (!Bookmark->Remote.IsEmpty())
+          {
+            AddToList(LongHint, FORMAT(LoadStrPart(LOCATION_PROFILE_HINT, 3), (Bookmark->Remote)), L"\n");
+          }
+          AddToList(Hint, LongHint, L"|");
+          Item->Hint = Hint;
         }
-        AddToList(Hint, LongHint, L"|");
-        Item->Hint = Hint;
-      }
 
-      Parent->Add(Item.release());
+        Parent->Add(Item.release());
+      }
     }
+    AddMenuSeparator(Menu);
   }
 }
 //---------------------------------------------------------------------------
@@ -9907,13 +9911,11 @@ void __fastcall TCustomScpExplorerForm::CreateOpenDirMenu(TTBCustomItem * Menu,
 {
   Menu->Clear();
 
-  CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
 
-  AddMenuSeparator(Menu);
 
-  CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
+  CreateOpenDirMenuList(Menu, Side, WinConfiguration->Bookmarks[Terminal->SessionData->SessionKey]);
 
-  AddMenuSeparator(Menu);
+  CreateOpenDirMenuList(Menu, Side, WinConfiguration->SharedBookmarks);
 
   std::unique_ptr<TTBCustomItem> Item(new TTBXItem(Owner));
   Item->Action = (Side == osLocal) ? NonVisualDataModule->LocalAddBookmarkAction : NonVisualDataModule->RemoteAddBookmarkAction;