IDE: added options for new project item console application from Michael Van Canneyt

git-svn-id: trunk@11805 -
This commit is contained in:
mattias 2007-08-13 08:59:41 +00:00
parent b050f71de9
commit 0df6cf29ec
5 changed files with 334 additions and 38 deletions

3
.gitattributes vendored
View File

@ -1524,6 +1524,9 @@ ide/findreplacedialog.lfm svneol=native#text/plain
ide/findreplacedialog.lrs svneol=native#text/plain
ide/findreplacedialog.pp svneol=native#text/pascal
ide/formeditor.pp svneol=native#text/pascal
ide/frmcustomapplicationoptions.lfm svneol=native#text/plain
ide/frmcustomapplicationoptions.lrs svneol=native#text/plain
ide/frmcustomapplicationoptions.pas svneol=native#text/plain
ide/frmsearch.lfm svneol=native#text/plain
ide/frmsearch.lrs svneol=native#text/pascal
ide/frmsearch.pas svneol=native#text/pascal

View File

@ -0,0 +1,119 @@
object CustomApplicationOptionsForm: TCustomApplicationOptionsForm
Left = 409
Height = 290
Top = 254
Width = 460
HorzScrollBar.Page = 459
VertScrollBar.Page = 289
ActiveControl = EClassName
BorderIcons = [biSystemMenu]
BorderStyle = bsDialog
Caption = 'New console application'
ClientHeight = 290
ClientWidth = 460
OnCreate = FormCreate
Position = poScreenCenter
object LEClassName: TLabel
Left = 8
Height = 23
Top = 8
Width = 227
Alignment = taRightJustify
AutoSize = False
Caption = '&Application class name'
FocusControl = EClassName
Layout = tlCenter
ParentColor = False
end
object LETitle: TLabel
Left = 8
Height = 23
Top = 38
Width = 227
Alignment = taRightJustify
AutoSize = False
Caption = '&Title'
FocusControl = ETitle
Layout = tlCenter
ParentColor = False
end
object BCancel: TButton
Left = 288
Height = 25
Top = 261
Width = 75
Anchors = [akRight, akBottom]
BorderSpacing.InnerBorder = 4
Cancel = True
Caption = '&Cancel'
ModalResult = 2
TabOrder = 4
end
object BOK: TButton
Left = 376
Height = 25
Top = 261
Width = 75
Anchors = [akRight, akBottom]
BorderSpacing.InnerBorder = 4
Caption = '&OK'
Default = True
ModalResult = 1
TabOrder = 3
end
object EClassName: TEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 241
Height = 23
Top = 8
Width = 213
Anchors = [akTop, akLeft, akRight]
AutoSelect = True
BorderSpacing.Around = 6
OnKeyPress = EClassNameKeyPress
TabOrder = 0
Text = 'TMyApplication'
end
object CGOptions: TCheckGroup
Left = 8
Height = 181
Top = 72
Width = 443
Anchors = [akTop, akLeft, akRight, akBottom]
AutoFill = True
Caption = 'Code generation options'
ChildSizing.LeftRightSpacing = 6
ChildSizing.TopBottomSpacing = 6
ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
ChildSizing.EnlargeVertical = crsHomogenousChildResize
ChildSizing.ShrinkHorizontal = crsScaleChilds
ChildSizing.ShrinkVertical = crsScaleChilds
ChildSizing.Layout = cclLeftToRightThenTopToBottom
ChildSizing.ControlsPerLine = 1
Items.Strings = (
'Usage message (-h option)'
'Stop on exception'
'Constructor code'
'Destructor code'
'Check options'
)
TabOrder = 2
Data = {
050000000202020202
}
end
object ETitle: TEdit
AnchorSideRight.Control = Owner
AnchorSideRight.Side = asrBottom
Left = 240
Height = 23
Top = 38
Width = 214
Anchors = [akTop, akLeft, akRight]
AutoSelect = True
BorderSpacing.Around = 6
TabOrder = 1
Text = 'My Application'
end
end

View File

@ -0,0 +1,42 @@
{ This is an automatically generated lazarus resource file }
LazarusResources.Add('TCustomApplicationOptionsForm','FORMDATA',[
'TPF0'#29'TCustomApplicationOptionsForm'#28'CustomApplicationOptionsForm'#4'L'
+'eft'#3#153#1#6'Height'#3'"'#1#3'Top'#3#254#0#5'Width'#3#204#1#18'HorzScroll'
+'Bar.Page'#3#203#1#18'VertScrollBar.Page'#3'!'#1#13'ActiveControl'#7#10'ECla'
+'ssName'#11'BorderIcons'#11#12'biSystemMenu'#0#11'BorderStyle'#7#8'bsDialog'
+#7'Caption'#6#23'New console application'#12'ClientHeight'#3'"'#1#11'ClientW'
+'idth'#3#204#1#8'OnCreate'#7#10'FormCreate'#8'Position'#7#14'poScreenCenter'
+#0#6'TLabel'#11'LEClassName'#4'Left'#2#8#6'Height'#2#23#3'Top'#2#8#5'Width'#3
+#227#0#9'Alignment'#7#14'taRightJustify'#8'AutoSize'#8#7'Caption'#6#23'&Appl'
+'ication class name'#12'FocusControl'#7#10'EClassName'#6'Layout'#7#8'tlCente'
+'r'#11'ParentColor'#8#0#0#6'TLabel'#7'LETitle'#4'Left'#2#8#6'Height'#2#23#3
+'Top'#2'&'#5'Width'#3#227#0#9'Alignment'#7#14'taRightJustify'#8'AutoSize'#8#7
+'Caption'#6#6'&Title'#12'FocusControl'#7#6'ETitle'#6'Layout'#7#8'tlCenter'#11
+'ParentColor'#8#0#0#7'TButton'#7'BCancel'#4'Left'#3' '#1#6'Height'#2#25#3'To'
+'p'#3#5#1#5'Width'#2'K'#7'Anchors'#11#7'akRight'#8'akBottom'#0#25'BorderSpac'
+'ing.InnerBorder'#2#4#6'Cancel'#9#7'Caption'#6#7'&Cancel'#11'ModalResult'#2#2
+#8'TabOrder'#2#4#0#0#7'TButton'#3'BOK'#4'Left'#3'x'#1#6'Height'#2#25#3'Top'#3
+#5#1#5'Width'#2'K'#7'Anchors'#11#7'akRight'#8'akBottom'#0#25'BorderSpacing.I'
+'nnerBorder'#2#4#7'Caption'#6#3'&OK'#7'Default'#9#11'ModalResult'#2#1#8'TabO'
+'rder'#2#3#0#0#5'TEdit'#10'EClassName'#23'AnchorSideRight.Control'#7#5'Owner'
+#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#3#241#0#6'Height'#2#23#3'To'
+'p'#2#8#5'Width'#3#213#0#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#10'Au'
+'toSelect'#9#20'BorderSpacing.Around'#2#6#10'OnKeyPress'#7#18'EClassNameKeyP'
+'ress'#8'TabOrder'#2#0#4'Text'#6#14'TMyApplication'#0#0#11'TCheckGroup'#9'CG'
+'Options'#4'Left'#2#8#6'Height'#3#181#0#3'Top'#2'H'#5'Width'#3#187#1#7'Ancho'
+'rs'#11#5'akTop'#6'akLeft'#7'akRight'#8'akBottom'#0#8'AutoFill'#9#7'Caption'
+#6#23'Code generation options'#28'ChildSizing.LeftRightSpacing'#2#6#28'Child'
+'Sizing.TopBottomSpacing'#2#6#29'ChildSizing.EnlargeHorizontal'#7#24'crsHomo'
+'genousChildResize'#27'ChildSizing.EnlargeVertical'#7#24'crsHomogenousChildR'
+'esize'#28'ChildSizing.ShrinkHorizontal'#7#14'crsScaleChilds'#26'ChildSizing'
+'.ShrinkVertical'#7#14'crsScaleChilds'#18'ChildSizing.Layout'#7#29'cclLeftTo'
+'RightThenTopToBottom'#27'ChildSizing.ControlsPerLine'#2#1#13'Items.Strings'
+#1#6#25'Usage message (-h option)'#6#17'Stop on exception'#6#16'Constructor '
+'code'#6#15'Destructor code'#6#13'Check options'#0#8'TabOrder'#2#2#4'Data'#10
+#9#0#0#0#5#0#0#0#2#2#2#2#2#0#0#5'TEdit'#6'ETitle'#23'AnchorSideRight.Control'
+#7#5'Owner'#20'AnchorSideRight.Side'#7#9'asrBottom'#4'Left'#3#240#0#6'Height'
+#2#23#3'Top'#2'&'#5'Width'#3#214#0#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRigh'
+'t'#0#10'AutoSelect'#9#20'BorderSpacing.Around'#2#6#8'TabOrder'#2#1#4'Text'#6
+#14'My Application'#0#0#0
]);

View File

@ -0,0 +1,90 @@
unit frmcustomapplicationoptions;
{$mode objfpc}{$H+}
interface
uses
Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls,
ExtCtrls;
type
{ TCustomApplicationOptionsForm }
TCustomApplicationOptionsForm = class(TForm)
BCancel: TButton;
BOK: TButton;
CGOptions: TCheckGroup;
EClassName: TEdit;
ETitle: TEdit;
LETitle: TLabel;
LEClassName: TLabel;
procedure EClassNameKeyPress(Sender: TObject; var Key: char);
procedure FormCreate(Sender: TObject);
function GetAppName: String;
function GetBool(Index: integer): Boolean;
function GetTitle: String;
private
{ private declarations }
public
{ public declarations }
Property Title : String Read GetTitle;
Property AppClassName : String Read GetAppName;
Property CodeUsage : Boolean Index 0 Read GetBool;
Property CodeStopOnError : Boolean Index 1 Read GetBool;
Property CodeConstructor : Boolean Index 2 Read GetBool;
Property CodeDestructor : Boolean Index 3 Read GetBool;
Property CodeCheckOptions : Boolean Index 4 Read GetBool;
end;
var
CustomApplicationOptionsForm: TCustomApplicationOptionsForm;
implementation
{ TCustomApplicationOptionsForm }
function TCustomApplicationOptionsForm.GetAppName: String;
begin
Result:=EClassName.Text;
end;
procedure TCustomApplicationOptionsForm.EClassNameKeyPress(Sender: TObject;
var Key: char);
Const
Alpha = ['a'..'z','A'..'Z'];
Num = ['0'..'9'];
Oth = ['_',#8,#9,#27]; // allow Backspace, tab, escape
AllowedKeys = Alpha+Num+Oth;
begin
If Not (Key in AllowedKeys) then
Key:=#0;
end;
procedure TCustomApplicationOptionsForm.FormCreate(Sender: TObject);
var
i: Integer;
begin
// set all defaults to true
for i:=0 to CGOptions.Items.Count-1 do
CGOptions.Checked[i]:=true;
end;
function TCustomApplicationOptionsForm.GetBool(Index: integer): Boolean;
begin
Result:= CGOptions.Checked[Index];
end;
function TCustomApplicationOptionsForm.GetTitle: String;
begin
Result:=ETitle.Text;
end;
initialization
{$I frmcustomapplicationoptions.lrs}
end.

View File

@ -794,6 +794,7 @@ procedure AddCompileReasonsDiff(Tool: TCompilerDiffTool;
implementation
uses frmcustomapplicationoptions;
const
ProjectInfoFileVersion = 5;
@ -4821,9 +4822,28 @@ function TProjectConsoleApplicationDescriptor.InitProject(AProject: TLazProject
var
NewSource: TStringList;
MainFile: TLazProjectFile;
C, T : String;
CC,CD,CU,CS, CO : Boolean;
begin
Result:=inherited InitProject(AProject);
If Result<>mrOk then
Exit;
With TCustomApplicationOptionsForm.Create(Application) do
try
Result:=ShowModal;
If Result<>mrOk then
Exit;
C:=Trim(AppClassName);
T:=StringReplace(Title,'''','''''',[rfReplaceAll]);
CC:=CodeConstructor;
CD:=CodeDestructor;
CU:=CodeUsage;
CS:=CodeStopOnError;
CO:=CodeCheckOptions;
finally
Free;
end;
MainFile:=AProject.CreateProjectFile('project1.lpr');
MainFile.IsPartOfProject:=true;
AProject.AddFile(MainFile,false);
@ -4844,35 +4864,44 @@ begin
NewSource.Add('');
NewSource.Add('type');
NewSource.Add('');
NewSource.Add(' { TMyApplication }');
NewSource.Add(' { '+C+' }');
NewSource.Add('');
NewSource.Add(' TMyApplication = class(TCustomApplication)');
NewSource.Add(' '+C+' = class(TCustomApplication)');
NewSource.Add(' protected');
NewSource.Add(' procedure DoRun; override;');
NewSource.Add(' public');
NewSource.Add(' constructor Create(TheOwner: TComponent); override;');
NewSource.Add(' destructor Destroy; override;');
NewSource.Add(' procedure WriteHelp; virtual;');
If CC or CS then
NewSource.Add(' constructor Create(TheOwner: TComponent); override;');
if CD then
NewSource.Add(' destructor Destroy; override;');
if CU then
NewSource.Add(' procedure WriteHelp; virtual;');
NewSource.Add(' end;');
NewSource.Add('');
NewSource.Add('{ TMyApplication }');
NewSource.Add('{ '+C+' }');
NewSource.Add('');
NewSource.Add('procedure TMyApplication.DoRun;');
NewSource.Add('procedure '+C+'.DoRun;');
NewSource.Add('var');
NewSource.Add(' ErrorMsg: String;');
NewSource.Add('begin');
NewSource.Add(' // quick check parameters');
NewSource.Add(' ErrorMsg:=CheckOptions(''h'',''help'');');
NewSource.Add(' if ErrorMsg<>'''' then begin');
NewSource.Add(' ShowException(Exception.Create(ErrorMsg));');
NewSource.Add(' Halt;');
NewSource.Add(' end;');
NewSource.Add('');
NewSource.Add(' // parse parameters');
NewSource.Add(' if HasOption(''h'',''help'') then begin');
NewSource.Add(' WriteHelp;');
NewSource.Add(' Halt;');
NewSource.Add(' end;');
if CO then
begin
NewSource.Add(' // quick check parameters');
NewSource.Add(' ErrorMsg:=CheckOptions(''h'',''help'');');
NewSource.Add(' if ErrorMsg<>'''' then begin');
NewSource.Add(' ShowException(Exception.Create(ErrorMsg));');
NewSource.Add(' Halt;');
NewSource.Add(' end;');
NewSource.Add('');
end;
If CU then
begin
NewSource.Add(' // parse parameters');
NewSource.Add(' if HasOption(''h'',''help'') then begin');
NewSource.Add(' WriteHelp;');
NewSource.Add(' Halt;');
NewSource.Add(' end;');
end;
NewSource.Add('');
NewSource.Add(' { add your program here }');
NewSource.Add('');
@ -4880,26 +4909,39 @@ begin
NewSource.Add(' Terminate;');
NewSource.Add('end;');
NewSource.Add('');
NewSource.Add('constructor TMyApplication.Create(TheOwner: TComponent);');
NewSource.Add('begin');
NewSource.Add(' inherited Create(TheOwner);');
NewSource.Add('end;');
NewSource.Add('');
NewSource.Add('destructor TMyApplication.Destroy;');
NewSource.Add('begin');
NewSource.Add(' inherited Destroy;');
NewSource.Add('end;');
NewSource.Add('');
NewSource.Add('procedure TMyApplication.WriteHelp;');
NewSource.Add('begin');
NewSource.Add(' { add your help code here }');
NewSource.Add(' writeln(''Usage: '',ExeName,'' -h'');');
NewSource.Add('end;');
NewSource.Add('');
If CC or CS then
begin
NewSource.Add('constructor '+C+'.Create(TheOwner: TComponent);');
NewSource.Add('begin');
NewSource.Add(' inherited Create(TheOwner);');
If CS then
NewSource.Add(' StopOnException:=True;');
NewSource.Add('end;');
NewSource.Add('');
end;
If CD then
begin
NewSource.Add('destructor '+C+'.Destroy;');
NewSource.Add('begin');
NewSource.Add(' inherited Destroy;');
NewSource.Add('end;');
NewSource.Add('');
end;
If CU then
begin
NewSource.Add('procedure '+C+'.WriteHelp;');
NewSource.Add('begin');
NewSource.Add(' { add your help code here }');
NewSource.Add(' writeln(''Usage: '',ExeName,'' -h'');');
NewSource.Add('end;');
NewSource.Add('');
end;
NewSource.Add('var');
NewSource.Add(' Application: TMyApplication;');
NewSource.Add(' Application: '+C+';');
NewSource.Add('begin');
NewSource.Add(' Application:=TMyApplication.Create(nil);');
NewSource.Add(' Application:='+C+'.Create(nil);');
If (T<>'') then
NewSource.Add(' Application.Title:='''+T+''';');
NewSource.Add(' Application.Run;');
NewSource.Add(' Application.Free;');
NewSource.Add('end.');