فهرست منبع

Site-specific extension options

Source commit: 18fc778ee0ad221f2b55d0f8b02899e5bffe96fc
Martin Prikryl 9 سال پیش
والد
کامیت
ad402af4c0

+ 11 - 7
source/forms/Custom.cpp

@@ -838,7 +838,7 @@ class TCustomCommandOptionsDialog : public TCustomDialog
 public:
   __fastcall TCustomCommandOptionsDialog(
     const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags,
-    TCustomCommand * CustomCommandForOptions);
+    TCustomCommand * CustomCommandForOptions, const UnicodeString & Site);
 
   bool __fastcall Execute();
 
@@ -852,6 +852,7 @@ private:
   std::vector<TControl *> FControls;
   std::vector<std::vector<UnicodeString> > FValues;
   unsigned int FFlags;
+  UnicodeString FSite;
 
   UnicodeString __fastcall HistoryKey(const TCustomCommandType::TOption & Option);
   THistoryComboBox * __fastcall CreateHistoryComboBox(const TCustomCommandType::TOption & Option, const UnicodeString & Value);
@@ -868,12 +869,14 @@ private:
 //---------------------------------------------------------------------------
 __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
     const TCustomCommandType * Command, TStrings * CustomCommandOptions,
-    unsigned int Flags, TCustomCommand * CustomCommandForOptions) :
+    unsigned int Flags, TCustomCommand * CustomCommandForOptions,
+    const UnicodeString & Site) :
   TCustomDialog(HELP_EXTENSION_OPTIONS)
 {
   FCommand = Command;
   FFlags = Flags;
   FCustomCommandOptions = CustomCommandOptions;
+  FSite = Site;
   Caption = FMTLOAD(EXTENSION_OPTIONS_CAPTION, (StripEllipsis(StripHotkey(FCommand->Name))));
   Width = ScaleByTextHeight(this, 400);
 
@@ -884,7 +887,7 @@ __fastcall TCustomCommandOptionsDialog::TCustomCommandOptionsDialog(
 
     if ((Option.Flags & FFlags) != 0)
     {
-      UnicodeString OptionKey = FCommand->GetOptionKey(Option);
+      UnicodeString OptionKey = FCommand->GetOptionKey(Option, FSite);
       UnicodeString Value;
       if ((CustomCommandForOptions != NULL) &&
           Option.HasPatterns(CustomCommandForOptions))
@@ -1142,7 +1145,7 @@ THistoryComboBox * __fastcall TCustomCommandOptionsDialog::CreateHistoryComboBox
 //---------------------------------------------------------------------------
 UnicodeString __fastcall TCustomCommandOptionsDialog::HistoryKey(const TCustomCommandType::TOption & Option)
 {
-  UnicodeString Result = FCommand->GetOptionKey(Option);
+  UnicodeString Result = FCommand->GetOptionKey(Option, FSite);
   Result = CustomWinConfiguration->GetValidHistoryKey(Result);
   return L"CustomCommandOption_" + Result;
 }
@@ -1162,7 +1165,7 @@ bool __fastcall TCustomCommandOptionsDialog::Execute()
         if ((Option.Kind != TCustomCommandType::okUnknown) &&
             Option.IsControl)
         {
-          UnicodeString OptionKey = FCommand->GetOptionKey(Option);
+          UnicodeString OptionKey = FCommand->GetOptionKey(Option, FSite);
 
           TControl * Control = FControls[ControlIndex];
 
@@ -1291,9 +1294,10 @@ void __fastcall TCustomCommandOptionsDialog::DoShow()
 //---------------------------------------------------------------------------
 bool __fastcall DoCustomCommandOptionsDialog(
   const TCustomCommandType * Command, TStrings * CustomCommandOptions,
-  unsigned int Flags, TCustomCommand * CustomCommandForOptions)
+  unsigned int Flags, TCustomCommand * CustomCommandForOptions,
+  const UnicodeString & Site)
 {
   std::unique_ptr<TCustomCommandOptionsDialog> Dialog(
-    new TCustomCommandOptionsDialog(Command, CustomCommandOptions, Flags, CustomCommandForOptions));
+    new TCustomCommandOptionsDialog(Command, CustomCommandOptions, Flags, CustomCommandForOptions, Site));
   return Dialog->Execute();
 }

+ 4 - 2
source/forms/CustomScpExplorer.cpp

@@ -1674,6 +1674,7 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
 {
 
   TCustomCommandData Data(Terminal);
+  UnicodeString Site = Terminal->SessionData->SessionKey;
 
   std::unique_ptr<TStrings> CustomCommandOptions(CloneStrings(WinConfiguration->CustomCommandOptions));
   if (ACommand.AnyOptionWithFlag(TCustomCommandType::ofRun))
@@ -1688,13 +1689,14 @@ void __fastcall TCustomScpExplorerForm::CustomCommand(TStrings * FileList,
       CustomCommandForOptions.reset(new TLocalCustomCommand(Data, Terminal->CurrentDirectory, DefaultDownloadTargetDirectory()));
     }
 
-    if (!DoCustomCommandOptionsDialog(&ACommand, CustomCommandOptions.get(), TCustomCommandType::ofRun, CustomCommandForOptions.get()))
+    if (!DoCustomCommandOptionsDialog(
+           &ACommand, CustomCommandOptions.get(), TCustomCommandType::ofRun, CustomCommandForOptions.get(), Site))
     {
       Abort();
     }
   }
 
-  UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get());
+  UnicodeString CommandCommand = ACommand.GetCommandWithExpandedOptions(CustomCommandOptions.get(), Site);
 
   if (FLAGCLEAR(ACommand.Params, ccLocal))
   {

+ 20 - 2
source/forms/Preferences.cpp

@@ -24,6 +24,7 @@
 #include "Setup.h"
 #include "ProgParams.h"
 #include "Http.h"
+#include "TerminalManager.h"
 //---------------------------------------------------------------------
 #pragma link "CopyParams"
 #pragma link "UpDownEdit"
@@ -2624,6 +2625,17 @@ void __fastcall TPreferencesDialog::AddCommandButtonDropDownClick(TObject * /*Se
   MenuPopup(AddCommandMenu, AddCommandButton);
 }
 //---------------------------------------------------------------------------
+UnicodeString __fastcall TPreferencesDialog::GetSessionKey()
+{
+  TTerminal * Terminal = TTerminalManager::Instance()->ActiveTerminal;
+  UnicodeString Result;
+  if (Terminal != NULL)
+  {
+    Result = Terminal->SessionData->SessionKey;
+  }
+  return Result;
+}
+//---------------------------------------------------------------------------
 void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Sender*/, TShiftState /*Shift*/, int X, int Y)
 {
   TListItem * Item = CustomCommandsView->GetItemAt(X, Y);
@@ -2646,7 +2658,7 @@ void __fastcall TPreferencesDialog::CustomCommandsViewMouseMove(TObject * /*Send
       {
         Hint += L"\n" + Command->Description;
       }
-      Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get());
+      Hint += L"\n" + Command->GetCommandWithExpandedOptions(FCustomCommandOptions.get(), GetSessionKey());
       if (List == FExtensionList)
       {
         Hint += L"\n" + Command->FileName;
@@ -2677,7 +2689,13 @@ void __fastcall TPreferencesDialog::ConfigureCommand()
   int Index = CustomCommandsView->ItemIndex;
   const TCustomCommandType * Command = GetCommandList(Index)->Commands[GetCommandIndex(Index)];
 
-  DoCustomCommandOptionsDialog(Command, FCustomCommandOptions.get(), TCustomCommandType::ofConfig, NULL);
+  UnicodeString Site = GetSessionKey();
+  if (Command->AnyOptionWithFlag(TCustomCommandType::ofSite) &&
+      Site.IsEmpty())
+  {
+    throw Exception(LoadStr(NO_SITE_FOR_COMMAND));
+  }
+  DoCustomCommandOptionsDialog(Command, FCustomCommandOptions.get(), TCustomCommandType::ofConfig, NULL, GetSessionKey());
   UpdateCustomCommandsView();
 }
 //---------------------------------------------------------------------------

+ 1 - 0
source/forms/Preferences.h

@@ -440,6 +440,7 @@ private:
   int __fastcall GetCommandIndex(int Index);
   int __fastcall GetCommandListIndex(TCustomCommandList * List, int Index);
   int __fastcall GetListCommandIndex(TCustomCommandList * List);
+  UnicodeString __fastcall GetSessionKey();
 public:
   virtual __fastcall ~TPreferencesDialog();
   bool __fastcall Execute(TPreferencesDialogData * DialogData);

+ 1 - 0
source/resource/TextsWin.h

@@ -91,6 +91,7 @@
 #define EXTENSION_DUPLICATE     1205
 #define EXTENSION_INSTALLED_ALREADY 1206
 #define EXTENSION_LOAD_ERROR    1207
+#define NO_SITE_FOR_COMMAND     1208
 
 #define WIN_CONFIRMATION_STRINGS 1300
 #define CONFIRM_OVERWRITE_SESSION 1301

+ 1 - 0
source/resource/TextsWin1.rc

@@ -97,6 +97,7 @@ BEGIN
         EXTENSION_DUPLICATE, "There is already an extension with the name \"%s\"."
         EXTENSION_INSTALLED_ALREADY, "The extension is installed already."
         EXTENSION_LOAD_ERROR, "Error loading an extension from \"%s\"."
+        NO_SITE_FOR_COMMAND, "**No session is opened**\nThe selected command has site-specific options, but no session is opened."
 
         WIN_CONFIRMATION_STRINGS, "WIN_CONFIRMATION"
         CONFIRM_OVERWRITE_SESSION, "Site with name '%s' already exists. Overwrite?"

+ 17 - 6
source/windows/WinConfiguration.cpp

@@ -2962,15 +2962,19 @@ bool __fastcall TCustomCommandType::ParseOption(const UnicodeString & Value, TOp
       {
         Option.Flags |= ofConfig;
       }
+      else if (FlagName == L"-site")
+      {
+        Option.Flags |= ofSite;
+      }
       else
       {
         Result = false;
       }
     }
 
-    if (Option.Flags == 0)
+    if ((Option.Flags & (ofRun | ofConfig)) == 0)
     {
-      Option.Flags = ofConfig;
+      Option.Flags |= ofConfig;
     }
 
     KindName = FlagName;
@@ -3100,9 +3104,15 @@ const TCustomCommandType::TOption & __fastcall TCustomCommandType::GetOption(int
   return FOptions[Index];
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TCustomCommandType::GetOptionKey(const TCustomCommandType::TOption & Option) const
+UnicodeString __fastcall TCustomCommandType::GetOptionKey(
+  const TCustomCommandType::TOption & Option, const UnicodeString & Site) const
 {
-  return Id + L"\\" + Option.Id;
+  UnicodeString Result = Id + L"\\" + Option.Id;
+  if (FLAGSET(Option.Flags, ofSite))
+  {
+    Result += L"\\" + Site;
+  }
+  return Result;
 }
 //---------------------------------------------------------------------------
 bool __fastcall TCustomCommandType::AnyOptionWithFlag(unsigned int Flag) const
@@ -3116,7 +3126,8 @@ bool __fastcall TCustomCommandType::AnyOptionWithFlag(unsigned int Flag) const
   return Result;
 }
 //---------------------------------------------------------------------------
-UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(TStrings * CustomCommandOptions) const
+UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(
+  TStrings * CustomCommandOptions, const UnicodeString & Site) const
 {
   UnicodeString Result = Command;
   for (int Index = 0; Index < OptionsCount; Index++)
@@ -3124,7 +3135,7 @@ UnicodeString __fastcall TCustomCommandType::GetCommandWithExpandedOptions(TStri
     const TCustomCommandType::TOption & Option = GetOption(Index);
     if (Option.IsControl)
     {
-      UnicodeString OptionKey = GetOptionKey(Option);
+      UnicodeString OptionKey = GetOptionKey(Option, Site);
       UnicodeString OptionValue;
       if (CustomCommandOptions->IndexOfName(OptionKey) >= 0)
       {

+ 4 - 3
source/windows/WinConfiguration.h

@@ -721,7 +721,7 @@ public:
   __fastcall TCustomCommandType(const TCustomCommandType & Other);
 
   enum TOptionKind { okUnknown, okLabel, okLink, okSeparator, okGroup, okTextBox, okFile, okDropDownList, okComboBox, okCheckBox };
-  enum TOptionFlag { ofRun = 0x01, ofConfig = 0x02 };
+  enum TOptionFlag { ofRun = 0x01, ofConfig = 0x02, ofSite = 0x04 };
 
   class TOption
   {
@@ -768,8 +768,9 @@ public:
   __property int OptionsCount = { read = GetOptionsCount };
   const TOption & __fastcall GetOption(int Index) const;
   bool __fastcall AnyOptionWithFlag(unsigned int Flag) const;
-  UnicodeString __fastcall GetOptionKey(const TOption & Option) const;
-  UnicodeString __fastcall GetCommandWithExpandedOptions(TStrings * CustomCommandOptions) const;
+  UnicodeString __fastcall GetOptionKey(const TOption & Option, const UnicodeString & Site) const;
+  UnicodeString __fastcall GetCommandWithExpandedOptions(
+    TStrings * CustomCommandOptions, const UnicodeString & Site) const;
 
 protected:
   bool __fastcall ParseOption(const UnicodeString & Value, TOption & Option, const UnicodeString & ExtensionBaseName);

+ 1 - 1
source/windows/WinInterface.h

@@ -133,7 +133,7 @@ bool __fastcall DoShortCutDialog(TShortCut & ShortCut,
   const TShortCuts & ShortCuts, UnicodeString HelpKeyword);
 bool __fastcall DoCustomCommandOptionsDialog(
   const TCustomCommandType * Command, TStrings * CustomCommandOptions, unsigned int Flags,
-  TCustomCommand * CustomCommandForOptions);
+  TCustomCommand * CustomCommandForOptions, const UnicodeString & Site);
 
 // windows\UserInterface.cpp
 bool __fastcall DoMasterPasswordDialog();