Exemple #1
0
        private void findMatchingTextSynchronous(string searchText)
        {
            lock (Search)
            {
                IList <string> kSearchBase;
                // if search text is empty, or current search text is not a substring of the previous search
                if (searchText == "")
                {
                    this.kMatches        = filterToTextbookAndChapter(wordDictionary.listWords());
                    this.kPrevSearchTerm = searchText;
                    computeOffsets();
                    VocabSelectionCanvas.Dispatcher.BeginInvoke(() =>
                    {
                        VocabSelectionCanvas.Height = canvasHeight; //dLineHeight * kMatches.Count;
                        VocabSelectionScrollViewer.ScrollToTop();
                        this.DrawSearchMatches();
                    });
                    return;
                }
                else if (searchText.Contains(kPrevSearchTerm) && kPrevSearchTerm != "")
                {
                    kSearchBase = filterToTextbookAndChapter(this.kMatches);
                }
                else
                {
                    kSearchBase = filterToTextbookAndChapter(wordDictionary.listWords());
                }

                IList <string> kNewMatches = new List <string>();
                foreach (string match in kSearchBase)
                {
                    if (match.IndexOf(searchText, 0, StringComparison.OrdinalIgnoreCase) >= 0 ||
                        wordDictionary.getReading(match).IndexOf(searchText, 0, StringComparison.OrdinalIgnoreCase) >= 0 ||
                        wordDictionary.translateToEnglish(match).IndexOf(searchText, 0, StringComparison.OrdinalIgnoreCase) >= 0)
                    {
                        kNewMatches.Add(match);
                    }
                }

                // update the state: kMatches, kPrevSearchTerm
                this.kMatches        = kNewMatches;
                this.kPrevSearchTerm = searchText;
                computeOffsets();
                VocabSelectionCanvas.Dispatcher.BeginInvoke(() =>
                {
                    VocabSelectionCanvas.Height = canvasHeight;
                    VocabSelectionScrollViewer.ScrollToTop();
                    this.DrawSearchMatches();
                });
            }
        }
Exemple #2
0
        public void performOnStartup()
        {
            defaultBrush = StudyFocusForeignWord.Background;
            StudyFocusForeignWord.Items.Add("General Review");
            StudyFocusForeignWord.SelectedIndex = 0;

            /*
             * foreach (var x in stringHeights.Take(100))
             * {
             *  Debug.WriteLine(x.Key + x.Value);
             * }
             */
            /*
             * TreeView tree = new TreeView();
             *
             * TreeViewItem t = new TreeViewItem();
             *
             * tree.Items.Add(t);
             *
             * for (int i = 0; i < 50; ++i)
             * {
             *  //                CheckBox c = new CheckBox();
             *  //                t.Items.Add(c);
             *  //            }
             *  Polygon p = new Polygon();
             *  p.Points.Add(new Point(0, 0));
             *  p.Points.Add(new Point(4, 0));
             *  p.Points.Add(new Point(0, 4));
             *  p.Fill = new SolidColorBrush(Color.FromArgb(255, 255, 0, 0));
             *  t.Items.Add(p);
             * }
             *
             * //            StackPanel s = ;
             * //           tree.Items.Add(obj);
             *
             * VocabSelectionScrollViewer.Content = tree;
             */
            StudyFocus = "";

            // load books

            /*
             * Dictionary<string, int> wordFreqs = new Dictionary<string,int>();
             * foreach (var y in mainPage.sentenceDictionary.getSentences("", q => true))
             * {
             *  foreach (var x in mainPage.sentenceDictionary.getWords(y))
             *  {
             *      if (!wordFreqs.ContainsKey(x))
             *      {
             *          wordFreqs[x] = 0;
             *      }
             ++wordFreqs[x];
             *  }
             * }
             * List<Tuple<int, string>> wordFreqsL = new List<Tuple<int, string>>();
             * foreach (var x in wordFreqs)
             * {
             *  wordFreqsL.Add(Tuple.Create(x.Value, x.Key));
             * }
             * wordFreqsL.Sort();
             * wordFreqsL.Reverse();
             * FileStream f = new FileStream(Environment.GetFolderPath(Environment.SpecialFolder.MyDocuments) + "\\gezaSpecialFile2.txt", FileMode.Create);
             * //IsolatedStorageFileStream isoStream = new IsolatedStorageFileStream("gezaFileSilverlight.txt", FileMode.Create, isoFile);
             * StreamWriter sw = new StreamWriter(f);
             * foreach (var x in wordFreqsL)
             * {
             *  sw.WriteLine(x.Item2 + "\t" + x.Item1);
             * }
             * sw.Close();
             * f.Close();
             */

            /*
             * foreach (string word in wordDictionary.listWordsByFrequency().Take(2000))
             * {
             *  this.kSetAllowedWords.Add(word);
             * }
             */

            selectedTextbook = allTextbooks;
            selectedChapter  = allChapters;
            //this.textbookSelect.Items.Add(allTextbooks);

            for (int i = 0; i < textbooks.textbooks.Length; ++i)
            {
                ComboBoxItem kItem = new ComboBoxItem();
                kItem.Content = textbooks.textbooks[i].textbookName;
                this.textbookSelect.Items.Add(textbooks.textbooks[i].textbookName);
            }
            this.textbookSelect.SelectedIndex = 0;
            textbookSelect.SelectionChanged  += (s, e) =>
            {
                this.kPrevSearchTerm = "";
                if (this.textbookSelect.SelectedItem.ToString() != this.selectedTextbook)
                {
                    this.chapterSelect.Items.Clear();
                    this.selectedTextbook = this.textbookSelect.SelectedItem.ToString();

                    if (textbooks.textbookDictionary.ContainsKey(textbookSelect.SelectedItem.ToString()))
                    {
                        Textbooks.Textbook t = textbooks.textbookDictionary[textbookSelect.SelectedItem.ToString()];
                        this.chapterSelect.Items.Add(allChapters);
                        for (int i = 0; i < t.chapters.Length; ++i)
                        {
                            this.chapterSelect.Items.Add(t.chapters[i].chapterName);
                        }
                    }
                    if (this.chapterSelect.Items.Count > 0)
                    {
                        this.chapterSelect.SelectedIndex = 0;
                    }
                    Search_TextChanged(null, null);
                }
            };

            Textbooks.Textbook t1 = textbooks.textbookDictionary[textbookSelect.SelectedItem.ToString()];
            this.chapterSelect.Items.Add(allChapters);
            for (int i = 0; i < t1.chapters.Length; ++i)
            {
                this.chapterSelect.Items.Add(t1.chapters[i].chapterName);
            }

            this.chapterSelect.SelectedIndex = 0;

            chapterSelect.SelectionChanged += (s, e) =>
            {
                this.kPrevSearchTerm = "";
                if (this.chapterSelect.SelectedItem != null &&
                    this.chapterSelect.SelectedItem.ToString() != this.selectedChapter)
                {
                    this.selectedChapter = this.chapterSelect.SelectedItem.ToString();
                    Search_TextChanged(null, null);
                }
            };


            //this.kSetAllowedWords = new HashSet<string>();



            //Label showVocab = new Label();
            //showVocab.Height = 20.0;
            //showVocab.Content = "show all vocab";
            //kMatches = wordDictionary.listWords();

            /*
             * IList<UIElement> elementList = new List<UIElement>();
             * showVocab.SetValue(Canvas.LeftProperty, 0.0);
             * showVocab.SetValue(Canvas.TopProperty, 0.0);
             * elementList.Add(showVocab);
             */
            // going ahead to create an Element List of every possible UI element that could ever be displayed on the canvas


            /*
             * IList<string> allWords = wordDictionary.listWords();
             * IList<UIElement> elementList = new List<UIElement>();
             * TreeView tree = new TreeView();
             *
             * VocabSelectionScrollViewer.Content = tree;
             *
             * //tree
             *
             *
             *
             */
            /*
             * for (int i = 0; i < allWords.Count; ++i)
             * {
             *  string word = allWords[i];
             *  CheckBox newVocab = new CheckBox();
             *  newVocab.Height = 20.0;
             *  newVocab.Content = word;
             *  newVocab.Checked += (s,e) =>
             *  {
             *      this.kSetAllowedWords.Add(word);
             *  };
             *  newVocab.Unchecked += (s,e) =>
             *  {
             *      this.kSetAllowedWords.Remove(word);
             *  };
             *
             *  //newVocab.SetValue(Canvas.LeftProperty, 10.0);
             *  //newVocab.SetValue(Canvas.TopProperty, 20.0 * i + 20.0);
             *  elementList.Add(newVocab);
             * }
             */


            //int iOffset = 0;

            //Search_TextChanged(null,null);
            findMatchingTextSynchronous("");
            sortPinYin(null, null);
            //VocabSelectionCanvas.Height = dLineHeight * this.kMatches.Count;
            VocabSelectionCanvas.Height = canvasHeight;

            PropertyChangedCallback onScrollChanged = (s, e) =>
            {
                //if (!vocabShownClicked) return;
                DrawSearchMatches();
            };

            // attach onScrolledChanged, so it is called everytime scrolling happens
            VocabSelectionScrollViewer.AddScrollCallback(onScrollChanged);


            /*            double dLineHeight = 20.0;
             *
             *          int iFirstVisibleItem = (int)(VocabSelectionScrollViewer.VerticalOffset/20.0);
             *          int iLastItemVisible = (int)((VocabSelectionScrollViewer.VerticalOffset+VocabSelectionScrollViewer.Height)/20.0);
             *
             *          for (int i = iFirstVisibleItem; i <= iLastItemVisible; ++i)
             *          {
             *              CheckBox kCheckBoxBook = new CheckBox();
             *              kCheckBoxBook.Height = dLineHeight;
             *              kCheckBoxBook.Content = this.kMatches[i];
             *              kCheckBoxBook.SetValue(Canvas.LeftProperty,10.0);
             *              kCheckBoxBook.SetValue(Canvas.TopProperty,dLineHeight*i+dLineHeight);
             *              VocabSelectionCanvas.Children.Add(kCheckBoxBook);
             *          }
             *
             */

            /*
             * // for each book
             * for (int i = 0; i < Textbooks.textbooks.Length; ++i)
             * {
             *
             *  CheckBox kCheckBoxBook = new CheckBox();
             *  kCheckBoxBook.Height = dLineHeight;
             *  kCheckBoxBook.Content = textbooks.textbooks[i].textbookName;
             *  kCheckBoxBook.SetValue(Canvas.LeftProperty, 10.0);
             *  kCheckBoxBook.SetValue(Canvas.TopProperty, 20.0 * iOffset + 20.0);
             *  VocabSelectionCanvas.Children.Add(kCheckBoxBook);
             *  iOffset += 1;
             *  // for each chapter
             *  for (int j = 0; j < textbooks[i].Length; ++j)
             *  {
             *      CheckBox kCheckBoxChapter = new CheckBox();
             *      elementList.Add(kCheckBoxChapter);
             *
             *      iOffset += 1;
             *      // for each word
             *      for (int k = 0; k < textbooks[i][j].Length; ++k)
             *      {
             *          CheckBox kCheckBoxWord = new CheckBox();
             *          elementList.Add(newVocab);
             *          // read in the word
             *          string kWord = "word";
             *          textbooks[i][j][k] = kWord;
             *          iOffset += 1;
             *      }
             *  }
             * }
             */


            /*
             *          VocabSelectionCanvas.Children.Add(showVocab);
             *          // given two input integers, draws the ui elements whos indices are in the list designated by the range indices
             *          Action<int, int> drawItemsInRange = (int firstItemVisible, int lastItemVisible) =>
             *          {
             *              VocabSelectionCanvas.Children.Clear();
             *              int startpos = Math.Max(firstItemVisible - 2, 0);
             *              int endpos = Math.Min(lastItemVisible + 2, allWords.Count - 1);
             *              for (int i = startpos; i < endpos; ++i)
             *              {
             *                  //elementList[i].SetValue(Canvas.LeftProperty, 10.0);
             *                  //elementList[i].SetValue(Canvas.TopProperty, 20.0 * i + 20.0);
             *                  CheckBox newVocab = new CheckBox();
             *                  newVocab.Height = 20.0;
             *                  newVocab.Content = allWords[i];
             *                  newVocab.SetValue(Canvas.LeftProperty, 10.0);
             *                  newVocab.SetValue(Canvas.TopProperty, 20.0 * i + 20.0);
             *                  VocabSelectionCanvas.Children.Add(newVocab);
             *              }
             *          };
             *
             *
             *          bool vocabShownClicked = false;
             *          showVocab.MouseLeftButtonDown += (s, e) =>
             *          {
             *              vocabShownClicked = true;
             *              VocabSelectionCanvas.Height = 20.0 + 20.0 * allWords.Count;
             *              int firstItemVisible = (int) (VocabSelectionScrollViewer.VerticalOffset / 20.0);
             *              int lastItemVisible = (int) ((VocabSelectionScrollViewer.VerticalOffset + VocabSelectionScrollViewer.Height) / 20.0);
             *              drawItemsInRange(firstItemVisible, lastItemVisible);
             *          };
             *
             *          // function that determines what ui elements are visible, and then calls drawItemsInRange to draw them
             *          PropertyChangedCallback onScrollChanged = (s, e) =>
             *          {
             *              if (!vocabShownClicked) return;
             *              int firstItemVisible = (int)(VocabSelectionScrollViewer.VerticalOffset / 20.0);
             *              int lastItemVisible = (int)((VocabSelectionScrollViewer.VerticalOffset + VocabSelectionScrollViewer.Height) / 20.0);
             *              drawItemsInRange(firstItemVisible, lastItemVisible);
             *          };
             *
             *          // attach onScrolledChanged, so it is called everytime scrolling happens
             *          VocabSelectionScrollViewer.AddScrollCallback(onScrollChanged);
             */
            /*
             * foreach (string word in wordDictionary.listWords().Take(50)) // first 50 words in dictionary
             * {
             *  CheckBox checkbox = new CheckBox();
             *  checkbox.Content = word;
             *  this.AllVocabList.Items.Add(checkbox);
             * }
             */
            //#endif
        }