Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Mailing lists / lazarus / 2011-05

Tweaking 'code completion' for event handlers

14 messages · 6 people ·

Reply by email Subscribe to this list Your subscription

Read-only archive. Use j and k to move between messages.

Graeme Geldenhuys

Hi,

I report a related issue already in the Bug Tracker back in 2009:

http://bugs.freepascal.org/view.php?id=13994

No solution has been implemented in Lazarus yet. As a work-around, is there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, to only generate the code in the interface of the unit, and not the implementation section?

I like to keep my code implementation in the same order as I have it defined in the Class definition (as defined in Code Tools settings: Method Insert Policy = class order). Currently it place the event handler method always in the undefined published section of my class, and thus the implementation of that method is in the wrong place too. So writing the event handler code, then ask Code Completion to implement the event handler method, I would prefer it (while bug 8135 is not fixed) if Code Tools could only write the method in the interface section only. I can then manually move it to the correct location in my class definition, then do Code Completion again, to implement the interface section in the correct location.

Is this possible in Lazarus IDE 0.9.30.x? I can't see an obvious option in Code Tools to adjust this, so I guess the answer is No. I just thought it worth asking to be sure though.

----8<-------------8<-------------8<-------------8<-------------8<----
  TKeyGenerateForm = class(TfpgForm)
    procedure   meKeyPhraseChanged(Sender: TObject); //<< WRONG LOCATION
  private
     KeyGenerateForm}
    Label1: TfpgLabel;
    cbKeyType: TfpgComboBox;
    btnOK: TfpgButton;
    btnCancel: TfpgButton;
    btnGenerateKey: TfpgButton;
    Label2: TfpgLabel;
    memKeyPhrase: TfpgMemo;
    Label3: TfpgLabel;
    edtBlockKey: TfpgEdit;
    edtByteBlockKey: TfpgEdit;
     KeyGenerateForm}
    FKey: TKey;
    FKeyType: TKeyType;
    procedure   SetKeyType(AValue: TKeyType);
    procedure   FormCreate(Sender: TObject);
    procedure   FormShow(Sender: TObject);
    procedure   cbKeyTypeChanged(Sender: TObject);
  public
    constructor Create(AOwner: TComponent); override;
    procedure   AfterCreate; override;
    procedure   SetKey(AValue: TKey);
    procedure   GetKey(var AValue: TKey);
    property    KeyType: TKeyType read FKeyType write SetKeyType;
  end;

----8<-------------8<-------------8<-------------8<-------------8<----

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Mattias Gaertner
to Graeme Geldenhuys

?
?

Graeme Geldenhuys hat am 13. Mai 2011 um 09:48
geschrieben:

Show quoted text 10 lines
Hi, I report a related issue already in the Bug Tracker back in 2009: ? ? http://bugs.freepascal.org/view.php?id=13994 No solution has been implemented in Lazarus yet. As a work-around, is there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, to only generate the code in the interface of the unit, and not the implementation section??

Not yet.
I will add the checkbox for the implementation to my todo list.

Show quoted text 16 lines
I like to keep my code implementation in the same order as I have it defined in the Class definition (as defined in Code Tools settings: Method Insert Policy = class order). Currently it place the event handler method always in the undefined published section of my class, and thus the implementation of that method is in the wrong place too. So writing the event handler code, then ask Code Completion to implement the event handler method, I would prefer it (while bug 8135 is not fixed) if Code Tools could only write the method in the interface section only. I can then manually move it to the correct location in my class definition, then do Code Completion again, to implement the interface section in the correct location. Is this possible in Lazarus IDE 0.9.30.x? I can't see an obvious option in Code Tools to adjust this, so I guess the answer is No. I just thought it worth asking to be sure though.?

?
Mattias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/cd29723f/attachment.html>

Reply by email

Martin
to Mattias Gaertner
Mattias Gaertner wrote 14 lines
Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: > http://bugs.freepascal.org/view.php?id=13994 > > No solution has been implemented in Lazarus yet. As a work-around, is > there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, > to only generate the code in the interface of the unit, and not the > implementation section? Not yet. I will add the checkbox for the implementation to my todo list.

That reminds me of an idea, a feature I would like. And that would solve this too.

It would be cool if one could with a single copy (or cut; as in copy/paste) copy a method (or procedure/function) declaration, including the implementation.
Or even several methods, if one selects several lines in the interface.

This would/should allow to:
- copy/cut paste a method from one place in a class to another place in the same class (adjusting order of implementation too)
- copy/cut paste a method from one class to any other class (adjusting the classname in the "procedure FOOCLASS.metho" line) This one would hugely add to the ability of refactoring, moving things up/down in the class hierachy, or even to rlated classes
- copy/cut paste a plain procedure into a class, making it a method
- copy/cut paste a method to become a plain procedure. So this one still requires some clean up, for any reference to self

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/2e221fec/attachment.html>

Reply by email

Michael Van Canneyt
to Martin
Martin wrote 29 lines
On 13/05/2011 10:03, Mattias Gaertner wrote: Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: >? ? http://bugs.freepascal.org/view.php?id=13994 > > No solution has been implemented in Lazarus yet. As a work-around, is > there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, > to only generate the code in the interface of the unit, and not the > implementation section? ? Not yet. I will add the checkbox for the implementation to my todo list. That reminds me of an idea, a feature I would like. And that would solve this too. It would be cool if one could with a single copy (or cut; as in copy/paste) copy a method (or procedure/function) declaration, including the implementation. Or even several methods, if one selects several lines in the interface. This would/should allow to: - copy/cut paste a method from one place in a class to another place in the same class (adjusting order of implementation too) - copy/cut paste a method from one class to any other class (adjusting the classname in the "procedure FOOCLASS.metho" line) ? This one would hugely add to the ability of refactoring, moving things up/down in the class hierachy, or even to rlated classes - copy/cut paste a plain procedure into a class, making it a method - copy/cut paste a method to become a plain procedure. So this one still requires some clean up, for any reference to self

I'm all for this one. A 'Remove method/procedure' and 'Insert method/procedure'.

As long as it doesn't interfere with regular copy&paste.

Michael.

Reply by email

Alexsander Rosa
to Mattias Gaertner: ? ? Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: Not yet. I will add the…

I wish something like this:

//--- into form's private/public/etc
a, b, c: TMyClass;
(some keys are pressed)
...FormCreate...
a := TMyClass.Create;
b := TMyClass.Create;
c := TMyClass.Create;
...FormDestroy
a.Free;
b.Free;
c.Free;

2011/5/13 Mattias Gaertner

Show quoted text 53 lines
Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: > Hi, > > I report a related issue already in the Bug Tracker back in 2009: > > http://bugs.freepascal.org/view.php?id=13994 > > No solution has been implemented in Lazarus yet. As a work-around, is > there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, > to only generate the code in the interface of the unit, and not the > implementation section? Not yet. I will add the checkbox for the implementation to my todo list. > > I like to keep my code implementation in the same order as I have it > defined in the Class definition (as defined in Code Tools settings: > Method Insert Policy = class order). Currently it place the event > handler method always in the undefined published section of my class, > and thus the implementation of that method is in the wrong place too. So > writing the event handler code, then ask Code Completion to implement > the event handler method, I would prefer it (while bug 8135 is not > fixed) if Code Tools could only write the method in the interface > section only. I can then manually move it to the correct location in my > class definition, then do Code Completion again, to implement the > interface section in the correct location. > > Is this possible in Lazarus IDE 0.9.30.x? I can't see an obvious option > in Code Tools to adjust this, so I guess the answer is No. I just > thought it worth asking to be sure though. Mattias -- _______________________________________________ Lazarus mailing list http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus
Atenciosamente, Alexsander da Rosa http://rednaxel.com -------------- next part -------------- An HTML attachment was scrubbed... URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/9c71df75/attachment.html>

Reply by email

Mattias Gaertner
to Michael Van Canneyt: I'm all for this one. A 'Remove method/procedure' and 'Insert method/procedure'. As long…

?
?

Michael Van Canneyt hat am 13. Mai 2011 um 12:55
geschrieben:

Show quoted text 45 lines
On Fri, 13 May 2011, Martin wrote: > On 13/05/2011 10:03, Mattias Gaertner wrote: >? ? ? ?Graeme Geldenhuys hat am 13. Mai 2011 um >09:48 geschrieben: > >? ? ? ?>? ? http://bugs.freepascal.org/view.php?id=13994 >? ? ? ?> >? ? ? ?> No solution has been implemented in Lazarus yet. As a work-around, >is >? ? ? ?> there any way to tell Code Completion (Ctrl+Shift+C) for event >handlers, >? ? ? ?> to only generate the code in the interface of the unit, and not the >? ? ? ?> implementation section? > > ? > > Not yet. > > I will add the checkbox for the implementation to my todo list. > > > That reminds me of an idea, a feature I would like. And that would solve > this too. > > It would be cool if one could with a single copy (or cut; as in copy/paste) > copy a method (or procedure/function) declaration, including the > implementation. > Or even several methods, if one selects several lines in the interface. > > This would/should allow to: > - copy/cut paste a method from one place in a class to another place in the > same class (adjusting order of implementation too) > - copy/cut paste a method from one class to any other class (adjusting the > classname in the "procedure FOOCLASS.metho" line) > ? This one would hugely add to the ability of refactoring, moving things > up/down in the class hierachy, or even to rlated classes > - copy/cut paste a plain procedure into a class, making it a method > - copy/cut paste a method to become a plain procedure. So this one still > requires some clean up, for any reference to self I'm all for this one. A 'Remove method/procedure' and 'Insert method/procedure'.?

Good idea.
?

As long as it doesn't interfere with regular copy&paste.

I agree, it should not use the Cut/Copy shortcuts. But I see no problem with Paste. Do you see one?

Mattias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/9a01420d/attachment.html>

Reply by email

Graeme Geldenhuys
to Alexsander Rosa: I wish something like this: //--- into form's private/public/etc a, b, c: TMyClass; (some…
Alexsander Rosa wrote 15 lines
I wish something like this: //--- into form's private/public/etc a, b, c: TMyClass; (some keys are pressed) ...FormCreate... a := TMyClass.Create; b := TMyClass.Create; c := TMyClass.Create; ...FormDestroy a.Free; b.Free; c.Free;

That would be very specific to LCL TForm descendants only. Not a general class definition or even forms from other toolkits like fpGUI. Why? Because only LCL forms have the generic FormCreate() and FormDestry() methods. And those identifier names are not even a must either, I can name my LCL.TForm.OnCreate and .OnDestroy event handlers whatever I want.

Maybe you should play with the Code Templates with macros enabled. They are pretty powerful. I have macros here that create multiple classes and associated list classes from simply copying a single word into the clipboard and triggering the macro.

But who knows, maybe the Lazarus Wizards can conjure up something for you. :)

Regards,
- Graeme -

fpGUI Toolkit - a cross-platform GUI toolkit using Free Pascal http://fpgui.sourceforge.net/

Reply by email

Martin
to Mattias Gaertner: ? ? Michael Van Canneyt hat am 13. Mai 2011 um 12:55 geschrieben: Good idea. ? I agree,…
Mattias Gaertner wrote 59 lines
Michael Van Canneyt hat am 13. Mai 2011 um 12:55 geschrieben: > > > On Fri, 13 May 2011, Martin wrote: > > > On 13/05/2011 10:03, Mattias Gaertner wrote: > > Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: > > > > > http://bugs.freepascal.org/view.php?id=13994 > > > > > > No solution has been implemented in Lazarus yet. As a work-around, is > > > there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, > > > to only generate the code in the interface of the unit, and not the > > > implementation section? > > > > > > > > Not yet. > > > > I will add the checkbox for the implementation to my todo list. > > > > > > That reminds me of an idea, a feature I would like. And that would solve this too. > > > > It would be cool if one could with a single copy (or cut; as in copy/paste) copy a method (or procedure/function) declaration, including the > > implementation. > > Or even several methods, if one selects several lines in the interface. > > > > This would/should allow to: > > - copy/cut paste a method from one place in a class to another place in the same class (adjusting order of implementation too) > > - copy/cut paste a method from one class to any other class (adjusting the classname in the "procedure FOOCLASS.metho" line) > > This one would hugely add to the ability of refactoring, moving things up/down in the class hierachy, or even to rlated classes > > - copy/cut paste a plain procedure into a class, making it a method > > - copy/cut paste a method to become a plain procedure. So this one still requires some clean up, for any reference to self > > I'm all for this one. A 'Remove method/procedure' and 'Insert method/procedure'. Good idea. > As long as it doesn't interfere with regular copy&paste. I agree, it should not use the Cut/Copy shortcuts. But I see no problem with Paste. Do you see one?

it should copy (or cut) to clipboard => but as indicated via different shortcut/command.

It does therefore need a different clipboard format (a mixed one plain text / codetool-format). The plain text would allow to paste into other apps (SynEdit does the same for copy with fold info / or copy column-mode selection)

If required, synEdit could get a callbackon paste => so codetool can check for the special format, and intercept it.
At some future point, I can provide insight, how this could even include foldstate info.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/85cc98d5/attachment.html>

Reply by email

Michael Van Canneyt
to Martin
Martin wrote 66 lines
On 13/05/2011 13:31, Mattias Gaertner wrote: ? ? Michael Van Canneyt hat am 13. Mai 2011 um 12:55 geschrieben: > > > On Fri, 13 May 2011, Martin wrote: > > > On 13/05/2011 10:03, Mattias Gaertner wrote: > >? ? ? ?Graeme Geldenhuys hat am 13. Mai 2011 um 09:48 geschrieben: > > > >? ? ? ?>? ? http://bugs.freepascal.org/view.php?id=13994 > >? ? ? ?> > >? ? ? ?> No solution has been implemented in Lazarus yet. As a work-around, is > >? ? ? ?> there any way to tell Code Completion (Ctrl+Shift+C) for event handlers, > >? ? ? ?> to only generate the code in the interface of the unit, and not the > >? ? ? ?> implementation section? > > > > ? > > > > Not yet. > > > > I will add the checkbox for the implementation to my todo list. > > > > > > That reminds me of an idea, a feature I would like. And that would solve this too. > > > > It would be cool if one could with a single copy (or cut; as in copy/paste) copy a method (or procedure/function) declaration, including the > > implementation. > > Or even several methods, if one selects several lines in the interface. > > > > This would/should allow to: > > - copy/cut paste a method from one place in a class to another place in the same class (adjusting order of implementation too) > > - copy/cut paste a method from one class to any other class (adjusting the classname in the "procedure FOOCLASS.metho" line) > > ? This one would hugely add to the ability of refactoring, moving things up/down in the class hierachy, or even to rlated classes > > - copy/cut paste a plain procedure into a class, making it a method > > - copy/cut paste a method to become a plain procedure. So this one still requires some clean up, for any reference to self > > I'm all for this one. A 'Remove method/procedure' and 'Insert method/procedure'. ? Good idea. ? > As long as it doesn't interfere with regular copy&paste. I agree, it should not use the Cut/Copy shortcuts. But I see no problem with Paste. Do you see one? Not at all. IMHO it should copy (or cut) to clipboard => but as indicated via different shortcut/command. It does therefore need a different clipboard format (a mixed one plain text / codetool-format). The plain text would allow to paste into other apps (SynEdit does the same for copy with fold info / or copy column-mode selection) If required, synEdit could get a callbackon paste? => so codetool can check for the special format, and intercept it. At some future point, I can provide insight, how this could even include foldstate info.

I think this is the way to go.

Michael.

Reply by email

Mattias Gaertner
to Martin: it should copy (or cut) to clipboard => but as indicated via different shortcut/command.…

?
?

Martin hat am 13. Mai 2011 um 14:44 geschrieben:

[...] IMHO it should copy (or cut) to clipboard => but as indicated via different shortcut/command.

?
Yes. Remove method/procedure. Or maybe better two functions: Copy- and Cut method/procedure.
?

Show quoted text 12 lines
It does therefore need a different clipboard format (a mixed one plain text / codetool-format). The plain text would allow to paste into other apps (SynEdit does the same for copy with fold info / or copy column-mode selection) If required, synEdit could get a callbackon paste? => so codetool can check for the special format, and intercept it. At some future point, I can provide insight, how this could even include foldstate info.

Yes, a special format would be useful.
?
The format must contain ?
- the source of the headers, because they might contain comments and ifdefs
- the implementations
- the source position. This is needed to resolve the identifiers, which could be used in a later extension to automatically extend the uses section of the target unit.

?
Mattias
?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/544413e3/attachment.html>

Reply by email

Martin
to Mattias Gaertner
Mattias Gaertner wrote 25 lines
Martin hat am 13. Mai 2011 um 14:44 geschrieben: > [...] > IMHO it should copy (or cut) to clipboard => but as indicated via > different shortcut/command. Yes. Remove method/procedure. Or maybe better two functions: Copy- and Cut method/procedure. > > It does therefore need a different clipboard format (a mixed one > plain text / codetool-format). The plain text would allow to paste > into other apps > (SynEdit does the same for copy with fold info / or copy column-mode > selection) > > If required, synEdit could get a callbackon paste => so codetool can > check for the special format, and intercept it. > At some future point, I can provide insight, how this could even > include foldstate info. > Yes, a special format would be useful.

Maybe even synedit could be told to create this format => it has already some nice code to create clipboard stuff.

Or it can be extended in SynSourceEditor

Show quoted text 12 lines
The format must contain - the source of the headers, because they might contain comments and ifdefs - the implementations - the source position. This is needed to resolve the identifiers, which could be used in a later extension to automatically extend the uses section of the target unit.

Actually, there should be (at least) 2 paste methods. (But for starters one would do)

1) Paste, without any question.
Necessary/Optional actions such as units-dependencies, or replacing identifiers, can be globally configured
IMHO kept to a minimum by default (insert units into uses, but do not update identifiers

2) Paste via feedback dialog (like "extract procedure " already has. Could offer a growing amount of options. Such as an identifier, to use as prefix for calls to the originating-class. Or creation of missing fields....

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/9fd48374/attachment-0001.html>

Reply by email

Mattias Gaertner
to Martin

?
?

Martin hat am 13. Mai 2011 um 15:36 geschrieben:

[...] Maybe even synedit could be told to create this format => it has already some nice code to create clipboard stuff.

?
Can you explain this??
?

Show quoted text 22 lines
Or it can be extended in SynSourceEditor > ? > The format must contain ? > - the source of the headers, because they might contain comments and ifdefs > - the implementations > - the source position. This is needed to resolve the identifiers, which > could be used in a later extension to automatically extend the uses section > of the target unit. > > Actually, there should be (at least) 2 paste methods. (But for starters one would do) 1) Paste, without any question. Necessary/Optional actions such as units-dependencies, or replacing identifiers, can be globally configured IMHO kept to a minimum by default (insert units into uses, but do not update identifiers

?
This could happen on normal Paste.?
?

2) Paste via feedback dialog (like "extract procedure " already has. Could offer a growing amount of options. Such as an identifier, to use as prefix for calls to the originating-class. Or creation of missing fields....

This can be a menu item under Refactor.

Mattias
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/926181f6/attachment.html>

Reply by email

Martin
to Mattias Gaertner
Mattias Gaertner wrote 10 lines
Martin hat am 13. Mai 2011 um 15:36 geschrieben: > [...] > Maybe even synedit could be told to create this format => it has > already some nice code to create clipboard stuff. Can you explain this?
for example in line 1509
procedure TCustomSynEdit.DoCopyToClipboard(SText: string; FoldInfo:
String = '');

SynEdit has TSynClipboardStream which accepts various parts of information (e.g the selection mode; and the fold state) It then generates text content, and a custom clipboard format version with the extra info

This class could be extended in TSynSourceEditor (which is a subclass of TSynEdit, but in hte IDE). So odetools would not have to bother to much how to store stuff in the clibpoard or read it. It could use the existing code...
Of course SynSourceEditor would have to expose some methods that can be used, As codetools would decide what text, and what format info need to be copied....

You could also just take a copy of this class and use it directly in codetools.

Show quoted text 11 lines
> Actually, there should be (at least) 2 paste methods. (But for > starters one would do) > > 1) Paste, without any question. > Necessary/Optional actions such as units-dependencies, or replacing > identifiers, can be globally configured > IMHO kept to a minimum by default (insert units into uses, but do not > update identifiers This could happen on normal Paste.

That's the idea.

Show quoted text 8 lines
> > 2) Paste via feedback dialog (like "extract procedure " already has. > Could offer a growing amount of options. Such as an identifier, to > use as prefix for calls to the originating-class. Or creation of > missing fields.... This can be a menu item under Refactor.

+1

Martin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.lazarus.freepascal.org/pipermail/lazarus/attachments/20110513/a61e57ca/attachment.html>

Reply by email