
/******************************************************************************
* MODULE     : edit_replace.gen.h
* DESCRIPTION: the interface for TeXmacs
* COPYRIGHT  : (C) 1999  Joris van der Hoeven
*******************************************************************************
* This software falls under the GNU general public license and comes WITHOUT
* ANY WARRANTY WHATSOEVER. See the file $TEXMACS_PATH/LICENSE for more details.
* If you don't have this file, write to the Free Software Foundation, Inc.,
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
******************************************************************************/

#include <editor.gen.h>

#module edit_replace
#import editor

class edit_replace_rep: virtual public editor_rep {
protected:
  bool        forward;       // forward search or replace ?
  string      search_mode;   // only search matches in search_mode mode
  string      search_lan;    // only search matches in search_lan language
  path        search_at;     // current search position
  path        search_end;    // position of the end of a match
  tree        search_what;   // search tree
  tree        search_old;    // search tree from previous search
  list<path>  where_stack;   // last search positions
  tree        what_stack;    // last search trees
  tree        replace_by;    // replace tree
  int         nr_replaced;   // number of replaced occurrences

  path        spell_end_p;   // spell check until here
  string      spell_s;       // the word being checked
  tree        spell_t;       // response of ispell
  bool        spell_dicmod;  // insert new words in personal dictionary?

protected:
  void spell_write (string s);
  tree spell_read ();

public:
  edit_replace_rep ();
  ~edit_replace_rep ();

  /* structural searching */
  bool inside (string what);
  bool inside (tree_label l);
  bool inside_expand (string what);
  bool inside_with (string var, string val);
  string inside_which (tree t);
  path search_upwards (string what);
  path search_upwards (tree_label l);
  path search_parent_upwards (tree_label l, int& last);
  path search_parent_upwards (tree_label l);
  path search_upwards_expand (string what);
  path search_upwards_with (string var, string val);
  path search_upwards_in_set (tree t);

  /* search and replace */
  path test (path p, tree t);
  void step_ascend (bool forward);
  void step_descend (bool forward);
  void step_horizontal (bool forward);
  void next_match (bool forward);
  void search_start (bool forward= TRUE);
  void search_next (bool forward);
  void search_next (tree what, bool forward, bool step);
  void search_button_next ();
  bool search_keypress (string s);
  void replace_start (tree what, tree by, bool forward= TRUE);
  void replace_next ();
  bool replace_keypress (string s);

  /* spell */
  path test_spellable (path p);
  void spell_next ();
  void spell_replace (string by);
  void spell_start ();
  void spell_end ();
  bool spell_keypress (string s);
};

#endmodule // edit_replace
