Working renovated DisplayProfilesForm

Finished the rework of the DisplayProfilesForm so
that the correct states are kept throughout the
lifecycle of the display profile. It handles changes
to current display profile, and seems to work fine.
Future improvements will be to make the
imagelistview use bitmaps in memory rather than
the images on disk, but that will be done under
another branch.
This commit is contained in:
temacdonald 2020-05-15 15:41:01 +12:00
parent 61d09e2f2f
commit 9685a7c358
7 changed files with 99 additions and 97 deletions

View File

@ -324,7 +324,7 @@ namespace HeliosPlus.Shared
}
public static void RefreshActiveStatus()
public static void UpdateCurrentProfile()
{
_currentProfile = new Profile
{
@ -538,13 +538,13 @@ namespace HeliosPlus.Shared
Thread.Sleep(10000);
// Check o see what our current screen profile is now!
RefreshActiveStatus();
UpdateCurrentProfile();
return true;
}
catch (Exception ex)
{
RefreshActiveStatus();
UpdateCurrentProfile();
MessageBox.Show(ex.Message, @"Profile", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return false;

View File

@ -41,7 +41,7 @@ namespace HeliosPlus.ShellExtension
if (Profile.LoadAllProfiles().Any())
{
Profile.RefreshActiveStatus();
Profile.UpdateCurrentProfile();
var extensionMenu = new ToolStripMenuItem(Language.Display_Profiles,
Properties.Resources.Icon_x16);

View File

@ -30,7 +30,7 @@ namespace HeliosPlus.ShellExtension
if (Profile.LoadAllProfiles().Any())
{
Profile.RefreshActiveStatus();
Profile.UpdateCurrentProfile();
foreach (var profile in Profile.LoadAllProfiles())
{

View File

@ -31,7 +31,7 @@ namespace HeliosPlus.ShellExtension
if (Profile.LoadAllProfiles().Any())
{
Profile.RefreshActiveStatus();
Profile.UpdateCurrentProfile();
foreach (var profile in Profile.LoadAllProfiles())
{

View File

@ -52,8 +52,7 @@
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>
</ApplicationIcon>
<ApplicationIcon>Resources\HeliosPlus.ico</ApplicationIcon>
</PropertyGroup>
<PropertyGroup>
<StartupObject>HeliosPlus.Program</StartupObject>

View File

@ -34,7 +34,6 @@ namespace HeliosPlus.UIForms
this.components = new System.ComponentModel.Container();
System.ComponentModel.ComponentResourceManager resources = new System.ComponentModel.ComponentResourceManager(typeof(DisplayProfileForm));
this.btn_apply = new System.Windows.Forms.Button();
this.btn_edit = new System.Windows.Forms.Button();
this.btn_back = new System.Windows.Forms.Button();
this.btn_delete = new System.Windows.Forms.Button();
this.dv_profile = new HeliosPlus.Shared.UserControls.DisplayView();
@ -76,22 +75,6 @@ namespace HeliosPlus.UIForms
this.btn_apply.UseVisualStyleBackColor = false;
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.BackColor = System.Drawing.Color.Black;
this.btn_edit.FlatStyle = System.Windows.Forms.FlatStyle.Flat;
this.btn_edit.Font = new System.Drawing.Font("Microsoft Sans Serif", 18F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(0)));
this.btn_edit.ForeColor = System.Drawing.Color.White;
this.btn_edit.Location = new System.Drawing.Point(12, 750);
this.btn_edit.Name = "btn_edit";
this.btn_edit.Size = new System.Drawing.Size(120, 40);
this.btn_edit.TabIndex = 8;
this.btn_edit.Text = "&Edit";
this.btn_edit.UseVisualStyleBackColor = false;
this.btn_edit.Visible = false;
this.btn_edit.Click += new System.EventHandler(this.Edit_Click);
//
// btn_back
//
this.btn_back.Anchor = ((System.Windows.Forms.AnchorStyles)((System.Windows.Forms.AnchorStyles.Bottom | System.Windows.Forms.AnchorStyles.Left)));
@ -177,7 +160,6 @@ namespace HeliosPlus.UIForms
//
this.editToolStripMenuItem.Name = "editToolStripMenuItem";
this.editToolStripMenuItem.Size = new System.Drawing.Size(67, 22);
this.editToolStripMenuItem.Click += new System.EventHandler(this.Edit_Click);
//
// deleteToolStripMenuItem
//
@ -320,7 +302,6 @@ namespace HeliosPlus.UIForms
this.Controls.Add(this.btn_view_current);
this.Controls.Add(this.btn_delete);
this.Controls.Add(this.btn_back);
this.Controls.Add(this.btn_edit);
this.Controls.Add(this.btn_apply);
this.Controls.Add(this.pb_down_arrow);
this.Controls.Add(this.dv_profile);
@ -333,8 +314,8 @@ namespace HeliosPlus.UIForms
this.StartPosition = System.Windows.Forms.FormStartPosition.CenterScreen;
this.Text = "HeliosPlus - Setup Display Profiles";
this.TopMost = true;
this.Activated += new System.EventHandler(this.MainForm_Activated);
this.Load += new System.EventHandler(this.MainForm_Load);
this.Activated += new System.EventHandler(this.DisplayProfileForm_Activated);
this.Load += new System.EventHandler(this.DisplayProfileForm_Load);
this.menu_profiles.ResumeLayout(false);
((System.ComponentModel.ISupportInitialize)(this.pb_down_arrow)).EndInit();
this.ResumeLayout(false);
@ -345,7 +326,6 @@ namespace HeliosPlus.UIForms
#endregion
private DisplayView dv_profile;
private System.Windows.Forms.Button btn_apply;
private System.Windows.Forms.Button btn_edit;
private System.Windows.Forms.Button btn_back;
private System.Windows.Forms.Button btn_delete;
private System.Windows.Forms.ContextMenuStrip menu_profiles;

View File

@ -23,6 +23,7 @@ namespace HeliosPlus.UIForms
private Profile _selectedProfile;
private List<Profile> _savedProfiles = new List<Profile>();
private string _saveOrRenameMode = "save";
private static bool _inDialog = false;
public DisplayProfileForm()
{
@ -64,6 +65,10 @@ namespace HeliosPlus.UIForms
private void Delete_Click(object sender, EventArgs e)
{
_inDialog = true;
if (MessageBox.Show($"Are you sure you want to delete the '{_selectedProfile.Name}' Display Profile?", $"Delete '{_selectedProfile.Name}' Display Profile?", MessageBoxButtons.YesNo, MessageBoxIcon.Error) == DialogResult.No)
return;
Profile profileToDelete = _selectedProfile;
string profileToDeleteFilename = _selectedProfile.SavedProfileCacheFilename;
@ -120,82 +125,82 @@ namespace HeliosPlus.UIForms
Profile.SaveAllProfiles(_savedProfiles);
}
private void Edit_Click(object sender, EventArgs e)
private void RefreshDisplayProfileUI()
{
/* if (dv_profile.Profile != null &&
lv_profiles_old.SelectedIndices.Count > 0 &&
lv_profiles_old.SelectedItems[0].Tag != null)
{
var selectedIndex = lv_profiles_old.SelectedIndices[0];
var editForm = new EditForm(dv_profile.Profile);
if (editForm.ShowDialog(this) == DialogResult.OK)
if (!_inDialog)
{
// Temporarily stop updating the saved_profiles listview
ilv_saved_profiles.SuspendLayout();
if (_savedProfiles.Count > 0)
{
lv_profiles_old.Items[selectedIndex].Tag = editForm.Profile;
SaveProfiles();
}
}*/
}
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_old.SelectedItems.Count == 0)
{
lv_profiles_old.Items[0].Selected = true;
}*/
}
private void MainForm_Load(object sender, EventArgs e)
{
ImageListViewItem newItem;
_savedProfiles = (List<Profile>)Profile.LoadAllProfiles();
// Temporarily stop updating the saved_profiles listview
ilv_saved_profiles.SuspendLayout();
if (_savedProfiles.Count > 0)
{
bool foundCurrentProfileInLoadedProfiles = false;
foreach (Profile loadedProfile in _savedProfiles)
{
loadedProfile.SaveProfileImageToCache();
newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
ilv_saved_profiles.Items.Add(newItem);
if (Profile.CurrentProfile.Equals(loadedProfile))
ImageListViewItem newItem = null;
bool foundCurrentProfileInLoadedProfiles = false;
foreach (Profile loadedProfile in _savedProfiles)
{
// We have already saved the current profile!
// so we need to show the current profile
// And finally we need to select the currentProfile, as it's the one we're using now
newItem.Selected = true;
ChangeSelectedProfile(Profile.CurrentProfile);
foundCurrentProfileInLoadedProfiles = true;
bool thisLoadedProfileIsAlreadyHere = (from item in ilv_saved_profiles.Items where item.Text == loadedProfile.Name select item.Text).Any();
if (!thisLoadedProfileIsAlreadyHere)
{
loadedProfile.SaveProfileImageToCache();
newItem = new ImageListViewItem(loadedProfile.SavedProfileCacheFilename, loadedProfile.Name);
ilv_saved_profiles.Items.Add(newItem);
}
if (Profile.CurrentProfile.Equals(loadedProfile))
{
// We have already saved the selected profile!
// so we need to show the selected profile
ChangeSelectedProfile(loadedProfile);
foundCurrentProfileInLoadedProfiles = true;
}
}
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
if (!foundCurrentProfileInLoadedProfiles)
ChangeSelectedProfile(Profile.CurrentProfile);
}
else
{
// If there are no profiles at all then we are starting from scratch!
// Show the profile in the DV window
// Use the current profile name in the label and the save name
ChangeSelectedProfile(Profile.CurrentProfile);
}
// If we get to the end of the loaded profiles and haven't
// found a matching profile, then we need to show the current
// Profile
ChangeSelectedProfile(Profile.CurrentProfile);
// Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout();
}
else
{
// If there are no profiles at all then we are starting from scratch!
// Show the profile in the DV window
// Use the current profile name in the label and the save name
ChangeSelectedProfile(Profile.CurrentProfile);
}
// Otherwise turn off the dialog mode we were just in
_inDialog = false;
}
// Restart updating the saved_profiles listview
ilv_saved_profiles.ResumeLayout();
private void DisplayProfileForm_Activated(object sender, EventArgs e)
{
// We handle the UI updating in DisplayProfileForm_Activated so that
// the app will check for changes to the current profile when the
// user clicks back to this app. This is designed to allow people to
// alter their Windows Display settings then come back to our app
// and the app will automatically recognise that things have changed.
// Reload the profiles in case we swapped to another program to change it
Profile.UpdateCurrentProfile();
// Refresh the Profile UI
RefreshDisplayProfileUI();
}
private void DisplayProfileForm_Load(object sender, EventArgs e)
{
// Load all the profiles to prepare things
_savedProfiles = (List<Profile>)Profile.LoadAllProfiles();
// Update the Current Profile
Profile.UpdateCurrentProfile();
// Refresh the Profile UI
RefreshDisplayProfileUI();
}
@ -211,7 +216,7 @@ namespace HeliosPlus.UIForms
// And update the save/rename textbox
txt_profile_save_name.Text = _selectedProfile.Name;
if (_selectedProfile.Name == Profile.CurrentProfile.Name)
if (_selectedProfile.Equals(Profile.CurrentProfile))
{
if (_savedProfiles.Contains(_selectedProfile))
{
@ -242,11 +247,26 @@ namespace HeliosPlus.UIForms
btn_apply.Visible = true;
}
}
// Refresh the image list view
RefreshImageListView(profile);
// And finally show the profile in the display view
dv_profile.Profile = profile;
dv_profile.Refresh();
}
private void RefreshImageListView(Profile profile)
{
ilv_saved_profiles.ClearSelection();
IEnumerable<ImageListViewItem> matchingImageListViewItems = (from item in ilv_saved_profiles.Items where item.Text == profile.Name select item);
if (matchingImageListViewItems.Any())
{
matchingImageListViewItems.First().Selected = true;
matchingImageListViewItems.First().Focused = true;
}
}
private bool IsValidFilename(string testName)
{
@ -378,7 +398,10 @@ namespace HeliosPlus.UIForms
private void btn_view_current_Click(object sender, EventArgs e)
{
ChangeSelectedProfile(Profile.CurrentProfile);
// Reload the profiles in case we swapped to another program to change it
Profile.UpdateCurrentProfile();
// Refresh the Profile UI
RefreshDisplayProfileUI();
}
private void txt_profile_save_name_KeyDown(object sender, KeyEventArgs e)