Pārlūkot izejas kodu

ADD: Default single-byte text encoding option

Alexander Koblov 3 gadi atpakaļ
vecāks
revīzija
40c7b0d68a

+ 51 - 17
src/frames/foptionsmisc.lfm

@@ -16,7 +16,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
     AnchorSideRight.Control = Owner
     AnchorSideRight.Side = asrBottom
     Left = 6
-    Height = 230
+    Height = 259
     Top = 6
     Width = 707
     Anchors = [akTop, akLeft, akRight]
@@ -24,7 +24,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
     BorderSpacing.Around = 6
     ChildSizing.LeftRightSpacing = 12
     ChildSizing.TopBottomSpacing = 6
-    ClientHeight = 210
+    ClientHeight = 239
     ClientWidth = 703
     TabOrder = 0
     object chkShowSplashForm: TCheckBox
@@ -51,31 +51,32 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       AnchorSideTop.Side = asrBottom
       Left = 12
       Height = 19
-      Top = 125
+      Top = 154
       Width = 154
       BorderSpacing.Top = 4
       Caption = '&Save thumbnails in cache'
-      TabOrder = 4
+      TabOrder = 5
     end
     object lblThumbSize: TLabel
       AnchorSideTop.Control = speThumbWidth
       AnchorSideTop.Side = asrCenter
       Left = 12
       Height = 15
-      Top = 154
+      Top = 183
       Width = 82
       Caption = '&Thumbnail size:'
       FocusControl = speThumbWidth
+      ParentColor = False
     end
     object dblThumbnails: TDividerBevel
       AnchorSideLeft.Control = gbExtended
-      AnchorSideTop.Control = chkShowCurDirTitleBar
+      AnchorSideTop.Control = cmbDefaultEncoding
       AnchorSideTop.Side = asrBottom
       AnchorSideRight.Control = gbExtended
       AnchorSideRight.Side = asrBottom
       Left = 12
       Height = 15
-      Top = 106
+      Top = 135
       Width = 679
       Caption = 'Thumbnails'
       Anchors = [akTop, akLeft, akRight]
@@ -89,13 +90,13 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       AnchorSideTop.Side = asrBottom
       Left = 100
       Height = 23
-      Top = 150
+      Top = 179
       Width = 50
       BorderSpacing.Left = 6
       BorderSpacing.Top = 6
       MaxValue = 512
       MinValue = 16
-      TabOrder = 5
+      TabOrder = 6
       Value = 16
     end
     object speThumbHeight: TSpinEdit
@@ -104,12 +105,12 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       AnchorSideTop.Control = speThumbWidth
       Left = 169
       Height = 23
-      Top = 150
+      Top = 179
       Width = 50
       BorderSpacing.Left = 6
       MaxValue = 512
       MinValue = 16
-      TabOrder = 6
+      TabOrder = 7
       Value = 16
     end
     object lblThumbSeparator: TLabel
@@ -119,10 +120,11 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       AnchorSideTop.Side = asrCenter
       Left = 156
       Height = 15
-      Top = 154
+      Top = 183
       Width = 7
       BorderSpacing.Left = 6
       Caption = 'X'
+      ParentColor = False
     end
     object lblThumbPixels: TLabel
       AnchorSideLeft.Control = speThumbHeight
@@ -131,23 +133,24 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       AnchorSideTop.Side = asrCenter
       Left = 225
       Height = 15
-      Top = 154
+      Top = 183
       Width = 30
       BorderSpacing.Left = 6
       Caption = 'pixels'
+      ParentColor = False
     end
     object btnThumbCompactCache: TButton
       AnchorSideTop.Control = speThumbWidth
       AnchorSideTop.Side = asrBottom
       Left = 12
       Height = 25
-      Top = 179
+      Top = 208
       Width = 272
       AutoSize = True
       BorderSpacing.Top = 6
       Caption = '&Remove thumbnails for no longer existing files'
       OnClick = btnThumbCompactCacheClick
-      TabOrder = 7
+      TabOrder = 8
     end
     object chkGoToRoot: TCheckBox
       AnchorSideTop.Control = chkShowWarningMessages
@@ -171,6 +174,33 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       Caption = 'Show &current directory in the main window title bar'
       TabOrder = 3
     end
+    object lblDefaultEncoding: TLabel
+      AnchorSideLeft.Control = chkShowSplashForm
+      AnchorSideTop.Control = cmbDefaultEncoding
+      AnchorSideTop.Side = asrCenter
+      Left = 12
+      Height = 15
+      Top = 104
+      Width = 179
+      Caption = '&Default single-byte text encoding:'
+      FocusControl = cmbDefaultEncoding
+      ParentColor = False
+    end
+    object cmbDefaultEncoding: TComboBox
+      AnchorSideLeft.Control = lblDefaultEncoding
+      AnchorSideLeft.Side = asrBottom
+      AnchorSideTop.Control = chkShowCurDirTitleBar
+      AnchorSideTop.Side = asrBottom
+      Left = 209
+      Height = 23
+      Top = 100
+      Width = 100
+      BorderSpacing.Left = 18
+      BorderSpacing.Top = 6
+      ItemHeight = 15
+      Style = csDropDownList
+      TabOrder = 4
+    end
   end
   object gbTCExportImport: TGroupBox[1]
     AnchorSideLeft.Control = gbExtended
@@ -180,7 +210,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
     AnchorSideRight.Side = asrBottom
     Left = 6
     Height = 164
-    Top = 315
+    Top = 344
     Width = 707
     Anchors = [akTop, akLeft, akRight]
     AutoSize = True
@@ -274,6 +304,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       Width = 76
       Alignment = taRightJustify
       Caption = 'TC executable:'
+      ParentColor = False
     end
     object fneTCConfigFilename: TFileNameEdit
       AnchorSideLeft.Control = gbTCExportImport
@@ -305,6 +336,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       Width = 96
       BorderSpacing.Top = 6
       Caption = 'Configuration file:'
+      ParentColor = False
     end
     object btnRelativeTCConfigFile: TSpeedButton
       AnchorSideTop.Control = fneTCConfigFilename
@@ -421,6 +453,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       Width = 108
       BorderSpacing.Top = 6
       Caption = 'Toolbar output path:'
+      ParentColor = False
     end
     object btnOutputPathForToolbar: TButton
       AnchorSideTop.Control = edOutputPathForToolbar
@@ -496,7 +529,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
     AnchorSideRight.Side = asrBottom
     Left = 6
     Height = 55
-    Top = 248
+    Top = 277
     Width = 707
     Anchors = [akTop, akLeft, akRight]
     AutoSize = True
@@ -517,6 +550,7 @@ inherited frmOptionsMisc: TfrmOptionsMisc
       Width = 94
       Caption = 'Default encoding:'
       Layout = tlCenter
+      ParentColor = False
     end
     object cmbDescDefaultEncoding: TComboBox
       Left = 108

+ 2 - 1
src/frames/foptionsmisc.lrj

@@ -1,4 +1,5 @@
 {"version":1,"strings":[
+{"hash":71209118,"name":"tfrmoptionsmisc.chkshowsplashform.caption","sourcebytes":[83,104,111,119,32,38,115,112,108,97,115,104,32,115,99,114,101,101,110],"value":"Show &splash screen"},
 {"hash":1395673,"name":"tfrmoptionsmisc.chkshowwarningmessages.caption","sourcebytes":[83,104,111,119,32,38,119,97,114,110,105,110,103,32,109,101,115,115,97,103,101,115,32,40,34,79,75,34,32,98,117,116,116,111,110,32,111,110,108,121,41],"value":"Show &warning messages (\"OK\" button only)"},
 {"hash":114241301,"name":"tfrmoptionsmisc.chkthumbsave.caption","sourcebytes":[38,83,97,118,101,32,116,104,117,109,98,110,97,105,108,115,32,105,110,32,99,97,99,104,101],"value":"&Save thumbnails in cache"},
 {"hash":38014346,"name":"tfrmoptionsmisc.lblthumbsize.caption","sourcebytes":[38,84,104,117,109,98,110,97,105,108,32,115,105,122,101,58],"value":"&Thumbnail size:"},
@@ -8,7 +9,7 @@
 {"hash":241754643,"name":"tfrmoptionsmisc.btnthumbcompactcache.caption","sourcebytes":[38,82,101,109,111,118,101,32,116,104,117,109,98,110,97,105,108,115,32,102,111,114,32,110,111,32,108,111,110,103,101,114,32,101,120,105,115,116,105,110,103,32,102,105,108,101,115],"value":"&Remove thumbnails for no longer existing files"},
 {"hash":158470307,"name":"tfrmoptionsmisc.chkgotoroot.caption","sourcebytes":[65,108,119,97,121,115,32,38,103,111,32,116,111,32,116,104,101,32,114,111,111,116,32,111,102,32,97,32,100,114,105,118,101,32,119,104,101,110,32,99,104,97,110,103,105,110,103,32,100,114,105,118,101,115],"value":"Always &go to the root of a drive when changing drives"},
 {"hash":3256530,"name":"tfrmoptionsmisc.chkshowcurdirtitlebar.caption","sourcebytes":[83,104,111,119,32,38,99,117,114,114,101,110,116,32,100,105,114,101,99,116,111,114,121,32,105,110,32,116,104,101,32,109,97,105,110,32,119,105,110,100,111,119,32,116,105,116,108,101,32,98,97,114],"value":"Show &current directory in the main window title bar"},
-{"hash":71209118,"name":"tfrmoptionsmisc.chkshowsplashform.caption","sourcebytes":[83,104,111,119,32,38,115,112,108,97,115,104,32,115,99,114,101,101,110],"value":"Show &splash screen"},
+{"hash":138614058,"name":"tfrmoptionsmisc.lbldefaultencoding.caption","sourcebytes":[38,68,101,102,97,117,108,116,32,115,105,110,103,108,101,45,98,121,116,101,32,116,101,120,116,32,101,110,99,111,100,105,110,103,58],"value":"&Default single-byte text encoding:"},
 {"hash":92360730,"name":"tfrmoptionsmisc.gbtcexportimport.caption","sourcebytes":[82,101,103,97,114,100,105,110,103,32,84,67,32,101,120,112,111,114,116,47,105,109,112,111,114,116,58],"value":"Regarding TC export/import:"},
 {"hash":15252584,"name":"tfrmoptionsmisc.btnrelativetcexecutablefile.hint","sourcebytes":[83,111,109,101,32,102,117,110,99,116,105,111,110,115,32,116,111,32,115,101,108,101,99,116,32,97,112,112,114,111,112,114,105,97,116,101,32,112,97,116,104],"value":"Some functions to select appropriate path"},
 {"hash":164330666,"name":"tfrmoptionsmisc.lbltcexecutable.caption","sourcebytes":[84,67,32,101,120,101,99,117,116,97,98,108,101,58],"value":"TC executable:"},

+ 24 - 0
src/frames/foptionsmisc.pas

@@ -43,9 +43,11 @@ type
     chkShowWarningMessages: TCheckBox;
     cmbDescDefaultEncoding: TComboBox;
     cmbDescCreateEncoding: TComboBox;
+    cmbDefaultEncoding: TComboBox;
     dblThumbnails: TDividerBevel;
     gbExtended: TGroupBox;
     gbFileComments: TGroupBox;
+    lblDefaultEncoding: TLabel;
     lblDescrDefaultEncoding: TLabel;
     lblThumbPixels: TLabel;
     lblThumbSize: TLabel;
@@ -112,13 +114,26 @@ begin
 end;
 
 procedure TfrmOptionsMisc.Init;
+var
+  Index: Integer;
 begin
   FSplashForm:= gSplashForm;
+
+  GetSupportedEncodings(cmbDefaultEncoding.Items);
+  for Index:= cmbDefaultEncoding.Items.Count - 1 downto 0 do
+  begin
+    if (not SingleByteEncoding(cmbDefaultEncoding.Items[Index])) then
+      cmbDefaultEncoding.Items.Delete(Index);
+  end;
+  cmbDefaultEncoding.Items.Insert(0, UpperCase(EncodingNone));
+
   fneTCExecutableFilename.Filter := ParseLineToFileFilter([rsFilterExecutableFiles, '*.exe', rsFilterAnyFiles, '*.*']);
   fneTCConfigFilename.Filter := ParseLineToFileFilter([rsFilterIniConfigFiles, '*.ini', rsFilterAnyFiles, '*.*']);
 end;
 
 procedure TfrmOptionsMisc.Load;
+var
+  Index: Integer;
 begin
   chkShowSplashForm.Checked      := gSplashForm;
   chkShowWarningMessages.Checked := gShowWarningMessages;
@@ -128,6 +143,13 @@ begin
   chkGoToRoot.Checked            := gGoToRoot;
   chkShowCurDirTitleBar.Checked  := gShowCurDirTitleBar;
 
+  Index:= cmbDefaultEncoding.Items.IndexOf(gDefaultTextEncoding);
+  if (Index < 0) then
+    cmbDefaultEncoding.ItemIndex:= 0
+  else begin
+    cmbDefaultEncoding.ItemIndex:= Index;
+  end;
+
   {$IFDEF MSWINDOWS}
   gbTCExportImport.Visible:=True;
   fneTCExecutableFilename.FileName := gTotalCommanderExecutableFilename;
@@ -166,6 +188,8 @@ begin
   gThumbSize.cy        := speThumbHeight.Value;
   gGoToRoot            := chkGoToRoot.Checked;
   gShowCurDirTitleBar  := chkShowCurDirTitleBar.Checked;
+  gDefaultTextEncoding := cmbDefaultEncoding.Text;
+
   {$IFDEF MSWINDOWS}
   gTotalCommanderExecutableFilename := fneTCExecutableFilename.FileName;
   gTotalCommanderConfigFilename := fneTCConfigFilename.FileName;

+ 20 - 7
src/uconvencoding.pas

@@ -3,7 +3,7 @@
    -------------------------------------------------------------------------
    Encoding conversion and related stuff
 
-   Copyright (C) 2011-2018 Alexander Koblov ([email protected])
+   Copyright (C) 2011-2022 Alexander Koblov ([email protected])
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -30,6 +30,7 @@ uses
 
 const
   EncodingOem = 'oem';
+  EncodingNone = 'none';
   EncodingDefault = 'default';
   EncodingUTF16LE = 'utf16le';
   EncodingUTF16BE = 'utf16be';
@@ -49,7 +50,7 @@ implementation
 
 uses
   SysUtils, LazUTF8, LConvEncoding, GetText, DCConvertEncoding,
-  DCUnicodeUtils, nsCore, nsUniversalDetector, uLng;
+  DCUnicodeUtils, nsCore, nsUniversalDetector, uLng, uGlobs;
 
 var
   Lang, FallbackLang: AnsiString;
@@ -402,15 +403,23 @@ function DetectEncoding(const S: String): String;
 var
   L, P: Integer;
   EndPos: Integer;
+  UserEncoding: Boolean;
 begin
+  UserEncoding:= (gDefaultTextEncoding <> EncodingNone);
+
   L:= Length(S);
-  if L = 0 then begin
-    Result:= GetDefaultTextEncoding;
+  if L = 0 then
+  begin
+    if UserEncoding then
+      Result:= gDefaultTextEncoding
+    else begin
+      Result:= GetDefaultTextEncoding;
+    end;
     Exit;
   end;
 
   // Try detect Unicode
-  case DetectEncoding(S, meOEM, False) of
+  case DetectEncoding(S, meOEM, UserEncoding) of
     meUTF8:    Exit(EncodingUTF8);
     meUTF8BOM: Exit(EncodingUTF8BOM);
     meUTF16LE: Exit(EncodingUTF16LE);
@@ -428,8 +437,12 @@ begin
     Exit;
   end;
 
-  // Try to detect encoding
-  Result:= MyDetectCodePageType(S);
+  if UserEncoding then
+    Result:= gDefaultTextEncoding
+  else begin
+    // Try to detect encoding
+    Result:= MyDetectCodePageType(S);
+  end;
 end;
 
 function SingleByteEncoding(TextEncoding: String): Boolean;

+ 4 - 0
src/uglobs.pas

@@ -567,6 +567,7 @@ var
   gDescCreateUnicode: Boolean;
   gDescReadEncoding: TMacroEncoding;
   gDescWriteEncoding: TMacroEncoding;
+  gDefaultTextEncoding: String;
 
   { Auto refresh page }
   gWatchDirs: TWatchOptions;
@@ -1994,6 +1995,7 @@ begin
   gDescReadEncoding:= meUTF8;
   gDescWriteEncoding:= meUTF8BOM;
   gDescCreateUnicode:= True;
+  gDefaultTextEncoding:= EncodingNone;
 
   { Auto refresh page }
   gWatchDirs := [watch_file_name_change, watch_attributes_change];
@@ -3048,6 +3050,7 @@ begin
       gHotDirFilenameStyle := TConfigFilenameStyle(GetValue(Node, 'FilenameStyle', ord(gHotDirFilenameStyle)));
       gHotDirPathToBeRelativeTo := gConfig.GetValue(Node, 'PathToBeRelativeTo', gHotDirPathToBeRelativeTo);
       gHotDirPathModifierElements := tHotDirPathModifierElements(GetValue(Node, 'PathModifierElements', Integer(gHotDirPathModifierElements)));
+      gDefaultTextEncoding := GetValue(Node, 'DefaultTextEncoding', gDefaultTextEncoding);
     end;
 
     { Thumbnails }
@@ -3698,6 +3701,7 @@ begin
     SetValue(Node, 'FilenameStyle', ord(gHotDirFilenameStyle));
     SetValue(Node, 'PathToBeRelativeTo', gHotDirPathToBeRelativeTo);
     SetValue(Node, 'PathModifierElements', Integer(gHotDirPathModifierElements));
+    SetValue(Node, 'DefaultTextEncoding', gDefaultTextEncoding);
 
     { Thumbnails }
     Node := FindNode(Root, 'Thumbnails', True);