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

#include "nsISupports.idl"
#include "koIFinder.idl"


[scriptable, uuid(C2F74525-AB2A-46da-9D00-A805EB77E256)]
interface koIFindSession : nsISupports {
    // It is important to know when repeated "Find Next" calls and "Replace"
    // calls come full circle in the target file(s), because this is used to (1)
    // let the user know when we have searched through the whole file start
    // from their start position (useful feedback); and (2) let ReplaceAll know
    // when to stop (necessary to avoid an infinite loop when the replacement
    // string contains the find pattern). A FindSession provides this
    // information by tracking the "find session". Unfortunately the
    // semantics are not that clean. This is heavily tuned to the usage in
    // find_functions.js.

    // reset the find session (equivalent to creating a new instance)
    void Reset();

    void NoteUrl(in wstring url);
    void StartFind(in wstring pattern,
                   in wstring url,
                   in koIFindOptions options,
                   in unsigned long findStartPos,
                   in unsigned long findSelectionStartPos,
                   in unsigned long findSelectionEndPos,
                   in string mode);
    void NoteFind(in koIFindResult findResult);
    void StartReplace(in wstring pattern,
                      in wstring replacement,
                      in wstring url,
                      in koIFindOptions options);
    void NoteReplace(in koIReplaceResult replaceResult);
    void NoteReplaces(in unsigned long count,
                      [array, size_is(count)] in koIReplaceResult replaces);

    attribute boolean wrapped;
    boolean HaveSearchedThisUrlAlready(in wstring url);
    boolean WasAlreadyFound(in koIFindResult findResult);
    // Return true iff the given findResult overlaps a previous replace
    // result, i.e. is a find hit created by a replacement.
    boolean IsRecursiveHit(in koIFindResult findResult);

    // The current cursor and selection state in the current file when
    // searching began in the current file.
    attribute unsigned long fileStartPos;
    attribute unsigned long fileSelectionStartPos;
    attribute unsigned long fileSelectionEndPos;
    
    // The editor state when this find session began.
    attribute wstring firstUrl;
    attribute unsigned long firstFileStartPos;
    attribute unsigned long firstFileSelectionStartPos;
    attribute unsigned long firstFileSelectionEndPos;
    
    // Useful information for the UI.
    wstring GetPattern();
    wstring GetReplacement();
    unsigned long GetNumFinds();
    unsigned long GetNumReplacements();
    void GetFinds(out unsigned long count,
                  [retval, array, size_is(count)] out koIFindResult rv);
    void GetReplacements(out unsigned long count,
                         [retval, array, size_is(count)] out koIReplaceResult rv);
    koIFindResult GetLastFindResult();
};

