Access to ko.prefs from XUL window

How I can get access to ko.prefs from window?
My XUL:

<?xml version="1.0"?>
<!-- Copyright (c) 2000-2013 ActiveState Software Inc. -->
<!-- See the file LICENSE.txt for licensing information. -->

<?xml-stylesheet type="text/css" href="chrome://global/skin" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/global/global.css" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/bindings/buttons.css" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/bindings/widgets.css" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/bindings/listbox.css" ?>
<?xml-stylesheet type="text/css" href="chrome://komodo/skin/prefs/prefs.css" ?>

<?xml-stylesheet type="text/css" href="chrome://test/content/prefs.css" ?>

<window
    class="kodialog"
    orient="vertical"
    xmlns:html="http://www.w3.org/1999/xhtml"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://test/content/prefs/prefs.js" />
    <vbox flex="1" class="autoscroll">
      <groupbox orient="vertical" style="padding:10px 4px;">
      <caption label="FlatUI"/>
        <box>
        </box>
        <vbox>
          <description>
          <button onclick="test()">Test it</button>
          </description>
        </vbox>
      </groupbox>
    </vbox>
</window>

test():

function test() {
  ko.prefs.setBoolean("mytest", true);
}

Error: [ERROR] console-logger: ReferenceError: ko.prefs is not defined (2) in chrome://test/content/prefs/prefs.js:2

You have to get it from the parent window, eg:

var ko = parent.opener.ko || parent.opener.ko.windowManager.getMainWindow().ko;
1 Like

Thanks a lot, Nathan! Hope you add this trick to your new Komodo modding documentation :smile:

Or you load the Komodo core via the script tag:

<script src="chrome://komodo/content/globals.js" type="application/x-javascript"/>

then you can use require to load sdk modules:

var prefs = require("ko/prefs");
2 Likes

Thanks, Todd. I think I will use this method instead of Nathan’s method.