コード例 #1
0
ファイル: MainForm.cs プロジェクト: Open-Source-Gems/TexE
        private void SaveFile(TextDocument ad)
        {
            if (ad == null)
            {
                return;
            }
            if (string.IsNullOrEmpty(ad.FileName))
            {
                // Default file extension
                //this.saveFileDialog1.DefaultExt = "txt";
                // Available file extensions
                saveFileDialog1.Filter = "tex files (*.tex)|*.tex|bibtex files (*.bib)|*.bib|txt files (*.txt)|*.txt|All files (*.*)|*.*";

                // show dialog
                if (saveFileDialog1.ShowDialog() == DialogResult.OK)
                {
                    string format = ".tex";
                    // resolve file format
                    switch (Path.GetExtension(saveFileDialog1.FileName).ToLower())
                    {
                    case ".txt":
                        format = ".txt";
                        break;

                    case ".tex":
                        format = ".tex";
                        break;

                    case ".bib":
                        format = ".bib";
                        break;

                    default:
                        MessageBox.Show(this, "Unsupported file format was specified", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        return;
                    }
                }

                ad.txtEditor.Encoding = System.Text.Encoding.Default;
                if (saveFileDialog1.EncodingType == EncodingType.Ansi)
                {
                    ad.txtEditor.Encoding = System.Text.Encoding.Default;
                }
                if (saveFileDialog1.EncodingType == EncodingType.Unicode)
                {
                    ad.txtEditor.Encoding = System.Text.Encoding.Unicode;
                }
                if (saveFileDialog1.EncodingType == EncodingType.UTF8)
                {
                    ad.txtEditor.Encoding = new  System.Text.UTF8Encoding(false);
                }
                ad.FileName = saveFileDialog1.FileName;
            }

            this.UpdateRecent(ad.FileName);
            ActiveDocument.SaveFile();
        }
コード例 #2
0
        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveFileDialogWithEncoding sf = new SaveFileDialogWithEncoding();

            sf.Filter       = "Text (*.txt)|*.txt|All files (*.*)|*.*";
            sf.DefaultExt   = "txt";
            sf.EncodingType = EncodingType.Unicode;
            if (sf.ShowDialog() == DialogResult.OK)
            {
                filePath = sf.FileName;

                try
                {
                    File.WriteAllText(filePath, richTextBox1.Text);
                    saved = false;
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                if (opened != true)
                {
                    this.Text = "Untitled - SNote";
                }
            }
        }
コード例 #3
0
        private void Form1_FormClosing(object sender, FormClosingEventArgs e)
        {
            if (this.Text.Contains("Untitled") != true)
            {
                FileInfo fi = new FileInfo(fileName);
                if (fi.IsReadOnly == true)
                {
                    saved = true;
                    Application.Exit();
                }
            }

            if (saved != true)
            {
                if (MessageBox.Show("Do you want to save " + this.Text, "SNote", MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
                {
                    if (opened != true)
                    {
                        SaveFileDialogWithEncoding sf = new SaveFileDialogWithEncoding();
                        sf.Filter       = "Text (*.txt)|*.txt|All files (*.*)|*.*";
                        sf.DefaultExt   = "txt";
                        sf.EncodingType = EncodingType.Unicode;
                        if (sf.ShowDialog() == DialogResult.OK)
                        {
                            filePath = sf.FileName;
                            try
                            {
                                File.WriteAllText(filePath, richTextBox1.Text);
                            }
                            catch (Exception ex)
                            {
                                MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                            }
                        }
                    }
                    else
                    {
                        try
                        {
                            File.WriteAllText(fileName, richTextBox1.Text);
                        }
                        catch (Exception ex)
                        {
                            MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
                        }
                    }
                }
                saved = true;
            }

            Application.Exit();
        }
コード例 #4
0
 private void saveToolStripMenuItem_Click(object sender, EventArgs e)
 {
     if (opened != true)
     {
         SaveFileDialogWithEncoding sf = new SaveFileDialogWithEncoding();
         sf.DefaultExt   = "txt";
         sf.Filter       = "Text (*.txt)|*.txt|All files (*.*)|*.*";
         sf.EncodingType = EncodingType.Unicode;
         if (sf.ShowDialog() == DialogResult.OK)
         {
             filePath = sf.FileName;
             fileName = filePath;
             try
             {
                 File.WriteAllText(filePath, richTextBox1.Text);
                 saved     = true;
                 trueName  = filePath.Substring(filePath.LastIndexOf("\\") + 1);
                 this.Text = trueName + " - SNote";
                 opened    = true;
             }
             catch (Exception ex)
             {
                 MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
             }
         }
     }
     else
     {
         FileInfo fi = new FileInfo(fileName);
         if (fi.IsReadOnly == true)
         {
             saved = true;
             MessageBox.Show(fileName + " is read only!!", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
             return;
         }
         try
         {
             File.WriteAllText(fileName, richTextBox1.Text);
             saved = true;
         }
         catch (Exception ex)
         {
             MessageBox.Show(ex.Message, "ERROR", MessageBoxButtons.OK, MessageBoxIcon.Error);
         }
     }
 }
コード例 #5
0
ファイル: Form1.cs プロジェクト: KrzyKuStudio/Noteman
        private void saveFileCtrlSToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (nazwapliku != null)
            {
                try
                {
                    Encoding enc = Encoding.GetEncoding(kodowanie);
                    System.IO.File.WriteAllText(get_nazwa_pliku(), richTextBox1.Text, enc);
                }
                catch (Exception ex)
                {
                    MessageBox.Show("bleError: Could not save file to disk. Original error: " + ex.Message);
                }

            }
            else if (nazwapliku == null)
            {
                SaveFileDialogWithEncoding saveFileDialog2 = new SaveFileDialogWithEncoding();
                saveFileDialog2.Filter = "Text files|*.txt|All files|*.*";
                if (saveFileDialog2.ShowDialog() == DialogResult.OK)
                {
                    string kodowanie;
                    if (saveFileDialog2.EncodingType == EncodingType.UTF8)
                    {
                        kodowanie = "UTF-8";
                    }
                    else if (saveFileDialog2.EncodingType == EncodingType.WIN)
                    {
                        kodowanie = "Windows-1250";
                    }
                    else if (saveFileDialog2.EncodingType == EncodingType.UNICODE)
                    {
                        kodowanie = "UNICODE";
                    }
                    else
                    {
                        kodowanie = "ASCII";
                    }

                    try
                    {
                        Encoding enc = Encoding.GetEncoding(kodowanie);
                        System.IO.File.WriteAllText(saveFileDialog2.FileName, richTextBox1.Text, enc);

                    }
                    catch (Exception ex)
                    {
                        MessageBox.Show("Error: Could not save file to disk. Original error: " + ex.Message);
                    }
                    set_nazwa_pliku(saveFileDialog2.FileName);
                    set_nazwa_w_formularzu(saveFileDialog2.FileName);

                }
            }
        }
コード例 #6
0
ファイル: formEffectsEditor.cs プロジェクト: Aegisub/SSATool
 private void menuSaveEffectsFile_Click(object sender, System.EventArgs e)
 {
     SaveFileDialogWithEncoding ofd=new SaveFileDialogWithEncoding();
     ofd.DefaultExt="exml";
     ofd.EncodingType=EncodingType.ANSI;
     ofd.Filter="XML effect files (*.exml)|*.exml|All files (*.*)|*.*";
     if (ofd.ShowDialog((IntPtr)this.Handle,Screen.FromControl(this))==DialogResult.OK) {
         Form1.SaveEffectsFile(ofd.FileName,tColl);
     }
 }
コード例 #7
0
ファイル: Form1.cs プロジェクト: Aegisub/SSATool
 private void menuSaveProj_Click(object sender, System.EventArgs e)
 {
     SaveFileDialogWithEncoding ofd = new SaveFileDialogWithEncoding();
     ofd.DefaultExt = "xml";
     ofd.EncodingType = EncodingType.UTF8;
     ofd.Filter = "XML files (*.xml)|*.xml|All files (*.*)|*.*";
     if (ofd.ShowDialog((IntPtr)this.Handle, Screen.FromControl(this), "UTF-8") == DialogResult.OK) {
         SaveProject(ofd.FileName);
     }
 }
コード例 #8
0
ファイル: Form1.cs プロジェクト: Aegisub/SSATool
        private void menuSaveAs_Click(object sender, System.EventArgs e)
        {
            SaveFileDialogWithEncoding ofd = new SaveFileDialogWithEncoding();
            ofd.DefaultExt = "ass";
            ofd.EncodingType = EncodingType.Unicode;
            ofd.Filter = "SSA/ASS files (*.ass;*.ssa)|*.ass;*.ssa|All files (*.*)|*.*";
            if (ofd.ShowDialog((IntPtr)this.Handle, Screen.FromControl(this), enc == null ? string.Empty : enc.ToString()) == DialogResult.OK) {
                enc = SaveFileDialogWithEncoding.stringToEncodingType(ofd.EncodingType.ToString());
                SaveFile(ofd.FileName);

            }
        }