PxPlus User Forum

Twitter Twitter Twitter

Author Topic: using code snippets for standard control definitions  (Read 2550 times)

Thomas Bock

  • Diamond Member
  • *****
  • Posts: 177
    • View Profile
using code snippets for standard control definitions
« on: April 03, 2019, 11:04:13 AM »
This is how we create new controls with default definitions in nomads. We use Sublime 3.2, which is able of using code snippets. (In PSPad they are called clips.) These snippets are like macros plus some predefined replacement tokens. Upon execution of a snippet each replacement token can be substituted on the fly. The result is a text fragment, designed to speed up coding. We use this feature to create controls with several default values in nomads.

  • create a properly defined control in nomads and copy it to the clipboard
  • paste the clipboard content into an editor and make changes in order to save it as a code snippet (depending on the editor)
    This may start like this (keep the empty lines and everything else)
    [Nomads]
    PANEL       2537${1:<CONTROL>}
    36
    24
    20
    1
    M


    19

    P";"+id$+"_POST_CREATE"

    P";"+id$+"_ON_CHANGE"

    ...
  • use such a code snippet and copy the whole text result to the clipboard
    the editor will ask for a substitution for ${1:<CONTROL>}
  • move to a panel and paste the control

That's a little bit long-winded, but it works and it is much faster than editing all the entrypoints one by one.

Stéphane Devouard

  • Diamond Member
  • *****
  • Posts: 122
  • PxPlus guru with skills in PHP, JS, C#, Java
    • View Profile
    • Stéphane's Web Resume
Re: using code snippets for standard control definitions
« Reply #1 on: April 03, 2019, 11:26:58 AM »
Thanks Thomas !
Stéphane Devouard
Portfolio | Work

Stéphane Devouard

  • Diamond Member
  • *****
  • Posts: 122
  • PxPlus guru with skills in PHP, JS, C#, Java
    • View Profile
    • Stéphane's Web Resume
Re: using code snippets for standard control definitions
« Reply #2 on: April 03, 2019, 12:14:53 PM »
Just looked at Visual Studio Code
The syntax for the placeholders replacement when inserting the snippet is the same

Nice one, Thomas. Thx again.
Stéphane Devouard
Portfolio | Work

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: using code snippets for standard control definitions
« Reply #3 on: April 03, 2019, 03:03:08 PM »
Thomas,

If you are wanting to copy/insert consistent controls why not use the lookup button beside the control name when defining the control in Nomads?

This will bring up a list of similar type/named controls from every other panel in the current library.

For example if you want consistent "Exit" buttons, all you need to do is select the type of control and position to the upper left corner where you want it placed.  When the control definition panel/property list appears press the query button in the name field and the system will show all similar controls with the same name.  You can disable the name match if desired and just select a similar control.  Basically this does a direct copy without the clipboard.

Have a look at the attached image.  If you press the lookup button (circled in green), the system will take the control name from the definition, send it to the lookup where if the match name option is enabled the system will find all similarly named objects in the same library.  You can search other libraries if desired and search by control type instead of name.

Does this do what you are looking for?
You should be able to create a template panel with all the common controls you may need.

Also consider using the Visual Classes and Templates to help assure consistency in your controls.
« Last Edit: April 03, 2019, 03:09:55 PM by Mike King »
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Thomas Bock

  • Diamond Member
  • *****
  • Posts: 177
    • View Profile
Re: using code snippets for standard control definitions
« Reply #4 on: April 05, 2019, 02:15:41 AM »
Mike,

I wasn't aware of this feature. I did dsome tests. It is okay for small libraries due to the time needed for the search. And  it is integrated of course.
But using the clipboard I can insert a group of controls at once as long as an embedded panel is no option.

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: using code snippets for standard control definitions
« Reply #5 on: April 05, 2019, 11:23:29 AM »
Actually what I do is simply run two copies of Nomads. 

On one copy I have a dummy panel with all the common controls and groups of controls I use with the "Group Items" selection option enabled. 

On the other copy I have the panel I am working on.  When I want one or multiple controls I simply highlight them on the dummy panel then select copy, then position/paste them onto the panel I am working on.

Since I have a dual monitor setup this makes it real easy to copy controls or groups of controls.

The dummy panel doesn't actually ever get used and I make it as large as I need to accommodate all the common elements.

You may find many instance using Embedded panels is much easier since that way you can change a control once and the change gets reflected throughout the system.

Also, with PxPlus 2018 you should have a look at Dynamic classes.  These provide similar functionality by allowing you to setup a library of common data elements/controls and since the definition is maintained in a single place (the class definition file) changing the control throughout the whole system is much easier than having to go to each and every panel, find and change the control(s).
« Last Edit: April 09, 2019, 09:45:52 AM by Mike King »
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com

Peter.Higgins

  • Diamond Member
  • *****
  • Posts: 124
    • View Profile
Re: using code snippets for standard control definitions
« Reply #6 on: May 24, 2019, 08:53:52 AM »

Another way to see all the lines and change them quickly is to export a similar panel and change the "INI" like text, and then reimport as the new panel.  Down side is you leave text files on the system that have to be transferred and cleaned up.  Occasionally it fails as well.  But it was a major time saver for years. 

I also use clip and snip nomads libraries, but when working around different systems you get burned by less obvious things like validations unless you examine every folder on every field.  Yesterday I copied a dictionary field and lost the time saving and more in the testing phase. 

After playing with Thomas's method yesterday, I realized it is a superior method, and is going to save me a lot of headaches and heartaches.

Thanks Thomas.

Mike King

  • Diamond Member
  • *****
  • Posts: 3811
  • Mike King
    • View Profile
    • BBSysco Consulting
Re: using code snippets for standard control definitions
« Reply #7 on: May 24, 2019, 10:48:59 AM »
Have you considered the PxPlus data classes?  In particular, the new 'Dynamic' classes that came out with PxPlus 2018.

This will allow you to simply draw a control on the screen, then select its class.  The system will fill in all the major properties such as validation, formatting, etc from the class definition.

Better yet, with Dynamic classes the system leaves the control pointing to the class definition so that a change to the class definition will change all the controls in the system of that class.  For example if you have a key field in the system that you want to change from 10 characters to 15 and you use dynamic classes, simply changing the class definition will change ALL panels that used that class. Or perhaps you want to change the help text reference, tip, query specification, format, etc..; All of these can be kept in a the class definition so changing it in pone place can change all occurrences in your Nomads panels.

In PxPlus 2019 we also added the ability in the class definition to specify data file validation for input fields where you tell us what file you want the input validated against. 

For example if you have a field of class "GLACCOUNT" you could have the system automatically validate the entry of that field against a table/file which contains a list of possible account numbers.  It can even auto-populate separate display fields so when the user enters a account value, not only will it be validated against a master file, but it can display the account name.

For Drop and List boxes it also allows you to identify a file/table to used to load the list from.  So if you had a drop list with a class such as "SHIPVIA", you could point it to a table of possible shipping codes and descriptions.  The system could then display the descriptions in the drop list but return the internal codes to the applications.

Basically the Data Classes are designed to make it easier for developers to use common code elements throughout their application without having to re-enter the same settings or even copy/paste them repeatedly.
Mike King
President - BBSysco Consulting
eMail: mike.king@bbsysco.com