diff --git a/Crypto Notepad/App.config b/Crypto Notepad/App.config index 4467dfb..66a8712 100644 --- a/Crypto Notepad/App.config +++ b/Crypto Notepad/App.config @@ -165,6 +165,9 @@ True + + False + diff --git a/Crypto Notepad/Program.cs b/Crypto Notepad/Program.cs index d819b1f..76829dd 100644 --- a/Crypto Notepad/Program.cs +++ b/Crypto Notepad/Program.cs @@ -1,19 +1,59 @@ -using System; +using Crypto_Notepad.Properties; +using System; +using System.Diagnostics; +using System.Runtime.InteropServices; +using System.Threading; using System.Windows.Forms; namespace Crypto_Notepad { static class Program { + [DllImport("user32.dll")] + [return: MarshalAs(UnmanagedType.Bool)] + static extern bool SetForegroundWindow(IntPtr hWnd); /// /// The main entry point for the application. /// [STAThread] static void Main() { - Application.EnableVisualStyles(); - Application.SetCompatibleTextRenderingDefault(false); - Application.Run(new MainForm()); + Settings settings = Settings.Default; + using (Mutex mutex = new Mutex(true, PublicVar.appName, out bool createdNew)) + { + if (!settings.singleInstance) + { + createdNew = true; + } + if (createdNew) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + else + { + DialogResult dialogResult = MessageBox.Show(PublicVar.appName + " is already running.\nDo you still want to open a new copy of the app?", PublicVar.appName, MessageBoxButtons.YesNo, MessageBoxIcon.Warning); + if (dialogResult == DialogResult.Yes) + { + Application.EnableVisualStyles(); + Application.SetCompatibleTextRenderingDefault(false); + Application.Run(new MainForm()); + } + if (dialogResult == DialogResult.No) + { + Process current = Process.GetCurrentProcess(); + foreach (Process process in Process.GetProcessesByName(current.ProcessName)) + { + if (process.Id != current.Id) + { + SetForegroundWindow(process.MainWindowHandle); + break; + } + } + } + } + } } } diff --git a/Crypto Notepad/Properties/Settings.Designer.cs b/Crypto Notepad/Properties/Settings.Designer.cs index 823b7a8..83b2928 100644 --- a/Crypto Notepad/Properties/Settings.Designer.cs +++ b/Crypto Notepad/Properties/Settings.Designer.cs @@ -12,7 +12,7 @@ namespace Crypto_Notepad.Properties { [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] - [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.1.0.0")] + [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "16.3.0.0")] internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); @@ -686,5 +686,18 @@ public bool toolbarCloseButton { this["toolbarCloseButton"] = value; } } + + [global::System.Configuration.UserScopedSettingAttribute()] + [global::System.Configuration.SettingsProviderAttribute(typeof(PortableSettingsProvider))] + [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] + [global::System.Configuration.DefaultSettingValueAttribute("False")] + public bool singleInstance { + get { + return ((bool)(this["singleInstance"])); + } + set { + this["singleInstance"] = value; + } + } } } diff --git a/Crypto Notepad/Properties/Settings.settings b/Crypto Notepad/Properties/Settings.settings index 09396bd..39441be 100644 --- a/Crypto Notepad/Properties/Settings.settings +++ b/Crypto Notepad/Properties/Settings.settings @@ -155,5 +155,8 @@ True + + False + \ No newline at end of file diff --git a/Crypto Notepad/SettingsForm.Designer.cs b/Crypto Notepad/SettingsForm.Designer.cs index 302f33a..cf343bd 100644 --- a/Crypto Notepad/SettingsForm.Designer.cs +++ b/Crypto Notepad/SettingsForm.Designer.cs @@ -101,21 +101,22 @@ private void InitializeComponent() this.statusPanelFontColorLabel = new System.Windows.Forms.Label(); this.statusPanelBackColorLabel = new System.Windows.Forms.Label(); this.toolbarTabPage = new System.Windows.Forms.TabPage(); + this.toolbarCloseButtonCheckBox = new System.Windows.Forms.CheckBox(); this.toolbarOldIconsCheckBox = new System.Windows.Forms.CheckBox(); this.toolbarBorderCheckBox = new System.Windows.Forms.CheckBox(); this.toolbarBackColor = new System.Windows.Forms.Panel(); this.toolbarBackColorLabel = new System.Windows.Forms.Label(); this.toolbarVisibleCheckBox = new System.Windows.Forms.CheckBox(); this.searchPanelTabPage = new System.Windows.Forms.TabPage(); + this.searchBorderComboBox = new System.Windows.Forms.ComboBox(); + this.searchBorderLabel = new System.Windows.Forms.Label(); this.searchFontColor = new System.Windows.Forms.Panel(); this.searchBackColor = new System.Windows.Forms.Panel(); this.searchFontColorLabel = new System.Windows.Forms.Label(); this.searchBackColorLabel = new System.Windows.Forms.Label(); this.settingsNavigation = new System.Windows.Forms.ListBox(); this.fontDialog = new System.Windows.Forms.FontDialog(); - this.searchBorderLabel = new System.Windows.Forms.Label(); - this.searchBorderComboBox = new System.Windows.Forms.ComboBox(); - this.toolbarCloseButtonCheckBox = new System.Windows.Forms.CheckBox(); + this.singleInstanceCheckBox = new System.Windows.Forms.CheckBox(); this.settingsTabControl.SuspendLayout(); this.editorTabPage.SuspendLayout(); this.applicationTabPage.SuspendLayout(); @@ -322,6 +323,7 @@ private void InitializeComponent() // this.applicationTabPage.BackColor = System.Drawing.SystemColors.Window; this.applicationTabPage.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle; + this.applicationTabPage.Controls.Add(this.singleInstanceCheckBox); this.applicationTabPage.Controls.Add(this.closeToTrayCheckBox); this.applicationTabPage.Controls.Add(this.minimizeToTrayCheckBox); this.applicationTabPage.Controls.Add(this.mainMenuCheckBox); @@ -989,6 +991,17 @@ private void InitializeComponent() this.toolbarTabPage.TabIndex = 6; this.toolbarTabPage.Text = "tb"; // + // toolbarCloseButtonCheckBox + // + this.toolbarCloseButtonCheckBox.AutoSize = true; + this.toolbarCloseButtonCheckBox.Location = new System.Drawing.Point(9, 116); + this.toolbarCloseButtonCheckBox.Name = "toolbarCloseButtonCheckBox"; + this.toolbarCloseButtonCheckBox.Size = new System.Drawing.Size(94, 19); + this.toolbarCloseButtonCheckBox.TabIndex = 12; + this.toolbarCloseButtonCheckBox.Text = "Close button"; + this.toolbarCloseButtonCheckBox.UseVisualStyleBackColor = true; + this.toolbarCloseButtonCheckBox.Click += new System.EventHandler(this.ToolbarCloseButtonCheckBox_Click); + // // toolbarOldIconsCheckBox // this.toolbarOldIconsCheckBox.AutoSize = true; @@ -1059,6 +1072,28 @@ private void InitializeComponent() this.searchPanelTabPage.TabIndex = 7; this.searchPanelTabPage.Text = "srch"; // + // searchBorderComboBox + // + this.searchBorderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; + this.searchBorderComboBox.FormattingEnabled = true; + this.searchBorderComboBox.Items.AddRange(new object[] { + "None", + "Single"}); + this.searchBorderComboBox.Location = new System.Drawing.Point(132, 58); + this.searchBorderComboBox.Name = "searchBorderComboBox"; + this.searchBorderComboBox.Size = new System.Drawing.Size(100, 23); + this.searchBorderComboBox.TabIndex = 5; + this.searchBorderComboBox.DropDownClosed += new System.EventHandler(this.SearchBorderComboBox_DropDownClosed); + // + // searchBorderLabel + // + this.searchBorderLabel.AutoSize = true; + this.searchBorderLabel.Location = new System.Drawing.Point(6, 61); + this.searchBorderLabel.Name = "searchBorderLabel"; + this.searchBorderLabel.Size = new System.Drawing.Size(42, 15); + this.searchBorderLabel.TabIndex = 4; + this.searchBorderLabel.Text = "Border"; + // // searchFontColor // this.searchFontColor.BackColor = System.Drawing.Color.Black; @@ -1134,38 +1169,16 @@ private void InitializeComponent() this.fontDialog.ShowEffects = false; this.fontDialog.Apply += new System.EventHandler(this.FontDialog_Apply); // - // searchBorderLabel + // singleInstanceCheckBox // - this.searchBorderLabel.AutoSize = true; - this.searchBorderLabel.Location = new System.Drawing.Point(6, 61); - this.searchBorderLabel.Name = "searchBorderLabel"; - this.searchBorderLabel.Size = new System.Drawing.Size(42, 15); - this.searchBorderLabel.TabIndex = 4; - this.searchBorderLabel.Text = "Border"; - // - // searchBorderComboBox - // - this.searchBorderComboBox.DropDownStyle = System.Windows.Forms.ComboBoxStyle.DropDownList; - this.searchBorderComboBox.FormattingEnabled = true; - this.searchBorderComboBox.Items.AddRange(new object[] { - "None", - "Single"}); - this.searchBorderComboBox.Location = new System.Drawing.Point(132, 58); - this.searchBorderComboBox.Name = "searchBorderComboBox"; - this.searchBorderComboBox.Size = new System.Drawing.Size(100, 23); - this.searchBorderComboBox.TabIndex = 5; - this.searchBorderComboBox.DropDownClosed += new System.EventHandler(this.SearchBorderComboBox_DropDownClosed); - // - // toolbarCloseButtonCheckBox - // - this.toolbarCloseButtonCheckBox.AutoSize = true; - this.toolbarCloseButtonCheckBox.Location = new System.Drawing.Point(9, 116); - this.toolbarCloseButtonCheckBox.Name = "toolbarCloseButtonCheckBox"; - this.toolbarCloseButtonCheckBox.Size = new System.Drawing.Size(94, 19); - this.toolbarCloseButtonCheckBox.TabIndex = 12; - this.toolbarCloseButtonCheckBox.Text = "Close button"; - this.toolbarCloseButtonCheckBox.UseVisualStyleBackColor = true; - this.toolbarCloseButtonCheckBox.Click += new System.EventHandler(this.ToolbarCloseButtonCheckBox_Click); + this.singleInstanceCheckBox.AutoSize = true; + this.singleInstanceCheckBox.Location = new System.Drawing.Point(7, 155); + this.singleInstanceCheckBox.Name = "singleInstanceCheckBox"; + this.singleInstanceCheckBox.Size = new System.Drawing.Size(105, 19); + this.singleInstanceCheckBox.TabIndex = 6; + this.singleInstanceCheckBox.Text = "Single instance"; + this.singleInstanceCheckBox.UseVisualStyleBackColor = true; + this.singleInstanceCheckBox.Click += new System.EventHandler(this.SingleInstanceCheckBox_Click); // // SettingsForm // @@ -1301,5 +1314,6 @@ private void InitializeComponent() private System.Windows.Forms.ComboBox searchBorderComboBox; private System.Windows.Forms.Label searchBorderLabel; private System.Windows.Forms.CheckBox toolbarCloseButtonCheckBox; + private System.Windows.Forms.CheckBox singleInstanceCheckBox; } } \ No newline at end of file diff --git a/Crypto Notepad/SettingsForm.cs b/Crypto Notepad/SettingsForm.cs index b1cd488..ca82c55 100644 --- a/Crypto Notepad/SettingsForm.cs +++ b/Crypto Notepad/SettingsForm.cs @@ -36,6 +36,7 @@ private void LoadSettings() menuIconsCheckBox.Checked = settings.menuIcons; minimizeToTrayCheckBox.Checked = settings.minimizeToTray; closeToTrayCheckBox.Checked = settings.closeToTray; + singleInstanceCheckBox.Checked = settings.singleInstance; integrateCheckBox.Checked = settings.explorerIntegrate; associateCheckBox.Checked = settings.explorerAssociate; @@ -837,6 +838,11 @@ private void ToolbarCloseButtonCheckBox_Click(object sender, EventArgs e) main.closeToolbarButton.Visible = toolbarCloseButtonCheckBox.Checked; settings.toolbarCloseButton = toolbarCloseButtonCheckBox.Checked; } + + private void SingleInstanceCheckBox_Click(object sender, EventArgs e) + { + settings.singleInstance = singleInstanceCheckBox.Checked; + } /*Settings Section*/