I am writing an addon, but I would first like to experiment with a Macro.
In Komodo Edit/IDE 10: What is the correct method to get & set Primary Languages?
Techniques I have used in the past no longer seem to apply to the current version. I also note that the primary languages do not appear to be set in the prefs.xml file (I looked for the string JavaScript which is definitely one of my primary languages, and there are 5 settings, none of whch are related to primary languages).
In the past, I have used the following code:
const {classes: Cc, interfaces: Ci} = Components;
var langRegistry = Cc["@activestate.com/koLanguageRegistryService;1"].getService(Ci.koILanguageRegistryService);
// get the names of all the languages
var languageNames = {};
langRegistry.getLanguageNames(languageNames , {}); // second {} needed to keep xpcom happy
languageNames = languageNames.value;
but, while I do get some results, they are definitely the wrong ones.
Sadly this is a bit more convoluted than it ought to be. Mind you this has always worked the same to my knowledge, no recent changes were made.
/* Get Primary Languages */
const {classes: Cc, interfaces: Ci} = Components;
var langRegistry = Cc["@activestate.com/koLanguageRegistryService;1"].getService(Ci.koILanguageRegistryService);
var hierarchy = langRegistry.getLanguageHierarchy();
var primaryLanguages = null;
let children = {};
let count = {};
hierarchy.getChildren(children, count);
for (let child of children.value)
{
if (child.container)
{
// Parent of non-primary languages
continue;
}
primaryLanguages.push(child);
}
/* Set Primary Language */
// This SHOULD be
// langRegistry.changeLanguageStatus("EJS", true);
// However this method has not been exposed through XPCOM, it will be once
// Komodo 11 is released
// For now we can use:
langRegistry.getLanguage("EJS").primary = true;
require("ko/prefs").setBoolean("languages/EJS/primary", true);
// However a restart of Komodo will be required