/* Copyright (c) 2000-2006 ActiveState Software Inc.
   See the file LICENSE.txt for licensing information. */

#include "nsISupports.idl"
#include "koIPrefs.idl"

// Interface to the Komodo process' environment variables.
[scriptable, uuid(30537776-473C-4ad6-9A2D-3320B3B5517D)]
interface koIEnviron : nsISupports {
  boolean has(in AString key);
  AString get(in AString key, [optional] in AString defaultvalue);
  void set(in AString key, in AString value);
  void remove(in AString key);
};


// Interface to the user's environment (to be used for spawning external
// commands on behalf of the user in Komodo).
//
// Typically/historically this is the system or shell environment when
// Komodo is started: i.e. before komodo.exe/komodo-bin mucks with it.
// However, the environment may be retrieved from the user's shell (as
// set in the "Environment" prefs panel on non-Windows systems).
//
[scriptable, uuid(CD50AE4E-52DF-499a-95FB-E964F6A42AD2)]
interface koIUserEnviron : nsISupports {
    // Must be set by Komodo initialization before anything else is done
    // with this service.
    attribute AString startupEnvironEncoding;
  
    boolean has(in AString key);
    AString get(in AString key, [optional] in AString defaultvalue);

    /**
     * Get all the keys in the environment
     */
    void keys([optional] out unsigned long count,
              [retval, array, size_is(count)] out wstring keys);

    AString getEnvVar(in AString name, in koIPreferenceContainer pref);

    // return all the env vars as "<name>=<value>" strings
    //  - this is a convenience function for passing to process creation
    //  - it is named after the Win32 API but no FreeEnvironmentStrings is
    //    necessary
    void GetEnvironmentStrings(
      out unsigned long count,
      [retval, array, size_is(count)] out wstring envStrs);

    // Return the user environment as a string encoded as specified by
    // ko.run.runCommand()'s env argument.
    AString GetEncodedEnvironment();
    AString GetEncodedStartupEnvironment();

    // Update the user environment from the given system shell.
    //
    //  "shell" is the full path to a system shell
    //
    // Returns null if successful, otherwise returns an error string.
    AString UpdateFromShell(in AString shell);
};


[scriptable, uuid(10afb005-4472-4d04-9372-94addc092928)]
interface koIEnvironUtils : nsISupports {
    // Utils for working with the environment sets.

    // Merge a set of "diff" environment strings into a "base" set of
    // environment strings. The "diff" strings are interpolated
    // according to the current platform shell interpolation rules,
    // i.e.  %FOO% to interpolate in the env. var. FOO on Windows,
    //       $FOO or $(FOO) otherwise.
    void MergeEnvironmentStrings(
        in unsigned long baseCount,
        [array, size_is(baseCount)] in wstring baseEnvStrs,
        in unsigned long diffCount,
        [array, size_is(diffCount)] in wstring diffEnvStrs,
        out unsigned long resultCount,
        [array, size_is(resultCount)] out wstring resultEnvStrs);

    // Return a list of available system shells from which the user can
    // select in the Environment prefs panel. (non-Windows only)
    void GetUserShells(
        out unsigned long count,
        [retval, array, size_is(count)] out wstring shells
    );
};


