Skip to content

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

@he-igel

Description

@he-igel

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
}
}
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions