mirror of
https://github.com/terrymacdonald/DisplayMagician.git
synced 2024-08-30 18:32:20 +00:00
Refactored tracking errors
Moved tracking profile errors into ProfileRepository and moved shortcut errors into ShortcutRepository.
This commit is contained in:
parent
001e351106
commit
34ae9069c7
@ -1937,7 +1937,7 @@ namespace DisplayMagician
|
||||
// Is the profile still valid right now? i.e. are all the screens available?
|
||||
if (ProfileToUse == null)
|
||||
{
|
||||
return (false,string.Format("The profile is not valid right now and cannot be used."));
|
||||
return (false,string.Format("The profile does not exist (probably deleted) and cannot be used."));
|
||||
}
|
||||
if (!ProfileToUse.IsPossible)
|
||||
{
|
||||
|
@ -26,6 +26,7 @@ namespace DisplayMagician
|
||||
#region Class Variables
|
||||
// Common items to the class
|
||||
private static List<ShortcutItem> _allShortcuts = new List<ShortcutItem>();
|
||||
public static Dictionary<string, bool> _shortcutValidityLookup = new Dictionary<string, bool>();
|
||||
private static bool _shortcutsLoaded = false;
|
||||
// Other constants that are useful
|
||||
private static string AppShortcutStoragePath = Path.Combine(Program.AppDataPath, $"Shortcuts");
|
||||
@ -90,6 +91,18 @@ namespace DisplayMagician
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, bool> ShortcutValidityLookup
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_shortcutsLoaded)
|
||||
// Load the Shortcuts from storage if they need to be
|
||||
LoadShortcuts();
|
||||
|
||||
return _shortcutValidityLookup;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static int ShortcutCount
|
||||
{
|
||||
|
@ -18,7 +18,7 @@ namespace DisplayMagician.UIForms
|
||||
//private static bool _inDialog = false;
|
||||
private static ProfileItem _profileToLoad = null;
|
||||
private ProfileAdaptor _profileAdaptor = new ProfileAdaptor();
|
||||
public static Dictionary<string, bool> profileValidity = new Dictionary<string, bool>();
|
||||
//public static Dictionary<string, bool> profileValidity = new Dictionary<string, bool>();
|
||||
|
||||
public DisplayProfileForm()
|
||||
{
|
||||
@ -129,8 +129,6 @@ namespace DisplayMagician.UIForms
|
||||
// Empty the imageListView
|
||||
ilv_saved_profiles.Items.Clear();
|
||||
|
||||
profileValidity.Clear();
|
||||
|
||||
//IOrderedEnumerable<ProfileItem> orderedProfiles = ProfileRepository.AllProfiles.OrderBy(p => p.Name);
|
||||
|
||||
// Check if the last selected profile is still in the list of profiles
|
||||
@ -149,7 +147,7 @@ namespace DisplayMagician.UIForms
|
||||
newItem.Selected = true;
|
||||
|
||||
|
||||
profileValidity[profile.Name] = profile.IsPossible;
|
||||
//ProfileRepository.ProfileValidityLookup[profile.Name] = profile.IsPossible;
|
||||
|
||||
// Add it to the list!
|
||||
ilv_saved_profiles.Items.Add(newItem, _profileAdaptor);
|
||||
@ -316,6 +314,9 @@ namespace DisplayMagician.UIForms
|
||||
// Lets save the old names for usage next
|
||||
string oldProfileName = _selectedProfile.Name;
|
||||
|
||||
// Lets rename the selectedProfile to the new name
|
||||
ProfileRepository.RenameProfile(_selectedProfile, txt_profile_save_name.Text);
|
||||
|
||||
// Lets rename the entry in the imagelistview to the new name
|
||||
foreach (ImageListViewItem myItem in ilv_saved_profiles.Items)
|
||||
{
|
||||
@ -324,8 +325,6 @@ namespace DisplayMagician.UIForms
|
||||
myItem.Text = txt_profile_save_name.Text;
|
||||
}
|
||||
}
|
||||
// Lets rename the selectedProfile to the new name
|
||||
ProfileRepository.RenameProfile(_selectedProfile, txt_profile_save_name.Text);
|
||||
|
||||
// Lets update the rest of the profile screen too
|
||||
lbl_profile_shown.Text = txt_profile_save_name.Text;
|
||||
@ -339,7 +338,7 @@ namespace DisplayMagician.UIForms
|
||||
ChangeSelectedProfile(_selectedProfile);
|
||||
|
||||
// now update the profiles image listview
|
||||
//ilv_saved_profiles.Refresh();
|
||||
RefreshDisplayProfileUI();
|
||||
|
||||
}
|
||||
|
||||
|
@ -7,6 +7,7 @@ using System.Linq;
|
||||
using System.Text;
|
||||
using System.Threading.Tasks;
|
||||
using System.Windows.Forms;
|
||||
using DisplayMagicianShared;
|
||||
using Manina.Windows.Forms;
|
||||
|
||||
namespace DisplayMagician.UIForms
|
||||
@ -95,7 +96,7 @@ namespace DisplayMagician.UIForms
|
||||
{
|
||||
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
||||
|
||||
if (ShortcutLibraryForm.shortcutValidity[item.Text])
|
||||
if (ShortcutRepository.ShortcutValidityLookup[item.Text])
|
||||
{
|
||||
// Draw the full color image as the shortcuts is not invalid
|
||||
g.DrawImage(img, pos);
|
||||
@ -253,7 +254,7 @@ namespace DisplayMagician.UIForms
|
||||
{
|
||||
Rectangle pos = Utility.GetSizedImageBounds(img, new Rectangle(bounds.Location + itemPadding, ImageListView.ThumbnailSize));
|
||||
|
||||
if (DisplayProfileForm.profileValidity[item.Text])
|
||||
if (ProfileRepository.ProfileValidityLookup[item.Text])
|
||||
{
|
||||
// Draw the full color image as the shortcuts is not invalid
|
||||
g.DrawImage(img, pos);
|
||||
|
@ -878,6 +878,12 @@ namespace DisplayMagician.UIForms
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
MessageBox.Show(
|
||||
@"The Display Profile used by this Shortcut no longer exists and cannot be used. You need to choose a new Display Profile for this Shortcut. We have selected the current Display Profile, but you can choose another profile if you wish.",
|
||||
@"Display Profile no longer exists",
|
||||
MessageBoxButtons.OK,
|
||||
MessageBoxIcon.Exclamation);
|
||||
}
|
||||
|
||||
// Now start populating the other fields if they need it
|
||||
|
@ -19,7 +19,7 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private ShortcutAdaptor _shortcutAdaptor = new ShortcutAdaptor();
|
||||
private ShortcutItem _selectedShortcut = null;
|
||||
public static Dictionary<string, bool> shortcutValidity = new Dictionary<string, bool>();
|
||||
//public static Dictionary<string, bool> shortcutValidity = new Dictionary<string, bool>();
|
||||
|
||||
public ShortcutLibraryForm()
|
||||
{
|
||||
@ -44,6 +44,8 @@ namespace DisplayMagician.UIForms
|
||||
RemoveWarningIfShortcuts();
|
||||
}
|
||||
|
||||
|
||||
|
||||
private void RefreshShortcutLibraryUI()
|
||||
{
|
||||
|
||||
@ -58,7 +60,7 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
ImageListViewItem newItem = null;
|
||||
ilv_saved_shortcuts.Items.Clear();
|
||||
shortcutValidity.Clear();
|
||||
ShortcutRepository.ShortcutValidityLookup.Clear();
|
||||
|
||||
foreach (ShortcutItem loadedShortcut in ShortcutRepository.AllShortcuts.OrderBy(s => s.Name))
|
||||
{
|
||||
@ -69,7 +71,7 @@ namespace DisplayMagician.UIForms
|
||||
newItem.Selected = true;
|
||||
|
||||
(bool result, string thing) = loadedShortcut.IsValid();
|
||||
shortcutValidity[loadedShortcut.Name] = result;
|
||||
ShortcutRepository.ShortcutValidityLookup[loadedShortcut.Name] = result;
|
||||
|
||||
//ilv_saved_profiles.Items.Add(newItem);
|
||||
ilv_saved_shortcuts.Items.Add(newItem, _shortcutAdaptor);
|
||||
@ -186,7 +188,7 @@ namespace DisplayMagician.UIForms
|
||||
if (_selectedShortcut == null)
|
||||
return;
|
||||
|
||||
if (!shortcutValidity[_selectedShortcut.Name])
|
||||
if (!ShortcutRepository.ShortcutValidityLookup[_selectedShortcut.Name])
|
||||
return;
|
||||
|
||||
// Run the selected shortcut
|
||||
@ -195,7 +197,7 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private void SetRunOption()
|
||||
{
|
||||
if (shortcutValidity[_selectedShortcut.Name])
|
||||
if (ShortcutRepository.ShortcutValidityLookup[_selectedShortcut.Name])
|
||||
{
|
||||
btn_run.Visible = true;
|
||||
cms_shortcuts.Items[1].Enabled = true;
|
||||
@ -211,6 +213,7 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private void btn_new_Click(object sender, EventArgs e)
|
||||
{
|
||||
this.Cursor = Cursors.WaitCursor;
|
||||
var shortcutForm = new ShortcutForm(new ShortcutItem());
|
||||
shortcutForm.ShowDialog(this);
|
||||
if (shortcutForm.DialogResult == DialogResult.OK)
|
||||
@ -219,7 +222,9 @@ namespace DisplayMagician.UIForms
|
||||
_selectedShortcut = shortcutForm.Shortcut;
|
||||
RefreshShortcutLibraryUI();
|
||||
}
|
||||
this.Cursor = Cursors.Default;
|
||||
RemoveWarningIfShortcuts();
|
||||
|
||||
}
|
||||
|
||||
private void btn_edit_Click(object sender, EventArgs e)
|
||||
@ -231,6 +236,8 @@ namespace DisplayMagician.UIForms
|
||||
if (_selectedShortcut == null)
|
||||
return;
|
||||
|
||||
this.Cursor = Cursors.WaitCursor;
|
||||
|
||||
var shortcutForm = new ShortcutForm(_selectedShortcut);
|
||||
shortcutForm.ShowDialog(this);
|
||||
if (shortcutForm.DialogResult == DialogResult.OK)
|
||||
@ -240,6 +247,7 @@ namespace DisplayMagician.UIForms
|
||||
ShortcutRepository.SaveShortcuts();
|
||||
}
|
||||
|
||||
this.Cursor = Cursors.Default;
|
||||
}
|
||||
|
||||
private void btn_delete_Click(object sender, EventArgs e)
|
||||
@ -313,6 +321,9 @@ namespace DisplayMagician.UIForms
|
||||
|
||||
private void ShortcutLibraryForm_Activated(object sender, EventArgs e)
|
||||
{
|
||||
// Refresh the Shortcut Library UI
|
||||
RefreshShortcutLibraryUI();
|
||||
|
||||
RemoveWarningIfShortcuts();
|
||||
}
|
||||
|
||||
|
@ -21,6 +21,7 @@ namespace DisplayMagicianShared
|
||||
#region Class Variables
|
||||
// Common items to the class
|
||||
private static List<ProfileItem> _allProfiles = new List<ProfileItem>();
|
||||
public static Dictionary<string, bool> _profileValidityLookup = new Dictionary<string, bool>();
|
||||
private static bool _profilesLoaded = false;
|
||||
public static Version _version = new Version(1, 0, 0);
|
||||
private static ProfileItem _currentProfile;
|
||||
@ -89,6 +90,18 @@ namespace DisplayMagicianShared
|
||||
}
|
||||
}
|
||||
|
||||
public static Dictionary<string, bool> ProfileValidityLookup
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!_profilesLoaded)
|
||||
// Load the Profiles from storage if they need to be
|
||||
LoadProfiles();
|
||||
|
||||
return _profileValidityLookup;
|
||||
}
|
||||
}
|
||||
|
||||
public static ProfileItem CurrentProfile
|
||||
{
|
||||
get
|
||||
@ -148,10 +161,12 @@ namespace DisplayMagicianShared
|
||||
SaveProfiles();
|
||||
}
|
||||
|
||||
// Refresh the profiles to see whats valid
|
||||
IsPossibleRefresh();
|
||||
|
||||
//Doublecheck it's been added
|
||||
if (ContainsProfile(profile))
|
||||
{
|
||||
IsPossibleRefresh();
|
||||
return true;
|
||||
}
|
||||
else
|
||||
@ -439,6 +454,8 @@ namespace DisplayMagicianShared
|
||||
|
||||
profile.Name = GetValidFilename(renamedName);
|
||||
|
||||
IsPossibleRefresh();
|
||||
|
||||
// If it's been added to the list of AllProfiles
|
||||
// then we also need to reproduce the Icons
|
||||
if (ContainsProfile(profile))
|
||||
@ -454,7 +471,6 @@ namespace DisplayMagicianShared
|
||||
return false;
|
||||
}
|
||||
|
||||
IsPossibleRefresh();
|
||||
|
||||
}
|
||||
|
||||
@ -488,6 +504,8 @@ namespace DisplayMagicianShared
|
||||
SharedLogger.logger.Debug($"ProfileRepository/UpdateActiveProfile: The current profile is a new profile that doesn't already exist in the Profile Repository.");
|
||||
_currentProfile = activeProfile;
|
||||
|
||||
//IsPossibleRefresh();
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -686,6 +704,9 @@ namespace DisplayMagicianShared
|
||||
|
||||
if (_profilesLoaded && _allProfiles.Count > 0)
|
||||
{
|
||||
|
||||
_profileValidityLookup.Clear();
|
||||
|
||||
foreach (ProfileItem loadedProfile in AllProfiles)
|
||||
{
|
||||
|
||||
@ -701,12 +722,14 @@ namespace DisplayMagicianShared
|
||||
{
|
||||
SharedLogger.logger.Debug($"ProfileRepository/IsPossibleRefresh: The profile {loadedProfile.Name} is possible!");
|
||||
loadedProfile.IsPossible = true;
|
||||
_profileValidityLookup[loadedProfile.Name] = true;
|
||||
}
|
||||
|
||||
else
|
||||
{
|
||||
SharedLogger.logger.Debug($"ProfileRepository/IsPossibleRefresh: The profile {loadedProfile.Name} is NOT possible!");
|
||||
loadedProfile.IsPossible = false;
|
||||
_profileValidityLookup[loadedProfile.Name] = false;
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user