Ejemplo n.º 1
0
        private void DualEditForm_FormClosing(object sender, FormClosingEventArgs e)
        {
            e.Cancel = false;

            if (this.IsDirty)   //  || this.IsNoName()  沒取檔名時不用問
            {
                string s = "點字資料尚未儲存,是否儲存?" + Environment.NewLine + Environment.NewLine +
                           "[是]  = 儲存並關閉此視窗。" + Environment.NewLine +
                           "[否]  = 不儲存並關閉此視窗。" + Environment.NewLine +
                           "[取消] = 取消關閉視窗的動作,繼續編輯點字。";

                DialogResult result = MsgBoxHelper.ShowYesNoCancel(s);
                if (result == DialogResult.Cancel)
                {
                    e.Cancel = true;
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    if (!DoSaveFile())
                    {
                        e.Cancel = true;
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void DoOpenFile()
        {
            if (IsDirty)
            {
                switch (MsgBoxHelper.ShowYesNoCancel("目前的檔案尚未儲存,是否儲存?"))
                {
                case DialogResult.Yes:
                    DoSaveFile();
                    break;

                case DialogResult.Cancel:
                    return;

                default:
                    break;
                }
            }

            OpenFileDialog dlg = new OpenFileDialog();

            dlg.Multiselect = false;
            dlg.Filter      = Constant.Files.FileNameFilter;
            dlg.FilterIndex = Constant.Files.FileNameFilterIndex;

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                InternalLoadFile(dlg.FileName);
            }
        }
Ejemplo n.º 3
0
        private void OpenFile()
        {
            if (Modified)
            {
                DialogResult result = MsgBoxHelper.ShowYesNoCancel("目前的文件尚未儲存,是否儲存?");
                if (result == DialogResult.Cancel)
                {
                    return;
                }
                if (result == DialogResult.Yes)
                {
                    SaveFile();
                }
            }

            var dlg = new OpenFileDialog
            {
                Filter = "文字檔(*.txt)|*.txt|雙視檔案(*.btx)|*.btx|所有檔案|*.*"
            };

            if (dlg.ShowDialog() == DialogResult.OK)
            {
                Modified = false;
                if (dlg.FileName.ToLower().EndsWith(".btx"))
                {
                    string s = dlg.FileName.Replace(".btx", ".txt");
                    if (File.Exists(s))
                    {
                        this.FileName = s;
                        if (FileHelper.IsUTF8Encoded(FileName))
                        {
                            rtbOrg.Text = File.ReadAllText(FileName, Encoding.UTF8);
                        }
                        rtbOrg.LoadFile(FileName, RichTextBoxStreamType.PlainText);
                    }

                    OpenBrailleFileInEditor(dlg.FileName);
                }
                else
                {
                    this.FileName = dlg.FileName;
                    if (FileHelper.IsUTF8Encoded(FileName))
                    {
                        rtbOrg.Text = File.ReadAllText(FileName, Encoding.UTF8);
                    }
                    else
                    {
                        rtbOrg.LoadFile(FileName, RichTextBoxStreamType.PlainText);
                    }
                }
            }
        }
Ejemplo n.º 4
0
 private void NewFile()
 {
     if (Modified)
     {
         DialogResult result = MsgBoxHelper.ShowYesNoCancel("目前的文件尚未儲存,是否儲存?");
         if (result == DialogResult.Cancel)
         {
             return;
         }
         if (result == DialogResult.Yes)
         {
             SaveFile();
         }
     }
     rtbOrg.Clear();
     rtbOrg.ClearUndo();
     Modified = false;
     FileName = "";
 }
Ejemplo n.º 5
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     e.Cancel = false;
     if (Modified)
     {
         DialogResult result = MsgBoxHelper.ShowYesNoCancel("目前的文件尚未儲存,是否儲存?");
         if (result == DialogResult.Cancel)
         {
             e.Cancel = true;
             return;
         }
         if (result == DialogResult.Yes)
         {
             if (!SaveFile())
             {
                 e.Cancel = true;
             }
         }
     }
 }
Ejemplo n.º 6
0
        /// <summary>
        /// 轉換點字並開啟編輯器。
        /// </summary>
        private void ConvertAndShowEditor()
        {
            if (m_ConvertDialog.ShowDialog() != DialogResult.OK)
            {
                return;
            }

            PrepareForConvertion();

            // 決定要轉換的輸入文字
            string content;

            if (rtbOrg.SelectionLength > 1) // 若有選取文字,就只轉換選取的部份。
            {
                content = rtbOrg.SelectedText;
            }
            else
            {
                // 若已存在雙視檔案,則詢問是否直接載入。
                string brljFileName = FileName.Replace(".txt", ".brlj");
                string btxFileName  = FileName.Replace(".txt", ".btx");
                if (File.Exists(brljFileName) || File.Exists(btxFileName))
                {
                    string s = "雙視檔案已經存在,是否重新轉點字?\n[是]: 執行點字轉換\n[否]: 直接載入既有的雙視資料";
                    switch (MsgBoxHelper.ShowYesNoCancel(s))
                    {
                    case DialogResult.Yes:
                        content = rtbOrg.Text;
                        break;

                    case DialogResult.No:
                        if (File.Exists(brljFileName))
                        {
                            OpenBrailleFileInEditor(brljFileName);
                        }
                        else
                        {
                            OpenBrailleFileInEditor(btxFileName);
                        }
                        return;

                    default:
                        this.Enabled = true;
                        return;
                    }
                }
                else
                {
                    content = rtbOrg.Text;
                }
            }

            this.Enabled      = false;
            txtErrors.Visible = true;

            // 執行轉換
            string outFileName = DoConvert(content);

            this.Enabled = true;

            if (!HandleConvertionError())
            {
                return;
            }

            OpenBrailleFileInEditor(outFileName);
        }