View Issue Details

IDProjectCategoryView StatusLast Update
0029979LazarusIDEpublic2016-04-12 17:00
ReportersilvioprogAssigned ToBart Broersma 
PrioritynormalSeverityminorReproducibilityhave not tried
Status closedResolutionfixed 
Product VersionProduct Build 
Target Version1.8Fixed in Version1.8 
Summary0029979: [FEATURE REQUEST] Choosing the files to be converted in the tool "Converte Encoding of Project/Packages"
DescriptionHello,

Sometimes I use this tool to convert some own files, but this option always convert some files that I need to keep in the original encoding.

The attached picture show how would be the idea, that consists in adding checkboxes allowing to choose the files to be converted.

Thank you!
Additional InformationI tried to create a patch, but it seems a little bit complex to be implemented.
TagsNo tags attached.
Fixed in Revisionr52163
LazTarget1.8
Widgetset
Attached Files
  • Capture.PNG (56,766 bytes)
    Capture.PNG (56,766 bytes)
  • changeencoding.diff (10,008 bytes)
    Index: converter/chgencodingdlg.pas
    ===================================================================
    --- converter/chgencodingdlg.pas	(revision 52056)
    +++ converter/chgencodingdlg.pas	(working copy)
    @@ -183,43 +183,53 @@
       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;
    +      if not HasChanged then begin
    +        li:=PreviewListView.Items.Add;
    +        li.Caption:=Filename;
    +        li.SubItems.Add(Encoding);
    +        li.Checked := True;
    +      end;
    +
         end;
    -    if not HasChanged then begin
    -      li:=PreviewListView.Items.Add;
    -      li.Caption:=Filename;
    -      li.SubItems.Add(Encoding);
    -    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 @@
           li:=PreviewListView.Items.Add;
           li.Caption:=Filename;
           li.SubItems.Add(Encoding);
    +      li.Checked := True;
           Node:=FFiles.Tree.FindSuccessor(Node);
         end;
         PreviewListView.EndUpdate;
    Index: converter/chgencodingdlg.lfm
    ===================================================================
    --- converter/chgencodingdlg.lfm	(revision 52056)
    +++ converter/chgencodingdlg.lfm	(working copy)
    @@ -14,14 +14,14 @@
       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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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 @@
           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 @@
       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 @@
           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 @@
         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 @@
       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 @@
           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 @@
           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 @@
           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 @@
       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 @@
       end
       object LabelNoPreview: TLabel
         Left = 20
    -    Height = 17
    -    Top = 267
    +    Height = 15
    +    Top = 238
         Width = 643
         Align = alTop
         BorderSpacing.Around = 20
    
    changeencoding.diff (10,008 bytes)
  • 0001-Improves-the-Convert-Encoding-window.-patch-by-silvi.patch (5,498 bytes)
    From 64d759044fde92058f012a1c42d4b9dac8729c9c Mon Sep 17 00:00:00 2001
    From: silvioprog <silvioprog@gmail.com>
    Date: Mon, 11 Apr 2016 10:31:33 -0300
    Subject: [PATCH 1/1] Improves the Convert Encoding window. (patch by
     silvioprog)
    
    ---
     converter/chgencodingdlg.lfm | 53 +++++++++++++++++++++++++++++++++++++-------
     converter/chgencodingdlg.pas | 25 +++++++++++++++++++++
     ide/lazarusidestrconsts.pas  |  1 +
     3 files changed, 71 insertions(+), 8 deletions(-)
    
    diff --git a/converter/chgencodingdlg.lfm b/converter/chgencodingdlg.lfm
    index 455f5ad..8533f35 100644
    --- a/converter/chgencodingdlg.lfm
    +++ b/converter/chgencodingdlg.lfm
    @@ -1,12 +1,12 @@
     object ChgEncodingDialog: TChgEncodingDialog
       Left = 290
    -  Height = 560
    +  Height = 590
       Top = 163
       Width = 683
       ActiveControl = OwnerComboBox
       BorderIcons = [biSystemMenu, biMaximize]
       Caption = 'ChgEncodingDialog'
    -  ClientHeight = 560
    +  ClientHeight = 590
       ClientWidth = 683
       OnCreate = FormCreate
       OnDestroy = FormDestroy
    @@ -114,7 +114,7 @@ object ChgEncodingDialog: TChgEncodingDialog
       object BtnPanel: TPanel
         Left = 0
         Height = 38
    -    Top = 522
    +    Top = 552
         Width = 683
         Align = alBottom
         AutoSize = True
    @@ -221,19 +221,19 @@ object ChgEncodingDialog: TChgEncodingDialog
       end
       object PreviewGroupBox: TGroupBox
         Left = 6
    -    Height = 243
    +    Height = 273
         Top = 273
         Width = 671
         Align = alClient
         BorderSpacing.Around = 6
         Caption = 'PreviewGroupBox'
    -    ClientHeight = 223
    +    ClientHeight = 253
         ClientWidth = 667
         TabOrder = 2
         object PreviewListView: TListView
           Left = 5
    -      Height = 213
    -      Top = 5
    +      Height = 212
    +      Top = 36
           Width = 657
           Align = alClient
           BorderSpacing.Around = 5
    @@ -251,9 +251,46 @@ object ChgEncodingDialog: TChgEncodingDialog
             end>
           SortColumn = 1
           SortType = stText
    -      TabOrder = 0
    +      TabOrder = 1
           ViewStyle = vsReport
         end
    +    object PreviewHeaderPanel: TPanel
    +      Left = 5
    +      Height = 31
    +      Top = 0
    +      Width = 657
    +      Align = alTop
    +      AutoSize = True
    +      BorderSpacing.Left = 5
    +      BorderSpacing.Right = 5
    +      ClientHeight = 31
    +      ClientWidth = 657
    +      TabOrder = 0
    +      object PreviewSelectAllCheckBox: TCheckBox
    +        Left = 6
    +        Height = 19
    +        Top = 6
    +        Width = 158
    +        Align = alLeft
    +        BorderSpacing.Around = 5
    +        Caption = 'PreviewSelectAllCheckBox'
    +        Checked = True
    +        OnChange = PreviewSelectAllCheckBoxChange
    +        State = cbChecked
    +        TabOrder = 0
    +      end
    +      object PreviewInvertSelectionCheckBox: TCheckBox
    +        Left = 169
    +        Height = 19
    +        Top = 6
    +        Width = 191
    +        Align = alLeft
    +        BorderSpacing.Around = 5
    +        Caption = 'PreviewInvertSelectionCheckBox'
    +        OnChange = PreviewInvertSelectionCheckBoxChange
    +        TabOrder = 1
    +      end
    +    end
       end
       object LabelNoPreview: TLabel
         Left = 20
    diff --git a/converter/chgencodingdlg.pas b/converter/chgencodingdlg.pas
    index f3e7376..6acd7ee 100644
    --- a/converter/chgencodingdlg.pas
    +++ b/converter/chgencodingdlg.pas
    @@ -50,10 +50,13 @@ type
     
       TChgEncodingDialog = class(TForm)
         ApplyButton: TBitBtn;
    +    PreviewSelectAllCheckBox: TCheckBox;
    +    PreviewInvertSelectionCheckBox: TCheckBox;
         HelpButton: TBitBtn;
         BtnPanel: TPanel;
         CloseButton: TBitBtn;
         LabelNoPreview: TLabel;
    +    PreviewHeaderPanel: TPanel;
         RegExprErrorLabel: TLabel;
         NewEncodingComboBox: TComboBox;
         FileFilterCombobox: TComboBox;
    @@ -72,6 +75,8 @@ type
         procedure FormDestroy(Sender: TObject);
         procedure HelpButtonClick(Sender: TObject);
         procedure PreviewClick(Sender: TObject);
    +    procedure PreviewInvertSelectionCheckBoxChange(Sender: TObject);
    +    procedure PreviewSelectAllCheckBoxChange(Sender: TObject);
       private
         FFiles: TFilenameToStringTree;
         function GetFiles: Boolean;
    @@ -121,6 +126,9 @@ begin
       ApplyButton.LoadGlyphFromResourceName(hInstance, 'btn_ok');
       HelpButton.LoadGlyphFromResourceName(hInstance, 'btn_help');
     
    +  PreviewSelectAllCheckBox.Caption := lisMenuSelectAll;
    +  PreviewInvertSelectionCheckBox.Caption := lisMenuInvertSelection;
    +
       PreviewGroupBox.Caption:=dlgWRDPreview;
       PreviewListView.Column[0].Caption:=dlgEnvFiles;
       PreviewListView.Column[0].Width:=350;
    @@ -244,6 +252,23 @@ begin
       UpdatePreview;
     end;
     
    +procedure TChgEncodingDialog.PreviewInvertSelectionCheckBoxChange(
    +  Sender: TObject);
    +var
    +  Item: TListItem;
    +begin
    +  for Item in PreviewListView.Items do
    +    Item.Checked := not Item.Checked;
    +end;
    +
    +procedure TChgEncodingDialog.PreviewSelectAllCheckBoxChange(Sender: TObject);
    +var
    +  Item: TListItem;
    +begin
    +  for Item in PreviewListView.Items do
    +    Item.Checked := PreviewSelectAllCheckBox.Checked;
    +end;
    +
     function TChgEncodingDialog.GetFiles: Boolean;
     // Returns true if some files were found, even if they were not added to list.
     var
    diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas
    index faa6a8a..889a4cf 100644
    --- a/ide/lazarusidestrconsts.pas
    +++ b/ide/lazarusidestrconsts.pas
    @@ -339,6 +339,7 @@ resourcestring
       lisUseAndClose = 'Use and close';
       lisMenuSelect = 'Select';
       lisMenuSelectAll = 'Select All';
    +  lisMenuInvertSelection = 'Invert Selection';
       lisCheckAll = 'Check All';
       lisUncheckAll = 'Uncheck All';
       dlgFiles = '%s files';
    -- 
    1.9.5.msysgit.0
    
    

Relationships

related to 0029996 closedBart Broersma [PATCH] add the "Select All" and "Invert Selection" checkboxes to Converte Encoding window 

Activities

silvioprog

2016-04-06 17:56

reporter  

Capture.PNG (56,766 bytes)
Capture.PNG (56,766 bytes)

Juha Manninen

2016-04-06 18:14

developer   ~0091796

> I tried to create a patch, but it seems a little bit complex to be implemented.

Did you try to add CheckBoxes to a ListView? How? Yes I believe it is difficult.
How about enabling multiselect and converting only selected rows?

silvioprog

2016-04-06 19:57

reporter   ~0091799

> Did you try to add CheckBoxes to a ListView? How? Yes I believe it is difficult.

Yes, you just need to enable it with:

  ListView1.Checkboxes := True;

And to check if the item is checked:

  if ListView1.Items[0].Checked then ...

> How about enabling multiselect and converting only selected rows?

Awesome! :-)

Juha Manninen

2016-04-06 20:59

developer   ~0091800

> ListView1.Checkboxes := True;

Oh, I didn't remember that feature at all. Has it been in TListView always?
Then it should be equally easy to use Checkboxes or multiselection. What kind of problems you encountered?
I don't think this feature will be a high priority for other developers. Everybody has ToDo lists of their own. If you want this quickly, you must implement it yourself.

silvioprog

2016-04-06 21:28

reporter   ~0091801

> Oh, I didn't remember that feature at all.

Hehe.

> Has it been in TListView always?

I successfully tested on Windows (7/10) and Linux (GTK).

> What kind of problems you encountered?

It lists many files that doesn't need to be converted. In the attached picture, I wanted to convert only the files showed in the red box, but there is no an option to select only those files.

Juha Manninen

2016-04-06 23:24

developer   ~0091804

> It lists many files that doesn't need to be converted. ...

Yes but you tried to change that and provide a patch.
The idea was to convert only files that have a checkmark in front of them.
What were the problems you encountered while changing the code?

silvioprog

2016-04-07 02:33

reporter   ~0091807

Hm... btw I can send a patch.

I changed the file "lazarus\converter\ChgEncodingDlg.pas", but I have some questions:

. Is there some package declaring the units IDEProcs, PackageDefs, PackageSystem, Project and LazarusIDEStrConsts?
. I created a dummy project just to call the ShowConvertEncodingDlg function, but I'm not sure how to instantiate the Project1 variable. Can I instantiate this variable outside IDE?

I need to understand it just to try to debug the TChgEncodingDialog class, because in the new possible logic using the checkboxes, I'll need to remove some parts from the code like "PreviewListView.Items.Clear".

Juha Manninen

2016-04-07 10:12

developer   ~0091810

Silvio, just debug the IDE. Open lazarus.lpi and press F9.
Other valid choice for debugging is to add DebugLn() calls that show variable values.

Bart Broersma

2016-04-07 15:54

developer  

changeencoding.diff (10,008 bytes)
Index: converter/chgencodingdlg.pas
===================================================================
--- converter/chgencodingdlg.pas	(revision 52056)
+++ converter/chgencodingdlg.pas	(working copy)
@@ -183,43 +183,53 @@
   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;
+      if not HasChanged then begin
+        li:=PreviewListView.Items.Add;
+        li.Caption:=Filename;
+        li.SubItems.Add(Encoding);
+        li.Checked := True;
+      end;
+
     end;
-    if not HasChanged then begin
-      li:=PreviewListView.Items.Add;
-      li.Caption:=Filename;
-      li.SubItems.Add(Encoding);
-    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 @@
       li:=PreviewListView.Items.Add;
       li.Caption:=Filename;
       li.SubItems.Add(Encoding);
+      li.Checked := True;
       Node:=FFiles.Tree.FindSuccessor(Node);
     end;
     PreviewListView.EndUpdate;
Index: converter/chgencodingdlg.lfm
===================================================================
--- converter/chgencodingdlg.lfm	(revision 52056)
+++ converter/chgencodingdlg.lfm	(working copy)
@@ -14,14 +14,14 @@
   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 @@
       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 @@
       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 @@
       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 @@
       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 @@
       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 @@
       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 @@
   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 @@
       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 @@
     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 @@
   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 @@
       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 @@
       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 @@
       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 @@
   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 @@
   end
   object LabelNoPreview: TLabel
     Left = 20
-    Height = 17
-    Top = 267
+    Height = 15
+    Top = 238
     Width = 643
     Align = alTop
     BorderSpacing.Around = 20
changeencoding.diff (10,008 bytes)

Bart Broersma

2016-04-07 15:54

developer   ~0091822

Attached possiblepatch.
@Juha: please review.

silvioprog

2016-04-07 16:23

reporter   ~0091823

@Bart: it worked like a charm for me. Thanks a lot for this patch! :-)
@Juha: thanks for tip "Open lazarus.lpi and press F9", now I can debug Lazarus IDE and contribute by sending some improvements. :-)

Juha Manninen

2016-04-07 22:29

developer   ~0091830

Bart, the patch looks good. You can commit it also yourself, thus assigning to you.

silvioprog

2016-04-09 05:51

reporter   ~0091873

I'll send some small new improvements after Bart's fix. :-)

Bart Broersma

2016-04-11 10:33

developer   ~0091931

Please test and close if OK.

silvioprog

2016-04-11 15:47

reporter   ~0091943

The attached patch adds the "Select All" and "Invert Selection" checkboxes.

silvioprog

2016-04-11 15:47

reporter  

0001-Improves-the-Convert-Encoding-window.-patch-by-silvi.patch (5,498 bytes)
From 64d759044fde92058f012a1c42d4b9dac8729c9c Mon Sep 17 00:00:00 2001
From: silvioprog <silvioprog@gmail.com>
Date: Mon, 11 Apr 2016 10:31:33 -0300
Subject: [PATCH 1/1] Improves the Convert Encoding window. (patch by
 silvioprog)

---
 converter/chgencodingdlg.lfm | 53 +++++++++++++++++++++++++++++++++++++-------
 converter/chgencodingdlg.pas | 25 +++++++++++++++++++++
 ide/lazarusidestrconsts.pas  |  1 +
 3 files changed, 71 insertions(+), 8 deletions(-)

diff --git a/converter/chgencodingdlg.lfm b/converter/chgencodingdlg.lfm
index 455f5ad..8533f35 100644
--- a/converter/chgencodingdlg.lfm
+++ b/converter/chgencodingdlg.lfm
@@ -1,12 +1,12 @@
 object ChgEncodingDialog: TChgEncodingDialog
   Left = 290
-  Height = 560
+  Height = 590
   Top = 163
   Width = 683
   ActiveControl = OwnerComboBox
   BorderIcons = [biSystemMenu, biMaximize]
   Caption = 'ChgEncodingDialog'
-  ClientHeight = 560
+  ClientHeight = 590
   ClientWidth = 683
   OnCreate = FormCreate
   OnDestroy = FormDestroy
@@ -114,7 +114,7 @@ object ChgEncodingDialog: TChgEncodingDialog
   object BtnPanel: TPanel
     Left = 0
     Height = 38
-    Top = 522
+    Top = 552
     Width = 683
     Align = alBottom
     AutoSize = True
@@ -221,19 +221,19 @@ object ChgEncodingDialog: TChgEncodingDialog
   end
   object PreviewGroupBox: TGroupBox
     Left = 6
-    Height = 243
+    Height = 273
     Top = 273
     Width = 671
     Align = alClient
     BorderSpacing.Around = 6
     Caption = 'PreviewGroupBox'
-    ClientHeight = 223
+    ClientHeight = 253
     ClientWidth = 667
     TabOrder = 2
     object PreviewListView: TListView
       Left = 5
-      Height = 213
-      Top = 5
+      Height = 212
+      Top = 36
       Width = 657
       Align = alClient
       BorderSpacing.Around = 5
@@ -251,9 +251,46 @@ object ChgEncodingDialog: TChgEncodingDialog
         end>
       SortColumn = 1
       SortType = stText
-      TabOrder = 0
+      TabOrder = 1
       ViewStyle = vsReport
     end
+    object PreviewHeaderPanel: TPanel
+      Left = 5
+      Height = 31
+      Top = 0
+      Width = 657
+      Align = alTop
+      AutoSize = True
+      BorderSpacing.Left = 5
+      BorderSpacing.Right = 5
+      ClientHeight = 31
+      ClientWidth = 657
+      TabOrder = 0
+      object PreviewSelectAllCheckBox: TCheckBox
+        Left = 6
+        Height = 19
+        Top = 6
+        Width = 158
+        Align = alLeft
+        BorderSpacing.Around = 5
+        Caption = 'PreviewSelectAllCheckBox'
+        Checked = True
+        OnChange = PreviewSelectAllCheckBoxChange
+        State = cbChecked
+        TabOrder = 0
+      end
+      object PreviewInvertSelectionCheckBox: TCheckBox
+        Left = 169
+        Height = 19
+        Top = 6
+        Width = 191
+        Align = alLeft
+        BorderSpacing.Around = 5
+        Caption = 'PreviewInvertSelectionCheckBox'
+        OnChange = PreviewInvertSelectionCheckBoxChange
+        TabOrder = 1
+      end
+    end
   end
   object LabelNoPreview: TLabel
     Left = 20
diff --git a/converter/chgencodingdlg.pas b/converter/chgencodingdlg.pas
index f3e7376..6acd7ee 100644
--- a/converter/chgencodingdlg.pas
+++ b/converter/chgencodingdlg.pas
@@ -50,10 +50,13 @@ type
 
   TChgEncodingDialog = class(TForm)
     ApplyButton: TBitBtn;
+    PreviewSelectAllCheckBox: TCheckBox;
+    PreviewInvertSelectionCheckBox: TCheckBox;
     HelpButton: TBitBtn;
     BtnPanel: TPanel;
     CloseButton: TBitBtn;
     LabelNoPreview: TLabel;
+    PreviewHeaderPanel: TPanel;
     RegExprErrorLabel: TLabel;
     NewEncodingComboBox: TComboBox;
     FileFilterCombobox: TComboBox;
@@ -72,6 +75,8 @@ type
     procedure FormDestroy(Sender: TObject);
     procedure HelpButtonClick(Sender: TObject);
     procedure PreviewClick(Sender: TObject);
+    procedure PreviewInvertSelectionCheckBoxChange(Sender: TObject);
+    procedure PreviewSelectAllCheckBoxChange(Sender: TObject);
   private
     FFiles: TFilenameToStringTree;
     function GetFiles: Boolean;
@@ -121,6 +126,9 @@ begin
   ApplyButton.LoadGlyphFromResourceName(hInstance, 'btn_ok');
   HelpButton.LoadGlyphFromResourceName(hInstance, 'btn_help');
 
+  PreviewSelectAllCheckBox.Caption := lisMenuSelectAll;
+  PreviewInvertSelectionCheckBox.Caption := lisMenuInvertSelection;
+
   PreviewGroupBox.Caption:=dlgWRDPreview;
   PreviewListView.Column[0].Caption:=dlgEnvFiles;
   PreviewListView.Column[0].Width:=350;
@@ -244,6 +252,23 @@ begin
   UpdatePreview;
 end;
 
+procedure TChgEncodingDialog.PreviewInvertSelectionCheckBoxChange(
+  Sender: TObject);
+var
+  Item: TListItem;
+begin
+  for Item in PreviewListView.Items do
+    Item.Checked := not Item.Checked;
+end;
+
+procedure TChgEncodingDialog.PreviewSelectAllCheckBoxChange(Sender: TObject);
+var
+  Item: TListItem;
+begin
+  for Item in PreviewListView.Items do
+    Item.Checked := PreviewSelectAllCheckBox.Checked;
+end;
+
 function TChgEncodingDialog.GetFiles: Boolean;
 // Returns true if some files were found, even if they were not added to list.
 var
diff --git a/ide/lazarusidestrconsts.pas b/ide/lazarusidestrconsts.pas
index faa6a8a..889a4cf 100644
--- a/ide/lazarusidestrconsts.pas
+++ b/ide/lazarusidestrconsts.pas
@@ -339,6 +339,7 @@ resourcestring
   lisUseAndClose = 'Use and close';
   lisMenuSelect = 'Select';
   lisMenuSelectAll = 'Select All';
+  lisMenuInvertSelection = 'Invert Selection';
   lisCheckAll = 'Check All';
   lisUncheckAll = 'Uncheck All';
   dlgFiles = '%s files';
-- 
1.9.5.msysgit.0

Bart Broersma

2016-04-11 16:55

developer   ~0091944

@Silvio: nex time please re-open the issue, don't just add a note and another patch.
It's just by chance I looked at it after I resolved it.

silvioprog

2016-04-11 20:14

reporter   ~0091949

Hm... mantis always confuse me. ^^'

Bart Broersma

2016-04-11 23:38

developer   ~0091955

Even more: the original issue was resolved (you now have the ability to select the files).
Now you want to improve that solution.
You really should open a new ticket for that and attach the patch there.

Why?
1) In the svn-log we refer to the bugtracker if an issue is solved.
It is confusing if multiple log entries refer to the same issue.

2) In theory you could keep on adding improvements to this feature and this ticket would ever be closed.

silvioprog

2016-04-12 01:45

reporter   ~0091959

I didn't know about this mantis details. Done: http://bugs.freepascal.org/view.php?id=29996.

silvioprog

2016-04-12 01:45

reporter   ~0091960

Please close this issue.

Juha Manninen

2016-04-12 01:58

developer   ~0091962

> You really should open a new ticket for that and attach the patch there.

Bart, it is quite OK to use the same issue for related patches.
At least I have had the same issue open for many incremental improvements of one feature if there are not VERY many of them.
It is not confusing when the commits are for the same thing.
It also means less administrative work. Opening and resolving many issues and marking them as related is more work.

Bart Broersma

2016-04-12 15:32

developer   ~0091974

@Silvio: please close.
@Juha: obviously I disagree with you ;-)

Issue History

Date Modified Username Field Change
2016-04-06 17:56 silvioprog New Issue
2016-04-06 17:56 silvioprog File Added: Capture.PNG
2016-04-06 18:14 Juha Manninen Note Added: 0091796
2016-04-06 19:57 silvioprog Note Added: 0091799
2016-04-06 20:59 Juha Manninen Note Added: 0091800
2016-04-06 21:28 silvioprog Note Added: 0091801
2016-04-06 23:24 Juha Manninen Note Added: 0091804
2016-04-07 02:33 silvioprog Note Added: 0091807
2016-04-07 10:12 Juha Manninen Note Added: 0091810
2016-04-07 15:54 Bart Broersma File Added: changeencoding.diff
2016-04-07 15:54 Bart Broersma Assigned To => Juha Manninen
2016-04-07 15:54 Bart Broersma Status new => assigned
2016-04-07 15:54 Bart Broersma Note Added: 0091822
2016-04-07 16:23 silvioprog Note Added: 0091823
2016-04-07 22:28 Juha Manninen Assigned To Juha Manninen => Bart Broersma
2016-04-07 22:29 Juha Manninen Note Added: 0091830
2016-04-09 05:51 silvioprog Note Added: 0091873
2016-04-11 10:33 Bart Broersma Fixed in Revision => r52163
2016-04-11 10:33 Bart Broersma LazTarget => 1.8
2016-04-11 10:33 Bart Broersma Note Added: 0091931
2016-04-11 10:33 Bart Broersma Status assigned => resolved
2016-04-11 10:33 Bart Broersma Fixed in Version => 1.8
2016-04-11 10:33 Bart Broersma Resolution open => fixed
2016-04-11 10:33 Bart Broersma Target Version => 1.8
2016-04-11 15:47 silvioprog Note Added: 0091943
2016-04-11 15:47 silvioprog File Added: 0001-Improves-the-Convert-Encoding-window.-patch-by-silvi.patch
2016-04-11 16:55 Bart Broersma Note Added: 0091944
2016-04-11 16:55 Bart Broersma Status resolved => feedback
2016-04-11 20:14 silvioprog Note Added: 0091949
2016-04-11 20:14 silvioprog Status feedback => assigned
2016-04-11 23:38 Bart Broersma Note Added: 0091955
2016-04-11 23:38 Bart Broersma Status assigned => feedback
2016-04-12 01:45 silvioprog Note Added: 0091959
2016-04-12 01:45 silvioprog Status feedback => assigned
2016-04-12 01:45 silvioprog Note Added: 0091960
2016-04-12 01:58 Juha Manninen Note Added: 0091962
2016-04-12 15:32 Bart Broersma Note Added: 0091974
2016-04-12 15:32 Bart Broersma Status assigned => resolved
2016-04-12 16:04 Juha Manninen Relationship added related to 0029996
2016-04-12 17:00 silvioprog Status resolved => closed