ソースを参照

First bit of duplicate code removal. Also fixes a memory leak in TCFLWForm.

Martijn Laan 1 年間 前
コミット
bd175e29d4
4 ファイル変更242 行追加179 行削除
  1. 127 127
      Projects/CompFileListWin.dfm
  2. 13 24
      Projects/CompFileListWin.pas
  3. 0 1
      Projects/CompWizard.dfm
  4. 102 27
      Projects/CompWizard.pas

+ 127 - 127
Projects/CompFileListWin.dfm

@@ -1,127 +1,127 @@
-object CFLWForm: TCFLWForm
-  Left = 624
-  Top = 375
-  BorderStyle = bsDialog
-  Caption = 'Insert File List Field'
-  ClientHeight = 458
-  ClientWidth = 636
-  Color = clBtnFace
-  Font.Charset = DEFAULT_CHARSET
-  Font.Color = clWindowText
-  Font.Height = -12
-  Font.Name = 'Segoe UI'
-  Font.Style = []
-  Position = poDesktopCenter
-  OnCreate = FormCreate
-  DesignSize = (
-    636
-    458)
-  TextHeight = 15
-  object Panel1: TPanel
-    Left = 0
-    Top = 408
-    Width = 636
-    Height = 50
-    Align = alBottom
-    TabOrder = 0
-    ExplicitTop = 399
-    ExplicitWidth = 630
-    DesignSize = (
-      636
-      50)
-    object CFLWButtonOK: TButton
-      Left = 408
-      Top = 16
-      Width = 75
-      Height = 25
-      Caption = 'Insert'
-      ModalResult = 1
-      TabOrder = 0
-    end
-    object CFLWButtonCancel: TButton
-      Left = 503
-      Top = 16
-      Width = 75
-      Height = 25
-      Anchors = [akRight, akBottom]
-      Cancel = True
-      Caption = 'Cancel'
-      ModalResult = 2
-      TabOrder = 1
-      ExplicitLeft = 497
-    end
-  end
-  object AppFilesEditButton: TButton
-    Left = 514
-    Top = 152
-    Width = 89
-    Height = 23
-    Anchors = [akTop, akRight]
-    Caption = '&Edit...'
-    TabOrder = 1
-    OnClick = AppFilesEditButtonClick
-  end
-  object AppFilesRemoveButton: TButton
-    Left = 514
-    Top = 180
-    Width = 89
-    Height = 23
-    Anchors = [akTop, akRight]
-    Caption = 'Remo&ve'
-    TabOrder = 2
-    OnClick = AppFilesRemoveButtonClick
-  end
-  object AppFilesAddDirButton: TButton
-    Left = 514
-    Top = 124
-    Width = 89
-    Height = 23
-    Anchors = [akTop, akRight]
-    Caption = 'Add fol&der...'
-    TabOrder = 3
-    OnClick = AppFilesAddDirButtonClick
-  end
-  object AppFilesAddButton: TButton
-    Left = 514
-    Top = 96
-    Width = 89
-    Height = 23
-    Anchors = [akTop, akRight]
-    Caption = '&Add file(s)...'
-    TabOrder = 4
-    OnClick = AppFilesAddButtonClick
-  end
-  object AppFilesListBox: TDropListBox
-    Left = 20
-    Top = 96
-    Width = 457
-    Height = 297
-    Anchors = [akLeft, akTop, akRight, akBottom]
-    ItemHeight = 15
-    TabOrder = 5
-    OnClick = AppFilesListBoxClick
-    OnDblClick = AppFilesListBoxDblClick
-    OnDropFile = AppFilesListBoxDropFile
-  end
-  object AppFilesLabel: TNewStaticText
-    Left = 20
-    Top = 62
-    Width = 415
-    Height = 16
-    Anchors = [akLeft, akTop, akRight]
-    AutoSize = False
-    Caption = 'Other application &files:'
-    FocusControl = AppFilesListBox
-    TabOrder = 6
-    WordWrap = True
-  end
-  object NotCreateAppDirCheck: TCheckBox
-    Left = 20
-    Top = 24
-    Width = 257
-    Height = 17
-    Anchors = [akLeft, akTop, akRight]
-    Caption = 'The application doe&sn'#39't need a folder'
-    TabOrder = 7
-  end
-end
+object CFLWForm: TCFLWForm
+  Left = 624
+  Top = 375
+  BorderStyle = bsDialog
+  Caption = 'Insert File List Field'
+  ClientHeight = 458
+  ClientWidth = 636
+  Color = clBtnFace
+  Font.Charset = DEFAULT_CHARSET
+  Font.Color = clWindowText
+  Font.Height = -12
+  Font.Name = 'Segoe UI'
+  Font.Style = []
+  Position = poDesktopCenter
+  OnCreate = FormCreate
+  OnDestroy = FormDestroy
+  DesignSize = (
+    636
+    458)
+  TextHeight = 15
+  object Panel1: TPanel
+    Left = 0
+    Top = 408
+    Width = 636
+    Height = 50
+    Align = alBottom
+    TabOrder = 0
+    ExplicitTop = 399
+    ExplicitWidth = 630
+    DesignSize = (
+      636
+      50)
+    object CFLWButtonOK: TButton
+      Left = 408
+      Top = 16
+      Width = 75
+      Height = 25
+      Caption = 'Insert'
+      ModalResult = 1
+      TabOrder = 0
+    end
+    object CFLWButtonCancel: TButton
+      Left = 503
+      Top = 16
+      Width = 75
+      Height = 25
+      Anchors = [akRight, akBottom]
+      Cancel = True
+      Caption = 'Cancel'
+      ModalResult = 2
+      TabOrder = 1
+      ExplicitLeft = 497
+    end
+  end
+  object AppFilesEditButton: TButton
+    Left = 514
+    Top = 152
+    Width = 89
+    Height = 23
+    Anchors = [akTop, akRight]
+    Caption = '&Edit...'
+    TabOrder = 1
+    OnClick = AppFilesEditButtonClick
+  end
+  object AppFilesRemoveButton: TButton
+    Left = 514
+    Top = 180
+    Width = 89
+    Height = 23
+    Anchors = [akTop, akRight]
+    Caption = 'Remo&ve'
+    TabOrder = 2
+    OnClick = AppFilesRemoveButtonClick
+  end
+  object AppFilesAddDirButton: TButton
+    Left = 514
+    Top = 124
+    Width = 89
+    Height = 23
+    Anchors = [akTop, akRight]
+    Caption = 'Add fol&der...'
+    TabOrder = 3
+    OnClick = AppFilesAddDirButtonClick
+  end
+  object AppFilesAddButton: TButton
+    Left = 514
+    Top = 96
+    Width = 89
+    Height = 23
+    Anchors = [akTop, akRight]
+    Caption = '&Add file(s)...'
+    TabOrder = 4
+  end
+  object AppFilesListBox: TDropListBox
+    Left = 20
+    Top = 96
+    Width = 457
+    Height = 297
+    Anchors = [akLeft, akTop, akRight, akBottom]
+    ItemHeight = 15
+    TabOrder = 5
+    OnClick = AppFilesListBoxClick
+    OnDblClick = AppFilesListBoxDblClick
+    OnDropFile = AppFilesListBoxDropFile
+  end
+  object AppFilesLabel: TNewStaticText
+    Left = 20
+    Top = 62
+    Width = 415
+    Height = 16
+    Anchors = [akLeft, akTop, akRight]
+    AutoSize = False
+    Caption = 'Other application &files:'
+    FocusControl = AppFilesListBox
+    TabOrder = 6
+    WordWrap = True
+  end
+  object NotCreateAppDirCheck: TCheckBox
+    Left = 20
+    Top = 24
+    Width = 257
+    Height = 17
+    Anchors = [akLeft, akTop, akRight]
+    Caption = 'The application doe&sn'#39't need a folder'
+    TabOrder = 7
+  end
+end

+ 13 - 24
Projects/CompFileListWin.pas

@@ -5,7 +5,7 @@ interface
 uses
   Windows, Messages, SysUtils, Variants, Classes, Graphics,
   Controls, Forms, Dialogs,ExtCtrls, StdCtrls,
-  NewStaticText, DropListBox;
+  NewStaticText, DropListBox, CompWizard;
 
 type
   TCFLWForm = class(TForm)
@@ -19,7 +19,6 @@ type
     AppFilesListBox: TDropListBox;
     AppFilesLabel: TNewStaticText;
     NotCreateAppDirCheck: TCheckBox;
-    procedure AppFilesAddButtonClick(Sender: TObject);
     procedure AppFilesAddDirButtonClick(Sender: TObject);
     procedure AppFilesEditButtonClick(Sender: TObject);
     procedure AppFilesRemoveButtonClick(Sender: TObject);
@@ -28,8 +27,10 @@ type
     procedure AppFilesListBoxDblClick(Sender: TObject);
     procedure AppFilesListBoxDropFile(Sender: TDropListBox;
       const FileName: string);
+    procedure FormDestroy(Sender: TObject);
   private
-    FWizardFiles: TList;
+    FWizardFiles: TList; //todo: remove?
+    FAppFilesPageHelper: TWizardFormAppFilesPageHelper;
     function GetText: String;
     procedure AddWizardFile(const Source: String;
       const RecurseSubDirs, CreateAllSubDirs: Boolean);
@@ -84,26 +85,6 @@ begin
   UpdateHorizontalExtent(AppFilesListBox);
 end;
 
-procedure TCFLWForm.AppFilesAddButtonClick(Sender: TObject);
-var
-  FileList: TStringList;
-  I: Integer;
-begin
-  FileList := TStringList.Create;
-  try
-    if NewGetOpenFileNameMulti('', FileList, '', SWizardAllFilesFilter, '',
-      Handle) then
-    begin
-      FileList.Sort;
-      for I := 0 to FileList.Count - 1 do
-        AddWizardFile(FileList[I], False, False);
-        UpdateWizardFiles;
-    end;
-  finally
-    FileList.Free;
-  end;
-end;
-
 procedure TCFLWForm.AppFilesAddDirButtonClick(Sender: TObject);
 var
   Path: String;
@@ -185,7 +166,15 @@ end;
 
 procedure TCFLWForm.FormCreate(Sender: TObject);
 begin
-   FWizardFiles := TList.Create;
+  FAppFilesPageHelper := TWizardFormAppFilesPageHelper.Create(Handle, FWizardFiles,
+    NotCreateAppDirCheck, AppFilesAddButton, AppFilesListBox);
+
+  FWizardFiles := FAppFilesPageHelper.WizardFiles;
+end;
+
+procedure TCFLWForm.FormDestroy(Sender: TObject);
+begin
+  FAppFilesPageHelper.Free;
 end;
 
 procedure TCFLWForm.UpdateWizardFilesButtons;

+ 0 - 1
Projects/CompWizard.dfm

@@ -533,7 +533,6 @@ object WizardForm: TWizardForm
             Anchors = [akTop, akRight]
             Caption = '&Add file(s)...'
             TabOrder = 7
-            OnClick = AppFilesAddButtonClick
           end
           object AppFilesEditButton: TButton
             Left = 360

+ 102 - 27
Projects/CompWizard.pas

@@ -15,7 +15,8 @@ interface
 
 uses
   Windows, Forms, Classes, Graphics, StdCtrls, ExtCtrls, Controls, Dialogs,
-  UIStateForm, NewStaticText, DropListBox, NewCheckListBox, NewNotebook;
+  UIStateForm, NewStaticText, DropListBox, NewCheckListBox, NewNotebook,
+  pngimage;
 
 type
   TWizardPage = (wpWelcome, wpAppInfo, wpAppDir, wpAppFiles, wpAppAssoc, wpAppIcons,
@@ -24,6 +25,23 @@ type
 
   TWizardFormResult = (wrNone, wrEmpty, wrComplete);
 
+  TWizardFormAppFilesPageHelper = class
+    private
+      FWizardFiles: TList;
+      FHandle: HWND;
+      FNotCreateAppDirCheck: TCheckBox;
+      FAppFilesListBox: TDropListBox;
+      procedure AddWizardFile(const Source: String; const RecurseSubDirs, CreateAllSubDirs: Boolean);
+      procedure UpdateWizardFiles;
+      procedure AddButtonClick(Sender: TObject);
+    public
+      property WizardFiles: TList read FWizardFiles;
+      constructor Create(const Handle: HWND; const WizardFiles: TList;
+        const NotCreateAppDirCheck: TCheckBox; const AppFilesAddButton: TButton;
+        const AppFilesListBox: TDropListBox);
+      destructor Destroy;
+  end;
+
   TWizardForm = class(TUIStateForm)
     CancelButton: TButton;
     NextButton: TButton;
@@ -142,7 +160,6 @@ type
     procedure AppExeButtonClick(Sender: TObject);
     procedure AppFilesListBoxClick(Sender: TObject);
     procedure AppFilesListBoxDblClick(Sender: TObject);
-    procedure AppFilesAddButtonClick(Sender: TObject);
     procedure NotDisableProgramGroupPageCheckClick(Sender: TObject);
     procedure AppFilesEditButtonClick(Sender: TObject);
     procedure AppFilesRemoveButtonClick(Sender: TObject);
@@ -160,14 +177,16 @@ type
   private
     CurPage: TWizardPage;
     FWizardName: String;
-    FWizardFiles: TList;
+    FWizardFiles: TList; //todo: remove?
     FLanguages: TStringList;
+    FAppFilesPageHelper: TWizardFormAppFilesPageHelper;
     FResult: TWizardFormResult;
     FResultScript: String;
     function FixLabel(const S: String): String;
     procedure SetWizardName(const WizardName: String);
     procedure CurPageChanged;
     function SkipCurPage: Boolean;
+    //todo remove!!!
     procedure AddWizardFile(const Source: String; const RecurseSubDirs, CreateAllSubDirs: Boolean);
     procedure UpdateWizardFiles;
     procedure UpdateWizardFilesButtons;
@@ -284,7 +303,6 @@ begin
   FResult := wrNone;
 
   FWizardName := SWizardDefaultName;
-  FWizardFiles := TList.Create;
 
   FLanguages := TStringList.Create;
   FLanguages.Sorted := True;
@@ -294,6 +312,11 @@ begin
   FLanguages.Sorted := False;
   FLanguages.Insert(0, LanguagesDefaultIsl);
 
+  FAppFilesPageHelper := TWizardFormAppFilesPageHelper.Create(Handle, FWizardFiles,
+    NotCreateAppDirCheck, AppFilesAddButton, AppFilesListBox);
+
+  FWizardFiles := FAppFilesPageHelper.WizardFiles;
+
   InitFormFont(Self);
   if Font.Name = 'Segoe UI' then begin
     { See Wizard.pas }
@@ -396,13 +419,9 @@ begin
 end;
 
 procedure TWizardForm.FormDestroy(Sender: TObject);
-var
-  I: Integer;
 begin
+  FAppFilesPageHelper.Free;
   FLanguages.Free;
-  for I := 0 to FWizardFiles.Count-1 do
-    Dispose(FWizardFiles[i]);
-  FWizardFiles.Free;
 end;
 
 { --- }
@@ -772,24 +791,6 @@ begin
     AppFilesEditButton.Click;
 end;
 
-procedure TWizardForm.AppFilesAddButtonClick(Sender: TObject);
-var
-  FileList: TStringList;
-  I: Integer;
-begin
-  FileList := TStringList.Create;
-  try
-    if NewGetOpenFileNameMulti('', FileList, '', SWizardAllFilesFilter, '', Handle) then begin
-      FileList.Sort;
-      for I := 0 to FileList.Count-1 do
-        AddWizardFile(FileList[I], False, False);
-      UpdateWizardFiles;
-    end;
-  finally
-    FileList.Free;
-  end;
-end;
-
 procedure TWizardForm.AppFilesAddDirButtonClick(Sender: TObject);
 var
   Path: String;
@@ -1176,4 +1177,78 @@ end;
 
 { --- }
 
+{ TWizardFormAppFilesPageHelper }
+
+constructor TWizardFormAppFilesPageHelper.Create(const Handle: HWND;
+  const WizardFiles: TList; const NotCreateAppDirCheck: TCheckBox;
+  const AppFilesAddButton: TButton; const AppFilesListBox: TDropListBox);
+begin
+  inherited Create;
+
+  FWizardFiles := TList.Create;
+
+  FHandle := Handle;
+  FNotCreateAppDirCheck := NotCreateAppDirCheck;
+  FAppFilesListBox := AppFilesListBox;
+
+  AppFilesAddButton.OnClick := AddButtonClick;
+end;
+
+destructor TWizardFormAppFilesPageHelper.Destroy;
+begin
+  for var I := 0 to FWizardFiles.Count-1 do
+    Dispose(FWizardFiles[i]);
+  FWizardFiles.Free;
+end;
+
+procedure TWizardFormAppFilesPageHelper.AddWizardFile(const Source: String; const RecurseSubDirs, CreateAllSubDirs: Boolean);
+var
+  WizardFile: PWizardFile;
+begin
+  New(WizardFile);
+  WizardFile.Source := Source;
+  WizardFile.RecurseSubDirs := RecurseSubDirs;
+  WizardFile.CreateAllSubDirs := CreateAllSubDirs;
+  WizardFile.DestRootDirIsConstant := True;
+  if not FNotCreateAppDirCheck.Checked then
+    WizardFile.DestRootDir := '{app}'
+  else
+    WizardFile.DestRootDir := '{win}';
+  WizardFile.DestSubDir := '';
+  FWizardFiles.Add(WizardFile);
+end;
+
+procedure TWizardFormAppFilesPageHelper.UpdateWizardFiles;
+var
+  WizardFile: PWizardFile;
+  I: Integer;
+begin
+  FAppFilesListBox.Items.BeginUpdate;
+  FAppFilesListBox.Items.Clear;
+  for I := 0 to FWizardFiles.Count-1 do begin
+    WizardFile := FWizardFiles[i];
+    FAppFilesListBox.Items.Add(WizardFile.Source);
+  end;
+  FAppFilesListBox.Items.EndUpdate;
+  UpdateHorizontalExtent(FAppFilesListBox);
+end;
+
+procedure TWizardFormAppFilesPageHelper.AddButtonClick(Sender: TObject);
+var
+  FileList: TStringList;
+  I: Integer;
+begin
+  FileList := TStringList.Create;
+  try
+    if NewGetOpenFileNameMulti('', FileList, '', SWizardAllFilesFilter, '', FHandle) then begin
+      FileList.Sort;
+      for I := 0 to FileList.Count-1 do
+        AddWizardFile(FileList[I], False, False);
+      UpdateWizardFiles;
+    end;
+  finally
+    FileList.Free;
+  end
+end;
+
 end.