File: package_integration_options.pas

package info (click to toggle)
lazarus 2.0.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 214,460 kB
  • sloc: pascal: 1,862,622; xml: 265,709; cpp: 56,595; sh: 3,008; java: 609; makefile: 535; perl: 297; sql: 222; ansic: 137
file content (284 lines) | stat: -rw-r--r-- 9,240 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
unit package_integration_options;

{$mode objfpc}{$H+}

interface

uses
  Classes, SysUtils,
  // LCL
  Forms, Controls, ExtCtrls, StdCtrls, Dialogs,
  // LazUtils
  LazFileUtils,
  // IdeIntf
  IDEOptionsIntf, IDEOptEditorIntf, MacroIntf, PackageIntf,
  // IDE
  PackageDefs, LazarusIDEStrConsts, PathEditorDlg, IDEProcs, CodeHelp;

type

  { TPackageIntegrationOptionsFrame }

  TPackageIntegrationOptionsFrame = class(TAbstractIDEOptionsEditor)
    DesignTimeRadioButton: TRadioButton;
    FPDocPackageNameEdit: TEdit;
    FPDocPackageNameLabel: TLabel;
    FPDocSearchPathsLabel: TLabel;
    DocGroupBox: TGroupBox;
    FPDocSearchPathsEdit: TEdit;
    PkgTypeGroupBox: TGroupBox;
    RunAndDesignTimeRadioButton: TRadioButton;
    RunTimeOnlyRadioButton: TRadioButton;
    RunTimeRadioButton: TRadioButton;
    UpdateRadioGroup: TRadioGroup;
    procedure PkgTypeGroupBoxClick(Sender: TObject);
  private
    FLazPackage: TLazPackage;
    FPDocPathButton: TPathEditorButton;
    FStoredPkgType: TLazPackageType;
    function GetSelectedPkgType: TLazPackageType;
    function PathEditBtnExecuted(Context: String; var NewPath: String): Boolean;
    procedure SetSelectedPkgType(PkgType: TLazPackageType);
    function ShowMsgPackageTypeMustBeDesign: boolean;
    function GetFPDocPkgNameEditValue: string;
  public
    function Check: Boolean; override;
    function GetTitle: string; override;
    procedure Setup({%H-}ADialog: TAbstractOptionsEditorDialog); override;
    procedure ReadSettings(AOptions: TAbstractIDEOptions); override;
    procedure WriteSettings(AOptions: TAbstractIDEOptions); override;
    class function SupportedOptionsClass: TAbstractIDEOptionsClass; override;
    function PkgTypeToCaption(t: TLazPackageType): string;
    function CaptionToPkgType(s: string): TLazPackageType;
  end;

implementation

{$R *.lfm}

{ TPackageIntegrationOptionsFrame }

procedure TPackageIntegrationOptionsFrame.PkgTypeGroupBoxClick(Sender: TObject);
var
  NewPkgType: TLazPackageType;
begin
  NewPkgType:=GetSelectedPkgType;
  if (FStoredPkgType<>NewPkgType)
  and (NewPkgType in [lptRunTime,lptRunTimeOnly])
  then begin
    // user sets to runtime
    if (FLazPackage.AutoInstall <> pitNope) then
      ShowMsgPackageTypeMustBeDesign;
  end;
end;

function TPackageIntegrationOptionsFrame.GetSelectedPkgType: TLazPackageType;
begin
  if RunTimeOnlyRadioButton.Checked then
    Result:=lptRunTimeOnly
  else if DesignTimeRadioButton.Checked then
    Result:=lptDesignTime
  else if RunTimeRadioButton.Checked then
    Result:=lptRunTime
  else
    Result:=lptRunAndDesignTime;
end;

function TPackageIntegrationOptionsFrame.PathEditBtnExecuted(Context: String;
  var NewPath: String): Boolean;
var
  CurDir: string;
  StartPos, OldStartPos: integer;
  DlgResult: TModalResult;
  s: String;
begin
  // check NewPath
  StartPos := 1;
  repeat
    OldStartPos := StartPos;
    CurDir := GetNextDirectoryInSearchPath(NewPath, StartPos);
    if CurDir <> '' then
    begin
      IDEMacros.SubstituteMacros(CurDir);
      FLazPackage.LongenFilename(CurDir);
      if not DirPathExists(CurDir) then
      begin
        s:=Format(lisDirectoryNotFound, [CurDir]);
        if Context<>'' then
          s:=Context+LineEnding+s;
        DlgResult := QuestionDlg(lisEnvOptDlgDirectoryNotFound,
          s,
          mtError, [mrIgnore, mrYes, lisRemoveFromSearchPath, mrCancel], 0);
        case DlgResult of
          mrIgnore: ;
          mrYes:
          begin  // remove directory from search path
            NewPath := copy(NewPath,1,OldStartPos-1) + copy(NewPath,StartPos,length(NewPath));
            StartPos := OldStartPos;
          end;
          else   // undo
            Exit(False);
        end;
      end;
    end;
  until StartPos > length(NewPath);
  Result := True;
end;

procedure TPackageIntegrationOptionsFrame.SetSelectedPkgType(PkgType: TLazPackageType);
begin
  case PkgType of
  lptRunTime: RunTimeRadioButton.Checked:=true;
  lptDesignTime: DesignTimeRadioButton.Checked:=true;
  lptRunAndDesignTime: RunAndDesignTimeRadioButton.Checked:=true;
  lptRunTimeOnly: RunTimeOnlyRadioButton.Checked:=true;
  end;
end;

function TPackageIntegrationOptionsFrame.GetTitle: string;
begin
  Result := lisPckOptsIDEIntegration;
end;

procedure TPackageIntegrationOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
  PkgTypeGroupBox.Caption := lisPckOptsPackageType;
  RunAndDesignTimeRadioButton.Caption := PkgTypeToCaption(lptRunAndDesignTime);
  RunAndDesignTimeRadioButton.Hint := lisRunAndDesignTimePackagesHaveNoLimitations;
  DesignTimeRadioButton.Caption := PkgTypeToCaption(lptDesignTime);
  DesignTimeRadioButton.Hint := lisDesignTimePackagesAddComponentsAndMenuItemsToTheID;
  RunTimeRadioButton.Caption := PkgTypeToCaption(lptRunTime);
  RunTimeRadioButton.Hint := lisRunTimePackagesCanBeUsedByProjectsTheyCanNotBeInst;
  RunTimeOnlyRadioButton.Caption := PkgTypeToCaption(lptRunTimeOnly);
  RunTimeOnlyRadioButton.Hint := lisRunTimeOnlyPackagesAreOnlyForProjectsTheyCanNotBeI;

  UpdateRadioGroup.Caption := lisPckOptsUpdateRebuild;
  UpdateRadioGroup.Items[0] := lisPckOptsAutomaticallyRebuildAsNeeded;
  UpdateRadioGroup.Items[1] := lisPckOptsAutoRebuildWhenRebuildingAll;
  UpdateRadioGroup.Items[2] := lisPckOptsManualCompilationNeverAutomatically;

  DocGroupBox.Caption := lisCodeHelpGroupBox;

  FPDocPackageNameLabel.Caption := lisPckPackage;
  FPDocPackageNameEdit.Hint := lisPckClearToUseThePackageName;
  FPDocSearchPathsLabel.Caption := lisPathEditSearchPaths;
  // ToDo: remove the resource string later.
  //FPDocSearchPathsEdit.Hint := lisPckSearchPathsForFpdocXmlFilesMultiplePathsMustBeSepa;

  FPDocPathButton := TPathEditorButton.Create(Self);
  with FPDocPathButton do
  begin
    Name := 'FPDocPathButton';
    Caption := '...';
    AutoSize := False;
    Width := Height;
    Anchors := [akRight];
    AnchorParallel(akRight, 6, DocGroupBox);
    AnchorParallel(akTop, 0, FPDocSearchPathsEdit);
    AnchorParallel(akBottom, 0, FPDocSearchPathsEdit);
    AssociatedEdit := FPDocSearchPathsEdit;
    OnExecuted := @PathEditBtnExecuted;
    Parent := DocGroupBox;
  end;
  FPDocSearchPathsEdit.AnchorToNeighbour(akRight, 0, FPDocPathButton);
end;

procedure TPackageIntegrationOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
begin
  FLazPackage := (AOptions as TPackageIDEOptions).Package;
  FStoredPkgType := FLazPackage.PackageType;
  SetSelectedPkgType(FStoredPkgType);
  case FLazPackage.AutoUpdate of
    pupAsNeeded: UpdateRadioGroup.ItemIndex := 0;
    pupOnRebuildingAll: UpdateRadioGroup.ItemIndex := 1;
    else
      UpdateRadioGroup.ItemIndex := 2;
  end;
  SetPathTextAndHint(FLazPackage.FPDocPaths, FPDocSearchPathsEdit);

  FPDocPackageNameEdit.TextHint:=lisDefaultPlaceholder;
  FPDocPackageNameEdit.Text:=FLazPackage.FPDocPackageName;
end;

function TPackageIntegrationOptionsFrame.ShowMsgPackageTypeMustBeDesign: boolean;
begin
  if MessageDlg(lisPckOptsInvalidPackageType,
    Format(lisPckOptsThePackageHasTheAutoInstallFlagThisMeans,
           [FLazPackage.IDAsString, LineEnding, LineEnding]),
    mtWarning, [mbIgnore, mbCancel], 0) <> mrIgnore then
  begin
    Result := True;
    SetSelectedPkgType(FStoredPkgType);
  end
  else
    Result := False;
end;

function TPackageIntegrationOptionsFrame.GetFPDocPkgNameEditValue: string;
begin
  Result:=MakeValidFPDocPackageName(FPDocPackageNameEdit.Text);
end;

function TPackageIntegrationOptionsFrame.Check: Boolean;
var
  NewPkgType: TLazPackageType;
begin
  NewPkgType:=GetSelectedPkgType;
  if NewPkgType <> FLazPackage.PackageType then
  begin
    if (NewPkgType in [lptRunTime,lptRunTimeOnly])
    and (FLazPackage.AutoInstall <> pitNope) then
    begin
      if ShowMsgPackageTypeMustBeDesign then
        Exit(False);
    end;
  end;
  Result := True;
end;

procedure TPackageIntegrationOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
  LazPackage: TLazPackage;
begin
  LazPackage := (AOptions as TPackageIDEOptions).Package;
  LazPackage.PackageType := GetSelectedPkgType;
  case UpdateRadioGroup.ItemIndex of
    2: LazPackage.AutoUpdate := pupManually;
    1: LazPackage.AutoUpdate := pupOnRebuildingAll;
    else
      LazPackage.AutoUpdate := pupAsNeeded;
  end;
  LazPackage.FPDocPaths := FPDocSearchPathsEdit.Text;
  LazPackage.FPDocPackageName := GetFPDocPkgNameEditValue;
end;

class function TPackageIntegrationOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
  Result := TPackageIDEOptions;
end;

function TPackageIntegrationOptionsFrame.PkgTypeToCaption(t: TLazPackageType): string;
begin
  case t of
  lptRunTime: Result:=lisPckOptsRuntime;
  lptDesignTime: Result:=lisPckOptsDesigntime;
  lptRunAndDesignTime: Result:=lisPckOptsDesigntimeAndRuntime;
  lptRunTimeOnly: Result:=lisRuntimeOnlyCanNotBeInstalledInIDE;
  else Result:='?'+IntToStr(ord(t));
  end;
end;

function TPackageIntegrationOptionsFrame.CaptionToPkgType(s: string): TLazPackageType;
var
  t: TLazPackageType;
begin
  for t:=Low(TLazPackageType) to high(TLazPackageType) do
    if s=PkgTypeToCaption(t) then exit(t);
  Result:=lptRunTime;
end;

initialization
  RegisterIDEOptionsEditor(GroupPackage, TPackageIntegrationOptionsFrame,
    PackageOptionsIntegration);
end.