-
Notifications
You must be signed in to change notification settings - Fork 0
/
Form_File.cs
75 lines (65 loc) · 2.01 KB
/
Form_File.cs
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
using System;
using System.Windows.Forms;
#nullable enable
namespace Interpret_Interface
{
public partial class Form_File : Form
{
public Form_File()
{
InitializeComponent();
}
public string OriginalFile { get; set; } = "";
// Open a file into the viewer
public void SetText(string pathString, string text)
{
Text_FileContents.Text = text;
Text = pathString;
OriginalFile = text;
}
// Save the contents to a file
public (string, string) GetText()
{
return new (Text, Text_FileContents.Text);
}
public void Cut()
{
if (ActiveControl is TextBox Text_FileContents)
{
if (!Text_FileContents.SelectionLength.Equals(0))
{
Clipboard.SetText(Text_FileContents.SelectedText);
Text_FileContents.SelectedText = "";
}
}
}
public void Copy()
{
if (ActiveControl is TextBox Text_FileContents)
{
if (!Text_FileContents.SelectionLength.Equals(0))
{
Clipboard.SetText(Text_FileContents.SelectedText);
}
}
}
public void Paste()
{
if (ActiveControl is TextBox Text_FileContents)
{
Text_FileContents.Paste(Clipboard.GetText());
}
}
private void Form_File_FormClosing(object sender, FormClosingEventArgs e)
{
if (Text_FileContents.Text != OriginalFile)
{
DialogResult result = MessageBox.Show($"Are you sure you want to close unsaved file, {Text}?", "Confirmation", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
if (result == DialogResult.No)
{
e.Cancel = true; // Cancel the closing action
}
}
}
}
}