Пример #1
0
        private void searchBox_TextChanged(object sender, TextChangedEventArgs e)
        {
            WordEntry result = viewModel.Search(this.searchBox.Text);

            if (result == null)
            {
                return;
            }

            var selectedItem = this.wordList.SelectedItem as WordEntry;
            var pos          = result.CompareTo(selectedItem);

            if (pos != 0)
            {
                this.wordList.SelectedItem = result;

                //little trick
                var viewIndex = this.wordList.SelectedIndex + (pos > 0 ? 1 : -1) * 5;
                if (viewIndex < 0)
                {
                    viewIndex = 0;
                }
                if (viewIndex >= this.viewModel.Dict.Count)
                {
                    viewIndex = this.viewModel.Dict.Count - 1;
                }
                var viewItem = this.viewModel.Dict[viewIndex];
                this.wordList.ScrollIntoView(viewItem);
            }
        }
Пример #2
0
        private void DisplayHelp()
        {
            if (!string.IsNullOrEmpty(this.viewModel.DbPath))
            {
                return;
            }

            string    usage    = @"<h1>How to use</h1>
            <ol>
            <li>Drag a StarDict DB file to the toolbar to load it.</li>
            <li>or Drag a StarDict IDX file to the toolbar to convert it to SQLite DB or load it if already converted.</li>
            </ol>
                ";
            string    usage_zh = @"<h1>用法说明</h1>
            <ol>
            <li>拖放一个 StarDict DB 文件到工具栏上即可。</li>
            <li>或拖放一个 StarDict IDX 文件到工具栏上, 即可转换成 SQLite DB 文件或调入已经转换好的。</li>
            </ol>
                ";
            WordEntry help     = new WordEntry {
                word = "help", content = usage + usage_zh
            };

            this.contentView.NavigateToString(this.viewModel.MakeContent(help));
        }
Пример #3
0
        public WordEntry ReadIfoEntry(string word)
        {
            if (string.IsNullOrWhiteSpace(word))
            {
                return(null);
            }

            WordEntry result = null;

            using var command   = conn.CreateCommand();
            command.CommandText = @"select word, content from ifo WHERE word=$word";
            command.Parameters.AddWithValue("$word", word);
            using var reader = command.ExecuteReader();
            //First
            if (reader.Read())
            {
                result = new WordEntry {
                    word = word
                };
                result.content = reader.GetString(1);
            }

            return(result);
        }