Example #1
0
        public MainDlg()
        {
            WordPadSavePath = Directory.GetCurrentDirectory() + "./WordPads/";
            if (!Directory.Exists(WordPadSavePath))
            {
                Directory.CreateDirectory(WordPadSavePath);
            }

            InitializeComponent();

            WordPadTree.TopNode = WordPadTree.Nodes.Add("All WordPad");

            // 加载生词本
            string[] fileNames = Directory.GetFiles(WordPadSavePath, "*" + WordPadExtesion);

            string strErrMsg = "";

            foreach (string fileName in fileNames)
            {
                // 很遗憾, .pad2 也会被.pad匹配
                if (Path.GetExtension(fileName) != WordPadExtesion)
                {
                    continue;
                }

                string rawFileName = Path.GetFileNameWithoutExtension(fileName);
                if (m_wordPads.ContainsKey(rawFileName))
                {
                    strErrMsg += "same name word pad of " + rawFileName + " already exists! errfile: " + fileName + "\n";
                    continue;
                }

                WordPad wp = new WordPad(rawFileName);

                if (wp.Load(fileName))
                {
                    m_wordPads.Add(wp.Name, wp);
                    WordPadTree.TopNode.Nodes.Add(wp.Name);

                    ListView wordList = new ListView();

                    m_wordLists.Add(wp.Name, WordList);
                }
            }

            if (strErrMsg != "")
            {
                MessageBox.Show(strErrMsg);
            }

            if (m_wordPads.Count == 0)
            {
                AddNewWordPad("Default", true);
            }

            WordPadTree.TopNode.Expand();

            WordPad firstWordPad;

            if (m_wordPads.TryGetValue(WordPadTree.TopNode.FirstNode.Text, out firstWordPad))
            {
                UpdateWordListFromWordPad(firstWordPad);
            }

            if (_instance == null)
            {
                _instance = this;
            }

            WordListComparer sorter = new WordListComparer();

            sorter.Ascending            = true;
            sorter.SortKey              = WordSortKeyType.WordSortKeyAddTime;
            WordList.ListViewItemSorter = (IComparer)sorter;

            // timer to save all words every little while
            timerSaveAll.Enabled = true;

            int relX = WordList.Bounds.Location.X - Bounds.Location.X;
            int relY = WordList.Bounds.Location.Y - Bounds.Location.Y;

            m_iniWordListRelativeLocation = new Point(relX, relY);

            m_iniWordListMargin        = new Size();
            m_iniWordListMargin.Width  = Bounds.Right - WordList.Bounds.Right;
            m_iniWordListMargin.Height = Bounds.Bottom - WordList.Bounds.Bottom;
        }