This commit is contained in:
Alexander 2019-10-20 22:59:52 +03:00
parent 83e63fa8d4
commit 7907f3bd9c
6 changed files with 118 additions and 39 deletions

View file

@ -165,6 +165,9 @@
<setting name="toolbarCloseButton" serializeAs="String">
<value>True</value>
</setting>
<setting name="singleInstance" serializeAs="String">
<value>False</value>
</setting>
</Crypto_Notepad.Properties.Settings>
</userSettings>
</configuration>

View file

@ -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);
/// <summary>
/// The main entry point for the application.
/// </summary>
[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;
}
}
}
}
}
}
}

View file

@ -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;
}
}
}
}

View file

@ -155,5 +155,8 @@
<Setting Name="toolbarCloseButton" Provider="PortableSettingsProvider" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">True</Value>
</Setting>
<Setting Name="singleInstance" Provider="PortableSettingsProvider" Type="System.Boolean" Scope="User">
<Value Profile="(Default)">False</Value>
</Setting>
</Settings>
</SettingsFile>

View file

@ -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;
}
}

View file

@ -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*/