From dc9ea5da5cd6a8cb17007f262c4337f03ea0d14b Mon Sep 17 00:00:00 2001 From: mattias Date: Sat, 6 Oct 2007 14:37:17 +0000 Subject: [PATCH] added new package lazthread from Carlos German Tejero git-svn-id: trunk@12345 - --- .gitattributes | 7 + components/lazthread/lazthread.lpk | 54 +++++++ components/lazthread/lazthread.pas | 21 +++ components/lazthread/reglazthread.pas | 146 +++++++++++++++++++ components/lazthread/threadoptionsdialog.lfm | 48 ++++++ components/lazthread/threadoptionsdialog.lrs | 17 +++ components/lazthread/threadoptionsdialog.pas | 63 ++++++++ packager/globallinks/lazthread-0.lpl | 1 + 8 files changed, 357 insertions(+) create mode 100644 components/lazthread/lazthread.lpk create mode 100644 components/lazthread/lazthread.pas create mode 100644 components/lazthread/reglazthread.pas create mode 100644 components/lazthread/threadoptionsdialog.lfm create mode 100644 components/lazthread/threadoptionsdialog.lrs create mode 100644 components/lazthread/threadoptionsdialog.pas create mode 100644 packager/globallinks/lazthread-0.lpl diff --git a/.gitattributes b/.gitattributes index 9cc95c01ad..2ae17541dd 100644 --- a/.gitattributes +++ b/.gitattributes @@ -502,6 +502,12 @@ components/lazreport/source/lr_view.lrs svneol=native#text/plain components/lazreport/source/lr_view.pas svneol=native#text/pascal components/lazreport/source/sysutilsadds.pas svneol=native#text/pascal components/lazreport/tools/localize.sh svneol=native#text/plain +components/lazthread/lazthread.lpk svneol=native#text/plain +components/lazthread/lazthread.pas svneol=native#text/plain +components/lazthread/reglazthread.pas svneol=native#text/plain +components/lazthread/threadoptionsdialog.lfm svneol=native#text/plain +components/lazthread/threadoptionsdialog.lrs svneol=native#text/plain +components/lazthread/threadoptionsdialog.pas svneol=native#text/plain components/macfiles/Makefile svneol=native#text/plain components/macfiles/Makefile.fpc svneol=native#text/plain components/macfiles/examples/Readme.txt svneol=native#text/plain @@ -3150,6 +3156,7 @@ packager/globallinks/lazcustomform-0.lpl svneol=native#text/plain packager/globallinks/lazdaemon-0.lpl svneol=native#text/plain packager/globallinks/lazopenglcontext-0.lpl svneol=native#text/plain packager/globallinks/lazreport-0.9.5.lpl svneol=native#text/plain +packager/globallinks/lazthread-0.lpl svneol=native#text/plain packager/globallinks/macosfiles-0.lpl svneol=native#text/plain packager/globallinks/popupnotifierlaz-0.lpl svneol=native#text/plain packager/globallinks/prettyformat-0.lpl svneol=native#text/plain diff --git a/components/lazthread/lazthread.lpk b/components/lazthread/lazthread.lpk new file mode 100644 index 0000000000..6bbccfdb5f --- /dev/null +++ b/components/lazthread/lazthread.lpk @@ -0,0 +1,54 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/components/lazthread/lazthread.pas b/components/lazthread/lazthread.pas new file mode 100644 index 0000000000..10021955e1 --- /dev/null +++ b/components/lazthread/lazthread.pas @@ -0,0 +1,21 @@ +{ This file was automatically created by Lazarus. Do not edit! +This source is only used to compile and install the package. + } + +unit lazthread; + +interface + +uses + RegLazThread, ThreadOptionsDialog, LazarusPackageIntf; + +implementation + +procedure Register; +begin + RegisterUnit('RegLazThread', @RegLazThread.Register); +end; + +initialization + RegisterPackage('lazthread', @Register); +end. diff --git a/components/lazthread/reglazthread.pas b/components/lazthread/reglazthread.pas new file mode 100644 index 0000000000..80fcab01cc --- /dev/null +++ b/components/lazthread/reglazthread.pas @@ -0,0 +1,146 @@ +{ + ***************************************************************************** + * * + * See the file COPYING.modifiedLGPL, included in this distribution, * + * for details about the copyright. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * * + ***************************************************************************** +} + +unit RegLazThread; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, ProjectIntf, LazIdeIntf; + +type + { TThreadFileDescriptor } + TThreadFileDescriptor = class(TFileDescPascalUnit) + private + FThreadCount:integer; + FThreadName :string; + function GetNextThreadName:string; + function GetCurrentThreadName:string; + public + constructor Create; override; + function GetLocalizedName : string; override; + function GetLocalizedDescription : string; override; + function GetInterfaceSource(const Filename, SourceName, ResourceName: string): string; override; + function GetImplementationSource(const Filename, SourceName, ResourceName: string): string; override; + end; + +procedure register; + +implementation + +uses + Controls, ThreadOptionsDialog; + +resourcestring + SThreadName = 'Thread Object'; + SThreadDescription = 'A Pascal unit with a subclass of TThread class'; + +//---------------// +procedure register; +begin + RegisterProjectFileDescriptor(TThreadFileDescriptor.Create, FileDescGroupName); +end; + +{ TThreadFileDescriptor } + +//-------------------------------------// +constructor TThreadFileDescriptor.Create; +begin + inherited Create; + Name := SThreadName; + FThreadCount := 1; + FThreadName := TThread.ClassName; +end; + +//-----------------------------------------------------// +function TThreadFileDescriptor.GetNextThreadName: string; +var + ThreadOptionsDialog:TThreadOptionsDialog; +begin + //Create Default Thread Class Name + FThreadName := TThread.ClassName + IntToStr(FThreadCount); + FThreadCount := (FThreadCount mod MaxInt) + 1; + + //Show Thread Options Dialog + with(TThreadOptionsDialog.Create(nil))do + begin + ThreadNameEdit.Text := FThreadName; + if((ShowModal = mrOK)and(ThreadNameEdit.Text <> ''))then + begin + FThreadName := ThreadNameEdit.Text; + end; + Free; + end; + + //Return Thread Class Name + Result := FThreadName; +end; + +//--------------------------------------------------------// +function TThreadFileDescriptor.GetCurrentThreadName: string; +begin + Result := FThreadName; +end; + +//----------------------------------------------------// +function TThreadFileDescriptor.GetLocalizedName: string; +begin + Result := SThreadName; +end; + +//-----------------------------------------------------------// +function TThreadFileDescriptor.GetLocalizedDescription: string; +begin + Result := SThreadDescription; +end; + +//--------------------------------------------------------------------------------------------------------// +function TThreadFileDescriptor.GetInterfaceSource(const Filename, SourceName, ResourceName: string): string; +begin + with(TStringList.Create)do + begin + Add('type'); + Add(' ' + GetNextThreadName + ' = class(TThread)'); + Add(' private'); + Add(' { Private declarations }'); + Add(' protected'); + Add(' { Protected declarations }'); + Add(' procedure Execute; override;'); + Add(' end;'); + Add(''); + Result := Text; + Free; + end; +end; + +//-------------------------------------------------------------------------------------------------------------// +function TThreadFileDescriptor.GetImplementationSource(const Filename, SourceName, ResourceName: string): string; +begin + with(TStringList.Create)do + begin + Add('{ ' + GetCurrentThreadName + ' }'); + Add(''); + Add('procedure ' + GetCurrentThreadName + '.Execute;'); + Add('begin'); + Add(' { Write your thread code here }'); + Add('end;'); + Add(''); + Result := Text; + Free; + end; +end; + +end. + diff --git a/components/lazthread/threadoptionsdialog.lfm b/components/lazthread/threadoptionsdialog.lfm new file mode 100644 index 0000000000..202643fd2a --- /dev/null +++ b/components/lazthread/threadoptionsdialog.lfm @@ -0,0 +1,48 @@ +object ThreadOptionsDialog: TThreadOptionsDialog + Left = 282 + Height = 106 + Top = 183 + Width = 283 + HorzScrollBar.Page = 282 + VertScrollBar.Page = 105 + ActiveControl = ThreadNameEdit + BorderIcons = [] + Caption = 'ThreadOptionsDialog' + ClientHeight = 106 + ClientWidth = 283 + Position = poDesktopCenter + object OptionsGroupBox: TGroupBox + Height = 65 + Width = 283 + Align = alTop + ClientHeight = 47 + ClientWidth = 279 + TabOrder = 1 + object ThreadNameLabel: TLabel + Left = 22 + Height = 17 + Top = 2 + Width = 90 + ParentColor = False + end + object ThreadNameEdit: TEdit + Left = 22 + Height = 22 + Top = 16 + Width = 232 + Anchors = [akTop, akLeft, akRight] + TabOrder = 0 + end + end + object CreateUnitButton: TButton + Left = 40 + Height = 25 + Top = 73 + Width = 200 + Anchors = [akLeft, akRight, akBottom] + BorderSpacing.InnerBorder = 4 + Default = True + ModalResult = 1 + TabOrder = 0 + end +end diff --git a/components/lazthread/threadoptionsdialog.lrs b/components/lazthread/threadoptionsdialog.lrs new file mode 100644 index 0000000000..b022123a16 --- /dev/null +++ b/components/lazthread/threadoptionsdialog.lrs @@ -0,0 +1,17 @@ +{ Este es un archivo de recurso de Lazarus generado automáticamente } + +LazarusResources.Add('TThreadOptionsDialog','FORMDATA',[ + 'TPF0'#20'TThreadOptionsDialog'#19'ThreadOptionsDialog'#4'Left'#3#26#1#6'Heig' + +'ht'#2'j'#3'Top'#3#183#0#5'Width'#3#27#1#18'HorzScrollBar.Page'#3#26#1#18'Ve' + +'rtScrollBar.Page'#2'i'#13'ActiveControl'#7#14'ThreadNameEdit'#11'BorderIcon' + +'s'#11#0#7'Caption'#6#19'ThreadOptionsDialog'#12'ClientHeight'#2'j'#11'Clien' + +'tWidth'#3#27#1#8'Position'#7#15'poDesktopCenter'#0#9'TGroupBox'#15'OptionsG' + +'roupBox'#6'Height'#2'A'#5'Width'#3#27#1#5'Align'#7#5'alTop'#12'ClientHeight' + +#2'/'#11'ClientWidth'#3#23#1#8'TabOrder'#2#1#0#6'TLabel'#15'ThreadNameLabel' + +#4'Left'#2#22#6'Height'#2#17#3'Top'#2#2#5'Width'#2'Z'#11'ParentColor'#8#0#0#5 + +'TEdit'#14'ThreadNameEdit'#4'Left'#2#22#6'Height'#2#22#3'Top'#2#16#5'Width'#3 + +#232#0#7'Anchors'#11#5'akTop'#6'akLeft'#7'akRight'#0#8'TabOrder'#2#0#0#0#0#7 + +'TButton'#16'CreateUnitButton'#4'Left'#2'('#6'Height'#2#25#3'Top'#2'I'#5'Wid' + +'th'#3#200#0#7'Anchors'#11#6'akLeft'#7'akRight'#8'akBottom'#0#25'BorderSpaci' + +'ng.InnerBorder'#2#4#7'Default'#9#11'ModalResult'#2#1#8'TabOrder'#2#0#0#0#0 +]); diff --git a/components/lazthread/threadoptionsdialog.pas b/components/lazthread/threadoptionsdialog.pas new file mode 100644 index 0000000000..601c9e6f43 --- /dev/null +++ b/components/lazthread/threadoptionsdialog.pas @@ -0,0 +1,63 @@ +{ + ***************************************************************************** + * * + * See the file COPYING.modifiedLGPL, included in this distribution, * + * for details about the copyright. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. * + * * + ***************************************************************************** +} + +unit ThreadOptionsDialog; + +{$mode objfpc}{$H+} + +interface + +uses + Classes, SysUtils, LResources, Forms, Controls, Graphics, Dialogs, StdCtrls; + +type + + { TThreadOptionsDialog } + + TThreadOptionsDialog = class(TForm) + CreateUnitButton: TButton; + ThreadNameLabel: TLabel; + ThreadNameEdit: TEdit; + OptionsGroupBox: TGroupBox; + private + { private declarations } + public + { public declarations } + constructor Create(AOwner: TComponent);override; + end; + +implementation + +resourcestring + SThreadDialogTitle = 'Thread Class Options'; + SOptionsGroupBoxCaption = 'Options'; + SThreadNameLabelCaption = 'Thread Class Name'; + SCreateUnitButtonCaption = 'Create Unit'; + +{ TThreadOptionsDialog } + +//--------------------------------------------------------// +constructor TThreadOptionsDialog.Create(AOwner: TComponent); +begin + inherited Create(AOwner); + Caption := SThreadDialogTitle; + OptionsGroupBox.Caption := SOptionsGroupBoxCaption; + ThreadNameLabel.Caption := SThreadNameLabelCaption; + CreateUnitButton.Caption := SCreateUnitButtonCaption; +end; + +initialization + {$I threadoptionsdialog.lrs} + +end. + diff --git a/packager/globallinks/lazthread-0.lpl b/packager/globallinks/lazthread-0.lpl new file mode 100644 index 0000000000..57e60e6ae7 --- /dev/null +++ b/packager/globallinks/lazthread-0.lpl @@ -0,0 +1 @@ +$(LazarusDir)/components/lazthread/lazthread.lpk