mirror of
https://gitlab.com/freepascal.org/lazarus/lazarus.git
synced 2025-08-29 08:50:16 +02:00
Converter: ChangeEncodingDlg: implement a mechanism to let user select which files are to be converted. Issue #0029979.
git-svn-id: trunk@52163 -
This commit is contained in:
parent
af42b4185f
commit
446f6a0930
@ -14,14 +14,14 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
LCLVersion = '1.7'
|
||||
object FilesGroupBox: TGroupBox
|
||||
Left = 6
|
||||
Height = 173
|
||||
Top = 74
|
||||
Height = 151
|
||||
Top = 67
|
||||
Width = 671
|
||||
Align = alTop
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'FilesGroupBox'
|
||||
ClientHeight = 154
|
||||
ClientHeight = 131
|
||||
ClientWidth = 667
|
||||
TabOrder = 1
|
||||
object FileFilterLabel: TLabel
|
||||
@ -29,9 +29,9 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideTop.Control = NonUTF8FilesCheckBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 17
|
||||
Top = 66
|
||||
Width = 97
|
||||
Height = 15
|
||||
Top = 56
|
||||
Width = 72
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'FileFilterLabel'
|
||||
ParentColor = False
|
||||
@ -40,9 +40,9 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideLeft.Control = FilesGroupBox
|
||||
AnchorSideTop.Control = FilesGroupBox
|
||||
Left = 6
|
||||
Height = 24
|
||||
Height = 19
|
||||
Top = 6
|
||||
Width = 157
|
||||
Width = 122
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'UTF8FilesCheckBox'
|
||||
Checked = True
|
||||
@ -55,9 +55,9 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideTop.Control = UTF8FilesCheckBox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 24
|
||||
Top = 36
|
||||
Width = 185
|
||||
Height = 19
|
||||
Top = 31
|
||||
Width = 145
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'NonUTF8FilesCheckBox'
|
||||
Checked = True
|
||||
@ -70,9 +70,9 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideTop.Control = FileFilterCombobox
|
||||
AnchorSideTop.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 24
|
||||
Top = 124
|
||||
Width = 148
|
||||
Height = 19
|
||||
Top = 106
|
||||
Width = 114
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'RegExprCheckBox'
|
||||
OnChange = PreviewClick
|
||||
@ -85,12 +85,12 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideRight.Control = FilesGroupBox
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 6
|
||||
Height = 29
|
||||
Top = 89
|
||||
Height = 23
|
||||
Top = 77
|
||||
Width = 655
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
ItemHeight = 15
|
||||
OnChange = PreviewClick
|
||||
TabOrder = 2
|
||||
Text = 'FileFilterCombobox'
|
||||
@ -100,10 +100,10 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideLeft.Side = asrBottom
|
||||
AnchorSideTop.Control = RegExprCheckBox
|
||||
AnchorSideTop.Side = asrCenter
|
||||
Left = 160
|
||||
Height = 17
|
||||
Top = 128
|
||||
Width = 128
|
||||
Left = 126
|
||||
Height = 15
|
||||
Top = 108
|
||||
Width = 95
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'RegExprErrorLabel'
|
||||
Font.Color = clFuchsia
|
||||
@ -113,20 +113,20 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
end
|
||||
object BtnPanel: TPanel
|
||||
Left = 0
|
||||
Height = 41
|
||||
Top = 519
|
||||
Height = 38
|
||||
Top = 522
|
||||
Width = 683
|
||||
Align = alBottom
|
||||
AutoSize = True
|
||||
BevelOuter = bvNone
|
||||
ClientHeight = 41
|
||||
ClientHeight = 38
|
||||
ClientWidth = 683
|
||||
TabOrder = 3
|
||||
object CloseButton: TBitBtn
|
||||
Left = 582
|
||||
Height = 29
|
||||
Left = 586
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 95
|
||||
Width = 91
|
||||
Align = alRight
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
@ -136,10 +136,10 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
TabOrder = 2
|
||||
end
|
||||
object ApplyButton: TBitBtn
|
||||
Left = 479
|
||||
Height = 29
|
||||
Left = 487
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 97
|
||||
Width = 93
|
||||
Align = alRight
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
@ -150,9 +150,9 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
end
|
||||
object HelpButton: TBitBtn
|
||||
Left = 6
|
||||
Height = 29
|
||||
Height = 26
|
||||
Top = 6
|
||||
Width = 63
|
||||
Width = 71
|
||||
Align = alLeft
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
@ -164,14 +164,14 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
end
|
||||
object ScopeGroupBox: TGroupBox
|
||||
Left = 6
|
||||
Height = 62
|
||||
Height = 55
|
||||
Top = 6
|
||||
Width = 671
|
||||
Align = alTop
|
||||
AutoSize = True
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'ScopeGroupBox'
|
||||
ClientHeight = 43
|
||||
ClientHeight = 35
|
||||
ClientWidth = 667
|
||||
TabOrder = 0
|
||||
object NewEncodingLabel: TLabel
|
||||
@ -179,10 +179,10 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideTop.Control = NewEncodingComboBox
|
||||
AnchorSideTop.Side = asrCenter
|
||||
AnchorSideRight.Control = NewEncodingComboBox
|
||||
Left = 400
|
||||
Height = 17
|
||||
Top = 13
|
||||
Width = 128
|
||||
Left = 426
|
||||
Height = 15
|
||||
Top = 10
|
||||
Width = 102
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'NewEncodingLabel'
|
||||
@ -193,12 +193,12 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideTop.Control = ScopeGroupBox
|
||||
AnchorSideRight.Control = NewEncodingLabel
|
||||
Left = 6
|
||||
Height = 31
|
||||
Height = 23
|
||||
Top = 6
|
||||
Width = 388
|
||||
Width = 414
|
||||
Anchors = [akTop, akLeft, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
ItemHeight = 15
|
||||
OnChange = PreviewClick
|
||||
Style = csDropDownList
|
||||
TabOrder = 0
|
||||
@ -208,12 +208,12 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
AnchorSideRight.Control = ScopeGroupBox
|
||||
AnchorSideRight.Side = asrBottom
|
||||
Left = 534
|
||||
Height = 31
|
||||
Height = 23
|
||||
Top = 6
|
||||
Width = 127
|
||||
Anchors = [akTop, akRight]
|
||||
BorderSpacing.Around = 6
|
||||
ItemHeight = 0
|
||||
ItemHeight = 15
|
||||
OnChange = PreviewClick
|
||||
Style = csDropDownList
|
||||
TabOrder = 1
|
||||
@ -221,32 +221,33 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
end
|
||||
object PreviewGroupBox: TGroupBox
|
||||
Left = 6
|
||||
Height = 209
|
||||
Top = 304
|
||||
Height = 243
|
||||
Top = 273
|
||||
Width = 671
|
||||
Align = alClient
|
||||
BorderSpacing.Around = 6
|
||||
Caption = 'PreviewGroupBox'
|
||||
ClientHeight = 190
|
||||
ClientHeight = 223
|
||||
ClientWidth = 667
|
||||
TabOrder = 2
|
||||
object PreviewListView: TListView
|
||||
Left = 5
|
||||
Height = 180
|
||||
Height = 213
|
||||
Top = 5
|
||||
Width = 657
|
||||
Align = alClient
|
||||
BorderSpacing.Around = 5
|
||||
Checkboxes = True
|
||||
Columns = <
|
||||
item
|
||||
AutoSize = True
|
||||
Caption = 'Files'
|
||||
Width = 41
|
||||
Width = 653
|
||||
end
|
||||
item
|
||||
AutoSize = True
|
||||
Caption = 'Encoding'
|
||||
Width = 598
|
||||
Width = 62
|
||||
end>
|
||||
SortColumn = 1
|
||||
SortType = stText
|
||||
@ -256,8 +257,8 @@ object ChgEncodingDialog: TChgEncodingDialog
|
||||
end
|
||||
object LabelNoPreview: TLabel
|
||||
Left = 20
|
||||
Height = 17
|
||||
Top = 267
|
||||
Height = 15
|
||||
Top = 238
|
||||
Width = 643
|
||||
Align = alTop
|
||||
BorderSpacing.Around = 20
|
||||
|
@ -183,43 +183,53 @@ var
|
||||
Item: PStringToStringTreeItem;
|
||||
Filename: String;
|
||||
HasChanged: boolean;
|
||||
li: TListItem;
|
||||
li, Cur: TListItem;
|
||||
OldCount, i: Integer;
|
||||
begin
|
||||
HasChanged:=False;
|
||||
NewEncoding:=NormalizeEncoding(NewEncodingComboBox.Text);
|
||||
PreviewListView.BeginUpdate;
|
||||
PreviewListView.Items.Clear;
|
||||
OldCount := PreviewListView.Items.Count;
|
||||
Node:=FFiles.Tree.FindLowest;
|
||||
while Node<>nil do begin
|
||||
Item:=PStringToStringTreeItem(Node.Data);
|
||||
Filename:=Item^.Name;
|
||||
Encoding:=Item^.Value;
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick Filename=',Filename,' Encoding=',Encoding]);
|
||||
Buf:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||
if (Buf<>nil) and (not Buf.ReadOnly) then begin
|
||||
OldEncoding:=Buf.DiskEncoding;
|
||||
SrcEdit:=SourceEditorManagerIntf.SourceEditorIntfWithFilename(Filename);
|
||||
HasChanged:=true;
|
||||
if SrcEdit<>nil then begin
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick changing in source editor: ',Filename]);
|
||||
Buf.DiskEncoding:=NewEncoding;
|
||||
SrcEdit.Modified:=true;
|
||||
end else begin
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick changing on disk: ',Filename]);
|
||||
// Buf:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||
Buf.DiskEncoding:=NewEncoding;
|
||||
HasChanged:=Buf.Save;
|
||||
if not HasChanged then
|
||||
Buf.DiskEncoding:=OldEncoding;
|
||||
|
||||
Cur := PreviewListView.Items.FindCaption(0, Filename, False, True, False);
|
||||
if Assigned(Cur) and Cur.Checked then
|
||||
begin
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick Filename=',Filename,' Encoding=',Encoding]);
|
||||
Buf:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||
if (Buf<>nil) and (not Buf.ReadOnly) then begin
|
||||
OldEncoding:=Buf.DiskEncoding;
|
||||
SrcEdit:=SourceEditorManagerIntf.SourceEditorIntfWithFilename(Filename);
|
||||
HasChanged:=true;
|
||||
if SrcEdit<>nil then begin
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick changing in source editor: ',Filename]);
|
||||
Buf.DiskEncoding:=NewEncoding;
|
||||
SrcEdit.Modified:=true;
|
||||
end else begin
|
||||
DebugLn(['TChgEncodingDialog.ApplyButtonClick changing on disk: ',Filename]);
|
||||
// Buf:=CodeToolBoss.LoadFile(Filename,true,false);
|
||||
Buf.DiskEncoding:=NewEncoding;
|
||||
HasChanged:=Buf.Save;
|
||||
if not HasChanged then
|
||||
Buf.DiskEncoding:=OldEncoding;
|
||||
end;
|
||||
end;
|
||||
end;
|
||||
if not HasChanged then begin
|
||||
li:=PreviewListView.Items.Add;
|
||||
li.Caption:=Filename;
|
||||
li.SubItems.Add(Encoding);
|
||||
if not HasChanged then begin
|
||||
li:=PreviewListView.Items.Add;
|
||||
li.Caption:=Filename;
|
||||
li.SubItems.Add(Encoding);
|
||||
li.Checked := True;
|
||||
end;
|
||||
|
||||
end;
|
||||
Node:=FFiles.Tree.FindSuccessor(Node);
|
||||
end;
|
||||
// Now delete all old nodes in PreviewListView
|
||||
for i := OldCount - 1 downto 0 do PreviewListView.Items.Delete(i);
|
||||
PreviewListView.EndUpdate;
|
||||
PreviewGroupBox.Caption:=Format(lisEncodingNumberOfFilesFailed, [PreviewListView.Items.Count]);
|
||||
end;
|
||||
@ -376,6 +386,7 @@ begin
|
||||
li:=PreviewListView.Items.Add;
|
||||
li.Caption:=Filename;
|
||||
li.SubItems.Add(Encoding);
|
||||
li.Checked := True;
|
||||
Node:=FFiles.Tree.FindSuccessor(Node);
|
||||
end;
|
||||
PreviewListView.EndUpdate;
|
||||
|
Loading…
Reference in New Issue
Block a user