Ver código fonte

Bug 892: Save command in transfer settings drop down menu

https://winscp.net/tracker/892

Source commit: e6208ef8aefe737e339ab40f203c65cc6ac2d83d
Martin Prikryl 7 anos atrás
pai
commit
50c9881608

+ 1 - 2
source/forms/CopyParamPreset.cpp

@@ -100,8 +100,7 @@ bool __fastcall TCopyParamPresetDialog::Execute(TCopyParamList * CopyParamList,
   else
   {
     DescriptionEdit->Text = L"";
-    TCopyParamType Default;
-    CopyParamsFrame->Params = Default;
+    CopyParamsFrame->Params = DefaultCopyParams;
     if (FMode == cpmAddCurrent)
     {
       SetRuleData(*FCurrentRuleData);

+ 2 - 2
source/forms/Login.cpp

@@ -3055,10 +3055,10 @@ void __fastcall TLoginDialog::CopyParamRuleActionExecute(TObject * /*Sender*/)
     Mode = cpmEdit;
   }
 
-  TCopyParamType DummyDefaultCopyParams;
+  TCopyParamType DefaultCopyParams;
 
   if (DoCopyParamPresetDialog(
-        CopyParamList.get(), CopyParamIndex, Mode, CurrentRuleData, DummyDefaultCopyParams))
+        CopyParamList.get(), CopyParamIndex, Mode, CurrentRuleData, DefaultCopyParams))
   {
     GUIConfiguration->CopyParamList = CopyParamList.get();
   }

+ 15 - 1
source/forms/Preferences.cpp

@@ -1778,7 +1778,21 @@ void __fastcall TPreferencesDialog::AddEditCopyParam(TCopyParamPresetMode Mode)
       (FDialogData != NULL ? FDialogData->CopyParamRuleData : NULL);
     // negative (when default is selected) means add to the end
     Index--;
-    Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, FCopyParams);
+
+    TCopyParamType DefaultCopyParams;
+    // For cpmAdd use defaults.
+    if (Mode == cpmDuplicate)
+    {
+      // Only used, when duplicating default settings (Index < 0)
+      DefaultCopyParams = FCopyParams;
+    }
+    else if (Mode == cpmEdit)
+    {
+      // For cpmEdit, DefaultCopyParams is never used.
+      DebugAssert(Index >= 0);
+    }
+
+    Result = DoCopyParamPresetDialog(FCopyParamList, Index, Mode, CopyParamRuleData, DefaultCopyParams);
     if (Result)
     {
       UpdateCopyParamListView();

+ 1 - 0
source/resource/TextsWin.h

@@ -612,6 +612,7 @@
 #define SYNCHRONIZE_CHECKLIST_CAPTION 6010
 #define EDITOR_READONLY         6011
 #define PROGRESS_TIME_LEFT_CALCULATING 6012
+#define COPY_PARAM_SAVE_PRESET  6013
 
 // 2xxx is reserved for TextsFileZilla.h
 

+ 1 - 0
source/resource/TextsWin1.rc

@@ -615,6 +615,7 @@ BEGIN
         SYNCHRONIZE_CHECKLIST_CAPTION, "Synchronization checklist"
         EDITOR_READONLY, "Read-only"
         PROGRESS_TIME_LEFT_CALCULATING, "Calculating"
+        COPY_PARAM_SAVE_PRESET, "Save as &Preset..."
 
         WIN_VARIABLE_STRINGS, "WIN_VARIABLE"
         WINSCP_COPYRIGHT, "Copyright © 2000-2018 Martin Prikryl"

+ 24 - 1
source/windows/WinInterface.cpp

@@ -797,6 +797,7 @@ const int cpiConfigure = -2;
 const int cpiCustom = -3;
 const int cpiSaveSettings = -4;
 const int cpiGenerateCode = -5;
+const int cpiSavePreset = -6;
 //---------------------------------------------------------------------------
 void __fastcall CopyParamListPopup(TRect Rect, TPopupMenu * Menu,
   const TCopyParamType & Param, UnicodeString Preset, TNotifyEvent OnClick,
@@ -825,6 +826,12 @@ void __fastcall CopyParamListPopup(TRect Rect, TPopupMenu * Menu,
     Menu->Items->Add(Item);
   }
 
+  Item = new TMenuItem(Menu);
+  Item->Caption = LoadStr(COPY_PARAM_SAVE_PRESET);
+  Item->Tag = cpiSavePreset;
+  Item->OnClick = OnClick;
+  Menu->Items->Add(Item);
+
   Item = new TMenuItem(Menu);
   Item->Caption = LoadStr(COPY_PARAM_PRESET_HEADER);
   Item->Visible = false;
@@ -903,7 +910,7 @@ int __fastcall CopyParamListPopupClick(TObject * Sender,
 {
   TComponent * Item = dynamic_cast<TComponent *>(Sender);
   DebugAssert(Item != NULL);
-  DebugAssert((Item->Tag >= cpiGenerateCode) && (Item->Tag < GUIConfiguration->CopyParamList->Count));
+  DebugAssert((Item->Tag >= cpiSavePreset) && (Item->Tag < GUIConfiguration->CopyParamList->Count));
 
   int Result;
   if (Item->Tag == cpiConfigure)
@@ -929,6 +936,22 @@ int __fastcall CopyParamListPopupClick(TObject * Sender,
     }
     Result = 0;
   }
+  else if (Item->Tag == cpiSavePreset)
+  {
+    std::unique_ptr<TCopyParamList> CopyParamList(new TCopyParamList());
+    *CopyParamList = *GUIConfiguration->CopyParamList;
+    int Index = -1;
+    if (DoCopyParamPresetDialog(CopyParamList.get(), Index, cpmAdd, NULL, Param))
+    {
+      GUIConfiguration->CopyParamList = CopyParamList.get();
+      // If saved unmodified, then make this the selected preset
+      if (*CopyParamList->CopyParams[Index] == Param)
+      {
+        Preset = CopyParamList->Names[Index];
+      }
+    }
+    Result = 0;
+  }
   else if (Item->Tag == cpiGenerateCode)
   {
     Result = -cplGenerateCode;