smolEdit/V_EditorPro/MainForm.cs
2024-05-27 22:48:14 +02:00

81 lines
2.4 KiB
C#

using System;
using System.Drawing;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Forms;
namespace V_EditorPro
{
public partial class MainForm : Form
{
public MainForm()
{
InitializeComponent();
this.KeyPreview = true;
this.KeyDown += new KeyEventHandler(MainForm_KeyDown);
}
private void MainForm_KeyDown(object sender, KeyEventArgs e)
{
if (e.Control && e.KeyCode == Keys.O)
{
OpenFile();
}
if (e.Control && e.KeyCode == Keys.S)
{
SaveFile();
}
}
private void openToolStripMenuItem_Click(object sender, EventArgs e)
{
OpenFile();
}
private void saveToolStripMenuItem_Click(object sender, EventArgs e)
{
SaveFile();
}
private void searchReplaceToolStripMenuItem_Click(object sender, EventArgs e)
{
using (SearchReplaceDialog searchReplaceDialog = new SearchReplaceDialog(richTextBox1))
{
searchReplaceDialog.ShowDialog();
}
}
private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
using (var aboutWindow = new AboutForm())
{
aboutWindow.ShowDialog();
}
}
private void OpenFile()
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Text Files (*.txt)|*.txt|Markdown Files (*.md)|*.md|Batch Files (*.bat)|*.bat|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog() == DialogResult.OK)
{
richTextBox1.Text = File.ReadAllText(openFileDialog.FileName);
}
}
private void SaveFile()
{
SaveFileDialog saveFileDialog = new SaveFileDialog();
saveFileDialog.FileName = $"{DateTime.Now.ToString("yyyy-MM-dd")}.txt";
saveFileDialog.Filter = "Text Files (*.txt)|*.txt|Markdown Files (*.md)|*.md|Batch Files (*.bat)|*.bat|All Files (*.*)|*.*";
saveFileDialog.DefaultExt = "txt";
saveFileDialog.FilterIndex = 1;
if (saveFileDialog.ShowDialog() == DialogResult.OK)
{
File.WriteAllText(saveFileDialog.FileName, richTextBox1.Text);
}
}
}
}