Browse Source

Clickable command-line and open command switches and SessionOptions properties + Quotes around log path + Reusing INI_SWITCH + INI_NUL + LOG_SWITCH + COMMAND_SWITCH + TProgramParams::FormatSwitch

Reimplementing AddAssemblyProperty for enum using AddAssemblyPropertyRaw

Source commit: e87db536722f53796c510d4faf171802d98a4290
Martin Prikryl 10 years ago
parent
commit
b0e6881e7a
4 changed files with 52 additions and 39 deletions
  1. 5 0
      source/core/Common.cpp
  2. 1 0
      source/core/Common.h
  3. 31 33
      source/core/SessionData.cpp
  4. 15 6
      source/forms/GenerateUrl.cpp

+ 5 - 0
source/core/Common.cpp

@@ -2964,6 +2964,11 @@ UnicodeString __fastcall RtfColorItalicText(int Color, const UnicodeString & Tex
   return RtfColor(Color) + L"\\i " + RtfText(Text) + L"\\i0" + RtfColor(0) + L" ";
 }
 //---------------------------------------------------------------------
+UnicodeString __fastcall RtfOverrideColorText(const UnicodeString & Text)
+{
+  return RtfColorText(1, Text);
+}
+//---------------------------------------------------------------------
 UnicodeString __fastcall RtfKeyword(const UnicodeString & Text)
 {
   return RtfColorText(5, Text);

+ 1 - 0
source/core/Common.h

@@ -207,6 +207,7 @@ extern const UnicodeString RtfHyperlinkFieldPrefix;
 //---------------------------------------------------------------------
 UnicodeString __fastcall RtfText(const UnicodeString & Text);
 UnicodeString __fastcall RtfColor(int Index);
+UnicodeString __fastcall RtfOverrideColorText(const UnicodeString & Text);
 UnicodeString __fastcall RtfColorItalicText(int Color, const UnicodeString & Text);
 UnicodeString __fastcall RtfColorText(int Color, const UnicodeString & Text);
 UnicodeString __fastcall RtfKeyword(const UnicodeString & Text);

+ 31 - 33
source/core/SessionData.cpp

@@ -2524,7 +2524,7 @@ UnicodeString __fastcall TSessionData::GenerateSessionUrl(unsigned int Flags)
 //---------------------------------------------------------------------
 void __fastcall TSessionData::AddSwitch(UnicodeString & Result, const UnicodeString & Switch)
 {
-  Result += RtfText(L" ") + RtfParameter(FORMAT(L"-%s", (Switch)));
+  Result += RtfText(L" ") + RtfLink(L"scriptcommand_open#" + Switch.LowerCase(), RtfParameter(FORMAT(L"-%s", (Switch))));
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::AddSwitchValue(UnicodeString & Result, const UnicodeString & Name, const UnicodeString & Value)
@@ -2578,7 +2578,12 @@ static UnicodeString __fastcall RtfLibraryClass(const UnicodeString & ClassName)
 //---------------------------------------------------------------------
 static UnicodeString __fastcall RtfLibraryMethod(const UnicodeString & ClassName, const UnicodeString & MethodName)
 {
-  return RtfLink(L"library_" + ClassName.LowerCase() + L"_" + MethodName.LowerCase(), RtfColorText(1, MethodName));
+  return RtfLink(L"library_" + ClassName.LowerCase() + L"_" + MethodName.LowerCase(), RtfOverrideColorText(MethodName));
+}
+//---------------------------------------------------------------------
+static UnicodeString __fastcall RtfLibraryProperty(const UnicodeString & ClassName, const UnicodeString & PropertyName)
+{
+  return RtfLink(L"library_" + ClassName.LowerCase() + L"#" + PropertyName.LowerCase(), RtfOverrideColorText(PropertyName));
 }
 //---------------------------------------------------------------------
 UnicodeString __fastcall TSessionData::GenerateOpenCommandArgs()
@@ -2658,31 +2663,6 @@ UnicodeString __fastcall TSessionData::GenerateOpenCommandArgs()
   return Result;
 }
 //---------------------------------------------------------------------
-void __fastcall TSessionData::AddAssemblyProperty(
-  UnicodeString & Result, TAssemblyLanguage Language,
-  const UnicodeString & Name, const UnicodeString & Type,
-  const UnicodeString & Member)
-{
-  UnicodeString PropertyCode;
-
-  switch (Language)
-  {
-    case alCSharp:
-      PropertyCode = RtfText(L"    %s = ") + RtfClass("%s") + RtfText(L".%s,") + RtfPara;
-      break;
-
-    case alVBNET:
-      PropertyCode = RtfText(L"    .%s = ") + RtfClass("%s") + RtfText(L".%s") + RtfPara;
-      break;
-
-    case alPowerShell:
-      PropertyCode = RtfText(L"$sessionOptions.%s = [WinSCP.") + RtfClass("%s") + RtfText(L"]::%s") + RtfPara;
-      break;
-  }
-
-  Result += FORMAT(PropertyCode, (Name, Type, Member));
-}
-//---------------------------------------------------------------------
 UnicodeString __fastcall TSessionData::AssemblyString(TAssemblyLanguage Language, UnicodeString S)
 {
   switch (Language)
@@ -2718,24 +2698,42 @@ void __fastcall TSessionData::AddAssemblyPropertyRaw(
   UnicodeString & Result, TAssemblyLanguage Language,
   const UnicodeString & Name, const UnicodeString & Value)
 {
-  UnicodeString PropertyCode;
-
   switch (Language)
   {
     case alCSharp:
-      PropertyCode = RtfText(L"    %s = %s,") + RtfPara;
+      Result += L"    " + RtfLibraryProperty(L"SessionOptions", Name) + L" = " + Value + L"," + RtfPara;
       break;
 
     case alVBNET:
-      PropertyCode = RtfText(L"    .%s = %s") + RtfPara;
+      Result += L"    ." + RtfLibraryProperty(L"SessionOptions", Name) + L" = " + Value + RtfPara;
       break;
 
     case alPowerShell:
-      PropertyCode = RtfText(L"$sessionOptions.%s = %s") + RtfPara;
+      Result += RtfText(L"$sessionOptions.") + RtfLibraryProperty(L"SessionOptions", Name) + L" = " + Value + RtfPara;
       break;
   }
+}
+//---------------------------------------------------------------------
+void __fastcall TSessionData::AddAssemblyProperty(
+  UnicodeString & Result, TAssemblyLanguage Language,
+  const UnicodeString & Name, const UnicodeString & Type,
+  const UnicodeString & Member)
+{
+  UnicodeString PropertyValue;
 
-  Result += FORMAT(PropertyCode, (Name, Value));
+  switch (Language)
+  {
+    case alCSharp:
+    case alVBNET:
+      PropertyValue = RtfClass(Type) + RtfText(L"." + Member);
+      break;
+
+    case alPowerShell:
+      PropertyValue = RtfText(L"[WinSCP.") + RtfClass(Type) + RtfText(L"]::" + Member);
+      break;
+  }
+
+  AddAssemblyPropertyRaw(Result, Language, Name, PropertyValue);
 }
 //---------------------------------------------------------------------
 void __fastcall TSessionData::AddAssemblyProperty(

+ 15 - 6
source/forms/GenerateUrl.cpp

@@ -10,6 +10,7 @@
 #include <Tools.h>
 #include <PuttyTools.h>
 #include <TextsWin.h>
+#include <ProgParams.h>
 //---------------------------------------------------------------------------
 #pragma package(smart_init)
 #ifndef NO_RESOURCES
@@ -191,6 +192,11 @@ static UnicodeString __fastcall RtfScriptCommand(const UnicodeString & Command)
 {
   return RtfLink(L"scriptcommand_" + Command, RtfKeyword(Command));
 }
+//---------------------------------------------------------------------
+UnicodeString __fastcall RtfCommandlineSwitch(const UnicodeString & Switch, const UnicodeString & Anchor)
+{
+  return RtfLink(L"commandline#" + Anchor, RtfParameter(TProgramParams::FormatSwitch(Switch.LowerCase())));
+}
 //---------------------------------------------------------------------------
 void __fastcall TGenerateUrlDialog::UpdateControls()
 {
@@ -278,8 +284,11 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
       UnicodeString CommandPlaceholder1 = FMTLOAD(GENERATE_URL_COMMAND, (1));
       UnicodeString CommandPlaceholder2 = FMTLOAD(GENERATE_URL_COMMAND, (2));
       UnicodeString LogParameter =
-        RtfParameter(L"/log") + RtfText(L"=") +
-        RtfScriptPlaceholder(LoadStr(GENERATE_URL_WRITABLE_PATH_TO_LOG) + RtfText(BaseExeName + L".log"));
+        RtfCommandlineSwitch(LOG_SWITCH, L"logging") + RtfText(L"=") +
+        RtfScriptPlaceholder(L"\"" + LoadStr(GENERATE_URL_WRITABLE_PATH_TO_LOG) + RtfText(BaseExeName + L".log") + L"\"");
+      UnicodeString IniParameter =
+        RtfCommandlineSwitch(INI_SWITCH, L"configuration") + RtfText(UnicodeString(L"=") + INI_NUL);
+      UnicodeString CommandParameter = RtfCommandlineSwitch(COMMAND_SWITCH, L"scripting");
 
       if (ScriptFormatCombo->ItemIndex == sfScriptFile)
       {
@@ -303,8 +312,8 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
           RtfScriptPlaceholder(L"@echo off") + RtfPara +
           RtfPara +
           RtfText(L"\"" + ComExeName + "\" ^") + RtfPara +
-          RtfText(L"  ") + LogParameter + L" " + RtfParameter(L"/ini") + RtfText(L"=nul ^") + RtfPara +
-          RtfText(L"  ") + RtfParameter(L"/command") + RtfText(L" ^") + RtfPara +
+          RtfText(L"  ") + LogParameter + L" " + IniParameter + RtfText(L" ^") + RtfPara +
+          RtfText(L"  ") + CommandParameter + RtfText(L" ^") + RtfPara +
           RtfText(L"    \"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(ReplaceStr(OpenCommand, L"%", L"%%")) + RtfText(L"\" ^") + RtfPara +
           RtfText(L"    \"") + RtfScriptPlaceholder(CommandPlaceholder1) + RtfText(L"\" ^") + RtfPara +
           RtfText(L"    \"") + RtfScriptPlaceholder(CommandPlaceholder2) + RtfText(L"\" ^") + RtfPara +
@@ -325,8 +334,8 @@ void __fastcall TGenerateUrlDialog::UpdateControls()
       {
         Result =
           LogParameter + L" " +
-          RtfParameter(L"/ini") + RtfText(L"=nul ") +
-          RtfParameter(L"/command") + RtfText(L" ") +
+          IniParameter + L" " +
+          CommandParameter + L" " +
             RtfText(L"\"") + RtfScriptCommand(L"open") + RtfText(L" ") + EscapeParam(OpenCommand) + RtfText(L"\" ") +
             RtfText(L"\"") + RtfScriptComment(CommandPlaceholder1) + RtfText(L"\" ") +
             RtfText(L"\"") + RtfScriptComment(CommandPlaceholder2) + RtfText(L"\" ") +