|
| 1 | +using System; |
| 2 | +using System.Collections.Generic; |
| 3 | +using System.ComponentModel; |
| 4 | +using System.Data; |
| 5 | +using System.Drawing; |
| 6 | +using System.IO; |
| 7 | +using System.Linq; |
| 8 | +using System.Text; |
| 9 | +using System.Threading.Tasks; |
| 10 | +using System.Windows.Forms; |
| 11 | + |
| 12 | +namespace VortexEditor |
| 13 | +{ |
| 14 | + public partial class Form1 : Form |
| 15 | + { |
| 16 | + protected bool boChanged = false; |
| 17 | + |
| 18 | + public String filename = "File"; |
| 19 | + public String fileindex = ""; |
| 20 | + public bool saved = false; |
| 21 | + |
| 22 | + public Form1() |
| 23 | + { |
| 24 | + InitializeComponent(); |
| 25 | + this.text.TextChanged += Text_TextChanged; |
| 26 | + this.FormClosing += Form1_FormClosing; |
| 27 | + this.Load += Form1_Load; |
| 28 | + clearChanged(); |
| 29 | + } |
| 30 | + |
| 31 | + protected void clearChanged() |
| 32 | + { |
| 33 | + boChanged = false; |
| 34 | + this.Text = Properties.Resources.Title + filename; |
| 35 | + } |
| 36 | + |
| 37 | + protected void setChanged() |
| 38 | + { |
| 39 | + boChanged = true; |
| 40 | + this.Text = Properties.Resources.Title_changed + filename + Properties.Resources.Title_changed_suffix; |
| 41 | + } |
| 42 | + |
| 43 | + private void newText_Click(object sender, EventArgs e) |
| 44 | + { |
| 45 | + if (!boChanged) |
| 46 | + { |
| 47 | + text.Clear(); |
| 48 | + } |
| 49 | + else |
| 50 | + { |
| 51 | + DialogResult saving = MessageBox.Show("Do you want to save the changes?", "Vortex Editor", MessageBoxButtons.YesNoCancel); |
| 52 | + if (saving == DialogResult.Yes) |
| 53 | + { |
| 54 | + saveText_Click(null, null); |
| 55 | + if (saved) |
| 56 | + { |
| 57 | + text.Clear(); |
| 58 | + } |
| 59 | + } |
| 60 | + else if (saving == DialogResult.No) |
| 61 | + { |
| 62 | + text.Clear(); |
| 63 | + } |
| 64 | + else if (saving == DialogResult.Cancel) |
| 65 | + { |
| 66 | + text.Clear(); |
| 67 | + } |
| 68 | + } |
| 69 | + } |
| 70 | + |
| 71 | + private void openText_Click(object sender, EventArgs e) |
| 72 | + { |
| 73 | + OpenFileDialog openfile = new OpenFileDialog(); |
| 74 | + openfile.Title = "Vortex Editor - Open File"; |
| 75 | + openfile.Filter = "Text files (*.txt)|*.txt|Markdown document (*.md)|*.md|JSON Config (*.json)|*.json|YAML Config (*.yml)|*.yml|All files (*.*)|*"; |
| 76 | + if (openfile.ShowDialog() == DialogResult.OK) |
| 77 | + { |
| 78 | + text.Clear(); |
| 79 | + text.Text = File.ReadAllText(openfile.FileName); |
| 80 | + fileindex = File.ReadAllText(openfile.FileName); |
| 81 | + filename = openfile.FileName; |
| 82 | + clearChanged(); |
| 83 | + } |
| 84 | + } |
| 85 | + private void saveText_Click(object sender, EventArgs e) |
| 86 | + { |
| 87 | + SaveFileDialog savefile = new SaveFileDialog(); |
| 88 | + savefile.Filter = "Text files (*.txt)|*.txt|Markdown document (*.md)|*.md|JSON Config (*.json)|*.json|YAML Config (*.yml)|*.yml|All files (*.*)|*"; |
| 89 | + savefile.FileName = "*.txt"; |
| 90 | + savefile.Title = "Vortex Editor - Save File"; |
| 91 | + if (savefile.ShowDialog() == DialogResult.OK) |
| 92 | + { |
| 93 | + File.WriteAllText(savefile.FileName, text.Text); |
| 94 | + clearChanged(); |
| 95 | + saved = true; |
| 96 | + } |
| 97 | + else |
| 98 | + { |
| 99 | + saved = false; |
| 100 | + } |
| 101 | + } |
| 102 | + |
| 103 | + private void quit_Click(object sender, EventArgs e) |
| 104 | + { |
| 105 | + this.Close(); |
| 106 | + } |
| 107 | + |
| 108 | + private void undoText_Click(object sender, EventArgs e) |
| 109 | + { |
| 110 | + text.Undo(); |
| 111 | + } |
| 112 | + |
| 113 | + private void redoText_Click(object sender, EventArgs e) |
| 114 | + { |
| 115 | + text.Redo(); |
| 116 | + } |
| 117 | + |
| 118 | + private void cutText_Click(object sender, EventArgs e) |
| 119 | + { |
| 120 | + text.Cut(); |
| 121 | + } |
| 122 | + |
| 123 | + private void copyText_Click(object sender, EventArgs e) |
| 124 | + { |
| 125 | + text.Copy(); |
| 126 | + } |
| 127 | + |
| 128 | + private void pasteText_Click(object sender, EventArgs e) |
| 129 | + { |
| 130 | + text.Paste(); |
| 131 | + } |
| 132 | + |
| 133 | + private void selectAllText_Click(object sender, EventArgs e) |
| 134 | + { |
| 135 | + text.SelectAll(); |
| 136 | + } |
| 137 | + |
| 138 | + private void info_Click(object sender, EventArgs e) |
| 139 | + { |
| 140 | + Info infoWindow = new Info(); |
| 141 | + infoWindow.Show(); |
| 142 | + } |
| 143 | + |
| 144 | + private void youtubeLink_Click(object sender, EventArgs e) |
| 145 | + { |
| 146 | + System.Diagnostics.Process process = new System.Diagnostics.Process(); |
| 147 | + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); |
| 148 | + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; |
| 149 | + startInfo.FileName = "explorer.exe"; |
| 150 | + startInfo.Arguments = "https://youtube.com/c/Minecodes"; |
| 151 | + process.StartInfo = startInfo; |
| 152 | + process.Start(); |
| 153 | + } |
| 154 | + |
| 155 | + private void githubLink_Click(object sender, EventArgs e) |
| 156 | + { |
| 157 | + System.Diagnostics.Process process = new System.Diagnostics.Process(); |
| 158 | + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); |
| 159 | + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; |
| 160 | + startInfo.FileName = "explorer.exe"; |
| 161 | + startInfo.Arguments = "https://github.com/Minecodes"; |
| 162 | + process.StartInfo = startInfo; |
| 163 | + process.Start(); |
| 164 | + } |
| 165 | + |
| 166 | + private void gitlabLink_Click(object sender, EventArgs e) |
| 167 | + { |
| 168 | + System.Diagnostics.Process process = new System.Diagnostics.Process(); |
| 169 | + System.Diagnostics.ProcessStartInfo startInfo = new System.Diagnostics.ProcessStartInfo(); |
| 170 | + startInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden; |
| 171 | + startInfo.FileName = "explorer.exe"; |
| 172 | + startInfo.Arguments = "https://gitlab.com/Minecodes13"; |
| 173 | + process.StartInfo = startInfo; |
| 174 | + process.Start(); |
| 175 | + } |
| 176 | + |
| 177 | + private void newTextTools_Click(object sender, EventArgs e) |
| 178 | + { |
| 179 | + newText.PerformClick(); |
| 180 | + } |
| 181 | + |
| 182 | + private void openTextTools_Click(object sender, EventArgs e) |
| 183 | + { |
| 184 | + openText.PerformClick(); |
| 185 | + } |
| 186 | + |
| 187 | + private void saveTextTools_Click(object sender, EventArgs e) |
| 188 | + { |
| 189 | + saveText.PerformClick(); |
| 190 | + } |
| 191 | + |
| 192 | + private void cutTextTools_Click(object sender, EventArgs e) |
| 193 | + { |
| 194 | + cutText.PerformClick(); |
| 195 | + } |
| 196 | + |
| 197 | + private void copyTextTools_Click(object sender, EventArgs e) |
| 198 | + { |
| 199 | + copyText.PerformClick(); |
| 200 | + } |
| 201 | + |
| 202 | + private void pasteTextTools_Click(object sender, EventArgs e) |
| 203 | + { |
| 204 | + pasteText.PerformClick(); |
| 205 | + } |
| 206 | + |
| 207 | + private void Text_TextChanged(object sender, System.EventArgs e) |
| 208 | + { |
| 209 | + if (string.IsNullOrEmpty(text.Text) || text.Text == fileindex) |
| 210 | + { |
| 211 | + clearChanged(); |
| 212 | + } |
| 213 | + else |
| 214 | + { |
| 215 | + setChanged(); |
| 216 | + } |
| 217 | + |
| 218 | + } |
| 219 | + |
| 220 | + private void Form1_Load(object sender, System.EventArgs e) |
| 221 | + { |
| 222 | + clearChanged(); |
| 223 | + } |
| 224 | + |
| 225 | + private void Form1_FormClosing(object sender, System.Windows.Forms.FormClosingEventArgs e) |
| 226 | + { |
| 227 | + if (boChanged) |
| 228 | + { |
| 229 | + DialogResult saving = MessageBox.Show("Do you want to save the changes?", "Vortex Editor", MessageBoxButtons.YesNoCancel); |
| 230 | + if (saving == DialogResult.Yes) |
| 231 | + { |
| 232 | + saveText_Click(null, null); |
| 233 | + e.Cancel = true; |
| 234 | + } else if (saving == DialogResult.No) |
| 235 | + { |
| 236 | + e.Cancel = false; |
| 237 | + } else if (saving == DialogResult.Cancel) |
| 238 | + { |
| 239 | + e.Cancel = true; |
| 240 | + } |
| 241 | + } |
| 242 | + } |
| 243 | + |
| 244 | + } |
| 245 | +} |
0 commit comments