예제 #1
0
        public static HotkeyCommand[] LoadHotkeys(string name)
        {
            var settings    = new HotkeySettings();
            var scriptKeys  = new HotkeySettings();
            var allSettings = LoadSettings();

            UpdateUsedKeys(allSettings);

            foreach (var setting in allSettings)
            {
                if (setting.Name == name)
                {
                    settings = setting;
                }

                if (setting.Name == "Scripts")
                {
                    scriptKeys = setting;
                }
            }

            // append general hotkeys to every form
            var allKeys = new HotkeyCommand[settings.Commands.Length + scriptKeys.Commands.Length];

            settings.Commands.CopyTo(allKeys, 0);
            scriptKeys.Commands.CopyTo(allKeys, settings.Commands.Length);

            return(allKeys);
        }
        public static HotkeyCommand[] LoadHotkeys(string name)
        {
            //var settings = LoadSettings().FirstOrDefault(s => s.Name == name);
            HotkeySettings[] allSettings;
            HotkeySettings settings = new HotkeySettings();
            HotkeySettings scriptkeys = new HotkeySettings();
            allSettings = LoadSettings();

            GetUsedHotkeys(allSettings);

            foreach(HotkeySettings hs in allSettings)
            {
                if(hs.Name == name)
                    settings = hs;
                if(hs.Name == "Scripts")
                    scriptkeys = hs;
            }

            //HotkeyCommand[] scriptkeys = LoadSettings().FirstOrDefault(s => s.Name == name);

            if(settings != null) {
                //append general hotkeys to every form
                //HotkeyCommand[] scriptkeys = LoadScriptHotkeys();
                HotkeyCommand[] allkeys = new HotkeyCommand[settings.Commands.Length + scriptkeys.Commands.Length];
                settings.Commands.CopyTo(allkeys,0);
                scriptkeys.Commands.CopyTo(allkeys,settings.Commands.Length);

                return allkeys;
            }

            //return settings != null ? settings.Commands : null;
            return null;
        }
        public void DidDefaultSettingsChangeTest1()
        {
            // arrange
            HotkeySettings hotkeySettings1 = new HotkeySettings("settings1", new HotkeyCommand(1, "C1"), new HotkeyCommand(2, "C2"));
            HotkeySettings hotkeySettings2 = new HotkeySettings("settings2", new HotkeyCommand(3, "C3"), new HotkeyCommand(4, "C4"));

            var defaultHotkeySettingsArray = new HotkeySettings[2] { hotkeySettings1, hotkeySettings2 };
            var loadedHotkeySettingsArray = new HotkeySettings[2] { hotkeySettings1, hotkeySettings2 };

            // act, assert
            HotkeySettingsManager.DidDefaultSettingsChange(defaultHotkeySettingsArray, loadedHotkeySettingsArray).Should().BeFalse();

            // arrange: add one more settings items
            defaultHotkeySettingsArray = new HotkeySettings[3] { hotkeySettings1, hotkeySettings2, hotkeySettings2 };

            // act, assert
            HotkeySettingsManager.DidDefaultSettingsChange(defaultHotkeySettingsArray, loadedHotkeySettingsArray).Should().BeTrue();

            // act (null handling), assert
            HotkeySettingsManager.DidDefaultSettingsChange(null, defaultHotkeySettingsArray).Should().BeTrue();

            // act (null handling), assert
            HotkeySettingsManager.DidDefaultSettingsChange(defaultHotkeySettingsArray, null).Should().BeTrue();

            // act (null handling), assert
            HotkeySettingsManager.DidDefaultSettingsChange(null, null).Should().BeTrue();
        }
예제 #4
0
        private void UpdateCombobox(HotkeySettings[] settings)
        {
            this.SelectedHotkeySettings = null;

            this.cmbSettings.Items.Clear();
            if (settings != null)
                foreach (var setting in settings)
                    cmbSettings.Items.Add(setting);
        }
예제 #5
0
        public override bool Equals(object obj)
        {
            HotkeySettings other = obj as HotkeySettings;

            if (other == null)
            {
                return(false);
            }

            return(Commands.SequenceEqual(other.Commands));
        }
예제 #6
0
        private void UpdateListViewItems(HotkeySettings setting)
        {
            this.SelectedHotkeyCommand = null;

            this.listMappings.Items.Clear();
            if (setting != null)
                foreach (var cmd in setting.Commands)
                {
                    if (cmd != null)
                        this.listMappings.Items.Add(new ListViewItem(new[] { cmd.Name, cmd.KeyData.ToText() }) { Tag = cmd });
                }
        }
예제 #7
0
 /// <summary>Serializes and saves the supplied settings</summary>
 public static void SaveSettings(HotkeySettings[] settings)
 {
     try
       {
     StringBuilder strBuilder = new StringBuilder();
     using (StringWriter writer = new StringWriter(strBuilder))
     {
       Serializer.Serialize(writer, settings);
       Properties.Settings.Default.Hotkeys = strBuilder.ToString();
       Properties.Settings.Default.Save();
     }
       }
       catch { }
 }
        public void DidDefaultSettingsChangeTest2()
        {
            // arrange
            var defaultHotkeySettingsArray = new HotkeySettings[2] {
                new HotkeySettings("settings1", new HotkeyCommand(1, "C1")),
                new HotkeySettings("settings2", new HotkeyCommand(3, "C3"), new HotkeyCommand(2, "C2"), new HotkeyCommand(4, "C4"))
            };

            var loadedHotkeySettingsArray = new HotkeySettings[2] {
                new HotkeySettings("settings1", new HotkeyCommand(1, "C1"), new HotkeyCommand(4, "C4")),
                new HotkeySettings("settings2", new HotkeyCommand(3, "C3"), new HotkeyCommand(2, "C2"))
            };

            // act, assert
            HotkeySettingsManager.DidDefaultSettingsChange(defaultHotkeySettingsArray, loadedHotkeySettingsArray).Should().BeTrue();
        }
예제 #9
0
        private void UpdateListViewItems(HotkeySettings setting)
        {
            this.SelectedHotkeyCommand = null;

            this.listMappings.Items.Clear();
            if (setting != null)
            {
                foreach (var cmd in setting.Commands)
                {
                    this.listMappings.Items.Add(new ListViewItem(new[] { cmd.Name, cmd.KeyData.ToText() })
                    {
                        Tag = cmd
                    });
                }
            }
        }
        public static HotkeyCommand[] LoadHotkeys(string name)
        {
            ////var settings = LoadSettings().FirstOrDefault(s => s.Name == name);
            HotkeySettings[] allSettings;
            HotkeySettings   settings   = new HotkeySettings();
            HotkeySettings   scriptkeys = new HotkeySettings();

            allSettings = LoadSettings();

            GetUsedHotkeys(allSettings);

            foreach (HotkeySettings hs in allSettings)
            {
                if (hs.Name == name)
                {
                    settings = hs;
                }

                if (hs.Name == "Scripts")
                {
                    scriptkeys = hs;
                }
            }

            ////HotkeyCommand[] scriptkeys = LoadSettings().FirstOrDefault(s => s.Name == name);

            if (settings != null)
            {
                // append general hotkeys to every form
                ////HotkeyCommand[] scriptkeys = LoadScriptHotkeys();
                HotkeyCommand[] allkeys = new HotkeyCommand[settings.Commands.Length + scriptkeys.Commands.Length];
                settings.Commands.CopyTo(allkeys, 0);
                scriptkeys.Commands.CopyTo(allkeys, settings.Commands.Length);

                return(allkeys);
            }

            ////return settings != null ? settings.Commands : null;
            return(null);
        }
예제 #11
0
        private static void GetUsedHotkeys(HotkeySettings[] settings)
        {
            UsedKeys.Clear();
            foreach (HotkeySettings hs in settings)
            {
                for (int i = 0; i < hs.Commands.Length; i++)
                {
                    HotkeyCommand hotkeyCommand = hs.Commands[i];

                    if (hotkeyCommand != null && !UsedKeys.Contains(hotkeyCommand.KeyData))
                        UsedKeys.Add(hotkeyCommand.KeyData);
                }
            }
            //MessageBox.Show(UsedKeys.Count.ToString());
        }
예제 #12
0
        private static bool DidDefaultSettingsChange(HotkeySettings[] defaultSettings, HotkeySettings[] loadedSettings)
        {
            if (defaultSettings == null || loadedSettings == null)
                return true;

            if (defaultSettings.Length != loadedSettings.Length)
                return true;

            var defaultCmds = defaultSettings.SelectMany(s => s.Commands).ToArray();
            var loadedCmds = loadedSettings.SelectMany(s => s.Commands).ToArray();

            if (defaultCmds.Length != loadedCmds.Length)
                return true;

            // TODO Add additional checks

            return false;
        }
        internal static bool DidDefaultSettingsChange(HotkeySettings[] defaultSettings, HotkeySettings[] loadedSettings)
        {
            if (defaultSettings == null || loadedSettings == null)
                return true;

            if (defaultSettings.Length != loadedSettings.Length)
                return true;

            var defaultCmds = defaultSettings.SelectMany(s => s.Commands).ToArray();
            var loadedCmds = loadedSettings.SelectMany(s => s.Commands).ToArray();

            // see if total commands count has changed
            if (defaultCmds.Length != loadedCmds.Length)
                return true;

            // detect if total commands count did not change but a command was moved from one set to another
            for (int i = 0; i < defaultSettings.Length; i++)
            {
                var defaultSetting = defaultSettings[i];
                var loadedSetting = loadedSettings[i];

                if (defaultSetting.Commands.Length != loadedSetting.Commands.Length)
                {
                    return true;
                }
            }

            return false;
        }
예제 #14
0
        private void UpdateListViewItems(HotkeySettings setting)
        {
            this.SelectedHotkeyCommand = null;

            this.listMappings.Items.Clear();
            if (setting != null)
            {
                foreach (var cmd in setting.Commands)
                {
                    if (cmd != null)
                    {
                        var item = new ListViewItem(new[] {cmd.Name, cmd.KeyData.ToText() ?? _hotkeyNotSet.Text});
                        item.Tag = cmd;
                        this.listMappings.Items.Add(item);
                    }
                }
            }
        }