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 285 286 287 288 289 290 291 292 293 294 295
|
unit project_forms_options;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils,
// LCL
Forms, Controls, Graphics, Dialogs, StdCtrls, Buttons,
// IdeIntf
IDEOptionsIntf, IDEOptEditorIntf, ProjectIntf, IDEImagesIntf,
// IDE
PackageDefs, Project, LazarusIDEStrConsts;
type
{ TProjectFormsOptionsFrame }
TProjectFormsOptionsFrame = class(TAbstractIDEOptionsEditor)
FormsAddToAutoCreatedFormsBtn: TSpeedButton;
FormsAutoCreatedLabel: TLabel;
FormsAutoCreatedListBox: TListBox;
FormsAutoCreateNewFormsCheckBox: TCheckBox;
FormsAvailFormsLabel: TLabel;
FormsAvailFormsListBox: TListBox;
FormsMoveAutoCreatedFormsDownBtn: TSpeedButton;
FormsMoveAutoCreatedFormUpBtn: TSpeedButton;
FormsRemoveFromAutoCreatedFormsBtn: TSpeedButton;
lblMiddle: TLabel;
procedure FormsAddToAutoCreatedFormsBtnClick(Sender: TObject);
procedure FormsMoveAutoCreatedFormsDownBtnClick(Sender: TObject);
procedure FormsMoveAutoCreatedFormUpBtnClick(Sender: TObject);
procedure FormsRemoveFromAutoCreatedFormsBtnClick(Sender: TObject);
private
function FirstAutoCreateFormSelected: Integer;
function FirstAvailFormSelected: Integer;
procedure SelectOnlyThisAutoCreateForm(Index: integer);
public
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;
end;
implementation
{$R *.lfm}
{ TProjectFormsOptionsFrame }
procedure TProjectFormsOptionsFrame.SelectOnlyThisAutoCreateForm(Index: integer);
var
i: integer;
begin
with FormsAutoCreatedListBox do
for i := 0 to Items.Count - 1 do
Selected[i] := (i = Index);
end;
procedure TProjectFormsOptionsFrame.FormsMoveAutoCreatedFormUpBtnClick(
Sender: TObject);
var
i: integer;
h: string;
begin
i := FirstAutoCreateFormSelected;
if i < 1 then
Exit;
with FormsAutoCreatedListBox do
begin
Items.BeginUpdate;
h := Items[i];
Items[i] := Items[i - 1];
Items[i - 1] := h;
Items.EndUpdate;
end;
SelectOnlyThisAutoCreateForm(i - 1);
end;
procedure TProjectFormsOptionsFrame.FormsRemoveFromAutoCreatedFormsBtnClick(
Sender: TObject);
var
i, NewPos, cmp: integer;
OldFormName: string;
begin
FormsAutoCreatedListBox.Items.BeginUpdate;
FormsAvailFormsListBox.Items.BeginUpdate;
i := 0;
while i < FormsAutoCreatedListBox.Items.Count do
if FormsAutoCreatedListBox.Selected[i] then
begin
OldFormName := FormsAutoCreatedListBox.Items[i];
FormsAutoCreatedListBox.Items.Delete(i);
NewPos := 0;
cmp := 1;
while (NewPos < FormsAvailFormsListBox.Items.Count) do
begin
cmp := CompareText(FormsAvailFormsListBox.Items[NewPos], OldFormName);
if cmp < 0 then
Inc(NewPos)
else
break;
end;
if cmp = 0 then
continue;
FormsAvailFormsListBox.Items.Insert(NewPos, OldFormName);
end
else
Inc(i);
FormsAvailFormsListBox.Items.EndUpdate;
FormsAutoCreatedListBox.Items.EndUpdate;
end;
function TProjectFormsOptionsFrame.FirstAutoCreateFormSelected: Integer;
begin
Result := 0;
while (Result < FormsAutoCreatedListBox.Items.Count) and
(not FormsAutoCreatedListBox.Selected[Result]) do
inc(Result);
if Result = FormsAutoCreatedListBox.Items.Count then
Result := -1;
end;
function TProjectFormsOptionsFrame.FirstAvailFormSelected: Integer;
begin
Result := 0;
while (Result < FormsAvailFormsListBox.Items.Count) and
(not FormsAvailFormsListBox.Selected[Result]) do
inc(Result);
if Result = FormsAvailFormsListBox.Items.Count then
Result := -1;
end;
procedure TProjectFormsOptionsFrame.FormsMoveAutoCreatedFormsDownBtnClick(
Sender: TObject);
var
i: integer;
h: string;
begin
i := FirstAutoCreateFormSelected;
if (i < 0) or (i >= FormsAutoCreatedListBox.Items.Count - 1) then
exit;
with FormsAutoCreatedListBox do
begin
Items.BeginUpdate;
h := Items[i];
Items[i] := Items[i + 1];
Items[i + 1] := h;
Items.EndUpdate;
end;
SelectOnlyThisAutoCreateForm(i + 1);
end;
procedure TProjectFormsOptionsFrame.FormsAddToAutoCreatedFormsBtnClick(
Sender: TObject);
var
i: integer;
NewFormName: string;
begin
FormsAutoCreatedListBox.Items.BeginUpdate;
with FormsAvailFormsListBox do
begin
Items.BeginUpdate;
i := 0;
while i < Items.Count do
if Selected[i] then
begin
NewFormName := Items[i];
Items.Delete(i);
FormsAutoCreatedListBox.Items.Add(NewFormName);
end
else
Inc(i);
Items.EndUpdate;
end;
FormsAutoCreatedListBox.Items.EndUpdate;
end;
function TProjectFormsOptionsFrame.GetTitle: string;
begin
Result := dlgPOFroms;
end;
procedure TProjectFormsOptionsFrame.Setup(ADialog: TAbstractOptionsEditorDialog);
begin
FormsAutoCreatedLabel.Caption := dlgAutoCreateForms;
FormsAutoCreatedListBox.Hint := dlgAutoCreateFormsHint;
FormsAvailFormsLabel.Caption := dlgAvailableForms;
FormsAvailFormsListBox.Hint := dlgAvailableFormsHint;
FormsAutoCreateNewFormsCheckBox.Caption := dlgAutoCreateNewForms;
IDEImages.AssignImage(FormsMoveAutoCreatedFormUpBtn, 'arrow_up');
IDEImages.AssignImage(FormsMoveAutoCreatedFormsDownBtn, 'arrow_down');
IDEImages.AssignImage(FormsAddToAutoCreatedFormsBtn, 'arrow_left');
IDEImages.AssignImage(FormsRemoveFromAutoCreatedFormsBtn, 'arrow_right');
end;
procedure TProjectFormsOptionsFrame.ReadSettings(AOptions: TAbstractIDEOptions);
var
Project: TProject;
procedure FillAutoCreateFormsListbox;
var
sl: TStrings;
begin
sl := Project.GetAutoCreatedFormsList;
FormsAutoCreatedListBox.Items.BeginUpdate;
FormsAutoCreatedListBox.Items.Clear;
if sl <> nil then
begin
FormsAutoCreatedListBox.Items.Assign(sl);
sl.Free;
end;
FormsAutoCreatedListBox.Items.EndUpdate;
end;
function IndexOfAutoCreateForm(FormName: string): integer;
var
p: integer;
begin
p := Pos(':', FormName);
if p > 0 then
FormName := Copy(FormName, 1, p - 1);
Result := FormsAutoCreatedListBox.Items.Count - 1;
while (Result >= 0) do
begin
p := Pos(':', FormsAutoCreatedListBox.Items[Result]);
if p < 1 then
p := Length(FormsAutoCreatedListBox.Items[Result]) + 1;
if CompareText(copy(FormsAutoCreatedListBox.Items[Result], 1, p - 1),
FormName) = 0 then
Exit;
Dec(Result);
end;
end;
procedure FillAvailFormsListBox;
var
sl: TStringList;
i: integer;
begin
FormsAvailFormsListBox.Items.BeginUpdate;
FormsAvailFormsListBox.Items.Clear;
if (Project <> nil) then
begin
sl := TStringList.Create;
try
for i := 0 to Project.UnitCount - 1 do
if (Project.Units[i].IsPartOfProject) and
(Project.Units[i].ComponentName <> '') and
(Project.Units[i].ResourceBaseClass in [pfcbcForm, pfcbcDataModule]) and
(IndexOfAutoCreateForm(Project.Units[i].ComponentName) < 0) then
sl.Add(Project.Units[i].ComponentName);
sl.Sort;
FormsAvailFormsListBox.Items.Assign(sl);
finally
sl.Free;
end;
end;
FormsAvailFormsListBox.Items.EndUpdate;
end;
begin
Project := (AOptions as TProjectIDEOptions).Project;
FillAutoCreateFormsListbox;
FillAvailFormsListBox;
FormsAutoCreateNewFormsCheckBox.Checked := Project.AutoCreateForms;
FormsMoveAutoCreatedFormUpBtn.ShowHint := true;
FormsMoveAutoCreatedFormsDownBtn.ShowHint := true;
FormsMoveAutoCreatedFormUpBtn.Hint := lisMMMoveSelectedItemUp;
FormsMoveAutoCreatedFormsDownBtn.Hint := lisMMMoveSelectedItemDown;
end;
procedure TProjectFormsOptionsFrame.WriteSettings(AOptions: TAbstractIDEOptions);
var
Project: TProject;
begin
Project := (AOptions as TProjectIDEOptions).Project;
Project.AutoCreateForms := FormsAutoCreateNewFormsCheckBox.Checked;
Project.TmpAutoCreatedForms := FormsAutoCreatedListBox.Items;
end;
class function TProjectFormsOptionsFrame.SupportedOptionsClass: TAbstractIDEOptionsClass;
begin
Result := TProjectIDEOptions;
end;
initialization
RegisterIDEOptionsEditor(GroupProject, TProjectFormsOptionsFrame, ProjectOptionsForms);
end.
|