Esempio n. 1
0
 ShortcutAttribute(string id, Type context, ShortcutBinding defaultBinding)
 {
     this.identifier     = id;
     this.context        = context;
     this.defaultBinding = defaultBinding;
     displayName         = identifier;
 }
Esempio n. 2
0
        public void ResetToDefault(ShortcutEntry entry)
        {
            var oldBinding = new ShortcutBinding(entry.combinations);

            entry.ResetToDefault();
            activeProfile.Remove(entry.identifier);
            SaveShortcutProfile(activeProfile);
            var newBinding = new ShortcutBinding(entry.combinations);

            shortcutBindingChanged?.Invoke(this, entry.identifier, oldBinding, newBinding);
        }
Esempio n. 3
0
        public void ModifyShortcutEntry(Identifier identifier, IEnumerable <KeyCombination> combinationSequence)
        {
            if (activeProfile == null)
            {
                throw new InvalidOperationException("No active profile");
            }

            if (!m_BindingValidator.IsCombinationValid(combinationSequence, out string invalidBindingMessage))
            {
                throw new ArgumentException(invalidBindingMessage, nameof(combinationSequence));
            }

            var shortcutEntry = m_Entries.FirstOrDefault(e => e.identifier.Equals(identifier));
            var oldBinding    = new ShortcutBinding(shortcutEntry.combinations);

            shortcutEntry.SetOverride(combinationSequence);

            if (!m_BindingValidator.IsBindingValid(shortcutEntry, out invalidBindingMessage))
            {
                shortcutEntry.ResetToDefault();
                Debug.LogError(invalidBindingMessage);
                shortcutBindingChanged?.Invoke(this, identifier, oldBinding, oldBinding);
                return;
            }

            SerializableShortcutEntry profileEntry = null;

            foreach (var activeProfileEntry in m_ActiveProfile.entries)
            {
                if (activeProfileEntry.identifier.Equals(identifier))
                {
                    profileEntry = activeProfileEntry;
                    oldBinding   = new ShortcutBinding(profileEntry.combinations);
                    profileEntry.combinations = new List <KeyCombination>(combinationSequence);
                    break;
                }
            }

            if (profileEntry == null)
            {
                m_ActiveProfile.Add(shortcutEntry);
            }

            SaveShortcutProfile(m_ActiveProfile);

            var newBinding = new ShortcutBinding(combinationSequence);

            shortcutBindingChanged?.Invoke(this, identifier, oldBinding, newBinding);
        }
Esempio n. 4
0
        public void RebindShortcut(string shortcutId, ShortcutBinding binding)
        {
            if (shortcutId == null)
            {
                throw new ArgumentNullException(nameof(shortcutId) + ":" + shortcutId);
            }

            var shortcutEntries = m_ShortcutProfileManager.GetAllShortcuts();
            var shortcutEntry   = shortcutEntries.FirstOrDefault(entry => entry.identifier.path == shortcutId);

            if (shortcutEntry == null)
            {
                throw new ArgumentException("Shortcut not available", nameof(shortcutId) + ": " + shortcutId);
            }

            if (IsProfileReadOnly(activeProfileId))
            {
                throw new InvalidOperationException("Cannot rebind shortcut on read-only profile");
            }

            m_ShortcutProfileManager.ModifyShortcutEntry(shortcutEntry.identifier, binding.keyCombinationSequence);
        }
 void OnShortcutBindingChanged(IShortcutProfileManager sender, Identifier identifier, ShortcutBinding oldBinding, ShortcutBinding newBinding)
 {
     Initialize();
 }
Esempio n. 6
0
 public ShortcutBindingChangedEventArgs(string shortcutId, ShortcutBinding oldBinding, ShortcutBinding newBinding)
 {
     this.shortcutId = shortcutId;
     this.oldBinding = oldBinding;
     this.newBinding = newBinding;
 }
Esempio n. 7
0
        void RaiseShortcutBindingChanged(IShortcutProfileManager shortcutProfileManager, Identifier identifier, ShortcutBinding oldBinding, ShortcutBinding newBinding)
        {
            var eventArgs = new ShortcutBindingChangedEventArgs(identifier.path, oldBinding, newBinding);

            shortcutBindingChanged?.Invoke(eventArgs);
        }