This repository has been archived by the owner on Dec 25, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCoreForm.cs
299 lines (240 loc) · 11.9 KB
/
CoreForm.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
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
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Diagnostics;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Xml;
namespace Ava
{
public partial class CoreForm : Form
{
// Declare global variables
string path;
public static string textualContent;
string targetText;
// private int aboutClickCounter;
PreviewForm previewingForm = new PreviewForm();
SeekForm findRequestForm = new SeekForm();
ReplaceForm substitutionForm = new ReplaceForm();
// Constuctor of CoreForm
public CoreForm()
{
InitializeComponent();
// Define base values for the forms
path = "";
textualContent = "";
targetText = "";
// Defines some basic properties at initialization
contentRichTb.WordWrap = true;
contentRichTb.AcceptsTab = true;
contentRichTb.EnableAutoDragDrop = true;
contentRichTb.DetectUrls = true;
contentRichTb.AutoWordSelection = true;
// contentRichTb.BulletIndent;
}
private void newToolStripButton_Click(object sender, EventArgs e)
{
// Start a new instance of the program
Process.Start(Application.ProductName);
}
private void openToolStripButton_Click(object sender, EventArgs e)
{
// Displays a new dialog window to gather the content of a existing file then record the choice in the variable "choice"
OpenFileDialog openFile1 = new OpenFileDialog();
DialogResult choice = openFile1.ShowDialog();
// Record the complete file path to the variable "path"
path = openFile1.FileName;
// If the choice is affirmative and that the file contains more than more character, then it shall be saved
if (choice == DialogResult.OK && openFile1.FileName.Length > 0)
{
// Opening the selected file and reads it to the very end
StreamReader softStreamRead = new StreamReader(openFile1.FileName);
contentRichTb.Text = softStreamRead.ReadToEnd();
// Closing the reader to optimize computer resources and avoid some vulnerabilities
softStreamRead.Close();
}
}
private void saveToolStripButton_Click(object sender, EventArgs e)
{
// Give file location choice to the user
SaveFileDialog saveFile = new SaveFileDialog();
// Define the extension nand filters for the types of files that it may save
saveFile.DefaultExt = "*.txt";
saveFile.Filter = "Plain text files(*.txt)|*.txt|All files(*.*)|*.*";
// Stocks the dialog choice and then the complete system path in the variable path
DialogResult choice = saveFile.ShowDialog();
path = saveFile.FileName;
// If the choice is affirmative (OK) and that the file contains more than zero characters, then it is saved
if (choice == DialogResult.OK && saveFile.FileName.Length > 0) { contentRichTb.SaveFile(saveFile.FileName, RichTextBoxStreamType.PlainText); /* The StreamType defines the saved file type */ }
else if (saveFile.FileName.Length <= 0) { saveFile.Dispose(); }
}
private void closeToolStripButton_Click(object sender, EventArgs e)
{
// Displays a choice dialog to warn the user and then stocks the response in a DialogResult
DialogResult choice = MessageBox.Show("Are you sure you want to exit the program?\nYou may have unsaved changes.", "Confirm exit?", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
// If the user indicates yes to the previous request, we empty the CoreForm content and properly terminates the entire program
if(choice == DialogResult.Yes)
{
contentRichTb.Clear();
Application.Exit();
}
}
private void contentRichTb_TextChanged(object sender, EventArgs e)
{
// Update the nymber of symbols in symbolCounterTSSLb
int numSymbols = contentRichTb.Text.Length;
symbolCounterTSSLb.Text = String.Format("Number of symbols: "+numSymbols);
textualContent = contentRichTb.Text;
}
private void previewToolStripButton_Click(object sender, EventArgs e)
{
previewingForm.Show();
/* Gonna see about that soon enough after some more reading of both the XML documentation and the hyperlink's ReadMe: https://github.com/MindTouch/SGMLReader */
}
private void undoToolStripButton_Click(object sender, EventArgs e)
{
// If we can undo instructions, then we simply undo then one step at a time
if(contentRichTb.CanUndo) { contentRichTb.Undo(); /* contentRichTb.ClearUndo(); /* Only if you want to undo only once, because clearing that buffer may impede productivity */ }
}
private void redoToolStripButton_Click(object sender, EventArgs e)
{
// If we can redo instructions that are also not Delete, then we can do the action of Redo
if (contentRichTb.CanRedo == true) { if (contentRichTb.RedoActionName != "Delete") { contentRichTb.Redo(); } }
}
private void cutToolStripButton_Click(object sender, EventArgs e)
{
// If there is more than zero charcters to cut, just do the requested Cut
if(contentRichTb.SelectionLength > 0) { contentRichTb.Cut(); }
}
private void copyToolStripButton_Click(object sender, EventArgs e)
{
// If there is more than zero charcters to copy, just do the requested Copy
if(contentRichTb.SelectionLength > 0) { contentRichTb.Copy(); }
}
private void pasteToolStripButton_Click(object sender, EventArgs e)
{
// When you have text in the clipboard to paste, just do the Pasting
if(Clipboard.GetDataObject().GetDataPresent(DataFormats.Text)) { contentRichTb.Paste(); }
}
/*
// AWFUL CODE THAT DOES ITS INTENDED PURPOSE BUT NOT WELL ENOUGH YET SO I DISABLED IT PARTIALLY
private void findToolStripButton_Click(object sender, EventArgs e)
{
if (!findRequestForm.Visible)
{
// Show the substituteForm
findRequestForm.Show();
SeekForm neueFindRequestForm = new SeekForm();
}
else if (findRequestForm.Visible)
{
// Hide the substituteForm
findRequestForm.Hide();
}
// Defines the target string to find out inside "contentRichTb"
targetText = SeekForm.seekedString;
if (SeekForm.hasValidValue)
{
// If textualContent contains targetText, then display a MessageBox with the target text and its position index into the richTextBox accordingly
if (textualContent.Contains(targetText)) { MessageBox.Show("Found a match for " + "\"" + targetText + "\"" + " in this document."); }
if (!textualContent.Contains(targetText)) { MessageBox.Show("Found no match for " + "\"" + targetText + "\"" + " in this document."); }
}
}
private void replaceToolStripButton_Click(object sender, EventArgs e)
{
if (!substitutionForm.Visible)
{
// Show the substituteForm
substitutionForm.Show();
ReplaceForm neueSubstitutionForm = new ReplaceForm();
}
else if (substitutionForm.Visible)
{
// Hide the substituteForm
substitutionForm.Hide();
}
if (ReplaceForm.canReplaceValue)
{
// Defines the target string to find out inside "contentRichTb", sets the replacing element and imports the text of "contentRichTb" into replacedTextCorpus
targetText = ReplaceForm.targetString;
string replaceTextElement = ReplaceForm.replacementString;
string replacedTextCorpus = contentRichTb.Text;
// If the contentRichTb contains the target string, then replace it accordingly and then updates the overall contentRichTb.Text to his updated content
if (contentRichTb.Text.Contains(targetText))
{
replacedTextCorpus = contentRichTb.Text.Replace(targetText, replaceTextElement);
contentRichTb.Text = replacedTextCorpus;
}
}
}
*/
private void appendToolStripButton_Click(object sender, EventArgs e)
{
// Give file location choice to the user
OpenFileDialog appendFileChoice = new OpenFileDialog();
string appendedFileText = "";
// Stocks the dialog choice and then the complete system path in the variable path
DialogResult choice = appendFileChoice.ShowDialog();
path = appendFileChoice.FileName;
// If the choice is affirmative (OK) and that the file contains more than zero characters, then it is saved
if (choice == DialogResult.OK && appendFileChoice.FileName.Length > 0)
{
// Opening the selected file and reads it to the very end
StreamReader softStreamRead = new StreamReader(appendFileChoice.FileName);
// Puts the text content of appendFileChoice into appendedFileText thanks to the softStreamRead
appendedFileText = softStreamRead.ReadToEnd();
// Appends the appendedFileText into contentRichTb
contentRichTb.Text += appendedFileText;
// Closing the reader to optimize computer resources and avoid some vulnerabilities
softStreamRead.Close();
}
}
/*
// AWFUL CODE THAT DOESN'T DO ITS INTENDED PURPOSE WELL ENOUGH YET SO I DISABLED IT IN ITS ENTIRETY
private void aboutToolStripButton_Click(object sender, EventArgs e)
{
// Counting the number of clicks over this very button is gotta be useful later on
aboutClickCounter += 1;
// Mauvaise position
AboutForm introForm = new AboutForm();
introForm.Show();
// When there is any other number of instances but one of the AboutForm, then do nothing
/*
if (AboutForm.numInstances < 1 || AboutForm.numInstances > 1)
{
// === When there is any other number of instance of the AboutForm than 1, then do nothing ===
}
*/
// When there 1, then either show or hide the introForm instance
/*
else if (AboutForm.numInstances == 1)
{
// If aboutCountClicks passes the partity check, which is at every even number, the form hides itself until the next click
if (parityCheck(aboutClickCounter)) { introForm.Hide(); }
// If aboutCountClicks fails the parity check, which is at every odd number, the form shows until the next click
else if (!parityCheck(aboutClickCounter)) { introForm.Show(); } // DESIGN ERROR occuring here it seems
}
*/
}
// PARITY-CHECKING CUSTOM METHOD
/*
private bool parityCheck(int evalNum)
{
float parityEval = evalNum % 2;
if(parityEval == 0)
{
return true;
}
else
{
return false;
}
}
*/
}