public void fileOpen(SimpleForm frame) { if(frame.getIsChanged()) { DialogResult selection = MessageBox.Show("Do you want save document?", "Warrning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if(selection == DialogResult.No) { OpenFileDialog chooser = new OpenFileDialog(); if(chooser.ShowDialog() == DialogResult.OK) { frame.setFileName(chooser.FileName); String str = ""; try { StreamReader inStream = new StreamReader(new FileStream(frame.getFileName(),FileMode.OpenOrCreate, FileAccess.Read)); while (inStream.Peek() != -1) { str = inStream.ReadToEnd(); } frame.setTextArea(str); } catch (FileNotFoundException e) { } catch (IOException e) { } } } if(selection == DialogResult.Yes) { SaveFileDialog chooser = new SaveFileDialog(); if(chooser.ShowDialog() == DialogResult.OK) { frame.setFileName(chooser.FileName); try { StreamWriter outStream = new StreamWriter(new FileStream(frame.getFileName(),FileMode.OpenOrCreate, FileAccess.Write)); String str = frame.getTextArea(); outStream.Write(str); outStream.Close(); } catch (IOException e) { } } OpenFileDialog chooser2 = new OpenFileDialog(); if (chooser2.ShowDialog() == DialogResult.OK) { frame.setFileName(chooser2.FileName); String str = ""; try { StreamReader inStream = new StreamReader(new FileStream(frame.getFileName(),FileMode.OpenOrCreate, FileAccess.Read)); while (inStream.Peek() != -1) { str = inStream.ReadToEnd(); } frame.setTextArea(str); } catch (FileNotFoundException e) { } catch (IOException e) { } } } } else { OpenFileDialog chooser2 = new OpenFileDialog(); if (chooser2.ShowDialog() == DialogResult.OK) { frame.setFileName(chooser2.FileName); String str = ""; try { StreamReader inStream = new StreamReader(new FileStream(frame.getFileName(), FileMode.OpenOrCreate, FileAccess.Read)); while (inStream.Peek() != -1) { str = inStream.ReadToEnd(); } frame.setTextArea(str); } catch (FileNotFoundException e) { } catch (IOException e) { } } } frame.setIsFileNameSetted(true); frame.Name = "Text Editor " + frame.getFileName(); }
public void fileNew(SimpleForm frame) { frame.setIsFileNameSetted(false); frame.Text = "Text Editor"; if(frame.getIsChanged()) { DialogResult selection = MessageBox.Show("Do you want save document?", "Warrning", MessageBoxButtons.YesNo, MessageBoxIcon.Warning); if(selection == DialogResult.No) { frame.setTextArea(""); frame.setIsChanged(false); frame.Text = "Text Editor"; } if(selection == DialogResult.Yes) { SaveFileDialog chooser = new SaveFileDialog(); if(chooser.ShowDialog() == DialogResult.OK) { frame.setFileName(chooser.FileName); try { StreamWriter outStream = new StreamWriter(new FileStream(frame.getFileName(),FileMode.OpenOrCreate, FileAccess.Write)); String str = frame.getTextArea(); outStream.Write(str); outStream.Close(); } catch (IOException e) { } } frame.setTextArea(""); frame.setIsChanged(false); frame.Name = "Text Editor"; } } else { frame.setTextArea(""); } }