Recent

Author Topic: Suggestion: additional functionality in the "Enclose Selection" window  (Read 1274 times)

zoltanleo

  • Full Member
  • ***
  • Posts: 243
Hi guys.

I have a suggestion to add a new item to the list of the this window (see attachment). During operation, me often have to enclose sections of code inside this expression.

What do you think about this?
Win7 Ultim x64/Deb 10 amd64 GTK3:
Lazarus x32/x64 2.1(r.63122); FPC 3.3.1 (r.44724), FB 3.0.5

Sorry for my bad English, I'm using translator ;)

lucamar

  • Hero Member
  • *****
  • Posts: 2850
What I would really like to see for features such as this one is an editor to customize them, ala Code Templates. Would be nice for this one, for the menu "Source->Insert General", etc.

Just day-dreaming, I know :D
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

zoltanleo

  • Full Member
  • ***
  • Posts: 243
Would be nice for this one, for the menu "Source->Insert General", etc.
At first I also had such thoughts.  ;)

But I decided that at first it was necessary to ask for at least such a meager functionality that is very easy to implement.
Win7 Ultim x64/Deb 10 amd64 GTK3:
Lazarus x32/x64 2.1(r.63122); FPC 3.3.1 (r.44724), FB 3.0.5

Sorry for my bad English, I'm using translator ;)

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6292
    • wiki
I have a suggestion to add a new item to the list of the this window (see attachment). During operation, me often have to enclose sections of code inside this expression.

IMHO, it is a "patches will be accepted".

Should all be in
ide\encloseselectiondlg.pas
(+ resource string)

see ide/sourceditor.pp
procedure TSourceEditor.EncloseSelection;
for how it is called.

It could either be extended by just the one template.
Or allow to have user-provided templates. (saved in an xml file)

And for the really daring: I guess it even is possible to add some of the macros from code templates.
 
In this particular case (since I would be willing to apply the patch), you can also pull request at https://github.com/User4martin/lazarus

zoltanleo

  • Full Member
  • ***
  • Posts: 243
IMHO, it is a "patches will be accepted".
Hi Martin.

Thanks for supporting my idea. I will see how this is implemented in the editor code. To get started, I will try to make the easiest option without supporting custom templates. Perhaps later someone will be interested too and will realize this opportunity in the best possible way.
Win7 Ultim x64/Deb 10 amd64 GTK3:
Lazarus x32/x64 2.1(r.63122); FPC 3.3.1 (r.44724), FB 3.0.5

Sorry for my bad English, I'm using translator ;)

lucamar

  • Hero Member
  • *****
  • Posts: 2850
Or allow to have user-provided templates. (saved in an xml file)

Has it to be XML? If so, is there any particular structure or would suffice something like, say:

Code: XML  [Select][+][-]
  1. <enclose>
  2.   <item caption="begin..end">
  3.     begin
  4.       |
  5.     end;
  6.   </item>
  7.   <!-- And so on -->
  8. </enclose>
Turbo Pascal 3 CP/M - Amstrad PCW 8256 (512 KB !!!) :P
Lazarus 2.0.8/FPC 3.0.4 - 32/64 bits on:
(K|L|X)Ubuntu 12..18, Windows XP, 7, 10 and various DOSes.

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6292
    • wiki
The IDE has really good routines to store xml files. And all config are xml.

Except the codetemplates file, which causes a big problem. Because once installed it gets edited, and if the IDE ships with new templates, people who update will never see them.

xml files have a version, so the IDE can decide what needs to be added by update.

TRttiXMLConfig can write entire objects based on public properties. Except it does not handle lists. Those need to be done by a loop.
It is getting very late now.
I can get more on it tomorrow.

Some example in ide\environmentopts.pp

    FXMLCfg: TRttiXMLConfig;
FXMLCfg:=TRttiXMLConfig.Create(Filename);

procedure TEnvironmentOptions.LoadDebuggerProperties;

// get count of "Config" nodes in path
ConfCount := FXMLCfg.GetListItemCount('EnvironmentOptions/Debugger/Configs/', 'Config', False);

<EnvironmentOptions> <Debugger> <Configs>
 <Config>... </Config>
 <Config>... </Config>
....

FXMLCfg.ReadObject('EnvironmentOptions/Debugger/Configs/Config[0]', SomeObj);  // first node
.... WriteObject(..)

SomeObj: TSomeClass with published properties / where possible with default value.


You also need
GetPrimaryConfigPath
see
components\macroscript\emscriptmacro.pas
function GetConfFileName: String;



eljo

  • Sr. Member
  • ****
  • Posts: 358
The IDE has really good routines to store xml files. And all config are xml.

Except the codetemplates file, which causes a big problem. Because once installed it gets edited, and if the IDE ships with new templates, people who update will never see them.
That can easily be solved by using two files merged at startup 1) the system templates only updatable from the lazarus team and 2 a user template, when the IDE starts, merges both templates in to one. Any conflicts will be the the user's obligation to resolve (with an option "not now").

I would like to avoid xml as much as possible but you can't ignore a couple of decades of development that easily.

PS.
It is nice to see that I can use github to contribute, very encouraging. Is there a central repo or something? (asked the man that has no plans for contribution at the moment).
« Last Edit: May 08, 2020, 06:59:35 am by eljo »

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6292
    • wiki
XML:
There are always technical possibilities to work around.
But given that we use it for all other config, it should be used.
Also, your code does not have much to deal with it, the RTTIXMLConf does 99% for you.
Code: Pascal  [Select][+][-]
  1. type
  2. TEncloseConfNode = class
  3. private
  4.   FTemlateText: string;
  5. published
  6.   property TemlateText: string read FTemlateText write FTemlateText;
  7. end;
Add other properties as needed, and throw the entire object at the RTTIXMLConf (in a loop, and with a path).

For a single value you can also use
    XMLConfig.SetDeleteValue('Foo/BarValue', TemlateText, ''); // the empty string is the default
    TemlateText := XMLConfig.GetValue('Foo/BarValue',  ''); // the empty string is the default
I have to check, if that works with indexes "[1]"....


GIT:
The official repro is the SVN.

I run my private git, and have it set up, so I can make my commits into svn.
But it allows me to run a mirror.
On that mirror, I can accept pull requests. But that means only for issues that I will take care of myself. (I.e. usually pre-agreed)

zoltanleo

  • Full Member
  • ***
  • Posts: 243
I run my private git, and have it set up, so I can make my commits into svn.
Hi Martin.

I made some changes to the code, look them please. And add them to the main branch of the lazarus trunk, if they are correct.
Win7 Ultim x64/Deb 10 amd64 GTK3:
Lazarus x32/x64 2.1(r.63122); FPC 3.3.1 (r.44724), FB 3.0.5

Sorry for my bad English, I'm using translator ;)

FTurtle

  • Sr. Member
  • ****
  • Posts: 269
Looks good. But I think better replace

From:
Code: Pascal  [Select][+][-]
  1. {$REGION 'description'}..{$ENDREGION}

To:
Code: Pascal  [Select][+][-]
  1. {$REGION '|'}..{$ENDREGION}

Martin_fr

  • Administrator
  • Hero Member
  • *
  • Posts: 6292
    • wiki
Thanks,

Committed as r63173

 

TinyPortal © 2005-2018