1
0
Эх сурвалжийг харах

Bug 1577: Per-session default encoding configuration for internal editor

https://winscp.net/tracker/1577

Source commit: 2209844f940bd6f76200df8555800b4f513ba085
Martin Prikryl 8 жил өмнө
parent
commit
7caf9181d3

+ 9 - 0
source/core/SessionData.cpp

@@ -158,6 +158,7 @@ void __fastcall TSessionData::Default()
   FOverrideCachedHostKey = true;
   Note = L"";
   WinTitle = L"";
+  InternalEditorEncoding = -1;
 
   ProxyMethod = ::pmNone;
   ProxyHost = L"proxy";
@@ -319,6 +320,7 @@ void __fastcall TSessionData::NonPersistant()
   PROPERTY(RekeyTime); \
   PROPERTY(HostKey); \
   PROPERTY(FingerprintScan); \
+  PROPERTY(InternalEditorEncoding); \
   \
   PROPERTY(UpdateDirectories); \
   PROPERTY(CacheDirectories); \
@@ -633,6 +635,7 @@ void __fastcall TSessionData::DoLoad(THierarchicalStorage * Storage, bool PuttyI
   EOLType = (TEOLType)Storage->ReadInteger(L"EOLType", EOLType);
   TrimVMSVersions = Storage->ReadBool(L"TrimVMSVersions", TrimVMSVersions);
   NotUtf = TAutoSwitch(Storage->ReadInteger(L"Utf", Storage->ReadInteger(L"SFTPUtfBug", NotUtf)));
+  InternalEditorEncoding = Storage->ReadInteger(L"InternalEditorEncoding", InternalEditorEncoding);
 
   S3DefaultRegion = Storage->ReadString(L"Utf", S3DefaultRegion);
 
@@ -984,6 +987,7 @@ void __fastcall TSessionData::DoSave(THierarchicalStorage * Storage,
     WRITE_DATA(Bool, TrimVMSVersions);
     Storage->DeleteValue(L"SFTPUtfBug");
     WRITE_DATA_EX(Integer, L"Utf", NotUtf, );
+    WRITE_DATA(Integer, InternalEditorEncoding);
     WRITE_DATA(String, S3DefaultRegion);
     WRITE_DATA(Integer, SendBuf);
     WRITE_DATA(Bool, SshSimple);
@@ -3701,6 +3705,11 @@ void __fastcall TSessionData::SetNotUtf(TAutoSwitch value)
   SET_SESSION_PROPERTY(NotUtf);
 }
 //---------------------------------------------------------------------
+void __fastcall TSessionData::SetInternalEditorEncoding(int value)
+{
+  SET_SESSION_PROPERTY(InternalEditorEncoding);
+}
+//---------------------------------------------------------------------
 void __fastcall TSessionData::SetS3DefaultRegion(UnicodeString value)
 {
   SET_SESSION_PROPERTY(S3DefaultRegion);

+ 3 - 0
source/core/SessionData.h

@@ -209,6 +209,7 @@ private:
   TTlsVersion FMinTlsVersion;
   TTlsVersion FMaxTlsVersion;
   TAutoSwitch FNotUtf;
+  int FInternalEditorEncoding;
   UnicodeString FS3DefaultRegion;
   bool FIsWorkspace;
   UnicodeString FLink;
@@ -379,6 +380,7 @@ private:
   void __fastcall SetMinTlsVersion(TTlsVersion value);
   void __fastcall SetMaxTlsVersion(TTlsVersion value);
   void __fastcall SetNotUtf(TAutoSwitch value);
+  void __fastcall SetInternalEditorEncoding(int value);
   void __fastcall SetS3DefaultRegion(UnicodeString value);
   void __fastcall SetLogicalHostName(UnicodeString value);
   void __fastcall SetIsWorkspace(bool value);
@@ -617,6 +619,7 @@ public:
   __property TTlsVersion MaxTlsVersion = { read = FMaxTlsVersion, write = SetMaxTlsVersion };
   __property UnicodeString LogicalHostName = { read = FLogicalHostName, write = SetLogicalHostName };
   __property TAutoSwitch NotUtf = { read = FNotUtf, write = SetNotUtf };
+  __property int InternalEditorEncoding = { read = FInternalEditorEncoding, write = SetInternalEditorEncoding };
   __property UnicodeString S3DefaultRegion = { read = FS3DefaultRegion, write = SetS3DefaultRegion };
   __property bool IsWorkspace = { read = FIsWorkspace, write = SetIsWorkspace };
   __property UnicodeString Link = { read = FLink, write = SetLink };

+ 2 - 2
source/forms/CustomScpExplorer.cpp

@@ -2905,7 +2905,7 @@ void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
         Editor = ShowEditorForm(FileName, this, FEditorManager->FileChanged,
           FEditorManager->FileReload, FEditorManager->FileClosed,
           SaveAllInternalEditors, AnyInternalEditorModified,
-          Caption, FStandaloneEditing, SessionColor);
+          Caption, FStandaloneEditing, SessionColor, Terminal->SessionData->InternalEditorEncoding);
       }
       catch(...)
       {
@@ -2924,7 +2924,7 @@ void __fastcall TCustomScpExplorerForm::CustomExecuteFile(TOperationSide Side,
       TForm * Editor =
         ShowEditorForm(FileName, this, NULL, NULL, LocalEditorClosed,
           SaveAllInternalEditors, AnyInternalEditorModified,
-          L"", false, SessionColor);
+          L"", false, SessionColor, -1);
       FLocalEditors->Add(Editor);
     }
   }

+ 11 - 2
source/forms/Editor.cpp

@@ -28,7 +28,7 @@
 TForm * __fastcall ShowEditorForm(const UnicodeString FileName, TForm * ParentForm,
   TNotifyEvent OnFileChanged, TNotifyEvent OnFileReload, TFileClosedEvent OnClose,
   TNotifyEvent OnSaveAll, TAnyModifiedEvent OnAnyModified,
-  const UnicodeString Caption, bool StandaloneEditor, TColor Color)
+  const UnicodeString Caption, bool StandaloneEditor, TColor Color, int InternalEditorEncodingOverride)
 {
   TEditorForm * Dialog = new TEditorForm(Application);
   try
@@ -43,6 +43,7 @@ TForm * __fastcall ShowEditorForm(const UnicodeString FileName, TForm * ParentFo
     Dialog->OnAnyModified = OnAnyModified;
     Dialog->StandaloneEditor = StandaloneEditor;
     Dialog->BackgroundColor = Color;
+    Dialog->InternalEditorEncodingOverride = InternalEditorEncodingOverride;
     // load before showing, so when loading failes,
     // we do not show an empty editor
     Dialog->LoadFile();
@@ -707,6 +708,7 @@ __fastcall TEditorForm::TEditorForm(TComponent* Owner)
   FStandaloneEditor = false;
   FClosePending = false;
   FReloading = false;
+  FInternalEditorEncodingOverride = -1;
   SetSubmenu(ColorItem);
 
   InitCodePage();
@@ -1282,7 +1284,14 @@ void __fastcall TEditorForm::LoadFromFile(bool PrimaryEncoding)
       }
       else
       {
-        Encoding = WinConfiguration->Editor.Encoding;
+        if (InternalEditorEncodingOverride >= 0)
+        {
+          Encoding = InternalEditorEncodingOverride;
+        }
+        else
+        {
+          Encoding = WinConfiguration->Editor.Encoding;
+        }
         CanTrySecondary = true;
       }
 

+ 2 - 0
source/forms/Editor.h

@@ -117,6 +117,7 @@ private:
   bool FStandaloneEditor;
   bool FClosePending;
   TColor FBackgroundColor;
+  int FInternalEditorEncodingOverride;
   bool FReloading;
 
   static unsigned int FInstances;
@@ -139,6 +140,7 @@ public:
   __property TAnyModifiedEvent OnAnyModified = { read = FOnAnyModified, write = FOnAnyModified };
   __property TForm * ParentForm = { read = FParentForm, write = FParentForm };
   __property TColor BackgroundColor = { read = FBackgroundColor, write = SetBackgroundColor };
+  __property int InternalEditorEncodingOverride = { read = FInternalEditorEncodingOverride, write = FInternalEditorEncodingOverride };
 protected:
   bool __fastcall CursorInUpperPart();
   void __fastcall Find();

+ 1 - 1
source/windows/WinInterface.h

@@ -353,7 +353,7 @@ typedef void __fastcall (__closure *TAnyModifiedEvent)
 TForm * __fastcall ShowEditorForm(const UnicodeString FileName, TForm * ParentForm,
   TNotifyEvent OnFileChanged, TNotifyEvent OnFileReload, TFileClosedEvent OnClose,
   TNotifyEvent OnSaveAll, TAnyModifiedEvent OnAnyModified,
-  const UnicodeString Caption, bool StandaloneEditor, TColor Color);
+  const UnicodeString Caption, bool StandaloneEditor, TColor Color, int InternalEditorEncodingOverride);
 void __fastcall ReconfigureEditorForm(TForm * Form);
 void __fastcall EditorFormFileUploadComplete(TForm * Form);
 void __fastcall EditorFormFileSave(TForm * Form);