예제 #1
0
        //Searches for a category and return s all the words in the category
        public static List <DictionaryItem> SearchReturnCategory(DictionaryItem Root, string Category)
        {
            List <DictionaryItem> ListOfWords = new List <DictionaryItem>();

            if (Root != null)
            {
                foreach (DictionaryItem DicItem in Root.DictionaryItems)
                {
                    if (DicItem.IsCategory && DicItem.CategoryName == Category)
                    {
                        ListOfWords = DicItem.DictionaryItems;
                        break;
                    }
                    else
                    {
                        continue;
                    }
                }
            }
            else
            {
            }

            return(ListOfWords);
        }
예제 #2
0
        private void textBox_Search_TextChanged(object sender, EventArgs e)
        {
            TypingInTextBox = true;
            System.Windows.Forms.TextBox textboxSearch = sender as System.Windows.Forms.TextBox;
            ModifiedRichTextBox          ModifiedRTB   = new ModifiedRichTextBox();

            try
            {
                try
                {
                    DictionaryItem DicObject = (DictionaryItem)ModifiedRTB.Search(textboxSearch.Text, ActiveDictionary.Dictionary.Root);
                    ModifiedRTB.PrintToScreen(DicObject, this.modifiedRichTextBox1);
                }
                catch (NullReferenceException)
                {
                    ActiveDictionary.InitializeActiveSearchList(ActiveDictionary.Dictionary.Root, textBox_Search.Text);
                    //ModifiedRTB.PrintToScreen(ActiveDictionary.ActiveSearchList[0], this.modifiedRichTextBox1);
                }
            }
            catch (InvalidCastException)
            {
                List <DictionaryItem> DicObject = (List <DictionaryItem>)ModifiedRTB.Search(textboxSearch.Text, ActiveDictionary.Dictionary.Root);
            }

            SearchStatus(this.label_Search, this.textBox_Search);
            TypingInTextBox = false;
            ActiveDictionary.ResetIndex();
        }
예제 #3
0
        public static List <DictionaryItem> SearchReturnAllWords(DictionaryItem Root, string Word)
        {
            List <DictionaryItem> WordItems = new List <DictionaryItem>();


            try
            {
                var WordCollection = from d in (from d2 in Root.DictionaryItems where d2.IsCategory select d2)
                                     select d
                                     into words
                                     from word in words.DictionaryItems
                                     where word.WordName.Contains(Word.Split('/')[1])
                                     select word;

                foreach (DictionaryItem d in WordCollection)
                {
                    WordItems.Add(d);
                }
            }
            catch (IndexOutOfRangeException)
            {
            }



            return(WordItems);
        }
예제 #4
0
        public static bool HasWord(string Word, DictionaryItem Root)
        {
            bool _hasWord = false;

here:
            if (!_hasWord)
            {
                try
                {
                    foreach (DictionaryItem DicItem in Root.DictionaryItems)
                    {
                        foreach (DictionaryItem DicItemChild in DicItem.DictionaryItems)
                        {
                            if (DicItemChild.WordName == Word)
                            {
                                _hasWord = true;
                                goto here;
                            }
                        }
                    }
                }
                catch (NullReferenceException)
                {
                    _hasWord = false;
                }
            }


            return(_hasWord);
        }
예제 #5
0
        public static bool HasCategory(string Category, DictionaryItem Root)
        {
            bool _hasCategory = false;

            try
            {
                foreach (DictionaryItem DicItem in Root.DictionaryItems)
                {
                    if (DicItem.IsCategory == true && DicItem.CategoryName == Category)
                    {
                        _hasCategory = true;
                        break;
                    }
                    else
                    {
                        _hasCategory = false;
                    }
                }
            }
            catch (NullReferenceException)
            {
                _hasCategory = false;
            }

            return(_hasCategory);
        }
예제 #6
0
 //Sets the properties of the root DictionaryItem
 public DictionaryTree(string Value)
 {
     if (Value != null)
     {
         _root          = new DictionaryItem(false);
         _root.IsRoot   = true;
         _root.RootName = Value;
     }
 }
예제 #7
0
        private DictionaryItem WordItem()
        {
            DictionaryItem dItem = new DictionaryItem(false);

            dItem.WordName       = DictionaryClipboard.GetWordSearch();
            dItem.CategoryName   = comboBox_Category.Text;
            dItem.WordDefinition = textBox_Definition.Text;

            return(dItem);
        }
        //Prints the DictionaryItem and its properties
        public void PrintToScreen(DictionaryItem DicItem, ModifiedRichTextBox ModifiedRTB)
        {
            int _boldSelectionStart   = 0;
            int _italicSelectionStart = 0;

            if (DicItem.WordName != null)
            {
                ModifiedRTB.Text = "";
                for (int i = 0; i < 3; i++)
                {
                    switch (i)
                    {
                    //Category index
                    case 0:
                        ModifiedRTB.Text            = DicItem.CategoryName;
                        ModifiedRTB.SelectionStart  = 0;
                        ModifiedRTB.SelectionLength = DicItem.CategoryName.Length;
                        ModifiedRTB.SelectionFont   = new Font(ModifiedRTB.SelectionFont, FontStyle.Underline);

                        _boldSelectionStart = ModifiedRTB.Text.Length;
                        ModifiedRTB.Text   += Environment.NewLine;


                        break;

                    //Word index
                    case 1:
                        ModifiedRTB.Text           += Environment.NewLine + DicItem.WordName;
                        ModifiedRTB.SelectionStart  = _boldSelectionStart;
                        ModifiedRTB.SelectionLength = DicItem.WordName.Length + 2;
                        ModifiedRTB.SelectionFont   = new Font(ModifiedRTB.SelectionFont, FontStyle.Bold);
                        _italicSelectionStart       = ModifiedRTB.Text.Length;
                        ModifiedRTB.Text           += Environment.NewLine;
                        break;

                    //Definition index
                    case 2:
                        ModifiedRTB.Text           += DicItem.WordDefinition;
                        ModifiedRTB.SelectionStart  = _italicSelectionStart;
                        ModifiedRTB.SelectionLength = DicItem.WordDefinition.Length + 2;
                        ModifiedRTB.SelectionFont   = new Font(ModifiedRTB.SelectionFont, FontStyle.Italic);

                        //Bolds the 2nd line again
                        ModifiedRTB.SelectionStart  = _boldSelectionStart;
                        ModifiedRTB.SelectionLength = DicItem.WordName.Length + 2;
                        ModifiedRTB.SelectionFont   = new Font(ModifiedRTB.SelectionFont, FontStyle.Bold);

                        break;
                    }
                }
            }
            else
            {
            }
        }
예제 #9
0
 public void AddDictionaryItem(DictionaryItem DicItem)
 {
     //only categories can be added to the root
     if (DicItem != null && DicItem.IsCategory == true && this.IsRoot == true)
     {
         this._dictionaryItems.Add(DicItem);
     }//Only words can be added to categories
     else if (DicItem != null && DicItem.IsCategory == false && this._isCategory == true)
     {
         this.DictionaryItems.Add(DicItem);
     }
 }
예제 #10
0
 private void button_AddWord_Click_1(object sender, EventArgs e)
 {
     if (DictionaryTree.HasWord(WordItem().WordName, ActiveDictionary.Dictionary.Root))
     {
         //Error Provider Code
     }
     else
     {
         DictionaryItem DItem = new DictionaryItem(false, false, WordItem().CategoryName, WordItem());
         FileIO.SerializeDictionary();
         this.Close();
     }
 }
예제 #11
0
        //Searches for a word in the dictoinary and returns it if the word is found
        public static DictionaryItem SearchReturnWord(DictionaryItem Root, string Word)
        {
            bool           hasFoundWord = false;
            DictionaryItem WordFound    = new DictionaryItem(false);

            if (Root != null)
            {
                //The assumption is that the word does not exist until found
                if (hasFoundWord == false)
                {
                    foreach (DictionaryItem DicItem in Root.DictionaryItems)
                    {
                        if (DicItem.IsCategory)
                        {
                            foreach (DictionaryItem childDicItem in DicItem.DictionaryItems)
                            {
                                if (childDicItem.WordName == Word)
                                {
                                    WordFound    = childDicItem;
                                    hasFoundWord = true;
                                    break;
                                }
                                else
                                {
                                }
                            }
                        }
                        else
                        {
                        }
                    }
                }
                else
                {
                }
            }

            return(WordFound);
        }
        //Calls the search methods from the DictionaryTree class
        //The marked string is a combinaton of the string to search plus a tag which refers to a category or word search
        public object Search(string MarkedSearchString, DictionaryItem DicItem)
        {
            List <DictionaryItem> CategoryItem = new List <DictionaryItem>();
            DictionaryItem        WordItem     = new DictionaryItem();

            try
            {
                string StringToSearch = MarkedSearchString.Split('/')[1];
                string SearchCriteria = MarkedSearchString.Split('/')[0];

                if (SearchCriteria == "(C)")
                {
                    DictionaryItem dictionaryItem = new DictionaryItem();

                    return(CategoryItem);
                }
                else if (SearchCriteria == "(W)")
                {
                    if (StringToSearch == DictionaryTree.SearchReturnWord(DicItem, StringToSearch).WordName)
                    {
                        WordItem = DictionaryTree.SearchReturnWord(DicItem, StringToSearch);
                    }
                    else
                    {
                        WordItem = null;
                    }
                    return(WordItem);
                }
                else
                {
                    return(null);
                }
            }
            catch (IndexOutOfRangeException)
            {
                return(null);
            }
        }
        protected override void OnKeyDown(KeyEventArgs e)
        {
            if (e.KeyData == Keys.Enter)
            {
                if (this.Text != string.Empty)
                {
                    _cursorIndex += 1;
                    //When the definition has been entered
                    if (_cursorIndex == 3)
                    {
                        if (ActiveDictionary.Dictionary != null)
                        {
                            DictionaryItem Word = new DictionaryItem(false, true, this.Lines[0],
                                                                     new DictionaryItem(false)
                            {
                                CategoryName   = Lines[0],
                                WordName       = Lines[2],
                                WordDefinition = Lines[3]
                            });
                            ActiveDictionary.Dictionary.Root.AddDictionaryItem(Word);
                        }
                        else
                        {
                            ActiveDictionary.Dictionary = new DictionaryTree("MyDictonary1");
                            DictionaryItem Word = new DictionaryItem(false, true, this.Lines[0],
                                                                     new DictionaryItem(false)
                            {
                                CategoryName   = Lines[0],
                                WordName       = Lines[2],
                                WordDefinition = Lines[3]
                            });

                            ActiveDictionary.Dictionary.Root.AddDictionaryItem(Word);
                        }
                    }
                }
            }

            else
            {
                if (e.Modifiers == Keys.Control)
                {
                    Keys keydata = e.KeyData & e.KeyCode;
                    switch (keydata)
                    {
                    case Keys.M:

                        bool goToBreak = false;

                        foreach (DictionaryItem category in ActiveDictionary.Dictionary.Root.DictionaryItems)
                        {
                            if (goToBreak == false)
                            {
                                foreach (DictionaryItem word in category.DictionaryItems)
                                {
                                    if (word.IsShowing)
                                    {
                                        word.CategoryName   = Lines[0];
                                        word.WordName       = Lines[2];
                                        word.WordDefinition = Lines[3];
                                        goToBreak           = true;
                                    }
                                }
                            }
                            else
                            {
                                break;
                            }
                        }

                        break;
                    }
                }
            }


            base.OnKeyDown(e);
        }
예제 #14
0
 public static void InitializeActiveSearchList(DictionaryItem DicItem, string Word)
 {
     ActiveSearchList = DictionaryTree.SearchReturnAllWords(DicItem, Word);
 }