// Thread threadRemote;


        public void GetTitleColor()
        {
            try {
                titleColor = MiscConverter.IntToSolidColorBrush(MiscConverter.StringToIntColor(Setting.GetAttribute("titleColor")));
            } catch (Exception ex) {
                Console.WriteLine(ex.Message);
                titleColor = MiscConverter.IntToSolidColorBrush(0xffff00);
            }

            if (freePresentationText != null)
            {
                // free text presentation: don't change contents
                UpdateFree();
            }
            if (WrapPanelPageList != null && WrapPanelPageList.Children.Count > 1)
            {
                // if a text file is open, the minimum of Count is 2
                int len = textList.Count;
                for (int i = 1; i < len; i++)
                {
                    if (isTitleList[i])
                    {
                        (WrapPanelPageList.Children[i - 1] as Button).Foreground = titleColor;
                    }
                }
            }

            if (isTitleList != null)
            {
                if (PgmContent != null && isTitleList[pgmManager.PageNumber])
                {
                    PgmContent.Foreground = titleColor;
                    if (pw != null)
                    {
                        pw.LabelPresenterText.Foreground = titleColor;
                    }
                }

                if (PvwContent != null && isTitleList[pvwManager.PageNumber])
                {
                    PvwContent.Foreground = titleColor;
                }
            }
        }
        private void OpenTxtFile(bool resetPvw)
        {
            Encoding encoding;

            if (resetPvw)
            {
                pvwManager.PageNumber = 1;
            }
            if (!int.TryParse(Setting.GetAttribute("textEncoding"), out int textEncoding) || textEncoding == 0)
            {
                textEncoding = 0;
                encoding     = Encoding.Default;
            }
            else
            {
                try {
                    encoding = Encoding.GetEncoding(textEncoding);
                } catch (Exception ex) {
                    MessageBox.Show(
                        ex.Message + "\n프로그램의 인코딩 설정(" + textEncoding.ToString() + ")이 잘못되었습니다.",
                        "TextPresenter51456");
                    textEncoding = 0;
                    encoding     = Encoding.Default;
                }
            }
            // read the selected file
            try {
                System.IO.StreamReader sr = new System.IO.StreamReader(filePath + fileName, encoding);
                string fullText           = sr.ReadToEnd();
                sr.Close();
                fullText = newLineUnifier.Replace(fullText, "\n");         // unify newline characters
                fullText = trimmer.Replace(fullText, "");                  // trimming newlines
                textList = new List <string>(pageBreaker.Split(fullText)); // split pages
                textList.Insert(0, "");                                    // leave index 0 empty for convenience
                textList.Add("");                                          // add an empty page at the end
                WindowMainWindow.Title = "TextPresenter51456 - " + fileName + " (" + filePath + ")";
            } catch (Exception e) {
                string errMsg = "Fail to read the file";
                errMsg += "\nMessage: " + e.Message;
                errMsg += "\nSource" + e.Source;
                MessageBox.Show(errMsg, "TextPresenter51456");
                return;
            }
            // show the file read as the page list
            try {
                int   len = textList.Count;
                int   i   = 1;
                Style pageListItemStyle = FindResource("PageListItem") as Style;

                isTitleList = new List <bool>(len)
                {
                    false
                };

                WrapPanelPageList.Children.Clear();

                // construct page list
                while (i < len)
                {
                    // unify escaped comments
                    if (commentEscaped.IsMatch(textList[i]))
                    {
                        textList[i] = commentEscaped.Replace(textList[i], @"/\/");
                    }
                    // remove comments
                    if (pageComment.IsMatch(textList[i]))   // page comment -> remove the page
                    {
                        textList.RemoveAt(i);
                        textList.Capacity -= 1;
                        len -= 1;
                        continue;
                    }
                    if (middleFullLineComment.IsMatch(textList[i]))   // full line comment (the middle line of the page) -> remove the line
                    {
                        textList[i] = middleFullLineComment.Replace(textList[i], "\n");
                    }
                    if (firstFullLineComment.IsMatch(textList[i]))   // full line comment (the 1st line of the page) -> remove the line
                    {
                        textList[i] = firstFullLineComment.Replace(textList[i], "");
                    }
                    if (lastFullLineComment.IsMatch(textList[i]))   // full line comment (the last line of the page) -> remove the line
                    {
                        textList[i] = lastFullLineComment.Replace(textList[i], "");
                    }
                    if (partialLineComment.IsMatch(textList[i]))   // partial line comment -> remove the comment
                    {
                        textList[i] = partialLineComment.Replace(textList[i], "$1");
                    }
                    // correct escaped comments
                    if (commentEscaped.IsMatch(textList[i]))
                    {
                        textList[i] = commentEscaped.Replace(textList[i], "//");
                    }

                    Button pageListItem = new Button {
                        Style = pageListItemStyle,
                        Tag   = i
                    };
                    if (sharp.IsMatch(textList[i]))   // remove beginning #s and make these pages "header pages"
                    {
                        textList[i] = sharp.Replace(textList[i], "");
                        isTitleList.Add(true);
                        pageListItem.Foreground = titleColor;
                    }
                    else
                    {
                        isTitleList.Add(false);
                    }
                    if (sharpEscaped.IsMatch(textList[i]))   // escaped # (\#)
                    {
                        textList[i] = sharpEscaped.Replace(textList[i], "#$1");
                    }
                    pageListItem.Content = textList[i];

                    WrapPanelPageList.Children.Add(pageListItem);

                    i++;
                }
                pgmManager.LastPageNumber  = pvwManager.LastPageNumber = len - 1;
                LabelPageIndicator.Content = "/" + (len - 1).ToString();
                UpdatePvw();
            } catch (Exception e) {
                string errMsg = "Failed to display the file";
                errMsg += "\nMessage: " + e.Message;
                errMsg += "\nSource" + e.Source;
                MessageBox.Show(errMsg, "TextPresenter51456");
            }

            MenuItemRefresh.IsEnabled = true;
            Session.New(PgmContent.Content as string, textList[pvwManager.PageNumber], textList[pgmManager.PageNumber + 1]);
        }