aboutsummaryrefslogtreecommitdiff
path: root/Histacom2/GlobalPrograms/WinClassicNotepad.cs
blob: 1a58d8edf89d75a4d1d0c2b34f1610fd355b57b6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using Histacom2.Engine;
using static Histacom2.Engine.FileDialogBoxManager;
using System.IO;

namespace Histacom2.GlobalPrograms
{
    public partial class WinClassicNotepad : UserControl
    {
        public string CurrentFilePath = "";
        public WinClassicNotepad()
        {
            InitializeComponent();
            foreach (ToolStripMenuItem item in menuStrip1.Items)
            {
                item.Font = new Font(TitleScreen.pfc.Families[0], 16F, FontStyle.Regular);
                item.BackColor = Color.Silver;
                item.BackgroundImage = Properties.Resources.sliversilver;
                item.BackgroundImageLayout = ImageLayout.Center;
                item.DisplayStyle = ToolStripItemDisplayStyle.Text;
            }
        }

        private void exitToolStripMenuItem_Click(object sender, EventArgs e)
        {
            this.ParentForm.Close();
        }

        private void aboutNotepadToolStripMenuItem_Click(object sender, EventArgs e)
        {
            WindowManager wm = new WindowManager();
            wm.StartAboutBox95("Notepad", "Microsoft Notepad", Properties.Resources.WinClassicNotepad);
        }

        private void wordWrapToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mainText.WordWrap = wordWrapToolStripMenuItem.Checked;
        }

        private void selectAllToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mainText.SelectAll();
        }

        private void undoToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mainText.Undo();
        }

        private void cutToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (mainText.SelectedText.Length >= 0) mainText.Cut();
        }

        private void copyToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (mainText.SelectedText.Length >= 0) mainText.Copy();
        }

        private void pasteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mainText.Paste();
        }

        private void deleteToolStripMenuItem_Click(object sender, EventArgs e)
        {
            mainText.Text.Remove(mainText.SelectionStart, mainText.SelectedText.Length);
        }

        private void timeDateToolStripMenuItem_Click(object sender, EventArgs e)
        {
            string DateTime = System.DateTime.Now.ToString("HH:mm tt dd/MM/yyyy");
            mainText.AppendText(DateTime);
        }

        private void openToolStripMenuItem_Click(object sender, EventArgs e)
        {
            try
            {
                ActivateOpenFileDialog(".txt");
                string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();

                if (selectedPath != "")
                {
                    mainText.Text = ReadTextFile(selectedPath);
                }
            }
            catch
            {
            }
        }

        private void saveToolStripMenuItem_Click(object sender, EventArgs e)
        {
            if (CurrentFilePath == "")
            {
                // We aren't in a file right now

                SaveAs();
            } else {

                File.Delete(CurrentFilePath);
                SaveSystem.CreateWindowsFile(new FileInfo(CurrentFilePath).Directory.FullName, CurrentFilePath.Split('\\').Last(), mainText.Text, 12, mainText.Text.Length);
            }
        }

        void SaveAs()
        {
            try
            {
                ActivateSaveFileDialog(".txt");
                string selectedPath = Program.OpenFileExplorerAsDialogAndReturnGivenPath();

                if (selectedPath != "")
                {
                    SaveSystem.CreateWindowsFile(new FileInfo(selectedPath).Directory.FullName, selectedPath.Split('\\').Last(), mainText.Text, 12, mainText.Text.Length);
                    CurrentFilePath = selectedPath;
                } 
            }
            catch { }
        }

        private void saveAsToolStripMenuItem_Click(object sender, EventArgs e)
        {
            SaveAs();
        }
    }
}