Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
Re: [cdt-dev] Can I sort CDT source templates to get my custom template the default one ?

Thanks a lot Jonah for your advices.
I will try to contribute in next future based on your advices.

Kind Regards
Lidia Popescu

Kind

On Fri, Mar 19, 2021 at 3:28 AM Jonah Graham <jonah@xxxxxxxxxxxxxxxx> wrote:
Hi Lidia,

It is an interesting question. Generally no guarantee is made about the order extensions are loaded - and indeed changing the order something is installed, or the name of the bundle that includes it can affect what order extensions are loaded, and therefore the order Platform.getExtensionRegistry().getConfigurationElementsFor returns objects in. 

The practical solution may be to sort the templates at the last step, which would be in org.eclipse.cdt.internal.corext.codemanipulation.StubUtility.getFileTemplatesForContentTypes(String[], IProject) - a consistent sorting by using IDs (TemplatePersistenceData.getId()) may help - you can make your new contribution sort top of the list consistently. The ID may not be unique (and may be null) so a secondary sort key by name is a good idea. This would have the nice effect of moving user provided templates to the top of the list (if null IDs are placed there).

The alternative would be to fix the extension point itself to add a priority/ranking. Some extension points have ranking in their definition so that an order can be made later. This SO answer has a simple example[1] - and content types are an example of an actual extension point with a priority [2].  Therefore, it is possible that the best solution is to add a priority/ranking field to the org.eclipse.ui.editors.templates extension point. This would allow a single vendor to have their item higher than built-in versions. However, getting this done in practice may be a lot of work, and I am not actually 100% sure that having templates have a priority makes the most sense. There is probably another metric that should be used to sort the templates in a consistent way (like the ID or name). Note, even if TemplateStoreCore.getTemplateData returns a sorted list, the code in StubUtility needs to be updated based on the way its nested loops iterate the template data list repeatedly.

I hope one of the options gives you the info needed to create a patch for CDT. I look forward to reviewing it when you do.


Jonah

~~~
Jonah Graham
Kichwa Coders
www.kichwacoders.com


On Thu, 18 Mar 2021 at 17:24, Lidia Popescu <lidochca@xxxxxxxxx> wrote:
Hello cdt forks,

Could you please help me to find out if there is a way to sort this templates from screenshort, when we create File from Template ?

Suppose I would like to add some custom cdt templates.
Is there a way to control the order in which extensions points are loaded?
I need to put 'Demo C source template' at the top in drop down list, as default option.
Seems that this order is based on how the extensions are loaded.
When the Demo plugin is installed by end user, e.g. Install new Software, its extension point is always the last one in the list.

in 
Platform.getExtensionRegistry().getConfigurationElementsFor("org.eclipse.ui.editors.templates");

image.png

Thank you in advance
Lidia


_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev
_______________________________________________
cdt-dev mailing list
cdt-dev@xxxxxxxxxxx
To unsubscribe from this list, visit https://www.eclipse.org/mailman/listinfo/cdt-dev

Back to the top