NetSpell icon indicating copy to clipboard operation
NetSpell copied to clipboard

NOT an issue , but an improvement : load / save user words

Open he-igel opened this issue 1 year ago • 0 comments

it would be nice to give the user the ability to manage the user words by his own. the following implementation works. the new code is between >>> and <<<

    public class WordDictionary : System.ComponentModel.Component     {         ...

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>     public delegate string [] LoadUserWordsDelegate () ;     public delegate void SaveUserWordsDelegate ( string [] Words ) ;

    public LoadUserWordsDelegate LoadUserWords { set ; get ; }     public SaveUserWordsDelegate SaveUserWords { set ; get ; } // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

        public WordDictionary()         {             InitializeComponent(); // >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>             LoadUserWords = null ;             SaveUserWords = null ; // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<         }

	    private void LoadUserFile()
	    {
		    // load user words
		    _userWords.Clear();

      // quit if user file is disabled
		    if(!this.EnableUserFile) return;

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if ( LoadUserWords != null ) { string [] Words = LoadUserWords () ; foreach ( string Word in Words ) _userWords.Add(Word, Word); } else { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // original code } }

	    private void SaveUserFile()
	    {

		    // quit if user file is disabled
		    if(!this.EnableUserFile) return;

// >>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>> if ( SaveUserWords != null ) { List < string > Words = new List < string > () ; foreach (string tempWord in _userWords.Keys) Words . Add ( tempWord ) ; SaveUserWords ( Words . ToArray () ); } else { // <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<< // original code } } }

he-igel avatar Dec 06 '23 13:12 he-igel