Suggestion: additional functionality in the "Enclose Selection" window lazarus / 9-Editor ---------------------------------------------------------------------- zoltanleo · 2020-05-07 19:16 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? ---------------------------------------------------------------------- lucamar · 2020-05-07 19:30 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 ---------------------------------------------------------------------- zoltanleo · 2020-05-07 19:36 Quote from: lucamar on May 07, 2020, 09:30:16 pmWould 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. ---------------------------------------------------------------------- Martin_fr · 2020-05-07 20:05 Quote from: zoltanleo on May 07, 2020, 09:16:11 pmI 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 · 2020-05-07 20:20 Quote from: Martin_fr on May 07, 2020, 10:05:16 pmIMHO, 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. ---------------------------------------------------------------------- lucamar · 2020-05-08 02:40 Quote from: Martin_fr on May 07, 2020, 10:05:16 pmOr 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i       begin      |    end;    ---------------------------------------------------------------------- Martin_fr · 2020-05-08 03:05 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);  ...  ... .... 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 · 2020-05-08 04:56 Quote from: Martin_fr on May 08, 2020, 05:05:42 amThe 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). ---------------------------------------------------------------------- Martin_fr · 2020-05-08 12:45 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][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i typeTEncloseConfNode = classprivate   FTemlateText: string;published  property TemlateText: string read FTemlateText write FTemlateText;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 · 2020-05-15 23:49 Quote from: Martin_fr on May 08, 2020, 02:45:32 pmI 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. ---------------------------------------------------------------------- FTurtle · 2020-05-16 16:52 Looks good. But I think better replace From: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$REGION 'description'}..{$ENDREGION} To: Code: Pascal  [Select][+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i {$REGION '|'}..{$ENDREGION} ---------------------------------------------------------------------- Martin_fr · 2020-05-16 17:50 Thanks, Committed as r63173