示例#1
0
        public void DeleteProfile(ShortcutProfile profile)
        {
            switch (CanDeleteProfile(profile))
            {
            case CanDeleteProfileResult.Success:
                profile = m_LoadedProfiles[profile.id];
                if (activeProfile == profile)
                {
                    activeProfile = null;
                }
                m_LoadedProfiles.Remove(profile.id);
                m_ProfileStore.DeleteShortcutProfile(profile.id);
                loadedProfilesChanged?.Invoke(this);
                break;

            case CanDeleteProfileResult.ProfileNotFound:
                throw new ArgumentException("Profile not found", nameof(profile));

            case CanDeleteProfileResult.ProfileHasDependencies:
                throw new ArgumentException("Profile has dependencies", nameof(profile));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#2
0
        public ShortcutProfile CreateProfile(string profileId, ShortcutProfile parentProfile = null)
        {
            switch (CanCreateProfile(profileId, parentProfile))
            {
            case CanCreateProfileResult.Success:
                var profile = new ShortcutProfile(profileId, parentProfile?.id ?? "");
                m_LoadedProfiles.Add(profileId, profile);
                ResolveProfileParentReference(profile);
                SaveShortcutProfile(profile);
                loadedProfilesChanged?.Invoke(this);
                return(profile);

            case CanCreateProfileResult.InvalidProfileId:
                throw new ArgumentException("Invalid profile id", nameof(profileId));

            case CanCreateProfileResult.DuplicateProfileId:
                throw new ArgumentException("Duplicate profile id", nameof(profileId));

            case CanCreateProfileResult.MissingParentProfile:
                throw new ArgumentException("Missing parent profile", nameof(parentProfile));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#3
0
 internal void ApplyProfile(ShortcutProfile shortcutProfile, bool migratePrefKeys = false)
 {
     // pref keys should only be migrated when the default user profile is applied
     if (migratePrefKeys)
     {
         foreach (var entry in entries)
         {
             if (entry.prefKeyMigratedValue != null)
             {
                 var overrideEntry = new SerializableShortcutEntry
                 {
                     identifier     = entry.identifier,
                     keyCombination = new List <KeyCombination> {
                         entry.prefKeyMigratedValue.Value
                     }
                 };
                 entry.ApplyOverride(overrideEntry);
             }
         }
     }
     foreach (var shortcutOverride in shortcutProfile.entries)
     {
         var entry = entries.FirstOrDefault(e => e.identifier.Equals(shortcutOverride.identifier));
         if (entry != null)
         {
             entry.ApplyOverride(shortcutOverride);
         }
     }
     m_ActiveProfile = shortcutProfile;
 }
示例#4
0
        void ApplySingleProfile(ShortcutProfile shortcutProfile)
        {
            foreach (var shortcutOverride in shortcutProfile.entries)
            {
                var entry = m_Entries.FirstOrDefault(e => e.identifier.Equals(shortcutOverride.identifier));
                if (entry != null)
                {
                    if (!m_BindingValidator.IsCombinationValid(shortcutOverride.combinations, out string invalidBindingMessage))
                    {
                        var nameSnippet = entry.displayName == entry.identifier.path
                            ? $"\"{entry.displayName}\""
                            : $"with ID \"{entry.identifier.path}\" and name \"{entry.displayName}\"";
                        Debug.LogWarning($"Ignoring shortcut {nameSnippet} in profile \"{shortcutProfile.id}\" with invalid binding.\n{invalidBindingMessage}.");
                        continue;
                    }

                    entry.ApplyOverride(shortcutOverride);

                    if (!m_BindingValidator.IsBindingValid(entry, out invalidBindingMessage))
                    {
                        var nameSnippet = entry.displayName == entry.identifier.path
                            ? $"\"{entry.displayName}\""
                            : $"with ID \"{entry.identifier.path}\" and name \"{entry.displayName}\"";
                        Debug.LogWarning($"Cannot apply override to shortcut {nameSnippet} in profile \"{shortcutProfile.id}\" with invalid binding.\n{invalidBindingMessage}.");
                        entry.ResetToDefault();
                        continue;
                    }
                }
            }
            m_ActiveProfile = shortcutProfile;
        }
 public void ApplyActiveProfile()
 {
     m_ActiveProfile = new ShortcutProfile(k_UserProfileId);
     ApplyProfile(m_ActiveProfile);
     MigrateUserSpecifiedPrefKeys(
         EditorAssemblies.GetAllMethodsWithAttribute <FormerlyPrefKeyAsAttribute>(), m_Entries
         );
 }
示例#6
0
        void LoadAndApplyJsonFile(string id, ShortcutProfile instance)
        {
            if (!m_Loader.ProfileExists(id))
            {
                return;
            }
            var json = m_Loader.LoadShortcutProfileJson(id);

            JsonUtility.FromJsonOverwrite(json, instance);
        }
示例#7
0
 ShortcutProfile LoadProfile(string id)
 {
     if (m_ProfileStore.ProfileExists(id))
     {
         ShortcutProfile tmpProfile = new ShortcutProfile();
         LoadAndApplyJsonFile(id, tmpProfile);
         return(tmpProfile);
     }
     throw new FileNotFoundException(string.Format("'{0}.shortcut' does not exist!", id));
 }
示例#8
0
        static List <ShortcutProfile> GetAncestorProfiles(ShortcutProfile profile)
        {
            var ancestors = new List <ShortcutProfile>();

            profile = profile.parent;
            while (profile != null)
            {
                ancestors.Add(profile);
                profile = profile.parent;
            }
            return(ancestors);
        }
 internal void ApplyProfile(ShortcutProfile shortcutProfile)
 {
     foreach (var shortcutOverride in shortcutProfile.entries)
     {
         var entry = m_Entries.FirstOrDefault(e => e.identifier.Equals(shortcutOverride.identifier));
         if (entry != null)
         {
             entry.ApplyOverride(shortcutOverride);
         }
     }
     m_ActiveProfile = shortcutProfile;
 }
示例#10
0
        public void ReloadProfiles()
        {
            InitializeLoadedProfilesDictionary();

            // Update active profile from store (it might be changed or deleted)
            if (activeProfile != null)
            {
                activeProfile = GetProfileById(activeProfile.id);
            }

            loadedProfilesChanged?.Invoke(this);
        }
示例#11
0
        void ResetActiveProfile()
        {
            var newProfile = new ShortcutProfile(m_ActiveProfile.id, m_ActiveProfile.parentId)
            {
                parent = m_ActiveProfile.parent
            };

            m_LoadedProfiles.Remove(m_ActiveProfile.id);
            m_LoadedProfiles.Add(newProfile.id, newProfile);
            activeProfile = newProfile;

            SaveShortcutProfile(m_ActiveProfile);
        }
示例#12
0
        void LoadAndApplyJsonFile(string id, ShortcutProfile instance)
        {
            if (!m_Loader.ProfileExists(id))
            {
                return;
            }
            var json = m_Loader.LoadShortcutProfileJson(id);

            JsonUtility.FromJsonOverwrite(json, instance);
            foreach (var entry in m_SerializableEntries)
            {
                m_Entries.Add(entry.identifier.path, entry);
            }
        }
示例#13
0
        void SwitchActiveProfileTo(ShortcutProfile shortcutProfile)
        {
            ResetShortcutEntries();
            var profileParents = GetAncestorProfiles(shortcutProfile);

            if (profileParents != null)
            {
                for (int i = profileParents.Count - 1; i >= 0; --i)
                {
                    ApplySingleProfile(profileParents[i]);
                }
            }

            ApplySingleProfile(shortcutProfile);
        }
示例#14
0
        void LoadAndApplyJsonFile(string id, ShortcutProfile instance)
        {
            if (!m_ProfileStore.ProfileExists(id))
            {
                return;
            }

            var json = m_ProfileStore.LoadShortcutProfileJson(id);

            JsonUtility.FromJsonOverwrite(json, instance);
            if (id != instance.id)
            {
                Debug.LogWarning(string.Format("The identifier '{0}' doesn't match the filename of '{1}.shortcut'!", id, instance.id));
            }
        }
示例#15
0
        public CanDeleteProfileResult CanDeleteProfile(ShortcutProfile profile)
        {
            // Profile must exist
            if (!m_LoadedProfiles.ContainsKey(profile.id))
            {
                return(CanDeleteProfileResult.ProfileNotFound);
            }

            // Profile cannot have any dependent profiles
            if (m_LoadedProfiles.Values.Any(p => p.parentId == profile.id))
            {
                return(CanDeleteProfileResult.ProfileHasDependencies);
            }

            return(CanDeleteProfileResult.Success);
        }
示例#16
0
        void ResolveProfileParentReference(ShortcutProfile profile)
        {
            if (string.IsNullOrEmpty(profile.parentId))
            {
                return;
            }

            if (m_LoadedProfiles.ContainsKey(profile.parentId))
            {
                profile.parent = m_LoadedProfiles[profile.parentId];
            }
            else
            {
                Debug.LogWarning($"Shortcut profile with id '{profile.id}' references unknown parent profile with id '{profile.parentId}'. Breaking parent link.");
                profile.BreakParentLink();
            }
        }
示例#17
0
        public void RenameProfile(ShortcutProfile profile, string newProfileId)
        {
            switch (CanRenameProfile(profile, newProfileId))
            {
            case CanRenameProfileResult.Success:
            {
                var newProfile = new ShortcutProfile(newProfileId, profile.entries, profile.parentId);
                m_LoadedProfiles.Add(newProfile.id, newProfile);
                SaveShortcutProfile(newProfile);
                foreach (var childProfile in m_LoadedProfiles.Values.Where(childProfile => childProfile.parent == profile))
                {
                    childProfile.parent   = newProfile;
                    childProfile.parentId = newProfile.id;
                    SaveShortcutProfile(childProfile);
                }

                if (activeProfile == profile)
                {
                    activeProfile = newProfile;
                }

                try
                {
                    DeleteProfile(profile);
                }
                catch (Exception exception)
                {
                    Debug.LogError($"Error removing old shortcut profile: {exception}");
                }
                break;
            }

            case CanRenameProfileResult.ProfileNotFound:
                throw new ArgumentException("Profile not found", nameof(profile));

            case CanRenameProfileResult.InvalidProfileId:
                throw new ArgumentException("Invalid profile id", nameof(newProfileId));

            case CanRenameProfileResult.DuplicateProfileId:
                throw new ArgumentException("Duplicate profile id", nameof(newProfileId));

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
示例#18
0
        public CanCreateProfileResult CanCreateProfile(string profileId, ShortcutProfile parentProfile = null)
        {
            // Profile id must be valid
            if (!m_ProfileStore.ValidateProfileId(profileId))
            {
                return(CanCreateProfileResult.InvalidProfileId);
            }

            // Profile id must be unique (case-insensitive)
            if (m_LoadedProfiles.Any(pair => pair.Key.Equals(profileId, StringComparison.OrdinalIgnoreCase)))
            {
                return(CanCreateProfileResult.DuplicateProfileId);
            }

            // Parent profile must exist, if given
            if (parentProfile != null && !m_LoadedProfiles.ContainsKey(parentProfile.id))
            {
                return(CanCreateProfileResult.MissingParentProfile);
            }

            return(CanCreateProfileResult.Success);
        }
示例#19
0
        public CanRenameProfileResult CanRenameProfile(ShortcutProfile profile, string newProfileId)
        {
            // Profile must exist
            if (!m_LoadedProfiles.ContainsKey(profile.id))
            {
                return(CanRenameProfileResult.ProfileNotFound);
            }

            // Profile id must be valid
            if (!m_ProfileStore.ValidateProfileId(newProfileId))
            {
                return(CanRenameProfileResult.InvalidProfileId);
            }

            // Profile id must be unique
            if (m_LoadedProfiles.ContainsKey(newProfileId))
            {
                return(CanRenameProfileResult.DuplicateProfileId);
            }

            return(CanRenameProfileResult.Success);
        }
示例#20
0
        static void BreakProfileParentCyclicDependency(ShortcutProfile profile)
        {
            if (profile.parent == null)
            {
                return;
            }

            var seenProfiles = new List <ShortcutProfile>();

            do
            {
                seenProfiles.Add(profile);

                if (seenProfiles.Contains(profile.parent))
                {
                    Debug.LogWarning($"Cyclic dependency between shortcut profiles found! Breaking parent link at '{profile.id}'.");
                    profile.BreakParentLink();
                    return;
                }

                profile = profile.parent;
            }while (profile.parent != null);
        }
示例#21
0
 void OnActiveProfileChanged(IShortcutProfileManager shortcutProfileManager, ShortcutProfile previousActiveProfile, ShortcutProfile currentActiveProfile)
 {
     UpdateInternalCache();
 }
示例#22
0
 internal void BreakParentLink()
 {
     m_ParentId = "";
     parent     = null;
 }
示例#23
0
 public void ApplyActiveProfile()
 {
     m_ActiveProfile = new ShortcutProfile(k_UserProfileId);
     ApplyProfile(m_ActiveProfile, true);
 }
 void OnActiveProfileChanged(IShortcutProfileManager sender, ShortcutProfile oldActiveProfile, ShortcutProfile newActiveProfile)
 {
     m_LastUsedProfileIdProvider.lastUsedProfileId = profileManager.activeProfile?.id;
     Initialize();
 }
示例#25
0
        void RaiseActiveProfileChanged(IShortcutProfileManager shortcutProfileManager, ShortcutProfile oldActiveProfile, ShortcutProfile newActiveProfile)
        {
            var oldActiveProfileId = oldActiveProfile?.id ?? ShortcutManager.defaultProfileId;
            var newActiveProfileId = newActiveProfile?.id ?? ShortcutManager.defaultProfileId;
            var eventArgs          = new ActiveProfileChangedEventArgs(oldActiveProfileId, newActiveProfileId);

            activeProfileChanged?.Invoke(eventArgs);
        }
示例#26
0
 void SaveShortcutProfile(ShortcutProfile profile)
 {
     m_ProfileStore.SaveShortcutProfileJson(profile.id, JsonUtility.ToJson(profile));
 }