PageRenderTime 11ms CodeModel.GetById 2ms app.highlight 5ms RepoModel.GetById 1ms app.codeStats 1ms

/ide/publishprojectdlg.pas

http://github.com/graemeg/lazarus
Pascal | 377 lines | 279 code | 50 blank | 48 comment | 19 complexity | e6d98483e5fc6283f8fb38e56151ee72 MD5 | raw file
  1{ /***************************************************************************
  2                 publishprojectdlg.pp  -  Lazarus IDE unit
  3                 -----------------------------------------
  4
  5 ***************************************************************************/
  6
  7 ***************************************************************************
  8 *                                                                         *
  9 *   This source is free software; you can redistribute it and/or modify   *
 10 *   it under the terms of the GNU General Public License as published by  *
 11 *   the Free Software Foundation; either version 2 of the License, or     *
 12 *   (at your option) any later version.                                   *
 13 *                                                                         *
 14 *   This code is distributed in the hope that it will be useful, but      *
 15 *   WITHOUT ANY WARRANTY; without even the implied warranty of            *
 16 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU     *
 17 *   General Public License for more details.                              *
 18 *                                                                         *
 19 *   A copy of the GNU General Public License is available on the World    *
 20 *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
 21 *   obtain it by writing to the Free Software Foundation,                 *
 22 *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
 23 *                                                                         *
 24 ***************************************************************************
 25
 26  Author: Mattias Gaertner
 27
 28  Abstract:
 29    - TPublishProjectDialog
 30    The dialog for TPublishModuleOptions to publish projects and packages.
 31
 32}
 33unit PublishProjectDlg;
 34
 35{$mode objfpc}{$H+}
 36
 37interface
 38
 39uses
 40  Classes, SysUtils, LazFileUtils, Forms, Controls, Graphics, Buttons,
 41  StdCtrls, Dialogs, LCLType,
 42  IDEWindowIntf, IDEHelpIntf, IDEDialogs,
 43  ProjectDefs, PackageDefs, PublishModule, IDEOptionDefs, InputHistory,
 44  LazarusIDEStrConsts, IDEProcs, ExtCtrls, ButtonPanel;
 45
 46type
 47  { TPublishProjectDialog }
 48
 49  TPublishProjectDialog = class(TForm)
 50    ButtonPanel1: TButtonPanel;
 51    DestDirGroupBox: TGroupBox;
 52    DestDirComboBox: TComboBox;
 53    BrowseDestDirBitBtn: TBitBtn;
 54    CommandAfterLabel: TLabel;
 55    CommandAfterCombobox: TComboBox;
 56
 57    FilesGroupbox: TGroupBox;
 58    IgnoreBinariesCheckbox: TCheckBox;
 59
 60    IncludeFilterCombobox: TComboBox;
 61    IncFilterSimpleSyntaxCheckbox: TCheckBox;
 62    UseIncludeFilterCheckbox: TCheckBox;
 63    IncludeFilterGroupbox: TGroupBox;
 64
 65    ExcludeFilterCombobox: TComboBox;
 66    ExcFilterSimpleSyntaxCheckbox: TCheckBox;
 67    UseExcludeFilterCheckbox: TCheckBox;
 68    ExcludeFilterGroupbox: TGroupBox;
 69
 70    ProjectInfoGroupbox: TGroupBox;
 71    SaveEditorInfoOfNonProjectFilesCheckbox: TCheckBox;
 72    SaveClosedEditorFilesInfoCheckbox: TCheckBox;
 73
 74    procedure BrowseDestDirBitBtnCLICK(Sender: TObject);
 75    procedure DestDirGroupBoxRESIZE(Sender: TObject);
 76    procedure FormClose(Sender: TObject; var {%H-}CloseAction: TCloseAction);
 77    procedure FormCreate(Sender: TObject);
 78    procedure HelpButtonClick(Sender: TObject);
 79    procedure OkButtonCLICK(Sender: TObject);
 80    procedure SaveSettingsButtonClick(Sender: TObject);
 81  private
 82    FOptions: TPublishModuleOptions;
 83    procedure SetComboBox(AComboBox: TComboBox; const NewText: string;
 84                          MaxItemCount: integer);
 85    procedure LoadHistoryLists;
 86    procedure SaveHistoryLists;
 87    procedure SetOptions(const AValue: TPublishModuleOptions);
 88    function CheckFilter: boolean;
 89  public
 90    constructor Create(TheOwner: TComponent); override;
 91    destructor Destroy; override;
 92    procedure LoadFromOptions(SrcOpts: TPublishModuleOptions);
 93    procedure SaveToOptions(DestOpts: TPublishModuleOptions);
 94    property Options: TPublishModuleOptions read FOptions write SetOptions;
 95  end;
 96
 97function ShowPublishProjectDialog(
 98  PublishOptions: TPublishModuleOptions): TModalResult;
 99
100
101implementation
102
103{$R *.lfm}
104
105function ShowPublishProjectDialog(
106  PublishOptions: TPublishModuleOptions): TModalResult;
107var
108  PublishProjectDialog: TPublishProjectDialog;
109begin
110  PublishProjectDialog:=TPublishProjectDialog.Create(nil);
111  with PublishProjectDialog do begin
112    Options:=PublishOptions;
113    Result:=ShowModal;
114    Free;
115  end;
116end;
117
118{ TPublishProjectDialog }
119
120procedure TPublishProjectDialog.DestDirGroupBoxRESIZE(Sender: TObject);
121begin
122  with DestDirComboBox do
123    SetBounds(Left,Top,
124              Parent.ClientWidth-2*Left-BrowseDestDirBitBtn.Width-5,Height);
125  with BrowseDestDirBitBtn do
126    Left:=DestDirComboBox.Left+DestDirComboBox.Width+5;
127  with CommandAfterCombobox do
128    SetBounds(Left,Top,Parent.ClientWidth-2*Left,Height);
129end;
130
131procedure TPublishProjectDialog.FormClose(Sender: TObject; var CloseAction: TCloseAction);
132begin
133  IDEDialogLayoutList.SaveLayout(Self);
134end;
135
136procedure TPublishProjectDialog.BrowseDestDirBitBtnCLICK(Sender: TObject);
137var
138  SelectDirDialog: TSelectDirectoryDialog;
139  NewDir: String;
140begin
141  SelectDirDialog:=TSelectDirectoryDialog.Create(Self);
142  InputHistories.ApplyFileDialogSettings(SelectDirDialog);
143  SelectDirDialog.Title:=lisChooseDirectory;
144  if SelectDirDialog.Execute then begin
145    NewDir:=ExpandFileNameUTF8(SelectDirDialog.Filename);
146    SeTComboBox(DestDirComboBox,NewDir,20);
147  end;
148  SelectDirDialog.Free;
149end;
150
151procedure TPublishProjectDialog.FormCreate(Sender: TObject);
152begin
153  DestDirGroupBox.Caption:=lisDestinationDirectory;
154  CommandAfterLabel.Caption:=lisCommandAfter;
155
156  FilesGroupbox.Caption:=dlgEnvFiles;
157  IgnoreBinariesCheckbox.Caption:=lisIgnoreBinaries;
158
159  IncFilterSimpleSyntaxCheckbox.Caption:=lisSimpleSyntax;
160  IncFilterSimpleSyntaxCheckbox.Hint:=
161    lisNormallyTheFilterIsARegularExpressionInSimpleSynta;
162  UseIncludeFilterCheckbox.Caption:=lisUseIncludeFilter;
163  IncludeFilterGroupbox.Caption:=lisIncludeFilter;
164
165  ExcFilterSimpleSyntaxCheckbox.Caption:=lisSimpleSyntax;
166  ExcFilterSimpleSyntaxCheckbox.Hint:=
167    lisNormallyTheFilterIsARegularExpressionInSimpleSynta;
168  UseExcludeFilterCheckbox.Caption:=lisUseExcludeFilter;
169  ExcludeFilterGroupbox.Caption:=lisExcludeFilter;
170
171  ProjectInfoGroupbox.Caption:=lisProjectInformation;
172  SaveEditorInfoOfNonProjectFilesCheckbox.Caption:=
173                                        lisSaveEditorInfoOfNonProjectFiles;
174  SaveClosedEditorFilesInfoCheckbox.Caption:=lisSaveInfoOfClosedEditorFiles;
175
176  ButtonPanel1.OkButton.Caption := lisMenuOk;
177  ButtonPanel1.OKButton.OnClick := @OkButtonCLICK;
178
179  ButtonPanel1.CloseButton.Caption := lisSaveSettings;
180  ButtonPanel1.CloseButton.ModalResult := mrNone;
181  ButtonPanel1.CloseButton.Kind := bkCustom;
182  ButtonPanel1.CloseButton.LoadGlyphFromStock(idButtonSave);
183  if ButtonPanel1.CloseButton.Glyph.Empty then
184    ButtonPanel1.CloseButton.LoadGlyphFromResourceName(HInstance, 'laz_save');
185  ButtonPanel1.CloseButton.OnClick := @SaveSettingsButtonCLICK;
186
187  ButtonPanel1.HelpButton.OnClick := @HelpButtonClick;
188end;
189
190procedure TPublishProjectDialog.HelpButtonClick(Sender: TObject);
191begin
192  LazarusHelp.ShowHelpForIDEControl(Self);
193end;
194
195procedure TPublishProjectDialog.OkButtonCLICK(Sender: TObject);
196begin
197  if not CheckFilter then exit;
198  if Options<>nil then SaveToOptions(Options);
199end;
200
201procedure TPublishProjectDialog.SaveSettingsButtonClick(Sender: TObject);
202begin
203  if not CheckFilter then exit;
204  if Options<>nil then SaveToOptions(Options);
205end;
206
207procedure TPublishProjectDialog.SetComboBox(AComboBox: TComboBox;
208  const NewText: string; MaxItemCount: integer);
209begin
210  AComboBox.AddHistoryItem(NewText,MaxItemCount,true,false);
211end;
212
213procedure TPublishProjectDialog.LoadHistoryLists;
214var
215  List: THistoryList;
216begin
217  // destination directories
218  List:=InputHistories.HistoryLists.GetList(hlPublishProjectDestDirs,true,rltFile);
219  List.AppendEntry(SetDirSeparators('$(TestDir)/publishedproject/'));
220  List.AppendEntry(SetDirSeparators('$(TestDir)/publishedpackage/'));
221  List.AppendEntry(SetDirSeparators('$(ProjPath)/published/'));
222  DestDirComboBox.Items.Assign(List);
223  
224  // command after
225  List:=InputHistories.HistoryLists.GetList(hlPublishProjectCommandsAfter,true,rltCaseSensitive);
226  List.AppendEntry(SetDirSeparators(
227                 'tar czf $MakeFile($(ProjPublishDir)).tgz $(ProjPublishDir)'));
228  List.AppendEntry(SetDirSeparators(
229              'tar czf $(TestDir)/project.tgz -C $(TestDir) publishedproject'));
230  List.AppendEntry(SetDirSeparators(
231              'tar czf $(TestDir)/package.tgz -C $(TestDir) publishedpackage'));
232  CommandAfterCombobox.Items.Assign(List);
233
234  // file filter
235  List:=InputHistories.HistoryLists.GetList(hlPublishProjectIncludeFileFilter,
236                                            true,rltFile);
237  if List.Count=0 then begin
238    List.Add(DefPublModIncFilter);
239  end;
240  IncludeFilterCombobox.Items.Assign(List);
241
242  List:=InputHistories.HistoryLists.GetList(hlPublishProjectExcludeFileFilter,
243                                            true,rltFile);
244  if List.Count=0 then begin
245    List.Add(DefPublModExcFilter);
246  end;
247  ExcludeFilterCombobox.Items.Assign(List);
248end;
249
250procedure TPublishProjectDialog.SaveHistoryLists;
251begin
252  // destination directories
253  SetComboBox(DestDirComboBox,DestDirComboBox.Text,20);
254  InputHistories.HistoryLists.GetList(hlPublishProjectDestDirs,true,rltFile).Assign(
255    DestDirComboBox.Items);
256    
257  // command after
258  SetComboBox(CommandAfterCombobox,CommandAfterCombobox.Text,20);
259  InputHistories.HistoryLists.GetList(hlPublishProjectCommandsAfter,true,
260    rltCaseSensitive).Assign(CommandAfterCombobox.Items);
261
262  // file filter
263  SetComboBox(IncludeFilterCombobox,IncludeFilterCombobox.Text,20);
264  InputHistories.HistoryLists.GetList(hlPublishProjectIncludeFileFilter,true,
265    rltFile).Assign(IncludeFilterCombobox.Items);
266  SetComboBox(ExcludeFilterCombobox,ExcludeFilterCombobox.Text,20);
267  InputHistories.HistoryLists.GetList(hlPublishProjectExcludeFileFilter,true,
268    rltFile).Assign(ExcludeFilterCombobox.Items);
269end;
270
271procedure TPublishProjectDialog.SetOptions(const AValue: TPublishModuleOptions);
272begin
273  if FOptions=AValue then exit;
274  FOptions:=AValue;
275  if FOptions is TPublishPackageOptions then
276    Caption:=lisPkgEditPublishPackage
277  else
278    Caption:=lisPublishProject;
279  LoadFromOptions(FOptions);
280end;
281
282function TPublishProjectDialog.CheckFilter: boolean;
283begin
284  Result:=false;
285  if Options<>nil then begin
286    if not Options.IncludeFilterValid then begin
287      if IDEMessageDialog(lisCCOErrorCaption, lisPublProjInvalidIncludeFilter,
288        mtError, [mbIgnore,
289        mbCancel])
290        =mrCancel
291      then exit;
292    end;
293    if not Options.ExcludeFilterValid then begin
294      if IDEMessageDialog(lisCCOErrorCaption, lisPublProjInvalidExcludeFilter,
295        mtError, [mbIgnore,
296        mbCancel])
297        =mrCancel
298      then exit;
299    end;
300  end;
301  Result:=true;
302end;
303
304constructor TPublishProjectDialog.Create(TheOwner: TComponent);
305begin
306  inherited Create(TheOwner);
307  Position:=poScreenCenter;
308  IDEDialogLayoutList.ApplyLayout(Self,500,500);
309  if Height<500 then Height:=500;
310  LoadHistoryLists;
311end;
312
313destructor TPublishProjectDialog.Destroy;
314begin
315  SaveHistoryLists;
316  inherited Destroy;
317end;
318
319procedure TPublishProjectDialog.LoadFromOptions(SrcOpts: TPublishModuleOptions);
320var
321  ProjSrcOpts: TPublishProjectOptions;
322begin
323  // destination
324  SeTComboBox(DestDirComboBox,SrcOpts.DestinationDirectory,20);
325  SeTComboBox(CommandAfterCombobox,SrcOpts.CommandAfter,20);
326
327  // file filter
328  IgnoreBinariesCheckbox.Checked:=SrcOpts.IgnoreBinaries;
329  UseIncludeFilterCheckbox.Checked:=SrcOpts.UseIncludeFileFilter;
330  IncFilterSimpleSyntaxCheckbox.Checked:=SrcOpts.IncludeFilterSimpleSyntax;
331  SeTComboBox(IncludeFilterCombobox,SrcOpts.IncludeFileFilter,20);
332  UseExcludeFilterCheckbox.Checked:=SrcOpts.UseExcludeFileFilter;
333  ExcFilterSimpleSyntaxCheckbox.Checked:=SrcOpts.ExcludeFilterSimpleSyntax;
334  SeTComboBox(ExcludeFilterCombobox,SrcOpts.ExcludeFileFilter,20);
335
336  // project info
337  if SrcOpts is TPublishProjectOptions then begin
338    ProjSrcOpts:=TPublishProjectOptions(SrcOpts);
339    SaveEditorInfoOfNonProjectFilesCheckbox.Checked:=
340      ProjSrcOpts.SaveEditorInfoOfNonProjectFiles;
341    SaveClosedEditorFilesInfoCheckbox.Checked:=
342      ProjSrcOpts.SaveClosedEditorFilesInfo;
343    ProjectInfoGroupbox.Enabled:=true;
344  end else begin
345    ProjectInfoGroupbox.Enabled:=false;
346  end;
347end;
348
349procedure TPublishProjectDialog.SaveToOptions(DestOpts: TPublishModuleOptions);
350var
351  ProjDestOpts: TPublishProjectOptions;
352begin
353  // destination
354  DestOpts.DestinationDirectory:=DestDirComboBox.Text;
355  DestOpts.CommandAfter:=CommandAfterCombobox.Text;
356  
357  // file filter
358  DestOpts.IgnoreBinaries:=IgnoreBinariesCheckbox.Checked;
359  DestOpts.UseIncludeFileFilter:=UseIncludeFilterCheckbox.Checked;
360  DestOpts.IncludeFilterSimpleSyntax:=IncFilterSimpleSyntaxCheckbox.Checked;
361  DestOpts.IncludeFileFilter:=IncludeFilterCombobox.Text;
362  DestOpts.UseExcludeFileFilter:=UseExcludeFilterCheckbox.Checked;
363  DestOpts.ExcludeFilterSimpleSyntax:=ExcFilterSimpleSyntaxCheckbox.Checked;
364  DestOpts.ExcludeFileFilter:=ExcludeFilterCombobox.Text;
365  
366  // project info
367  if DestOpts is TPublishProjectOptions then begin
368    ProjDestOpts:=TPublishProjectOptions(DestOpts);
369    ProjDestOpts.SaveEditorInfoOfNonProjectFiles:=
370      SaveEditorInfoOfNonProjectFilesCheckbox.Checked;
371    ProjDestOpts.SaveClosedEditorFilesInfo:=
372      SaveClosedEditorFilesInfoCheckbox.Checked;
373  end;
374end;
375
376end.
377