Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
he-igel opened this issue Dec 6, 2023 · 0 comments
Open

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

he-igel opened this issue Dec 6, 2023 · 0 comments

Comments

@he-igel
Copy link

he-igel commented Dec 6, 2023

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant