DisplayMagician/HeliosPlus/UIForms/MainForm.cs
Terry MacDonald dd85aeb0f1 Fixed notification icon menu
Also fixed console messages as well. The programme
is just about working properly! I'm going to start
creating branches now as it is nearly at ready for a
v1.0!
2020-11-04 18:47:41 +13:00

223 lines
7.7 KiB
C#

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HeliosPlus.GameLibraries;
using System.Threading;
using System.Reflection;
using HeliosPlus.Shared;
namespace HeliosPlus.UIForms
{
public partial class MainForm : Form
{
private bool allowVisible; // ContextMenu's Show command used
private bool allowClose; // ContextMenu's Exit command used
public MainForm()
{
InitializeComponent();
btn_setup_display_profiles.Parent = splitContainer1.Panel1;
btn_setup_game_shortcuts.Parent = splitContainer1.Panel2;
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);
notifyIcon.Visible = true;
RefreshNotifyIconMenus();
if (Program.AppProgramSettings.MinimiseOnStart)
{
// Make the form minimised on start
allowVisible = false;
// Hide the application to notification area when the form is closed
allowClose = false;
cb_minimise_notification_area.Checked = true;
}
else
{
// Make the form show to the user on startup
allowVisible = true;
// Really close the application when the form is closed
allowClose = true;
cb_minimise_notification_area.Checked = false;
}
}
protected override void SetVisibleCore(bool value)
{
if (!allowVisible)
{
value = false;
if (!this.IsHandleCreated) CreateHandle();
}
base.SetVisibleCore(value);
}
protected override void OnFormClosing(FormClosingEventArgs e)
{
if (!allowClose)
{
this.Hide();
e.Cancel = true;
}
base.OnFormClosing(e);
}
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void pb_display_profile_Click(object sender, EventArgs e)
{
var displayProfileForm = new DisplayProfileForm();
displayProfileForm.ShowDialog(this);
}
private void btn_setup_display_profiles_Click(object sender, EventArgs e)
{
var displayProfileForm = new DisplayProfileForm();
displayProfileForm.ShowDialog(this);
}
private void pb_game_shortcut_Click(object sender, EventArgs e)
{
var shortcutForm = new ShortcutForm();
shortcutForm.ShowDialog(this);
}
private void btn_setup_game_shortcuts_Click(object sender, EventArgs e)
{
var shortcutLibraryForm = new ShortcutLibraryForm();
shortcutLibraryForm.ShowDialog(this);
}
private void MainForm_Load(object sender, EventArgs e)
{
// Start loading the Steam Games just after the Main form opens
//SteamGame.GetAllInstalledGames();
}
private void RefreshNotifyIconMenus()
{
// Clear all the profiles
profileToolStripMenuItem.DropDownItems.Clear();
// Prepare the heading shortcuts
ToolStripMenuItem heading = new ToolStripMenuItem();
heading.Text = "Display Profiles";
Font headingFont = new Font(heading.Font, FontStyle.Italic);
heading.Font = headingFont;
heading.Enabled = false;
profileToolStripMenuItem.DropDownItems.Add(heading);
ToolStripSeparator separator = new ToolStripSeparator();
profileToolStripMenuItem.DropDownItems.Add(separator);
// Add the current slist of profiles into the NotifyIcon context menu
foreach (ProfileItem profile in ProfileRepository.AllProfiles)
{
profileToolStripMenuItem.DropDownItems.Add(profile.Name,profile.ProfileBitmap, runProfileToolStripMenuItem_Click);
}
// Clear all the shortcuts
shortcutToolStripMenuItem.DropDownItems.Clear();
// Prepare the heading shortcuts
heading = new ToolStripMenuItem();
heading.Text = "Game Shortcuts";
heading.Font = headingFont;
heading.Enabled = false;
shortcutToolStripMenuItem.DropDownItems.Add(heading);
separator = new ToolStripSeparator();
shortcutToolStripMenuItem.DropDownItems.Add(separator);
// Add the current list of profiles into the NotifyIcon context menu
foreach (ShortcutItem shortcut in ShortcutRepository.AllShortcuts)
{
shortcutToolStripMenuItem.DropDownItems.Add(shortcut.Name,shortcut.ShortcutBitmap, runShortcutToolStripMenuItem_Click);
}
}
private void runProfileToolStripMenuItem_Click(object sender, EventArgs e)
{
var menuItem = sender as ToolStripMenuItem;
ProfileItem profileToRun = null;
if (menuItem != null)
{
foreach (ProfileItem profile in ProfileRepository.AllProfiles)
{
if (profile.Name.Equals(menuItem.Text))
{
profileToRun = profile;
break;
}
}
// Run the shortcut if it's still there
if (profileToRun != null)
Program.ApplyProfile(profileToRun);
}
}
private void runShortcutToolStripMenuItem_Click(object sender, EventArgs e)
{
var menuItem = sender as ToolStripMenuItem;
ShortcutItem shortcutToRun = null;
if (menuItem != null)
{
foreach (ShortcutItem shortcut in ShortcutRepository.AllShortcuts)
{
if (shortcut.Name.Equals(menuItem.Text))
{
shortcutToRun = shortcut;
break;
}
}
// Run the shortcut if it's still there
if (shortcutToRun != null)
ShortcutRepository.RunShortcut(shortcutToRun);
}
}
private void openApplicationWindowToolStripMenuItem_Click(object sender, EventArgs e)
{
allowVisible = true;
Show();
BringToFront();
}
private void exitToolStripMenuItem_Click(object sender, EventArgs e)
{
allowClose = true;
Application.Exit();
}
private void cb_minimise_notification_area_CheckedChanged(object sender, EventArgs e)
{
if (cb_minimise_notification_area.Checked)
{
// Make the form minimised on start
allowVisible = false;
// Hide the application to notification area when the form is closed
allowClose = false;
// Enable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = true;
}
else
{
// Make the form show to the user on startup
allowVisible = true;
// Really close the application when the form is closed
allowClose = true;
// Disable the MinimiseOnStart setting
Program.AppProgramSettings.MinimiseOnStart = false;
}
}
}
}