Crypto-Notepad/Crypto Notepad/MainForm.cs

1569 lines
55 KiB
C#
Raw Normal View History

2019-08-21 20:45:15 +00:00
using IWshRuntimeLibrary;
2018-12-17 11:16:17 +00:00
using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Drawing;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Net;
using System.Reflection;
using System.Security.Cryptography;
using System.Threading;
using System.Windows.Forms;
using File = System.IO.File;
namespace Crypto_Notepad
{
public partial class MainForm : Form
{
Properties.Settings ps = Properties.Settings.Default;
string filePath = "";
string[] args = Environment.GetCommandLineArgs();
int caretPos = 0;
bool shiftPresed;
bool noExit = false;
string argsPath = "";
2019-08-22 17:05:18 +00:00
int findPos = 0;
2018-12-17 11:16:17 +00:00
public MainForm()
{
InitializeComponent();
RichTextBox.DragDrop += new DragEventHandler(RichTextBox_DragDrop);
RichTextBox.AllowDrop = true;
2018-12-17 11:16:17 +00:00
}
/*Functions*/
private void DecryptAES()
2018-12-17 11:16:17 +00:00
{
EnterKeyForm f2 = new EnterKeyForm();
f2.ShowDialog();
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
PublicVar.openFileName = Path.GetFileName(filePath);
2018-12-17 11:16:17 +00:00
return;
}
if (SearchPanel.Visible)
2018-12-17 11:16:17 +00:00
{
FindToolStripMenuItem_Click(this, new EventArgs());
2018-12-17 11:16:17 +00:00
}
try
{
string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
string de;
2019-01-04 11:16:40 +00:00
if (ps.TheSalt != null)
{
2019-08-21 11:15:16 +00:00
de = AES.Decrypt(opnfile, TypedPassword.Value, ps.TheSalt, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
}
else
{
2019-08-21 11:15:16 +00:00
de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
}
RichTextBox.Text = de;
Text = PublicVar.appName + " " + NameWithotPath;
2018-12-17 11:16:17 +00:00
filePath = OpenFile.FileName;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
2018-12-17 11:16:17 +00:00
PublicVar.openFileName = Path.GetFileName(OpenFile.FileName);
PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null;
}
catch (CryptographicException)
{
using (new CenterWinDialog(this))
{
TypedPassword.Value = null;
2019-01-07 10:08:47 +00:00
DialogResult dialogResult = MessageBox.Show("Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
2018-12-17 11:16:17 +00:00
if (dialogResult == DialogResult.Retry)
{
DecryptAES();
}
if (dialogResult == DialogResult.Cancel)
{
PublicVar.openFileName = Path.GetFileName(filePath);
2018-12-17 11:16:17 +00:00
return;
}
2018-12-17 11:16:17 +00:00
}
}
}
private void OpenAsotiations()
2018-12-17 11:16:17 +00:00
{
EnterKeyForm Form2 = new EnterKeyForm();
Form2.StartPosition = FormStartPosition.CenterScreen;
string fileExtension = Path.GetExtension(args[1]);
PublicVar.openFileName = Path.GetFileName(args[1]);
2018-12-17 11:16:17 +00:00
if (fileExtension == ".cnp")
{
try
{
string NameWithotPath = Path.GetFileName(args[1]);
string opnfile = File.ReadAllText(args[1]);
Form2.ShowDialog();
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
OpenFile.FileName = "";
return;
}
PublicVar.okPressed = false;
2018-12-19 22:56:59 +00:00
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = de;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
2018-12-17 11:16:17 +00:00
filePath = args[1];
string cc = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
2018-12-17 11:16:17 +00:00
PublicVar.encryptionKey.Set(TypedPassword.Value);
RichTextBox.Select(Convert.ToInt32(cc), 0);
2018-12-17 11:16:17 +00:00
TypedPassword.Value = null;
}
catch (CryptographicException)
{
TypedPassword.Value = null;
2019-01-07 10:08:47 +00:00
DialogResult dialogResult = MessageBox.Show("Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
2018-12-17 11:16:17 +00:00
if (dialogResult == DialogResult.Retry)
{
OpenAsotiations();
2018-12-17 11:16:17 +00:00
}
}
}
else
{
string opnfile = File.ReadAllText(args[1]);
string NameWithotPath = Path.GetFileName(args[1]);
RichTextBox.Text = opnfile;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
2018-12-17 11:16:17 +00:00
}
}
private void SendTo()
2018-12-17 11:16:17 +00:00
{
EnterKeyForm f2 = new EnterKeyForm();
f2.StartPosition = FormStartPosition.CenterScreen;
string fileExtension = Path.GetExtension(argsPath);
if (fileExtension == ".cnp")
{
try
{
string NameWithotPath = Path.GetFileName(argsPath);
string opnfile = File.ReadAllText(argsPath);
PublicVar.openFileName = Path.GetFileName(argsPath);
2018-12-17 11:16:17 +00:00
f2.ShowDialog();
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
OpenFile.FileName = "";
return;
}
PublicVar.okPressed = false;
2018-12-19 22:56:59 +00:00
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = de;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
2018-12-17 11:16:17 +00:00
filePath = argsPath;
string cc = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc), 0);
2018-12-17 11:16:17 +00:00
PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null;
}
catch (CryptographicException)
{
TypedPassword.Value = null;
2019-01-07 10:08:47 +00:00
DialogResult dialogResult = MessageBox.Show("Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
2018-12-17 11:16:17 +00:00
if (dialogResult == DialogResult.Retry)
{
SendTo();
2018-12-17 11:16:17 +00:00
}
}
}
else
{
string opnfile = File.ReadAllText(argsPath);
string NameWithotPath = Path.GetFileName(argsPath);
RichTextBox.Text = opnfile;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
2018-12-17 11:16:17 +00:00
}
}
private void SendToShortcut()
2018-12-17 11:16:17 +00:00
{
string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo";
2019-01-07 10:08:47 +00:00
string shortcutName = PublicVar.appName + ".lnk";
2018-12-17 11:16:17 +00:00
string shortcutLocation = Path.Combine(shortcutPath, shortcutName);
string targetFileLocation = Assembly.GetEntryAssembly().Location;
WshShell shell = new WshShell();
IWshShortcut shortcut = (IWshShortcut)shell.CreateShortcut(shortcutLocation);
2019-01-07 10:08:47 +00:00
shortcut.Description = PublicVar.appName;
2018-12-17 11:16:17 +00:00
shortcut.IconLocation = targetFileLocation;
shortcut.TargetPath = targetFileLocation;
shortcut.Arguments = "/s";
shortcut.Save();
2018-12-17 11:16:17 +00:00
}
private void ContextMenuEncryptReplace()
2018-12-17 11:16:17 +00:00
{
if (args[1].Contains(".cnp"))
{
2019-01-07 10:08:47 +00:00
MessageBox.Show("Looks like this file is already encrypted", PublicVar.appName, MessageBoxButtons.OK, MessageBoxIcon.Error);
2018-12-17 11:16:17 +00:00
return;
}
2019-01-07 10:08:47 +00:00
DialogResult res = MessageBox.Show("This action will delete the source file and replace it with encrypted version", PublicVar.appName, MessageBoxButtons.OKCancel, MessageBoxIcon.Question);
2018-12-17 11:16:17 +00:00
if (res == DialogResult.Cancel)
{
2018-12-17 13:03:08 +00:00
Environment.Exit(0);
2018-12-17 11:16:17 +00:00
}
if (!args[1].Contains(".cnp"))
{
string opnfile = File.ReadAllText(args[1]);
RichTextBox.Text = opnfile;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
PublicVar.openFileName = Path.GetFileName(args[1]);
2018-12-17 11:16:17 +00:00
string newFile = Path.GetDirectoryName(args[1]) + @"\" + Path.GetFileNameWithoutExtension(args[1]) + ".cnp";
EnterKeyForm f2 = new EnterKeyForm();
f2.ShowDialog();
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
Application.Exit();
}
PublicVar.okPressed = false;
File.Delete(args[1]);
string noenc = RichTextBox.Text;
2018-12-17 11:16:17 +00:00
string en;
en = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = en;
2018-12-17 11:16:17 +00:00
StreamWriter sw = new StreamWriter(newFile);
int i = RichTextBox.Lines.Count();
2018-12-17 11:16:17 +00:00
int j = 0;
i = i - 1;
while (j <= i)
{
sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
2018-12-17 11:16:17 +00:00
j = j + 1;
}
sw.Close();
PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null;
filePath = newFile;
PublicVar.openFileName = Path.GetFileName(newFile);
Text = PublicVar.appName + " " + PublicVar.openFileName;
RichTextBox.Text = noenc;
2018-12-17 11:16:17 +00:00
}
#region fix strange behavior with the cursor in RichTextBox
RichTextBox.DetectUrls = false;
RichTextBox.DetectUrls = true;
RichTextBox.Modified = false;
2018-12-17 11:16:17 +00:00
#endregion
if (PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
PublicVar.okPressed = false;
}
}
private void ContextMenuEncrypt()
2018-12-17 11:16:17 +00:00
{
if (!args[1].Contains(".cnp"))
{
string opnfile = File.ReadAllText(args[1]);
string NameWithotPath = Path.GetFileName(args[1]);
RichTextBox.Text = opnfile;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + NameWithotPath;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
PublicVar.openFileName = Path.GetFileName(args[1]);
2018-12-17 11:16:17 +00:00
filePath = OpenFile.FileName;
}
#region fix strange behavior with the cursor in RichTextBox
RichTextBox.DetectUrls = false;
RichTextBox.DetectUrls = true;
2018-12-17 11:16:17 +00:00
#endregion
RichTextBox.Modified = false;
if (PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
PublicVar.okPressed = false;
}
}
private void DeleteUpdateFiles()
2018-12-17 11:16:17 +00:00
{
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
string UpdaterExe = exePath + "Updater.exe";
string UpdateZip = exePath + "Crypto-Notepad-Update.zip";
string ZipDll = exePath + "Ionic.Zip.dll";
if (File.Exists(UpdaterExe))
{
File.Delete(UpdaterExe);
}
if (File.Exists(UpdateZip))
{
File.Delete(UpdateZip);
}
if (File.Exists(ZipDll))
{
File.Delete(ZipDll);
}
}
private void SaveConfirm(bool exit)
2018-12-17 11:16:17 +00:00
{
if (!RichTextBox.Modified)
2018-12-17 11:16:17 +00:00
{
if (exit)
2018-12-17 11:16:17 +00:00
{
Environment.Exit(0);
2018-12-17 11:16:17 +00:00
}
}
else
{
if (PublicVar.openFileName == null)
{
PublicVar.openFileName = "Unnamed.cnp";
}
2018-12-17 11:16:17 +00:00
2019-08-22 19:31:10 +00:00
if (PublicVar.openFileName == String.Empty)
{
PublicVar.openFileName = "Unnamed.cnp";
}
if (RichTextBox.Text != "")
{
string messageBoxText = "";
2018-12-17 11:16:17 +00:00
if (!PublicVar.keyChanged)
{
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " ? ";
}
else
{
messageBoxText = "Save file: " + "\"" + PublicVar.openFileName + "\"" + " with a new key? ";
}
2018-12-19 22:56:59 +00:00
using (new CenterWinDialog(this))
{
2019-01-07 10:08:47 +00:00
DialogResult res = MessageBox.Show(messageBoxText, PublicVar.appName, MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (res == DialogResult.Yes)
{
SaveToolStripMenuItem_Click(this, new EventArgs());
if (exit)
{
Environment.Exit(0);
}
}
2018-12-17 11:16:17 +00:00
if (res == DialogResult.No)
{
if (exit)
{
Environment.Exit(0);
}
}
2018-12-17 11:16:17 +00:00
if (res == DialogResult.Cancel)
{
noExit = true;
return;
}
}
}
2018-12-17 11:16:17 +00:00
}
}
private void CheckForUpdates(bool autoCheck)
2018-12-17 11:16:17 +00:00
{
try
2018-12-17 11:16:17 +00:00
{
WebClient client = new WebClient();
2019-01-02 19:10:41 +00:00
Stream stream = client.OpenRead("https://raw.githubusercontent.com/Crypto-Notepad/Crypto-Notepad/master/version.txt");
StreamReader reader = new StreamReader(stream);
string content = reader.ReadToEnd();
string version = Application.ProductVersion;
string exePath = Path.GetDirectoryName(Assembly.GetEntryAssembly().Location) + @"\";
int appVersion = Convert.ToInt32(version.Replace(".", "")), serverVersion = Convert.ToInt32(content.Replace(".", ""));
2018-12-17 11:16:17 +00:00
if (serverVersion > appVersion)
2018-12-17 11:16:17 +00:00
{
MainMenu.Invoke((Action)delegate
2018-12-17 11:16:17 +00:00
{
using (new CenterWinDialog(this))
{
DialogResult res = MessageBox.Show("New version is available. Install it now?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Information);
if (res == DialogResult.Yes)
{
File.WriteAllBytes(exePath + "Ionic.Zip.dll", Properties.Resources.Ionic_Zip);
File.WriteAllBytes(exePath + "Updater.exe", Properties.Resources.Updater);
var pr = new Process();
pr.StartInfo.FileName = exePath + "Updater.exe";
pr.StartInfo.Arguments = "/u";
pr.Start();
Application.Exit();
}
}
});
2018-12-17 11:16:17 +00:00
}
if (serverVersion <= appVersion && autoCheck)
{
MainMenu.Invoke((Action)delegate
{
using (new CenterWinDialog(this))
{
2019-01-07 10:08:47 +00:00
MessageBox.Show("Crypto Notepad is up to date.", PublicVar.appName, MessageBoxButtons.OK, MessageBoxIcon.Information);
}
});
}
2018-12-17 11:16:17 +00:00
}
catch
2018-12-17 11:16:17 +00:00
{
return;
2018-12-17 11:16:17 +00:00
}
}
private void AutoLock(bool minimize)
2018-12-17 11:16:17 +00:00
{
EnterKeyForm f2 = new EnterKeyForm();
PublicVar.encryptionKey.Set(null);
caretPos = RichTextBox.SelectionStart;
f2.MinimizeBox = true;
Hide();
2018-12-17 11:16:17 +00:00
if (minimize)
2018-12-17 11:16:17 +00:00
{
f2.WindowState = FormWindowState.Minimized;
2018-12-17 11:16:17 +00:00
}
f2.ShowDialog();
2018-12-17 11:16:17 +00:00
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
PublicVar.encryptionKey.Set(null);
RichTextBox.Clear();
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName;
PublicVar.openFileName = null;
filePath = "";
Show();
return;
2018-12-17 11:16:17 +00:00
}
PublicVar.okPressed = false;
try
2018-12-17 11:16:17 +00:00
{
RichTextBox.Clear();
string opnfile = File.ReadAllText(filePath);
string de = AES.Decrypt(opnfile, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = de;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + PublicVar.openFileName;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
RichTextBox.SelectionStart = caretPos;
PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null;
Show();
2018-12-17 11:16:17 +00:00
}
catch (Exception ex)
2018-12-17 11:16:17 +00:00
{
if (ex is CryptographicException)
{
TypedPassword.Value = null;
2019-01-07 10:08:47 +00:00
DialogResult dialogResult = MessageBox.Show("Invalid key!", PublicVar.appName, MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (dialogResult == DialogResult.Retry)
{
AutoLock(false);
}
if (dialogResult == DialogResult.Cancel)
{
PublicVar.encryptionKey.Set(null);
RichTextBox.Clear();
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName;
filePath = "";
PublicVar.openFileName = null;
Show();
return;
}
}
2018-12-17 11:16:17 +00:00
}
}
protected override void WndProc(ref Message m)
2018-12-17 11:16:17 +00:00
{
const int WM_SYSCOMMAND = 0x112;
2019-08-27 07:04:44 +00:00
const int SC_MINIMIZE = 0xF020;
if (m.Msg == WM_SYSCOMMAND && m.WParam.ToInt32() == SC_MINIMIZE && ps.AutoLock && PublicVar.encryptionKey.Get() != null)
2018-12-17 11:16:17 +00:00
{
if (ps.AutoSave)
{
SaveToolStripMenuItem_Click(this, new EventArgs());
}
else
2018-12-17 11:16:17 +00:00
{
SaveConfirm(false);
2018-12-17 11:16:17 +00:00
}
AutoLock(true);
return;
2018-12-17 11:16:17 +00:00
}
base.WndProc(ref m);
2018-12-17 11:16:17 +00:00
}
2018-12-29 16:26:51 +00:00
2019-08-27 07:04:44 +00:00
2018-12-29 16:26:51 +00:00
private void MenuIcons()
{
if (ps.MenuIcons)
{
NewToolStripMenuItem.Image = Properties.Resources.document_plus;
OpenToolStripMenuItem.Image = Properties.Resources.folder_open_document;
SaveToolStripMenuItem.Image = Properties.Resources.disk_return_black;
SaveAsToolStripMenuItem.Image = Properties.Resources.disks_black;
OpenFileLocationToolStripMenuItem.Image = Properties.Resources.folder_horizontal;
DeleteFileToolStripMenuItem.Image = Properties.Resources.document_minus;
ExitToolStripMenuItem.Image = Properties.Resources.cross_button;
UndoToolStripMenuItem.Image = Properties.Resources.arrow_left;
RedoToolStripMenuItem.Image = Properties.Resources.arrow_right;
CutToolStripMenuItem.Image = Properties.Resources.scissors;
CopyToolStripMenuItem.Image = Properties.Resources.document_copy;
PasteToolStripMenuItem.Image = Properties.Resources.clipboard;
DeleteToolStripMenuItem.Image = Properties.Resources.minus;
FindToolStripMenuItem.Image = Properties.Resources.magnifier;
SelectAllToolStripMenuItem.Image = Properties.Resources.selection_input;
WordWrapToolStripMenuItem.Image = Properties.Resources.wrap_option;
ClearToolStripMenuItem.Image = Properties.Resources.document;
ChangeKeyToolStripMenuItem.Image = Properties.Resources.key;
LockToolStripMenuItem.Image = Properties.Resources.lock_warning;
SettingsToolStripMenuItem.Image = Properties.Resources.gear;
DocumentationToolStripMenuItem.Image = Properties.Resources.document_text;
CheckForUpdatesToolStripMenuItem.Image = Properties.Resources.upload_cloud;
AboutToolStripMenuItem.Image = Properties.Resources.information;
}
else
{
foreach (ToolStripItem item in MainMenu.Items)
{
if (item is ToolStripDropDownItem)
foreach (ToolStripItem dropDownItem in ((ToolStripDropDownItem)item).DropDownItems)
{
dropDownItem.Image = null;
}
}
}
}
2019-08-27 07:04:44 +00:00
/*Functions*/
2018-12-17 11:16:17 +00:00
/*Form Events*/
private void MainWindow_Activated(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
2019-08-22 19:31:10 +00:00
RichTextBox.Focus();
if (PublicVar.settingsChanged)
2018-12-17 11:16:17 +00:00
{
PublicVar.settingsChanged = false;
RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
RichTextBox.ForeColor = ps.RichForeColor;
RichTextBox.BackColor = ps.RichBackColor;
BackColor = ps.RichBackColor;
2019-08-21 09:23:51 +00:00
LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible);
LineNumbers_For_RichTextBox.BackColor = ps.LNBackgroundColor;
LineNumbers_For_RichTextBox.ForeColor = ps.LNFontColorPanel;
LineNumbers_For_RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
LineNumbers_For_RichTextBox.Show_BorderLines = bool.Parse(ps.BLShow);
LineNumbers_For_RichTextBox.BorderLines_Color = ps.BLColor;
LineNumbers_For_RichTextBox.BorderLines_Style = ps.BLStyle;
LineNumbers_For_RichTextBox.Show_GridLines = bool.Parse(ps.GLShow);
LineNumbers_For_RichTextBox.GridLines_Color = ps.GLColor;
LineNumbers_For_RichTextBox.GridLines_Style = ps.GLStyle;
2019-08-21 09:09:05 +00:00
if (ps.InserKey == "Disable")
{
insertToolStripMenuItem.ShortcutKeys = Keys.Insert;
}
else
{
insertToolStripMenuItem.ShortcutKeys = Keys.None;
}
2019-08-21 09:23:51 +00:00
2018-12-17 11:16:17 +00:00
if (ps.SendTo)
{
SendToShortcut();
}
else
{
string shortcutPath = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData) + @"\Microsoft\Windows\SendTo\Crypto Notepad.lnk";
if (File.Exists(shortcutPath))
{
File.Delete(shortcutPath);
}
}
#region workaround, unhighlight URLs fix
RichTextBox.DetectUrls = false;
RichTextBox.DetectUrls = true;
2018-12-17 11:16:17 +00:00
#endregion
if (!ps.ShowToolbar && ToolbarPanel.Visible)
2018-12-17 11:16:17 +00:00
{
ToolbarPanel.Visible = false;
2018-12-17 11:16:17 +00:00
}
if (ps.ShowToolbar && !ToolbarPanel.Visible)
2018-12-17 11:16:17 +00:00
{
ToolbarPanel.Visible = true;
2019-08-23 20:46:11 +00:00
LineNumbers_For_RichTextBox.Height = 1;
2018-12-17 11:16:17 +00:00
}
2018-12-29 16:26:51 +00:00
MenuIcons();
if (ps.ColoredToolbar)
{
ToolbarPanel.BackColor = ps.RichBackColor;
ToolbarPanel.BorderStyle = BorderStyle.FixedSingle;
}
else
{
ToolbarPanel.BackColor = SystemColors.ButtonFace;
ToolbarPanel.BorderStyle = BorderStyle.None;
}
2018-12-17 11:16:17 +00:00
}
if (PublicVar.keyChanged)
2018-12-17 11:16:17 +00:00
{
RichTextBox.Modified = true;
2018-12-17 11:16:17 +00:00
}
if (PublicVar.encryptionKey.Get() == null)
{
FileLocationToolbarButton.Enabled = false;
DeleteFileToolbarButton.Enabled = false;
ChangeKeyToolbarButton.Enabled = false;
2019-01-04 12:14:12 +00:00
LockToolbarButton.Enabled = false;
2018-12-17 11:16:17 +00:00
}
else
2018-12-17 11:16:17 +00:00
{
FileLocationToolbarButton.Enabled = true;
DeleteFileToolbarButton.Enabled = true;
ChangeKeyToolbarButton.Enabled = true;
2019-01-04 12:14:12 +00:00
LockToolbarButton.Enabled = true;
2018-12-17 11:16:17 +00:00
}
}
private void MainWindow_FormClosing(object sender, FormClosingEventArgs e)
2018-12-17 11:16:17 +00:00
{
if (WindowState == FormWindowState.Normal)
{
ps.WindowSize = Size;
ps.WindowLocation = Location;
ps.WindowState = WindowState;
}
2018-12-17 11:16:17 +00:00
if (WindowState == FormWindowState.Maximized)
{
ps.WindowState = WindowState;
}
ps.Save();
SaveConfirm(true);
if (RichTextBox.Text == "")
2019-08-19 21:09:52 +00:00
{
noExit = false;
}
if (noExit)
{
e.Cancel = true;
}
2018-12-17 11:16:17 +00:00
}
2018-12-29 16:26:51 +00:00
private void MainWindow_Load(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
string pos = ps.WindowLocation.ToString();
RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
RichTextBox.ForeColor = ps.RichForeColor;
RichTextBox.BackColor = ps.RichBackColor;
BackColor = ps.RichBackColor;
WordWrapToolStripMenuItem.Checked = ps.MenuWrap;
RichTextBox.WordWrap = ps.RichWrap;
ToolbarPanel.Visible = ps.ShowToolbar;
2019-08-21 09:23:51 +00:00
LineNumbers_For_RichTextBox.Visible = bool.Parse(ps.LNVisible);
LineNumbers_For_RichTextBox.ForeColor = ps.LNFontColorPanel;
LineNumbers_For_RichTextBox.BackColor = ps.LNBackgroundColor;
LineNumbers_For_RichTextBox.Show_BorderLines = bool.Parse(ps.BLShow);
LineNumbers_For_RichTextBox.BorderLines_Color = ps.BLColor;
LineNumbers_For_RichTextBox.BorderLines_Style = ps.BLStyle;
LineNumbers_For_RichTextBox.Show_GridLines = bool.Parse(ps.GLShow);
LineNumbers_For_RichTextBox.GridLines_Color = ps.GLColor;
LineNumbers_For_RichTextBox.GridLines_Style = ps.GLStyle;
LineNumbers_For_RichTextBox.Font = new Font(ps.RichTextFont, ps.RichTextSize);
2019-08-21 09:09:05 +00:00
if (ps.InserKey == "Disable")
{
insertToolStripMenuItem.ShortcutKeys = Keys.Insert;
}
else
{
insertToolStripMenuItem.ShortcutKeys = Keys.None;
}
2019-08-22 19:31:10 +00:00
2018-12-29 16:26:51 +00:00
if (ps.ColoredToolbar)
{
ToolbarPanel.BackColor = ps.RichBackColor;
ToolbarPanel.BorderStyle = BorderStyle.FixedSingle;
}
if (!ps.ShowToolbar)
2018-12-17 11:16:17 +00:00
{
ToolbarPanel.Visible = false;
}
else
{
ToolbarPanel.Visible = true;
}
if (ps.AutoCheckUpdate)
{
Thread up = new Thread(() => CheckForUpdates(false));
up.Start();
2018-12-17 11:16:17 +00:00
}
2018-12-29 16:26:51 +00:00
MenuIcons();
DeleteUpdateFiles();
if (args.Length == 2) /*drag & drop to executable*/
2019-08-19 19:35:20 +00:00
{
OpenAsotiations();
}
if (args.Contains("/s")) /*send to*/
2018-12-17 11:16:17 +00:00
{
foreach (var arg in args)
{
argsPath = arg;
}
SendTo();
2018-12-17 11:16:17 +00:00
}
if (args.Contains("/o")) /*decrypt & open cnp*/
{
OpenAsotiations();
}
if (args.Contains("/e")) /*encrypt*/
{
ContextMenuEncrypt();
}
if (args.Contains("/er")) /*encrypt and replace*/
{
ContextMenuEncryptReplace();
}
if (pos != "{X=0,Y=0}")
{
Location = ps.WindowLocation;
}
Size = ps.WindowSize;
WindowState = ps.WindowState;
#if DEBUG
DebugToolStripMenuItem.Visible = true;
#endif
2018-12-17 11:16:17 +00:00
}
/*Form Events*/
2018-12-17 11:16:17 +00:00
/*RichTextBox Events*/
private void RichTextBox_SelectionChanged(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
if (RichTextBox.SelectionLength != 0)
2018-12-17 11:16:17 +00:00
{
CutToolbarButton.Enabled = true;
CopyToolbarButton.Enabled = true;
2018-12-17 11:16:17 +00:00
}
else
{
CutToolbarButton.Enabled = false;
CopyToolbarButton.Enabled = false;
2018-12-17 11:16:17 +00:00
}
}
private void RichTextBox_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
caretPos = RichTextBox.SelectionStart;
2018-12-17 11:16:17 +00:00
}
private void RichTextBox_KeyDown(object sender, KeyEventArgs e)
2018-12-17 11:16:17 +00:00
{
caretPos = RichTextBox.SelectionStart;
if (e.KeyCode == Keys.ShiftKey)
{
shiftPresed = true;
}
2019-08-22 17:05:18 +00:00
if (e.KeyCode == Keys.Escape)
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
RichTextBox.Focus();
RichTextBox.DeselectAll();
2019-08-22 17:05:18 +00:00
e.Handled = e.SuppressKeyPress = true;
findPos = 0;
}
2018-12-17 11:16:17 +00:00
}
private void RichTextBox_LinkClicked(object sender, LinkClickedEventArgs e)
2018-12-17 11:16:17 +00:00
{
if (shiftPresed)
{
shiftPresed = false;
Process.Start(e.LinkText);
}
2018-12-17 11:16:17 +00:00
}
private void RichTextBox_DragDrop(object sender, DragEventArgs e)
2018-12-17 11:16:17 +00:00
{
SaveConfirm(false);
string[] FileList = (string[])e.Data.GetData(DataFormats.FileDrop, false);
foreach (string file in FileList) OpenFile.FileName = file;
object fname = e.Data.GetData("FileDrop");
PublicVar.openFileName = Path.GetFileName(OpenFile.FileName);
if (fname != null)
{
var list = fname as string[];
if (list != null && !string.IsNullOrWhiteSpace(list[0]))
{
if (!OpenFile.FileName.Contains(".cnp"))
{
string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
RichTextBox.Text = opnfile;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
filePath = OpenFile.FileName;
return;
}
DecryptAES();
if (PublicVar.okPressed)
{
PublicVar.okPressed = false;
}
}
}
if (PublicVar.encryptionKey.Get() == null)
{
FileLocationToolbarButton.Enabled = false;
DeleteFileToolbarButton.Enabled = false;
ChangeKeyToolbarButton.Enabled = false;
LockToolbarButton.Enabled = false;
}
else
{
FileLocationToolbarButton.Enabled = true;
DeleteFileToolbarButton.Enabled = true;
ChangeKeyToolbarButton.Enabled = true;
LockToolbarButton.Enabled = true;
}
2018-12-17 11:16:17 +00:00
}
private void RichTextBox_KeyUp(object sender, KeyEventArgs e)
2018-12-17 11:16:17 +00:00
{
if (e.KeyCode == Keys.ShiftKey)
{
shiftPresed = false;
}
2018-12-17 11:16:17 +00:00
}
/*RichTextBox Events*/
2018-12-17 11:16:17 +00:00
/* Main Menu */
/*File*/
private void NewToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
SaveConfirm(false);
PublicVar.openFileName = "Unnamed.cnp";
EnterKeyForm f2 = new EnterKeyForm();
f2.ShowDialog();
2018-12-17 11:16:17 +00:00
if (!PublicVar.okPressed)
{
if (filePath != "")
{
PublicVar.openFileName = Path.GetFileName(filePath);
2019-08-21 11:15:16 +00:00
}
TypedPassword.Value = null;
return;
}
else
{
SaveFile.FileName = "Unnamed.cnp";
PublicVar.encryptionKey.Set(TypedPassword.Value);
PublicVar.okPressed = false;
if (SaveFile.ShowDialog() != DialogResult.OK)
{
TypedPassword.Value = null;
return;
}
2018-12-17 11:16:17 +00:00
RichTextBox.Clear();
StreamWriter sw = new StreamWriter(SaveFile.FileName);
string NameWithotPath = Path.GetFileName(SaveFile.FileName);
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
filePath = SaveFile.FileName;
PublicVar.openFileName = Path.GetFileName(SaveFile.FileName);
sw.Close();
}
TypedPassword.Value = null;
2018-12-17 11:16:17 +00:00
}
private void OpenToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
OpenFile.FileName = "";
SaveConfirm(false);
if (OpenFile.ShowDialog() != DialogResult.OK) return;
2018-12-17 11:16:17 +00:00
{
PublicVar.openFileName = Path.GetFileName(OpenFile.FileName);
if (!OpenFile.FileName.Contains(".cnp"))
{
string opnfile = File.ReadAllText(OpenFile.FileName);
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
RichTextBox.Text = opnfile;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + NameWithotPath;
string cc2 = RichTextBox.Text.Length.ToString(CultureInfo.InvariantCulture);
RichTextBox.Select(Convert.ToInt32(cc2), 0);
return;
}
DecryptAES();
#region fix strange behavior with the cursor in RichTextBox
RichTextBox.DetectUrls = false;
RichTextBox.DetectUrls = true;
#endregion
RichTextBox.Modified = false;
if (PublicVar.okPressed)
{
PublicVar.okPressed = false;
}
2018-12-29 16:26:51 +00:00
if (PublicVar.encryptionKey.Get() == null)
{
FileLocationToolbarButton.Enabled = false;
DeleteFileToolbarButton.Enabled = false;
ChangeKeyToolbarButton.Enabled = false;
2019-01-04 12:14:12 +00:00
LockToolbarButton.Enabled = false;
2018-12-29 16:26:51 +00:00
}
else
{
FileLocationToolbarButton.Enabled = true;
DeleteFileToolbarButton.Enabled = true;
ChangeKeyToolbarButton.Enabled = true;
2019-01-04 12:14:12 +00:00
LockToolbarButton.Enabled = true;
2018-12-29 16:26:51 +00:00
}
2018-12-17 11:16:17 +00:00
}
}
private void SaveToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
int saveCaret = RichTextBox.SelectionStart;
2018-12-17 11:16:17 +00:00
if (PublicVar.encryptionKey.Get() == null)
2018-12-17 11:16:17 +00:00
{
SaveAsToolStripMenuItem_Click(this, new EventArgs());
if (!PublicVar.okPressed)
2018-12-17 11:16:17 +00:00
{
return;
}
PublicVar.okPressed = false;
}
2018-12-17 11:16:17 +00:00
string noenc = RichTextBox.Text;
string en;
en = AES.Encrypt(RichTextBox.Text, PublicVar.encryptionKey.Get(), null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath);
int i = RichTextBox.Lines.Count();
int j = 0;
i = i - 1;
2018-12-17 11:16:17 +00:00
while (j <= i)
2018-12-17 11:16:17 +00:00
{
sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
j = j + 1;
2018-12-17 11:16:17 +00:00
}
sw.Close();
RichTextBox.Text = noenc;
RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.keyChanged = false;
2018-12-17 11:16:17 +00:00
}
private void SaveAsToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
int saveCaret = RichTextBox.SelectionStart;
string NameWithotPath = Path.GetFileName(OpenFile.FileName);
if (filePath != "")
{
PublicVar.openFileName = Path.GetFileName(filePath);
SaveFile.FileName = Path.GetFileName(filePath);
}
else
{
PublicVar.openFileName = "Unnamed.cnp";
SaveFile.FileName = "Unnamed.cnp";
}
2018-12-17 11:16:17 +00:00
EnterKeyForm f2 = new EnterKeyForm();
if (string.IsNullOrEmpty(PublicVar.encryptionKey.Get()))
2018-12-17 11:16:17 +00:00
{
f2.ShowDialog();
if (!PublicVar.okPressed)
{
return;
}
PublicVar.okPressed = false;
2018-12-17 11:16:17 +00:00
}
if (SaveFile.ShowDialog() != DialogResult.OK)
2018-12-17 11:16:17 +00:00
{
return;
}
if (TypedPassword.Value == null)
2018-12-17 11:16:17 +00:00
{
TypedPassword.Value = PublicVar.encryptionKey.Get();
2018-12-17 11:16:17 +00:00
}
filePath = SaveFile.FileName;
string noenc = RichTextBox.Text;
string en;
en = AES.Encrypt(RichTextBox.Text, TypedPassword.Value, null, ps.HashAlgorithm, ps.PasswordIterations, ps.KeySize);
RichTextBox.Text = en;
StreamWriter sw = new StreamWriter(filePath);
int i = RichTextBox.Lines.Count();
int j = 0;
i = i - 1;
while (j <= i)
2018-12-17 11:16:17 +00:00
{
sw.WriteLine(RichTextBox.Lines.GetValue(j).ToString());
j = j + 1;
}
sw.Close();
RichTextBox.Text = noenc;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName + " " + Path.GetFileName(filePath);
RichTextBox.Select(Convert.ToInt32(saveCaret), 0);
PublicVar.encryptionKey.Set(TypedPassword.Value);
TypedPassword.Value = null;
PublicVar.openFileName = Path.GetFileName(SaveFile.FileName);
}
private void OpenFileLocationToolStripMenuItem_Click(object sender, EventArgs e)
{
Process.Start("explorer.exe", @"/select, " + filePath);
}
private void DeleteFileToolStripMenuItem_Click(object sender, EventArgs e)
{
if (filePath != "")
{
using (new CenterWinDialog(this))
2018-12-17 11:16:17 +00:00
{
2019-01-07 10:08:47 +00:00
if (MessageBox.Show("Delete file: " + "\"" + filePath + "\"" + " ?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Question) == DialogResult.Yes)
2018-12-17 11:16:17 +00:00
{
File.Delete(filePath);
RichTextBox.Clear();
2018-12-17 11:16:17 +00:00
PublicVar.encryptionKey.Set(null);
FileLocationToolbarButton.Enabled = false;
DeleteFileToolbarButton.Enabled = false;
ChangeKeyToolbarButton.Enabled = false;
2019-01-04 12:14:12 +00:00
LockToolbarButton.Enabled = false;
2018-12-19 22:56:59 +00:00
filePath = "";
PublicVar.openFileName = null;
2019-01-07 10:08:47 +00:00
Text = PublicVar.appName;
2018-12-17 11:16:17 +00:00
return;
}
}
}
}
private void ExitToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
Application.Exit();
}
2018-12-17 11:16:17 +00:00
private void FileToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (filePath == "")
2018-12-17 11:16:17 +00:00
{
OpenFileLocationToolStripMenuItem.Enabled = false;
DeleteFileToolStripMenuItem.Enabled = false;
}
else
{
OpenFileLocationToolStripMenuItem.Enabled = true;
DeleteFileToolStripMenuItem.Enabled = true;
2018-12-17 11:16:17 +00:00
}
}
/*File*/
2018-12-17 11:16:17 +00:00
/*Edit*/
private void UndoToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
RichTextBox.Undo();
}
public void RedoToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox.Redo();
}
private void CutToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox.Cut();
}
private void CopyToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox.Copy();
}
private void PasteToolStripMenuItem_Click(object sender, EventArgs e)
{
if (RichTextBox.Focused)
{
RichTextBox.Paste(DataFormats.GetFormat(DataFormats.Text));
}
if (SearchTextBox.Focused)
{
SearchTextBox.Paste();
}
}
private void DeleteToolStripMenuItem_Click(object sender, EventArgs e)
{
RichTextBox.SelectedText = "";
}
private void FindToolStripMenuItem_Click(object sender, EventArgs e)
{
if (SearchPanel.Visible)
2018-12-17 11:16:17 +00:00
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
RichTextBox.Focus();
RichTextBox.DeselectAll();
2018-12-17 11:16:17 +00:00
}
else
{
SearchPanel.Visible = true;
SearchTextBox.Focus();
2018-12-17 11:16:17 +00:00
}
}
private void SelectAllToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
if (RichTextBox.Focused)
{
RichTextBox.SelectAll();
}
if (SearchTextBox.Focused)
{
SearchTextBox.SelectAll();
}
}
private void WordWrapToolStripMenuItem_Click(object sender, EventArgs e)
{
if (WordWrapToolStripMenuItem.Checked)
2018-12-17 11:16:17 +00:00
{
RichTextBox.WordWrap = true;
2018-12-17 11:16:17 +00:00
}
else
{
RichTextBox.WordWrap = false;
2018-12-17 11:16:17 +00:00
}
ps.MenuWrap = WordWrapToolStripMenuItem.Checked;
ps.RichWrap = RichTextBox.WordWrap;
ps.Save();
2018-12-17 11:16:17 +00:00
}
private void ClearToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
RichTextBox.Clear();
2018-12-17 11:16:17 +00:00
}
private void EditToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
if (RichTextBox.SelectionLength != 0)
2018-12-17 11:16:17 +00:00
{
CutToolStripMenuItem.Enabled = true;
CopyToolStripMenuItem.Enabled = true;
DeleteToolStripMenuItem.Enabled = true;
}
else
{
CutToolStripMenuItem.Enabled = false;
CopyToolStripMenuItem.Enabled = false;
DeleteToolStripMenuItem.Enabled = false;
2018-12-17 11:16:17 +00:00
}
}
/*Edit*/
2018-12-17 11:16:17 +00:00
/*Tools*/
private void ChangeKeyToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
ChangeKeyForm c = new ChangeKeyForm();
c.ShowDialog(this);
}
private void LockToolStripMenuItem_Click(object sender, EventArgs e)
{
if (ps.AutoSave)
2018-12-17 11:16:17 +00:00
{
SaveToolStripMenuItem_Click(this, new EventArgs());
}
else
{
SaveConfirm(false);
2018-12-17 11:16:17 +00:00
}
AutoLock(false);
2018-12-17 11:16:17 +00:00
}
private void SettingsToolStripMenuItem_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
SettingsForm sf = new SettingsForm();
sf.ShowDialog();
}
private void ToolsToolStripMenuItem_DropDownOpened(object sender, EventArgs e)
{
if (PublicVar.encryptionKey.Get() == null)
2018-12-17 11:16:17 +00:00
{
ChangeKeyToolStripMenuItem.Enabled = false;
LockToolStripMenuItem.Enabled = false;
}
else
{
ChangeKeyToolStripMenuItem.Enabled = true;
LockToolStripMenuItem.Enabled = true;
2018-12-17 11:16:17 +00:00
}
}
/*Tools*/
/*Help*/
private void DocumentationToolStripMenuItem_Click(object sender, EventArgs e)
{
2019-01-02 19:10:41 +00:00
Process.Start("https://github.com/Crypto-Notepad/Crypto-Notepad/wiki/Documentation");
}
private void CheckForUpdatesToolStripMenuItem_Click(object sender, EventArgs e)
{
Thread up = new Thread(() => CheckForUpdates(true));
up.Start();
}
private void AboutToolStripMenuItem_Click(object sender, EventArgs e)
{
AboutFrom a = new AboutFrom();
a.ShowDialog(this);
}
/*Help*/
/* Main Menu */
/* Editor Menu */
private void UndoEditorMenuStrip_Click(object sender, EventArgs e)
{
UndoToolStripMenuItem_Click(this, new EventArgs());
}
private void RedoEditorMenuStrip_Click(object sender, EventArgs e)
{
RedoToolStripMenuItem_Click(this, new EventArgs());
}
private void CutEditorMenuStrip_Click(object sender, EventArgs e)
{
CutToolStripMenuItem_Click(this, new EventArgs());
}
private void CopyEditorMenuStrip_Click(object sender, EventArgs e)
{
CopyToolStripMenuItem_Click(this, new EventArgs());
}
private void PasteEditorMenuStrip_Click(object sender, EventArgs e)
{
PasteToolStripMenuItem_Click(this, new EventArgs());
}
private void DeleteEditorMenuStrip_Click(object sender, EventArgs e)
{
DeleteToolStripMenuItem_Click(this, new EventArgs());
}
private void SelectAllEditorMenuStrip_Click(object sender, EventArgs e)
{
SelectAllToolStripMenuItem_Click(this, new EventArgs());
}
2018-12-17 11:16:17 +00:00
2018-12-25 15:22:59 +00:00
private void RightToLeftEditorMenuStrip_Click(object sender, EventArgs e)
{
if (RightToLeftEditorMenuStrip.Checked)
{
if (!WordWrapToolStripMenuItem.Checked)
2018-12-17 11:16:17 +00:00
{
string rtbTxt = RichTextBox.Text;
RichTextBox.Clear();
RichTextBox.RightToLeft = RightToLeft.Yes;
2018-12-25 15:22:59 +00:00
Application.DoEvents();
RichTextBox.Text = rtbTxt;
}
2018-12-25 15:22:59 +00:00
else
{
RichTextBox.RightToLeft = RightToLeft.Yes;
2018-12-17 11:16:17 +00:00
}
}
2018-12-25 15:22:59 +00:00
else
{
RichTextBox.RightToLeft = RightToLeft.No;
2018-12-25 15:22:59 +00:00
}
2018-12-17 11:16:17 +00:00
}
private void ClearEditorMenuStrip_Click(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
ClearToolStripMenuItem_Click(this, new EventArgs());
}
private void EditorMenuStrip_Opening(object sender, CancelEventArgs e)
{
if (RichTextBox.SelectionLength != 0)
2018-12-17 11:16:17 +00:00
{
CutEditorMenuStrip.Enabled = true;
CopyEditorMenuStrip.Enabled = true;
DeleteEditorMenuStrip.Enabled = true;
2018-12-17 11:16:17 +00:00
}
else
2018-12-17 11:16:17 +00:00
{
CutEditorMenuStrip.Enabled = false;
CopyEditorMenuStrip.Enabled = false;
DeleteEditorMenuStrip.Enabled = false;
}
}
/* Editor Menu */
2018-12-17 11:16:17 +00:00
/*Toolbar*/
private void NewToolbarButton_Click(object sender, EventArgs e)
{
NewToolStripMenuItem_Click(this, new EventArgs());
}
2018-12-17 11:16:17 +00:00
private void OpenToolbarButton_Click(object sender, EventArgs e)
{
OpenToolStripMenuItem_Click(this, new EventArgs());
}
private void SaveToolbarButton_Click(object sender, EventArgs e)
{
SaveToolStripMenuItem_Click(this, new EventArgs());
}
private void FileLocationToolbarButton_Click(object sender, EventArgs e)
{
OpenFileLocationToolStripMenuItem_Click(this, new EventArgs());
}
private void DeleteFileToolbarButton_Click(object sender, EventArgs e)
{
DeleteFileToolStripMenuItem_Click(this, new EventArgs());
}
2018-12-17 11:16:17 +00:00
private void CutToolbarButton_Click(object sender, EventArgs e)
{
CutToolStripMenuItem_Click(this, new EventArgs());
}
private void CopyToolbarButton_Click(object sender, EventArgs e)
{
CopyToolStripMenuItem_Click(this, new EventArgs());
}
private void PasteToolbarButton_Click(object sender, EventArgs e)
{
PasteToolStripMenuItem_Click(this, new EventArgs());
}
private void ChangeKeyToolbarButton_Click(object sender, EventArgs e)
{
ChangeKeyToolStripMenuItem_Click(this, new EventArgs());
}
private void SettingsToolbarButton_Click(object sender, EventArgs e)
{
SettingsToolStripMenuItem_Click(this, new EventArgs());
}
2019-01-04 12:14:12 +00:00
private void LockToolbarButton_Click(object sender, EventArgs e)
{
LockToolStripMenuItem_Click(this, new EventArgs());
}
private void CloseToolbar_Click(object sender, EventArgs e)
{
ToolbarPanel.Visible = false;
ps.ShowToolbar = false;
ps.Save();
}
2018-12-17 11:16:17 +00:00
private void CloseToolbar_MouseEnter(object sender, EventArgs e)
{
CloseToolbar.Image = Properties.Resources.close_b;
}
2018-12-17 11:16:17 +00:00
private void CloseToolbar_MouseLeave(object sender, EventArgs e)
{
CloseToolbar.Image = Properties.Resources.close_g;
2018-12-17 11:16:17 +00:00
}
/*Toolbar*/
/*Search Panel*/
private void SearchTextBox_TextChanged(object sender, EventArgs e)
2018-12-17 11:16:17 +00:00
{
2019-08-22 17:05:18 +00:00
findPos = 0;
}
private void SearchTextBox_KeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.Escape)
2018-12-17 11:16:17 +00:00
{
SearchTextBox.Text = "";
SearchPanel.Visible = false;
RichTextBox.Focus();
RichTextBox.DeselectAll();
e.Handled = e.SuppressKeyPress = true;
2019-08-22 17:05:18 +00:00
findPos = 0;
2018-12-17 11:16:17 +00:00
}
}
private void CloseSearchPanel_Click(object sender, EventArgs e)
{
FindToolStripMenuItem_Click(this, new EventArgs());
2019-08-21 11:15:16 +00:00
}
private void CloseSearchPanel_MouseHover(object sender, EventArgs e)
{
2019-08-27 07:04:44 +00:00
CloseSearchPanel.Image = Properties.Resources.close_b;
}
private void CloseSearchPanel_MouseLeave(object sender, EventArgs e)
{
2019-08-27 07:04:44 +00:00
CloseSearchPanel.Image = Properties.Resources.close_g;
}
2019-08-22 17:05:18 +00:00
private void MatchCaseCheckBox_CheckedChanged(object sender, EventArgs e)
{
2019-08-22 17:05:18 +00:00
findPos = 0;
RichTextBox.DeselectAll();
}
2019-08-22 17:05:18 +00:00
private void WholeWordCheckBox_CheckedChanged(object sender, EventArgs e)
{
2019-08-22 17:05:18 +00:00
findPos = 0;
RichTextBox.DeselectAll();
2019-08-22 17:05:18 +00:00
}
2019-08-27 07:04:44 +00:00
private void FindText(string text, RichTextBoxFinds findOptions)
2019-08-22 17:05:18 +00:00
{
if (text.Length > 0)
{
try
{
findPos = RichTextBox.Find(SearchTextBox.Text, findPos, findOptions);
2019-08-22 17:05:18 +00:00
if (findPos == -1)
{
findPos = 0;
return;
}
RichTextBox.Focus();
RichTextBox.Select(findPos, SearchTextBox.Text.Length);
2019-08-22 17:05:18 +00:00
findPos += SearchTextBox.Text.Length + 1;
}
catch
{
findPos = 0;
}
}
}
private void FindNextButton_Click(object sender, EventArgs e)
{
if ((!WholeWordCheckBox.Checked) & (!MatchCaseCheckBox.Checked))
{
2019-08-27 07:04:44 +00:00
FindText(SearchTextBox.Text, RichTextBoxFinds.None);
2019-08-22 17:05:18 +00:00
return;
}
if (WholeWordCheckBox.Checked & MatchCaseCheckBox.Checked)
{
2019-08-27 07:04:44 +00:00
FindText(SearchTextBox.Text, RichTextBoxFinds.MatchCase | RichTextBoxFinds.WholeWord);
2019-08-22 17:05:18 +00:00
return;
}
if (MatchCaseCheckBox.Checked)
{
2019-08-27 07:04:44 +00:00
FindText(SearchTextBox.Text, RichTextBoxFinds.MatchCase);
2019-08-22 17:05:18 +00:00
return;
}
if (WholeWordCheckBox.Checked)
{
2019-08-27 07:04:44 +00:00
FindText(SearchTextBox.Text, RichTextBoxFinds.WholeWord);
2019-08-22 17:05:18 +00:00
return;
}
}
/*Search Panel*/
/*Debug Menu*/
private void MainVariablesToolStripMenuItem_Click(object sender, EventArgs e)
{
#if DEBUG
string formattedTime = DateTime.Now.ToString("yyyy.MM.dd hh:mm:ss");
2019-01-07 10:09:14 +00:00
Debug.WriteLine("\nTime: " + formattedTime);
Debug.WriteLine("PublicVar.openFileName: " + PublicVar.openFileName);
Debug.WriteLine("filePath: " + filePath);
Debug.WriteLine("encryptionKey: " + PublicVar.encryptionKey.Get());
Debug.WriteLine("TypedPassword: " + TypedPassword.Value);
Debug.WriteLine("noExit: " + noExit);
Debug.WriteLine("keyChanged: " + PublicVar.keyChanged);
Debug.WriteLine("settingsChanged: " + PublicVar.settingsChanged);
Debug.WriteLine("okPressed: " + PublicVar.okPressed);
Debug.WriteLine("RichTextBox.Modified: " + RichTextBox.Modified);
Debug.WriteLine("EditorMenuStrip: " + EditorMenuStrip.Enabled);
2019-01-07 10:09:14 +00:00
#endif
2019-08-23 18:41:21 +00:00
}
/*Debug Menu*/
2018-12-17 11:16:17 +00:00
}
2019-08-21 11:15:16 +00:00
}