mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
[WIP] Nearly completed refactor of DisplayProfileForm
Nearly have it working. It now saves, loads and renames the display profiles. Need to fix up the delete, apply buttons and make it remove the old ilv images when we rename profiles.
This commit is contained in:
parent
7196791298
commit
861f1585b2
@ -16,6 +16,7 @@ namespace HeliosPlus.Reporting
|
||||
internal class Program
|
||||
{
|
||||
private static StreamWriter _writer;
|
||||
internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
|
||||
|
||||
private static void Dump<T>(
|
||||
IEnumerable<T> items,
|
||||
|
@ -174,9 +174,14 @@ namespace HeliosPlus.Shared
|
||||
|
||||
public ProfilePath[] Paths { get; set; } = new ProfilePath[0];
|
||||
|
||||
public static string ProfilesPath
|
||||
public static string SavedProfilesFilePath
|
||||
{
|
||||
get => System.IO.Path.Combine(AppDataPath, $"DisplayProfiles_{Version.ToString(2)}.json");
|
||||
get => System.IO.Path.Combine(AppDataPath, $"Profiles\\DisplayProfiles_{Version.ToString(2)}.json");
|
||||
}
|
||||
|
||||
public static string SavedProfilesPath
|
||||
{
|
||||
get => System.IO.Path.Combine(AppDataPath, $"Profiles");
|
||||
}
|
||||
|
||||
public static List<Profile> AllSavedProfiles
|
||||
@ -200,6 +205,9 @@ namespace HeliosPlus.Shared
|
||||
|
||||
}
|
||||
|
||||
public string SavedProfileCacheFilename { get; set; }
|
||||
|
||||
|
||||
[JsonConverter(typeof(CustomBitmapConverter))]
|
||||
public Bitmap ProfileBitmap
|
||||
{
|
||||
@ -229,58 +237,61 @@ namespace HeliosPlus.Shared
|
||||
|
||||
public static IEnumerable<Profile> LoadAllProfiles()
|
||||
{
|
||||
try
|
||||
|
||||
if (File.Exists(SavedProfilesFilePath))
|
||||
{
|
||||
if (File.Exists(ProfilesPath))
|
||||
{
|
||||
var json = File.ReadAllText(ProfilesPath, Encoding.Unicode);
|
||||
var json = File.ReadAllText(SavedProfilesFilePath, Encoding.Unicode);
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
List<Profile> profiles = new List<Profile>();
|
||||
try
|
||||
{
|
||||
//var profiles = JsonConvert.DeserializeObject<Profile[]>(json, new JsonSerializerSettings
|
||||
var profiles = JsonConvert.DeserializeObject<List<Profile>>(json, new JsonSerializerSettings
|
||||
profiles = JsonConvert.DeserializeObject<List<Profile>>(json, new JsonSerializerSettings
|
||||
{
|
||||
MissingMemberHandling = MissingMemberHandling.Ignore,
|
||||
NullValueHandling = NullValueHandling.Ignore,
|
||||
DefaultValueHandling = DefaultValueHandling.Include,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored
|
||||
Console.WriteLine("Unable to deserialize profile: " + ex.Message);
|
||||
}
|
||||
|
||||
//Convert array to list
|
||||
//List<Profile> profilesList = profiles.ToList<Profile>();
|
||||
|
||||
// Find which entry is being used now, and save that info in a class variable
|
||||
Profile myCurrentProfile = new Profile
|
||||
{
|
||||
Name = "Current Display Profile",
|
||||
Paths = PathInfo.GetActivePaths().Select(info => new ProfilePath(info)).ToArray()
|
||||
};
|
||||
//Convert array to list
|
||||
//List<Profile> profilesList = profiles.ToList<Profile>();
|
||||
|
||||
_currentProfile = myCurrentProfile;
|
||||
// Find which entry is being used now, and save that info in a class variable
|
||||
Profile myCurrentProfile = new Profile
|
||||
{
|
||||
Name = "Current Display Profile",
|
||||
Paths = PathInfo.GetActivePaths().Select(info => new ProfilePath(info)).ToArray()
|
||||
};
|
||||
|
||||
foreach (Profile loadedProfile in profiles)
|
||||
{
|
||||
// Save a profile Icon to the profile
|
||||
loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile);
|
||||
loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(128,128);
|
||||
_currentProfile = myCurrentProfile;
|
||||
|
||||
if (loadedProfile == myCurrentProfile) {
|
||||
_currentProfile = loadedProfile;
|
||||
}
|
||||
foreach (Profile loadedProfile in profiles)
|
||||
{
|
||||
// Save a profile Icon to the profile
|
||||
loadedProfile.ProfileIcon = new ProfileIcon(loadedProfile);
|
||||
loadedProfile.ProfileBitmap = loadedProfile.ProfileIcon.ToBitmap(128,128);
|
||||
|
||||
if (loadedProfile == myCurrentProfile) {
|
||||
_currentProfile = loadedProfile;
|
||||
}
|
||||
|
||||
_allSavedProfiles = profiles;
|
||||
|
||||
return _allSavedProfiles;
|
||||
}
|
||||
|
||||
_allSavedProfiles = profiles;
|
||||
|
||||
return _allSavedProfiles;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored
|
||||
Console.WriteLine("Unable to deserialize profile: " + ex.Message);
|
||||
}
|
||||
|
||||
// If we get here, then we don't have any profiles saved!
|
||||
// So we gotta start from scratch
|
||||
@ -347,41 +358,42 @@ namespace HeliosPlus.Shared
|
||||
|
||||
public static bool SaveAllProfiles()
|
||||
{
|
||||
try
|
||||
{
|
||||
var json = JsonConvert.SerializeObject(_allSavedProfiles, Formatting.Indented, new JsonSerializerSettings
|
||||
{
|
||||
NullValueHandling = NullValueHandling.Include,
|
||||
DefaultValueHandling = DefaultValueHandling.Populate,
|
||||
TypeNameHandling = TypeNameHandling.Auto
|
||||
});
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
var dir = System.IO.Path.GetDirectoryName(ProfilesPath);
|
||||
|
||||
if (dir != null)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(ProfilesPath, json, Encoding.Unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored
|
||||
Console.WriteLine("Unable to serialize profile: " + ex.Message);
|
||||
}
|
||||
|
||||
if (SaveAllProfiles(_allSavedProfiles))
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
public static bool SaveAllProfiles(List<Profile> profilesToSave)
|
||||
{
|
||||
|
||||
List<string> jsonParsingErrors = new List<string>();
|
||||
if (!Directory.Exists(SavedProfilesPath))
|
||||
{
|
||||
try
|
||||
{
|
||||
Directory.CreateDirectory(SavedProfilesPath);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Unable to create Profile folder " + SavedProfilesPath + ": " + ex.Message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Now we loop over the profiles and save their images for later
|
||||
foreach (Profile profileToSave in profilesToSave)
|
||||
{
|
||||
profileToSave.SavedProfileCacheFilename = Path.Combine(SavedProfilesPath, GetValidFilename(String.Concat(profileToSave.Name + @".png")));
|
||||
try
|
||||
{
|
||||
|
||||
profileToSave.ProfileBitmap.Save(profileToSave.SavedProfileCacheFilename, ImageFormat.Png);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
Console.WriteLine("Unable to create profile image in cache using " + profileToSave.SavedProfileCacheFilename + ": " + ex.Message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
@ -396,12 +408,12 @@ namespace HeliosPlus.Shared
|
||||
|
||||
if (!string.IsNullOrWhiteSpace(json))
|
||||
{
|
||||
var dir = System.IO.Path.GetDirectoryName(ProfilesPath);
|
||||
var dir = System.IO.Path.GetDirectoryName(SavedProfilesFilePath);
|
||||
|
||||
if (dir != null)
|
||||
{
|
||||
Directory.CreateDirectory(dir);
|
||||
File.WriteAllText(ProfilesPath, json, Encoding.Unicode);
|
||||
File.WriteAllText(SavedProfilesFilePath, json, Encoding.Unicode);
|
||||
|
||||
return true;
|
||||
}
|
||||
@ -409,11 +421,10 @@ namespace HeliosPlus.Shared
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
// ignored
|
||||
Console.WriteLine("Unable to serialize profile: " + ex.Message);
|
||||
}
|
||||
|
||||
// Overright the list of saved profiles as the new lot we received.
|
||||
// Overwrite the list of saved profiles as the new lot we received.
|
||||
_allSavedProfiles = profilesToSave;
|
||||
|
||||
return false;
|
||||
@ -455,6 +466,16 @@ namespace HeliosPlus.Shared
|
||||
return (Name ?? Language.UN_TITLED_PROFILE) + (IsActive ? " " + Language._Active_ : "");
|
||||
}
|
||||
|
||||
private static string GetValidFilename(string uncheckedFilename)
|
||||
{
|
||||
string invalid = new string(Path.GetInvalidFileNameChars()) + new string(Path.GetInvalidPathChars());
|
||||
foreach (char c in invalid)
|
||||
{
|
||||
uncheckedFilename = uncheckedFilename.Replace(c.ToString(), "");
|
||||
}
|
||||
return uncheckedFilename;
|
||||
}
|
||||
|
||||
public bool Apply()
|
||||
{
|
||||
try
|
||||
|
@ -1,4 +1,5 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
using System.Windows.Forms;
|
||||
using HeliosPlus.Shared;
|
||||
using HeliosPlus.ShellExtension.Resources;
|
||||
@ -7,6 +8,8 @@ namespace HeliosPlus.ShellExtension
|
||||
{
|
||||
internal class HeliosPlus
|
||||
{
|
||||
internal static string AppDataPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData), "HeliosPlus");
|
||||
|
||||
public static void Open(
|
||||
HeliosStartupAction action = HeliosStartupAction.None,
|
||||
Profile profile = null,
|
||||
|
@ -171,12 +171,6 @@
|
||||
<ItemGroup>
|
||||
<None Include="Properties\DataSources\HeliosDisplayManagement.UIForms.ShortcutForm.datasource" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HeliosDisplayManagement.Shared\HeliosPlus.Shared.csproj">
|
||||
<Project>{1cacda43-01c7-4cd4-bf6e-9421a29510fc}</Project>
|
||||
<Name>HeliosPlus.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="CircularProgressBar">
|
||||
<Version>2.8.0.16</Version>
|
||||
@ -190,6 +184,9 @@
|
||||
<PackageReference Include="IconLib.Unofficial">
|
||||
<Version>0.73.0</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ImageListView">
|
||||
<Version>13.8.2</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="McMaster.Extensions.CommandLineUtils">
|
||||
<Version>3.0.0</Version>
|
||||
</PackageReference>
|
||||
@ -201,9 +198,6 @@
|
||||
<PackageReference Include="Newtonsoft.Json">
|
||||
<Version>12.0.3</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ObjectListView.Official">
|
||||
<Version>2.9.1</Version>
|
||||
</PackageReference>
|
||||
<PackageReference Include="ValveKeyValue">
|
||||
<Version>0.3.0.144</Version>
|
||||
</PackageReference>
|
||||
@ -232,6 +226,12 @@
|
||||
<ItemGroup>
|
||||
<Content Include="Resources\redarrows.png" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="..\HeliosDisplayManagement.Shared\HeliosPlus.Shared.csproj">
|
||||
<Project>{1cacda43-01c7-4cd4-bf6e-9421a29510fc}</Project>
|
||||
<Name>HeliosPlus.Shared</Name>
|
||||
</ProjectReference>
|
||||
</ItemGroup>
|
||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
|
||||
Other similar extension points exist, see Microsoft.Common.targets.
|
||||
|
@ -489,8 +489,6 @@ namespace HeliosPlus {
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
private static void SwitchToExecutable(Profile profile, string executableToRun, string processToMonitor, uint timeout, string executableArguments)
|
||||
{
|
||||
var rollbackProfile = Profile.CurrentProfile;
|
||||
|
@ -46,19 +46,15 @@ namespace HeliosPlus.UIForms
|
||||
this.editToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.deleteToolStripMenuItem = new System.Windows.Forms.ToolStripMenuItem();
|
||||
this.il_profiles = new System.Windows.Forms.ImageList(this.components);
|
||||
this.olv_profiles = new BrightIdeasSoftware.ObjectListView();
|
||||
this.olvImageColumn = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
||||
this.olvNameColumn = ((BrightIdeasSoftware.OLVColumn)(new BrightIdeasSoftware.OLVColumn()));
|
||||
this.btn_view_current = new System.Windows.Forms.Button();
|
||||
this.btn_save_or_rename = new System.Windows.Forms.Button();
|
||||
this.pb_down_arrow = new System.Windows.Forms.PictureBox();
|
||||
this.lbl_profile_shown = new System.Windows.Forms.Label();
|
||||
this.txt_profile_save_name = new System.Windows.Forms.TextBox();
|
||||
this.errorProvider1 = new System.Windows.Forms.ErrorProvider(this.components);
|
||||
this.imageList1 = new System.Windows.Forms.ImageList(this.components);
|
||||
this.ilv_saved_profiles = new Manina.Windows.Forms.ImageListView();
|
||||
this.menu_profiles.SuspendLayout();
|
||||
((System.ComponentModel.ISupportInitialize)(this.olv_profiles)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).BeginInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).BeginInit();
|
||||
this.SuspendLayout();
|
||||
//
|
||||
// btn_apply
|
||||
@ -139,7 +135,7 @@ namespace HeliosPlus.UIForms
|
||||
this.dv_profile.PaddingX = 100;
|
||||
this.dv_profile.PaddingY = 100;
|
||||
this.dv_profile.Profile = null;
|
||||
this.dv_profile.Size = new System.Drawing.Size(974, 602);
|
||||
this.dv_profile.Size = new System.Drawing.Size(974, 579);
|
||||
this.dv_profile.TabIndex = 4;
|
||||
//
|
||||
// menu_profiles
|
||||
@ -165,18 +161,6 @@ namespace HeliosPlus.UIForms
|
||||
this.toolStripMenuItem2.Name = "toolStripMenuItem2";
|
||||
this.toolStripMenuItem2.Size = new System.Drawing.Size(64, 6);
|
||||
//
|
||||
// cloneToolStripMenuItem
|
||||
//
|
||||
this.cloneToolStripMenuItem.Name = "cloneToolStripMenuItem";
|
||||
this.cloneToolStripMenuItem.Size = new System.Drawing.Size(67, 22);
|
||||
this.cloneToolStripMenuItem.Click += new System.EventHandler(this.Copy_Click);
|
||||
//
|
||||
// createShortcutToolStripMenuItem
|
||||
//
|
||||
this.createShortcutToolStripMenuItem.Name = "createShortcutToolStripMenuItem";
|
||||
this.createShortcutToolStripMenuItem.Size = new System.Drawing.Size(67, 22);
|
||||
this.createShortcutToolStripMenuItem.Click += new System.EventHandler(this.CreateShortcut_Click);
|
||||
//
|
||||
// editToolStripMenuItem
|
||||
//
|
||||
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
|
||||
@ -195,47 +179,6 @@ namespace HeliosPlus.UIForms
|
||||
this.il_profiles.ImageSize = new System.Drawing.Size(64, 64);
|
||||
this.il_profiles.TransparentColor = System.Drawing.Color.Transparent;
|
||||
//
|
||||
// olv_profiles
|
||||
//
|
||||
this.olv_profiles.AllColumns.Add(this.olvImageColumn);
|
||||
this.olv_profiles.AllColumns.Add(this.olvNameColumn);
|
||||
this.olv_profiles.CellEditActivation = BrightIdeasSoftware.ObjectListView.CellEditActivateMode.SingleClick;
|
||||
this.olv_profiles.CellEditUseWholeCell = false;
|
||||
this.olv_profiles.Columns.AddRange(new System.Windows.Forms.ColumnHeader[] {
|
||||
this.olvImageColumn,
|
||||
this.olvNameColumn});
|
||||
this.olv_profiles.ContextMenuStrip = this.menu_profiles;
|
||||
this.olv_profiles.Cursor = System.Windows.Forms.Cursors.Default;
|
||||
this.olv_profiles.GroupImageList = this.il_profiles;
|
||||
this.olv_profiles.HasCollapsibleGroups = false;
|
||||
this.olv_profiles.HeaderStyle = System.Windows.Forms.ColumnHeaderStyle.None;
|
||||
this.olv_profiles.HideSelection = false;
|
||||
this.olv_profiles.LargeImageList = this.il_profiles;
|
||||
this.olv_profiles.Location = new System.Drawing.Point(1, 601);
|
||||
this.olv_profiles.Name = "olv_profiles";
|
||||
this.olv_profiles.OwnerDraw = false;
|
||||
this.olv_profiles.ShowGroups = false;
|
||||
this.olv_profiles.Size = new System.Drawing.Size(974, 125);
|
||||
this.olv_profiles.SmallImageList = this.il_profiles;
|
||||
this.olv_profiles.TabIndex = 13;
|
||||
this.olv_profiles.TileSize = new System.Drawing.Size(128, 128);
|
||||
this.olv_profiles.UseCompatibleStateImageBehavior = false;
|
||||
this.olv_profiles.View = System.Windows.Forms.View.Tile;
|
||||
this.olv_profiles.SelectedIndexChanged += new System.EventHandler(this.olv_profiles_SelectedIndexChanged);
|
||||
//
|
||||
// olvImageColumn
|
||||
//
|
||||
this.olvImageColumn.AspectName = "";
|
||||
this.olvImageColumn.ImageAspectName = "ProfileBitmap";
|
||||
this.olvImageColumn.Width = 256;
|
||||
//
|
||||
// olvNameColumn
|
||||
//
|
||||
this.olvNameColumn.AspectName = "Name";
|
||||
this.olvNameColumn.Groupable = false;
|
||||
this.olvNameColumn.ShowTextInHeader = false;
|
||||
this.olvNameColumn.Width = 256;
|
||||
//
|
||||
// btn_view_current
|
||||
//
|
||||
this.btn_view_current.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Right)));
|
||||
@ -250,6 +193,7 @@ namespace HeliosPlus.UIForms
|
||||
this.btn_view_current.TabIndex = 6;
|
||||
this.btn_view_current.Text = "View &Current";
|
||||
this.btn_view_current.UseVisualStyleBackColor = true;
|
||||
this.btn_view_current.Click += new System.EventHandler(this.btn_view_current_Click);
|
||||
//
|
||||
// btn_save_or_rename
|
||||
//
|
||||
@ -259,7 +203,7 @@ namespace HeliosPlus.UIForms
|
||||
this.btn_save_or_rename.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
|
||||
this.btn_save_or_rename.Font = new System.Drawing.Font("Microsoft Sans Serif", 15.75F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.btn_save_or_rename.ForeColor = System.Drawing.Color.White;
|
||||
this.btn_save_or_rename.Location = new System.Drawing.Point(221, 545);
|
||||
this.btn_save_or_rename.Location = new System.Drawing.Point(221, 520);
|
||||
this.btn_save_or_rename.Name = "btn_save_or_rename";
|
||||
this.btn_save_or_rename.Size = new System.Drawing.Size(151, 33);
|
||||
this.btn_save_or_rename.TabIndex = 1;
|
||||
@ -271,7 +215,7 @@ namespace HeliosPlus.UIForms
|
||||
//
|
||||
this.pb_down_arrow.BackColor = System.Drawing.Color.DimGray;
|
||||
this.pb_down_arrow.Image = ((System.Drawing.Image)(resources.GetObject("pb_down_arrow.Image")));
|
||||
this.pb_down_arrow.Location = new System.Drawing.Point(461, 576);
|
||||
this.pb_down_arrow.Location = new System.Drawing.Point(461, 551);
|
||||
this.pb_down_arrow.Name = "pb_down_arrow";
|
||||
this.pb_down_arrow.Size = new System.Drawing.Size(54, 27);
|
||||
this.pb_down_arrow.SizeMode = System.Windows.Forms.PictureBoxSizeMode.Zoom;
|
||||
@ -293,15 +237,35 @@ namespace HeliosPlus.UIForms
|
||||
// txt_profile_save_name
|
||||
//
|
||||
this.txt_profile_save_name.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
|
||||
this.txt_profile_save_name.Location = new System.Drawing.Point(372, 544);
|
||||
this.txt_profile_save_name.Location = new System.Drawing.Point(372, 519);
|
||||
this.txt_profile_save_name.MaxLength = 200;
|
||||
this.txt_profile_save_name.Name = "txt_profile_save_name";
|
||||
this.txt_profile_save_name.Size = new System.Drawing.Size(384, 35);
|
||||
this.txt_profile_save_name.TabIndex = 20;
|
||||
//
|
||||
// errorProvider1
|
||||
// imageList1
|
||||
//
|
||||
this.errorProvider1.ContainerControl = this;
|
||||
this.imageList1.ColorDepth = System.Windows.Forms.ColorDepth.Depth8Bit;
|
||||
this.imageList1.ImageSize = new System.Drawing.Size(16, 16);
|
||||
this.imageList1.TransparentColor = System.Drawing.Color.Transparent;
|
||||
//
|
||||
// ilv_saved_profiles
|
||||
//
|
||||
this.ilv_saved_profiles.AllowCheckBoxClick = false;
|
||||
this.ilv_saved_profiles.AllowColumnClick = false;
|
||||
this.ilv_saved_profiles.AllowColumnResize = false;
|
||||
this.ilv_saved_profiles.AllowItemReorder = false;
|
||||
this.ilv_saved_profiles.AllowPaneResize = false;
|
||||
this.ilv_saved_profiles.Location = new System.Drawing.Point(0, 578);
|
||||
this.ilv_saved_profiles.MultiSelect = false;
|
||||
this.ilv_saved_profiles.Name = "ilv_saved_profiles";
|
||||
this.ilv_saved_profiles.PersistentCacheDirectory = "";
|
||||
this.ilv_saved_profiles.PersistentCacheSize = ((long)(100));
|
||||
this.ilv_saved_profiles.Size = new System.Drawing.Size(974, 128);
|
||||
this.ilv_saved_profiles.TabIndex = 21;
|
||||
this.ilv_saved_profiles.UseWIC = true;
|
||||
this.ilv_saved_profiles.View = Manina.Windows.Forms.View.HorizontalStrip;
|
||||
this.ilv_saved_profiles.ItemClick += new Manina.Windows.Forms.ItemClickEventHandler(this.ilv_saved_profiles_ItemClick);
|
||||
//
|
||||
// DisplayProfileForm
|
||||
//
|
||||
@ -311,6 +275,7 @@ namespace HeliosPlus.UIForms
|
||||
this.BackColor = System.Drawing.Color.Black;
|
||||
this.CancelButton = this.btn_back;
|
||||
this.ClientSize = new System.Drawing.Size(976, 812);
|
||||
this.Controls.Add(this.ilv_saved_profiles);
|
||||
this.Controls.Add(this.txt_profile_save_name);
|
||||
this.Controls.Add(this.lbl_profile_shown);
|
||||
this.Controls.Add(this.btn_save_or_rename);
|
||||
@ -319,9 +284,9 @@ namespace HeliosPlus.UIForms
|
||||
this.Controls.Add(this.btn_back);
|
||||
this.Controls.Add(this.btn_edit);
|
||||
this.Controls.Add(this.btn_apply);
|
||||
this.Controls.Add(this.olv_profiles);
|
||||
this.Controls.Add(this.pb_down_arrow);
|
||||
this.Controls.Add(this.dv_profile);
|
||||
this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedSingle;
|
||||
this.Icon = ((System.Drawing.Icon)(resources.GetObject("$this.Icon")));
|
||||
this.MaximizeBox = false;
|
||||
this.MinimumSize = new System.Drawing.Size(800, 400);
|
||||
@ -333,9 +298,7 @@ namespace HeliosPlus.UIForms
|
||||
this.Activated += new System.EventHandler(this.MainForm_Activated);
|
||||
this.Load += new System.EventHandler(this.MainForm_Load);
|
||||
this.menu_profiles.ResumeLayout(false);
|
||||
((System.ComponentModel.ISupportInitialize)(this.olv_profiles)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).EndInit();
|
||||
((System.ComponentModel.ISupportInitialize)(this.errorProvider1)).EndInit();
|
||||
this.ResumeLayout(false);
|
||||
this.PerformLayout();
|
||||
|
||||
@ -355,15 +318,13 @@ namespace HeliosPlus.UIForms
|
||||
private System.Windows.Forms.ToolStripSeparator toolStripMenuItem2;
|
||||
private System.Windows.Forms.ToolStripMenuItem createShortcutToolStripMenuItem;
|
||||
private System.Windows.Forms.ImageList il_profiles;
|
||||
private BrightIdeasSoftware.ObjectListView olv_profiles;
|
||||
private BrightIdeasSoftware.OLVColumn olvNameColumn;
|
||||
private BrightIdeasSoftware.OLVColumn olvImageColumn;
|
||||
private System.Windows.Forms.Button btn_view_current;
|
||||
private System.Windows.Forms.Button btn_save_or_rename;
|
||||
private System.Windows.Forms.PictureBox pb_down_arrow;
|
||||
private System.Windows.Forms.Label lbl_profile_shown;
|
||||
private System.Windows.Forms.TextBox txt_profile_save_name;
|
||||
private System.Windows.Forms.ErrorProvider errorProvider1;
|
||||
private System.Windows.Forms.ImageList imageList1;
|
||||
private Manina.Windows.Forms.ImageListView ilv_saved_profiles;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -10,6 +10,8 @@ using HeliosPlus.Shared;
|
||||
using System.Drawing;
|
||||
using System.Drawing.Drawing2D;
|
||||
using System.Globalization;
|
||||
using Manina.Windows.Forms;
|
||||
using System.Text.RegularExpressions;
|
||||
|
||||
namespace HeliosPlus.UIForms
|
||||
{
|
||||
@ -216,45 +218,6 @@ namespace HeliosPlus.UIForms
|
||||
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_old.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_old.SelectedIndices.Count > 0 &&
|
||||
lv_profiles_old.SelectedItems[0].Tag != null)
|
||||
{
|
||||
var shortcutForm = new ShortcutForm(dv_profile.Profile);
|
||||
shortcutForm.ShowDialog(this);
|
||||
SaveProfiles();
|
||||
}*/
|
||||
}
|
||||
|
||||
private void Delete_Click(object sender, EventArgs e)
|
||||
{
|
||||
@ -414,20 +377,27 @@ namespace HeliosPlus.UIForms
|
||||
//lv_profiles_old.Items[0].Selected = true;
|
||||
//lv_profiles.Items[0].Focused = true;
|
||||
//lv_profiles.Items[0].Checked = true;
|
||||
List<Profile> profiles = (List<Profile>)Profile.LoadAllProfiles();
|
||||
ImageListViewItem newItem;
|
||||
_savedProfiles = (List<Profile>)Profile.LoadAllProfiles();
|
||||
|
||||
|
||||
dv_profile.Profile = Profile.CurrentProfile;
|
||||
_selectedProfile = Profile.CurrentProfile;
|
||||
|
||||
if (profiles.Count > 0)
|
||||
// Temporarily stop updating the saved_profiles listview
|
||||
ilv_saved_profiles.SuspendLayout();
|
||||
|
||||
if (_savedProfiles.Count > 0)
|
||||
{
|
||||
foreach (Profile loadedProfile in profiles)
|
||||
foreach (Profile loadedProfile in _savedProfiles)
|
||||
{
|
||||
Bitmap profileIconImage = loadedProfile.ProfileIcon.ToBitmap(
|
||||
il_profiles.ImageSize.Width,
|
||||
il_profiles.ImageSize.Height
|
||||
);
|
||||
il_profiles.Images.Add(profileIconImage);
|
||||
|
||||
newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
|
||||
ilv_saved_profiles.Items.Add(newItem);
|
||||
|
||||
if (Profile.CurrentProfile.Equals(loadedProfile))
|
||||
{
|
||||
@ -435,16 +405,13 @@ namespace HeliosPlus.UIForms
|
||||
// so we need to show the current profile
|
||||
// and make sure the current profile name has
|
||||
// been updated with the name saved last time
|
||||
|
||||
// So as the current profile was already saved, we need to change
|
||||
// the save button to a rename one
|
||||
_saveOrRenameMode = "rename";
|
||||
btn_save_or_rename.Text = "Rename to";
|
||||
// We also need to load the saved profile name to show the user
|
||||
lbl_profile_shown.Text = loadedProfile.Name;
|
||||
txt_profile_save_name.Text = loadedProfile.Name;
|
||||
// ANd we need to update the actual current profile name too!
|
||||
Profile.CurrentProfile.Name = loadedProfile.Name;
|
||||
// And finally we need to select the currentProfile, as it's the one we're using now
|
||||
newItem.Selected = true;
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -452,13 +419,18 @@ namespace HeliosPlus.UIForms
|
||||
// This is a new one
|
||||
_saveOrRenameMode = "save";
|
||||
btn_save_or_rename.Text = "Save As";
|
||||
lbl_profile_shown.Text = Profile.CurrentProfile.Name;
|
||||
txt_profile_save_name.Text = Profile.CurrentProfile.Name;
|
||||
if (!loadedProfile.IsPossible)
|
||||
{
|
||||
// TODO mark the imagelist view netItem in some way
|
||||
// to identify that it's not avalid profile, but
|
||||
// still allow users to select it to rename it and
|
||||
// see what the profile looks like.
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
dv_profile.Profile = Profile.CurrentProfile;
|
||||
lbl_profile_shown.Text = Profile.CurrentProfile.Name;
|
||||
ChangeSelectedProfile(Profile.CurrentProfile);
|
||||
}
|
||||
else
|
||||
{
|
||||
@ -467,23 +439,53 @@ namespace HeliosPlus.UIForms
|
||||
// Use the current profile name in the label and the save name
|
||||
_saveOrRenameMode = "save";
|
||||
btn_save_or_rename.Text = "Save As";
|
||||
lbl_profile_shown.Text = Profile.CurrentProfile.Name;
|
||||
txt_profile_save_name.Text = Profile.CurrentProfile.Name;
|
||||
ChangeSelectedProfile(Profile.CurrentProfile);
|
||||
}
|
||||
|
||||
// Restart updating the saved_profiles listview
|
||||
ilv_saved_profiles.ResumeLayout();
|
||||
|
||||
//olv_profiles.LargeImageList = il_profiles;
|
||||
|
||||
// Start the ObjectListView list view
|
||||
olv_profiles.SetObjects(profiles);
|
||||
//ilv_saved_profiles.Items = il_profiles;
|
||||
}
|
||||
|
||||
/* public object ProfileImageGetter(object rowObject)
|
||||
/* public object ProfileImageGetter(object rowObject)
|
||||
{
|
||||
Profile p = (Profile)rowObject;
|
||||
return
|
||||
};*/
|
||||
|
||||
private void ChangeSelectedProfile(Profile profile)
|
||||
{
|
||||
Profile p = (Profile)rowObject;
|
||||
return
|
||||
};*/
|
||||
|
||||
// We also need to load the saved profile name to show the user
|
||||
ChangeSelectedProfileDetails(profile.Name);
|
||||
// And we need to update the actual selected profile too!
|
||||
_selectedProfile = profile;
|
||||
// And finally show the profile in the display view
|
||||
dv_profile.Profile = profile;
|
||||
dv_profile.Refresh();
|
||||
}
|
||||
|
||||
private void ChangeSelectedProfileDetails(string profileName)
|
||||
{
|
||||
// We also need to load the saved profile name to show the user
|
||||
lbl_profile_shown.Text = profileName;
|
||||
txt_profile_save_name.Text = profileName;
|
||||
}
|
||||
|
||||
|
||||
private bool IsValidFilename(string testName)
|
||||
{
|
||||
string strTheseAreInvalidFileNameChars = new string(Path.GetInvalidFileNameChars());
|
||||
Regex regInvalidFileName = new Regex("[" + Regex.Escape(strTheseAreInvalidFileNameChars) + "]");
|
||||
|
||||
if (regInvalidFileName.IsMatch(testName)) { return false; };
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
private void RefreshProfilesStatus()
|
||||
@ -515,36 +517,108 @@ namespace HeliosPlus.UIForms
|
||||
//lv_profiles_old.Invalidate();
|
||||
}
|
||||
|
||||
private void SaveProfiles()
|
||||
{
|
||||
/*Profile.SaveAllProfiles(
|
||||
lv_profiles_old.Items.Cast<ListViewItem>()
|
||||
.Select(item => item.Tag as Profile)
|
||||
.Where(profile => profile != null));*/
|
||||
ReloadProfiles();
|
||||
}
|
||||
|
||||
private void olv_profiles_SelectedIndexChanged(object sender, EventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
private void btn_save_as_Click(object sender, EventArgs e)
|
||||
{
|
||||
// Check we're not already using the name
|
||||
foreach (Profile savedProfile in _savedProfiles)
|
||||
{
|
||||
//if (String.Equals(txt_profile_save_name.Text, savedProfile.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
if (_selectedProfile.Equals(Profile.CurrentProfile))
|
||||
{
|
||||
MessageBox.Show("Sorry, you can only have one saved display profile for each display configuration.", "Display profile already exists", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return;
|
||||
// Check the name is valid
|
||||
if (!IsValidFilename(txt_profile_save_name.Text))
|
||||
{
|
||||
MessageBox.Show("The profile name cannot contain the following characters:" + Path.GetInvalidFileNameChars(), "Invalid characters in profile name", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// If we're saving the current profile as a new item
|
||||
// then we'll be in "save" mode
|
||||
if (_saveOrRenameMode == "save")
|
||||
{
|
||||
|
||||
// Check we're not already using the name
|
||||
foreach (Profile savedProfile in Profile.AllSavedProfiles)
|
||||
{
|
||||
//if (String.Equals(txt_profile_save_name.Text, savedProfile.Name, StringComparison.InvariantCultureIgnoreCase))
|
||||
if (_selectedProfile.Equals(Profile.CurrentProfile))
|
||||
{
|
||||
MessageBox.Show("Sorry, you can only have one saved display profile for each display configuration.", "Display profile already exists", MessageBoxButtons.OK, MessageBoxIcon.Error);
|
||||
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// We're in 'save' mode!
|
||||
// Add the current profile to the list of profiles
|
||||
_savedProfiles.Add(_selectedProfile);
|
||||
// Then save the profiles so we always have it updated
|
||||
Profile.SaveAllProfiles(_savedProfiles);
|
||||
// Load the currentProfile image into the imagelistview
|
||||
ImageListViewItem newItem = new ImageListViewItem(_selectedProfile.SavedProfileCacheFilename, _selectedProfile.Name);
|
||||
newItem.Selected = true;
|
||||
ilv_saved_profiles.Items.Add(newItem);
|
||||
|
||||
//ilv_saved_profiles.Refresh();
|
||||
/*foreach (ImageListViewItem myItem in ilv_saved_profiles.Items)
|
||||
{
|
||||
if (_selectedProfile.Name == myItem.Text)
|
||||
{
|
||||
myItem.Selected = true;
|
||||
myItem.Focused = true;
|
||||
}
|
||||
|
||||
}*/
|
||||
}
|
||||
else
|
||||
{
|
||||
// We're in 'rename' mode!
|
||||
// THen rename the imagelistview item
|
||||
string oldProfileName = _selectedProfile.Name;
|
||||
foreach (ImageListViewItem myItem in ilv_saved_profiles.Items)
|
||||
{
|
||||
if (myItem.Text == oldProfileName)
|
||||
{
|
||||
myItem.Text = txt_profile_save_name.Text;
|
||||
}
|
||||
}
|
||||
// So lets rename the profile itself in the saved profiles
|
||||
// and the selectprofile name too
|
||||
foreach (Profile savedProfile in _savedProfiles)
|
||||
{
|
||||
if (savedProfile.Equals(_selectedProfile))
|
||||
{
|
||||
_selectedProfile.Name = txt_profile_save_name.Text;
|
||||
savedProfile.Name = txt_profile_save_name.Text;
|
||||
ChangeSelectedProfileDetails(_selectedProfile.Name);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO - delete the old PNG that we renamed from so we don't get a buildup of them!
|
||||
// Then save all the profiles to lock it in
|
||||
Profile.SaveAllProfiles(_savedProfiles);
|
||||
}
|
||||
|
||||
_savedProfiles.Add(_selectedProfile);
|
||||
Profile.SaveAllProfiles(_savedProfiles);
|
||||
// now update the profiles image listview
|
||||
//ilv_saved_profiles.Refresh();
|
||||
|
||||
}
|
||||
|
||||
private void ilv_saved_profiles_ItemClick(object sender, ItemClickEventArgs e)
|
||||
{
|
||||
foreach (Profile savedProfile in _savedProfiles)
|
||||
{
|
||||
if (savedProfile.Name == e.Item.Text)
|
||||
{
|
||||
ChangeSelectedProfile(savedProfile);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void btn_view_current_Click(object sender, EventArgs e)
|
||||
{
|
||||
ChangeSelectedProfile(Profile.CurrentProfile);
|
||||
}
|
||||
|
||||
/*protected void txt_profile_save_name_Validating(object sender, System.ComponentModel.CancelEventArgs e)
|
||||
|
@ -156,7 +156,7 @@
|
||||
AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAH0riv8AqmJbqTbWBoYAAAAASUVORK5CYII=
|
||||
</value>
|
||||
</data>
|
||||
<metadata name="errorProvider1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<metadata name="imageList1.TrayLocation" type="System.Drawing.Point, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a">
|
||||
<value>248, 17</value>
|
||||
</metadata>
|
||||
<data name="$this.Icon" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
|
||||
|
Loading…
Reference in New Issue
Block a user