Sfoglia il codice sorgente

Bug fix: Local custom commands that need session but no remote files were not disabled when session was not connected

(cherry picked from commit 5248f2f7e0e552bad8776762b094635821752c08)

Source commit: 335f6c6e808a6898cae6f6e0ac66f5c7926932d2
Martin Prikryl 5 anni fa
parent
commit
d454b68ad4

+ 9 - 1
source/core/FileMasks.cpp

@@ -1325,7 +1325,15 @@ bool __fastcall TFileCustomCommand::IsFileCommand(const UnicodeString & Command)
 //---------------------------------------------------------------------------
 bool __fastcall TFileCustomCommand::IsSiteCommand(const UnicodeString & Command)
 {
-  return FindPattern(Command, L'@');
+  return FindPattern(Command, L'@') || FindPattern(Command, L'S') || FindPattern(Command, L'E');
+}
+//---------------------------------------------------------------------------
+bool __fastcall TFileCustomCommand::IsSessionCommand(const UnicodeString & Command)
+{
+  return
+    IsSiteCommand(Command) || IsPasswordCommand(Command) ||
+    FindPattern(Command, L'U') || FindPattern(Command, L'#') || FindPattern(Command, L'N') ||
+    FindPattern(Command, L'/');
 }
 //---------------------------------------------------------------------------
 bool __fastcall TFileCustomCommand::IsPasswordCommand(const UnicodeString & Command)

+ 1 - 0
source/core/FileMasks.h

@@ -224,6 +224,7 @@ public:
   virtual bool __fastcall IsFileCommand(const UnicodeString & Command);
   bool __fastcall IsRemoteFileCommand(const UnicodeString & Command);
   bool __fastcall IsSiteCommand(const UnicodeString & Command);
+  bool __fastcall IsSessionCommand(const UnicodeString & Command);
   bool __fastcall IsPasswordCommand(const UnicodeString & Command);
 
 protected:

+ 11 - 3
source/forms/CustomScpExplorer.cpp

@@ -1797,6 +1797,7 @@ bool __fastcall TCustomScpExplorerForm::CustomCommandRemoteAllowed()
 int __fastcall TCustomScpExplorerForm::CustomCommandState(
   const TCustomCommandType & Command, bool OnFocused, TCustomCommandListType ListType)
 {
+  // -1 = hidden, 0 = disabled, 1 = enabled
   int Result;
 
   TFileCustomCommand RemoteCustomCommand;
@@ -1877,6 +1878,13 @@ int __fastcall TCustomScpExplorerForm::CustomCommandState(
         Result = -1;
       }
     }
+
+    if ((Result > 0) &&
+        LocalCustomCommand.IsSessionCommand(Cmd) &&
+        !HasActiveTerminal())
+    {
+      Result = 0;
+    }
   }
 
   return Result;
@@ -2392,7 +2400,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
   TCustomCommandData Data;
   UnicodeString Site;
   UnicodeString RemotePath;
-  if (Terminal != NULL)
+  if (HasActiveTerminal())
   {
     Data = TCustomCommandData(Terminal);
     Site = Terminal->SessionData->SessionKey;
@@ -8939,7 +8947,7 @@ void __fastcall TCustomScpExplorerForm::AdHocCustomCommandValidate(
 {
   if (CustomCommandState(Command, FEditingFocusedAdHocCommand, ccltAll) <= 0)
   {
-    throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (Command.Command)));
+    throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (Command.Command)));
   }
 }
 //---------------------------------------------------------------------------
@@ -8979,7 +8987,7 @@ void __fastcall TCustomScpExplorerForm::LastCustomCommand(bool OnFocused)
   DebugAssert(State > 0);
   if (State <= 0)
   {
-    throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE, (FLastCustomCommand.Command)));
+    throw Exception(FMTLOAD(CUSTOM_COMMAND_IMPOSSIBLE2, (FLastCustomCommand.Command)));
   }
 
   ExecuteFileOperation(foCustomCommand, osRemote, OnFocused, false, &FLastCustomCommand);

+ 1 - 1
source/resource/TextsWin.h

@@ -48,7 +48,7 @@
 #define ALREADY_EDITED_EXTERNALLY_OR_UPLOADED 1161
 #define COPY_PARAM_NO_RULE      1162
 #define COPY_PARAM_DUPLICATE    1163
-#define CUSTOM_COMMAND_IMPOSSIBLE 1164
+#define CUSTOM_COMMAND_IMPOSSIBLE2 1164
 #define EDIT_SESSION_CLOSED_RELOAD 1165
 #define DECRYPT_PASSWORD_ERROR  1168
 #define MASTER_PASSWORD_INCORRECT 1169

+ 1 - 1
source/resource/TextsWin1.rc

@@ -55,7 +55,7 @@ BEGIN
         ALREADY_EDITED_EXTERNALLY_OR_UPLOADED, "The file '%s' is already opened in external editor (application) or is being uploaded."
         COPY_PARAM_NO_RULE, "You have not specified any autoselection rule mask."
         COPY_PARAM_DUPLICATE, "Transfer settings preset with description '%s' already exists."
-        CUSTOM_COMMAND_IMPOSSIBLE, "Custom command '%s' cannot be executed right now. Please select files for the command first."
+        CUSTOM_COMMAND_IMPOSSIBLE2, "**Custom command '%s' cannot be executed right now.** You may need to select files for the command or open a session first."
         CUSTOM_COMMAND_AD_HOC_NAME, "Ad Hoc"
         EDIT_SESSION_CLOSED_RELOAD, "Cannot reload file '%s', the session '%s' has been already closed."
         DECRYPT_PASSWORD_ERROR, "The password cannot be decrypted."