View Issue Details

IDProjectCategoryView StatusLast Update
0013994LazarusIDEpublic2015-10-29 12:17
ReporterGraeme GeldenhuysAssigned ToOndrej Pokorny 
PrioritynormalSeverityfeatureReproducibilityN/A
Status resolvedResolutionfixed 
Platformx86OSUbuntu LinuxOS Version8.04.2
Product Version0.9.27 (SVN)Product Buildlatest svn 
Target VersionFixed in Version1.5 (SVN) 
Summary0013994: Code Tools tuning - location of new events
DescriptionAt the moment the events are always added to the first published section. There is currently no way to tell Code Tools where to place new event handlers.

Maybe Code Tools can have a new tuning option as follows: Specify the preferred location for new event handlers: first published, public, protected, private, ask. "Ask" will popup a dialog.

Maybe the option could be called: "Event insert policy" to keep with the naming convention used for other similar policies. A radio button group will then contain the options listed above.

Below is the message I posted to the mailing list explaining the issue in more details.

==========[ forward ]==============
I have code defined as follows (it's a fpGUI Toolkit project). Here I
have a Form with 2 Buttons on it. No event handlers have been defined yet.

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    btnCreate: TfpgButton;
    btnDebug: TfpgButton;
    {@VFD_HEAD_END: MainForm}
  public
    procedure AfterCreate; override;
  end;


Inside the AfterCreate() method is the code that initializes the GUI.
fpGUI doesn't use external *.lfm files like Lazarus LCL projects.

Anyway, I add a OnClick event handler in the AfterCreate method for one
of the buttons.

  btnDebug := TfpgButton.Create(self);
  with btnDebug do
  begin
    ...
    OnClick := | // | is the cursor position
  end;

I then press Ctrl+Shift+C to fire off code completion which creates the
event handler. This is the result:

  TMainForm = class(TfpgForm)
    procedure btnDebugClick(Sender: TObject);
  private
    {@VFD_HEAD_BEGIN: MainForm}
    btnCreate: TfpgButton;
    btnDebug: TfpgButton;
    {@VFD_HEAD_END: MainForm}
  public
    procedure AfterCreate; override;
  end;


But that is not really what I wanted. I wanted the btnDebugClick method
to be private, not published. Published is the default visibility if no
visibility is specified. The following code is actually what I wanted:

  TMainForm = class(TfpgForm)
  private
    {@VFD_HEAD_BEGIN: MainForm}
    btnCreate: TfpgButton;
    btnDebug: TfpgButton;
    {@VFD_HEAD_END: MainForm}
    procedure btnDebugClick(Sender: TObject);
    procedure btnCreateClick(Sender: TObject);
  public
    procedure AfterCreate; override;
  end;

Even after I manually moved the btnDebugClick() event handler to the
correct location in the 'private' area, when I create the second event
handler for the Create Button, Code Tools again places the event handler
in the published section.

In Code Tools I have "Class part insert policy" set to "Last" and
"Method insert policy" set to "class order".
========================
TagsNo tags attached.
Fixed in Revision50197
LazTarget-
Widgetset
Attached Files
  • ct-event-method-section-1.patch (35,462 bytes)
    Index: components/codetools/codecompletiontool.pas
    ===================================================================
    --- components/codetools/codecompletiontool.pas	(revision 50022)
    +++ components/codetools/codecompletiontool.pas	(working copy)
    @@ -124,6 +124,14 @@
         ctnClassPublished  // pcsPublished
       );
     
    +  InsertMethodSectionToNewClassPart: array[TInsertMethodSectionResult] of TNewClassPart = (
    +    ncpPrivateProcs,
    +    ncpProtectedProcs,
    +    ncpPublicProcs,
    +    ncpPublishedProcs,
    +    ncpPrivateProcs
    +  );
    +
     type
       TCodeCompletionCodeTool = class;
     
    @@ -207,10 +215,10 @@
         procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer;
                               out NewPos: TCodeXYPosition; out NewTopLine: integer);
         procedure AddNeededUnitToMainUsesSection(AnUnitName: PChar);
    -    procedure AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
    +    function AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
                       const AnEventName: string; ProcContext: TFindContext; out
                       MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
    -                  SourceChangeCache: TSourceChangeCache);
    +                  SourceChangeCache: TSourceChangeCache): Boolean;
         procedure AddProcedureCompatibleToProcType(
                       const NewProcName: string; ProcContext: TFindContext; out
                       MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
    @@ -1363,14 +1371,17 @@
       Pointer(s):=nil;
     end;
     
    -procedure TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
    +function TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
       AClassNode: TCodeTreeNode; const AnEventName: string;
       ProcContext: TFindContext; out MethodDefinition: string; out
    -  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
    +  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache
    +  ): Boolean;
     var
       CleanMethodDefinition: string;
       Beauty: TBeautifyCodeOptions;
    +  MethodSection: TInsertMethodSectionResult;
     begin
    +  Result := False;
       MethodDefinition:='';
       MethodAttr:=[];
     
    @@ -1402,8 +1413,11 @@
       {$ENDIF}
       if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
         // insert method definition into class
    +    MethodSection := Beauty.GetRealEventMethodSection;
    +    if MethodSection=imsrAbort then
    +      Exit;
         AddClassInsertion(CleanMethodDefinition, MethodDefinition,
    -                      AnEventName, ncpPublishedProcs);
    +                      AnEventName, InsertMethodSectionToNewClassPart[MethodSection]);
       end;
       MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition,
                        ExtractClassName(AClassNode,false,true), AnEventName);
    @@ -1413,6 +1427,7 @@
       // insert all missing proc bodies
       if not CreateMissingClassProcBodies(false) then
         RaiseException(ctsErrorDuringCreationOfNewProcBodies);
    +  Result := True;
     end;
     
     procedure TCodeCompletionCodeTool.AddProcedureCompatibleToProcType(
    @@ -2145,8 +2160,10 @@
             if FullEventName='' then exit;
     
             // add published method and method body and right side of assignment
    -        AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
    -          AMethodDefinition,AMethodAttr,SourceChangeCache);
    +        if not AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
    +          AMethodDefinition,AMethodAttr,SourceChangeCache)
    +        then
    +          Exit;
             if not CompleteAssignment(FullEventName,AssignmentOperator,
               AddrOperatorPos,SemicolonPos,UserEventAtom)
             then
    @@ -2293,8 +2310,10 @@
         ProcContext:=CreateFindContext(TypeTool,TypeNode);
     
         // create new method
    -    AddMethodCompatibleToProcType(AClassNode,Identifier,
    -      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache);
    +    if not AddMethodCompatibleToProcType(AClassNode,Identifier,
    +      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache)
    +    then
    +      Exit;
     
         // apply the changes
         if not SourceChangeCache.Apply then
    Index: components/codetools/sourcechanger.pas
    ===================================================================
    --- components/codetools/sourcechanger.pas	(revision 50022)
    +++ components/codetools/sourcechanger.pas	(working copy)
    @@ -59,6 +59,22 @@
         mipClassOrder      // try to copy the order of the class
         );
         
    +  //where to add created methods from event assignment: "OnClick := @MyNewProc;"
    +  TInsertMethodSection = (
    +    imsPrivate,
    +    imsProtected,
    +    imsPublic,
    +    imsPublished,
    +    imsPrompt //show dialog prompt
    +    );
    +  TInsertMethodSectionResult = (
    +    imsrPrivate,
    +    imsrProtected,
    +    imsrPublic,
    +    imsrPublished,
    +    imsrAbort //prompt dialog aborted
    +  );
    +
       TForwardProcBodyInsertPolicy = (
         fpipLast,
         fpipInFrontOfMethods,
    @@ -90,7 +106,16 @@
     
     const
       DefaultUsesInsertPolicy = uipBehindRelated;
    +  DefaultEventMethodSection = imsPrompt;
     
    +  InsertMethodSectionToResult: array[TInsertMethodSection] of TInsertMethodSectionResult = (
    +    imsrPrivate,
    +    imsrProtected,
    +    imsrPublic,
    +    imsrPublished,
    +    imsrPrivate
    +    );
    +
     type
       TWordPolicyException = class
         Word: string;
    @@ -157,6 +182,7 @@
         ClassPartInsertPolicy: TClassPartInsertPolicy;
         MixMethodsAndProperties: boolean;
         MethodInsertPolicy: TMethodInsertPolicy;
    +    EventMethodSection: TInsertMethodSection;
         PropertyReadIdentPrefix: string;
         PropertyWriteIdentPrefix: string;
         PropertyStoredIdentPostfix: string;
    @@ -169,6 +195,7 @@
         
         NestedComments: boolean;
     
    +    function GetRealEventMethodSection: TInsertMethodSectionResult; //in case of imsPrompt show a dialog and return a "normal" section
         function GetIndentStr(TheIndent: integer): string; inline;
         function GetLineIndent(const Source: string; Position: integer): integer; inline;
         procedure SetupWordPolicyExceptions(ws: TStrings);
    @@ -328,7 +355,15 @@
       MethodInsertPolicyNames: array[TMethodInsertPolicy] of shortstring = (
           'Alphabetically', 'Last', 'ClassOrder'
         );
    -    
    +
    +  InsertMethodSectionNames: array[TInsertMethodSection] of ShortString = (
    +    'Private', 'Protected', 'Public', 'Published', 'Prompt'
    +    );
    +
    +  InsertMethodSectionResultNames: array[TInsertMethodSectionResult] of ShortString = (
    +    'Private', 'Protected', 'Public', 'Published', 'Abort'
    +    );
    +
       ForwardProcBodyInsertPolicyNames: array[TForwardProcBodyInsertPolicy] of
         shortstring = (
           'Last',
    @@ -352,11 +387,18 @@
       DefaultDoNotInsertSpaceInFront: TAtomTypes = [];
       DefaultDoNotInsertSpaceAfter: TAtomTypes = [atDirectiveStart];
     
    +type
    +  TShowEventMethodSectionPromptFunc = function(): TInsertMethodSectionResult;
    +var
    +  ShowEventMethodSectionPrompt: TShowEventMethodSectionPromptFunc = nil;
    +
     function AtomTypeNameToType(const s: string): TAtomType;
     function AtomTypesToStr(const AtomTypes: TAtomTypes): string;
     function WordPolicyNameToPolicy(const s: string): TWordPolicy;
     function ClassPartPolicyNameToPolicy(const s: string): TClassPartInsertPolicy;
     function MethodInsertPolicyNameToPolicy(const s: string): TMethodInsertPolicy;
    +function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
    +function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
     function ForwardProcBodyInsertPolicyNameToPolicy(
       const s: string): TForwardProcBodyInsertPolicy;
     function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
    @@ -409,6 +451,20 @@
       Result:=mipLast;
     end;
     
    +function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
    +begin
    +  for Result:=Low(TInsertMethodSection) to High(TInsertMethodSection) do
    +    if SysUtils.CompareText(InsertMethodSectionNames[Result],s)=0 then exit;
    +  Result:=DefaultEventMethodSection;
    +end;
    +
    +function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
    +begin
    +  for Result:=Low(TInsertMethodSectionResult) to High(TInsertMethodSectionResult) do
    +    if SysUtils.CompareText(InsertMethodSectionResultNames[Result],s)=0 then exit;
    +  Result:=imsrPrivate;
    +end;
    +
     function ForwardProcBodyInsertPolicyNameToPolicy(
       const s: string): TForwardProcBodyInsertPolicy;
     begin
    @@ -1259,6 +1315,7 @@
       UpdateOtherProcSignaturesCase:=true;
       GroupLocalVariables:=true;
       MethodInsertPolicy:=mipClassOrder;
    +  EventMethodSection:=DefaultEventMethodSection;
       ForwardProcBodyInsertPolicy:=fpipBehindMethods;
       KeepForwardProcOrder:=true;
       ClassHeaderComments:=true;
    @@ -1685,6 +1742,21 @@
         Result:=false;
     end;
     
    +function TBeautifyCodeOptions.GetRealEventMethodSection: TInsertMethodSectionResult;
    +var
    +  SectionResult: TInsertMethodSection;
    +begin
    +  SectionResult := EventMethodSection;
    +  if (SectionResult = imsPrompt) then
    +  begin
    +    if Assigned(ShowEventMethodSectionPrompt) then
    +      Result := ShowEventMethodSectionPrompt()
    +    else
    +      Result := InsertMethodSectionToResult[DefaultEventMethodSection];
    +  end else
    +    Result := InsertMethodSectionToResult[SectionResult];
    +end;
    +
     procedure TBeautifyCodeOptions.SetupWordPolicyExceptions(ws: TStrings);
     begin
       if Assigned(WordExceptions) then WordExceptions.Free;
    Index: ide/choosemethodsectiondlg.lfm
    ===================================================================
    --- ide/choosemethodsectiondlg.lfm	(nonexistent)
    +++ ide/choosemethodsectiondlg.lfm	(working copy)
    @@ -0,0 +1,45 @@
    +object ChooseMethodSectionDialog: TChooseMethodSectionDialog
    +  Left = 460
    +  Height = 177
    +  Top = 220
    +  Width = 252
    +  BorderStyle = bsDialog
    +  Caption = 'ChooseMethodSectionDialog'
    +  ClientHeight = 177
    +  ClientWidth = 252
    +  KeyPreview = True
    +  OnKeyPress = FormKeyPress
    +  Position = poDesktopCenter
    +  LCLVersion = '1.5'
    +  object SectionsListBox: TListBox
    +    Left = 10
    +    Height = 117
    +    Top = 10
    +    Width = 232
    +    Align = alClient
    +    BorderSpacing.Left = 10
    +    BorderSpacing.Top = 10
    +    BorderSpacing.Right = 10
    +    BorderSpacing.Bottom = 10
    +    ItemHeight = 0
    +    OnDblClick = SectionsListBoxDblClick
    +    OnKeyPress = SectionsListBoxKeyPress
    +    TabOrder = 0
    +  end
    +  object ButtonPanel: TButtonPanel
    +    Left = 6
    +    Height = 34
    +    Top = 137
    +    Width = 240
    +    OKButton.Name = 'OKButton'
    +    OKButton.DefaultCaption = True
    +    HelpButton.Name = 'HelpButton'
    +    HelpButton.DefaultCaption = True
    +    CloseButton.Name = 'CloseButton'
    +    CloseButton.DefaultCaption = True
    +    CancelButton.Name = 'CancelButton'
    +    CancelButton.DefaultCaption = True
    +    TabOrder = 1
    +    ShowButtons = [pbOK]
    +  end
    +end
    Index: ide/choosemethodsectiondlg.pas
    ===================================================================
    --- ide/choosemethodsectiondlg.pas	(nonexistent)
    +++ ide/choosemethodsectiondlg.pas	(working copy)
    @@ -0,0 +1,124 @@
    +{
    + ***************************************************************************
    + *                                                                         *
    + *   This source is free software; you can redistribute it and/or modify   *
    + *   it under the terms of the GNU General Public License as published by  *
    + *   the Free Software Foundation; either version 2 of the License, or     *
    + *   (at your option) any later version.                                   *
    + *                                                                         *
    + *   This code 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.  See the GNU     *
    + *   General Public License for more details.                              *
    + *                                                                         *
    + *   A copy of the GNU General Public License is available on the World    *
    + *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
    + *   obtain it by writing to the Free Software Foundation,                 *
    + *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
    + *                                                                         *
    + ***************************************************************************
    +
    +  Author: Ondrej Pokorny
    +
    +  Abstract:
    +    A simple dialog to select class section.
    +}
    +unit ChooseMethodSectionDlg;
    +
    +{$mode objfpc}{$H+}
    +
    +interface
    +
    +uses
    +  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    +  ButtonPanel, SourceChanger, LazarusIDEStrConsts, EnvironmentOpts;
    +
    +type
    +  //this dialog can easily be reused.
    +  //for now it is used only in the method event assignment code creation
    +
    +  TChooseMethodSectionDialog = class(TForm)
    +    ButtonPanel: TButtonPanel;
    +    SectionsListBox: TListBox;
    +    procedure FormKeyPress(Sender: TObject; var Key: char);
    +    procedure SectionsListBoxDblClick(Sender: TObject);
    +    procedure SectionsListBoxKeyPress(Sender: TObject; var Key: char);
    +  protected
    +    procedure DoCreate; override;
    +  public
    +
    +  end;
    +
    +function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult): TInsertMethodSectionResult;
    +function ShowEventMethodSectionDialog: TInsertMethodSectionResult;
    +
    +implementation
    +
    +{$R *.lfm}
    +
    +function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult): TInsertMethodSectionResult;
    +var
    +  Dlg: TChooseMethodSectionDialog;
    +begin
    +  Dlg := TChooseMethodSectionDialog.Create(Application);
    +  try
    +    Dlg.Caption := ACaption;
    +    Dlg.PopupMode := pmAuto;
    +    if Ord(ADefault) < Dlg.SectionsListBox.Count then
    +      Dlg.SectionsListBox.ItemIndex := Ord(ADefault)
    +    else
    +      Dlg.SectionsListBox.ItemIndex := 0;
    +    if Dlg.ShowModal = mrOK then
    +      Result := TInsertMethodSectionResult(Dlg.SectionsListBox.ItemIndex)
    +    else
    +      Result := imsrAbort;
    +  finally
    +    Dlg.Free;
    +  end;
    +end;
    +
    +function ShowEventMethodSectionDialog: TInsertMethodSectionResult;
    +begin
    +  Result := ChooseMethodSectionDialog(lisChooseClassSectionDlgForMethodCaption,
    +    EnvironmentOptions.LastEventMethodSectionPrompt);
    +  if Result <> imsrAbort then
    +    EnvironmentOptions.LastEventMethodSectionPrompt := Result;
    +end;
    +
    +{ TChooseMethodSectionDialog }
    +
    +procedure TChooseMethodSectionDialog.DoCreate;
    +begin
    +  inherited DoCreate;
    +
    +  Assert(Ord(High(TInsertMethodSectionResult)) = 4);
    +  SectionsListBox.Items.Add(lisPrivate);
    +  SectionsListBox.Items.Add(lisProtected);
    +  SectionsListBox.Items.Add(lisEMDPublic);
    +  SectionsListBox.Items.Add(lisEMDPublished);
    +end;
    +
    +procedure TChooseMethodSectionDialog.FormKeyPress(Sender: TObject;
    +  var Key: char);
    +begin
    +  if Key = #27 then
    +    ModalResult := mrCancel;
    +end;
    +
    +procedure TChooseMethodSectionDialog.SectionsListBoxDblClick(Sender: TObject);
    +begin
    +  ModalResult := mrOK;
    +end;
    +
    +procedure TChooseMethodSectionDialog.SectionsListBoxKeyPress(
    +  Sender: TObject; var Key: char);
    +begin
    +  if Key = #13 then
    +    ModalResult := mrOK;
    +end;
    +
    +initialization
    +  ShowEventMethodSectionPrompt := @ShowEventMethodSectionDialog;
    +
    +end.
    +
    Index: ide/codetoolsoptions.pas
    ===================================================================
    --- ide/codetoolsoptions.pas	(revision 50022)
    +++ ide/codetoolsoptions.pas	(working copy)
    @@ -82,6 +82,7 @@
         FForwardProcBodyInsertPolicy: TForwardProcBodyInsertPolicy;
         FKeepForwardProcOrder: boolean;
         FMethodInsertPolicy: TMethodInsertPolicy;
    +    FEventMethodSection: TInsertMethodSection;
         FKeyWordPolicy : TWordPolicy;
         FIdentifierPolicy: TWordPolicy;
         FUpdateAllMethodSignatures: boolean;
    @@ -187,6 +188,8 @@
           read FClassImplementationComments write FClassImplementationComments;
         property MethodInsertPolicy: TMethodInsertPolicy
           read FMethodInsertPolicy write FMethodInsertPolicy;
    +    property EventMethodSection: TInsertMethodSection
    +      read FEventMethodSection write FEventMethodSection;
         property KeyWordPolicy : TWordPolicy
           read FKeyWordPolicy write FKeyWordPolicy;
         property IdentifierPolicy: TWordPolicy
    @@ -459,6 +462,9 @@
         FMethodInsertPolicy:=MethodInsertPolicyNameToPolicy(XMLConfig.GetValue(
           'CodeToolsOptions/MethodInsertPolicy/Value',
           MethodInsertPolicyNames[mipClassOrder]));
    +    FEventMethodSection:=InsertMethodSectionNameToSection(XMLConfig.GetValue(
    +      'CodeToolsOptions/EventMethodSection/Value',
    +      InsertMethodSectionNames[DefaultEventMethodSection]));
         FKeyWordPolicy:=WordPolicyNameToPolicy(XMLConfig.GetValue(
           'CodeToolsOptions/KeyWordPolicy/Value',
           WordPolicyNames[wpLowerCase]));
    @@ -614,6 +620,9 @@
         XMLConfig.SetDeleteValue('CodeToolsOptions/MethodInsertPolicy/Value',
           MethodInsertPolicyNames[FMethodInsertPolicy],
           MethodInsertPolicyNames[mipClassOrder]);
    +    XMLConfig.SetDeleteValue('CodeToolsOptions/EventMethodSection/Value',
    +      InsertMethodSectionNames[FEventMethodSection],
    +      InsertMethodSectionNames[DefaultEventMethodSection]);
         XMLConfig.SetDeleteValue('CodeToolsOptions/KeyWordPolicy/Value',
           WordPolicyNames[FKeyWordPolicy],
           WordPolicyNames[wpLowerCase]);
    @@ -779,6 +788,7 @@
         FClassHeaderComments:=CodeToolsOpts.ClassHeaderComments;
         FClassImplementationComments:=CodeToolsOpts.ClassImplementationComments;
         FMethodInsertPolicy:=CodeToolsOpts.FMethodInsertPolicy;
    +    FEventMethodSection:=CodeToolsOpts.FEventMethodSection;
         FKeyWordPolicy:=CodeToolsOpts.FKeyWordPolicy;
         FIdentifierPolicy:=CodeToolsOpts.FIdentifierPolicy;
         FDoNotSplitLineInFront:=CodeToolsOpts.FDoNotSplitLineInFront;
    @@ -839,6 +849,7 @@
       FClassHeaderComments:=true;
       FClassImplementationComments:=true;
       FMethodInsertPolicy:=mipClassOrder;
    +  FEventMethodSection:=DefaultEventMethodSection;
       FKeyWordPolicy:=wpLowerCase;
       FIdentifierPolicy:=wpNone;
       FDoNotSplitLineInFront:=DefaultDoNotSplitLineInFront;
    @@ -917,6 +928,7 @@
         and (FClassHeaderComments=CodeToolsOpts.ClassHeaderComments)
         and (FClassImplementationComments=CodeToolsOpts.ClassImplementationComments)
         and (FMethodInsertPolicy=CodeToolsOpts.FMethodInsertPolicy)
    +    and (FEventMethodSection=CodeToolsOpts.FEventMethodSection)
         and (FKeyWordPolicy=CodeToolsOpts.FKeyWordPolicy)
         and (FIdentifierPolicy=CodeToolsOpts.FIdentifierPolicy)
         and (FDoNotSplitLineInFront=CodeToolsOpts.FDoNotSplitLineInFront)
    @@ -1037,6 +1049,7 @@
         Beauty.ClassHeaderComments:=ClassHeaderComments;
         Beauty.ClassImplementationComments:=ClassImplementationComments;
         Beauty.MethodInsertPolicy:=MethodInsertPolicy;
    +    Beauty.EventMethodSection:=EventMethodSection;
         Beauty.KeyWordPolicy:=KeyWordPolicy;
         Beauty.IdentifierPolicy:=IdentifierPolicy;
         Beauty.SetupWordPolicyExceptions(WordPolicyExceptions);
    Index: ide/environmentopts.pp
    ===================================================================
    --- ide/environmentopts.pp	(revision 50022)
    +++ ide/environmentopts.pp	(working copy)
    @@ -39,7 +39,7 @@
     {$endif}
       Classes, SysUtils, TypInfo, contnrs, Graphics, Controls, Forms, Dialogs,
       LCLProc, FileProcs, LazFileUtils, LazFileCache, LazConfigStorage,
    -  Laz2_XMLCfg, LazUTF8,
    +  Laz2_XMLCfg, LazUTF8, SourceChanger,
       // IDEIntf
       ProjectIntf, ObjectInspector, IDEWindowIntf, IDEOptionsIntf,
       ComponentReg, IDEExternToolIntf, MacroDefIntf, DbgIntfDebuggerBase,
    @@ -499,6 +499,9 @@
         // Prevent repopulating Recent project files menu with example projects if it was already cleared up.
         FAlreadyPopulatedRecentFiles : Boolean;
     
    +    //other recent settings
    +    FLastEventMethodSectionPrompt: TInsertMethodSectionResult;
    +
         // backup
         FBackupInfoProjectFiles: TBackupInfo;
         FBackupInfoOtherFiles: TBackupInfo;
    @@ -752,6 +755,10 @@
                                                                     write FMultipleInstances;
         property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter;
     
    +    // other recent settings
    +    property LastEventMethodSectionPrompt: TInsertMethodSectionResult
    +      read FLastEventMethodSectionPrompt write FLastEventMethodSectionPrompt;
    +
         // backup
         property BackupInfoProjectFiles: TBackupInfo read FBackupInfoProjectFiles
                                                      write FBackupInfoProjectFiles;
    @@ -1347,6 +1354,9 @@
       FOpenLastProjectAtStart:=true;
       FMultipleInstances:=DefaultIDEMultipleInstancesOption;
     
    +  // other recent settings
    +  FLastEventMethodSectionPrompt:=InsertMethodSectionToResult[DefaultEventMethodSection];
    +
       // backup
       with FBackupInfoProjectFiles do begin
         BackupType:=bakSameName;
    @@ -1745,6 +1755,11 @@
     
         FAlreadyPopulatedRecentFiles := FXMLCfg.GetValue(Path+'Recent/AlreadyPopulated', false);
     
    +    // other recent settings
    +    FLastEventMethodSectionPrompt:=InsertMethodSectionResultNameToSection(FXMLCfg.GetValue(
    +      'Recent/EventMethodSectionPrompt/Value',
    +      InsertMethodSectionNames[DefaultEventMethodSection]));
    +
         // Add example projects to an empty project list if examples have write access
         if (FRecentProjectFiles.count=0) and (not FAlreadyPopulatedRecentFiles) then begin
           AddRecentProjectInitial('examples/jpeg/',          'jpegexample.lpi');
    @@ -2073,6 +2088,11 @@
     
         FXMLCfg.SetDeleteValue(Path+'Recent/AlreadyPopulated', FAlreadyPopulatedRecentFiles, false);
     
    +    // other recent settings
    +    FXMLCfg.SetDeleteValue('Recent/EventMethodSectionPrompt/Value',
    +      InsertMethodSectionResultNames[FLastEventMethodSectionPrompt],
    +      InsertMethodSectionResultNames[InsertMethodSectionToResult[DefaultEventMethodSection]]);
    +
         // external tools
         fExternalUserTools.Save(FConfigStore,Path+'ExternalTools/');
         FXMLCfg.SetDeleteValue(Path+'ExternalTools/MaxInParallel',FMaxExtToolsInParallel,0);
    Index: ide/frames/codetools_codecreation_options.lfm
    ===================================================================
    --- ide/frames/codetools_codecreation_options.lfm	(revision 50022)
    +++ ide/frames/codetools_codecreation_options.lfm	(working copy)
    @@ -8,76 +8,27 @@
       TabOrder = 0
       Visible = False
       DesignLeft = 322
    -  DesignTop = 184
    -  object ForwardProcsInsertPolicyRadioGroup: TRadioGroup
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = Owner
    -    AnchorSideRight.Control = Owner
    -    AnchorSideRight.Side = asrBottom
    -    Left = 6
    -    Height = 100
    -    Top = 6
    -    Width = 554
    -    Anchors = [akTop, akLeft, akRight]
    -    AutoFill = True
    -    BorderSpacing.Around = 6
    -    Caption = 'ForwardProcsInsertPolicyRadioGroup'
    -    ChildSizing.LeftRightSpacing = 6
    -    ChildSizing.TopBottomSpacing = 6
    -    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
    -    ChildSizing.EnlargeVertical = crsHomogenousChildResize
    -    ChildSizing.ShrinkHorizontal = crsScaleChilds
    -    ChildSizing.ShrinkVertical = crsScaleChilds
    -    ChildSizing.Layout = cclLeftToRightThenTopToBottom
    -    ChildSizing.ControlsPerLine = 1
    -    TabOrder = 0
    -  end
    +  DesignTop = 167
       object ForwardProcsKeepOrderCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = ForwardProcsInsertPolicyRadioGroup
    +    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 112
    +    Top = 45
         Width = 200
    -    BorderSpacing.Around = 6
    +    BorderSpacing.Left = 6
    +    BorderSpacing.Top = 6
         Caption = 'ForwardProcsKeepOrderCheckBox'
         TabOrder = 1
       end
    -  object UsesInsertPolicyRadioGroup: TRadioGroup
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
    -    AnchorSideTop.Side = asrBottom
    -    AnchorSideRight.Control = Owner
    -    AnchorSideRight.Side = asrBottom
    -    Left = 6
    -    Height = 100
    -    Top = 143
    -    Width = 554
    -    Anchors = [akTop, akLeft, akRight]
    -    AutoFill = True
    -    AutoSize = True
    -    BorderSpacing.Top = 6
    -    BorderSpacing.Around = 6
    -    Caption = 'UsesInsertPolicyRadioGroup'
    -    ChildSizing.LeftRightSpacing = 6
    -    ChildSizing.TopBottomSpacing = 6
    -    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
    -    ChildSizing.EnlargeVertical = crsHomogenousChildResize
    -    ChildSizing.ShrinkHorizontal = crsScaleChilds
    -    ChildSizing.ShrinkVertical = crsScaleChilds
    -    ChildSizing.Layout = cclLeftToRightThenTopToBottom
    -    ChildSizing.ControlsPerLine = 1
    -    Constraints.MinHeight = 100
    -    TabOrder = 2
    -  end
       object UpdateMultiProcSignaturesCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = UsesInsertPolicyRadioGroup
    +    AnchorSideTop.Control = UsesInsertPolicyComboBox
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 249
    +    Top = 99
         Width = 217
         BorderSpacing.Left = 6
         BorderSpacing.Top = 6
    @@ -90,7 +41,7 @@
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 268
    +    Top = 118
         Width = 244
         BorderSpacing.Left = 6
         Caption = 'UpdateOtherProcSignaturesCaseCheckBox'
    @@ -102,7 +53,7 @@
         AnchorSideTop.Side = asrCenter
         Left = 6
         Height = 15
    -    Top = 316
    +    Top = 195
         Width = 95
         Caption = 'TemplateFileLabel'
         ParentColor = False
    @@ -110,16 +61,17 @@
       object TemplateFileEdit: TEdit
         AnchorSideLeft.Control = TemplateFileLabel
         AnchorSideLeft.Side = asrBottom
    -    AnchorSideTop.Control = GroupLocalVariablesCheckBox
    +    AnchorSideTop.Control = EventMethodSectionComboBox
         AnchorSideTop.Side = asrBottom
         AnchorSideRight.Control = TemplateFileBrowseButton
    -    Left = 101
    +    Left = 107
         Height = 23
    -    Top = 312
    -    Width = 424
    +    Top = 191
    +    Width = 418
         Anchors = [akTop, akLeft, akRight]
    +    BorderSpacing.Left = 6
         BorderSpacing.Top = 6
    -    TabOrder = 6
    +    TabOrder = 7
         Text = 'TemplateFileEdit'
       end
       object TemplateFileBrowseButton: TButton
    @@ -130,7 +82,7 @@
         AnchorSideBottom.Side = asrBottom
         Left = 525
         Height = 23
    -    Top = 312
    +    Top = 191
         Width = 35
         Anchors = [akTop, akRight, akBottom]
         AutoSize = True
    @@ -137,7 +89,7 @@
         BorderSpacing.Right = 6
         Caption = '...'
         OnClick = TemplateFileBrowseButtonClick
    -    TabOrder = 7
    +    TabOrder = 8
       end
       object GroupLocalVariablesCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    @@ -145,10 +97,88 @@
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 287
    +    Top = 137
         Width = 180
         BorderSpacing.Left = 6
         Caption = 'GroupLocalVariablesCheckBox'
         TabOrder = 5
       end
    +  object ForwardProcsInsertPolicyComboBox: TComboBox
    +    AnchorSideLeft.Control = ForwardProcsInsertPolicyLabel
    +    AnchorSideLeft.Side = asrBottom
    +    Left = 173
    +    Height = 23
    +    Top = 16
    +    Width = 170
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 0
    +  end
    +  object ForwardProcsInsertPolicyLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = ForwardProcsInsertPolicyComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 20
    +    Width = 161
    +    BorderSpacing.Around = 6
    +    Caption = 'ForwardProcsInsertPolicyLabel'
    +    ParentColor = False
    +  end
    +  object UsesInsertPolicyLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = UsesInsertPolicyComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = UsesInsertPolicyComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 74
    +    Width = 113
    +    BorderSpacing.Around = 6
    +    Caption = 'UsesInsertPolicyLabel'
    +    ParentColor = False
    +  end
    +  object UsesInsertPolicyComboBox: TComboBox
    +    AnchorSideLeft.Control = UsesInsertPolicyLabel
    +    AnchorSideLeft.Side = asrBottom
    +    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
    +    AnchorSideTop.Side = asrBottom
    +    Left = 125
    +    Height = 23
    +    Top = 70
    +    Width = 170
    +    BorderSpacing.Top = 6
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 2
    +  end
    +  object EventMethodSectionLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = EventMethodSectionComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = EventMethodSectionComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 166
    +    Width = 138
    +    BorderSpacing.Around = 6
    +    Caption = 'EventMethodSectionLabel'
    +    ParentColor = False
    +  end
    +  object EventMethodSectionComboBox: TComboBox
    +    AnchorSideLeft.Control = EventMethodSectionLabel
    +    AnchorSideLeft.Side = asrBottom
    +    AnchorSideTop.Control = GroupLocalVariablesCheckBox
    +    AnchorSideTop.Side = asrBottom
    +    Left = 150
    +    Height = 23
    +    Top = 162
    +    Width = 170
    +    BorderSpacing.Top = 6
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 6
    +  end
     end
    Index: ide/frames/codetools_codecreation_options.pas
    ===================================================================
    --- ide/frames/codetools_codecreation_options.pas	(revision 50022)
    +++ ide/frames/codetools_codecreation_options.pas	(working copy)
    @@ -34,8 +34,12 @@
       { TCodetoolsCodeCreationOptionsFrame }
     
       TCodetoolsCodeCreationOptionsFrame = class(TAbstractIDEOptionsEditor)
    -    ForwardProcsInsertPolicyRadioGroup: TRadioGroup;
    +    ForwardProcsInsertPolicyComboBox: TComboBox;
    +    UsesInsertPolicyComboBox: TComboBox;
         ForwardProcsKeepOrderCheckBox: TCheckBox;
    +    ForwardProcsInsertPolicyLabel: TLabel;
    +    EventMethodSectionComboBox: TComboBox;
    +    UsesInsertPolicyLabel: TLabel;
         TemplateFileBrowseButton: TButton;
         TemplateFileEdit: TEdit;
         TemplateFileLabel: TLabel;
    @@ -42,7 +46,7 @@
         UpdateMultiProcSignaturesCheckBox: TCheckBox;
         UpdateOtherProcSignaturesCaseCheckBox: TCheckBox;
         GroupLocalVariablesCheckBox: TCheckBox;
    -    UsesInsertPolicyRadioGroup: TRadioGroup;
    +    EventMethodSectionLabel: TLabel;
         procedure TemplateFileBrowseButtonClick(Sender: TObject);
       private
       public
    @@ -87,8 +91,8 @@
     procedure TCodetoolsCodeCreationOptionsFrame.Setup(
       ADialog: TAbstractOptionsEditorDialog);
     begin
    -  with ForwardProcsInsertPolicyRadioGroup do begin
    -    Caption:=dlgForwardProcsInsertPolicy;
    +  ForwardProcsInsertPolicyLabel.Caption:=dlgForwardProcsInsertPolicy;
    +  with ForwardProcsInsertPolicyComboBox do begin
         with Items do begin
           BeginUpdate;
           Add(dlgLast);
    @@ -100,8 +104,8 @@
     
       ForwardProcsKeepOrderCheckBox.Caption:=dlgForwardProcsKeepOrder;
     
    -  with UsesInsertPolicyRadioGroup do begin
    -    Caption:=lisNewUnitsAreAddedToUsesSections;
    +  UsesInsertPolicyLabel.Caption:=lisNewUnitsAreAddedToUsesSections;
    +  with UsesInsertPolicyComboBox do begin
         with Items do begin
           BeginUpdate;
           Add(lisFirst);
    @@ -113,6 +117,20 @@
         end;
       end;
     
    +  EventMethodSectionLabel.Caption:=lisEventMethodSectionLabel;
    +  with EventMethodSectionComboBox do begin
    +    Assert(Ord(High(TInsertMethodSection)) = 4);
    +    with Items do begin
    +      BeginUpdate;
    +      Add(lisPrivate);
    +      Add(lisProtected);
    +      Add(lisEMDPublic);
    +      Add(lisEMDPublished);
    +      Add(lisPromptForValue);
    +      EndUpdate;
    +    end;
    +  end;
    +
       UpdateMultiProcSignaturesCheckBox.Caption:=
         lisCTOUpdateMultipleProcedureSignatures;
       UpdateOtherProcSignaturesCaseCheckBox.Caption:=
    @@ -134,24 +152,25 @@
       with AOptions as TCodetoolsOptions do
       begin
         case ForwardProcBodyInsertPolicy of
    -      fpipLast: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=0;
    -      fpipInFrontOfMethods: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=1;
    +      fpipLast: ForwardProcsInsertPolicyComboBox.ItemIndex:=0;
    +      fpipInFrontOfMethods: ForwardProcsInsertPolicyComboBox.ItemIndex:=1;
         else
           // fpipBehindMethods
    -      ForwardProcsInsertPolicyRadioGroup.ItemIndex:=2;
    +      ForwardProcsInsertPolicyComboBox.ItemIndex:=2;
         end;
     
         ForwardProcsKeepOrderCheckBox.Checked := KeepForwardProcOrder;
     
         case UsesInsertPolicy of
    -    uipFirst:             UsesInsertPolicyRadioGroup.ItemIndex:=0;
    -    uipInFrontOfRelated:  UsesInsertPolicyRadioGroup.ItemIndex:=1;
    -    uipBehindRelated:     UsesInsertPolicyRadioGroup.ItemIndex:=2;
    -    uipLast:              UsesInsertPolicyRadioGroup.ItemIndex:=3;
    +    uipFirst:             UsesInsertPolicyComboBox.ItemIndex:=0;
    +    uipInFrontOfRelated:  UsesInsertPolicyComboBox.ItemIndex:=1;
    +    uipBehindRelated:     UsesInsertPolicyComboBox.ItemIndex:=2;
    +    uipLast:              UsesInsertPolicyComboBox.ItemIndex:=3;
         else
           //uipAlphabetically:
    -                          UsesInsertPolicyRadioGroup.ItemIndex:=4;
    +                          UsesInsertPolicyComboBox.ItemIndex:=4;
         end;
    +    EventMethodSectionComboBox.ItemIndex := Ord(EventMethodSection);
     
         UpdateMultiProcSignaturesCheckBox.Checked:=UpdateMultiProcSignatures;
         UpdateOtherProcSignaturesCaseCheckBox.Checked:=UpdateOtherProcSignaturesCase;
    @@ -166,7 +185,7 @@
     begin
       with AOptions as TCodetoolsOptions do
       begin
    -    case ForwardProcsInsertPolicyRadioGroup.ItemIndex of
    +    case ForwardProcsInsertPolicyComboBox.ItemIndex of
           0: ForwardProcBodyInsertPolicy := fpipLast;
           1: ForwardProcBodyInsertPolicy := fpipInFrontOfMethods;
           2: ForwardProcBodyInsertPolicy := fpipBehindMethods;
    @@ -174,7 +193,7 @@
     
         KeepForwardProcOrder := ForwardProcsKeepOrderCheckBox.Checked;
     
    -    case UsesInsertPolicyRadioGroup.ItemIndex of
    +    case UsesInsertPolicyComboBox.ItemIndex of
         0: UsesInsertPolicy:=uipFirst;
         1: UsesInsertPolicy:=uipInFrontOfRelated;
         2: UsesInsertPolicy:=uipBehindRelated;
    @@ -182,6 +201,8 @@
         else UsesInsertPolicy:=uipAlphabetically;
         end;
     
    +    EventMethodSection := TInsertMethodSection(EventMethodSectionComboBox.ItemIndex);
    +
         UpdateMultiProcSignatures:=UpdateMultiProcSignaturesCheckBox.Checked;
         UpdateOtherProcSignaturesCase:=UpdateOtherProcSignaturesCaseCheckBox.Checked;
         GroupLocalVariables:=GroupLocalVariablesCheckBox.Checked;
    Index: ide/lazarusidestrconsts.pas
    ===================================================================
    --- ide/lazarusidestrconsts.pas	(revision 50022)
    +++ ide/lazarusidestrconsts.pas	(working copy)
    @@ -3639,6 +3639,10 @@
       lisAllBlocksLooksOk = 'All blocks look ok.';
       lisTheApplicationBundleWasCreatedFor = 'The Application Bundle was created for "%s"';
     
    +  //codetools ChooseClassSectionDlg
    +  lisChooseClassSectionDlgForMethodCaption = 'Insert new method to section';
    +  lisEventMethodSectionLabel = 'Insert new event methods to section';
    +
       // diff dialog
       lisDiffDlgFile1 = 'File1';
       lisDiffDlgOnlySelection = 'Only selection';
    Index: ide/main.pp
    ===================================================================
    --- ide/main.pp	(revision 50022)
    +++ ide/main.pp	(working copy)
    @@ -69,7 +69,7 @@
       // CodeTools
       FileProcs, FindDeclarationTool, LinkScanner, BasicCodeTools, CodeToolsStructs,
       CodeToolManager, CodeCache, DefineTemplates, KeywordFuncLists, CodeTree,
    -  StdCodeTools,
    +  StdCodeTools, ChooseMethodSectionDlg,
       // LazUtils
       // use lazutf8, lazfileutils and lazfilecache after FileProcs and FileUtil
       FileUtil, LazFileUtils, LazFileCache, LazUTF8, LazUTF8Classes, UTF8Process,
    
  • ct-event-method-section-2.patch (35,716 bytes)
    Index: components/codetools/codecompletiontool.pas
    ===================================================================
    --- components/codetools/codecompletiontool.pas	(revision 50022)
    +++ components/codetools/codecompletiontool.pas	(working copy)
    @@ -124,6 +124,13 @@
         ctnClassPublished  // pcsPublished
       );
     
    +  InsertMethodSectionToNewClassPart: array[TInsertMethodSectionResult] of TNewClassPart = (
    +    ncpPrivateProcs,
    +    ncpProtectedProcs,
    +    ncpPublicProcs,
    +    ncpPublishedProcs
    +  );
    +
     type
       TCodeCompletionCodeTool = class;
     
    @@ -207,10 +214,10 @@
         procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer;
                               out NewPos: TCodeXYPosition; out NewTopLine: integer);
         procedure AddNeededUnitToMainUsesSection(AnUnitName: PChar);
    -    procedure AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
    +    function AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
                       const AnEventName: string; ProcContext: TFindContext; out
                       MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
    -                  SourceChangeCache: TSourceChangeCache);
    +                  SourceChangeCache: TSourceChangeCache): Boolean;
         procedure AddProcedureCompatibleToProcType(
                       const NewProcName: string; ProcContext: TFindContext; out
                       MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
    @@ -1363,14 +1370,17 @@
       Pointer(s):=nil;
     end;
     
    -procedure TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
    +function TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
       AClassNode: TCodeTreeNode; const AnEventName: string;
       ProcContext: TFindContext; out MethodDefinition: string; out
    -  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
    +  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache
    +  ): Boolean;
     var
       CleanMethodDefinition: string;
       Beauty: TBeautifyCodeOptions;
    +  MethodSection: TInsertMethodSectionResult;
     begin
    +  Result := False;
       MethodDefinition:='';
       MethodAttr:=[];
     
    @@ -1402,8 +1412,10 @@
       {$ENDIF}
       if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
         // insert method definition into class
    +    if not Beauty.GetRealEventMethodSection(MethodSection) then
    +      Exit;
         AddClassInsertion(CleanMethodDefinition, MethodDefinition,
    -                      AnEventName, ncpPublishedProcs);
    +                      AnEventName, InsertMethodSectionToNewClassPart[MethodSection]);
       end;
       MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition,
                        ExtractClassName(AClassNode,false,true), AnEventName);
    @@ -1413,6 +1425,7 @@
       // insert all missing proc bodies
       if not CreateMissingClassProcBodies(false) then
         RaiseException(ctsErrorDuringCreationOfNewProcBodies);
    +  Result := True;
     end;
     
     procedure TCodeCompletionCodeTool.AddProcedureCompatibleToProcType(
    @@ -2145,8 +2158,10 @@
             if FullEventName='' then exit;
     
             // add published method and method body and right side of assignment
    -        AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
    -          AMethodDefinition,AMethodAttr,SourceChangeCache);
    +        if not AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
    +          AMethodDefinition,AMethodAttr,SourceChangeCache)
    +        then
    +          Exit;
             if not CompleteAssignment(FullEventName,AssignmentOperator,
               AddrOperatorPos,SemicolonPos,UserEventAtom)
             then
    @@ -2293,8 +2308,10 @@
         ProcContext:=CreateFindContext(TypeTool,TypeNode);
     
         // create new method
    -    AddMethodCompatibleToProcType(AClassNode,Identifier,
    -      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache);
    +    if not AddMethodCompatibleToProcType(AClassNode,Identifier,
    +      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache)
    +    then
    +      Exit;
     
         // apply the changes
         if not SourceChangeCache.Apply then
    Index: components/codetools/sourcechanger.pas
    ===================================================================
    --- components/codetools/sourcechanger.pas	(revision 50022)
    +++ components/codetools/sourcechanger.pas	(working copy)
    @@ -59,6 +59,21 @@
         mipClassOrder      // try to copy the order of the class
         );
         
    +  //where to add created methods from event assignment: "OnClick := @MyNewProc;"
    +  TInsertMethodSection = (
    +    imsPrivate,
    +    imsProtected,
    +    imsPublic,
    +    imsPublished,
    +    imsPrompt //show dialog prompt
    +    );
    +  TInsertMethodSectionResult = (
    +    imsrPrivate,
    +    imsrProtected,
    +    imsrPublic,
    +    imsrPublished
    +  );
    +
       TForwardProcBodyInsertPolicy = (
         fpipLast,
         fpipInFrontOfMethods,
    @@ -90,7 +105,16 @@
     
     const
       DefaultUsesInsertPolicy = uipBehindRelated;
    +  DefaultEventMethodSection = imsPrompt;
     
    +  InsertMethodSectionToResult: array[TInsertMethodSection] of TInsertMethodSectionResult = (
    +    imsrPrivate,
    +    imsrProtected,
    +    imsrPublic,
    +    imsrPublished,
    +    imsrPrivate
    +    );
    +
     type
       TWordPolicyException = class
         Word: string;
    @@ -157,6 +181,7 @@
         ClassPartInsertPolicy: TClassPartInsertPolicy;
         MixMethodsAndProperties: boolean;
         MethodInsertPolicy: TMethodInsertPolicy;
    +    EventMethodSection: TInsertMethodSection;
         PropertyReadIdentPrefix: string;
         PropertyWriteIdentPrefix: string;
         PropertyStoredIdentPostfix: string;
    @@ -169,6 +194,7 @@
         
         NestedComments: boolean;
     
    +    function GetRealEventMethodSection(out Section: TInsertMethodSectionResult): Boolean; //in case of imsPrompt show a dialog and return a "normal" section; returns true if OK, false if canceled
         function GetIndentStr(TheIndent: integer): string; inline;
         function GetLineIndent(const Source: string; Position: integer): integer; inline;
         procedure SetupWordPolicyExceptions(ws: TStrings);
    @@ -328,7 +354,15 @@
       MethodInsertPolicyNames: array[TMethodInsertPolicy] of shortstring = (
           'Alphabetically', 'Last', 'ClassOrder'
         );
    -    
    +
    +  InsertMethodSectionNames: array[TInsertMethodSection] of ShortString = (
    +    'Private', 'Protected', 'Public', 'Published', 'Prompt'
    +    );
    +
    +  InsertMethodSectionResultNames: array[TInsertMethodSectionResult] of ShortString = (
    +    'Private', 'Protected', 'Public', 'Published'
    +    );
    +
       ForwardProcBodyInsertPolicyNames: array[TForwardProcBodyInsertPolicy] of
         shortstring = (
           'Last',
    @@ -352,11 +386,18 @@
       DefaultDoNotInsertSpaceInFront: TAtomTypes = [];
       DefaultDoNotInsertSpaceAfter: TAtomTypes = [atDirectiveStart];
     
    +type
    +  TShowEventMethodSectionPromptFunc = function(out Section: TInsertMethodSectionResult): Boolean;
    +var
    +  ShowEventMethodSectionPrompt: TShowEventMethodSectionPromptFunc = nil;
    +
     function AtomTypeNameToType(const s: string): TAtomType;
     function AtomTypesToStr(const AtomTypes: TAtomTypes): string;
     function WordPolicyNameToPolicy(const s: string): TWordPolicy;
     function ClassPartPolicyNameToPolicy(const s: string): TClassPartInsertPolicy;
     function MethodInsertPolicyNameToPolicy(const s: string): TMethodInsertPolicy;
    +function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
    +function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
     function ForwardProcBodyInsertPolicyNameToPolicy(
       const s: string): TForwardProcBodyInsertPolicy;
     function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
    @@ -409,6 +450,20 @@
       Result:=mipLast;
     end;
     
    +function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
    +begin
    +  for Result:=Low(TInsertMethodSection) to High(TInsertMethodSection) do
    +    if SysUtils.CompareText(InsertMethodSectionNames[Result],s)=0 then exit;
    +  Result:=DefaultEventMethodSection;
    +end;
    +
    +function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
    +begin
    +  for Result:=Low(TInsertMethodSectionResult) to High(TInsertMethodSectionResult) do
    +    if SysUtils.CompareText(InsertMethodSectionResultNames[Result],s)=0 then exit;
    +  Result:=imsrPrivate;
    +end;
    +
     function ForwardProcBodyInsertPolicyNameToPolicy(
       const s: string): TForwardProcBodyInsertPolicy;
     begin
    @@ -1259,6 +1314,7 @@
       UpdateOtherProcSignaturesCase:=true;
       GroupLocalVariables:=true;
       MethodInsertPolicy:=mipClassOrder;
    +  EventMethodSection:=DefaultEventMethodSection;
       ForwardProcBodyInsertPolicy:=fpipBehindMethods;
       KeepForwardProcOrder:=true;
       ClassHeaderComments:=true;
    @@ -1685,6 +1741,21 @@
         Result:=false;
     end;
     
    +function TBeautifyCodeOptions.GetRealEventMethodSection(out
    +  Section: TInsertMethodSectionResult): Boolean;
    +begin
    +  Result := True;
    +  if (EventMethodSection <> imsPrompt) then
    +    Section := InsertMethodSectionToResult[EventMethodSection]
    +  else
    +  begin
    +    if Assigned(ShowEventMethodSectionPrompt) then
    +      Result := ShowEventMethodSectionPrompt(Section)
    +    else
    +      Section := InsertMethodSectionToResult[DefaultEventMethodSection];
    +  end;
    +end;
    +
     procedure TBeautifyCodeOptions.SetupWordPolicyExceptions(ws: TStrings);
     begin
       if Assigned(WordExceptions) then WordExceptions.Free;
    Index: ide/choosemethodsectiondlg.lfm
    ===================================================================
    --- ide/choosemethodsectiondlg.lfm	(nonexistent)
    +++ ide/choosemethodsectiondlg.lfm	(working copy)
    @@ -0,0 +1,45 @@
    +object ChooseMethodSectionDialog: TChooseMethodSectionDialog
    +  Left = 460
    +  Height = 177
    +  Top = 220
    +  Width = 252
    +  BorderStyle = bsDialog
    +  Caption = 'ChooseMethodSectionDialog'
    +  ClientHeight = 177
    +  ClientWidth = 252
    +  KeyPreview = True
    +  OnKeyPress = FormKeyPress
    +  Position = poDesktopCenter
    +  LCLVersion = '1.5'
    +  object SectionsListBox: TListBox
    +    Left = 10
    +    Height = 117
    +    Top = 10
    +    Width = 232
    +    Align = alClient
    +    BorderSpacing.Left = 10
    +    BorderSpacing.Top = 10
    +    BorderSpacing.Right = 10
    +    BorderSpacing.Bottom = 10
    +    ItemHeight = 0
    +    OnDblClick = SectionsListBoxDblClick
    +    OnKeyPress = SectionsListBoxKeyPress
    +    TabOrder = 0
    +  end
    +  object ButtonPanel: TButtonPanel
    +    Left = 6
    +    Height = 34
    +    Top = 137
    +    Width = 240
    +    OKButton.Name = 'OKButton'
    +    OKButton.DefaultCaption = True
    +    HelpButton.Name = 'HelpButton'
    +    HelpButton.DefaultCaption = True
    +    CloseButton.Name = 'CloseButton'
    +    CloseButton.DefaultCaption = True
    +    CancelButton.Name = 'CancelButton'
    +    CancelButton.DefaultCaption = True
    +    TabOrder = 1
    +    ShowButtons = [pbOK]
    +  end
    +end
    Index: ide/choosemethodsectiondlg.pas
    ===================================================================
    --- ide/choosemethodsectiondlg.pas	(nonexistent)
    +++ ide/choosemethodsectiondlg.pas	(working copy)
    @@ -0,0 +1,127 @@
    +{
    + ***************************************************************************
    + *                                                                         *
    + *   This source is free software; you can redistribute it and/or modify   *
    + *   it under the terms of the GNU General Public License as published by  *
    + *   the Free Software Foundation; either version 2 of the License, or     *
    + *   (at your option) any later version.                                   *
    + *                                                                         *
    + *   This code 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.  See the GNU     *
    + *   General Public License for more details.                              *
    + *                                                                         *
    + *   A copy of the GNU General Public License is available on the World    *
    + *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
    + *   obtain it by writing to the Free Software Foundation,                 *
    + *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
    + *                                                                         *
    + ***************************************************************************
    +
    +  Author: Ondrej Pokorny
    +
    +  Abstract:
    +    A simple dialog to select class section.
    +}
    +unit ChooseMethodSectionDlg;
    +
    +{$mode objfpc}{$H+}
    +
    +interface
    +
    +uses
    +  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
    +  ButtonPanel, SourceChanger, LazarusIDEStrConsts, EnvironmentOpts;
    +
    +type
    +  //this dialog can easily be reused.
    +  //for now it is used only in the method event assignment code creation
    +
    +  TChooseMethodSectionDialog = class(TForm)
    +    ButtonPanel: TButtonPanel;
    +    SectionsListBox: TListBox;
    +    procedure FormKeyPress(Sender: TObject; var Key: char);
    +    procedure SectionsListBoxDblClick(Sender: TObject);
    +    procedure SectionsListBoxKeyPress(Sender: TObject; var Key: char);
    +  protected
    +    procedure DoCreate; override;
    +  public
    +
    +  end;
    +
    +function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult;
    +  out Section: TInsertMethodSectionResult): Boolean;
    +function ShowEventMethodSectionDialog(out Section: TInsertMethodSectionResult): Boolean;
    +
    +implementation
    +
    +{$R *.lfm}
    +
    +function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult;
    +  out Section: TInsertMethodSectionResult): Boolean;
    +var
    +  Dlg: TChooseMethodSectionDialog;
    +begin
    +  Dlg := TChooseMethodSectionDialog.Create(Application);
    +  try
    +    Dlg.Caption := ACaption;
    +    Dlg.PopupMode := pmAuto;
    +    if Ord(ADefault) < Dlg.SectionsListBox.Count then
    +      Dlg.SectionsListBox.ItemIndex := Ord(ADefault)
    +    else
    +      Dlg.SectionsListBox.ItemIndex := 0;
    +    Result := Dlg.ShowModal = mrOK;
    +    if Result then
    +      Section := TInsertMethodSectionResult(Dlg.SectionsListBox.ItemIndex)
    +    else
    +      Section := imsrPrivate;
    +  finally
    +    Dlg.Free;
    +  end;
    +end;
    +
    +function ShowEventMethodSectionDialog(out Section: TInsertMethodSectionResult): Boolean;
    +begin
    +  Result := ChooseMethodSectionDialog(lisChooseClassSectionDlgForMethodCaption,
    +    EnvironmentOptions.LastEventMethodSectionPrompt, Section);
    +  if Result then
    +    EnvironmentOptions.LastEventMethodSectionPrompt := Section;
    +end;
    +
    +{ TChooseMethodSectionDialog }
    +
    +procedure TChooseMethodSectionDialog.DoCreate;
    +begin
    +  inherited DoCreate;
    +
    +  Assert(Ord(High(TInsertMethodSectionResult)) = 3,  'TChooseMethodSectionDialog.DoCreate: High(TInsertMethodSectionResult) <> 3');
    +  SectionsListBox.Items.Add(lisPrivate);
    +  SectionsListBox.Items.Add(lisProtected);
    +  SectionsListBox.Items.Add(lisEMDPublic);
    +  SectionsListBox.Items.Add(lisEMDPublished);
    +end;
    +
    +procedure TChooseMethodSectionDialog.FormKeyPress(Sender: TObject;
    +  var Key: char);
    +begin
    +  if Key = #27 then
    +    ModalResult := mrCancel;
    +end;
    +
    +procedure TChooseMethodSectionDialog.SectionsListBoxDblClick(Sender: TObject);
    +begin
    +  ModalResult := mrOK;
    +end;
    +
    +procedure TChooseMethodSectionDialog.SectionsListBoxKeyPress(
    +  Sender: TObject; var Key: char);
    +begin
    +  if Key = #13 then
    +    ModalResult := mrOK;
    +end;
    +
    +initialization
    +  ShowEventMethodSectionPrompt := @ShowEventMethodSectionDialog;
    +
    +end.
    +
    Index: ide/codetoolsoptions.pas
    ===================================================================
    --- ide/codetoolsoptions.pas	(revision 50022)
    +++ ide/codetoolsoptions.pas	(working copy)
    @@ -82,6 +82,7 @@
         FForwardProcBodyInsertPolicy: TForwardProcBodyInsertPolicy;
         FKeepForwardProcOrder: boolean;
         FMethodInsertPolicy: TMethodInsertPolicy;
    +    FEventMethodSection: TInsertMethodSection;
         FKeyWordPolicy : TWordPolicy;
         FIdentifierPolicy: TWordPolicy;
         FUpdateAllMethodSignatures: boolean;
    @@ -187,6 +188,8 @@
           read FClassImplementationComments write FClassImplementationComments;
         property MethodInsertPolicy: TMethodInsertPolicy
           read FMethodInsertPolicy write FMethodInsertPolicy;
    +    property EventMethodSection: TInsertMethodSection
    +      read FEventMethodSection write FEventMethodSection;
         property KeyWordPolicy : TWordPolicy
           read FKeyWordPolicy write FKeyWordPolicy;
         property IdentifierPolicy: TWordPolicy
    @@ -459,6 +462,9 @@
         FMethodInsertPolicy:=MethodInsertPolicyNameToPolicy(XMLConfig.GetValue(
           'CodeToolsOptions/MethodInsertPolicy/Value',
           MethodInsertPolicyNames[mipClassOrder]));
    +    FEventMethodSection:=InsertMethodSectionNameToSection(XMLConfig.GetValue(
    +      'CodeToolsOptions/EventMethodSection/Value',
    +      InsertMethodSectionNames[DefaultEventMethodSection]));
         FKeyWordPolicy:=WordPolicyNameToPolicy(XMLConfig.GetValue(
           'CodeToolsOptions/KeyWordPolicy/Value',
           WordPolicyNames[wpLowerCase]));
    @@ -614,6 +620,9 @@
         XMLConfig.SetDeleteValue('CodeToolsOptions/MethodInsertPolicy/Value',
           MethodInsertPolicyNames[FMethodInsertPolicy],
           MethodInsertPolicyNames[mipClassOrder]);
    +    XMLConfig.SetDeleteValue('CodeToolsOptions/EventMethodSection/Value',
    +      InsertMethodSectionNames[FEventMethodSection],
    +      InsertMethodSectionNames[DefaultEventMethodSection]);
         XMLConfig.SetDeleteValue('CodeToolsOptions/KeyWordPolicy/Value',
           WordPolicyNames[FKeyWordPolicy],
           WordPolicyNames[wpLowerCase]);
    @@ -779,6 +788,7 @@
         FClassHeaderComments:=CodeToolsOpts.ClassHeaderComments;
         FClassImplementationComments:=CodeToolsOpts.ClassImplementationComments;
         FMethodInsertPolicy:=CodeToolsOpts.FMethodInsertPolicy;
    +    FEventMethodSection:=CodeToolsOpts.FEventMethodSection;
         FKeyWordPolicy:=CodeToolsOpts.FKeyWordPolicy;
         FIdentifierPolicy:=CodeToolsOpts.FIdentifierPolicy;
         FDoNotSplitLineInFront:=CodeToolsOpts.FDoNotSplitLineInFront;
    @@ -839,6 +849,7 @@
       FClassHeaderComments:=true;
       FClassImplementationComments:=true;
       FMethodInsertPolicy:=mipClassOrder;
    +  FEventMethodSection:=DefaultEventMethodSection;
       FKeyWordPolicy:=wpLowerCase;
       FIdentifierPolicy:=wpNone;
       FDoNotSplitLineInFront:=DefaultDoNotSplitLineInFront;
    @@ -917,6 +928,7 @@
         and (FClassHeaderComments=CodeToolsOpts.ClassHeaderComments)
         and (FClassImplementationComments=CodeToolsOpts.ClassImplementationComments)
         and (FMethodInsertPolicy=CodeToolsOpts.FMethodInsertPolicy)
    +    and (FEventMethodSection=CodeToolsOpts.FEventMethodSection)
         and (FKeyWordPolicy=CodeToolsOpts.FKeyWordPolicy)
         and (FIdentifierPolicy=CodeToolsOpts.FIdentifierPolicy)
         and (FDoNotSplitLineInFront=CodeToolsOpts.FDoNotSplitLineInFront)
    @@ -1037,6 +1049,7 @@
         Beauty.ClassHeaderComments:=ClassHeaderComments;
         Beauty.ClassImplementationComments:=ClassImplementationComments;
         Beauty.MethodInsertPolicy:=MethodInsertPolicy;
    +    Beauty.EventMethodSection:=EventMethodSection;
         Beauty.KeyWordPolicy:=KeyWordPolicy;
         Beauty.IdentifierPolicy:=IdentifierPolicy;
         Beauty.SetupWordPolicyExceptions(WordPolicyExceptions);
    Index: ide/environmentopts.pp
    ===================================================================
    --- ide/environmentopts.pp	(revision 50022)
    +++ ide/environmentopts.pp	(working copy)
    @@ -39,7 +39,7 @@
     {$endif}
       Classes, SysUtils, TypInfo, contnrs, Graphics, Controls, Forms, Dialogs,
       LCLProc, FileProcs, LazFileUtils, LazFileCache, LazConfigStorage,
    -  Laz2_XMLCfg, LazUTF8,
    +  Laz2_XMLCfg, LazUTF8, SourceChanger,
       // IDEIntf
       ProjectIntf, ObjectInspector, IDEWindowIntf, IDEOptionsIntf,
       ComponentReg, IDEExternToolIntf, MacroDefIntf, DbgIntfDebuggerBase,
    @@ -499,6 +499,9 @@
         // Prevent repopulating Recent project files menu with example projects if it was already cleared up.
         FAlreadyPopulatedRecentFiles : Boolean;
     
    +    //other recent settings
    +    FLastEventMethodSectionPrompt: TInsertMethodSectionResult;
    +
         // backup
         FBackupInfoProjectFiles: TBackupInfo;
         FBackupInfoOtherFiles: TBackupInfo;
    @@ -752,6 +755,10 @@
                                                                     write FMultipleInstances;
         property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter;
     
    +    // other recent settings
    +    property LastEventMethodSectionPrompt: TInsertMethodSectionResult
    +      read FLastEventMethodSectionPrompt write FLastEventMethodSectionPrompt;
    +
         // backup
         property BackupInfoProjectFiles: TBackupInfo read FBackupInfoProjectFiles
                                                      write FBackupInfoProjectFiles;
    @@ -1347,6 +1354,9 @@
       FOpenLastProjectAtStart:=true;
       FMultipleInstances:=DefaultIDEMultipleInstancesOption;
     
    +  // other recent settings
    +  FLastEventMethodSectionPrompt:=InsertMethodSectionToResult[DefaultEventMethodSection];
    +
       // backup
       with FBackupInfoProjectFiles do begin
         BackupType:=bakSameName;
    @@ -1745,6 +1755,11 @@
     
         FAlreadyPopulatedRecentFiles := FXMLCfg.GetValue(Path+'Recent/AlreadyPopulated', false);
     
    +    // other recent settings
    +    FLastEventMethodSectionPrompt:=InsertMethodSectionResultNameToSection(FXMLCfg.GetValue(
    +      'Recent/EventMethodSectionPrompt/Value',
    +      InsertMethodSectionNames[DefaultEventMethodSection]));
    +
         // Add example projects to an empty project list if examples have write access
         if (FRecentProjectFiles.count=0) and (not FAlreadyPopulatedRecentFiles) then begin
           AddRecentProjectInitial('examples/jpeg/',          'jpegexample.lpi');
    @@ -2073,6 +2088,11 @@
     
         FXMLCfg.SetDeleteValue(Path+'Recent/AlreadyPopulated', FAlreadyPopulatedRecentFiles, false);
     
    +    // other recent settings
    +    FXMLCfg.SetDeleteValue('Recent/EventMethodSectionPrompt/Value',
    +      InsertMethodSectionResultNames[FLastEventMethodSectionPrompt],
    +      InsertMethodSectionResultNames[InsertMethodSectionToResult[DefaultEventMethodSection]]);
    +
         // external tools
         fExternalUserTools.Save(FConfigStore,Path+'ExternalTools/');
         FXMLCfg.SetDeleteValue(Path+'ExternalTools/MaxInParallel',FMaxExtToolsInParallel,0);
    Index: ide/frames/codetools_codecreation_options.lfm
    ===================================================================
    --- ide/frames/codetools_codecreation_options.lfm	(revision 50022)
    +++ ide/frames/codetools_codecreation_options.lfm	(working copy)
    @@ -8,76 +8,27 @@
       TabOrder = 0
       Visible = False
       DesignLeft = 322
    -  DesignTop = 184
    -  object ForwardProcsInsertPolicyRadioGroup: TRadioGroup
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = Owner
    -    AnchorSideRight.Control = Owner
    -    AnchorSideRight.Side = asrBottom
    -    Left = 6
    -    Height = 100
    -    Top = 6
    -    Width = 554
    -    Anchors = [akTop, akLeft, akRight]
    -    AutoFill = True
    -    BorderSpacing.Around = 6
    -    Caption = 'ForwardProcsInsertPolicyRadioGroup'
    -    ChildSizing.LeftRightSpacing = 6
    -    ChildSizing.TopBottomSpacing = 6
    -    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
    -    ChildSizing.EnlargeVertical = crsHomogenousChildResize
    -    ChildSizing.ShrinkHorizontal = crsScaleChilds
    -    ChildSizing.ShrinkVertical = crsScaleChilds
    -    ChildSizing.Layout = cclLeftToRightThenTopToBottom
    -    ChildSizing.ControlsPerLine = 1
    -    TabOrder = 0
    -  end
    +  DesignTop = 167
       object ForwardProcsKeepOrderCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = ForwardProcsInsertPolicyRadioGroup
    +    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 112
    +    Top = 45
         Width = 200
    -    BorderSpacing.Around = 6
    +    BorderSpacing.Left = 6
    +    BorderSpacing.Top = 6
         Caption = 'ForwardProcsKeepOrderCheckBox'
         TabOrder = 1
       end
    -  object UsesInsertPolicyRadioGroup: TRadioGroup
    -    AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
    -    AnchorSideTop.Side = asrBottom
    -    AnchorSideRight.Control = Owner
    -    AnchorSideRight.Side = asrBottom
    -    Left = 6
    -    Height = 100
    -    Top = 143
    -    Width = 554
    -    Anchors = [akTop, akLeft, akRight]
    -    AutoFill = True
    -    AutoSize = True
    -    BorderSpacing.Top = 6
    -    BorderSpacing.Around = 6
    -    Caption = 'UsesInsertPolicyRadioGroup'
    -    ChildSizing.LeftRightSpacing = 6
    -    ChildSizing.TopBottomSpacing = 6
    -    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
    -    ChildSizing.EnlargeVertical = crsHomogenousChildResize
    -    ChildSizing.ShrinkHorizontal = crsScaleChilds
    -    ChildSizing.ShrinkVertical = crsScaleChilds
    -    ChildSizing.Layout = cclLeftToRightThenTopToBottom
    -    ChildSizing.ControlsPerLine = 1
    -    Constraints.MinHeight = 100
    -    TabOrder = 2
    -  end
       object UpdateMultiProcSignaturesCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    -    AnchorSideTop.Control = UsesInsertPolicyRadioGroup
    +    AnchorSideTop.Control = UsesInsertPolicyComboBox
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 249
    +    Top = 99
         Width = 217
         BorderSpacing.Left = 6
         BorderSpacing.Top = 6
    @@ -90,7 +41,7 @@
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 268
    +    Top = 118
         Width = 244
         BorderSpacing.Left = 6
         Caption = 'UpdateOtherProcSignaturesCaseCheckBox'
    @@ -102,7 +53,7 @@
         AnchorSideTop.Side = asrCenter
         Left = 6
         Height = 15
    -    Top = 316
    +    Top = 195
         Width = 95
         Caption = 'TemplateFileLabel'
         ParentColor = False
    @@ -110,16 +61,17 @@
       object TemplateFileEdit: TEdit
         AnchorSideLeft.Control = TemplateFileLabel
         AnchorSideLeft.Side = asrBottom
    -    AnchorSideTop.Control = GroupLocalVariablesCheckBox
    +    AnchorSideTop.Control = EventMethodSectionComboBox
         AnchorSideTop.Side = asrBottom
         AnchorSideRight.Control = TemplateFileBrowseButton
    -    Left = 101
    +    Left = 107
         Height = 23
    -    Top = 312
    -    Width = 424
    +    Top = 191
    +    Width = 418
         Anchors = [akTop, akLeft, akRight]
    +    BorderSpacing.Left = 6
         BorderSpacing.Top = 6
    -    TabOrder = 6
    +    TabOrder = 7
         Text = 'TemplateFileEdit'
       end
       object TemplateFileBrowseButton: TButton
    @@ -130,7 +82,7 @@
         AnchorSideBottom.Side = asrBottom
         Left = 525
         Height = 23
    -    Top = 312
    +    Top = 191
         Width = 35
         Anchors = [akTop, akRight, akBottom]
         AutoSize = True
    @@ -137,7 +89,7 @@
         BorderSpacing.Right = 6
         Caption = '...'
         OnClick = TemplateFileBrowseButtonClick
    -    TabOrder = 7
    +    TabOrder = 8
       end
       object GroupLocalVariablesCheckBox: TCheckBox
         AnchorSideLeft.Control = Owner
    @@ -145,10 +97,88 @@
         AnchorSideTop.Side = asrBottom
         Left = 6
         Height = 19
    -    Top = 287
    +    Top = 137
         Width = 180
         BorderSpacing.Left = 6
         Caption = 'GroupLocalVariablesCheckBox'
         TabOrder = 5
       end
    +  object ForwardProcsInsertPolicyComboBox: TComboBox
    +    AnchorSideLeft.Control = ForwardProcsInsertPolicyLabel
    +    AnchorSideLeft.Side = asrBottom
    +    Left = 173
    +    Height = 23
    +    Top = 16
    +    Width = 170
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 0
    +  end
    +  object ForwardProcsInsertPolicyLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = ForwardProcsInsertPolicyComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 20
    +    Width = 161
    +    BorderSpacing.Around = 6
    +    Caption = 'ForwardProcsInsertPolicyLabel'
    +    ParentColor = False
    +  end
    +  object UsesInsertPolicyLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = UsesInsertPolicyComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = UsesInsertPolicyComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 74
    +    Width = 113
    +    BorderSpacing.Around = 6
    +    Caption = 'UsesInsertPolicyLabel'
    +    ParentColor = False
    +  end
    +  object UsesInsertPolicyComboBox: TComboBox
    +    AnchorSideLeft.Control = UsesInsertPolicyLabel
    +    AnchorSideLeft.Side = asrBottom
    +    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
    +    AnchorSideTop.Side = asrBottom
    +    Left = 125
    +    Height = 23
    +    Top = 70
    +    Width = 170
    +    BorderSpacing.Top = 6
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 2
    +  end
    +  object EventMethodSectionLabel: TLabel
    +    AnchorSideLeft.Control = Owner
    +    AnchorSideTop.Control = EventMethodSectionComboBox
    +    AnchorSideTop.Side = asrCenter
    +    AnchorSideRight.Control = EventMethodSectionComboBox
    +    Left = 6
    +    Height = 15
    +    Top = 166
    +    Width = 138
    +    BorderSpacing.Around = 6
    +    Caption = 'EventMethodSectionLabel'
    +    ParentColor = False
    +  end
    +  object EventMethodSectionComboBox: TComboBox
    +    AnchorSideLeft.Control = EventMethodSectionLabel
    +    AnchorSideLeft.Side = asrBottom
    +    AnchorSideTop.Control = GroupLocalVariablesCheckBox
    +    AnchorSideTop.Side = asrBottom
    +    Left = 150
    +    Height = 23
    +    Top = 162
    +    Width = 170
    +    BorderSpacing.Top = 6
    +    ItemHeight = 15
    +    Style = csDropDownList
    +    TabOrder = 6
    +  end
     end
    Index: ide/frames/codetools_codecreation_options.pas
    ===================================================================
    --- ide/frames/codetools_codecreation_options.pas	(revision 50022)
    +++ ide/frames/codetools_codecreation_options.pas	(working copy)
    @@ -34,8 +34,12 @@
       { TCodetoolsCodeCreationOptionsFrame }
     
       TCodetoolsCodeCreationOptionsFrame = class(TAbstractIDEOptionsEditor)
    -    ForwardProcsInsertPolicyRadioGroup: TRadioGroup;
    +    ForwardProcsInsertPolicyComboBox: TComboBox;
    +    UsesInsertPolicyComboBox: TComboBox;
         ForwardProcsKeepOrderCheckBox: TCheckBox;
    +    ForwardProcsInsertPolicyLabel: TLabel;
    +    EventMethodSectionComboBox: TComboBox;
    +    UsesInsertPolicyLabel: TLabel;
         TemplateFileBrowseButton: TButton;
         TemplateFileEdit: TEdit;
         TemplateFileLabel: TLabel;
    @@ -42,7 +46,7 @@
         UpdateMultiProcSignaturesCheckBox: TCheckBox;
         UpdateOtherProcSignaturesCaseCheckBox: TCheckBox;
         GroupLocalVariablesCheckBox: TCheckBox;
    -    UsesInsertPolicyRadioGroup: TRadioGroup;
    +    EventMethodSectionLabel: TLabel;
         procedure TemplateFileBrowseButtonClick(Sender: TObject);
       private
       public
    @@ -87,8 +91,8 @@
     procedure TCodetoolsCodeCreationOptionsFrame.Setup(
       ADialog: TAbstractOptionsEditorDialog);
     begin
    -  with ForwardProcsInsertPolicyRadioGroup do begin
    -    Caption:=dlgForwardProcsInsertPolicy;
    +  ForwardProcsInsertPolicyLabel.Caption:=dlgForwardProcsInsertPolicy;
    +  with ForwardProcsInsertPolicyComboBox do begin
         with Items do begin
           BeginUpdate;
           Add(dlgLast);
    @@ -100,8 +104,8 @@
     
       ForwardProcsKeepOrderCheckBox.Caption:=dlgForwardProcsKeepOrder;
     
    -  with UsesInsertPolicyRadioGroup do begin
    -    Caption:=lisNewUnitsAreAddedToUsesSections;
    +  UsesInsertPolicyLabel.Caption:=lisNewUnitsAreAddedToUsesSections;
    +  with UsesInsertPolicyComboBox do begin
         with Items do begin
           BeginUpdate;
           Add(lisFirst);
    @@ -113,6 +117,20 @@
         end;
       end;
     
    +  EventMethodSectionLabel.Caption:=lisEventMethodSectionLabel;
    +  with EventMethodSectionComboBox do begin
    +    Assert(Ord(High(TInsertMethodSectionResult)) = 3,  'TCodetoolsCodeCreationOptionsFrame.Setup: High(TInsertMethodSectionResult) <> 3');
    +    with Items do begin
    +      BeginUpdate;
    +      Add(lisPrivate);
    +      Add(lisProtected);
    +      Add(lisEMDPublic);
    +      Add(lisEMDPublished);
    +      Add(lisPromptForValue);
    +      EndUpdate;
    +    end;
    +  end;
    +
       UpdateMultiProcSignaturesCheckBox.Caption:=
         lisCTOUpdateMultipleProcedureSignatures;
       UpdateOtherProcSignaturesCaseCheckBox.Caption:=
    @@ -134,24 +152,25 @@
       with AOptions as TCodetoolsOptions do
       begin
         case ForwardProcBodyInsertPolicy of
    -      fpipLast: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=0;
    -      fpipInFrontOfMethods: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=1;
    +      fpipLast: ForwardProcsInsertPolicyComboBox.ItemIndex:=0;
    +      fpipInFrontOfMethods: ForwardProcsInsertPolicyComboBox.ItemIndex:=1;
         else
           // fpipBehindMethods
    -      ForwardProcsInsertPolicyRadioGroup.ItemIndex:=2;
    +      ForwardProcsInsertPolicyComboBox.ItemIndex:=2;
         end;
     
         ForwardProcsKeepOrderCheckBox.Checked := KeepForwardProcOrder;
     
         case UsesInsertPolicy of
    -    uipFirst:             UsesInsertPolicyRadioGroup.ItemIndex:=0;
    -    uipInFrontOfRelated:  UsesInsertPolicyRadioGroup.ItemIndex:=1;
    -    uipBehindRelated:     UsesInsertPolicyRadioGroup.ItemIndex:=2;
    -    uipLast:              UsesInsertPolicyRadioGroup.ItemIndex:=3;
    +    uipFirst:             UsesInsertPolicyComboBox.ItemIndex:=0;
    +    uipInFrontOfRelated:  UsesInsertPolicyComboBox.ItemIndex:=1;
    +    uipBehindRelated:     UsesInsertPolicyComboBox.ItemIndex:=2;
    +    uipLast:              UsesInsertPolicyComboBox.ItemIndex:=3;
         else
           //uipAlphabetically:
    -                          UsesInsertPolicyRadioGroup.ItemIndex:=4;
    +                          UsesInsertPolicyComboBox.ItemIndex:=4;
         end;
    +    EventMethodSectionComboBox.ItemIndex := Ord(EventMethodSection);
     
         UpdateMultiProcSignaturesCheckBox.Checked:=UpdateMultiProcSignatures;
         UpdateOtherProcSignaturesCaseCheckBox.Checked:=UpdateOtherProcSignaturesCase;
    @@ -166,7 +185,7 @@
     begin
       with AOptions as TCodetoolsOptions do
       begin
    -    case ForwardProcsInsertPolicyRadioGroup.ItemIndex of
    +    case ForwardProcsInsertPolicyComboBox.ItemIndex of
           0: ForwardProcBodyInsertPolicy := fpipLast;
           1: ForwardProcBodyInsertPolicy := fpipInFrontOfMethods;
           2: ForwardProcBodyInsertPolicy := fpipBehindMethods;
    @@ -174,7 +193,7 @@
     
         KeepForwardProcOrder := ForwardProcsKeepOrderCheckBox.Checked;
     
    -    case UsesInsertPolicyRadioGroup.ItemIndex of
    +    case UsesInsertPolicyComboBox.ItemIndex of
         0: UsesInsertPolicy:=uipFirst;
         1: UsesInsertPolicy:=uipInFrontOfRelated;
         2: UsesInsertPolicy:=uipBehindRelated;
    @@ -182,6 +201,8 @@
         else UsesInsertPolicy:=uipAlphabetically;
         end;
     
    +    EventMethodSection := TInsertMethodSection(EventMethodSectionComboBox.ItemIndex);
    +
         UpdateMultiProcSignatures:=UpdateMultiProcSignaturesCheckBox.Checked;
         UpdateOtherProcSignaturesCase:=UpdateOtherProcSignaturesCaseCheckBox.Checked;
         GroupLocalVariables:=GroupLocalVariablesCheckBox.Checked;
    Index: ide/lazarusidestrconsts.pas
    ===================================================================
    --- ide/lazarusidestrconsts.pas	(revision 50022)
    +++ ide/lazarusidestrconsts.pas	(working copy)
    @@ -3639,6 +3639,10 @@
       lisAllBlocksLooksOk = 'All blocks look ok.';
       lisTheApplicationBundleWasCreatedFor = 'The Application Bundle was created for "%s"';
     
    +  //codetools ChooseClassSectionDlg
    +  lisChooseClassSectionDlgForMethodCaption = 'Insert new method to section';
    +  lisEventMethodSectionLabel = 'Insert new event methods to section';
    +
       // diff dialog
       lisDiffDlgFile1 = 'File1';
       lisDiffDlgOnlySelection = 'Only selection';
    Index: ide/main.pp
    ===================================================================
    --- ide/main.pp	(revision 50022)
    +++ ide/main.pp	(working copy)
    @@ -69,7 +69,7 @@
       // CodeTools
       FileProcs, FindDeclarationTool, LinkScanner, BasicCodeTools, CodeToolsStructs,
       CodeToolManager, CodeCache, DefineTemplates, KeywordFuncLists, CodeTree,
    -  StdCodeTools,
    +  StdCodeTools, ChooseMethodSectionDlg,
       // LazUtils
       // use lazutf8, lazfileutils and lazfilecache after FileProcs and FileUtil
       FileUtil, LazFileUtils, LazFileCache, LazUTF8, LazUTF8Classes, UTF8Process,
    

Activities

Ondrej Pokorny

2015-10-10 01:26

developer  

ct-event-method-section-1.patch (35,462 bytes)
Index: components/codetools/codecompletiontool.pas
===================================================================
--- components/codetools/codecompletiontool.pas	(revision 50022)
+++ components/codetools/codecompletiontool.pas	(working copy)
@@ -124,6 +124,14 @@
     ctnClassPublished  // pcsPublished
   );
 
+  InsertMethodSectionToNewClassPart: array[TInsertMethodSectionResult] of TNewClassPart = (
+    ncpPrivateProcs,
+    ncpProtectedProcs,
+    ncpPublicProcs,
+    ncpPublishedProcs,
+    ncpPrivateProcs
+  );
+
 type
   TCodeCompletionCodeTool = class;
 
@@ -207,10 +215,10 @@
     procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer;
                           out NewPos: TCodeXYPosition; out NewTopLine: integer);
     procedure AddNeededUnitToMainUsesSection(AnUnitName: PChar);
-    procedure AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
+    function AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
                   const AnEventName: string; ProcContext: TFindContext; out
                   MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
-                  SourceChangeCache: TSourceChangeCache);
+                  SourceChangeCache: TSourceChangeCache): Boolean;
     procedure AddProcedureCompatibleToProcType(
                   const NewProcName: string; ProcContext: TFindContext; out
                   MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
@@ -1363,14 +1371,17 @@
   Pointer(s):=nil;
 end;
 
-procedure TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
+function TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
   AClassNode: TCodeTreeNode; const AnEventName: string;
   ProcContext: TFindContext; out MethodDefinition: string; out
-  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
+  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache
+  ): Boolean;
 var
   CleanMethodDefinition: string;
   Beauty: TBeautifyCodeOptions;
+  MethodSection: TInsertMethodSectionResult;
 begin
+  Result := False;
   MethodDefinition:='';
   MethodAttr:=[];
 
@@ -1402,8 +1413,11 @@
   {$ENDIF}
   if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
     // insert method definition into class
+    MethodSection := Beauty.GetRealEventMethodSection;
+    if MethodSection=imsrAbort then
+      Exit;
     AddClassInsertion(CleanMethodDefinition, MethodDefinition,
-                      AnEventName, ncpPublishedProcs);
+                      AnEventName, InsertMethodSectionToNewClassPart[MethodSection]);
   end;
   MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition,
                    ExtractClassName(AClassNode,false,true), AnEventName);
@@ -1413,6 +1427,7 @@
   // insert all missing proc bodies
   if not CreateMissingClassProcBodies(false) then
     RaiseException(ctsErrorDuringCreationOfNewProcBodies);
+  Result := True;
 end;
 
 procedure TCodeCompletionCodeTool.AddProcedureCompatibleToProcType(
@@ -2145,8 +2160,10 @@
         if FullEventName='' then exit;
 
         // add published method and method body and right side of assignment
-        AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
-          AMethodDefinition,AMethodAttr,SourceChangeCache);
+        if not AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
+          AMethodDefinition,AMethodAttr,SourceChangeCache)
+        then
+          Exit;
         if not CompleteAssignment(FullEventName,AssignmentOperator,
           AddrOperatorPos,SemicolonPos,UserEventAtom)
         then
@@ -2293,8 +2310,10 @@
     ProcContext:=CreateFindContext(TypeTool,TypeNode);
 
     // create new method
-    AddMethodCompatibleToProcType(AClassNode,Identifier,
-      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache);
+    if not AddMethodCompatibleToProcType(AClassNode,Identifier,
+      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache)
+    then
+      Exit;
 
     // apply the changes
     if not SourceChangeCache.Apply then
Index: components/codetools/sourcechanger.pas
===================================================================
--- components/codetools/sourcechanger.pas	(revision 50022)
+++ components/codetools/sourcechanger.pas	(working copy)
@@ -59,6 +59,22 @@
     mipClassOrder      // try to copy the order of the class
     );
     
+  //where to add created methods from event assignment: "OnClick := @MyNewProc;"
+  TInsertMethodSection = (
+    imsPrivate,
+    imsProtected,
+    imsPublic,
+    imsPublished,
+    imsPrompt //show dialog prompt
+    );
+  TInsertMethodSectionResult = (
+    imsrPrivate,
+    imsrProtected,
+    imsrPublic,
+    imsrPublished,
+    imsrAbort //prompt dialog aborted
+  );
+
   TForwardProcBodyInsertPolicy = (
     fpipLast,
     fpipInFrontOfMethods,
@@ -90,7 +106,16 @@
 
 const
   DefaultUsesInsertPolicy = uipBehindRelated;
+  DefaultEventMethodSection = imsPrompt;
 
+  InsertMethodSectionToResult: array[TInsertMethodSection] of TInsertMethodSectionResult = (
+    imsrPrivate,
+    imsrProtected,
+    imsrPublic,
+    imsrPublished,
+    imsrPrivate
+    );
+
 type
   TWordPolicyException = class
     Word: string;
@@ -157,6 +182,7 @@
     ClassPartInsertPolicy: TClassPartInsertPolicy;
     MixMethodsAndProperties: boolean;
     MethodInsertPolicy: TMethodInsertPolicy;
+    EventMethodSection: TInsertMethodSection;
     PropertyReadIdentPrefix: string;
     PropertyWriteIdentPrefix: string;
     PropertyStoredIdentPostfix: string;
@@ -169,6 +195,7 @@
     
     NestedComments: boolean;
 
+    function GetRealEventMethodSection: TInsertMethodSectionResult; //in case of imsPrompt show a dialog and return a "normal" section
     function GetIndentStr(TheIndent: integer): string; inline;
     function GetLineIndent(const Source: string; Position: integer): integer; inline;
     procedure SetupWordPolicyExceptions(ws: TStrings);
@@ -328,7 +355,15 @@
   MethodInsertPolicyNames: array[TMethodInsertPolicy] of shortstring = (
       'Alphabetically', 'Last', 'ClassOrder'
     );
-    
+
+  InsertMethodSectionNames: array[TInsertMethodSection] of ShortString = (
+    'Private', 'Protected', 'Public', 'Published', 'Prompt'
+    );
+
+  InsertMethodSectionResultNames: array[TInsertMethodSectionResult] of ShortString = (
+    'Private', 'Protected', 'Public', 'Published', 'Abort'
+    );
+
   ForwardProcBodyInsertPolicyNames: array[TForwardProcBodyInsertPolicy] of
     shortstring = (
       'Last',
@@ -352,11 +387,18 @@
   DefaultDoNotInsertSpaceInFront: TAtomTypes = [];
   DefaultDoNotInsertSpaceAfter: TAtomTypes = [atDirectiveStart];
 
+type
+  TShowEventMethodSectionPromptFunc = function(): TInsertMethodSectionResult;
+var
+  ShowEventMethodSectionPrompt: TShowEventMethodSectionPromptFunc = nil;
+
 function AtomTypeNameToType(const s: string): TAtomType;
 function AtomTypesToStr(const AtomTypes: TAtomTypes): string;
 function WordPolicyNameToPolicy(const s: string): TWordPolicy;
 function ClassPartPolicyNameToPolicy(const s: string): TClassPartInsertPolicy;
 function MethodInsertPolicyNameToPolicy(const s: string): TMethodInsertPolicy;
+function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
+function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
 function ForwardProcBodyInsertPolicyNameToPolicy(
   const s: string): TForwardProcBodyInsertPolicy;
 function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
@@ -409,6 +451,20 @@
   Result:=mipLast;
 end;
 
+function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
+begin
+  for Result:=Low(TInsertMethodSection) to High(TInsertMethodSection) do
+    if SysUtils.CompareText(InsertMethodSectionNames[Result],s)=0 then exit;
+  Result:=DefaultEventMethodSection;
+end;
+
+function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
+begin
+  for Result:=Low(TInsertMethodSectionResult) to High(TInsertMethodSectionResult) do
+    if SysUtils.CompareText(InsertMethodSectionResultNames[Result],s)=0 then exit;
+  Result:=imsrPrivate;
+end;
+
 function ForwardProcBodyInsertPolicyNameToPolicy(
   const s: string): TForwardProcBodyInsertPolicy;
 begin
@@ -1259,6 +1315,7 @@
   UpdateOtherProcSignaturesCase:=true;
   GroupLocalVariables:=true;
   MethodInsertPolicy:=mipClassOrder;
+  EventMethodSection:=DefaultEventMethodSection;
   ForwardProcBodyInsertPolicy:=fpipBehindMethods;
   KeepForwardProcOrder:=true;
   ClassHeaderComments:=true;
@@ -1685,6 +1742,21 @@
     Result:=false;
 end;
 
+function TBeautifyCodeOptions.GetRealEventMethodSection: TInsertMethodSectionResult;
+var
+  SectionResult: TInsertMethodSection;
+begin
+  SectionResult := EventMethodSection;
+  if (SectionResult = imsPrompt) then
+  begin
+    if Assigned(ShowEventMethodSectionPrompt) then
+      Result := ShowEventMethodSectionPrompt()
+    else
+      Result := InsertMethodSectionToResult[DefaultEventMethodSection];
+  end else
+    Result := InsertMethodSectionToResult[SectionResult];
+end;
+
 procedure TBeautifyCodeOptions.SetupWordPolicyExceptions(ws: TStrings);
 begin
   if Assigned(WordExceptions) then WordExceptions.Free;
Index: ide/choosemethodsectiondlg.lfm
===================================================================
--- ide/choosemethodsectiondlg.lfm	(nonexistent)
+++ ide/choosemethodsectiondlg.lfm	(working copy)
@@ -0,0 +1,45 @@
+object ChooseMethodSectionDialog: TChooseMethodSectionDialog
+  Left = 460
+  Height = 177
+  Top = 220
+  Width = 252
+  BorderStyle = bsDialog
+  Caption = 'ChooseMethodSectionDialog'
+  ClientHeight = 177
+  ClientWidth = 252
+  KeyPreview = True
+  OnKeyPress = FormKeyPress
+  Position = poDesktopCenter
+  LCLVersion = '1.5'
+  object SectionsListBox: TListBox
+    Left = 10
+    Height = 117
+    Top = 10
+    Width = 232
+    Align = alClient
+    BorderSpacing.Left = 10
+    BorderSpacing.Top = 10
+    BorderSpacing.Right = 10
+    BorderSpacing.Bottom = 10
+    ItemHeight = 0
+    OnDblClick = SectionsListBoxDblClick
+    OnKeyPress = SectionsListBoxKeyPress
+    TabOrder = 0
+  end
+  object ButtonPanel: TButtonPanel
+    Left = 6
+    Height = 34
+    Top = 137
+    Width = 240
+    OKButton.Name = 'OKButton'
+    OKButton.DefaultCaption = True
+    HelpButton.Name = 'HelpButton'
+    HelpButton.DefaultCaption = True
+    CloseButton.Name = 'CloseButton'
+    CloseButton.DefaultCaption = True
+    CancelButton.Name = 'CancelButton'
+    CancelButton.DefaultCaption = True
+    TabOrder = 1
+    ShowButtons = [pbOK]
+  end
+end
Index: ide/choosemethodsectiondlg.pas
===================================================================
--- ide/choosemethodsectiondlg.pas	(nonexistent)
+++ ide/choosemethodsectiondlg.pas	(working copy)
@@ -0,0 +1,124 @@
+{
+ ***************************************************************************
+ *                                                                         *
+ *   This source is free software; you can redistribute it and/or modify   *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This code 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.  See the GNU     *
+ *   General Public License for more details.                              *
+ *                                                                         *
+ *   A copy of the GNU General Public License is available on the World    *
+ *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
+ *   obtain it by writing to the Free Software Foundation,                 *
+ *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
+ *                                                                         *
+ ***************************************************************************
+
+  Author: Ondrej Pokorny
+
+  Abstract:
+    A simple dialog to select class section.
+}
+unit ChooseMethodSectionDlg;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+  ButtonPanel, SourceChanger, LazarusIDEStrConsts, EnvironmentOpts;
+
+type
+  //this dialog can easily be reused.
+  //for now it is used only in the method event assignment code creation
+
+  TChooseMethodSectionDialog = class(TForm)
+    ButtonPanel: TButtonPanel;
+    SectionsListBox: TListBox;
+    procedure FormKeyPress(Sender: TObject; var Key: char);
+    procedure SectionsListBoxDblClick(Sender: TObject);
+    procedure SectionsListBoxKeyPress(Sender: TObject; var Key: char);
+  protected
+    procedure DoCreate; override;
+  public
+
+  end;
+
+function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult): TInsertMethodSectionResult;
+function ShowEventMethodSectionDialog: TInsertMethodSectionResult;
+
+implementation
+
+{$R *.lfm}
+
+function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult): TInsertMethodSectionResult;
+var
+  Dlg: TChooseMethodSectionDialog;
+begin
+  Dlg := TChooseMethodSectionDialog.Create(Application);
+  try
+    Dlg.Caption := ACaption;
+    Dlg.PopupMode := pmAuto;
+    if Ord(ADefault) < Dlg.SectionsListBox.Count then
+      Dlg.SectionsListBox.ItemIndex := Ord(ADefault)
+    else
+      Dlg.SectionsListBox.ItemIndex := 0;
+    if Dlg.ShowModal = mrOK then
+      Result := TInsertMethodSectionResult(Dlg.SectionsListBox.ItemIndex)
+    else
+      Result := imsrAbort;
+  finally
+    Dlg.Free;
+  end;
+end;
+
+function ShowEventMethodSectionDialog: TInsertMethodSectionResult;
+begin
+  Result := ChooseMethodSectionDialog(lisChooseClassSectionDlgForMethodCaption,
+    EnvironmentOptions.LastEventMethodSectionPrompt);
+  if Result <> imsrAbort then
+    EnvironmentOptions.LastEventMethodSectionPrompt := Result;
+end;
+
+{ TChooseMethodSectionDialog }
+
+procedure TChooseMethodSectionDialog.DoCreate;
+begin
+  inherited DoCreate;
+
+  Assert(Ord(High(TInsertMethodSectionResult)) = 4);
+  SectionsListBox.Items.Add(lisPrivate);
+  SectionsListBox.Items.Add(lisProtected);
+  SectionsListBox.Items.Add(lisEMDPublic);
+  SectionsListBox.Items.Add(lisEMDPublished);
+end;
+
+procedure TChooseMethodSectionDialog.FormKeyPress(Sender: TObject;
+  var Key: char);
+begin
+  if Key = #27 then
+    ModalResult := mrCancel;
+end;
+
+procedure TChooseMethodSectionDialog.SectionsListBoxDblClick(Sender: TObject);
+begin
+  ModalResult := mrOK;
+end;
+
+procedure TChooseMethodSectionDialog.SectionsListBoxKeyPress(
+  Sender: TObject; var Key: char);
+begin
+  if Key = #13 then
+    ModalResult := mrOK;
+end;
+
+initialization
+  ShowEventMethodSectionPrompt := @ShowEventMethodSectionDialog;
+
+end.
+
Index: ide/codetoolsoptions.pas
===================================================================
--- ide/codetoolsoptions.pas	(revision 50022)
+++ ide/codetoolsoptions.pas	(working copy)
@@ -82,6 +82,7 @@
     FForwardProcBodyInsertPolicy: TForwardProcBodyInsertPolicy;
     FKeepForwardProcOrder: boolean;
     FMethodInsertPolicy: TMethodInsertPolicy;
+    FEventMethodSection: TInsertMethodSection;
     FKeyWordPolicy : TWordPolicy;
     FIdentifierPolicy: TWordPolicy;
     FUpdateAllMethodSignatures: boolean;
@@ -187,6 +188,8 @@
       read FClassImplementationComments write FClassImplementationComments;
     property MethodInsertPolicy: TMethodInsertPolicy
       read FMethodInsertPolicy write FMethodInsertPolicy;
+    property EventMethodSection: TInsertMethodSection
+      read FEventMethodSection write FEventMethodSection;
     property KeyWordPolicy : TWordPolicy
       read FKeyWordPolicy write FKeyWordPolicy;
     property IdentifierPolicy: TWordPolicy
@@ -459,6 +462,9 @@
     FMethodInsertPolicy:=MethodInsertPolicyNameToPolicy(XMLConfig.GetValue(
       'CodeToolsOptions/MethodInsertPolicy/Value',
       MethodInsertPolicyNames[mipClassOrder]));
+    FEventMethodSection:=InsertMethodSectionNameToSection(XMLConfig.GetValue(
+      'CodeToolsOptions/EventMethodSection/Value',
+      InsertMethodSectionNames[DefaultEventMethodSection]));
     FKeyWordPolicy:=WordPolicyNameToPolicy(XMLConfig.GetValue(
       'CodeToolsOptions/KeyWordPolicy/Value',
       WordPolicyNames[wpLowerCase]));
@@ -614,6 +620,9 @@
     XMLConfig.SetDeleteValue('CodeToolsOptions/MethodInsertPolicy/Value',
       MethodInsertPolicyNames[FMethodInsertPolicy],
       MethodInsertPolicyNames[mipClassOrder]);
+    XMLConfig.SetDeleteValue('CodeToolsOptions/EventMethodSection/Value',
+      InsertMethodSectionNames[FEventMethodSection],
+      InsertMethodSectionNames[DefaultEventMethodSection]);
     XMLConfig.SetDeleteValue('CodeToolsOptions/KeyWordPolicy/Value',
       WordPolicyNames[FKeyWordPolicy],
       WordPolicyNames[wpLowerCase]);
@@ -779,6 +788,7 @@
     FClassHeaderComments:=CodeToolsOpts.ClassHeaderComments;
     FClassImplementationComments:=CodeToolsOpts.ClassImplementationComments;
     FMethodInsertPolicy:=CodeToolsOpts.FMethodInsertPolicy;
+    FEventMethodSection:=CodeToolsOpts.FEventMethodSection;
     FKeyWordPolicy:=CodeToolsOpts.FKeyWordPolicy;
     FIdentifierPolicy:=CodeToolsOpts.FIdentifierPolicy;
     FDoNotSplitLineInFront:=CodeToolsOpts.FDoNotSplitLineInFront;
@@ -839,6 +849,7 @@
   FClassHeaderComments:=true;
   FClassImplementationComments:=true;
   FMethodInsertPolicy:=mipClassOrder;
+  FEventMethodSection:=DefaultEventMethodSection;
   FKeyWordPolicy:=wpLowerCase;
   FIdentifierPolicy:=wpNone;
   FDoNotSplitLineInFront:=DefaultDoNotSplitLineInFront;
@@ -917,6 +928,7 @@
     and (FClassHeaderComments=CodeToolsOpts.ClassHeaderComments)
     and (FClassImplementationComments=CodeToolsOpts.ClassImplementationComments)
     and (FMethodInsertPolicy=CodeToolsOpts.FMethodInsertPolicy)
+    and (FEventMethodSection=CodeToolsOpts.FEventMethodSection)
     and (FKeyWordPolicy=CodeToolsOpts.FKeyWordPolicy)
     and (FIdentifierPolicy=CodeToolsOpts.FIdentifierPolicy)
     and (FDoNotSplitLineInFront=CodeToolsOpts.FDoNotSplitLineInFront)
@@ -1037,6 +1049,7 @@
     Beauty.ClassHeaderComments:=ClassHeaderComments;
     Beauty.ClassImplementationComments:=ClassImplementationComments;
     Beauty.MethodInsertPolicy:=MethodInsertPolicy;
+    Beauty.EventMethodSection:=EventMethodSection;
     Beauty.KeyWordPolicy:=KeyWordPolicy;
     Beauty.IdentifierPolicy:=IdentifierPolicy;
     Beauty.SetupWordPolicyExceptions(WordPolicyExceptions);
Index: ide/environmentopts.pp
===================================================================
--- ide/environmentopts.pp	(revision 50022)
+++ ide/environmentopts.pp	(working copy)
@@ -39,7 +39,7 @@
 {$endif}
   Classes, SysUtils, TypInfo, contnrs, Graphics, Controls, Forms, Dialogs,
   LCLProc, FileProcs, LazFileUtils, LazFileCache, LazConfigStorage,
-  Laz2_XMLCfg, LazUTF8,
+  Laz2_XMLCfg, LazUTF8, SourceChanger,
   // IDEIntf
   ProjectIntf, ObjectInspector, IDEWindowIntf, IDEOptionsIntf,
   ComponentReg, IDEExternToolIntf, MacroDefIntf, DbgIntfDebuggerBase,
@@ -499,6 +499,9 @@
     // Prevent repopulating Recent project files menu with example projects if it was already cleared up.
     FAlreadyPopulatedRecentFiles : Boolean;
 
+    //other recent settings
+    FLastEventMethodSectionPrompt: TInsertMethodSectionResult;
+
     // backup
     FBackupInfoProjectFiles: TBackupInfo;
     FBackupInfoOtherFiles: TBackupInfo;
@@ -752,6 +755,10 @@
                                                                 write FMultipleInstances;
     property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter;
 
+    // other recent settings
+    property LastEventMethodSectionPrompt: TInsertMethodSectionResult
+      read FLastEventMethodSectionPrompt write FLastEventMethodSectionPrompt;
+
     // backup
     property BackupInfoProjectFiles: TBackupInfo read FBackupInfoProjectFiles
                                                  write FBackupInfoProjectFiles;
@@ -1347,6 +1354,9 @@
   FOpenLastProjectAtStart:=true;
   FMultipleInstances:=DefaultIDEMultipleInstancesOption;
 
+  // other recent settings
+  FLastEventMethodSectionPrompt:=InsertMethodSectionToResult[DefaultEventMethodSection];
+
   // backup
   with FBackupInfoProjectFiles do begin
     BackupType:=bakSameName;
@@ -1745,6 +1755,11 @@
 
     FAlreadyPopulatedRecentFiles := FXMLCfg.GetValue(Path+'Recent/AlreadyPopulated', false);
 
+    // other recent settings
+    FLastEventMethodSectionPrompt:=InsertMethodSectionResultNameToSection(FXMLCfg.GetValue(
+      'Recent/EventMethodSectionPrompt/Value',
+      InsertMethodSectionNames[DefaultEventMethodSection]));
+
     // Add example projects to an empty project list if examples have write access
     if (FRecentProjectFiles.count=0) and (not FAlreadyPopulatedRecentFiles) then begin
       AddRecentProjectInitial('examples/jpeg/',          'jpegexample.lpi');
@@ -2073,6 +2088,11 @@
 
     FXMLCfg.SetDeleteValue(Path+'Recent/AlreadyPopulated', FAlreadyPopulatedRecentFiles, false);
 
+    // other recent settings
+    FXMLCfg.SetDeleteValue('Recent/EventMethodSectionPrompt/Value',
+      InsertMethodSectionResultNames[FLastEventMethodSectionPrompt],
+      InsertMethodSectionResultNames[InsertMethodSectionToResult[DefaultEventMethodSection]]);
+
     // external tools
     fExternalUserTools.Save(FConfigStore,Path+'ExternalTools/');
     FXMLCfg.SetDeleteValue(Path+'ExternalTools/MaxInParallel',FMaxExtToolsInParallel,0);
Index: ide/frames/codetools_codecreation_options.lfm
===================================================================
--- ide/frames/codetools_codecreation_options.lfm	(revision 50022)
+++ ide/frames/codetools_codecreation_options.lfm	(working copy)
@@ -8,76 +8,27 @@
   TabOrder = 0
   Visible = False
   DesignLeft = 322
-  DesignTop = 184
-  object ForwardProcsInsertPolicyRadioGroup: TRadioGroup
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = Owner
-    AnchorSideRight.Control = Owner
-    AnchorSideRight.Side = asrBottom
-    Left = 6
-    Height = 100
-    Top = 6
-    Width = 554
-    Anchors = [akTop, akLeft, akRight]
-    AutoFill = True
-    BorderSpacing.Around = 6
-    Caption = 'ForwardProcsInsertPolicyRadioGroup'
-    ChildSizing.LeftRightSpacing = 6
-    ChildSizing.TopBottomSpacing = 6
-    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
-    ChildSizing.EnlargeVertical = crsHomogenousChildResize
-    ChildSizing.ShrinkHorizontal = crsScaleChilds
-    ChildSizing.ShrinkVertical = crsScaleChilds
-    ChildSizing.Layout = cclLeftToRightThenTopToBottom
-    ChildSizing.ControlsPerLine = 1
-    TabOrder = 0
-  end
+  DesignTop = 167
   object ForwardProcsKeepOrderCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = ForwardProcsInsertPolicyRadioGroup
+    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 112
+    Top = 45
     Width = 200
-    BorderSpacing.Around = 6
+    BorderSpacing.Left = 6
+    BorderSpacing.Top = 6
     Caption = 'ForwardProcsKeepOrderCheckBox'
     TabOrder = 1
   end
-  object UsesInsertPolicyRadioGroup: TRadioGroup
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
-    AnchorSideTop.Side = asrBottom
-    AnchorSideRight.Control = Owner
-    AnchorSideRight.Side = asrBottom
-    Left = 6
-    Height = 100
-    Top = 143
-    Width = 554
-    Anchors = [akTop, akLeft, akRight]
-    AutoFill = True
-    AutoSize = True
-    BorderSpacing.Top = 6
-    BorderSpacing.Around = 6
-    Caption = 'UsesInsertPolicyRadioGroup'
-    ChildSizing.LeftRightSpacing = 6
-    ChildSizing.TopBottomSpacing = 6
-    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
-    ChildSizing.EnlargeVertical = crsHomogenousChildResize
-    ChildSizing.ShrinkHorizontal = crsScaleChilds
-    ChildSizing.ShrinkVertical = crsScaleChilds
-    ChildSizing.Layout = cclLeftToRightThenTopToBottom
-    ChildSizing.ControlsPerLine = 1
-    Constraints.MinHeight = 100
-    TabOrder = 2
-  end
   object UpdateMultiProcSignaturesCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = UsesInsertPolicyRadioGroup
+    AnchorSideTop.Control = UsesInsertPolicyComboBox
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 249
+    Top = 99
     Width = 217
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
@@ -90,7 +41,7 @@
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 268
+    Top = 118
     Width = 244
     BorderSpacing.Left = 6
     Caption = 'UpdateOtherProcSignaturesCaseCheckBox'
@@ -102,7 +53,7 @@
     AnchorSideTop.Side = asrCenter
     Left = 6
     Height = 15
-    Top = 316
+    Top = 195
     Width = 95
     Caption = 'TemplateFileLabel'
     ParentColor = False
@@ -110,16 +61,17 @@
   object TemplateFileEdit: TEdit
     AnchorSideLeft.Control = TemplateFileLabel
     AnchorSideLeft.Side = asrBottom
-    AnchorSideTop.Control = GroupLocalVariablesCheckBox
+    AnchorSideTop.Control = EventMethodSectionComboBox
     AnchorSideTop.Side = asrBottom
     AnchorSideRight.Control = TemplateFileBrowseButton
-    Left = 101
+    Left = 107
     Height = 23
-    Top = 312
-    Width = 424
+    Top = 191
+    Width = 418
     Anchors = [akTop, akLeft, akRight]
+    BorderSpacing.Left = 6
     BorderSpacing.Top = 6
-    TabOrder = 6
+    TabOrder = 7
     Text = 'TemplateFileEdit'
   end
   object TemplateFileBrowseButton: TButton
@@ -130,7 +82,7 @@
     AnchorSideBottom.Side = asrBottom
     Left = 525
     Height = 23
-    Top = 312
+    Top = 191
     Width = 35
     Anchors = [akTop, akRight, akBottom]
     AutoSize = True
@@ -137,7 +89,7 @@
     BorderSpacing.Right = 6
     Caption = '...'
     OnClick = TemplateFileBrowseButtonClick
-    TabOrder = 7
+    TabOrder = 8
   end
   object GroupLocalVariablesCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
@@ -145,10 +97,88 @@
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 287
+    Top = 137
     Width = 180
     BorderSpacing.Left = 6
     Caption = 'GroupLocalVariablesCheckBox'
     TabOrder = 5
   end
+  object ForwardProcsInsertPolicyComboBox: TComboBox
+    AnchorSideLeft.Control = ForwardProcsInsertPolicyLabel
+    AnchorSideLeft.Side = asrBottom
+    Left = 173
+    Height = 23
+    Top = 16
+    Width = 170
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 0
+  end
+  object ForwardProcsInsertPolicyLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = ForwardProcsInsertPolicyComboBox
+    Left = 6
+    Height = 15
+    Top = 20
+    Width = 161
+    BorderSpacing.Around = 6
+    Caption = 'ForwardProcsInsertPolicyLabel'
+    ParentColor = False
+  end
+  object UsesInsertPolicyLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = UsesInsertPolicyComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = UsesInsertPolicyComboBox
+    Left = 6
+    Height = 15
+    Top = 74
+    Width = 113
+    BorderSpacing.Around = 6
+    Caption = 'UsesInsertPolicyLabel'
+    ParentColor = False
+  end
+  object UsesInsertPolicyComboBox: TComboBox
+    AnchorSideLeft.Control = UsesInsertPolicyLabel
+    AnchorSideLeft.Side = asrBottom
+    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
+    AnchorSideTop.Side = asrBottom
+    Left = 125
+    Height = 23
+    Top = 70
+    Width = 170
+    BorderSpacing.Top = 6
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 2
+  end
+  object EventMethodSectionLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = EventMethodSectionComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = EventMethodSectionComboBox
+    Left = 6
+    Height = 15
+    Top = 166
+    Width = 138
+    BorderSpacing.Around = 6
+    Caption = 'EventMethodSectionLabel'
+    ParentColor = False
+  end
+  object EventMethodSectionComboBox: TComboBox
+    AnchorSideLeft.Control = EventMethodSectionLabel
+    AnchorSideLeft.Side = asrBottom
+    AnchorSideTop.Control = GroupLocalVariablesCheckBox
+    AnchorSideTop.Side = asrBottom
+    Left = 150
+    Height = 23
+    Top = 162
+    Width = 170
+    BorderSpacing.Top = 6
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 6
+  end
 end
Index: ide/frames/codetools_codecreation_options.pas
===================================================================
--- ide/frames/codetools_codecreation_options.pas	(revision 50022)
+++ ide/frames/codetools_codecreation_options.pas	(working copy)
@@ -34,8 +34,12 @@
   { TCodetoolsCodeCreationOptionsFrame }
 
   TCodetoolsCodeCreationOptionsFrame = class(TAbstractIDEOptionsEditor)
-    ForwardProcsInsertPolicyRadioGroup: TRadioGroup;
+    ForwardProcsInsertPolicyComboBox: TComboBox;
+    UsesInsertPolicyComboBox: TComboBox;
     ForwardProcsKeepOrderCheckBox: TCheckBox;
+    ForwardProcsInsertPolicyLabel: TLabel;
+    EventMethodSectionComboBox: TComboBox;
+    UsesInsertPolicyLabel: TLabel;
     TemplateFileBrowseButton: TButton;
     TemplateFileEdit: TEdit;
     TemplateFileLabel: TLabel;
@@ -42,7 +46,7 @@
     UpdateMultiProcSignaturesCheckBox: TCheckBox;
     UpdateOtherProcSignaturesCaseCheckBox: TCheckBox;
     GroupLocalVariablesCheckBox: TCheckBox;
-    UsesInsertPolicyRadioGroup: TRadioGroup;
+    EventMethodSectionLabel: TLabel;
     procedure TemplateFileBrowseButtonClick(Sender: TObject);
   private
   public
@@ -87,8 +91,8 @@
 procedure TCodetoolsCodeCreationOptionsFrame.Setup(
   ADialog: TAbstractOptionsEditorDialog);
 begin
-  with ForwardProcsInsertPolicyRadioGroup do begin
-    Caption:=dlgForwardProcsInsertPolicy;
+  ForwardProcsInsertPolicyLabel.Caption:=dlgForwardProcsInsertPolicy;
+  with ForwardProcsInsertPolicyComboBox do begin
     with Items do begin
       BeginUpdate;
       Add(dlgLast);
@@ -100,8 +104,8 @@
 
   ForwardProcsKeepOrderCheckBox.Caption:=dlgForwardProcsKeepOrder;
 
-  with UsesInsertPolicyRadioGroup do begin
-    Caption:=lisNewUnitsAreAddedToUsesSections;
+  UsesInsertPolicyLabel.Caption:=lisNewUnitsAreAddedToUsesSections;
+  with UsesInsertPolicyComboBox do begin
     with Items do begin
       BeginUpdate;
       Add(lisFirst);
@@ -113,6 +117,20 @@
     end;
   end;
 
+  EventMethodSectionLabel.Caption:=lisEventMethodSectionLabel;
+  with EventMethodSectionComboBox do begin
+    Assert(Ord(High(TInsertMethodSection)) = 4);
+    with Items do begin
+      BeginUpdate;
+      Add(lisPrivate);
+      Add(lisProtected);
+      Add(lisEMDPublic);
+      Add(lisEMDPublished);
+      Add(lisPromptForValue);
+      EndUpdate;
+    end;
+  end;
+
   UpdateMultiProcSignaturesCheckBox.Caption:=
     lisCTOUpdateMultipleProcedureSignatures;
   UpdateOtherProcSignaturesCaseCheckBox.Caption:=
@@ -134,24 +152,25 @@
   with AOptions as TCodetoolsOptions do
   begin
     case ForwardProcBodyInsertPolicy of
-      fpipLast: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=0;
-      fpipInFrontOfMethods: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=1;
+      fpipLast: ForwardProcsInsertPolicyComboBox.ItemIndex:=0;
+      fpipInFrontOfMethods: ForwardProcsInsertPolicyComboBox.ItemIndex:=1;
     else
       // fpipBehindMethods
-      ForwardProcsInsertPolicyRadioGroup.ItemIndex:=2;
+      ForwardProcsInsertPolicyComboBox.ItemIndex:=2;
     end;
 
     ForwardProcsKeepOrderCheckBox.Checked := KeepForwardProcOrder;
 
     case UsesInsertPolicy of
-    uipFirst:             UsesInsertPolicyRadioGroup.ItemIndex:=0;
-    uipInFrontOfRelated:  UsesInsertPolicyRadioGroup.ItemIndex:=1;
-    uipBehindRelated:     UsesInsertPolicyRadioGroup.ItemIndex:=2;
-    uipLast:              UsesInsertPolicyRadioGroup.ItemIndex:=3;
+    uipFirst:             UsesInsertPolicyComboBox.ItemIndex:=0;
+    uipInFrontOfRelated:  UsesInsertPolicyComboBox.ItemIndex:=1;
+    uipBehindRelated:     UsesInsertPolicyComboBox.ItemIndex:=2;
+    uipLast:              UsesInsertPolicyComboBox.ItemIndex:=3;
     else
       //uipAlphabetically:
-                          UsesInsertPolicyRadioGroup.ItemIndex:=4;
+                          UsesInsertPolicyComboBox.ItemIndex:=4;
     end;
+    EventMethodSectionComboBox.ItemIndex := Ord(EventMethodSection);
 
     UpdateMultiProcSignaturesCheckBox.Checked:=UpdateMultiProcSignatures;
     UpdateOtherProcSignaturesCaseCheckBox.Checked:=UpdateOtherProcSignaturesCase;
@@ -166,7 +185,7 @@
 begin
   with AOptions as TCodetoolsOptions do
   begin
-    case ForwardProcsInsertPolicyRadioGroup.ItemIndex of
+    case ForwardProcsInsertPolicyComboBox.ItemIndex of
       0: ForwardProcBodyInsertPolicy := fpipLast;
       1: ForwardProcBodyInsertPolicy := fpipInFrontOfMethods;
       2: ForwardProcBodyInsertPolicy := fpipBehindMethods;
@@ -174,7 +193,7 @@
 
     KeepForwardProcOrder := ForwardProcsKeepOrderCheckBox.Checked;
 
-    case UsesInsertPolicyRadioGroup.ItemIndex of
+    case UsesInsertPolicyComboBox.ItemIndex of
     0: UsesInsertPolicy:=uipFirst;
     1: UsesInsertPolicy:=uipInFrontOfRelated;
     2: UsesInsertPolicy:=uipBehindRelated;
@@ -182,6 +201,8 @@
     else UsesInsertPolicy:=uipAlphabetically;
     end;
 
+    EventMethodSection := TInsertMethodSection(EventMethodSectionComboBox.ItemIndex);
+
     UpdateMultiProcSignatures:=UpdateMultiProcSignaturesCheckBox.Checked;
     UpdateOtherProcSignaturesCase:=UpdateOtherProcSignaturesCaseCheckBox.Checked;
     GroupLocalVariables:=GroupLocalVariablesCheckBox.Checked;
Index: ide/lazarusidestrconsts.pas
===================================================================
--- ide/lazarusidestrconsts.pas	(revision 50022)
+++ ide/lazarusidestrconsts.pas	(working copy)
@@ -3639,6 +3639,10 @@
   lisAllBlocksLooksOk = 'All blocks look ok.';
   lisTheApplicationBundleWasCreatedFor = 'The Application Bundle was created for "%s"';
 
+  //codetools ChooseClassSectionDlg
+  lisChooseClassSectionDlgForMethodCaption = 'Insert new method to section';
+  lisEventMethodSectionLabel = 'Insert new event methods to section';
+
   // diff dialog
   lisDiffDlgFile1 = 'File1';
   lisDiffDlgOnlySelection = 'Only selection';
Index: ide/main.pp
===================================================================
--- ide/main.pp	(revision 50022)
+++ ide/main.pp	(working copy)
@@ -69,7 +69,7 @@
   // CodeTools
   FileProcs, FindDeclarationTool, LinkScanner, BasicCodeTools, CodeToolsStructs,
   CodeToolManager, CodeCache, DefineTemplates, KeywordFuncLists, CodeTree,
-  StdCodeTools,
+  StdCodeTools, ChooseMethodSectionDlg,
   // LazUtils
   // use lazutf8, lazfileutils and lazfilecache after FileProcs and FileUtil
   FileUtil, LazFileUtils, LazFileCache, LazUTF8, LazUTF8Classes, UTF8Process,

Ondrej Pokorny

2015-10-10 01:27

developer   ~0086405

Implemented. See patch.

I felt that the prompt dialog doesn't belong into the CodeTools package therefore I included it directly into the IDE.

Ondrej Pokorny

2015-10-10 01:50

developer  

ct-event-method-section-2.patch (35,716 bytes)
Index: components/codetools/codecompletiontool.pas
===================================================================
--- components/codetools/codecompletiontool.pas	(revision 50022)
+++ components/codetools/codecompletiontool.pas	(working copy)
@@ -124,6 +124,13 @@
     ctnClassPublished  // pcsPublished
   );
 
+  InsertMethodSectionToNewClassPart: array[TInsertMethodSectionResult] of TNewClassPart = (
+    ncpPrivateProcs,
+    ncpProtectedProcs,
+    ncpPublicProcs,
+    ncpPublishedProcs
+  );
+
 type
   TCodeCompletionCodeTool = class;
 
@@ -207,10 +214,10 @@
     procedure AdjustCursor(OldCodePos: TCodePosition; OldTopLine: integer;
                           out NewPos: TCodeXYPosition; out NewTopLine: integer);
     procedure AddNeededUnitToMainUsesSection(AnUnitName: PChar);
-    procedure AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
+    function AddMethodCompatibleToProcType(AClassNode: TCodeTreeNode;
                   const AnEventName: string; ProcContext: TFindContext; out
                   MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
-                  SourceChangeCache: TSourceChangeCache);
+                  SourceChangeCache: TSourceChangeCache): Boolean;
     procedure AddProcedureCompatibleToProcType(
                   const NewProcName: string; ProcContext: TFindContext; out
                   MethodDefinition: string; out MethodAttr: TProcHeadAttributes;
@@ -1363,14 +1370,17 @@
   Pointer(s):=nil;
 end;
 
-procedure TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
+function TCodeCompletionCodeTool.AddMethodCompatibleToProcType(
   AClassNode: TCodeTreeNode; const AnEventName: string;
   ProcContext: TFindContext; out MethodDefinition: string; out
-  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache);
+  MethodAttr: TProcHeadAttributes; SourceChangeCache: TSourceChangeCache
+  ): Boolean;
 var
   CleanMethodDefinition: string;
   Beauty: TBeautifyCodeOptions;
+  MethodSection: TInsertMethodSectionResult;
 begin
+  Result := False;
   MethodDefinition:='';
   MethodAttr:=[];
 
@@ -1402,8 +1412,10 @@
   {$ENDIF}
   if not ProcExistsInCodeCompleteClass(CleanMethodDefinition) then begin
     // insert method definition into class
+    if not Beauty.GetRealEventMethodSection(MethodSection) then
+      Exit;
     AddClassInsertion(CleanMethodDefinition, MethodDefinition,
-                      AnEventName, ncpPublishedProcs);
+                      AnEventName, InsertMethodSectionToNewClassPart[MethodSection]);
   end;
   MethodDefinition:=Beauty.AddClassAndNameToProc(MethodDefinition,
                    ExtractClassName(AClassNode,false,true), AnEventName);
@@ -1413,6 +1425,7 @@
   // insert all missing proc bodies
   if not CreateMissingClassProcBodies(false) then
     RaiseException(ctsErrorDuringCreationOfNewProcBodies);
+  Result := True;
 end;
 
 procedure TCodeCompletionCodeTool.AddProcedureCompatibleToProcType(
@@ -2145,8 +2158,10 @@
         if FullEventName='' then exit;
 
         // add published method and method body and right side of assignment
-        AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
-          AMethodDefinition,AMethodAttr,SourceChangeCache);
+        if not AddMethodCompatibleToProcType(AClassNode,FullEventName,ProcContext,
+          AMethodDefinition,AMethodAttr,SourceChangeCache)
+        then
+          Exit;
         if not CompleteAssignment(FullEventName,AssignmentOperator,
           AddrOperatorPos,SemicolonPos,UserEventAtom)
         then
@@ -2293,8 +2308,10 @@
     ProcContext:=CreateFindContext(TypeTool,TypeNode);
 
     // create new method
-    AddMethodCompatibleToProcType(AClassNode,Identifier,
-      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache);
+    if not AddMethodCompatibleToProcType(AClassNode,Identifier,
+      ProcContext,AMethodDefinition,AMethodAttr,SourceChangeCache)
+    then
+      Exit;
 
     // apply the changes
     if not SourceChangeCache.Apply then
Index: components/codetools/sourcechanger.pas
===================================================================
--- components/codetools/sourcechanger.pas	(revision 50022)
+++ components/codetools/sourcechanger.pas	(working copy)
@@ -59,6 +59,21 @@
     mipClassOrder      // try to copy the order of the class
     );
     
+  //where to add created methods from event assignment: "OnClick := @MyNewProc;"
+  TInsertMethodSection = (
+    imsPrivate,
+    imsProtected,
+    imsPublic,
+    imsPublished,
+    imsPrompt //show dialog prompt
+    );
+  TInsertMethodSectionResult = (
+    imsrPrivate,
+    imsrProtected,
+    imsrPublic,
+    imsrPublished
+  );
+
   TForwardProcBodyInsertPolicy = (
     fpipLast,
     fpipInFrontOfMethods,
@@ -90,7 +105,16 @@
 
 const
   DefaultUsesInsertPolicy = uipBehindRelated;
+  DefaultEventMethodSection = imsPrompt;
 
+  InsertMethodSectionToResult: array[TInsertMethodSection] of TInsertMethodSectionResult = (
+    imsrPrivate,
+    imsrProtected,
+    imsrPublic,
+    imsrPublished,
+    imsrPrivate
+    );
+
 type
   TWordPolicyException = class
     Word: string;
@@ -157,6 +181,7 @@
     ClassPartInsertPolicy: TClassPartInsertPolicy;
     MixMethodsAndProperties: boolean;
     MethodInsertPolicy: TMethodInsertPolicy;
+    EventMethodSection: TInsertMethodSection;
     PropertyReadIdentPrefix: string;
     PropertyWriteIdentPrefix: string;
     PropertyStoredIdentPostfix: string;
@@ -169,6 +194,7 @@
     
     NestedComments: boolean;
 
+    function GetRealEventMethodSection(out Section: TInsertMethodSectionResult): Boolean; //in case of imsPrompt show a dialog and return a "normal" section; returns true if OK, false if canceled
     function GetIndentStr(TheIndent: integer): string; inline;
     function GetLineIndent(const Source: string; Position: integer): integer; inline;
     procedure SetupWordPolicyExceptions(ws: TStrings);
@@ -328,7 +354,15 @@
   MethodInsertPolicyNames: array[TMethodInsertPolicy] of shortstring = (
       'Alphabetically', 'Last', 'ClassOrder'
     );
-    
+
+  InsertMethodSectionNames: array[TInsertMethodSection] of ShortString = (
+    'Private', 'Protected', 'Public', 'Published', 'Prompt'
+    );
+
+  InsertMethodSectionResultNames: array[TInsertMethodSectionResult] of ShortString = (
+    'Private', 'Protected', 'Public', 'Published'
+    );
+
   ForwardProcBodyInsertPolicyNames: array[TForwardProcBodyInsertPolicy] of
     shortstring = (
       'Last',
@@ -352,11 +386,18 @@
   DefaultDoNotInsertSpaceInFront: TAtomTypes = [];
   DefaultDoNotInsertSpaceAfter: TAtomTypes = [atDirectiveStart];
 
+type
+  TShowEventMethodSectionPromptFunc = function(out Section: TInsertMethodSectionResult): Boolean;
+var
+  ShowEventMethodSectionPrompt: TShowEventMethodSectionPromptFunc = nil;
+
 function AtomTypeNameToType(const s: string): TAtomType;
 function AtomTypesToStr(const AtomTypes: TAtomTypes): string;
 function WordPolicyNameToPolicy(const s: string): TWordPolicy;
 function ClassPartPolicyNameToPolicy(const s: string): TClassPartInsertPolicy;
 function MethodInsertPolicyNameToPolicy(const s: string): TMethodInsertPolicy;
+function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
+function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
 function ForwardProcBodyInsertPolicyNameToPolicy(
   const s: string): TForwardProcBodyInsertPolicy;
 function UsesInsertPolicyNameToPolicy(const s: string): TUsesInsertPolicy;
@@ -409,6 +450,20 @@
   Result:=mipLast;
 end;
 
+function InsertMethodSectionNameToSection(const s: string): TInsertMethodSection;
+begin
+  for Result:=Low(TInsertMethodSection) to High(TInsertMethodSection) do
+    if SysUtils.CompareText(InsertMethodSectionNames[Result],s)=0 then exit;
+  Result:=DefaultEventMethodSection;
+end;
+
+function InsertMethodSectionResultNameToSection(const s: string): TInsertMethodSectionResult;
+begin
+  for Result:=Low(TInsertMethodSectionResult) to High(TInsertMethodSectionResult) do
+    if SysUtils.CompareText(InsertMethodSectionResultNames[Result],s)=0 then exit;
+  Result:=imsrPrivate;
+end;
+
 function ForwardProcBodyInsertPolicyNameToPolicy(
   const s: string): TForwardProcBodyInsertPolicy;
 begin
@@ -1259,6 +1314,7 @@
   UpdateOtherProcSignaturesCase:=true;
   GroupLocalVariables:=true;
   MethodInsertPolicy:=mipClassOrder;
+  EventMethodSection:=DefaultEventMethodSection;
   ForwardProcBodyInsertPolicy:=fpipBehindMethods;
   KeepForwardProcOrder:=true;
   ClassHeaderComments:=true;
@@ -1685,6 +1741,21 @@
     Result:=false;
 end;
 
+function TBeautifyCodeOptions.GetRealEventMethodSection(out
+  Section: TInsertMethodSectionResult): Boolean;
+begin
+  Result := True;
+  if (EventMethodSection <> imsPrompt) then
+    Section := InsertMethodSectionToResult[EventMethodSection]
+  else
+  begin
+    if Assigned(ShowEventMethodSectionPrompt) then
+      Result := ShowEventMethodSectionPrompt(Section)
+    else
+      Section := InsertMethodSectionToResult[DefaultEventMethodSection];
+  end;
+end;
+
 procedure TBeautifyCodeOptions.SetupWordPolicyExceptions(ws: TStrings);
 begin
   if Assigned(WordExceptions) then WordExceptions.Free;
Index: ide/choosemethodsectiondlg.lfm
===================================================================
--- ide/choosemethodsectiondlg.lfm	(nonexistent)
+++ ide/choosemethodsectiondlg.lfm	(working copy)
@@ -0,0 +1,45 @@
+object ChooseMethodSectionDialog: TChooseMethodSectionDialog
+  Left = 460
+  Height = 177
+  Top = 220
+  Width = 252
+  BorderStyle = bsDialog
+  Caption = 'ChooseMethodSectionDialog'
+  ClientHeight = 177
+  ClientWidth = 252
+  KeyPreview = True
+  OnKeyPress = FormKeyPress
+  Position = poDesktopCenter
+  LCLVersion = '1.5'
+  object SectionsListBox: TListBox
+    Left = 10
+    Height = 117
+    Top = 10
+    Width = 232
+    Align = alClient
+    BorderSpacing.Left = 10
+    BorderSpacing.Top = 10
+    BorderSpacing.Right = 10
+    BorderSpacing.Bottom = 10
+    ItemHeight = 0
+    OnDblClick = SectionsListBoxDblClick
+    OnKeyPress = SectionsListBoxKeyPress
+    TabOrder = 0
+  end
+  object ButtonPanel: TButtonPanel
+    Left = 6
+    Height = 34
+    Top = 137
+    Width = 240
+    OKButton.Name = 'OKButton'
+    OKButton.DefaultCaption = True
+    HelpButton.Name = 'HelpButton'
+    HelpButton.DefaultCaption = True
+    CloseButton.Name = 'CloseButton'
+    CloseButton.DefaultCaption = True
+    CancelButton.Name = 'CancelButton'
+    CancelButton.DefaultCaption = True
+    TabOrder = 1
+    ShowButtons = [pbOK]
+  end
+end
Index: ide/choosemethodsectiondlg.pas
===================================================================
--- ide/choosemethodsectiondlg.pas	(nonexistent)
+++ ide/choosemethodsectiondlg.pas	(working copy)
@@ -0,0 +1,127 @@
+{
+ ***************************************************************************
+ *                                                                         *
+ *   This source is free software; you can redistribute it and/or modify   *
+ *   it under the terms of the GNU General Public License as published by  *
+ *   the Free Software Foundation; either version 2 of the License, or     *
+ *   (at your option) any later version.                                   *
+ *                                                                         *
+ *   This code 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.  See the GNU     *
+ *   General Public License for more details.                              *
+ *                                                                         *
+ *   A copy of the GNU General Public License is available on the World    *
+ *   Wide Web at <http://www.gnu.org/copyleft/gpl.html>. You can also      *
+ *   obtain it by writing to the Free Software Foundation,                 *
+ *   Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.        *
+ *                                                                         *
+ ***************************************************************************
+
+  Author: Ondrej Pokorny
+
+  Abstract:
+    A simple dialog to select class section.
+}
+unit ChooseMethodSectionDlg;
+
+{$mode objfpc}{$H+}
+
+interface
+
+uses
+  Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls,
+  ButtonPanel, SourceChanger, LazarusIDEStrConsts, EnvironmentOpts;
+
+type
+  //this dialog can easily be reused.
+  //for now it is used only in the method event assignment code creation
+
+  TChooseMethodSectionDialog = class(TForm)
+    ButtonPanel: TButtonPanel;
+    SectionsListBox: TListBox;
+    procedure FormKeyPress(Sender: TObject; var Key: char);
+    procedure SectionsListBoxDblClick(Sender: TObject);
+    procedure SectionsListBoxKeyPress(Sender: TObject; var Key: char);
+  protected
+    procedure DoCreate; override;
+  public
+
+  end;
+
+function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult;
+  out Section: TInsertMethodSectionResult): Boolean;
+function ShowEventMethodSectionDialog(out Section: TInsertMethodSectionResult): Boolean;
+
+implementation
+
+{$R *.lfm}
+
+function ChooseMethodSectionDialog(const ACaption: string; ADefault: TInsertMethodSectionResult;
+  out Section: TInsertMethodSectionResult): Boolean;
+var
+  Dlg: TChooseMethodSectionDialog;
+begin
+  Dlg := TChooseMethodSectionDialog.Create(Application);
+  try
+    Dlg.Caption := ACaption;
+    Dlg.PopupMode := pmAuto;
+    if Ord(ADefault) < Dlg.SectionsListBox.Count then
+      Dlg.SectionsListBox.ItemIndex := Ord(ADefault)
+    else
+      Dlg.SectionsListBox.ItemIndex := 0;
+    Result := Dlg.ShowModal = mrOK;
+    if Result then
+      Section := TInsertMethodSectionResult(Dlg.SectionsListBox.ItemIndex)
+    else
+      Section := imsrPrivate;
+  finally
+    Dlg.Free;
+  end;
+end;
+
+function ShowEventMethodSectionDialog(out Section: TInsertMethodSectionResult): Boolean;
+begin
+  Result := ChooseMethodSectionDialog(lisChooseClassSectionDlgForMethodCaption,
+    EnvironmentOptions.LastEventMethodSectionPrompt, Section);
+  if Result then
+    EnvironmentOptions.LastEventMethodSectionPrompt := Section;
+end;
+
+{ TChooseMethodSectionDialog }
+
+procedure TChooseMethodSectionDialog.DoCreate;
+begin
+  inherited DoCreate;
+
+  Assert(Ord(High(TInsertMethodSectionResult)) = 3,  'TChooseMethodSectionDialog.DoCreate: High(TInsertMethodSectionResult) <> 3');
+  SectionsListBox.Items.Add(lisPrivate);
+  SectionsListBox.Items.Add(lisProtected);
+  SectionsListBox.Items.Add(lisEMDPublic);
+  SectionsListBox.Items.Add(lisEMDPublished);
+end;
+
+procedure TChooseMethodSectionDialog.FormKeyPress(Sender: TObject;
+  var Key: char);
+begin
+  if Key = #27 then
+    ModalResult := mrCancel;
+end;
+
+procedure TChooseMethodSectionDialog.SectionsListBoxDblClick(Sender: TObject);
+begin
+  ModalResult := mrOK;
+end;
+
+procedure TChooseMethodSectionDialog.SectionsListBoxKeyPress(
+  Sender: TObject; var Key: char);
+begin
+  if Key = #13 then
+    ModalResult := mrOK;
+end;
+
+initialization
+  ShowEventMethodSectionPrompt := @ShowEventMethodSectionDialog;
+
+end.
+
Index: ide/codetoolsoptions.pas
===================================================================
--- ide/codetoolsoptions.pas	(revision 50022)
+++ ide/codetoolsoptions.pas	(working copy)
@@ -82,6 +82,7 @@
     FForwardProcBodyInsertPolicy: TForwardProcBodyInsertPolicy;
     FKeepForwardProcOrder: boolean;
     FMethodInsertPolicy: TMethodInsertPolicy;
+    FEventMethodSection: TInsertMethodSection;
     FKeyWordPolicy : TWordPolicy;
     FIdentifierPolicy: TWordPolicy;
     FUpdateAllMethodSignatures: boolean;
@@ -187,6 +188,8 @@
       read FClassImplementationComments write FClassImplementationComments;
     property MethodInsertPolicy: TMethodInsertPolicy
       read FMethodInsertPolicy write FMethodInsertPolicy;
+    property EventMethodSection: TInsertMethodSection
+      read FEventMethodSection write FEventMethodSection;
     property KeyWordPolicy : TWordPolicy
       read FKeyWordPolicy write FKeyWordPolicy;
     property IdentifierPolicy: TWordPolicy
@@ -459,6 +462,9 @@
     FMethodInsertPolicy:=MethodInsertPolicyNameToPolicy(XMLConfig.GetValue(
       'CodeToolsOptions/MethodInsertPolicy/Value',
       MethodInsertPolicyNames[mipClassOrder]));
+    FEventMethodSection:=InsertMethodSectionNameToSection(XMLConfig.GetValue(
+      'CodeToolsOptions/EventMethodSection/Value',
+      InsertMethodSectionNames[DefaultEventMethodSection]));
     FKeyWordPolicy:=WordPolicyNameToPolicy(XMLConfig.GetValue(
       'CodeToolsOptions/KeyWordPolicy/Value',
       WordPolicyNames[wpLowerCase]));
@@ -614,6 +620,9 @@
     XMLConfig.SetDeleteValue('CodeToolsOptions/MethodInsertPolicy/Value',
       MethodInsertPolicyNames[FMethodInsertPolicy],
       MethodInsertPolicyNames[mipClassOrder]);
+    XMLConfig.SetDeleteValue('CodeToolsOptions/EventMethodSection/Value',
+      InsertMethodSectionNames[FEventMethodSection],
+      InsertMethodSectionNames[DefaultEventMethodSection]);
     XMLConfig.SetDeleteValue('CodeToolsOptions/KeyWordPolicy/Value',
       WordPolicyNames[FKeyWordPolicy],
       WordPolicyNames[wpLowerCase]);
@@ -779,6 +788,7 @@
     FClassHeaderComments:=CodeToolsOpts.ClassHeaderComments;
     FClassImplementationComments:=CodeToolsOpts.ClassImplementationComments;
     FMethodInsertPolicy:=CodeToolsOpts.FMethodInsertPolicy;
+    FEventMethodSection:=CodeToolsOpts.FEventMethodSection;
     FKeyWordPolicy:=CodeToolsOpts.FKeyWordPolicy;
     FIdentifierPolicy:=CodeToolsOpts.FIdentifierPolicy;
     FDoNotSplitLineInFront:=CodeToolsOpts.FDoNotSplitLineInFront;
@@ -839,6 +849,7 @@
   FClassHeaderComments:=true;
   FClassImplementationComments:=true;
   FMethodInsertPolicy:=mipClassOrder;
+  FEventMethodSection:=DefaultEventMethodSection;
   FKeyWordPolicy:=wpLowerCase;
   FIdentifierPolicy:=wpNone;
   FDoNotSplitLineInFront:=DefaultDoNotSplitLineInFront;
@@ -917,6 +928,7 @@
     and (FClassHeaderComments=CodeToolsOpts.ClassHeaderComments)
     and (FClassImplementationComments=CodeToolsOpts.ClassImplementationComments)
     and (FMethodInsertPolicy=CodeToolsOpts.FMethodInsertPolicy)
+    and (FEventMethodSection=CodeToolsOpts.FEventMethodSection)
     and (FKeyWordPolicy=CodeToolsOpts.FKeyWordPolicy)
     and (FIdentifierPolicy=CodeToolsOpts.FIdentifierPolicy)
     and (FDoNotSplitLineInFront=CodeToolsOpts.FDoNotSplitLineInFront)
@@ -1037,6 +1049,7 @@
     Beauty.ClassHeaderComments:=ClassHeaderComments;
     Beauty.ClassImplementationComments:=ClassImplementationComments;
     Beauty.MethodInsertPolicy:=MethodInsertPolicy;
+    Beauty.EventMethodSection:=EventMethodSection;
     Beauty.KeyWordPolicy:=KeyWordPolicy;
     Beauty.IdentifierPolicy:=IdentifierPolicy;
     Beauty.SetupWordPolicyExceptions(WordPolicyExceptions);
Index: ide/environmentopts.pp
===================================================================
--- ide/environmentopts.pp	(revision 50022)
+++ ide/environmentopts.pp	(working copy)
@@ -39,7 +39,7 @@
 {$endif}
   Classes, SysUtils, TypInfo, contnrs, Graphics, Controls, Forms, Dialogs,
   LCLProc, FileProcs, LazFileUtils, LazFileCache, LazConfigStorage,
-  Laz2_XMLCfg, LazUTF8,
+  Laz2_XMLCfg, LazUTF8, SourceChanger,
   // IDEIntf
   ProjectIntf, ObjectInspector, IDEWindowIntf, IDEOptionsIntf,
   ComponentReg, IDEExternToolIntf, MacroDefIntf, DbgIntfDebuggerBase,
@@ -499,6 +499,9 @@
     // Prevent repopulating Recent project files menu with example projects if it was already cleared up.
     FAlreadyPopulatedRecentFiles : Boolean;
 
+    //other recent settings
+    FLastEventMethodSectionPrompt: TInsertMethodSectionResult;
+
     // backup
     FBackupInfoProjectFiles: TBackupInfo;
     FBackupInfoOtherFiles: TBackupInfo;
@@ -752,6 +755,10 @@
                                                                 write FMultipleInstances;
     property FileDialogFilter: string read FFileDialogFilter write FFileDialogFilter;
 
+    // other recent settings
+    property LastEventMethodSectionPrompt: TInsertMethodSectionResult
+      read FLastEventMethodSectionPrompt write FLastEventMethodSectionPrompt;
+
     // backup
     property BackupInfoProjectFiles: TBackupInfo read FBackupInfoProjectFiles
                                                  write FBackupInfoProjectFiles;
@@ -1347,6 +1354,9 @@
   FOpenLastProjectAtStart:=true;
   FMultipleInstances:=DefaultIDEMultipleInstancesOption;
 
+  // other recent settings
+  FLastEventMethodSectionPrompt:=InsertMethodSectionToResult[DefaultEventMethodSection];
+
   // backup
   with FBackupInfoProjectFiles do begin
     BackupType:=bakSameName;
@@ -1745,6 +1755,11 @@
 
     FAlreadyPopulatedRecentFiles := FXMLCfg.GetValue(Path+'Recent/AlreadyPopulated', false);
 
+    // other recent settings
+    FLastEventMethodSectionPrompt:=InsertMethodSectionResultNameToSection(FXMLCfg.GetValue(
+      'Recent/EventMethodSectionPrompt/Value',
+      InsertMethodSectionNames[DefaultEventMethodSection]));
+
     // Add example projects to an empty project list if examples have write access
     if (FRecentProjectFiles.count=0) and (not FAlreadyPopulatedRecentFiles) then begin
       AddRecentProjectInitial('examples/jpeg/',          'jpegexample.lpi');
@@ -2073,6 +2088,11 @@
 
     FXMLCfg.SetDeleteValue(Path+'Recent/AlreadyPopulated', FAlreadyPopulatedRecentFiles, false);
 
+    // other recent settings
+    FXMLCfg.SetDeleteValue('Recent/EventMethodSectionPrompt/Value',
+      InsertMethodSectionResultNames[FLastEventMethodSectionPrompt],
+      InsertMethodSectionResultNames[InsertMethodSectionToResult[DefaultEventMethodSection]]);
+
     // external tools
     fExternalUserTools.Save(FConfigStore,Path+'ExternalTools/');
     FXMLCfg.SetDeleteValue(Path+'ExternalTools/MaxInParallel',FMaxExtToolsInParallel,0);
Index: ide/frames/codetools_codecreation_options.lfm
===================================================================
--- ide/frames/codetools_codecreation_options.lfm	(revision 50022)
+++ ide/frames/codetools_codecreation_options.lfm	(working copy)
@@ -8,76 +8,27 @@
   TabOrder = 0
   Visible = False
   DesignLeft = 322
-  DesignTop = 184
-  object ForwardProcsInsertPolicyRadioGroup: TRadioGroup
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = Owner
-    AnchorSideRight.Control = Owner
-    AnchorSideRight.Side = asrBottom
-    Left = 6
-    Height = 100
-    Top = 6
-    Width = 554
-    Anchors = [akTop, akLeft, akRight]
-    AutoFill = True
-    BorderSpacing.Around = 6
-    Caption = 'ForwardProcsInsertPolicyRadioGroup'
-    ChildSizing.LeftRightSpacing = 6
-    ChildSizing.TopBottomSpacing = 6
-    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
-    ChildSizing.EnlargeVertical = crsHomogenousChildResize
-    ChildSizing.ShrinkHorizontal = crsScaleChilds
-    ChildSizing.ShrinkVertical = crsScaleChilds
-    ChildSizing.Layout = cclLeftToRightThenTopToBottom
-    ChildSizing.ControlsPerLine = 1
-    TabOrder = 0
-  end
+  DesignTop = 167
   object ForwardProcsKeepOrderCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = ForwardProcsInsertPolicyRadioGroup
+    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 112
+    Top = 45
     Width = 200
-    BorderSpacing.Around = 6
+    BorderSpacing.Left = 6
+    BorderSpacing.Top = 6
     Caption = 'ForwardProcsKeepOrderCheckBox'
     TabOrder = 1
   end
-  object UsesInsertPolicyRadioGroup: TRadioGroup
-    AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
-    AnchorSideTop.Side = asrBottom
-    AnchorSideRight.Control = Owner
-    AnchorSideRight.Side = asrBottom
-    Left = 6
-    Height = 100
-    Top = 143
-    Width = 554
-    Anchors = [akTop, akLeft, akRight]
-    AutoFill = True
-    AutoSize = True
-    BorderSpacing.Top = 6
-    BorderSpacing.Around = 6
-    Caption = 'UsesInsertPolicyRadioGroup'
-    ChildSizing.LeftRightSpacing = 6
-    ChildSizing.TopBottomSpacing = 6
-    ChildSizing.EnlargeHorizontal = crsHomogenousChildResize
-    ChildSizing.EnlargeVertical = crsHomogenousChildResize
-    ChildSizing.ShrinkHorizontal = crsScaleChilds
-    ChildSizing.ShrinkVertical = crsScaleChilds
-    ChildSizing.Layout = cclLeftToRightThenTopToBottom
-    ChildSizing.ControlsPerLine = 1
-    Constraints.MinHeight = 100
-    TabOrder = 2
-  end
   object UpdateMultiProcSignaturesCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
-    AnchorSideTop.Control = UsesInsertPolicyRadioGroup
+    AnchorSideTop.Control = UsesInsertPolicyComboBox
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 249
+    Top = 99
     Width = 217
     BorderSpacing.Left = 6
     BorderSpacing.Top = 6
@@ -90,7 +41,7 @@
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 268
+    Top = 118
     Width = 244
     BorderSpacing.Left = 6
     Caption = 'UpdateOtherProcSignaturesCaseCheckBox'
@@ -102,7 +53,7 @@
     AnchorSideTop.Side = asrCenter
     Left = 6
     Height = 15
-    Top = 316
+    Top = 195
     Width = 95
     Caption = 'TemplateFileLabel'
     ParentColor = False
@@ -110,16 +61,17 @@
   object TemplateFileEdit: TEdit
     AnchorSideLeft.Control = TemplateFileLabel
     AnchorSideLeft.Side = asrBottom
-    AnchorSideTop.Control = GroupLocalVariablesCheckBox
+    AnchorSideTop.Control = EventMethodSectionComboBox
     AnchorSideTop.Side = asrBottom
     AnchorSideRight.Control = TemplateFileBrowseButton
-    Left = 101
+    Left = 107
     Height = 23
-    Top = 312
-    Width = 424
+    Top = 191
+    Width = 418
     Anchors = [akTop, akLeft, akRight]
+    BorderSpacing.Left = 6
     BorderSpacing.Top = 6
-    TabOrder = 6
+    TabOrder = 7
     Text = 'TemplateFileEdit'
   end
   object TemplateFileBrowseButton: TButton
@@ -130,7 +82,7 @@
     AnchorSideBottom.Side = asrBottom
     Left = 525
     Height = 23
-    Top = 312
+    Top = 191
     Width = 35
     Anchors = [akTop, akRight, akBottom]
     AutoSize = True
@@ -137,7 +89,7 @@
     BorderSpacing.Right = 6
     Caption = '...'
     OnClick = TemplateFileBrowseButtonClick
-    TabOrder = 7
+    TabOrder = 8
   end
   object GroupLocalVariablesCheckBox: TCheckBox
     AnchorSideLeft.Control = Owner
@@ -145,10 +97,88 @@
     AnchorSideTop.Side = asrBottom
     Left = 6
     Height = 19
-    Top = 287
+    Top = 137
     Width = 180
     BorderSpacing.Left = 6
     Caption = 'GroupLocalVariablesCheckBox'
     TabOrder = 5
   end
+  object ForwardProcsInsertPolicyComboBox: TComboBox
+    AnchorSideLeft.Control = ForwardProcsInsertPolicyLabel
+    AnchorSideLeft.Side = asrBottom
+    Left = 173
+    Height = 23
+    Top = 16
+    Width = 170
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 0
+  end
+  object ForwardProcsInsertPolicyLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = ForwardProcsInsertPolicyComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = ForwardProcsInsertPolicyComboBox
+    Left = 6
+    Height = 15
+    Top = 20
+    Width = 161
+    BorderSpacing.Around = 6
+    Caption = 'ForwardProcsInsertPolicyLabel'
+    ParentColor = False
+  end
+  object UsesInsertPolicyLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = UsesInsertPolicyComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = UsesInsertPolicyComboBox
+    Left = 6
+    Height = 15
+    Top = 74
+    Width = 113
+    BorderSpacing.Around = 6
+    Caption = 'UsesInsertPolicyLabel'
+    ParentColor = False
+  end
+  object UsesInsertPolicyComboBox: TComboBox
+    AnchorSideLeft.Control = UsesInsertPolicyLabel
+    AnchorSideLeft.Side = asrBottom
+    AnchorSideTop.Control = ForwardProcsKeepOrderCheckBox
+    AnchorSideTop.Side = asrBottom
+    Left = 125
+    Height = 23
+    Top = 70
+    Width = 170
+    BorderSpacing.Top = 6
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 2
+  end
+  object EventMethodSectionLabel: TLabel
+    AnchorSideLeft.Control = Owner
+    AnchorSideTop.Control = EventMethodSectionComboBox
+    AnchorSideTop.Side = asrCenter
+    AnchorSideRight.Control = EventMethodSectionComboBox
+    Left = 6
+    Height = 15
+    Top = 166
+    Width = 138
+    BorderSpacing.Around = 6
+    Caption = 'EventMethodSectionLabel'
+    ParentColor = False
+  end
+  object EventMethodSectionComboBox: TComboBox
+    AnchorSideLeft.Control = EventMethodSectionLabel
+    AnchorSideLeft.Side = asrBottom
+    AnchorSideTop.Control = GroupLocalVariablesCheckBox
+    AnchorSideTop.Side = asrBottom
+    Left = 150
+    Height = 23
+    Top = 162
+    Width = 170
+    BorderSpacing.Top = 6
+    ItemHeight = 15
+    Style = csDropDownList
+    TabOrder = 6
+  end
 end
Index: ide/frames/codetools_codecreation_options.pas
===================================================================
--- ide/frames/codetools_codecreation_options.pas	(revision 50022)
+++ ide/frames/codetools_codecreation_options.pas	(working copy)
@@ -34,8 +34,12 @@
   { TCodetoolsCodeCreationOptionsFrame }
 
   TCodetoolsCodeCreationOptionsFrame = class(TAbstractIDEOptionsEditor)
-    ForwardProcsInsertPolicyRadioGroup: TRadioGroup;
+    ForwardProcsInsertPolicyComboBox: TComboBox;
+    UsesInsertPolicyComboBox: TComboBox;
     ForwardProcsKeepOrderCheckBox: TCheckBox;
+    ForwardProcsInsertPolicyLabel: TLabel;
+    EventMethodSectionComboBox: TComboBox;
+    UsesInsertPolicyLabel: TLabel;
     TemplateFileBrowseButton: TButton;
     TemplateFileEdit: TEdit;
     TemplateFileLabel: TLabel;
@@ -42,7 +46,7 @@
     UpdateMultiProcSignaturesCheckBox: TCheckBox;
     UpdateOtherProcSignaturesCaseCheckBox: TCheckBox;
     GroupLocalVariablesCheckBox: TCheckBox;
-    UsesInsertPolicyRadioGroup: TRadioGroup;
+    EventMethodSectionLabel: TLabel;
     procedure TemplateFileBrowseButtonClick(Sender: TObject);
   private
   public
@@ -87,8 +91,8 @@
 procedure TCodetoolsCodeCreationOptionsFrame.Setup(
   ADialog: TAbstractOptionsEditorDialog);
 begin
-  with ForwardProcsInsertPolicyRadioGroup do begin
-    Caption:=dlgForwardProcsInsertPolicy;
+  ForwardProcsInsertPolicyLabel.Caption:=dlgForwardProcsInsertPolicy;
+  with ForwardProcsInsertPolicyComboBox do begin
     with Items do begin
       BeginUpdate;
       Add(dlgLast);
@@ -100,8 +104,8 @@
 
   ForwardProcsKeepOrderCheckBox.Caption:=dlgForwardProcsKeepOrder;
 
-  with UsesInsertPolicyRadioGroup do begin
-    Caption:=lisNewUnitsAreAddedToUsesSections;
+  UsesInsertPolicyLabel.Caption:=lisNewUnitsAreAddedToUsesSections;
+  with UsesInsertPolicyComboBox do begin
     with Items do begin
       BeginUpdate;
       Add(lisFirst);
@@ -113,6 +117,20 @@
     end;
   end;
 
+  EventMethodSectionLabel.Caption:=lisEventMethodSectionLabel;
+  with EventMethodSectionComboBox do begin
+    Assert(Ord(High(TInsertMethodSectionResult)) = 3,  'TCodetoolsCodeCreationOptionsFrame.Setup: High(TInsertMethodSectionResult) <> 3');
+    with Items do begin
+      BeginUpdate;
+      Add(lisPrivate);
+      Add(lisProtected);
+      Add(lisEMDPublic);
+      Add(lisEMDPublished);
+      Add(lisPromptForValue);
+      EndUpdate;
+    end;
+  end;
+
   UpdateMultiProcSignaturesCheckBox.Caption:=
     lisCTOUpdateMultipleProcedureSignatures;
   UpdateOtherProcSignaturesCaseCheckBox.Caption:=
@@ -134,24 +152,25 @@
   with AOptions as TCodetoolsOptions do
   begin
     case ForwardProcBodyInsertPolicy of
-      fpipLast: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=0;
-      fpipInFrontOfMethods: ForwardProcsInsertPolicyRadioGroup.ItemIndex:=1;
+      fpipLast: ForwardProcsInsertPolicyComboBox.ItemIndex:=0;
+      fpipInFrontOfMethods: ForwardProcsInsertPolicyComboBox.ItemIndex:=1;
     else
       // fpipBehindMethods
-      ForwardProcsInsertPolicyRadioGroup.ItemIndex:=2;
+      ForwardProcsInsertPolicyComboBox.ItemIndex:=2;
     end;
 
     ForwardProcsKeepOrderCheckBox.Checked := KeepForwardProcOrder;
 
     case UsesInsertPolicy of
-    uipFirst:             UsesInsertPolicyRadioGroup.ItemIndex:=0;
-    uipInFrontOfRelated:  UsesInsertPolicyRadioGroup.ItemIndex:=1;
-    uipBehindRelated:     UsesInsertPolicyRadioGroup.ItemIndex:=2;
-    uipLast:              UsesInsertPolicyRadioGroup.ItemIndex:=3;
+    uipFirst:             UsesInsertPolicyComboBox.ItemIndex:=0;
+    uipInFrontOfRelated:  UsesInsertPolicyComboBox.ItemIndex:=1;
+    uipBehindRelated:     UsesInsertPolicyComboBox.ItemIndex:=2;
+    uipLast:              UsesInsertPolicyComboBox.ItemIndex:=3;
     else
       //uipAlphabetically:
-                          UsesInsertPolicyRadioGroup.ItemIndex:=4;
+                          UsesInsertPolicyComboBox.ItemIndex:=4;
     end;
+    EventMethodSectionComboBox.ItemIndex := Ord(EventMethodSection);
 
     UpdateMultiProcSignaturesCheckBox.Checked:=UpdateMultiProcSignatures;
     UpdateOtherProcSignaturesCaseCheckBox.Checked:=UpdateOtherProcSignaturesCase;
@@ -166,7 +185,7 @@
 begin
   with AOptions as TCodetoolsOptions do
   begin
-    case ForwardProcsInsertPolicyRadioGroup.ItemIndex of
+    case ForwardProcsInsertPolicyComboBox.ItemIndex of
       0: ForwardProcBodyInsertPolicy := fpipLast;
       1: ForwardProcBodyInsertPolicy := fpipInFrontOfMethods;
       2: ForwardProcBodyInsertPolicy := fpipBehindMethods;
@@ -174,7 +193,7 @@
 
     KeepForwardProcOrder := ForwardProcsKeepOrderCheckBox.Checked;
 
-    case UsesInsertPolicyRadioGroup.ItemIndex of
+    case UsesInsertPolicyComboBox.ItemIndex of
     0: UsesInsertPolicy:=uipFirst;
     1: UsesInsertPolicy:=uipInFrontOfRelated;
     2: UsesInsertPolicy:=uipBehindRelated;
@@ -182,6 +201,8 @@
     else UsesInsertPolicy:=uipAlphabetically;
     end;
 
+    EventMethodSection := TInsertMethodSection(EventMethodSectionComboBox.ItemIndex);
+
     UpdateMultiProcSignatures:=UpdateMultiProcSignaturesCheckBox.Checked;
     UpdateOtherProcSignaturesCase:=UpdateOtherProcSignaturesCaseCheckBox.Checked;
     GroupLocalVariables:=GroupLocalVariablesCheckBox.Checked;
Index: ide/lazarusidestrconsts.pas
===================================================================
--- ide/lazarusidestrconsts.pas	(revision 50022)
+++ ide/lazarusidestrconsts.pas	(working copy)
@@ -3639,6 +3639,10 @@
   lisAllBlocksLooksOk = 'All blocks look ok.';
   lisTheApplicationBundleWasCreatedFor = 'The Application Bundle was created for "%s"';
 
+  //codetools ChooseClassSectionDlg
+  lisChooseClassSectionDlgForMethodCaption = 'Insert new method to section';
+  lisEventMethodSectionLabel = 'Insert new event methods to section';
+
   // diff dialog
   lisDiffDlgFile1 = 'File1';
   lisDiffDlgOnlySelection = 'Only selection';
Index: ide/main.pp
===================================================================
--- ide/main.pp	(revision 50022)
+++ ide/main.pp	(working copy)
@@ -69,7 +69,7 @@
   // CodeTools
   FileProcs, FindDeclarationTool, LinkScanner, BasicCodeTools, CodeToolsStructs,
   CodeToolManager, CodeCache, DefineTemplates, KeywordFuncLists, CodeTree,
-  StdCodeTools,
+  StdCodeTools, ChooseMethodSectionDlg,
   // LazUtils
   // use lazutf8, lazfileutils and lazfilecache after FileProcs and FileUtil
   FileUtil, LazFileUtils, LazFileCache, LazUTF8, LazUTF8Classes, UTF8Process,

Issue History

Date Modified Username Field Change
2009-06-17 09:29 Graeme Geldenhuys New Issue
2009-06-17 09:35 Vincent Snijders LazTarget => post 1.2
2009-06-17 09:35 Vincent Snijders Status new => acknowledged
2009-06-17 11:52 Martin Friebe Relationship added related to 0013937
2009-06-17 13:21 Mattias Gaertner Relationship deleted related to 0013937
2013-09-03 12:07 Martin Friebe LazTarget post 1.2 => 1.4
2014-09-10 16:15 Juha Manninen LazTarget 1.4 => -
2015-10-10 01:26 Ondrej Pokorny File Added: ct-event-method-section-1.patch
2015-10-10 01:27 Ondrej Pokorny Note Added: 0086405
2015-10-10 01:50 Ondrej Pokorny File Added: ct-event-method-section-2.patch
2015-10-29 12:15 Ondrej Pokorny Assigned To => Ondrej Pokorny
2015-10-29 12:15 Ondrej Pokorny Status acknowledged => assigned
2015-10-29 12:17 Ondrej Pokorny Fixed in Revision => 50197
2015-10-29 12:17 Ondrej Pokorny Status assigned => resolved
2015-10-29 12:17 Ondrej Pokorny Fixed in Version => 1.5 (SVN)
2015-10-29 12:17 Ondrej Pokorny Resolution open => fixed