Created new Main Form to separate main tasks

It seemed to me that it would make more sense to
separate tht two main tasks completely and have them
independent from each other in the program. So I
created a new MainForm that opens up either a
'Setup Display Profiles' or 'Setup Game Shortcuts'
window depending on what the user clicks.
    The idea is that Display Profile setup only happens
when the app is first installed, and after that it's just
the game shortcut that gets updated.
    Also created a first attempt at a new HeliosPlus Icon.
This commit is contained in:
temacdonald 2020-05-03 20:39:35 +12:00
parent 205dcdf2c7
commit cc42c05bd7
23 changed files with 67665 additions and 911 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

View File

@ -44,7 +44,7 @@ namespace HeliosPlus.ShellExtension
Properties.Resources.Icon_x16,
(sender, args) =>
{
HeliosDisplayManagement.Open();
HeliosPlus.Open();
}));
explorerMenu.Items.Add(extensionMenu);
explorerMenu.Items.Add(new ToolStripSeparator());
@ -57,16 +57,16 @@ namespace HeliosPlus.ShellExtension
var profileMenu = new ToolStripMenuItem(profile.Name, new ProfileIcon(profile).ToBitmap(16, 16));
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run, null,
(sender, args) =>
HeliosDisplayManagement.Open(HeliosStartupAction.SwitchProfile, profile,
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
SelectedItemPaths.FirstOrDefault())));
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Run_as_administrator, Shield.SmallIcon,
(sender, args) =>
HeliosDisplayManagement.Open(HeliosStartupAction.SwitchProfile, profile,
HeliosPlus.Open(HeliosStartupAction.SwitchProfile, profile,
SelectedItemPaths.FirstOrDefault(), true)));
profileMenu.DropDownItems.Add(new ToolStripSeparator());
profileMenu.DropDownItems.Add(new ToolStripMenuItem(Language.Create_Shortcut, null,
(sender, args) =>
HeliosDisplayManagement.Open(HeliosStartupAction.CreateShortcut, profile,
HeliosPlus.Open(HeliosStartupAction.CreateShortcut, profile,
SelectedItemPaths.FirstOrDefault())));
return profileMenu;

View File

@ -61,6 +61,7 @@
<Reference Include="Microsoft.CSharp" />
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Data" />
<Reference Include="System.Drawing" />
<Reference Include="System.ServiceModel" />
<Reference Include="System.Windows.Forms" />
@ -74,6 +75,12 @@
<Compile Include="GameLibraries\SteamAppInfoParser\Package.cs" />
<Compile Include="GameLibraries\SteamAppInfoParser\PackageInfo.cs" />
<Compile Include="GameLibraries\SteamAppInfoParser\App.cs" />
<Compile Include="UIForms\MainForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UIForms\MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
</Compile>
<Compile Include="Validators.cs" />
<Compile Include="DisplayRepresentation.cs" />
<Compile Include="InterProcess\IPCClient.cs" />
@ -105,11 +112,11 @@
<Compile Include="UIForms\SplashForm.Designer.cs">
<DependentUpon>SplashForm.cs</DependentUpon>
</Compile>
<Compile Include="UIForms\MainForm.cs">
<Compile Include="UIForms\DisplayProfileForm.cs">
<SubType>Form</SubType>
</Compile>
<Compile Include="UIForms\MainForm.Designer.cs">
<DependentUpon>MainForm.cs</DependentUpon>
<Compile Include="UIForms\DisplayProfileForm.Designer.cs">
<DependentUpon>DisplayProfileForm.cs</DependentUpon>
</Compile>
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
@ -123,14 +130,18 @@
<LastGenOutput>Language.Designer.cs</LastGenOutput>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<SubType>Designer</SubType>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\ShortcutForm.resx">
<DependentUpon>ShortcutForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\EditForm.resx">
<DependentUpon>EditForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="UIForms\MainForm.resx">
<DependentUpon>MainForm.cs</DependentUpon>
<EmbeddedResource Include="UIForms\DisplayProfileForm.resx">
<DependentUpon>DisplayProfileForm.cs</DependentUpon>
</EmbeddedResource>
<EmbeddedResource Include="Properties\Resources.resx">
<Generator>ResXFileCodeGenerator</Generator>
@ -163,7 +174,6 @@
</ItemGroup>
<ItemGroup>
<None Include="Properties\DataSources\HeliosDisplayManagement.UIForms.ShortcutForm.datasource" />
<None Include="Resources\SteamIcon.png" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\HeliosDisplayManagement.Shared\HeliosPlus.Shared.csproj">

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.2 KiB

Binary file not shown.

View File

@ -461,7 +461,7 @@ namespace HeliosPlus {
IPCService.GetInstance().Status = InstanceStatus.User;
Application.Run(new MainForm());
Application.Run(new UIForms.MainForm());
}
catch (Exception e)

Binary file not shown.

After

Width:  |  Height:  |  Size: 108 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 115 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 8.8 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 491 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.2 MiB

View File

@ -0,0 +1,276 @@
using HeliosPlus.Resources;
using HeliosPlus.Shared.UserControls;
namespace HeliosPlus.UIForms
{
partial class DisplayProfileForm
{
/// <summary>
/// Required designer variable.
/// </summary>
private System.ComponentModel.IContainer components = null;
/// <summary>
/// Clean up any resources being used.
/// </summary>
/// <param name="disposing">true if managed resources should be disposed; otherwise, false.</param>
protected override void Dispose(bool disposing)
{
if (disposing && (components != null))
{
components.Dispose();
}
base.Dispose(disposing);
}
#region Windows Form Designer generated code
/// <summary>
/// Required method for Designer support - do not modify
/// the contents of this method with the code editor.
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DisplayProfileForm));
this.btn_copy = new System.Windows.Forms.Button();
this.btn_apply = new System.Windows.Forms.Button();
this.btn_edit = new System.Windows.Forms.Button();
this.btn_cancel = new System.Windows.Forms.Button();
this.lbl_profile = new System.Windows.Forms.Label();
this.btn_delete = new System.Windows.Forms.Button();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.menu_profiles = new System.Windows.Forms.ContextMenuStrip(this.components);
this.applyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.cloneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.createShortcutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.lv_profiles = new System.Windows.Forms.ListView();
this.il_profiles = new System.Windows.Forms.ImageList(this.components);
this.lbl_version = new System.Windows.Forms.Label();
this.menu_profiles.SuspendLayout();
this.SuspendLayout();
//
// btn_copy
//
this.btn_copy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_copy.Location = new System.Drawing.Point(368, 506);
this.btn_copy.Name = "btn_copy";
this.btn_copy.Size = new System.Drawing.Size(75, 23);
this.btn_copy.TabIndex = 6;
this.btn_copy.Text = "&Copy";
this.btn_copy.UseVisualStyleBackColor = true;
this.btn_copy.Click += new System.EventHandler(this.Copy_Click);
//
// btn_apply
//
this.btn_apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_apply.Location = new System.Drawing.Point(611, 506);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(75, 23);
this.btn_apply.TabIndex = 9;
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.Apply_Click);
//
// btn_edit
//
this.btn_edit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_edit.Location = new System.Drawing.Point(530, 506);
this.btn_edit.Name = "btn_edit";
this.btn_edit.Size = new System.Drawing.Size(75, 23);
this.btn_edit.TabIndex = 8;
this.btn_edit.UseVisualStyleBackColor = true;
this.btn_edit.Click += new System.EventHandler(this.Edit_Click);
//
// btn_cancel
//
this.btn_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btn_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_cancel.Location = new System.Drawing.Point(803, 506);
this.btn_cancel.Name = "btn_cancel";
this.btn_cancel.Size = new System.Drawing.Size(75, 23);
this.btn_cancel.TabIndex = 5;
this.btn_cancel.Text = "&Back";
this.btn_cancel.UseVisualStyleBackColor = true;
this.btn_cancel.Click += new System.EventHandler(this.Exit_Click);
//
// lbl_profile
//
this.lbl_profile.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.lbl_profile.Location = new System.Drawing.Point(262, 8);
this.lbl_profile.Name = "lbl_profile";
this.lbl_profile.Size = new System.Drawing.Size(382, 13);
this.lbl_profile.TabIndex = 3;
this.lbl_profile.Text = "[None]";
this.lbl_profile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// btn_delete
//
this.btn_delete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_delete.Location = new System.Drawing.Point(449, 506);
this.btn_delete.Name = "btn_delete";
this.btn_delete.Size = new System.Drawing.Size(75, 23);
this.btn_delete.TabIndex = 7;
this.btn_delete.UseVisualStyleBackColor = true;
this.btn_delete.Click += new System.EventHandler(this.Delete_Click);
//
// dv_profile
//
this.dv_profile.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dv_profile.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(174)))), ((int)(((byte)(184)))), ((int)(((byte)(196)))));
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(256, 18);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(634, 482);
this.dv_profile.TabIndex = 4;
//
// menu_profiles
//
this.menu_profiles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.applyToolStripMenuItem,
this.toolStripMenuItem2,
this.cloneToolStripMenuItem,
this.createShortcutToolStripMenuItem,
this.editToolStripMenuItem,
this.deleteToolStripMenuItem});
this.menu_profiles.Name = "menu_profiles";
this.menu_profiles.Size = new System.Drawing.Size(157, 120);
//
// applyToolStripMenuItem
//
this.applyToolStripMenuItem.Name = "applyToolStripMenuItem";
this.applyToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.applyToolStripMenuItem.Click += new System.EventHandler(this.Apply_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(153, 6);
//
// cloneToolStripMenuItem
//
this.cloneToolStripMenuItem.Name = "cloneToolStripMenuItem";
this.cloneToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.cloneToolStripMenuItem.Click += new System.EventHandler(this.Copy_Click);
//
// createShortcutToolStripMenuItem
//
this.createShortcutToolStripMenuItem.Name = "createShortcutToolStripMenuItem";
this.createShortcutToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.createShortcutToolStripMenuItem.Click += new System.EventHandler(this.CreateShortcut_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.editToolStripMenuItem.Click += new System.EventHandler(this.Edit_Click);
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.Delete_Click);
//
// lv_profiles
//
this.lv_profiles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lv_profiles.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(248)))));
this.lv_profiles.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lv_profiles.GridLines = true;
this.lv_profiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lv_profiles.HideSelection = false;
this.lv_profiles.LabelEdit = true;
this.lv_profiles.LargeImageList = this.il_profiles;
this.lv_profiles.Location = new System.Drawing.Point(-1, -1);
this.lv_profiles.MultiSelect = false;
this.lv_profiles.Name = "lv_profiles";
this.lv_profiles.Size = new System.Drawing.Size(254, 544);
this.lv_profiles.SmallImageList = this.il_profiles;
this.lv_profiles.TabIndex = 11;
this.lv_profiles.UseCompatibleStateImageBehavior = false;
this.lv_profiles.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lv_profiles_AfterLabelEdit);
this.lv_profiles.BeforeLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lv_profiles_BeforeLabelEdit);
this.lv_profiles.SelectedIndexChanged += new System.EventHandler(this.lv_profiles_SelectedIndexChanged);
this.lv_profiles.DoubleClick += new System.EventHandler(this.lv_profiles_DoubleClick);
this.lv_profiles.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lv_profiles_MouseUp);
//
// il_profiles
//
this.il_profiles.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.il_profiles.ImageSize = new System.Drawing.Size(48, 48);
this.il_profiles.TransparentColor = System.Drawing.Color.Transparent;
//
// lbl_version
//
this.lbl_version.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lbl_version.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.lbl_version.Location = new System.Drawing.Point(725, 8);
this.lbl_version.Name = "lbl_version";
this.lbl_version.Size = new System.Drawing.Size(157, 13);
this.lbl_version.TabIndex = 12;
this.lbl_version.Text = "v{0}";
this.lbl_version.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
//
// DisplayProfileForm
//
this.AcceptButton = this.btn_apply;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(174)))), ((int)(((byte)(184)))), ((int)(((byte)(196)))));
this.CancelButton = this.btn_cancel;
this.ClientSize = new System.Drawing.Size(893, 541);
this.ControlBox = false;
this.Controls.Add(this.lbl_version);
this.Controls.Add(this.lv_profiles);
this.Controls.Add(this.btn_delete);
this.Controls.Add(this.lbl_profile);
this.Controls.Add(this.btn_cancel);
this.Controls.Add(this.btn_edit);
this.Controls.Add(this.btn_apply);
this.Controls.Add(this.dv_profile);
this.Controls.Add(this.btn_copy);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(800, 400);
this.Name = "DisplayProfileForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "HeliosPlus - Setup Display Profiles";
this.Activated += new System.EventHandler(this.MainForm_Activated);
this.Load += new System.EventHandler(this.MainForm_Load);
this.menu_profiles.ResumeLayout(false);
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btn_copy;
private DisplayView dv_profile;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Button btn_edit;
private System.Windows.Forms.Button btn_cancel;
private System.Windows.Forms.Label lbl_profile;
private System.Windows.Forms.Button btn_delete;
private System.Windows.Forms.ContextMenuStrip menu_profiles;
private System.Windows.Forms.ToolStripMenuItem cloneToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem applyToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem createShortcutToolStripMenuItem;
private System.Windows.Forms.ListView lv_profiles;
private System.Windows.Forms.ImageList il_profiles;
private System.Windows.Forms.Label lbl_version;
}
}

View File

@ -0,0 +1,325 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.Linq;
using System.Reflection;
using System.Threading.Tasks;
using System.Windows.Forms;
using HeliosPlus.Resources;
using HeliosPlus.Shared;
namespace HeliosPlus.UIForms
{
internal partial class DisplayProfileForm : Form
{
private const string GroupActive = "active";
private const string GroupCurrent = "current";
private const string GroupSaved = "saved";
private Profile SelectedProfile;
public DisplayProfileForm()
{
InitializeComponent();
lv_profiles.Groups.Add(GroupCurrent, Language.Current);
lv_profiles.Groups.Add(GroupActive, Language.Active_Profiles);
lv_profiles.Groups.Add(GroupSaved, Language.Saved_Profiles);
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);
}
private ListViewItem AddProfile(Profile profile = null)
{
il_profiles.Images.Add(
new ProfileIcon(profile ?? Profile.GetCurrent()).ToBitmap(
il_profiles.ImageSize.Width,
il_profiles.ImageSize.Height));
return lv_profiles.Items.Add(new ListViewItem
{
Text = profile?.Name ?? Language.Current,
ImageIndex = il_profiles.Images.Count - 1,
Tag = profile,
Group =
lv_profiles.Groups[profile == null ? GroupCurrent : (profile.IsActive ? GroupActive : GroupSaved)]
});
}
private void Apply_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
if (!dv_profile.Profile.IsPossible)
{
MessageBox.Show(this, Language.This_profile_is_currently_impossible_to_apply,
Language.Apply_Profile,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Enabled = false;
Visible = false;
if (
new SplashForm(
() =>
{
Task.Factory.StartNew(() => dv_profile.Profile.Apply(), TaskCreationOptions.LongRunning);
}, 3, 30).ShowDialog(this) !=
DialogResult.Cancel)
{
ReloadProfiles();
}
Visible = true;
Enabled = true;
Activate();
}
}
private void Exit_Click(object sender, EventArgs e)
{
this.Close();
}
private void Copy_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null)
{
var clone = dv_profile.Profile.Clone();
var i = 0;
string name;
while (true)
{
i++;
name = $"{clone.Name} ({i})";
if (lv_profiles.Items.OfType<Profile>().Any(profile => profile.Name == name))
{
continue;
}
break;
}
clone.Name = name;
AddProfile(clone).Selected = true;
SaveProfiles();
btn_edit.PerformClick();
}
}
private void CreateShortcut_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var shortcutForm = new ShortcutForm(dv_profile.Profile);
shortcutForm.ShowDialog(this);
SaveProfiles();
}
}
private void Delete_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var selectedIndex = lv_profiles.SelectedIndices[0];
if (
MessageBox.Show(this, Language.Are_you_sure, Language.Deletion, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) ==
DialogResult.Yes)
{
il_profiles.Images.RemoveAt(lv_profiles.Items[selectedIndex].ImageIndex);
lv_profiles.Items.RemoveAt(selectedIndex);
SaveProfiles();
}
}
ReloadProfiles();
}
private void Edit_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var selectedIndex = lv_profiles.SelectedIndices[0];
var editForm = new EditForm(dv_profile.Profile);
if (editForm.ShowDialog(this) == DialogResult.OK)
{
lv_profiles.Items[selectedIndex].Tag = editForm.Profile;
SaveProfiles();
}
}
ReloadProfiles();
}
private void lv_profiles_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
var selectedProfile = (Profile) lv_profiles.Items[e.Item].Tag;
if (selectedProfile == null || e.Label == null || selectedProfile.Name == e.Label)
{
e.CancelEdit = true;
return;
}
if (string.IsNullOrWhiteSpace(e.Label) ||
lv_profiles.Items.Cast<ListViewItem>()
.Select(item => item.Tag as Profile)
.Where(profile => profile != null)
.Any(
profile =>
!profile.Equals(selectedProfile) &&
profile.Name.Equals(e.Label, StringComparison.InvariantCultureIgnoreCase)))
{
MessageBox.Show(this, Language.Invalid_or_duplicate_profile_name, Language.Validation,
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
e.CancelEdit = true;
return;
}
lv_profiles.Items[e.Item].Text = selectedProfile.Name = e.Label;
SaveProfiles();
}
private void lv_profiles_BeforeLabelEdit(object sender, LabelEditEventArgs e)
{
e.CancelEdit = !(lv_profiles.Items[e.Item].Tag is Profile);
}
private void lv_profiles_DoubleClick(object sender, EventArgs e)
{
btn_edit.PerformClick();
}
// Need to check why we did it this way rather than just using the
// list items themselves for clicking? That way we'd avoid selecting nothing...
private void lv_profiles_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && lv_profiles.SelectedItems.Count > 0)
{
var itemRect = lv_profiles.GetItemRect(lv_profiles.SelectedIndices[0]);
if (e.Location.X > itemRect.X &&
e.Location.X <= itemRect.Right &&
e.Location.Y > itemRect.Y &&
e.Location.Y <= itemRect.Bottom)
{
menu_profiles.Show(lv_profiles, e.Location);
}
}
}
private void lv_profiles_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_profiles.SelectedItems.Count > 0)
{
dv_profile.Profile = lv_profiles.SelectedItems[0].Tag as Profile ?? Profile.GetCurrent(Language.Current);
}
else
{
dv_profile.Profile = null;
}
// Set the Profile name
lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}";
// Turn on the buttons if the
if (dv_profile.Profile != null) {
if (lv_profiles.SelectedItems[0].Tag != null)
{
editToolStripMenuItem.Enabled = true;
btn_edit.Enabled = true;
deleteToolStripMenuItem.Enabled = true;
btn_delete.Enabled = true;
createShortcutToolStripMenuItem.Enabled = true;
if (!dv_profile.Profile.IsActive)
{
applyToolStripMenuItem.Enabled = true;
btn_apply.Enabled = true;
}
}
cloneToolStripMenuItem.Enabled = true;
btn_copy.Enabled = true;
}
// Refresh the profiles again in case anything changed
RefreshProfilesStatus();
}
private void MainForm_Activated(object sender, EventArgs e)
{
// Reload the profiles in case we swapped to another program to change it
ReloadProfiles();
// If nothing is selected then select the currently used profile
if (lv_profiles.SelectedItems.Count == 0)
{
lv_profiles.Items[0].Selected = true;
}
}
private void MainForm_Load(object sender, EventArgs e)
{
ReloadProfiles();
// Select the first item in the profiles list so pressing the buttons makes sense!
lv_profiles.Items[0].Selected = true;
lv_profiles.Items[0].Focused = true;
lv_profiles.Items[0].Checked = true;
}
private void RefreshProfilesStatus()
{
Profile.RefreshActiveStatus();
lv_profiles.Invalidate();
}
private void ReloadProfiles()
{
Profile.RefreshActiveStatus();
var profiles = Profile.GetAllProfiles().ToArray();
lv_profiles.Items.Clear();
il_profiles.Images.Clear();
if (!profiles.Any(profile => profile.IsActive))
{
AddProfile().Selected = true;
}
foreach (var profile in profiles)
{
AddProfile(profile);
}
lv_profiles.SelectedIndices.Clear();
lv_profiles.Invalidate();
}
private void SaveProfiles()
{
Profile.SetAllProfiles(
lv_profiles.Items.Cast<ListViewItem>()
.Select(item => item.Tag as Profile)
.Where(profile => profile != null));
ReloadProfiles();
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -1,7 +1,4 @@
using HeliosPlus.Resources;
using HeliosPlus.Shared.UserControls;
namespace HeliosPlus.UIForms
namespace HeliosPlus.UIForms
{
partial class MainForm
{
@ -31,267 +28,103 @@ namespace HeliosPlus.UIForms
/// </summary>
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(MainForm));
this.btn_copy = new System.Windows.Forms.Button();
this.btn_apply = new System.Windows.Forms.Button();
this.btn_edit = new System.Windows.Forms.Button();
this.btn_cancel = new System.Windows.Forms.Button();
this.lbl_profile = new System.Windows.Forms.Label();
this.btn_delete = new System.Windows.Forms.Button();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
this.btn_shortcut = new System.Windows.Forms.Button();
this.menu_profiles = new System.Windows.Forms.ContextMenuStrip(this.components);
this.applyToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.toolStripMenuItem2 = new System.Windows.Forms.ToolStripSeparator();
this.cloneToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.createShortcutToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
this.lv_profiles = new System.Windows.Forms.ListView();
this.il_profiles = new System.Windows.Forms.ImageList(this.components);
this.lbl_version = new System.Windows.Forms.Label();
this.menu_profiles.SuspendLayout();
this.splitContainer1 = new System.Windows.Forms.SplitContainer();
this.btn_setup_display_profiles = new System.Windows.Forms.Button();
this.pb_display_profile = new System.Windows.Forms.PictureBox();
this.btn_setup_game_shortcuts = new System.Windows.Forms.Button();
this.btn_exit = new System.Windows.Forms.Button();
this.pb_game_shortcut = new System.Windows.Forms.PictureBox();
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).BeginInit();
this.splitContainer1.Panel1.SuspendLayout();
this.splitContainer1.Panel2.SuspendLayout();
this.splitContainer1.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.pb_display_profile)).BeginInit();
((System.ComponentModel.ISupportInitialize)(this.pb_game_shortcut)).BeginInit();
this.SuspendLayout();
//
// btn_copy
// splitContainer1
//
this.btn_copy.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_copy.Location = new System.Drawing.Point(367, 506);
this.btn_copy.Name = "btn_copy";
this.btn_copy.Size = new System.Drawing.Size(75, 23);
this.btn_copy.TabIndex = 6;
this.btn_copy.Text = "&Copy";
this.btn_copy.UseVisualStyleBackColor = true;
this.btn_copy.Click += new System.EventHandler(this.Copy_Click);
this.splitContainer1.BackColor = System.Drawing.Color.Black;
resources.ApplyResources(this.splitContainer1, "splitContainer1");
this.splitContainer1.Name = "splitContainer1";
//
// btn_apply
// splitContainer1.Panel1
//
this.btn_apply.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_apply.Location = new System.Drawing.Point(610, 506);
this.btn_apply.Name = "btn_apply";
this.btn_apply.Size = new System.Drawing.Size(75, 23);
this.btn_apply.TabIndex = 9;
this.btn_apply.Text = global::HeliosPlus.Resources.Language.Apply;
this.btn_apply.UseVisualStyleBackColor = true;
this.btn_apply.Click += new System.EventHandler(this.Apply_Click);
this.splitContainer1.Panel1.Controls.Add(this.btn_setup_display_profiles);
this.splitContainer1.Panel1.Controls.Add(this.pb_display_profile);
//
// btn_edit
// splitContainer1.Panel2
//
this.btn_edit.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_edit.Location = new System.Drawing.Point(529, 506);
this.btn_edit.Name = "btn_edit";
this.btn_edit.Size = new System.Drawing.Size(75, 23);
this.btn_edit.TabIndex = 8;
this.btn_edit.Text = global::HeliosPlus.Resources.Language.Edit;
this.btn_edit.UseVisualStyleBackColor = true;
this.btn_edit.Click += new System.EventHandler(this.Edit_Click);
this.splitContainer1.Panel2.Controls.Add(this.btn_setup_game_shortcuts);
this.splitContainer1.Panel2.Controls.Add(this.btn_exit);
this.splitContainer1.Panel2.Controls.Add(this.pb_game_shortcut);
this.splitContainer1.TabStop = false;
//
// btn_cancel
// btn_setup_display_profiles
//
this.btn_cancel.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
this.btn_cancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
this.btn_cancel.Location = new System.Drawing.Point(803, 506);
this.btn_cancel.Name = "btn_cancel";
this.btn_cancel.Size = new System.Drawing.Size(75, 23);
this.btn_cancel.TabIndex = 5;
this.btn_cancel.Text = "E&xit";
this.btn_cancel.UseVisualStyleBackColor = true;
this.btn_cancel.Click += new System.EventHandler(this.Exit_Click);
resources.ApplyResources(this.btn_setup_display_profiles, "btn_setup_display_profiles");
this.btn_setup_display_profiles.ForeColor = System.Drawing.Color.White;
this.btn_setup_display_profiles.Name = "btn_setup_display_profiles";
this.btn_setup_display_profiles.UseVisualStyleBackColor = true;
this.btn_setup_display_profiles.Click += new System.EventHandler(this.btn_setup_display_profiles_Click);
//
// lbl_profile
// pb_display_profile
//
this.lbl_profile.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.lbl_profile.Location = new System.Drawing.Point(262, 8);
this.lbl_profile.Name = "lbl_profile";
this.lbl_profile.Size = new System.Drawing.Size(382, 13);
this.lbl_profile.TabIndex = 3;
this.lbl_profile.Text = "[None]";
this.lbl_profile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
resources.ApplyResources(this.pb_display_profile, "pb_display_profile");
this.pb_display_profile.Name = "pb_display_profile";
this.pb_display_profile.TabStop = false;
this.pb_display_profile.Click += new System.EventHandler(this.pb_display_profile_Click);
//
// btn_delete
// btn_setup_game_shortcuts
//
this.btn_delete.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_delete.Location = new System.Drawing.Point(448, 506);
this.btn_delete.Name = "btn_delete";
this.btn_delete.Size = new System.Drawing.Size(75, 23);
this.btn_delete.TabIndex = 7;
this.btn_delete.Text = global::HeliosPlus.Resources.Language.Delete;
this.btn_delete.UseVisualStyleBackColor = true;
this.btn_delete.Click += new System.EventHandler(this.Delete_Click);
resources.ApplyResources(this.btn_setup_game_shortcuts, "btn_setup_game_shortcuts");
this.btn_setup_game_shortcuts.ForeColor = System.Drawing.Color.Transparent;
this.btn_setup_game_shortcuts.Name = "btn_setup_game_shortcuts";
this.btn_setup_game_shortcuts.UseVisualStyleBackColor = true;
this.btn_setup_game_shortcuts.Click += new System.EventHandler(this.btn_setup_game_shortcuts_Click);
//
// dv_profile
// btn_exit
//
this.dv_profile.Anchor = ((System.Windows.Forms.AnchorStyles)((((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)
| System.Windows.Forms.AnchorStyles.Right)));
this.dv_profile.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(174)))), ((int)(((byte)(184)))), ((int)(((byte)(196)))));
this.dv_profile.Font = new System.Drawing.Font("Consolas", 50F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.dv_profile.ForeColor = System.Drawing.Color.MidnightBlue;
this.dv_profile.Location = new System.Drawing.Point(256, 18);
this.dv_profile.Margin = new System.Windows.Forms.Padding(18);
this.dv_profile.Name = "dv_profile";
this.dv_profile.PaddingX = 100;
this.dv_profile.PaddingY = 100;
this.dv_profile.Profile = null;
this.dv_profile.Size = new System.Drawing.Size(634, 482);
this.dv_profile.TabIndex = 4;
resources.ApplyResources(this.btn_exit, "btn_exit");
this.btn_exit.ForeColor = System.Drawing.Color.White;
this.btn_exit.Name = "btn_exit";
this.btn_exit.UseVisualStyleBackColor = true;
this.btn_exit.Click += new System.EventHandler(this.btn_exit_Click);
//
// btn_shortcut
// pb_game_shortcut
//
this.btn_shortcut.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
this.btn_shortcut.Location = new System.Drawing.Point(271, 506);
this.btn_shortcut.Name = "btn_shortcut";
this.btn_shortcut.Size = new System.Drawing.Size(90, 23);
this.btn_shortcut.TabIndex = 10;
this.btn_shortcut.Text = "Create &Shortcut";
this.btn_shortcut.UseVisualStyleBackColor = true;
this.btn_shortcut.Click += new System.EventHandler(this.CreateShortcut_Click);
//
// menu_profiles
//
this.menu_profiles.Items.AddRange(new System.Windows.Forms.ToolStripItem[] {
this.applyToolStripMenuItem,
this.toolStripMenuItem2,
this.cloneToolStripMenuItem,
this.createShortcutToolStripMenuItem,
this.editToolStripMenuItem,
this.deleteToolStripMenuItem});
this.menu_profiles.Name = "menu_profiles";
this.menu_profiles.Size = new System.Drawing.Size(157, 120);
//
// applyToolStripMenuItem
//
this.applyToolStripMenuItem.Name = "applyToolStripMenuItem";
this.applyToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.applyToolStripMenuItem.Text = global::HeliosPlus.Resources.Language.Apply;
this.applyToolStripMenuItem.Click += new System.EventHandler(this.Apply_Click);
//
// toolStripMenuItem2
//
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
this.toolStripMenuItem2.Size = new System.Drawing.Size(153, 6);
//
// cloneToolStripMenuItem
//
this.cloneToolStripMenuItem.Name = "cloneToolStripMenuItem";
this.cloneToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.cloneToolStripMenuItem.Text = global::HeliosPlus.Resources.Language.Clone;
this.cloneToolStripMenuItem.Click += new System.EventHandler(this.Copy_Click);
//
// createShortcutToolStripMenuItem
//
this.createShortcutToolStripMenuItem.Name = "createShortcutToolStripMenuItem";
this.createShortcutToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.createShortcutToolStripMenuItem.Text = global::HeliosPlus.Resources.Language.Create_Shortcut;
this.createShortcutToolStripMenuItem.Click += new System.EventHandler(this.CreateShortcut_Click);
//
// editToolStripMenuItem
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.editToolStripMenuItem.Text = global::HeliosPlus.Resources.Language.Edit;
this.editToolStripMenuItem.Click += new System.EventHandler(this.Edit_Click);
//
// deleteToolStripMenuItem
//
this.deleteToolStripMenuItem.Name = "deleteToolStripMenuItem";
this.deleteToolStripMenuItem.Size = new System.Drawing.Size(156, 22);
this.deleteToolStripMenuItem.Text = global::HeliosPlus.Resources.Language.Delete;
this.deleteToolStripMenuItem.Click += new System.EventHandler(this.Delete_Click);
//
// lv_profiles
//
this.lv_profiles.Anchor = ((System.Windows.Forms.AnchorStyles)(((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Bottom)
| System.Windows.Forms.AnchorStyles.Left)));
this.lv_profiles.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(248)))));
this.lv_profiles.BorderStyle = System.Windows.Forms.BorderStyle.FixedSingle;
this.lv_profiles.GridLines = true;
this.lv_profiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.Nonclickable;
this.lv_profiles.HideSelection = false;
this.lv_profiles.LabelEdit = true;
this.lv_profiles.LargeImageList = this.il_profiles;
this.lv_profiles.Location = new System.Drawing.Point(-1, -1);
this.lv_profiles.MultiSelect = false;
this.lv_profiles.Name = "lv_profiles";
this.lv_profiles.Size = new System.Drawing.Size(254, 544);
this.lv_profiles.SmallImageList = this.il_profiles;
this.lv_profiles.TabIndex = 11;
this.lv_profiles.UseCompatibleStateImageBehavior = false;
this.lv_profiles.AfterLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lv_profiles_AfterLabelEdit);
this.lv_profiles.BeforeLabelEdit += new System.Windows.Forms.LabelEditEventHandler(this.lv_profiles_BeforeLabelEdit);
this.lv_profiles.SelectedIndexChanged += new System.EventHandler(this.lv_profiles_SelectedIndexChanged);
this.lv_profiles.DoubleClick += new System.EventHandler(this.lv_profiles_DoubleClick);
this.lv_profiles.MouseUp += new System.Windows.Forms.MouseEventHandler(this.lv_profiles_MouseUp);
//
// il_profiles
//
this.il_profiles.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
this.il_profiles.ImageSize = new System.Drawing.Size(48, 48);
this.il_profiles.TransparentColor = System.Drawing.Color.Transparent;
//
// lbl_version
//
this.lbl_version.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Top | System.Windows.Forms.AnchorStyles.Right)));
this.lbl_version.Font = new System.Drawing.Font("Microsoft Sans Serif", 8.25F, System.Drawing.FontStyle.Bold, System.Drawing.GraphicsUnit.Point, ((byte)(178)));
this.lbl_version.Location = new System.Drawing.Point(724, 8);
this.lbl_version.Name = "lbl_version";
this.lbl_version.Size = new System.Drawing.Size(157, 13);
this.lbl_version.TabIndex = 12;
this.lbl_version.Text = "v{0}";
this.lbl_version.TextAlign = System.Drawing.ContentAlignment.MiddleRight;
resources.ApplyResources(this.pb_game_shortcut, "pb_game_shortcut");
this.pb_game_shortcut.Name = "pb_game_shortcut";
this.pb_game_shortcut.TabStop = false;
this.pb_game_shortcut.Click += new System.EventHandler(this.pb_game_shortcut_Click);
//
// MainForm
//
this.AcceptButton = this.btn_apply;
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F);
resources.ApplyResources(this, "$this");
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(174)))), ((int)(((byte)(184)))), ((int)(((byte)(196)))));
this.CancelButton = this.btn_cancel;
this.ClientSize = new System.Drawing.Size(893, 541);
this.Controls.Add(this.lbl_version);
this.Controls.Add(this.lv_profiles);
this.Controls.Add(this.btn_shortcut);
this.Controls.Add(this.btn_delete);
this.Controls.Add(this.lbl_profile);
this.Controls.Add(this.btn_cancel);
this.Controls.Add(this.btn_edit);
this.Controls.Add(this.btn_apply);
this.Controls.Add(this.dv_profile);
this.Controls.Add(this.btn_copy);
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
this.MaximizeBox = false;
this.MinimumSize = new System.Drawing.Size(800, 400);
this.ControlBox = false;
this.Controls.Add(this.splitContainer1);
this.Name = "MainForm";
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "HeliosPlus";
this.Activated += new System.EventHandler(this.MainForm_Activated);
this.SizeGripStyle = System.Windows.Forms.SizeGripStyle.Hide;
this.Load += new System.EventHandler(this.MainForm_Load);
this.menu_profiles.ResumeLayout(false);
this.splitContainer1.Panel1.ResumeLayout(false);
this.splitContainer1.Panel2.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.splitContainer1)).EndInit();
this.splitContainer1.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pb_display_profile)).EndInit();
((System.ComponentModel.ISupportInitialize)(this.pb_game_shortcut)).EndInit();
this.ResumeLayout(false);
}
#endregion
private System.Windows.Forms.Button btn_copy;
private DisplayView dv_profile;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Button btn_edit;
private System.Windows.Forms.Button btn_cancel;
private System.Windows.Forms.Label lbl_profile;
private System.Windows.Forms.Button btn_delete;
private System.Windows.Forms.Button btn_shortcut;
private System.Windows.Forms.ContextMenuStrip menu_profiles;
private System.Windows.Forms.ToolStripMenuItem cloneToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem deleteToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem editToolStripMenuItem;
private System.Windows.Forms.ToolStripMenuItem applyToolStripMenuItem;
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
private System.Windows.Forms.ToolStripMenuItem createShortcutToolStripMenuItem;
private System.Windows.Forms.ListView lv_profiles;
private System.Windows.Forms.ImageList il_profiles;
private System.Windows.Forms.Label lbl_version;
private System.Windows.Forms.SplitContainer splitContainer1;
private System.Windows.Forms.PictureBox pb_display_profile;
private System.Windows.Forms.PictureBox pb_game_shortcut;
private System.Windows.Forms.Button btn_exit;
private System.Windows.Forms.Button btn_setup_display_profiles;
private System.Windows.Forms.Button btn_setup_game_shortcuts;
}
}
}

View File

@ -1,326 +1,59 @@
using System;
using System.IO;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using HeliosPlus.Resources;
using HeliosPlus.Shared;
using HeliosPlus.GameLibraries;
using System.Threading;
namespace HeliosPlus.UIForms
{
internal partial class MainForm : Form
public partial class MainForm : Form
{
private const string GroupActive = "active";
private const string GroupCurrent = "current";
private const string GroupSaved = "saved";
private Profile SelectedProfile;
public MainForm()
{
InitializeComponent();
lv_profiles.Groups.Add(GroupCurrent, Language.Current);
lv_profiles.Groups.Add(GroupActive, Language.Active_Profiles);
lv_profiles.Groups.Add(GroupSaved, Language.Saved_Profiles);
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);
btn_setup_display_profiles.Parent = splitContainer1.Panel1;
btn_setup_game_shortcuts.Parent = splitContainer1.Panel2;
}
private ListViewItem AddProfile(Profile profile = null)
{
il_profiles.Images.Add(
new ProfileIcon(profile ?? Profile.GetCurrent()).ToBitmap(
il_profiles.ImageSize.Width,
il_profiles.ImageSize.Height));
return lv_profiles.Items.Add(new ListViewItem
{
Text = profile?.Name ?? Language.Current,
ImageIndex = il_profiles.Images.Count - 1,
Tag = profile,
Group =
lv_profiles.Groups[profile == null ? GroupCurrent : (profile.IsActive ? GroupActive : GroupSaved)]
});
}
private void Apply_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
if (!dv_profile.Profile.IsPossible)
{
MessageBox.Show(this, Language.This_profile_is_currently_impossible_to_apply,
Language.Apply_Profile,
MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
Enabled = false;
Visible = false;
if (
new SplashForm(
() =>
{
Task.Factory.StartNew(() => dv_profile.Profile.Apply(), TaskCreationOptions.LongRunning);
}, 3, 30).ShowDialog(this) !=
DialogResult.Cancel)
{
ReloadProfiles();
}
Visible = true;
Enabled = true;
Activate();
}
}
private void Exit_Click(object sender, EventArgs e)
private void btn_exit_Click(object sender, EventArgs e)
{
Application.Exit();
}
private void Copy_Click(object sender, EventArgs e)
private void pb_display_profile_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null)
{
var clone = dv_profile.Profile.Clone();
var i = 0;
string name;
while (true)
{
i++;
name = $"{clone.Name} ({i})";
if (lv_profiles.Items.OfType<Profile>().Any(profile => profile.Name == name))
{
continue;
}
break;
}
clone.Name = name;
AddProfile(clone).Selected = true;
SaveProfiles();
btn_edit.PerformClick();
}
var displayProfileForm = new DisplayProfileForm();
displayProfileForm.ShowDialog(this);
}
private void CreateShortcut_Click(object sender, EventArgs e)
private void btn_setup_display_profiles_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var shortcutForm = new ShortcutForm(dv_profile.Profile);
shortcutForm.ShowDialog(this);
SaveProfiles();
}
var displayProfileForm = new DisplayProfileForm();
displayProfileForm.ShowDialog(this);
}
private void Delete_Click(object sender, EventArgs e)
private void pb_game_shortcut_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var selectedIndex = lv_profiles.SelectedIndices[0];
if (
MessageBox.Show(this, Language.Are_you_sure, Language.Deletion, MessageBoxButtons.YesNo,
MessageBoxIcon.Warning) ==
DialogResult.Yes)
{
il_profiles.Images.RemoveAt(lv_profiles.Items[selectedIndex].ImageIndex);
lv_profiles.Items.RemoveAt(selectedIndex);
SaveProfiles();
}
}
ReloadProfiles();
var shortcutForm = new ShortcutForm();
shortcutForm.ShowDialog(this);
}
private void Edit_Click(object sender, EventArgs e)
private void btn_setup_game_shortcuts_Click(object sender, EventArgs e)
{
if (dv_profile.Profile != null &&
lv_profiles.SelectedIndices.Count > 0 &&
lv_profiles.SelectedItems[0].Tag != null)
{
var selectedIndex = lv_profiles.SelectedIndices[0];
var editForm = new EditForm(dv_profile.Profile);
if (editForm.ShowDialog(this) == DialogResult.OK)
{
lv_profiles.Items[selectedIndex].Tag = editForm.Profile;
SaveProfiles();
}
}
ReloadProfiles();
}
private void lv_profiles_AfterLabelEdit(object sender, LabelEditEventArgs e)
{
var selectedProfile = (Profile) lv_profiles.Items[e.Item].Tag;
if (selectedProfile == null || e.Label == null || selectedProfile.Name == e.Label)
{
e.CancelEdit = true;
return;
}
if (string.IsNullOrWhiteSpace(e.Label) ||
lv_profiles.Items.Cast<ListViewItem>()
.Select(item => item.Tag as Profile)
.Where(profile => profile != null)
.Any(
profile =>
!profile.Equals(selectedProfile) &&
profile.Name.Equals(e.Label, StringComparison.InvariantCultureIgnoreCase)))
{
MessageBox.Show(this, Language.Invalid_or_duplicate_profile_name, Language.Validation,
MessageBoxButtons.OK,
MessageBoxIcon.Warning);
e.CancelEdit = true;
return;
}
lv_profiles.Items[e.Item].Text = selectedProfile.Name = e.Label;
SaveProfiles();
}
private void lv_profiles_BeforeLabelEdit(object sender, LabelEditEventArgs e)
{
e.CancelEdit = !(lv_profiles.Items[e.Item].Tag is Profile);
}
private void lv_profiles_DoubleClick(object sender, EventArgs e)
{
btn_edit.PerformClick();
}
// Need to check why we did it this way rather than just using the
// list items themselves for clicking? That way we'd avoid selecting nothing...
private void lv_profiles_MouseUp(object sender, MouseEventArgs e)
{
if (e.Button == MouseButtons.Right && lv_profiles.SelectedItems.Count > 0)
{
var itemRect = lv_profiles.GetItemRect(lv_profiles.SelectedIndices[0]);
if (e.Location.X > itemRect.X &&
e.Location.X <= itemRect.Right &&
e.Location.Y > itemRect.Y &&
e.Location.Y <= itemRect.Bottom)
{
menu_profiles.Show(lv_profiles, e.Location);
}
}
}
private void lv_profiles_SelectedIndexChanged(object sender, EventArgs e)
{
if (lv_profiles.SelectedItems.Count > 0)
{
dv_profile.Profile = lv_profiles.SelectedItems[0].Tag as Profile ?? Profile.GetCurrent(Language.Current);
}
else
{
dv_profile.Profile = null;
}
// Set the Profile name
lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}";
// Turn on the buttons if the
if (dv_profile.Profile != null) {
if (lv_profiles.SelectedItems[0].Tag != null)
{
editToolStripMenuItem.Enabled = true;
btn_edit.Enabled = true;
deleteToolStripMenuItem.Enabled = true;
btn_delete.Enabled = true;
createShortcutToolStripMenuItem.Enabled = true;
btn_shortcut.Enabled = true;
if (!dv_profile.Profile.IsActive)
{
applyToolStripMenuItem.Enabled = true;
btn_apply.Enabled = true;
}
}
cloneToolStripMenuItem.Enabled = true;
btn_copy.Enabled = true;
}
// Refresh the profiles again in case anything changed
RefreshProfilesStatus();
}
private void MainForm_Activated(object sender, EventArgs e)
{
// Reload the profiles in case we swapped to another program to change it
ReloadProfiles();
// If nothing is selected then select the currently used profile
if (lv_profiles.SelectedItems.Count == 0)
{
lv_profiles.Items[0].Selected = true;
}
var shortcutForm = new ShortcutForm();
shortcutForm.ShowDialog(this);
}
private void MainForm_Load(object sender, EventArgs e)
{
ReloadProfiles();
// Select the first item in the profiles list so pressing the buttons makes sense!
lv_profiles.Items[0].Selected = true;
lv_profiles.Items[0].Focused = true;
lv_profiles.Items[0].Checked = true;
// Start loading the Steam Games just after the Main form opens
SteamGame.GetAllInstalledGames();
}
private void RefreshProfilesStatus()
{
Profile.RefreshActiveStatus();
lv_profiles.Invalidate();
}
private void ReloadProfiles()
{
Profile.RefreshActiveStatus();
var profiles = Profile.GetAllProfiles().ToArray();
lv_profiles.Items.Clear();
il_profiles.Images.Clear();
if (!profiles.Any(profile => profile.IsActive))
{
AddProfile().Selected = true;
}
foreach (var profile in profiles)
{
AddProfile(profile);
}
lv_profiles.SelectedIndices.Clear();
lv_profiles.Invalidate();
}
private void SaveProfiles()
{
Profile.SetAllProfiles(
lv_profiles.Items.Cast<ListViewItem>()
.Select(item => item.Tag as Profile)
.Where(profile => profile != null));
ReloadProfiles();
}
}
}
}

File diff suppressed because it is too large Load Diff

View File

@ -75,6 +75,7 @@ namespace HeliosPlus.UIForms
this.rb_switch_temp = new System.Windows.Forms.RadioButton();
this.openFileDialog1 = new System.Windows.Forms.OpenFileDialog();
this.lbl_profile = new System.Windows.Forms.Label();
this.cb_selected_profile = new System.Windows.Forms.ComboBox();
this.g_temporary.SuspendLayout();
this.p_game.SuspendLayout();
((System.ComponentModel.ISupportInitialize)(this.nud_timeout_game)).BeginInit();
@ -527,6 +528,15 @@ namespace HeliosPlus.UIForms
this.lbl_profile.Text = "[None]";
this.lbl_profile.TextAlign = System.Drawing.ContentAlignment.MiddleLeft;
//
// cb_selected_profile
//
this.cb_selected_profile.FormattingEnabled = true;
this.cb_selected_profile.Location = new System.Drawing.Point(168, 277);
this.cb_selected_profile.Name = "cb_selected_profile";
this.cb_selected_profile.Size = new System.Drawing.Size(203, 21);
this.cb_selected_profile.TabIndex = 11;
this.cb_selected_profile.SelectedIndexChanged += new System.EventHandler(this.cb_selected_profile_SelectedIndexChanged);
//
// ShortcutForm
//
this.AcceptButton = this.btn_save;
@ -535,6 +545,7 @@ namespace HeliosPlus.UIForms
this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(248)))), ((int)(((byte)(248)))), ((int)(((byte)(248)))));
this.CancelButton = this.btn_cancel;
this.ClientSize = new System.Drawing.Size(810, 890);
this.Controls.Add(this.cb_selected_profile);
this.Controls.Add(this.lbl_profile);
this.Controls.Add(this.rb_switch_temp);
this.Controls.Add(this.rb_switch_perm);
@ -549,7 +560,7 @@ namespace HeliosPlus.UIForms
this.Name = "ShortcutForm";
this.ShowIcon = false;
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterParent;
this.Text = "Create Shortcut";
this.Text = "HeliosPlus - Setup Game Shortcuts";
this.Load += new System.EventHandler(this.ShortcutForm_Load);
this.g_temporary.ResumeLayout(false);
this.g_temporary.PerformLayout();
@ -608,5 +619,6 @@ namespace HeliosPlus.UIForms
private System.Windows.Forms.ColumnHeader clm_name;
private System.Windows.Forms.TextBox txt_game_id;
private System.Windows.Forms.TextBox txt_game_launcher;
private System.Windows.Forms.ComboBox cb_selected_profile;
}
}

View File

@ -22,10 +22,38 @@ namespace HeliosPlus.UIForms
{
List<SteamGame> _allSteamGames;
private const string GroupActive = "active";
private const string GroupCurrent = "current";
private const string GroupSaved = "saved";
internal Profile[] _allProfiles;
/* private ListViewItem AddProfile(Profile profile = null)
{
il_profiles.Images.Add(
new ProfileIcon(profile ?? Profile.GetCurrent()).ToBitmap(
il_profiles.ImageSize.Width,
il_profiles.ImageSize.Height));
return lv_profiles.Items.Add(new ListViewItem
{
Text = profile?.Name ?? Language.Current,
ImageIndex = il_profiles.Images.Count - 1,
Tag = profile,
Group =
lv_profiles.Groups[profile == null ? GroupCurrent : (profile.IsActive ? GroupActive : GroupSaved)]
});
}*/
public ShortcutForm()
{
InitializeComponent();
/*lv_profiles.Groups.Add(GroupCurrent, Language.Current);
lv_profiles.Groups.Add(GroupActive, Language.Active_Profiles);
lv_profiles.Groups.Add(GroupSaved, Language.Saved_Profiles);
lbl_version.Text = string.Format(lbl_version.Text, Assembly.GetExecutingAssembly().GetName().Version);*/
}
public ShortcutForm(Profile profile) : this()
@ -61,6 +89,7 @@ namespace HeliosPlus.UIForms
// Check the profile is valid
// Create an array of display profiles we have
var profiles = Profile.GetAllProfiles().ToArray();
_allProfiles = profiles;
// Check if the user supplied a --profile option using the profiles' ID
var profileIndex = profiles.Length > 0 ? Array.FindIndex(profiles, p => p.Id.Equals(value.Id, StringComparison.InvariantCultureIgnoreCase)) : -1;
// If the profileID wasn't there, maybe they used the profile name?
@ -82,7 +111,6 @@ namespace HeliosPlus.UIForms
}
}
public string ExecutableNameAndPath
{
get => rb_switch_temp.Checked && rb_launcher.Checked ? txt_executable.Text : string.Empty;
@ -662,16 +690,6 @@ namespace HeliosPlus.UIForms
}
private void label1_Click(object sender, EventArgs e)
{
}
private void label7_Click(object sender, EventArgs e)
{
}
private void rb_standalone_CheckedChanged(object sender, EventArgs e)
{
if (rb_standalone.Checked)
@ -742,6 +760,14 @@ namespace HeliosPlus.UIForms
// Set the Profile name
lbl_profile.Text = $"Selected Profile: {dv_profile.Profile?.Name ?? Language.None}";
/*// Reload the profiles in case we swapped to another program to change it
ReloadProfiles();
// If nothing is selected then select the currently used profile
if (lv_profiles.SelectedItems.Count == 0)
{
lv_profiles.Items[0].Selected = true;
}
*/
// Start finding the games and loading the Games ListView
List<SteamGame> allSteamGames = SteamGame.GetAllInstalledGames();
_allSteamGames = allSteamGames;
@ -870,5 +896,44 @@ namespace HeliosPlus.UIForms
}
}
/*private void RefreshProfilesStatus()
{
Profile.RefreshActiveStatus();
lv_profiles.Invalidate();
}
private void ReloadProfiles()
{
Profile.RefreshActiveStatus();
var profiles = Profile.GetAllProfiles().ToArray();
lv_profiles.Items.Clear();
il_profiles.Images.Clear();
if (!profiles.Any(profile => profile.IsActive))
{
AddProfile().Selected = true;
}
foreach (var profile in profiles)
{
AddProfile(profile);
}
lv_profiles.SelectedIndices.Clear();
lv_profiles.Invalidate();
}
*/
private void cb_selected_profile_SelectedIndexChanged(object sender, EventArgs e)
{
foreach (Profile profile in _allProfiles)
{
if (SelectedProfile.Name == cb_selected_profile.SelectedItem.ToString())
{
SelectedProfile = profile;
}
}
}
}
}

BIN
Icon.afphoto Normal file

Binary file not shown.