From 943b4dcb5fa597264f13f2d0cfa305f4dd542dbe Mon Sep 17 00:00:00 2001 From: Alex-TIMEHACK Date: Fri, 18 Aug 2017 20:41:45 +0100 Subject: Wordpad Save, Open and Save As --- .../OS/Win95/Win95Apps/WinClassicWordPad.cs | 64 ++++++++++++++++++++++ 1 file changed, 64 insertions(+) (limited to 'TimeHACK.Main/OS/Win95/Win95Apps/WinClassicWordPad.cs') diff --git a/TimeHACK.Main/OS/Win95/Win95Apps/WinClassicWordPad.cs b/TimeHACK.Main/OS/Win95/Win95Apps/WinClassicWordPad.cs index 7d7956a..f8a927e 100644 --- a/TimeHACK.Main/OS/Win95/Win95Apps/WinClassicWordPad.cs +++ b/TimeHACK.Main/OS/Win95/Win95Apps/WinClassicWordPad.cs @@ -9,6 +9,8 @@ using System.Threading.Tasks; using System.Windows.Forms; using System.Drawing.Text; using TimeHACK.Engine; +using static TimeHACK.Engine.FileDialogBoxManager; +using System.IO; namespace TimeHACK.OS.Win95.Win95Apps { @@ -20,6 +22,8 @@ namespace TimeHACK.OS.Win95.Win95Apps bool doItalic = false; bool doUnderline = false; + string CurrentFilePath = ""; + public WinClassicWordPad() { InitializeComponent(); @@ -169,5 +173,65 @@ namespace TimeHACK.OS.Win95.Win95Apps if (doUnderline) Underline = FontStyle.Underline; mainText.SelectionFont = new Font(mainText.SelectionFont.FontFamily, mainText.SelectionFont.Size, Bold | Italic | Underline); } + + private void openToolStripMenuItem1_Click(object sender, EventArgs e) + { + try + { + ActivateOpenFileDialog(".rtf"); + string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath(); + + if (selectedPath != null) + { + try + { + mainText.LoadFile(selectedPath); + } catch + { + (new WindowManager()).StartInfobox95("Wordpad", "An error occured opening the file.", Engine.Template.InfoboxType.Error, Engine.Template.InfoboxButtons.OK); + } + + } + } + catch + { + } + } + + private void saveAsToolStripMenuItem_Click(object sender, EventArgs e) + { + SaveAs(); + } + + private void saveToolStripMenuItem_Click(object sender, EventArgs e) + { + if (CurrentFilePath == "") + { + // We aren't in a file right now + + SaveAs(); + } + else + { + File.Delete(CurrentFilePath); + SaveRtfDocument(mainText, CurrentFilePath); + } + } + + void SaveAs() + { + try + { + ActivateSaveFileDialog(".rtf"); + string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath(); + + if (selectedPath != "") + { + SaveRtfDocument(mainText, selectedPath); + CurrentFilePath = selectedPath; + } + } + catch (Exception ex) { MessageBox.Show(ex.Message); } + } } } \ No newline at end of file -- cgit v1.2.3