Exemplo n.º 1
0
        protected virtual void LoadFile()
        {
            this.ReadOnly = true;
            string ext = Path.GetExtension(this.FileName).ToLower();

            if (ext == ".txt" && this is SentenceListWithIndent)
            {
                LoadFileAsText();
            }
            else if (Array.IndexOf(GlobalOptions.SubtitlesFileExtensions, ext) != -1)
            {
                try
                {
                    List <Sentence> result = SentenceParser.GetSentencesFromSubtitles(this.FileName);
                    if (result.Count == 1 &&
                        string.IsNullOrEmpty(result[0].TextValue) &&
                        string.Equals(".txt", ext)) // is empty
                    {
                        this.FullText = SentenceParser.GetFileByRichTextBox(this.FileName);
                        this.ReadOnly = false;
                    }
                    else
                    {
                        this.Sentences  = result;
                        this.m_FullText = this.GetAllSentences();
                    }
                }
                catch // если не смогли пропарсить как субтитры попробуем открыть просто как текст
                {
                    // TODO: дублируется код 3 раза
                    if (string.Equals(".txt", ext))
                    {
                        LoadFileAsText();
                    }
                }
            }
            else
            {
                this.FullText = SentenceParser.GetFileByRichTextBox(this.FileName);
                this.ReadOnly = false;
            }
        }