【问题标题】:How to build a Treeview design (a task group with tasks nesting hierarchy) using Inno Setup?如何使用 Inno Setup 构建 Treeview 设计(具有任务嵌套层次结构的任务组)?
【发布时间】:2016-11-22 13:38:56
【问题描述】:

我正在尝试构建一个包含可检查元素和标签的 Treeview 层次结构,它们必须或多或少像这样:

Standalone Controls (label, root)
|__Check/Uncheck all controls of all groups (checkbox)
|  |
|  |__Controls group 1 (group description label)
|  |  |__Check/Uncheck all these controls (checkbox)
|  |     |__Control name 1 (task)
|  |     |__Control name 2 (task)
|  |     |__Control name 3 (task)
|  |       
|  |__Controls group 2 (group description label)
|  |  |__Check/Uncheck all these controls (checkbox)
|  |     |__Control name 1 (task)
|  |     |__Control name 2 (task)
|  |     |__Control name 3 (task)

...等等。

或者如果上面显示的层次结构,下面的这个变体可能太难编码了:

Standalone Controls (label, root)
|
|__Controls group 1 (group description label)
|  |__Check/Uncheck all these controls (checkbox)
|     |__Control name 1 (task)
|     |__Control name 2 (task)
|     |__Control name 3 (task)
|       
|__Controls group 2 (group description label)
|  |__Check/Uncheck all these controls (checkbox)
|     |__Control name 1 (task)
|     |__Control name 2 (task)
|     |__Control name 3 (task)

但是,到目前为止我得到的是:

这是我的代码示例:

[CustomMessages]
StandaloneDescr=%nStandalone Controls
ButtonsDescr=%nButtons
CheckboxesDescr=%nCheckboxes
GroupboxesDescr=%nGroupboxes
KnobsDescr=%nKnobs
...

[Tasks]
Name: WinFormsControls; Description: Check/Uncheck all; GroupDescription: {cm:StandaloneDescr}

Name: WinFormsControls; Description: Check/Uncheck all; GroupDescription: {cm:ButtonsDescr}
Name: WinFormsControls\CButton; Description: CButton
Name: WinFormsControls\GlassButton; Description: Glass Button
Name: WinFormsControls\MyCommandButtonNET; Description: My Command Button.NET
Name: WinFormsControls\PulseButton; Description: Pulse Button

Name: WinFormsControls; Description: Check/Uncheck all; GroupDescription: {cm:CheckboxesDescr}
Name: WinFormsControls\DontShowAgainCheckbox; Description: Don't Show Again Checkbox

Name: WinFormsControls; Description: Check/Uncheck all; GroupDescription: {cm:GroupboxesDescr}
Name: WinFormsControls\Grouper; Description: Grouper

Name: WinFormsControls; Description: Check/Uncheck all; GroupDescription: {cm:KnobsDescr}
Name: WinFormsControls\Knob; Description: Knob
Name: WinFormsControls\KnobControl; Description: KnobControl

...

我怎样才能做到这一点?

【问题讨论】:

    标签: treeview installation inno-setup freepascal pascalscript


    【解决方案1】:

    如果我正确理解您的问题,问题是主“独立控件”复选框不起作用,对吧?因为它不是层次结构的一部分。


    最简单的解决方案是放弃GroupDescription's 并将它们移动到复选框描述:

    [Setup]
    ShowTasksTreeLines=yes
    
    [Tasks]
    Name: WinFormsControls; Description: "Standalone controls"
    
    Name: WinFormsControls\Buttons; Description: "Buttons"
    Name: WinFormsControls\Buttons\CButton; Description: CButton
    Name: WinFormsControls\Buttons\GlassButton; Description: Glass Button
    Name: WinFormsControls\Buttons\MyCommandButtonNET; Description: My Command Button.NET
    Name: WinFormsControls\Buttons\PulseButton; Description: Pulse Button
    
    Name: WinFormsControls\Checkboxes; Description: "Checkboxes"
    Name: WinFormsControls\Checkboxes\DontShowAgainCheckbox; Description: Don't Show Again Checkbox
    
    Name: WinFormsControls\Groupboxes; Description: "Groupboxes"
    Name: WinFormsControls\Groupboxes\Grouper; Description: Grouper
    
    Name: WinFormsControls\Knobs; Description: "Knobs"
    Name: WinFormsControls\Knobs\Knob; Description: Knob
    Name: WinFormsControls\Knobs\KnobControl; Description: KnobControl
    


    如果您想保留GroupDescription's,您可以通过编程方式将主“选中/取消选中所有”绑定到其他复选框:

    procedure TasksListClickCheck(Sender: TObject);
    var
      Index: Integer;
    begin
      if WizardForm.TasksList.ItemIndex = 1 then
      begin
        for Index := 2 to WizardForm.TasksList.Items.Count - 1 do
          WizardForm.TasksList.Checked[Index] := WizardForm.TasksList.Checked[1];
      end;
    end;
    
    procedure InitializeWizard();
    begin
      WizardForm.TasksList.OnClickCheck := @TasksListClickCheck;
    end;
    

    如果你真的需要层次结构(缩进),你需要构建一个自定义页面。 Inno Setup 不支持 Tasks 部分中的嵌套组描述。它忽略子任务的GroupDescription 参数。

    var
      TasksList: TNewCheckListBox;
    
    procedure InitializeWizard();
    var
      CustomSelectTasksPage: TWizardPage;
    begin
      CustomSelectTasksPage :=
        CreateCustomPage(wpSelectTasks, SetupMessage(msgWizardSelectTasks), SetupMessage(msgSelectTasksDesc));
    
      TasksList := TNewCheckListBox.Create(WizardForm);
      TasksList.Left := WizardForm.TasksList.Left; 
      TasksList.Top := WizardForm.SelectTasksLabel.Top; 
      TasksList.Width := WizardForm.TasksList.Width; 
      TasksList.Height := WizardForm.TasksList.Top + WizardForm.TasksList.Height - WizardForm.SelectTasksLabel.Top; 
    
      TasksList.BorderStyle := WizardForm.TasksList.BorderStyle;
      TasksList.Color := WizardForm.TasksList.Color;
      TasksList.ShowLines := WizardForm.TasksList.ShowLines;
      TasksList.MinItemHeight := WizardForm.TasksList.MinItemHeight;
      TasksList.ParentColor := WizardForm.TasksList.ParentColor;
      TasksList.WantTabs := WizardForm.TasksList.WantTabs;
    
      TasksList.Parent := CustomSelectTasksPage.Surface;
    
      TasksList.AddGroup('Standalone controls', '', 0, nil);
      TasksList.AddCheckBox('Check/Uncheck all', '', 0, True, True, False, True, nil);
        TasksList.AddGroup('Buttons', '', 1, nil);
        TasksList.AddCheckBox('Check/Uncheck all', '', 1, True, True, False, True, nil);
          TasksList.AddCheckBox('CButton', '', 2, True, True, False, True, nil);
          TasksList.AddCheckBox('Glass Button', '', 2, True, True, False, True, nil);
          TasksList.AddCheckBox('My Command Button.NET', '', 2, True, True, False, True, nil);
          TasksList.AddCheckBox('Pulse Button', '', 2, True, True, False, True, nil);
        TasksList.AddGroup('Checkboxes', '', 1, nil);
        TasksList.AddCheckBox('Check/Uncheck all', '', 1, True, True, False, True, nil);
          TasksList.AddCheckBox('Don''t Show Again Checkbox', '', 2, True, True, False, True, nil);
        TasksList.AddGroup('Knobs', '', 1, nil);
        TasksList.AddCheckBox('Check/Uncheck all', '', 1, True, True, False, True, nil);
          TasksList.AddCheckBox('KnobControl', '', 2, True, True, False, True, nil);
    end;
    

    您需要使用Check parameters 将任务绑定到[Files][Run][Registry] 等部分中的操作:

    [Files]
    Source: "CButton.dll"; DestDir: "{app}"; Check: GetCustomTask(2)
    
    [Code]
    
    var
      TasksList: TNewCheckListBox;
    
    { ... }
    
    function GetCustomTask(TaskIndex: Integer): Boolean;
    begin 
      Result := TasksList.Checked[TaskIndex];
    end;
    

    对于类似的问题,请参阅How to split tasklist at tasks page of Inno Setup into multiple columns?


    在 Inno Setup 6 中,除了使用索引之外,您还可以使用带有 WizardIsTaskSelectedWizardSelectTasks 的任务名称。

    【讨论】:

    • 太棒了,感谢您花时间写这个说明性的答案,我选择了第一个设计选项而不是“选中/取消选中所有”。
    猜你喜欢
    • 2012-08-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-07-15
    • 2013-05-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多